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.
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!