21FrameBuffer::FrameBuffer(int32_t width, int32_t height, int32_t buffers, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
41 auto rendererCubeMapTextureIndex = -1;
110 renderer->disableCulling(contextIdx);
114 renderer->clear(renderer->CLEAR_COLOR_BUFFER_BIT | renderer->CLEAR_DEPTH_BUFFER_BIT);
118 frameBufferRenderShader->useProgram();
121 renderer->setTextureUnit(contextIdx, 0);
125 renderer->setTextureUnit(contextIdx, 1);
129 renderer->bindVerticesBufferObject(contextIdx, frameBufferRenderShader->getVBOVertices());
130 renderer->bindTextureCoordinatesBufferObject(contextIdx, frameBufferRenderShader->getVBOTextureCoordinates());
133 renderer->drawTrianglesFromBufferObjects(contextIdx, 2, 0);
136 renderer->unbindBufferObjects(contextIdx);
139 renderer->setTextureUnit(contextIdx, 0);
140 renderer->bindTexture(contextIdx, renderer->ID_NONE);
143 renderer->setTextureUnit(contextIdx, 1);
144 renderer->bindTexture(contextIdx, renderer->ID_NONE);
147 renderer->setTextureUnit(contextIdx, 0);
150 frameBufferRenderShader->unUseProgram();
153 renderer->enableCulling(contextIdx);
158 if (target !=
nullptr) {
168 if (blendToSource !=
nullptr) {
171 renderer->enableAdditionBlending();
172 renderer->disableDepthBufferTest();
176 renderer->clear(renderer->CLEAR_COLOR_BUFFER_BIT | renderer->CLEAR_DEPTH_BUFFER_BIT);
180 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
183 renderer->disableCulling(contextIdx);
195 postProcessingShader->setShader(contextIdx, shaderId);
196 postProcessingShader->setBufferPixelWidth(contextIdx, 1.0f /
static_cast<float>(source->
getWidth()));
197 postProcessingShader->setBufferPixelHeight(contextIdx, 1.0f /
static_cast<float>(source->
getHeight()));
198 postProcessingShader->setShaderParameters(contextIdx, engine);
201 renderer->setTextureUnit(contextIdx, 0);
205 renderer->setTextureUnit(contextIdx, 1);
209 if (temporary !=
nullptr) {
210 renderer->setTextureUnit(contextIdx, 2);
213 renderer->setTextureUnit(contextIdx, 3);
218 renderer->bindVerticesBufferObject(contextIdx, frameBufferRenderShader->getVBOVertices());
219 renderer->bindTextureCoordinatesBufferObject(contextIdx, frameBufferRenderShader->getVBOTextureCoordinates());
222 renderer->drawTrianglesFromBufferObjects(contextIdx, 2, 0);
225 renderer->unbindBufferObjects(contextIdx);
228 renderer->setTextureUnit(contextIdx, 0);
229 renderer->bindTexture(contextIdx, renderer->ID_NONE);
232 renderer->setTextureUnit(contextIdx, 1);
233 renderer->bindTexture(contextIdx, renderer->ID_NONE);
236 if (temporary !=
nullptr) {
237 renderer->setTextureUnit(contextIdx, 2);
238 renderer->bindTexture(contextIdx, renderer->ID_NONE);
240 renderer->setTextureUnit(contextIdx, 3);
241 renderer->bindTexture(contextIdx, renderer->ID_NONE);
245 renderer->setTextureUnit(contextIdx, 0);
248 postProcessingShader->unUseProgram();
251 renderer->enableCulling(contextIdx);
254 if (blendToSource !=
nullptr) {
255 renderer->disableBlending();
256 renderer->enableDepthBufferTest();
260 if (target !=
nullptr) {
static FrameBufferRenderShader * getFrameBufferRenderShader()
static STATIC_DLL_IMPEXT Renderer * renderer
static STATIC_DLL_IMPEXT Engine * instance
static PostProcessingShader * getPostProcessingShader()
static Engine * getInstance()
Returns engine instance.
int32_t getScaledHeight()
void bindColorBufferTexture(int contextIdx)
Bind color texture.
static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Z
void reshape(int32_t width, int32_t height)
Resize the frame buffer.
void renderToScreen(Engine *engine, int32_t depthBufferTextureId, int32_t colorBufferTextureId)
Render given depth texture and color buffer texture to screen @parma engine engine.
void initialize()
Initialize the frame buffer.
static constexpr int32_t CUBEMAPTEXTUREID_NONE
static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_X
int32_t colorBufferTextureId
static void disableFrameBuffer()
Switches back to non offscreen main frame buffer to be rendered.
void enableFrameBuffer()
Enables this frame buffer to be rendered.
static constexpr int32_t FRAMEBUFFER_COLORBUFFER
static constexpr int32_t CUBEMAPTEXTUREINDEX_NONE
static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_X
static void doPostProcessing(Engine *engine, FrameBuffer *target, FrameBuffer *source, const string &programId, const string &shaderId, FrameBuffer *temporary=nullptr, FrameBuffer *blendToSource=nullptr)
Do post processing into target frame buffer (which can be screen as well when passing nullptr)
static constexpr int32_t FRAMEBUFFER_DEPTHBUFFER
void dispose()
Disposes this frame buffer.
static constexpr int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Y
static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Y
static constexpr int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Z
int32_t cubeMapTextureIndex
int32_t depthBufferTextureId
void bindDepthBufferTexture(int contextIdx)
Bind depth texture.
Frame buffer render shader.
void useProgram()
Use program.
virtual void resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height)=0
Resizes a depth texture.
int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Z
virtual void setViewPort(int32_t width, int32_t height)=0
Set up viewport parameter.
virtual void resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height)=0
Resize color buffer texture.
virtual int32_t createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)=0
Creates a color buffer texture.
int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_X
int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Y
virtual void updateViewPort()=0
Update viewport.
int32_t CUBEMAPTEXTUREINDEX_NEGATIVE_Y
virtual int32_t createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId=0, int32_t cubeMapTextureIndex=0)=0
Creates a frame buffer object with depth texture attached.
virtual void bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
virtual int32_t createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)=0
Creates a depth buffer texture.
virtual void disposeTexture(int32_t textureId)=0
Dispose a 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.
int32_t CUBEMAPTEXTUREINDEX_POSITIVE_Z
int32_t CONTEXTINDEX_DEFAULT
int32_t CUBEMAPTEXTUREINDEX_POSITIVE_X