Hi. I’m trying to render some lines to a texture. I need them antialiased, so I first have to create multisampled color and depth renderbuffers, attach them to an FBO, and render the lines. Since multisampled FBOs cannot have texture attachments, I then have to blit the multisampled FBO to a plain old FBO with texture attachments.
This works excellently for the color buffer, and I get the following magnified result, which is antialiased:
However, the depth buffer does not appear to be multisampled:
The code that does all this is:
// Create a multisampled color buffer.
GLuint msaa_color;
glGenRenderbuffersEXT(1, &msaa_color);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, msaa_color);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 8, GL_RGBA8,
FBO_SIZE, FBO_SIZE);
// Create a multisampled depth buffer.
GLuint msaa_depth;
glGenRenderbuffersEXT(1, &msaa_depth);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, msaa_depth);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 8,
GL_DEPTH_COMPONENT, FBO_SIZE,
FBO_SIZE);
// Create a multisampled fbo and attached the color and depth buffers.
GLuint msaa_fbo;
glGenFramebuffersEXT(1, &msaa_fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, msaa_fbo);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, msaa_color);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, msaa_depth);
// draw stuff
// Create an fbo for blitting the multisampled fbo to a texture.
GLuint fbo;
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
// Draw into the texture.
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, lines_tex_id, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_2D, depth_tex_id, 0);
// Make the multisampled fbo the source and the texture fbo the target.
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, msaa_fbo);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo);
glBlitFramebufferEXT(0, 0, FBO_SIZE, FBO_SIZE, 0, 0, FBO_SIZE, FBO_SIZE,
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
To get the images, I retrieve the textures and save them out to a file. My FBOs are framebuffer complete.
Should not the depth texture also be antialiased? Or is multisampling not actually performed for a depth buffer?
I would sincerely appreciate any insight. Let me know if I can provide more information. My graphics cards are an NVIDIA 7300 GeForce Go and a Quadro 3450 with current drivers. Both show the same results.
- Chris