kakashidinho/metalangle

Always getting GL_FRAMEBUFFER_UNSUPPORTED as soon as I try to add a depth buffer

escamoteur opened this issue · 2 comments

I'm trying to create a Framebuffer that uses RBOs.

The code that works on Windows results on my Mac in GL_FRAMEBUFFER_UNSUPPORTED when I check the framebuffer status.

Here is how I create everything:

        glGenRenderbuffers(1, &_rbo);
        glBindRenderbuffer(GL_RENDERBUFFER, _rbo);

        glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);

In Dart I use that RBO to connect it to a framebuffer:

    rawOpenGl.glGenFramebuffers(1, fbo);
    rawOpenGl.glBindFramebuffer(GL_FRAMEBUFFER, fbo.value);

    final newTexture = FlutterGLTexture.fromMap(result, fbo.value, width, height);

    print(rawOpenGl.glGetError());
    rawOpenGl.glBindRenderbuffer(GL_RENDERBUFFER, newTexture.rboId);

    rawOpenGl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, newTexture.rboId);
    var frameBufferCheck = rawOpenGl.glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (frameBufferCheck != GL_FRAMEBUFFER_COMPLETE) {
      print("Framebuffer (color) check failed: ${frameBufferCheck.toRadixString(16)}");
    }

    Pointer<Int32> depthBuffer = calloc();
    rawOpenGl.glGenRenderbuffers(1, depthBuffer.cast());
    rawOpenGl.glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer.value);
    if (Platform.isMacOS || Platform.isIOS) {
      rawOpenGl.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
    } else {
      rawOpenGl.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
    }

    rawOpenGl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer.value);
    frameBufferCheck = rawOpenGl.glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (frameBufferCheck != GL_FRAMEBUFFER_COMPLETE) {
      print("Framebuffer (depth) check failed: ${frameBufferCheck.toRadixString(16)}");
    }

Attaching the ColorAttachment works, but as soon as I try to attach a depth attachment I get this error.
I tried different values for glRenderbufferStorage but without any success.

Any idea what could be wrong?

Thanks a lot!

One possibility is that your FlutterGLTexture.fromMap(result, fbo.value, width, height) doesn't actually return a texture with size exactly = width, height. Hence, when creating depth buffer with size = width, height and attach to FBO, it throws this error.
Other ANGLE backends might support framebuffer's attachments having different size. However, Metal backend currently doesn't.

Awesome, you had the right hunch, it wasn't the fromMap but I had still some constants for width and size in the objetive C part with different dimensions!
Thanks a lot!