GlFramebufferTexture2D does not work on iPhone for certain texture sizes

When I try to attach a texture to the framebuffer, glCheckFramebufferStatus tells GL_FRAMEBUFFER_UNSUPPORTED for specific texture sizes. I tested both the second and fourth generation iPod Touch. The texture sizes that fail are not identical between the two models.

Here are some interesting results:

The second generation - 8x8 failed, 16x8 failed, but 8x16 succeeded!

4th generation - 8x8 succeeded, 8x16 succeeded, but 16x8 failed!

Here is the code I used to test the attached 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 sizes are at least 16 pixels, everything works fine on both devices. However, it bothers me that I have not seen anything written about texture size requirements for attaching to a framebuffer object. Today, one of the solutions would be to limit the texture size to at least 16 pixels, but could this happen in the future or already break on some device that I have not tried? I could also run this test code at startup to dynamically determine what texture sizes are allowed, but that seems a bit hockey.

+2
source share
1 answer

I had a similar problem when I try to make a 480x320 texture size (fullscreen without permission) on iPod touch 4. When I call glCheckFramebufferStatus() , it returns GL_FRAMEBUFFER_UNSUPPORTED . My code is:

 glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 480, 320, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0); glBindTexture(GL_TEXTURE_2D, 0); glGenFramebuffers(1, &frameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { // report error } 

Investigating this problem, I found that GL_TEXTURE_2D must be a valid OpenGL ES object if we want it to be used in the render-to-texture mechanism. This means that the texture must be ready for snapping and use. Therefore, to fix the error, I need to set some texture parameters. Since I use a texture other than POT, I need to set GL_TEXTURE_WRAP_ to GL_CLAMP_TO_EDGE (the default is GL_REPEAT ) and GL_TEXTURE_MIN_FILTER is GL_NEAREST or GL_LINEAR (the default is GL_NEAREST_MIPMAP_LINEAR to use this)

I could not find that the problem is with 16x8, but 16x9 and 17x8 work fine if these options are set. I hope this information is helpful to you.

+1
source

All Articles