Problems displaying the z-buffer

Started by
4 comments, last by Lutz 19 years, 8 months ago
Hey, I tried to display the z-buffer using

glCopyPixels(0,0,SCREEN_W,SCREEN_H,GL_DEPTH);
I've set up the raster position and zoom factor correctly. All it did display is a white rectangle (even when I cleared the z-buffer with 0.0f beforehand). Apart from that, it was terribly slow: 8FPS on a RadeOn 9800 Pro! As far as I understand, glCopyPixels should transfer the stuff on the GPU only, so it should be rather fast. Then I replaced glCopyPixels by

glReadPixels(0,0,SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);
glDrawPixels(SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);
and it worked. It displayed the z-buffer contents correctly, but it was even slower (since it has to transfer stuff from GPU to CPU and back). Any ideas why glCopyPixels doesn't give the expected results? I haven't changed any other settings like glPixelTransfer or things like that. And I'm quite sure that I've set up the modelview/projection matrices and the raster position and pixel zoom correctly.
Advertisement
Quote:Original post by Lutz
I tried to display the z-buffer using
glCopyPixels(0,0,SCREEN_W,SCREEN_H,GL_DEPTH);

I've set up the raster position and zoom factor correctly. All it did display is a white rectangle (even when I cleared the z-buffer with 0.0f beforehand).

What you're doing is rendering a rectangle using the current raster color and depth values taken from the depth buffer. If the current raster color is white, then the whole rectangle will be white.
I don't know if you can do what you want with glCopyPixels (at least not without an extension.)
I tried getting it to work with fog, but didn't succeed.

Quote:Apart from that, it was terribly slow: 8FPS on a RadeOn 9800 Pro! As far as I understand, glCopyPixels should transfer the stuff on the GPU only, so it should be rather fast.

glCopyPixels isn't exactly the fastest operation. Making sure that texturing, lighting etc. are disabled might make it a bit faster..

Quote:Then I replaced glCopyPixels by
glReadPixels(0,0,SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);glDrawPixels(SCREEN_W,SCREEN_H, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, buffer);

and it worked. It displayed the z-buffer contents correctly, but it was even slower (since it has to transfer stuff from GPU to CPU and back).

Any ideas why glCopyPixels doesn't give the expected results?

Yes, but I don't understand why the above worked [smile]
It shouldn't, unless you're doing something clever elsewhere in the code. glReadPixels/glDrawPixels with GL_DEPTH_COMPONENT shouldn't produce any better results than glCopyPixels with GL_DEPTH.
Now, if the format for glDrawPixels was something like GL_RED, then I'd understand. [smile]
you'd be much better off copying the data to a texture and then displaying a textured quad, its faster and works correctly
TomasH:

Thanks for the explanation, I think I understand now what's wrong. Since I have the code at home and not here, I've probably made a mistake: I've probably used
glDrawPixels(SCREEN_W,SCREEN_H, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);

instead of GL_DEPTH_COMPONENT.

_the_phantom_:
How?
Is there some fancy glCopyDepthToTexture?
Quote:Original post by Lutz
_the_phantom_:
How?
Is there some fancy glCopyDepthToTexture?


You can use glCopyTexImage2D with GL_DEPTH_COMPONENT as internalformat.The texture needs to be power of 2,though(I don't know if you can use the TEXTURE_RECTANGLE extension with DEPTH_COMPONENT).
Are you sure? GL_DEPTH_COMPONENT is not listed among the possible interal formats (at least not in the descriptions of glCopyTexImage2D that google finds).

EDIT: Oh no, I just found some pages. It seems to be an extension. I'll try. Thanks all!

This topic is closed to new replies.

Advertisement