GLKView : Trouble with offscreen RenderBuffer with Core Animation Layer

Viewed 268

I am trying to attach a renderbuffer following Apples guide Here.

My problem is that if try to I create the FBO this way, 2 scenarios happen :

a) If I draw any thing or call self.bindDrawable() prior to renderbufferStorage(_:_:), renderbufferStorage will return false, so the whole thing fails

b) If I run the two functions below before I call bindDrawable or draw anything, the renderbuffer will be successfully created, but I will get this error when I try to draw :

Failed to bind EAGLDrawable: to GL_RENDERBUFFER 2 Failed to make complete framebuffer object 8cd6

private func initFrameBuffer() -> GLuint {
    var framebuffer_id: GLuint = 0
    glGenFramebuffers(1, &framebuffer_id)
    glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer_id)
    return framebuffer_id
}

private func initRenderBuffer() -> GLuint {
    var renderBuffer_id: GLuint = 0
    glGenRenderbuffers(1, &renderBuffer_id);
    glBindRenderbuffer(GLenum(GL_RENDERBUFFER), renderBuffer_id);
    let status = context.renderbufferStorage(Int(GL_RENDERBUFFER), from: layer as! CAEAGLLayer)
    glFramebufferRenderbuffer(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_RENDERBUFFER), renderBuffer_id)
    return renderBuffer_id
}

I sat up my GLKView as such :

    context               = EAGLContext(api: .openGLES3)
    drawableColorFormat   = .RGBA8888
0 Answers
Related