CSEngine
Loading...
Searching...
No Matches
SFrameBuffer.h
1#pragma once
2
3#include "../../Object/SResource.h"
4#include "../../OGLDef.h"
5#include "../Vector.h"
6#include <vector>
7
8namespace CSE {
9
10 class STexture;
11
12 class GLProgramHandle;
13
31 class SFrameBuffer : public SResource {
32 public:
33 enum BufferType {
34 RENDER = 0, DEPTH = 1, STENCIL = 2,
35 };
36 enum BufferDimension {
37 PLANE = 0, CUBE = 1,
38 };
39 enum BufferStatus {
40 NONE = 0, COLOR_ONLY = 1, DEPTH_ONLY = 2, MULTI = 3,
41 };
42 enum BlitType {
43 IN_ORDER = 0, REVERSE = 1,
44 };
45
46 private:
47 struct BufferObject {
48 BufferType type = RENDER;
49 unsigned int renderbufferId = 0;
50 STexture* texture = nullptr;
51 int format = 0;
52 short level = 0;
53 };
54 struct BlitObject {
55 GLProgramHandle* handle = nullptr;
56 int aColor = -1;
57 int bColor = -1;
58 int aDepth = -1;
59 int bDepth = -1;
60 };
61
62 public:
64
65 ~SFrameBuffer() override;
66
74 void GenerateFramebuffer(BufferDimension dimension, int width, int height);
75
82 unsigned int GenerateRenderbuffer(BufferType type, int internalFormat);
83
91 STexture* GenerateTexturebuffer(BufferType type, int channel, int level = 0);
92
98
99 void AttachCubeBuffer(int index, int level = 0) const;
100
101 void AttachFrameBuffer(int target = GL_FRAMEBUFFER) const;
102
103 void DetachFrameBuffer() const;
104
105 void ResizeFrameBuffer(int width, int height);
106
107 void Exterminate() override;
108
120 void BlitFrameBuffer(const SFrameBuffer& dst, BlitType type = IN_ORDER);
121
122 int GetWidth() const;
123
124 int GetHeight() const;
125
126 const ivec2& GetSize() const {
127 return *m_size;
128 }
129
130 BufferStatus GetBufferStatus() const;
131
137 STexture* GetTexture(int index) const;
138
144 STexture* GetTexture(const char* id) const;
145
151 unsigned int GetRenderbufferID(int index) const;
152
158 if (m_mainColorBuffer == nullptr) return nullptr;
159 return m_mainColorBuffer->texture;
160 }
161
167 if (m_depthBuffer == nullptr) return nullptr;
168 return m_depthBuffer->texture;
169 }
170
171 protected:
172 void Init(const AssetMgr::AssetReference* asset) override;
173
174 private:
175 int GenerateAttachmentType(SFrameBuffer::BufferType type, bool isIncreaseAttachment = true) const;
176
177 int GenerateInternalFormat(int channel) const;
178
179 int GenerateInternalType(int channel) const;
180
181 void ReleaseBufferObject(const SFrameBuffer::BufferObject* bufferObject);
182
183 private:
184 ivec2* m_size = new ivec2(512, 512);
185 BufferDimension m_dimension = PLANE;
186
187 unsigned int m_fbo = 0;
188 std::vector<BufferObject*> m_buffers;
189 BufferObject* m_mainColorBuffer = nullptr;
190 BufferObject* m_depthBuffer = nullptr;
191
192 mutable BufferStatus m_bufferStatus = BufferStatus::NONE;
193 mutable unsigned short m_colorAttachmentSize = 0;
194
198 static BlitObject m_blitObject;
199 };
200}
unsigned int GetRenderbufferID(int index) const
STexture * GenerateTexturebuffer(BufferType type, int channel, int level=0)
STexture * GetMainColorTexture() const
unsigned int GenerateRenderbuffer(BufferType type, int internalFormat)
STexture * GetDepthTexture() const
void GenerateFramebuffer(BufferDimension dimension, int width, int height)
STexture * GetTexture(int index) const
void BlitFrameBuffer(const SFrameBuffer &dst, BlitType type=IN_ORDER)