[objective-c]开放的 GL ES 2.0 renderbufferStorage 返回 false

标签: ios Objective-C
发布时间: 2016/10/4 3:28:42
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我试图创建帧缓冲器,在我的 iOS 应用程序中显示 3D 模型,但在创建时帧缓冲器,renderbufferStorage 返回 false。我的代码基于 GLCameraRipple 的示例代码。

创建帧缓冲区的代码如下︰

- (void)createFramebuffer
{
if (_context && !defaultFramebuffer) {

    [EAGLContext setCurrentContext:_context];

    // Create default framebuffer object
    glGenFramebuffers(1, &defaultFramebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);

    // Create colour renderbuffer and allocate backing store
    glGenRenderbuffers(1, &colorRenderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);

    // Allocate the renderbuffer's storage (shared with the drawable object)
    CAEAGLLayer *layer = (CAEAGLLayer*)self.glkView.layer;
    BOOL success = [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer];
    if(!success) {
        NSLog(@"Error rendering buffer storage");
    }

    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, layer.bounds.size.width, layer.bounds.size.height);

    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);


    // Create the depth render buffer and allocate storage
    glGenRenderbuffers(1, &depthRenderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, framebufferWidth, framebufferHeight);

    // Attach colour and depth render buffers to the frame buffer
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);


    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));

}
}

任何帮助将不胜感激。

在此先感谢。

解决方法 1:

我也在挣扎与此,找到了解决办法,为我工作。我正在使用

var openGLView = OpenGLView()

和"renderbufferStorage"返回 false。之后我改变了对

var openGLView: OpenGLView!

我得到了"renderbufferStorage"时返回 true。

赞助商