如何使用GL_RGB9_E5格式?
how to use GL_RGB9_E5 format?
我正在尝试使用具有 3D 纹理的 GL_RGB9_E5 格式。为此,我创建了简单的测试来了解格式的用法。不知何故,我没有得到我所期望的。以下是测试程序
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 .
我采用了float3_to_rgb9e5的方法Specification for GL_RGB9_E5
在底部你可以找到代码。
如果有人能给我举例说明如何正确使用它或正确的方法,那就太好了。
GL_RGB,
GL_UNSIGNED_INT,
这意味着您要传递 3 通道像素数据,其中每个通道都是标准化的 32 位无符号整数。但这不是你实际在做的。
你实际上传递的是 3 通道数据,它被打包成一个 32 位无符号整数,这样前 5 位代表一个浮点指数,后面是 3 组 9 位,每组代表浮点数的无符号尾数。我们拼写:
GL_RGB,
GL_UNSIGNED_INT_5_9_9_9_REV
我正在尝试使用具有 3D 纹理的 GL_RGB9_E5 格式。为此,我创建了简单的测试来了解格式的用法。不知何故,我没有得到我所期望的。以下是测试程序
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 .
我采用了float3_to_rgb9e5的方法Specification for GL_RGB9_E5 在底部你可以找到代码。
如果有人能给我举例说明如何正确使用它或正确的方法,那就太好了。
GL_RGB, GL_UNSIGNED_INT,
这意味着您要传递 3 通道像素数据,其中每个通道都是标准化的 32 位无符号整数。但这不是你实际在做的。
你实际上传递的是 3 通道数据,它被打包成一个 32 位无符号整数,这样前 5 位代表一个浮点指数,后面是 3 组 9 位,每组代表浮点数的无符号尾数。我们拼写:
GL_RGB,
GL_UNSIGNED_INT_5_9_9_9_REV