6
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – JBeurer
    Mar 15, 2012 at 1:43
  • \$\begingroup\$ 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. \$\endgroup\$ Mar 16, 2012 at 0:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .