TDME2 1.9.121
GeometryBuffer.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
9#include <tdme/math/Math.h>
12
14
22
23GeometryBuffer::GeometryBuffer(int32_t width, int32_t height)
24{
25 this->width = width;
26 this->height = height;
27 this->frameBufferId = -1;
37}
38
40{
60 );
61}
62
63void GeometryBuffer::reshape(int32_t width, int32_t height)
64{
65 this->width = width;
66 this->height = height;
76}
77
79{
89 // TODO: Vulkan might need a extra method here
91}
92
94{
98}
99
101{
105}
106
108{
109 auto renderer = Engine::renderer;
110
111 // use default context
112 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
113
114 //
115 renderer->disableCulling(contextIdx);
116
117 // clear
118 renderer->setClearColor(engine->sceneColor.getRed(), engine->sceneColor.getGreen(), engine->sceneColor.getBlue(), engine->sceneColor.getAlpha());
119 renderer->clear(renderer->CLEAR_COLOR_BUFFER_BIT | renderer->CLEAR_DEPTH_BUFFER_BIT);
120
121 // use deferred lighting render shader
122 auto frameBufferRenderShader = Engine::getFrameBufferRenderShader();
123 auto deferredLightingRenderShader = Engine::getDeferredLightingRenderShader();
124 deferredLightingRenderShader->useProgram(engine);
125
126 // bind geometry buffer textures
127 renderer->setTextureUnit(contextIdx, 0);
128 renderer->bindTexture(contextIdx, geometryBufferTextureId1);
129 renderer->setTextureUnit(contextIdx, 1);
130 renderer->bindTexture(contextIdx, geometryBufferTextureId2);
131 renderer->setTextureUnit(contextIdx, 2);
132 renderer->bindTexture(contextIdx, geometryBufferTextureId3);
133
134 // bind color buffer textures
135 renderer->setTextureUnit(contextIdx, 3);
136 renderer->bindTexture(contextIdx, colorBufferTextureId1);
137 renderer->setTextureUnit(contextIdx, 4);
138 renderer->bindTexture(contextIdx, colorBufferTextureId2);
139 renderer->setTextureUnit(contextIdx, 5);
140 renderer->bindTexture(contextIdx, colorBufferTextureId3);
141 renderer->setTextureUnit(contextIdx, 6);
142 renderer->bindTexture(contextIdx, colorBufferTextureId4);
143 renderer->setTextureUnit(contextIdx, 7);
144 renderer->bindTexture(contextIdx, colorBufferTextureId5);
145
146 // bind depth buffer texture
147 renderer->setTextureUnit(contextIdx, 8);
148 renderer->bindTexture(contextIdx, depthBufferTextureId);
149
150 //
151 renderer->bindVerticesBufferObject(contextIdx, frameBufferRenderShader->getVBOVertices());
152 renderer->bindTextureCoordinatesBufferObject(contextIdx, frameBufferRenderShader->getVBOTextureCoordinates());
153
154 // draw
155 renderer->drawTrianglesFromBufferObjects(contextIdx, 2, 0);
156
157 // unbind buffers
158 renderer->unbindBufferObjects(contextIdx);
159
160 // unbind geometry buffer textures
161 renderer->setTextureUnit(contextIdx, 0);
162 renderer->bindTexture(contextIdx, renderer->ID_NONE);
163 renderer->setTextureUnit(contextIdx, 1);
164 renderer->bindTexture(contextIdx, renderer->ID_NONE);
165 renderer->setTextureUnit(contextIdx, 2);
166 renderer->bindTexture(contextIdx, renderer->ID_NONE);
167
168 // unbind color buffer textures
169 renderer->setTextureUnit(contextIdx, 3);
170 renderer->bindTexture(contextIdx, renderer->ID_NONE);
171 renderer->setTextureUnit(contextIdx, 4);
172 renderer->bindTexture(contextIdx, renderer->ID_NONE);
173 renderer->setTextureUnit(contextIdx, 5);
174 renderer->bindTexture(contextIdx, renderer->ID_NONE);
175 renderer->setTextureUnit(contextIdx, 6);
176 renderer->bindTexture(contextIdx, renderer->ID_NONE);
177 renderer->setTextureUnit(contextIdx, 7);
178 renderer->bindTexture(contextIdx, renderer->ID_NONE);
179
180 // unbind depth buffer texture
181 renderer->setTextureUnit(contextIdx, 8);
182 renderer->bindTexture(contextIdx, renderer->ID_NONE);
183
184 // switch back to diffuse texture unit
185 renderer->setTextureUnit(contextIdx, 0);
186
187 //
188 deferredLightingRenderShader->unUseProgram();
189
190 // unset
191 renderer->enableCulling(contextIdx);
192}
193
Engine main class.
Definition: Engine.h:122
static FrameBufferRenderShader * getFrameBufferRenderShader()
Definition: Engine.h:449
static STATIC_DLL_IMPEXT Renderer * renderer
Definition: Engine.h:184
static STATIC_DLL_IMPEXT Engine * instance
Definition: Engine.h:183
static DeferredLightingRenderShader * getDeferredLightingRenderShader()
Definition: Engine.h:456
Geometry buffer class.
void reshape(int32_t width, int32_t height)
Resize the geometry buffer.
void initialize()
Initialize the geometry buffer.
void renderToScreen(Engine *engine)
Render to screen or bound geometry buffer @engine engine.
void dispose()
Disposes this geometry buffer.
void enableGeometryBuffer()
Enables this geometry buffer to be rendered.
static void disableGeometryBuffer()
Switches back to non offscreen main frame buffer to be rendered.
virtual void resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height)=0
Resizes a depth texture.
virtual void setViewPort(int32_t width, int32_t height)=0
Set up viewport parameter.
virtual void updateViewPort()=0
Update viewport.
virtual int32_t createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)=0
Creates a depth buffer texture.
virtual int32_t createGBufferGeometryTexture(int32_t width, int32_t height)=0
Creates a geometry buffer geometry texture.
virtual void disposeTexture(int32_t textureId)=0
Dispose a texture.
virtual void resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height)=0
Resizes a geometry buffer geometry texture.
virtual void bindFrameBuffer(int32_t frameBufferId)=0
Enables a framebuffer to be rendered.
virtual void disposeFrameBufferObject(int32_t frameBufferId)=0
Disposes a frame buffer object.
virtual int32_t createGBufferColorTexture(int32_t width, int32_t height)=0
Creates a geometry buffer color RGBA texture.
virtual int32_t createGeometryBufferObject(int32_t depthBufferTextureId, int32_t geometryBufferTextureId1, int32_t geometryBufferTextureId2, int32_t geometryBufferTextureId3, int32_t colorBufferTextureId1, int32_t colorBufferTextureId2, int32_t colorBufferTextureId3, int32_t colorBufferTextureId4, int32_t colorBufferTextureId5)=0
Creates a geometry frame buffer object.
virtual void resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height)=0
Resizes a geometry buffer color RGBA texture.
Standard math functions.
Definition: Math.h:21
Console class.
Definition: Console.h:26
Float class.
Definition: Float.h:23