Open GL ES 2.0 renderbufferStorage返回false

时间:2014-07-09 10:07:13

标签: ios objective-c opengl-es-2.0 framebuffer caeagllayer

我试图创建一个Framebuffer来在我的iOS应用程序中显示3D模型,但是当创建了framebuffer时,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));

}
}

任何帮助将不胜感激。

提前致谢。

2 个答案:

答案 0 :(得分:1)

我也在努力解决这个问题,并找到了适合我的解决方案。我正在使用

var openGLView = OpenGLView()

和" renderbufferStorage"返回假。在我改为

之后
var openGLView: OpenGLView!

我得到了#34; renderbufferStorage"返回true。

答案 1 :(得分:-1)

你不能在iOS中使用标准的renderbufferStorage。您必须使用作为EAGLContext

实例的对象来执行此操作