1

我正在尝试创建一个帧缓冲区以在我的 iOS 应用程序中显示 3D 模型,但是当创建帧缓冲区时,渲染缓冲区存储返回 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));

}
}

任何帮助将不胜感激。

提前致谢。

4

2 回答 2

1

我也在为此苦苦挣扎,并找到了适合我的解决方案。我正在使用

var openGLView = OpenGLView()

并且“renderbufferStorage”返回false。在我将其更改为之后

var openGLView: OpenGLView!

我得到“renderbufferStorage”返回真。

于 2016-04-19T23:19:20.673 回答
-1

你不能在 iOS 中使用标准的 renderbufferStorage。您必须使用作为 EAGLContext 实例的对象来执行此操作

于 2015-02-28T13:15:19.693 回答