PDA

View Full Version : Reading back shadow-only FBO?



Gene78
07-06-2009, 06:40 AM
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.

Gene78
07-06-2009, 07:32 AM
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);

DmitryM
07-07-2009, 09:52 AM
AFAIK, You can attach the depth texture to the color channel - nothing stops you from doing that - and then read pixels.

MalcolmB
07-07-2009, 10:01 AM
Setting the ReadBuffer to GL_NONE, and then using GL_DEPTH_COMPONENT in the ReadPixels call works for me.

Dark Photon
07-08-2009, 05:08 AM
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 (http://www.opengl.org/sdk/docs/man/xhtml/glReadBuffer.xml), GL_NONE is not a valid option. Check for GL errors in your app (see this link (http://www.opengl.org/wiki/FAQ#glGetError_.28or_.22How_do_I_check_for_GL_erro rs.3F.29)).

Gene78
07-08-2009, 11:25 AM
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.

dletozeun
07-08-2009, 01:41 PM
Also I note that per the glReadBuffer man page (http://www.opengl.org/sdk/docs/man/xhtml/glReadBuffer.xml), GL_NONE is not a valid option. Check for GL errors in your app (see this link (http://www.opengl.org/wiki/FAQ#glGetError_.28or_.22How_do_I_check_for_GL_erro rs.3F.29)).


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.

Dark Photon
07-09-2009, 05:26 AM
Thanks. The glReadBuffer man page won't have GL_NONE because the usage is defined in the FBO extension.
Thanks for the correction. My bad. Man page is out-of-date or at least incomplete.