Jump to content

  • Log In with Google      Sign In   
  • Create Account


MSAA not working with GL_EXT_framebuffer_multisample


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 ic0de   Members   -  Reputation: 831

Like
0Likes
Like

Posted 21 November 2012 - 03:53 PM

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?

you know you program too much when you start ending sentences with semicolons;


Sponsor:

#2 theagentd   Members   -  Reputation: 551

Like
0Likes
Like

Posted 21 November 2012 - 10:24 PM

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.

#3 ic0de   Members   -  Reputation: 831

Like
0Likes
Like

Posted 21 November 2012 - 10:28 PM

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.

you know you program too much when you start ending sentences with semicolons;


#4 ic0de   Members   -  Reputation: 831

Like
0Likes
Like

Posted 22 November 2012 - 05:23 PM

I fixed it, I don't know why but I needed to create the fbos without attaching any textures to them.

you know you program too much when you start ending sentences with semicolons;





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS