PDA

View Full Version : Reading depth buffer with glReadPixels



tksuoran
11-01-2010, 03:57 PM
Is there a portable way to read depth buffer values with glReadPixels()?

I have tried the following (using OpenTK bindings)

GL.ReadPixels<uint>(px, py, 1, 1, PixelFormat.DepthComponent, PixelType.UnsignedInt, depthsi);
GL.ReadPixels<float>(px, py, 1, 1, PixelFormat.DepthComponent, PixelType.Float, depthsf);

Both of these work on NVidia. Unfortunately on AMD the first one only gives me 0 and the second gives me INVALID_OPERATION. Querying the framebuffer attachment says the depth attachment has float component type.

tksuoran
11-05-2010, 02:21 AM
I have converted my app to read ID from the ID*buffer framebuffer color attachment and depth from the default back framebuffer. This works. So it appears on AMD reading depth from non-default framebuffer is not supported at least on my framebuffer configuration - or I*am doing something else wrong..

skynet
11-05-2010, 01:33 PM
Is your FBO multisampled? It is not allowed to call glReadPixels on a multisampled buffer.

tksuoran
11-11-2010, 02:28 AM
No, it was not multisampled. This would not have a good idea anyway, since this was for picking, like color picking, although I*had a unsigned int red component renderbuffer attached to color.

One day I decided I also want to support 2.1 so I removed the use of FBO and integer/red buffer. Converting picking to use just the normal RGB color back buffer was pretty simple after all and it works just as good.