PDA

View Full Version : glReadPixels() with EXT_packed_depth_stencil



Schnulla
09-21-2009, 02:02 PM
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 :)

Dark Photon
09-21-2009, 06:19 PM
how can I get the float depth value from an active framebuffer object (FBO) that uses a
packed depth-stencil buffer?
Try this

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

Schnulla
09-22-2009, 04:53 AM
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 =/

arekkusu
09-22-2009, 04:03 PM
Reading depth from depth_stencil is supposed to work. If it doesn't, could be a driver bug.

Schnulla
09-22-2009, 04:35 PM
I just found out that it works with GL_DEPTH_COMPONENT
IF the FBO is not multisampled. Otherwise it does not.

Schnulla
09-27-2009, 03:44 AM
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."

Dark Photon
09-28-2009, 06:00 AM
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.