void FBO_Shadow::start_frame() { //Binds the shadow framebuffer, and then clear the buffer bind_fbo(); glClear(GL_DEPTH_BUFFER_BIT); }
void FBO_Shadow::bind_for_spot_shadow_pass() { bind_fbo(); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_spot_texture, 0); //Draw only depth glDrawBuffer(GL_NONE); }
void FBO_Deferred::start_frame() { //Binds the custom framebuffer, and then clear the previous final_texture bind_fbo(); glDrawBuffer(GL_COLOR_ATTACHMENT4); glClear(GL_COLOR_BUFFER_BIT); }
void FBO_Deferred::bind_for_stencil_pass() { bind_fbo(); //Disable all draw buffers, cause it just wants to get depth and stencil. //Without this, the drawing would override geometry pass (because the fbo is the same) glDrawBuffer(GL_NONE); }
void FBO_Shadow::bind_for_point_shadow_pass() { bind_fbo(); //Bind all cubemap, the geometry shader will take care of the faces glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_point_cube, 0); glDrawBuffer(GL_NONE); }
void FBO_Deferred::bind_for_light_pass() { bind_fbo(); //Draw in the final_texture of fbo, not yet in the screen buffer glDrawBuffer(GL_COLOR_ATTACHMENT4); }
void ColorBuffer::readback(unsigned char* img) { FrameBuffer *fb = FrameBuffer::getFB(); if (fb->bind_locked()) { if (bind_fbo()) { s_gl.glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, img); } fb->unbind_locked(); } }
void FBO_Deferred::bind_for_geometry_pass() { //Binds custom buffer, specify draw buffers, and set them to draw bind_fbo(); GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; glDrawBuffers(FRAME_NUM_TEXTURES, DrawBuffers); }
bool ColorBuffer::blitFromPbuffer(EGLSurface p_pbufSurface) { FrameBuffer *fb = FrameBuffer::getFB(); if (!fb->bind_locked()) return false; // // bind FBO object which has this colorbuffer as render target // if (!bind_fbo()) { fb->unbind_locked(); return false; } // // bind the pbuffer to a temporary texture object // GLuint tempTex; s_gl.glGenTextures(1, &tempTex); s_gl.glBindTexture(GL_TEXTURE_2D, tempTex); if (!s_egl.eglBindTexImage(fb->getDisplay(), p_pbufSurface, EGL_BACK_BUFFER)) { printf("eglBindTexImage failed 0x%x\n", s_egl.eglGetError()); s_gl.glDeleteTextures(1, &tempTex); fb->unbind_locked(); return false; } s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); s_gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); s_gl.glEnable(GL_TEXTURE_2D); drawTexQuad(); // // unbind FBO, release the pbuffer and delete the temp texture object // s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); s_egl.eglReleaseTexImage(fb->getDisplay(), p_pbufSurface, EGL_BACK_BUFFER); s_gl.glDeleteTextures(1, &tempTex); fb->unbind_locked(); return true; }
bool ColorBuffer::blitFromCurrentReadBuffer() { RenderThreadInfo *tInfo = getRenderThreadInfo(); if (!tInfo->currContext.Ptr()) { // no Current context return false; } // // Create a temporary texture inside the current context // from the blit_texture EGLImage and copy the pixels // from the current read buffer to that texture // GLuint tmpTex; GLint currTexBind; if (tInfo->currContext->isGL2()) { s_gl2.glGetIntegerv(GL_TEXTURE_BINDING_2D, &currTexBind); s_gl2.glGenTextures(1,&tmpTex); s_gl2.glBindTexture(GL_TEXTURE_2D, tmpTex); s_gl2.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_blitEGLImage); s_gl2.glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, 0, 0, m_width, m_height, 0); } else { s_gl.glGetIntegerv(GL_TEXTURE_BINDING_2D, &currTexBind); s_gl.glGenTextures(1,&tmpTex); s_gl.glBindTexture(GL_TEXTURE_2D, tmpTex); s_gl.glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_blitEGLImage); s_gl.glCopyTexImage2D(GL_TEXTURE_2D, 0, m_internalFormat, 0, 0, m_width, m_height, 0); } // // Now bind the frame buffer context and blit from // m_blitTex into m_tex // FrameBuffer *fb = FrameBuffer::getFB(); if (fb->bind_locked()) { // // bind FBO object which has this colorbuffer as render target // if (bind_fbo()) { // // save current viewport and match it to the current // colorbuffer size // GLint vport[4]; s_gl.glGetIntegerv(GL_VIEWPORT, vport); s_gl.glViewport(0, 0, m_width, m_height); // render m_blitTex s_gl.glBindTexture(GL_TEXTURE_2D, m_blitTex); s_gl.glEnable(GL_TEXTURE_2D); s_gl.glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); drawTexQuad(); // this will render the texture flipped // unbind the fbo s_gl.glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); // restrore previous viewport s_gl.glViewport(vport[0], vport[1], vport[2], vport[3]); } // unbind from the FrameBuffer context fb->unbind_locked(); } // // delete the temporary texture and restore the texture binding // inside the current context // if (tInfo->currContext->isGL2()) { s_gl2.glDeleteTextures(1, &tmpTex); s_gl2.glBindTexture(GL_TEXTURE_2D, currTexBind); } else { s_gl.glDeleteTextures(1, &tmpTex); s_gl.glBindTexture(GL_TEXTURE_2D, currTexBind); } return true; }
void FBO_Deferred::bind_for_GUI_pass() { bind_fbo(); glDrawBuffer(GL_COLOR_ATTACHMENT4); }