PDA

View Full Version : Getting depth texture pixels



Arkion
10-11-2005, 09:44 AM
Hi all

I need to get pixels of a 2D depth texture, ie. the format is GL_DEPTH_COMPONENT. glGetTexImage doesn't seem to work with depth textures - I've tried setting the format parameter both to GL_RGB and DEPTH_COMPONENT, but neither one returns anything meaningful to the buffer.


glBindTexture(GL_TEXTURE_2D, shadowMapID);
byte *buffer = new byte[512*512*3];
glGetTexImage(GL_TEXTURE_2D,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
buffer);The texture itself is working - if I render a textured quad the texture appears okay. I have ATI Radeon 9700 with Catalyst 5.9 drivers.

sqrt[-1]
10-11-2005, 10:56 PM
It could just be that the ATI drivers are broken, but in my experience reading back depth buffers in bytes is that most of the time you get close to black or close to white. (This is correct as it is just how the floats are mapped). What exactly are you getting?

You could also try my tool on your app and do a XML screen grab which will dump all active textures used in the frame. Then compare what it dumped for the depth texture as opposed to what you got.

Get it here: http://glintercept.nutty.org/

Arkion
10-14-2005, 07:00 AM
If I pass GL_DEPTH_COMPONENT for glGetTexImage format parameter, then I don't get anything at all -buffer is left unmodified.

Passing GL_RGB format returns just alternating stripes of one and zero bytes (eg. some hundred 0x01, followed by some hundred 0x00 bytes, and this keeps repeating for the rest of the buffer).

No matter what I pass for the format parameter, glGetError seems to return GL_INVALID_VALUE error each time.

I suspect that the problem lies with the translation from depth values to RGB values?

sqrt[-1]
10-14-2005, 01:17 PM
You have to pass GL_DEPTH_COMPONENT for depth textures according to the ARB depth texture spec:

INVALID_OPERATION is generated if GetTexImage parameter <format>
is one of RED, GREEN, BLUE, ALPHA, RGB, RGBA, BGR, BGRA, LUMINANCE,
or LUMINANCE_ALPHA but the internal format of the texture level
image is not a color format.

INVALID_OPERATION is generated if GetTexImage parameter <format>
is DEPTH_COMPONENT but the internal format of the texture level
image is not a depth format.