iphone – 无法制作完整的帧缓冲对象8cd6(iOS,以编程方式创建的OpenGL视图)

我在编程创建OpenGL视图时遇到问题,无法在某些iOS版本/设备上运行.它似乎在Jailbroken设备上最常见,但也会在普通设备上发生.它似乎只是v4.1或4.2.1失败了.

我拥有的设备是越狱(它不是我的,当然不是我越狱的选择!)并且有iOS的v4.1(8B117).

错误是8cd6,这意味着它无法附加帧缓冲区(或沿着这些行的东西).

我进行了搜索和搜索,但我找到的其他解决方案都没有帮助.他们中的大多数也使用深度缓冲,但我的纯粹是2D并且没有深度缓冲.

这是我创建缓冲区的方法:

glGenFramebuffersOES(1, &defaultFramebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);

glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);

glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);

其他设置值:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, rect.size.width, 0, rect.size.height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glViewport(0, 0, rect.size.width, rect.size.height);

glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

int* mts = calloc(1, sizeof(int));
glGetIntegerv(GL_MAX_TEXTURE_SIZE, mts);

resizeFromLayer:

-(BOOL) resizeFromLayer: (CAEAGLLayer*) _layer
{
    // Allocate color buffer backing based on the current layer size
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);

    NSLog(@"Layer Bounds: %f x %f", _layer.bounds.size.width, _layer.bounds.size.height);
    NSLog(@"Layer Position: %f x %f", _layer.bounds.origin.x, _layer.bounds.origin.y);
    if(![context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable: _layer])
    {
        NSLog(@"renderBufferStorage failed!");
    }

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
    NSLog(@"Backing: %d x %d", backingWidth, backingHeight);

    if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
    {
        NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
        return NO;
    }

    return YES;
}

这是使用错误代码8cd6调用的“无法制作完整的帧缓冲对象”这一行.

最佳答案
感谢上面的两位用户帮助我实现了一些目标.

我将缓冲区的创建移出了类的init函数,并创建了两个新函数:

-(void) destroyFrameBuffer
{
    // Tear down GL
    if (defaultFramebuffer)
    {
        glDeleteFramebuffersOES(1, &defaultFramebuffer);
        defaultFramebuffer = 0;
    }

    if (colorRenderbuffer)
    {
        glDeleteRenderbuffersOES(1, &colorRenderbuffer);
        colorRenderbuffer = 0;
    }
}

-(void) createFrameBuffer
{
    // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
    glGenFramebuffersOES(1, &defaultFramebuffer);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);

    glGenRenderbuffersOES(1, &colorRenderbuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);

    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
}

然后我在resizeFromLayer函数的开头添加了对这些的调用:

[self destroyFrameBuffer];
[self createFrameBuffer];

转载注明原文:iphone – 无法制作完整的帧缓冲对象8cd6(iOS,以编程方式创建的OpenGL视图) - 代码日志