Switch between MSAA and no MSAA in realtime

Hi,

I’m looking for idea on how to easily implement a switch between MSAA and noMSAA in realtime without recreating rendering context and reloading all resources, etc. MSAA is used via WGL_ARB_multisample.

Is there a method with recreating context, but without a need of reloading resources?

Any ideas?

You can create new context, share all resources with old one (wglShareLists) and then delete old context. No resources will need reloading.

I use OpenGL under Windows.

For creating second context, I need to get new HDC, set pixel format and create context for this HDC. But I don’t understand how can I get a new HDC if only one HDC can be associated with a window?

If I try to set pixel format for old HDC and create new context for old HDC, I get an error on setting pixel format…

I don’t think that deleting the old context is a good idea. I experiment this once and get the following result: CRASH

I guest that the old context keep all the resources that die with it. If you want to delete contexts but save the resources then create a dummy context and share it with all contexts you want to delete.

However for your case, why not just call glDisable(GL_MULTISAMPLES); ?

Maybe it will be slightly faster with a noMSAA context but I’m not even sure. I guest, the best benefice would be with memory allocate for the multiple sample layer.

MSAA framebuffer requires <number of samples>-times more memory than normal framebuffer. We use a lot of textures and we can get a situation when amount of videomemory is not enough for all textures needed for a frame + MSAA framebuffer (that is not actually used because MSAA is turned off in a program). It can lead to a significant drop of FPS.

From description of wglShareLists function
http://msdn.microsoft.com/en-us/library/ms537565(VS.85).aspx
“All rendering contexts of a shared display list must use an identical pixel format. Otherwise the results depend on the implementation of OpenGL used.”

MSAA pixelformat != noMSAA pixelformat

Well, a possible solution would be rendering to a MSAA-enabled FBO, without a MSAA-enabled e window buffer . When you need more resources, you can delete the FBO.

At the moment, this is the best solution. This method had only one strong disadvantage: at low-end models of ATI videocards (like HD2400PRO) rendering to FBO with stencil usage is much more slower than rendering to the main framebuffer.

It’s very strange, that there is no way to change the number of samples in realtime for the main framebuffer :frowning:

Hm… thats interesting. I did not know that.
In my code for switching on and off MSAA for main window I create new window in same position as old window, create new GL context, share it with old one, and delete old GL context and window. Had no problems with Ati or Nvidia drivers on Windows Vista (32-bit). All the texture/FBO/VBO/shader handles from old context are still usable new context.