glReadPixels() with EXT_packed_depth_stencil

Hello,

how can I get the float depth value from an
active framebuffer object (FBO) that uses a
packed depth-stencil buffer?

unsigned int DepthBufferZi;
glReadPixels(x, y, 1, 1, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, &DepthBufferZi);

But I don’t know how to extract the depth part as float,
tried logical AND with shifting but nothing worked.

The OpenGL registry says:
glReadPixels of GL_DEPTH_STENCIL_EXT data reads back a rectangle from both the depth and stencil buffers.

Still don’t know how to do it.

Please help! Thanks :slight_smile:

Try this

glReadPixels( x, y, w, h, GL_DEPTH_COMPONENT, GL_FLOAT, buf );

That was exactly how I did it in the past on my main window
depth buffer. With my FBO as rendertarget it does not seem
to work. I guess GL_DEPTH_STENCIL_EXT in combination with
GL_UNSIGNED_INT_24_8_EXT is the only way to use glReadPixels
with a packed depth-stencil buffer. But I’m not sure,
I only know GL_DEPTH_COMPONENT + GL_FLOAT are not doing
their job anymore =/

Reading depth from depth_stencil is supposed to work. If it doesn’t, could be a driver bug.

I just found out that it works with GL_DEPTH_COMPONENT
IF the FBO is not multisampled. Otherwise it does not.

I guess I found the reason why glReadPixels is not
working for Multisampled framebuffers:

http://www.opengl.org/registry/specs/EXT/framebuffer_multisample.txt

…says: “Note that ReadPixels and CopyPixels are disallowed when the read framebuffer is multisample.”

Good find. Thanks for letting us know. Hadn’t ever gone looking for that before. I guess the vendors have special paths in there for multisample system FB that aren’t necessarily replicated for off-screen FBOs.