禁用 mipmap 时空白纹理?

发布于 2024-10-19 01:17:28 字数 744 浏览 7 评论 0原文

我没有掌握 OpenGL 的所有微妙之处,所以很抱歉,如果我的问题不够精确,

在 iPhone 上,我加载一个像这样的纹理(png 图像),

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTextureSize.width, iTextureSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_FILTER, GL_NEAREST);

效果很好,但我注意到这分配的大小恰好是纹理数据大小的两倍。 我在论坛上读到这可能是由 mipmaping 引起的,所以我尝试通过以下方式将其关闭 评论 glTexParameteri 行,但我的纹理是空白的。

我的显示代码中的纹理加载参数是否有问题? 我的显示代码是这样的

glTexCoordPointer(2, GL_FLOAT, 0, texture);
glVertexPointer(DIMENSION,  GL_SHORT,  0, iVertex);
glBindTexture(GL_TEXTURE_2D, (GLuint)textureID);
glDrawArrays(GL_TRIANGLE_FAN,  0, iVertexCount);

I do not master all the subtlety of OpenGL so sorry if my question is not precise enough

On iPhone I load a texture (png image) like this

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTextureSize.width, iTextureSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_FILTER, GL_NEAREST);

Which works well but I noticed that this allocate exactly twice the size of textureData.
I've read in forums that this could be caused by mipmaping so I tried to turn it off by
commenting the glTexParameteri lines but then my textures is blank.

Is this a problem is my texture loading parameter on in my display code ?
My display code is like this

glTexCoordPointer(2, GL_FLOAT, 0, texture);
glVertexPointer(DIMENSION,  GL_SHORT,  0, iVertex);
glBindTexture(GL_TEXTURE_2D, (GLuint)textureID);
glDrawArrays(GL_TRIANGLE_FAN,  0, iVertexCount);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萝莉病 2024-10-26 01:17:28

现在您已经禁用了 mipmap,您是否尝试过禁用纹理重复?

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

如果您的纹理宽度或高度不是 2 的幂,您就会陷入“非 2 幂纹理”(NPOT),这在 iPhone 上的处理有限制,请参阅:

在 iPhone 上渲染为非二次方纹理

Now that you have mipmaps disabled alright, have you tried to disable the texture repeat ?

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

If your texture width or height is a value that is not a power of two, you fall into the 'non-power-of-two texture' (NPOT), which is handled with limitations on iPhone, see :

Rendering to non-power-of-two texture on iPhone

如若梦似彩虹 2024-10-26 01:17:28

注释掉两条纹理参数行可启用 MIP 映射。由于您只上传一层纹理,因此所有其他层都是空白的。这就是为什么您随后看不到任何东西。

您通过什么方式得出结论,导致分配了两倍大小的纹理数据,以及如何得出这是一个错误的结论? GL 驱动程序如何在内部分配内存以及在何处缓存所需内容取决于 GL 驱动程序。没有理由认为 double 是不正确的,特别是当您将视频 RAM 添加到主 RAM 时。

此外,存储 MIP 贴图会增加总体存储需求的三分之一,而不是 100%。

Commenting out the two texture parameter lines enables MIP mapping. Since you upload only one level of texture, all the other levels are blank. That's why you subsequently don't see anything.

By what means are you concluding that you're causing twice the size of textureData to be allocated and how do you reach the conclusion that this is an error? It's up to the GL driver how it allocates memory internally and where it caches what it wants. There's no reason to assume that double is incorrect, especially if you're adding video RAM to main RAM.

Furthermore, storing MIP maps adds one third to your overall storage requirements, not 100%.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文