对于某些纹理尺寸,glFramebufferTexture2D 在 iPhone 上失败
当我尝试将纹理附加到帧缓冲区时,glCheckFramebufferStatus 报告某些纹理大小的 GL_FRAMEBUFFER_UNSUPPORTED。我已经在第二代和第四代 iPod Touch 上进行了测试。两个模型之间失败的纹理尺寸并不相同。
以下是一些有趣的结果:
第二代 - 8x8 失败,16x8 失败,但 8x16 成功!
第四代——8x8成功,8x16成功,但16x8失败!
下面是我用来测试附加不同尺寸的纹理的一些代码:
void TestFBOTextureSize(int width, int height)
{
GLuint framebuffer, texture;
// Create framebuffer
glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
// Create texture
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D,0);
// Attach texture to framebuffer
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0);
GLenum error = glGetError();
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
if (status==GL_FRAMEBUFFER_COMPLETE_OES)
NSLog(@"%dx%d Succeeded!",width,height,status);
else
NSLog(@"%dx%d Failed: %x %x %d %d",width,height,status,error,texture,framebuffer);
// Cleanup
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, 0, 0);
glDeleteTextures(1, &texture);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
glDeleteFramebuffersOES(1, &framebuffer);
}
void TestFBOTextureSizes()
{
int width,height;
for (width=1; width<=1024; width<<=1)
{
for (height=1; height<=1024; height<<=1)
TestFBOTextureSize(width,height);
}
}
似乎只要两个尺寸至少为 16 像素,那么一切都可以在两个设备上正常工作。但令我困扰的是,我还没有看到任何关于附加到帧缓冲区对象的纹理大小要求的文章。目前,一种解决方案是将我的纹理大小限制为至少 16 像素,但这可能会在将来被破坏,或者已经在我尚未尝试过的某些设备上被破坏?我还可以在启动时执行此测试代码,以便动态找出允许的纹理大小,但这似乎有点做作。
When I try to attach a texture to a framebuffer, glCheckFramebufferStatus reports GL_FRAMEBUFFER_UNSUPPORTED for certain texture sizes. I've tested on both a 2nd and 4th generation iPod Touch. The sizes of texture that fail are not identical between the two models.
Here are some interesting results:
2nd generation - 8x8 failed, 16x8 failed, but 8x16 succeeded!
4th generation - 8x8 succeeded, 8x16 succeeded, but 16x8 failed!
Here's some code I used to test attaching textures of different sizes:
void TestFBOTextureSize(int width, int height)
{
GLuint framebuffer, texture;
// Create framebuffer
glGenFramebuffersOES(1, &framebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
// Create texture
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D,0);
// Attach texture to framebuffer
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0);
GLenum error = glGetError();
GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
if (status==GL_FRAMEBUFFER_COMPLETE_OES)
NSLog(@"%dx%d Succeeded!",width,height,status);
else
NSLog(@"%dx%d Failed: %x %x %d %d",width,height,status,error,texture,framebuffer);
// Cleanup
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, 0, 0);
glDeleteTextures(1, &texture);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
glDeleteFramebuffersOES(1, &framebuffer);
}
void TestFBOTextureSizes()
{
int width,height;
for (width=1; width<=1024; width<<=1)
{
for (height=1; height<=1024; height<<=1)
TestFBOTextureSize(width,height);
}
}
It seems that as long as both dimensions are at least 16 pixels then everything works ok on both devices. The thing that bothers me, though, is that I haven't seen anything written about texture size requirements for attaching to a framebuffer object. One solution, for now, would be to restrict my texture sizes to be at least 16 pixels, but might this break in the future or already be broken on some device I haven't tried? I could also perform this test code at startup in order to dynamically figure out which texture sizes are allowed, but that seems a bit hokey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我尝试在 iPod touch 4 上渲染尺寸为 480x320(全屏,无分辨率比例)的纹理时,我遇到了类似的问题。当我调用
glCheckFramebufferStatus()
时,它返回GL_FRAMEBUFFER_UNSUPPORTED
。我的代码:调查这个问题我发现如果我们希望在渲染到纹理机制中使用
GL_TEXTURE_2D
,它必须是一个有效的OpenGL ES对象。这意味着纹理应该准备好绑定和使用。因此,要修复错误,我必须设置一些纹理参数。因为我使用非 POT 纹理,所以必须将GL_TEXTURE_WRAP_
设置为GL_CLAMP_TO_EDGE
(默认值为GL_REPEAT
)和GL_TEXTURE_MIN_FILTER
到GL_NEAREST
或GL_LINEAR
(默认值为GL_NEAREST_MIPMAP_LINEAR
)来使用此纹理。我找不到 16x8 的问题,但如果设置了此参数,16x9 和 17x8 就可以正常工作。我希望这些信息对您有所帮助。
I have experienced similar problem, when I'm trying to render to texture with size 480x320 (full screen w/o resolution scale) on iPod touch 4. When I call
glCheckFramebufferStatus()
it returnsGL_FRAMEBUFFER_UNSUPPORTED
. My code:Investigating this problem I have found that
GL_TEXTURE_2D
has to be a valid OpenGL ES object if we want it to use in render-to-texture mechanism. This means texture should be ready for bound and use. So to fix an error I have to set some texture parameters. Because I use non-POT texture I have to setGL_TEXTURE_WRAP_
toGL_CLAMP_TO_EDGE
(default value isGL_REPEAT
) andGL_TEXTURE_MIN_FILTER
toGL_NEAREST
orGL_LINEAR
(default value isGL_NEAREST_MIPMAP_LINEAR
) to use this texture.I couldn't find what's the problem with 16x8, but 16x9 and 17x8 works fine if this parameters are set. I hope this information will be helpful for you.