Difference between revisions of "Multisampling"

From OpenGL.org
Jump to: navigation, search
m (Multisample moved to Multisampling: Seems more reasonable. Also, other pages link to this.)
(Categorizing.)
Line 34: Line 34:
 
Setting up FSAA takes a few steps but it is worth it. Todays GPUs are very rapid and the user wants control over the quality of the game's graphics.<br>
 
Setting up FSAA takes a few steps but it is worth it. Todays GPUs are very rapid and the user wants control over the quality of the game's graphics.<br>
 
On Windows, the extension we are interested in are WGL_ARB_extensions_string which defines wglGetExtensionsStringARB, but the only way to check if this is available is to call wglGetExtensionsStringARB. So this is a chicken and egg situation. Just get the function pointer to wglGetExtensionsStringARB and use it to see if you have WGL_ARB_pixel_format and WGL_ARB_multisample.
 
On Windows, the extension we are interested in are WGL_ARB_extensions_string which defines wglGetExtensionsStringARB, but the only way to check if this is available is to call wglGetExtensionsStringARB. So this is a chicken and egg situation. Just get the function pointer to wglGetExtensionsStringARB and use it to see if you have WGL_ARB_pixel_format and WGL_ARB_multisample.
 +
 +
[[Category:Rasterization]]

Revision as of 23:35, 23 August 2009

Full Scene Anti-Aliasing - also called FSAA
The 1995 method of doing AA was to call glEnable(GL_POINT_SMOOTH), glEnable(GL_LINE_SMOOTH), glEnable(GL_POLYGON_SMOOTH) and to enable blending with glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), glEnable(GL_BLEND). For points and lines, you need to make them a little big, glPointSize(1.1), glLineWidth(1.1).

Since GPUs of the day didn't support it in hw, it would run very slow.

These days, they still run slow unless you have a workstation GPU.
For gaming GPUs, you should only use FSAA. You should even give the user the option to turn on and off FSAA.

The Procedure

The problem is that this part of OpenGL is platform specific. If you use freeGLUT, SDL or some other library, they hide this platform specific stuff. Here, we will talk about Windows and the platform specific API.
This is what you must do :
1. Start your program, open a dummy window for getting function pointers (CreateWindowEx)
2. Make the window invisible ShowWindow(window.HWnd, SW_HIDE)
3. You can then SetPixelFormat, create the GL context, make the GL context current (wglMakeCurrent(hdc, glrc))
4. Now you can get the funcion pointers. If you are using GLEW

 GLenum err=glewInit();
 if(err!=GLEW_OK)
 {
    //Problem: glewInit failed, something is seriously wrong
    sprintf(pErrorMessage, "Error: %s", glewGetErrorString(err));
    return -1;
 }

5. Check to see if function pointer (wglGetExtensionsStringARB) is not NULL. If it is not NULL, call wglGetExtensionsStringARB(hdc) to get a list of WGL extensions supported.
6. WGL_ARB_pixel_format and WGL_ARB_multisample should be in the list. If they are, set some variable to TRUE and then make GL context non-current, kill the GL context, destroy the temporary window.
7. Now, create your real window. Make it visible.
8. Now you must check that variable that you had set. Is it FALSE or TRUE. If it is TRUE, then you can setup a FSAA pixelformat.
9. Since you have already called glewInit, you don't need to call it again. Use wglGetPixelFormatAttribivARB to collect information.
10. When you find a pixelformat that you like, call the "tradional" SetPixelFormat. Make a GL context, make context current and now you are ready to render.

The most difficult part is choosing a suitable pixelformat. One that has the right color bits, depth bits, stencil bits, the right FSAA level.
You should also call glEnable(GL_MULTISAMPLE) but in reality this is useless since it is not possible to enable or disable FSAA once you have chosen a FSAA pixelformat.
In this entire document, we called it FSAA (Full Scene Anti-Aliasing) but it is also called MS (multisampling) since multiple samples are taken in various ways and the samples are blended together to give the resulting pixel. There is also another concept called supersampling and there are also nVidia specific GPU algorithms for sampling (see nVidia's documents on their developer website. http://developer.nvidia.com)

Conclusion

Setting up FSAA takes a few steps but it is worth it. Todays GPUs are very rapid and the user wants control over the quality of the game's graphics.
On Windows, the extension we are interested in are WGL_ARB_extensions_string which defines wglGetExtensionsStringARB, but the only way to check if this is available is to call wglGetExtensionsStringARB. So this is a chicken and egg situation. Just get the function pointer to wglGetExtensionsStringARB and use it to see if you have WGL_ARB_pixel_format and WGL_ARB_multisample.