Par*_*rni 2 c++ opengl opengl-es opengl-4
我正在尝试将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++;
}
Run Code Online (Sandbox Code Playgroud)
我所期待是什么都uColor.raw我在我把T1,我回去相同的原始颜色T2。
我从 底部的GL_RGB9_E5规范中获取了float3_to_rgb9e5方法,您可以在其中找到代码。
如果有人可以给我提供有关如何正确使用它或正确使用方法的示例,那就太好了。
Run Code Online (Sandbox Code Playgroud)GL_RGB, GL_UNSIGNED_INT,
这意味着您正在传递3通道像素数据,其中每个通道都是标准化的32位无符号整数。但这不是您真正在做什么。
实际上,您正在传递3通道数据,该数据打包成一个32位无符号整数,因此前5位代表浮点指数,其后是3组9位,每组代表浮点数的无尾数。我们将其拼写为:
GL_RGB,
GL_UNSIGNED_INT_5_9_9_9_REV
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
105 次 |
| 最近记录: |