2

I am trying to use GL_RGB9_E5 format with 3D texture. For this I have created simple test to understand the usage of format. Somehow I am not getting what I expect. Following is test program

GLuint texture;
const unsigned int depth = 1;
const unsigned int width = 7;
const unsigned int height = 3;

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
const float color[3] = { 0.0f, 0.5f, 0.0f };
const rgb9e5 uColor = float3_to_rgb9e5(color);

GLuint * t1 = (GLuint*)malloc(width*height*depth* sizeof(GLuint));
GLuint * t2 = (GLuint*)malloc(width*height*depth* sizeof(GLuint));
int index = 0;
for (int i = 0; i < depth; i++)
    for (int j = 0; j < width; j++)
        for (int k = 0; k < height; k++)
        {
            t1[index] = uColor.raw;
            index++;
        }

glTexImage3D(GL_TEXTURE_3D, 0,
    GL_RGB9_E5,
    width, height, depth, 0,
    GL_RGB,
    GL_UNSIGNED_INT,
    (void*)t1);

glGetTexImage(GL_TEXTURE_3D, 0, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, t2);

index = 0;
for (int i = 0; i < depth; i++)
    for (int j = 0; j < width; j++)
        for (int k = 0; k < height; k++)
        {
            rgb9e5 t;
            t.raw = t2[index];
            index++;
        }

What I am expecting is what ever uColor.raw I am putting in t1 I get back same raw color in t2 .

I have taken float3_to_rgb9e5 method from Specification for GL_RGB9_E5 at bottom you can find code.

It would be great If someone can give me example for how to use it correctly or correct way of doing it.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174

1 Answers1

7
    GL_RGB,
    GL_UNSIGNED_INT,

This means that you are passing 3-channel pixel data, where each channel is a normalized, 32-bit unsigned integer. But that's not what you're actually doing.

You're actually passing 3 channel data, which is packed into a 32-bit unsigned integer, such that the first 5 bits represent a floating-point exponent, followed by 3 sets of 9-bits, each representing the unsigned mantissa of a float. We spell that:

GL_RGB,
GL_UNSIGNED_INT_5_9_9_9_REV
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982