Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How to attach default depth buffer to FBO? How to use depth renderbuffer buffer attached to FBO (after drawing to it) as a default depth buffer?

Basically I want to use the same depth buffer for both the FBO and backbuffer rendering.

share|improve this question

1 Answer 1

You can't.

This is by design. OpenGL (and older versions of DirectX) were designed back in the days when windowed apps literally shared the same frame buffer. That meant that if you had two overlapped windows, the windows would be trying to use the exact same pixels from the color, depth, and stencil buffers. The windowing systems dealt with this via a hard-coded masking operation.

In other words, you do not own the default depth buffer, cannot change the default depth buffer, and cannot reliably read from the default depth buffer in the OpenGL API.

Your best bet is to just do all of your rendering in an FBO and then use a texture blit to get the final image into the default FBO.

share|improve this answer
    
What do you mean by reliably? In fact you can both read and write to default depth buffer using glReadPixels(format set to GL_DEPTH_COMPONENT) and glDrawPixels(format set to GL_DEPTH_COMPONTENT and calling glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) prior to that to indicate that we are not gonna change the color buffer). This however may not be the most effiecient and up-to-date of method of doing so. –  JBeurer Mar 15 '12 at 1:43
    
Not all of the default framebuffer may have valid data, due to the shared ownership and masking. On all modem compositing desktops it will just work, but the GL API neither requires or even expects it to. –  Sean Middleditch Mar 16 '12 at 0:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.