Jump to content
  • Advertisement
Sign in to follow this  
ic0de

OpenGL MSAA not working with GL_EXT_framebuffer_multisample

This topic is 2064 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to add MSAA to my OpenGL game but for some reason it's not working. I have two FBO's, one of them is multisampled and one is not. They both have Two color attachments and one depth attachment. Each frame the multisampled one is blitted onto the non multisampled one. The problem is that the multisampling doesn't seem to have any effect, still lots of aliasing, I thing something is broken. Here is relevant code:

FBO setup:


void fbuffer::create(bool mrt, bool hdr, bool depth, bool multisample, int samples, bool noColour)
{
if(hdr)
{
colorFormat = GL_HALF_FLOAT_ARB;
format = GL_RGBA16F_ARB;
}
else
{
colorFormat = GL_UNSIGNED_BYTE;
}
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, format, screenw, screenh, 0, GL_RGBA, colorFormat, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glGenRenderbuffersEXT(1, &rboColour);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboColour);
if(GLEW_EXT_framebuffer_multisample && multisample)
{
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, format, screenw, screenh);
}
else
{
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, format, screenw, screenh);
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rboColour);
glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);
if(mrt)
{
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexImage2D(GL_TEXTURE_2D, 0, format, screenw, screenh, 0, GL_RGBA, colorFormat, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glGenRenderbuffersEXT(1, &rboColour2);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboColour2);
if(GLEW_EXT_framebuffer_multisample && multisample)
{
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, format, screenw, screenh);
}
else
{
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, format, screenw, screenh);
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, rboColour2);
glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, texture2, 0);
}
if(depth)
{
glGenTextures(1, &depthtex);
glBindTexture(GL_TEXTURE_2D, depthtex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, screenw, screenh, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glGenRenderbuffersEXT(1, &rboDepth);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rboDepth);
if(GLEW_EXT_framebuffer_multisample && multisample)
{
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_DEPTH_COMPONENT, screenw, screenh);
}
else
{
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, screenw, screenh);
}
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rboDepth);
glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthtex, 0);
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
void fbuffer::bind()
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
}


creating the objects:


msbuffer.format = screen->format->BytesPerPixel;
msbuffer.screenw = screen->w;
msbuffer.screenh = screen->h;
msbuffer.create(true, true, true, true, 8, false);
fbo1.format = screen->format->BytesPerPixel;
fbo1.screenw = screen->w;
fbo1.screenh = screen->h;
fbo1.create(true, true, true, false, 1, false);


blitting the buffers:


glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, msbuffer.fbo);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo1.fbo);
glBlitFramebufferEXT(0, 0, screen->w, screen->h, 0, 0, screen->w, screen->h, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
fbo1.bind();


Anyone know what I'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
You shouldn't have to blit the depth buffer. Resolved depth is practically worthless. What hardware are you running on? Maybe you've forced antialiasing to off in your drivers? Exactly what is aliased? MSAA does nothing to improve shader aliasing.

Share this post


Link to post
Share on other sites

You shouldn't have to blit the depth buffer. Resolved depth is practically worthless. What hardware are you running on? Maybe you've forced antialiasing to off in your drivers? Exactly what is aliased? MSAA does nothing to improve shader aliasing.


I'm running on an Nvidia GTX 460, the aliased part is around the edges of objects. I suppose I should also check my driver settings.

Share this post


Link to post
Share on other sites
I fixed it, I don't know why but I needed to create the fbos without attaching any textures to them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!