Difference between revisions of "Multisampling"

From OpenGL.org
Jump to: navigation, search
(Categorizing.)
m (Some touch ups)
Line 1: Line 1:
Full Scene Anti-Aliasing - also called FSAA<br>
+
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).<br>
+
 
<br>
+
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) would do the job.
Since GPUs of the day didn't support it in hw, it would run very slow.<br>
+
 
<br>
+
Since GPUs of the day didn't support it in hw, it would run very slow with those point smoothing and line smoothing and polygon smoothing.
These days, they still run slow unless you have a workstation GPU.<br>
+
 
For gaming GPUs, you should only use FSAA. You should even give the user the option to turn on and off FSAA.<br>
+
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 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.<br>
+
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 :<br>
+
 
1. Start your program, open a dummy window for getting function pointers (CreateWindowEx)<br>
+
This is what you must do :
2. Make the window invisible ShowWindow(window.HWnd, SW_HIDE)<br>
+
 
3. You can then SetPixelFormat, create the GL context, make the GL context current (wglMakeCurrent(hdc, glrc))<br>
+
1. Start your program, open a dummy window for getting function pointers. You would use CreateWindowEx to create your window.
4. Now you can get the funcion pointers. If you are using GLEW
+
 
 +
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 function pointers. If you are using GLEW
 
   GLenum err=glewInit();
 
   GLenum err=glewInit();
 
   if(err!=GLEW_OK)
 
   if(err!=GLEW_OK)
Line 21: Line 29:
 
   }
 
   }
  
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.<br>
+
5. Check to see if the 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. <br>
+
 
7. Now, create your real window. Make it visible.<br>
+
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.
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.<br>
+
 
9. Since you have already called glewInit, you don't need to call it again. Use wglGetPixelFormatAttribivARB to collect information.<br>
+
7. Now, create your real window. Make it visible.
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.<br>
+
 
<br>
+
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.<br>
The most difficult part is choosing a suitable pixelformat. One that has the right color bits, depth bits, stencil bits, the right FSAA level.<br>
+
 
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.<br>
+
9. Since you have already called glewInit, you don't need to call it again. Use wglGetPixelFormatAttribivARB to collect information. Also keep in mind that a GL context is not needed for wgl functions to work such as wglGetPixelFormatAttribivARB.
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)
+
 
 +
10. When you find a pixelformat that you like, call the "traditional" 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).
 +
 
 +
 
 +
Here are the links to the extensions in question (Windows) :
 +
 
 +
- http://www.opengl.org/registry/specs/ARB/wgl_extensions_string.txt
 +
 
 +
- http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt
 +
 
 +
These are for *nix systems :
 +
 
 +
- http://www.opengl.org/registry/specs/SGIS/multisample.txt (GL_SGIS_multisample and GLX_SGIS_multisample are on the same page)
 +
 
 +
These are for all platforms :
 +
 
 +
- http://www.opengl.org/registry/specs/ARB/multisample.txt
 +
 
 +
 
 +
These might interest you :
 +
 
 +
- http://www.opengl.org/registry/specs/NV/multisample_filter_hint.txt
 +
 
 +
- http://www.opengl.org/registry/specs/NV/explicit_multisample.txt
 +
 
 +
- http://www.opengl.org/registry/specs/NV/multisample_coverage.txt
 +
 
 +
 
 
== Conclusion ==
 
== 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.<br>
+
Setting up FSAA takes a few steps but it is worth it. Today's 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]]
 
[[Category:Rasterization]]

Revision as of 14:33, 10 February 2011

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) would do the job.

Since GPUs of the day didn't support it in hw, it would run very slow with those point smoothing and line smoothing and polygon smoothing.

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. You would use CreateWindowEx to create your window.

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 function 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 the 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. Also keep in mind that a GL context is not needed for wgl functions to work such as wglGetPixelFormatAttribivARB.

10. When you find a pixelformat that you like, call the "traditional" 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).


Here are the links to the extensions in question (Windows) :

- http://www.opengl.org/registry/specs/ARB/wgl_extensions_string.txt

- http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt

These are for *nix systems :

- http://www.opengl.org/registry/specs/SGIS/multisample.txt (GL_SGIS_multisample and GLX_SGIS_multisample are on the same page)

These are for all platforms :

- http://www.opengl.org/registry/specs/ARB/multisample.txt


These might interest you :

- http://www.opengl.org/registry/specs/NV/multisample_filter_hint.txt

- http://www.opengl.org/registry/specs/NV/explicit_multisample.txt

- http://www.opengl.org/registry/specs/NV/multisample_coverage.txt


Conclusion

Setting up FSAA takes a few steps but it is worth it. Today's 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.