Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Convert GL_UNSIGNED_INT_24_8 packed depth stencil to float depth

  1. #1
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    61

    Question 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):
    Code :
    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:
    Code :
    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!
    ++i--;

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,470
    Quote Originally Posted by RealtimeSlave View Post
    Maybe just take the upper or lower 24 bits and divide by 2^24 or something like that?
    Upper 24 bits. And divide by 224-1. So:
    Code :
    float f = (i>>8)/16777215.0f;
    or
    Code :
    float f = (i&~0xFFU)/4294967040.0f;

  3. #3
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    61
    Thanks! The values look reasonable.
    ++i--;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •