A limitation of FBOs is that you can’t share buffers between FBO and onscreen buffers. With color data this is no problem, because I can just draw a textured quad and I have my copy in the other buffer.
But what if I need the same depth data in my onscreen and offscreen buffers? For example when doing deferred shading I’d like to have the depth buffer that’s produced in the initial pass to be copied into the framebuffer to help with culling of light source fragments…
I can only think of three solutions to this problem:
- use two depth only passes, one for each buffer
- render the depth only pass on screen and use a texture instead of a renderbuffer, then copy the data with glCopyTexSubImage
- render the depth only pass to a texture and use a quad with a simple depth replacing fragment program to fill the default depth buffer and/or the renderbuffer
I’d like to avoid solution 1, this would mean an additional geometry pass, and that’s somehow defeating the idea of deferred shading…
Solution 2 has the problem that I’d have to use a depth texture instead of a depth renderbuffer for all my FBO rendering. Someone mentioned in another thread that this may slow rendering down.
And finally solution 3 uses depth replace, and AFAIK using depth replace deactivates early Z not only as long as the shader is active but until the next buffer swap, so performance is even worse than solution 2…
Does anyone have a better idea?