CachedTexture * DepthBuffer::resolveDepthBufferTexture(FrameBuffer * _pBuffer) { #ifdef GL_MULTISAMPLING_SUPPORT if (config.video.multisampling == 0) return m_pDepthBufferTexture; if (m_resolved) return m_pResolveDepthBufferTexture; glScissor(0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight); glBindFramebuffer(GL_READ_FRAMEBUFFER, _pBuffer->m_FBO); glReadBuffer(GL_COLOR_ATTACHMENT0); GLuint attachment = GL_COLOR_ATTACHMENT0; glDrawBuffers(1, &attachment); assert(checkFBO()); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_resolveFBO); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_pResolveDepthBufferTexture->glName, 0); assert(checkFBO()); glBlitFramebuffer( 0, 0, m_pDepthBufferTexture->realWidth, m_pDepthBufferTexture->realHeight, 0, 0, m_pResolveDepthBufferTexture->realWidth, m_pResolveDepthBufferTexture->realHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST ); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _pBuffer->m_FBO); m_resolved = true; gDP.changed |= CHANGED_SCISSOR; return m_pResolveDepthBufferTexture; #else return m_pDepthBufferTexture; #endif }
void createFrameBuffer(FrameBuffer &fb, bool depth) { // Create the color render buffer glGenTextures(1, &fb.texture); glBindTexture(GL_TEXTURE_2D, fb.texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fb.bufferSize.x , fb.bufferSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); checkError("Creation of the color texture for the FBO"); // Create the depth render buffer if (depth) { glGenRenderbuffersEXT(1, &fb.depth); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fb.depth); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, fb.bufferSize.x, fb.bufferSize.y); checkError("Creation of the depth renderbuffer for the FBO"); } else { fb.depth = 0; } // Create the FBO glGenFramebuffersEXT(1, &fb.fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb.fbo); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fb.texture, 0); if (depth) { glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, fb.depth); } checkFBO(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); checkError("Creation of the FBO"); }
static void _initFBO(GLuint _FBO, CachedTexture * _pTexture) { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _FBO); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _pTexture->glName, 0); assert(checkFBO()); }
static GLuint _createFBO(CachedTexture * _pTexture) { GLuint FBO; glGenFramebuffers(1, &FBO); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FBO); glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _pTexture->glName, 0); assert(checkFBO()); return FBO; }
void VSMPerPixelRenderer::reshape(int w,int h) { DefaultRenderer::reshape(w,h); release(); for(int i=0; i<MAX_LIGHTS; i++) { genTexture(_tid[i],w,h,GL_DEPTH_COMPONENT,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE); genTexture(_ctid[i],w,h,GL_RGB32F_ARB,GL_RGB,GL_FLOAT,GL_LINEAR); //create a framebuffer object glGenFramebuffersEXT(1,&(_fboId[i])); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,_fboId[i]); //Instruct openGL that we won't bind a color texture with the currently binded FBO //glDrawBuffer(GL_NONE); //glReadBuffer(GL_NONE); //attach the texture to FBO depth attachment point glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,_tid[i],0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,_ctid[i],0); checkFBO(); //switch back to window-system-provided framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); } { genTexture(_ctTmp,w,h,GL_RGB32F_ARB,GL_RGB,GL_FLOAT,GL_LINEAR); //create a framebuffer object glGenFramebuffersEXT(1,&_fboTmp); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,_fboTmp); //Instruct openGL that we won't bind a color texture with the currently binded FBO //glDrawBuffer(GL_NONE); //glReadBuffer(GL_NONE); //attach the texture to FBO depth attachment point glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,_ctTmp,0); checkFBO(); //switch back to window-system-provided framebuffer glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); } _released=false; }
void FrameBufferObject::init(unsigned int width, unsigned height) { if (!initialized) { this->width = width; this->height = height; glGenFramebuffersEXT(1, &id); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, id); if(enableDepth) { createDepthBuffer(); initDepthBuffer(); //choice between rendering depth into a texture or a renderbuffer if(depthTexture) glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureID, 0); else glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthTextureID); } if(enableColor) { createColorBuffer(); initColorBuffer(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTextureID, 0); } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_defaultWindowFramebufferID); if(enableColor) { glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK);; } #ifdef _DEBUG checkFBO(); #endif initialized=true; glDisable(GL_TEXTURE_2D); } else setSize(width, height); }