MSAA FBO with depth -> not working

Hello all,

I’m trying to get an MSAA FBO to output an antialiased scene, but I cannot get the depth component to work. Without the depth test, the entire thing is useless. :frowning:

Here is my code.


1) glGenRenderbuffers(1, &tex);
2) glBindRenderbuffer(GL_RENDERBUFFER, tex);
3) glRenderbufferStorageMultisample(GL_RENDERBUFFER, number_of_samples, GL_RGB8, (GLsizei)gWindowWidth, (GLsizei)gWindowHeight);
// number_of_samples is 4

4) glGenRenderbuffers(1, &depth_tex);
5) glBindRenderbuffer(GL_RENDERBUFFER, depth_tex);
6) glRenderbufferStorageMultisample(GL_RENDERBUFFER, number_of_samples, GL_DEPTH_COMPONENT, (GLsizei)gWindowWidth, (GLsizei)gWindowHeight);


7) glGenFramebuffers(1, &fbo);
8) glBindFramebuffer(GL_FRAMEBUFFER, fbo);


9) glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, tex);
        
10) glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_tex);
// Commenting out line 10 causes it to work fine, but with a depth-corrupted scene.
// Without commenting out line 10, I get a black screen




11) if (pglCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
12)      debug_string = "Frame Buffer not complete";     // THIS NEVER TRIGGERS




// DRAWING GOES HERE




13) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
14) glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
15) glBlitFramebuffer(0, 0, (GLint)gWindowWidth, (GLint)gWindowHeight, 0, 0, (GLint)gWindowWidth, (GLint)gWindowHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
16) glBlitFramebuffer(0, 0, (GLint)gWindowWidth, (GLint)gWindowHeight, 0, 0, (GLint)gWindowWidth, (GLint)gWindowHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST);


//Note:
// I've also tried:
/*
glBlitFramebuffer(0, 0, (GLint)gWindowWidth, (GLint)gWindowHeight, 0, 0, (GLint)gWindowWidth, (GLint)gWindowHeight, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
*/



If I comment out line 10, (the line attaching the depth buffer to the FBO), it works fine, but has no depth testing. Otherwise, I get a black screen. I’ve tried innumerable tutorials, and they are all essentially the same.

Also I have a breakpoint on line 12, but it never triggers in debug mode. I also never get any debug_string message (displayed elsewhere).

If anyone can give me a pointer on what’s going wrong, I’d be very grateful.

Cheers!

  1. Have you checked for GL errors?
  2. Have you checked for framebuffer completeness?
  3. Have you tried specific internal formats for your depth renderbuffer, such as GL_DEPTH_COMPONENT24 or GL_DEPTH_COMPONENT32?
  4. Instead of creating a depth attachment, you might try creating a combined depth+stencil renderbuffer (GL_DEPTH24_STENCIL8) and attaching it to the GL_DEPTH_STENCIL_ATTACHMENT.

Hello Dark Photon,

Thanks for the reply :slight_smile:

I checked for the OpenGL errors. None.

Framebuffer completeness seems to be ok. Line 12 never triggers.

I tried GL_DEPTH_COMPONENT24 and GL_DEPTH_COMPONENT32, but neither worked (unless I’m blitting them wrong).

Lastly, I also tried GL_DEPTH24_STENCIL8. No good. . . again unless I’m blitting them wrong.

No clue. :,(

What GL drivers and GPU?

You could always try a depth (or depth+stencil) texture. As a test, try w/o multisample render targets as well.