LkEngine 0.1.2
 
Loading...
Searching...
No Matches
Framebuffer.h
1#pragma once
2
4#include "LkEngine/Renderer/Texture.h"
5
6
7namespace LkEngine {
8
9 class LFramebuffer;
10
11 enum class EFramebufferTextureFormat
12 {
13 None = 0,
14
15 RGBA8,
16 RED_INTEGER,
17
18 DEPTH24STENCIL8, /* Depth/Stencil */
19
20 Depth = DEPTH24STENCIL8
21 };
22
23 enum class EFramebufferBlendMode
24 {
25 None = 0,
26 OneZero,
27 SrcAlphaOneMinusSrcAlpha,
28 Additive,
29 Zero_SrcColor
30 };
31
32 enum class EAttachmentLoadOp
33 {
34 Inherit = 0,
35 Clear = 1,
36 Load = 2
37 };
38
40 {
42 FFramebufferTextureSpecification(EImageFormat InImageFormat)
43 : ImageFormat(InImageFormat) {}
44
45 EImageFormat ImageFormat{};
46 bool bBlend = true;
47 EFramebufferBlendMode BlendMode = EFramebufferBlendMode::SrcAlphaOneMinusSrcAlpha;
48 EAttachmentLoadOp LoadOp = EAttachmentLoadOp::Inherit;
49 };
50
52 {
54 FFramebufferAttachmentSpecification(const std::initializer_list<FFramebufferTextureSpecification>& InAttachments)
55 : Attachments(InAttachments) {}
56
57 std::vector<FFramebufferTextureSpecification> Attachments{};
58 };
59
61 {
62 float Scale = 1.0f;
63 uint32_t Width = 0;
64 uint32_t Height = 0;
65 glm::vec4 ClearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
66 float DepthClearValue = 0.0f;
67 bool ClearColorOnLoad = true;
68 bool ClearDepthOnLoad = true;
69
70 uint32_t Samples = 1;
71
73 EFramebufferBlendMode BlendMode = EFramebufferBlendMode::None;
74
75 bool SwapChainTarget = false; // SwapChainTarget
76 bool Transfer = false; // Transfer operation flag
77 bool Blend = true;
78
79 TObjectPtr<LFramebuffer> ExistingFramebuffer;
80
81 // Note: these are used to attach multi-layered color/depth images
82 TObjectPtr<LImage> ExistingImage;
83 std::vector<uint32_t> ExistingImageLayers;
84
85 std::map<uint32_t, TObjectPtr<LImage>> ExistingImages;
86
87 std::string DebugName;
88
89 FFramebufferSpecification() = default;
90 };
91
92 using FResizeCallback = std::function<void(TObjectPtr<LFramebuffer>)>;
93
94 class LFramebuffer : public LObject
95 {
96 public:
97 virtual ~LFramebuffer() = default;
98
99 virtual void Invalidate() = 0;
100 virtual void Resize(const uint32_t NewWidth, const uint32_t NewHeight, const bool bForceRecreate = false) = 0;
101 virtual void AddResizeCallback(const FResizeCallback& Func) = 0;
102
103 virtual TObjectPtr<LImage> GetImage(const uint32_t AttachmentIndex = 0) const = 0;
104 virtual TObjectPtr<LImage> GetDepthImage() const = 0;
105 virtual size_t GetColorAttachmentCount() const = 0;
106 virtual bool HasDepthAttachment() const = 0;
107
108 virtual void Bind() const = 0;
109 virtual void Unbind() const = 0;
110 virtual void BindTexture(const uint32_t AttachmentIndex = 0, const uint32_t TextureSlot = 0) const = 0;
111
112 virtual void Clear() = 0;
113 virtual int ReadPixel(const uint32_t AttachmentIndex, const int PosX, const int PosY) = 0;
114 virtual void ClearAttachment(const uint32_t AttachmentIndex, int value) = 0;
115 virtual LRendererID GetColorAttachmentRendererID(const uint32_t Index = 0) const = 0;
116
117 virtual LRendererID GetRendererID() const = 0;
118 virtual LRendererID& GetRendererID() = 0;
119 virtual uint32_t GetWidth() const = 0;
120 virtual uint32_t GetHeight() const = 0;
121 virtual uint64_t GetSize() const = 0;
122 virtual const FFramebufferSpecification& GetSpecification() const = 0;
123
124 static TObjectPtr<LFramebuffer> Create(const FFramebufferSpecification& InSpecification);
125
126 static void TargetSwapChain();
127
128 private:
130 };
131
132
133 namespace Enum {
134
135 FORCEINLINE static constexpr const char* ToString(const EFramebufferTextureFormat Format)
136 {
137 switch (Format)
138 {
139 case EFramebufferTextureFormat::RGBA8: return "RGBA8";
140 case EFramebufferTextureFormat::RED_INTEGER: return "RED_INTEGER";
141 case EFramebufferTextureFormat::DEPTH24STENCIL8: return "DEPTH24STENCIL8";
142 case EFramebufferTextureFormat::None: return "None";
143 }
144
145 LK_CORE_ASSERT(false, "Invalid FramebufferTextureFormat");
146 return "";
147 }
148
149 }
150
151}
Core header.
Definition Framebuffer.h:95
Definition Object.h:46
Definition ObjectPtr.h:102
#define LCLASS(Class)
Definition CoreMacros.h:226
uint32_t LRendererID
Definition CoreTypes.h:30
Definition Asset.h:11
Definition Framebuffer.h:61