Reading back shadow-only FBO?

How can I read back values from an FBO that only has a depth attachment (with glDrawBuffer set to GL_NONE)?

It appears that a glReadBuffer of GL_DEPTH_ATTACHMENT_EXT is not legal. Nor does it work on my implementation. Do I have to attach a color renderbuffer just to get at the depth values?

Thanks.

Sorry. For apparently no reason at all other than a forced (Java) rebuild, it just started working with glReadBuffer set to GL_NONE. I’m still not sure if this is behavior I should rely on. Your thoughts appreciated.

FWIW, here are relevant code snips:


// init
shadowFrameBuffer = genFramebuffer(gl);
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, shadowFrameBuffer);
gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_TEXTURE_2D, shadowMapTexture.getTextureObject(), 0);
gl.glDrawBuffer(GL.GL_NONE);
gl.glReadBuffer(GL.GL_NONE);
if (gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT) != GL.GL_FRAMEBUFFER_COMPLETE_EXT) {
    fbosAvailable = false;
}
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);


// display
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, shadowFrameBuffer);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
drawScene(gl, angle);
// Optionally show the shadow buffer contants in grayscale.
if (showShadowBuffer) {
    // Blit the depth buffer values to the image as a luminance signal.
    gl.glReadPixels(0, 0, shadowMapWidth, shadowMapHeight, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, depthBuffer);
    gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
    gl.glWindowPos2f(0, 0);
    gl.glDrawPixels(shadowMapWidth, shadowMapHeight, GL.GL_LUMINANCE, GL.GL_FLOAT, depthBuffer);
    return;
}        
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);

AFAIK, You can attach the depth texture to the color channel - nothing stops you from doing that - and then read pixels.

Setting the ReadBuffer to GL_NONE, and then using GL_DEPTH_COMPONENT in the ReadPixels call works for me.

ReadPixels of GL_DEPTH_COMPONENT as GL_FLOAT definitely works on NVidia, without the need to mess with ReadBuffer.

Also I note that per the glReadBuffer man page, GL_NONE is not a valid option. Check for GL errors in your app (see this link).

Thanks. The glReadBuffer man page won’t have GL_NONE because the usage is defined in the FBO extension. With my NVidia Quadro FX 360M/PCI/SSE2, I need the call or else the readPixels doesn’t work at all.

No it is a valid option using a framebuffer object since it may not have a color buffer.

Gene78, note that since you are creating the depth buffer as a texture you may also get its data with glGetTexImage.

Thanks for the correction. My bad. Man page is out-of-date or at least incomplete.