View Full Version : Render FBO to screen taking into account Depth

01-30-2017, 07:14 AM
Target: OpenGL ES 3.0

Suppose my default Framebuffer (the screen) already contains part of my scene rendered; its color and depth buffers contain valid data.

Now suppose I have another part of the scene rendered to an intermediate FBO 'fbo' already. Its color data is kept in texture 'mColor', which is attached to fbo.COLOR0 attachment, and its depth is kept in another texture 'mDepth', which is attached to fbo.DEPTH attachment.

Now I would like to take mColor and render it to the Screen, with DEPTH test enabled and taking into account the depth from the 'mDepth' texture.

Essentially it looks like when we render the Quad textured with mColor to the screen, we need to compare the Screen's depth buffer not with the depth computed from linearily interpolating the 4 verticaes of the Quad, but with depth from the 'mDepth' texture.

How to do that?

01-30-2017, 08:57 AM
Search for "depth sprite".