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
14 class CameraBase;
15
33 class SFrameBuffer : public SResource {
34 public:
35 enum BufferType {
36 RENDER = 0, DEPTH = 1, STENCIL = 2,
37 };
38 enum BufferDimension {
39 PLANE = 0, CUBE = 1,
40 };
41 enum BufferStatus {
42 NONE = 0, COLOR_ONLY = 1, DEPTH_ONLY = 2, MULTI = 3,
43 };
44 enum BlitType {
45 IN_ORDER = 0, REVERSE = 1,
46 };
47
48 private:
49 struct BufferObject {
50 BufferType type = RENDER;
51 unsigned int renderbufferId = 0;
52 STexture* texture = nullptr;
53 int format = 0;
54 short level = 0;
55 };
56 struct PostObject {
57 GLProgramHandle* handle = nullptr;
58 STexture* copyBuffer = nullptr;
59 int copyFbo = -1;
60 int copyTexId = -1;
61 int color = -1;
62 int depth = -1;
63 };
64
65 public:
66 RESOURCE_DEFINE_CONSTRUCTOR(SFrameBuffer);
67
68 ~SFrameBuffer() override;
69
77 void GenerateFramebuffer(BufferDimension dimension, int width, int height);
78
85 unsigned int GenerateRenderbuffer(BufferType type, int internalFormat);
86
94 STexture* GenerateTexturebuffer(BufferType type, int channel, int level = 0);
95
101
102 void AttachCubeBuffer(int index, int level = 0) const;
103
104 void AttachFrameBuffer(int target = GL_FRAMEBUFFER) const;
105
106 void DetachFrameBuffer() const;
107
108 void ResizeFrameBuffer(int width, int height);
109
110 void Exterminate() override;
111
112 void PostFrameBuffer(GLProgramHandle* handle, const CameraBase& camera);
113
114 STexture* BlitCopiedFrameBuffer() const;
115
116 int GetWidth() const;
117
118 int GetHeight() const;
119
120 const ivec2& GetSize() const {
121 return *m_size;
122 }
123
124 BufferStatus GetBufferStatus() const;
125
131 STexture* GetTexture(int index) const;
132
138 STexture* GetTexture(const char* id) const;
139
145 unsigned int GetRenderbufferID(int index) const;
146
152 if (m_mainColorBuffer == nullptr) return nullptr;
153 return m_mainColorBuffer->texture;
154 }
155
161 if (m_depthBuffer == nullptr) return nullptr;
162 return m_depthBuffer->texture;
163 }
164
165 void SetValue(std::string name_str, Arguments value) override;
166
167 std::string PrintValue() const override;
168
169 protected:
170 void Init(const AssetMgr::AssetReference* asset) override;
171
172 private:
173 int GenerateAttachmentType(SFrameBuffer::BufferType type, bool isIncreaseAttachment = true) const;
174
175 int GenerateInternalFormat(int channel) const;
176
177 int GenerateInternalType(int channel) const;
178
179 void ReleaseBufferObject(const SFrameBuffer::BufferObject* bufferObject);
180
181 private:
182 ivec2* m_size = new ivec2(512, 512);
183 BufferDimension m_dimension = PLANE;
184
185 unsigned int m_fbo = 0;
186 std::vector<BufferObject*> m_buffers;
187 BufferObject* m_mainColorBuffer = nullptr;
188 BufferObject* m_depthBuffer = nullptr;
189
190 mutable BufferStatus m_bufferStatus = BufferStatus::NONE;
191 mutable unsigned short m_colorAttachmentSize = 0;
192
193 mutable PostObject m_postObject;
194 };
195}
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 SetValue(std::string name_str, Arguments value) override
void GenerateFramebuffer(BufferDimension dimension, int width, int height)
STexture * GetTexture(int index) const