2

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.

Brian Rothstein
  • 1,312
  • 10
  • 20

1 Answers1

1

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 returns GL_FRAMEBUFFER_UNSUPPORTED. My code:

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 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 set GL_TEXTURE_WRAP_ to GL_CLAMP_TO_EDGE (default value is GL_REPEAT) and GL_TEXTURE_MIN_FILTER to GL_NEAREST or GL_LINEAR (default value is GL_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.

Jon
  • 2,932
  • 2
  • 23
  • 30
  • I still get errors even if I set the wrap mode to GL_CLAMP_TO_EDGE and the min filter to nearest. When you say you don't have a problem with the 16x8 texture, do you mean that my sample code works on your device for a 16x8 texture? Or do you mean it works in your own code? Maybe you could post a small sample similar to my sample that works for a 16x8 texture. Thanks! – Brian Rothstein Jul 06 '11 at 20:05
  • I also have problem with texture 16x8. It doesn't work for me too. But 16x9 and 17x8 just works! This is very strange. I have just noticed that texture object should have valid parameters if you want to attach it to framebuffer. – Alexander Dolbilov Jul 12 '11 at 05:25
  • Very strange! I think my solution is going to be to not try to read data from my textures. I was using the texture attached to a framebuffer combined with a glReadPixels to recover texture data back into memory. It wasn't vital to what I was doing, so I can just work around it. – Brian Rothstein Jul 12 '11 at 20:45