PDA

View Full Version : Problem keeping depth-buffer in FBO



Ilian Dinev
06-24-2008, 11:30 PM
I have a FBO with 3 attached RGBA8 textures, and depth-buffer created as a texture or as a Renderbuffer (switching between either doesn't matter for the problem).
Here's pseudo-code for my frame-rendering:



static int PingPong=0;

PingPong ^=1;

frameBuf->enter()

//-----[ draw scene into targetID=PingPong ]------[
int bufs[1];
bufs[0]=FBO_AttColorTex[PingPong];
glDrawBuffers(1,bufs);
glClear(GL_DEPTH_BUFFER_BIT);

DrawScene();
//------------------------------------------------/

//---[ draw scene with one override-shader ]---[
// transforms are the same!
SetOverrideShader("override1");
glDepthMask(false); // makes no output-image difference
glClear(GL_DEPTH_BUFFER_BIT); // **** THIS causes Z-fighting if removed

DrawScene();
//---------------------------------------------/
frameBuf->leave();

int tex0 = FBO_AttColorTex[2];
int tex1 = FBO_AttColorTex[PingPong]; // "current frame"
int tex2 = FBO_AttColorTex[PingPong^1]; // "previous frame"
DrawFullscreenQuadPostProcess(tex0,tex1,tex2); // depth test disabled only while drawing the quad

I would simply like to make use of early-Z culling. The funny thing is that if I remove the first glClear(), and rest the camera/objects, there is no Z-fighting (the depth-buffer, computed on the second pass, stays). I'm not disabling gl_depth_test in pass#1 .
Is there something I'm overlooking, if the different functions I've coded (like frameBuf->enter) are ok?