如何使用GL_RGB9_E5格式?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用GL_RGB9_E5格式?相关的知识,希望对你有一定的参考价值。
我正在尝试将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方法你可以找到代码。
如果有人可以给我一些如何正确使用它或正确的方法,那就太棒了。
答案
GL_RGB, GL_UNSIGNED_INT,
这意味着您正在传递3通道像素数据,其中每个通道都是标准化的32位无符号整数。但那并不是你真正在做的事情。
你实际上传递了3个通道数据,它被打包成一个32位无符号整数,这样前5位表示一个浮点指数,后面跟着3组9位,每组表示一个浮点数的无符号尾数。 。我们拼写:
GL_RGB,
GL_UNSIGNED_INT_5_9_9_9_REV
以上是关于如何使用GL_RGB9_E5格式?的主要内容,如果未能解决你的问题,请参考以下文章
在 glCopyTexImage1D() OpenGL 3.3 中使用 GL_RGB10_A2UI 内部格式
我应该使用哪种 OpenGL ES 纹理格式来在 iPad 上获得更好的动态范围?
如何在 Javadoc 中使用 @ 和 符号格式化代码片段?