1

I'm trying to create a Framebuffer to display a 3D model in my iOS app but when the framebuffer is created, the renderbufferStorage is returning false. My code is based on GLCameraRipple sample code.

The code to create the frame buffer is the following:

- (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));

}
}

Any help will be appreciated.

Thanks in advance.

sastresa
  • 75
  • 8
  • I've found the solution. The problem was that I was creating the frame in the viewcontroller not in the UIView. The same code in the UIView works fine. – sastresa Jul 11 '14 at 09:28

2 Answers2

1

I was struggling with this too and found a solution worked for me. I was using

var openGLView = OpenGLView()

and the "renderbufferStorage" returned false. After I changed that to

var openGLView: OpenGLView!

I got the "renderbufferStorage" returned true.

variadics
  • 370
  • 2
  • 5
-1

you can't use standard renderbufferStorage in iOS. You have to do that using an object that is instance of EAGLContext

NicoRaf
  • 73
  • 2
  • 7