PDA

View Full Version : Multisampled FBO problem



dukey
06-06-2012, 09:35 AM
I have a problem with multisampled FBO's. I just don't get any anti-alaising unless i specify the max supported value.
Code



GLint maxSamples;

glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);

glGenRenderbuffersEXT ( 1, &mColourBuffer );
glBindRenderbufferEXT ( GL_RENDERBUFFER_EXT, mColourBuffer);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFE R_EXT, maxSamples, GL_RGBA, mFBOTextureWidth, mFBOTextureHeight );

glGenRenderbuffersEXT ( 1, &mDepthBuffer );
glBindRenderbufferEXT ( GL_RENDERBUFFER_EXT, mDepthBuffer );
glRenderbufferStorageMultisampleEXT( GL_RENDERBUFFER_EXT, maxSamples, GL_DEPTH_COMPONENT, mFBOTextureWidth, mFBOTextureHeight );

glGenFramebuffersEXT ( 1, &mFrameBufferMulti );
glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, mFrameBufferMulti );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, mColourBuffer );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mDepthBuffer );

GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );


I set my FBO


glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, mFrameBufferMulti );

draw a bunch of stuff

Then final blit to another FBO, do some shaders on it and swap buffers


glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, mFrameBufferMulti);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, mFrameBuffer);
glBlitFramebufferEXT(0, 0, mFBOTextureWidth, mFBOTextureHeight, 0, 0, mFBOTextureWidth, mFBOTextureHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);


Pic
http://i.imgur.com/C1AQj.png

For some reason only the value 16x seems to work. There is no glEnable for FBOs to set anti-alaising ?

kyle_
06-06-2012, 09:46 AM
There is no glEnable for FBOs to set anti-alaising ?

Nope. There is single enable for multisampling, and its enabled by default.

dukey
06-06-2012, 09:50 AM
Is it possible to disable multisampling for a multisampled FBO ?

This kind of reminds me of when I was using a multisampled back buffer and setting a value of 16x, then disable multisampling. You would still get something like 4x multisampling anyway with nvidia ..

Dark Photon
06-07-2012, 07:43 AM
Is it possible to disable multisampling for a multisampled FBO ?

There are two pieces to multisample rendering: multisample rasterization and multisample downsample filtering. The first happens while rendering, the second happens internally to SwapBuffers (or explicitly when downsampling via glBlitFramebuffer).

You can easily disable the first: glDisable( GL_MULTISAMPLE ). For the system FB, don't think you can disable the multisample downsample filtering. But if you render to an off-screen multisample texture/renderbuffer via an FBO, then you can chose what to do after rendering the multisampled render target. You could write your own trivial downsample shader that that basically just takes the first sample in each pixel (or whatever) as the pixel's value.


This kind of reminds me of when I was using a multisampled back buffer and setting a value of 16x, then disable multisampling. You would still get something like 4x multisampling anyway with nvidia ..

Right. I've seen the same. I think this is because you disabled multisample rasterization but not the multisample downsample filtering.

dukey
06-07-2012, 08:19 AM
My source and destination FBOs are the same size. I just don't understand why I don't get any anti-aliasing unless I specify the max value. Interestingly 16x seems to look more like 4x anti-alaising.

shadocko
06-11-2012, 07:04 AM
My source and destination FBOs are the same size. I just don't understand why I don't get any anti-aliasing unless I specify the max value. Interestingly 16x seems to look more like 4x anti-alaising.

Yup, you're certainly getting 4x SUPERsampling (and no useful multisampling).
On nVidia cards, at least up to GT200 series, so-called 16x multisampling is achieved by cumulating 4x multisampling with 4x supersampling.
That results in images being anti-aliased even if multisampling is disabled while rendering to a 16x multisample buffer. I encountered the exact same problem (except I wanted to have no anti-aliasing to implement a stencil-routed K-buffer).

For some reason it seems as if multisampling is disabled in your case. Did you try glEnable( GL_MULTISAMPLE ) before rendering?
Did you try to blit from your multisample buffer to your output buffer another way (e.g. the infamous glCopyPixels)?

dukey
06-11-2012, 09:09 AM
On nVidia cards, at least up to GT200 series, so-called 16x multisampling is achieved by cumulating 4x multisampling with 4x supersampling.

Yeah I remember something like this was true. I found it myself when using a multisampled back buffer. Trying to disable multi sampling still leaves you with some super sampling.


For some reason it seems as if multisampling is disabled in your case
I know, I have been stuck on this problem for a while now. I didn't think it was possible to disable multisampling on a multisampled FBO ..
I can try
glEnable( GL_MULTISAMPLE )

and just see what happens.

I haven't tried glCopyPixels either, but I guess I can give it ago.

dukey
06-11-2012, 10:40 AM
okay,
there was a stray call to glDisable(GL_MULTISAMPLE_ARB)
that was doing it !
Solved thankfully