如何使用GL_RGB9_E5格式?

问题描述 投票:2回答:1

我正在尝试将GL_RGB9_E5格式与3D纹理结合使用。为此我创建了简单的测试来理解格式的用法。不知怎的,我没有得到我所期望的。以下是测试程序

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++;
        }

我所期待的是什么uColor.raw我放在t1我在t2回到相同的原始颜色。

我从底部的Specification for GL_RGB9_E5采取了float3_to_rgb9e5方法你可以找到代码。

如果有人可以给我一些如何正确使用它或正确的方法,那就太棒了。

c++ opengl opengl-es opengl-4
1个回答
6
投票
    GL_RGB,
    GL_UNSIGNED_INT,

这意味着您正在传递3通道像素数据,其中每个通道都是标准化的32位无符号整数。但那并不是你真正在做的事情。

你实际上传递了3个通道数据,它被打包成一个32位无符号整数,这样前5位表示一个浮点指数,后面跟着3组9位,每组表示一个浮点数的无符号尾数。 。我们拼写:

GL_RGB,
GL_UNSIGNED_INT_5_9_9_9_REV
© www.soinside.com 2019 - 2024. All rights reserved.