Convert GL_UNSIGNED_INT_24_8 packed depth stencil to float depth

Hello,

I want to get the depth values of the FBO’s depth-stencil texture attachment as float.

First I read the values with their original packed integer format (GL_UNSIGNED_INT_24_8):

unsigned int values[CubeMapSize];
glBindTexture(GL_TEXTURE_CUBE_MAP, CubeMapHandle);
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X /*reading one cube map side only*/, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, values);

Now I want to convert one value (here the first) to float-depth:

float depth = DoSomeConversion(values[0]);

Anybody knows how the correct conversion has to look like?
Maybe just take the upper or lower 24 bits and divide by 2^24 or something like that?

Help is really appreciated!

Upper 24 bits. And divide by 224-1. So:


float f = (i>>8)/16777215.0f;

or


float f = (i&~0xFFU)/4294967040.0f;

Thanks! The values look reasonable.