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);
4

2 回答 2

2

既然您已经禁用了 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 上渲染为非二次幂纹理

于 2011-02-26T07:45:05.537 回答
1

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%.

于 2011-02-23T17:46:22.487 回答