2
votes

Currently I am rendering some stuff to a FBO with an attached depth render buffer.

However, after I am done with the render buffer, the depth information is pretty much lost.

How can I copy the data from the render buffer to the fixed function depth buffer?

1

1 Answers

5
votes

You can use glBlitFramebuffer, enabling the GL_DEPTH_BUFFER_BIT flag.

Example code:

glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_id);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

glBlitFramebuffer(offset_x, offset_y, offset_x + size_x, offset_y + size_y,
                  offset_x, offset_y, offset_x + size_x, offset_y + size_y,
                  GL_DEPTH_BUFFER_BIT,
                  GL_NEAREST);

This will copy only the depth buffer.