I'm doing 2-pass rendering, where for the first pass I'm rendering to a texture and for the second pass I'm rendering to the screen.
I'm rendering the same polygons in both passes, but I'm using different shaders. In particular, the second pass uses a shader that takes the texture generated by the first pass as a parameter.
Currently my first pass has a framebuffer with a texture for the color attachment and a renderbuffer for the depth attachment (stenciling is disabled), while the second pass renders to the default framebuffer (0).
It occurred to me that since I'm rendering exactly the same polygons in pass-2, the depth buffer will end up looking identical to my pass-1 depth buffer. If I could somehow have the pass-2 depth buffer start out initialized to pass-1's depth buffer, I could then change my depth test function to GL_LEQUAL and avoid a lot of unnecessary work for pass-2's fragment shader. Depth writes could also be disabled for this pass.
So... is there some way to do one of the following?
- create my own framebuffer that uses the screen's depth buffer (but still writes colors to a texture)
- attach my own renderbuffer to the default framebuffer's depth attachment
The only workaround I can think of (and I haven't tried this yet, so I have no idea what kind of effect this will have on performance) is to have the second pass also render to a texture, and then have a third pass that just "blits" the texture to the screen.