Multi- sampling in OpenGL
one of the biggest advantages of antialiasing is that it makes the edges of polygons smoother, rendering them more realistic and natural. Antialiasing of points and lines is widely supported, but unfortunately, the smoothing of polygons is not implemented on all platforms. And even when Gl_polygon_smooth is available, antialiasing of the entire scene is not as convenient as it might seem. This is because antialiasing is based on mixed operations, which requires sorting all the elements from front to back, which is cumbersome.
There is also a feature in OpenGL called multi-sampling (multisampling) that can be used to solve this problem in antialiasing. OpenGL with multi-sampling supportimplementation, an additional buffer is added to the frame buffer that already contains the color, depth, and template values, and all the entities are sampled multiple times on each pixel, and the result is stored in the new buffer. Each time the pixel is updated, the sampled values are parsed to produce a separate value. This processing belongs to "What's going on behind the scenes", which brings additional memory and processor overhead, which can have a certain impact on performance. Therefore, some OpenGL implementations may not support multi-sampling processing in a multi-render environment.
For multi-sampling, you must first obtain a rendering environment that supports multiple sampling frame buffers, which may vary from one platform to another. GLUT provides a bit segment (Glut_multisample) that allows the request of such a framebuffer. For example, in order to request a multi-sample, full color, and deep double-buffered frame buffer, you can call:
Glutinitdisplaymode (glut_double | Glut_rgb | glut_depth | glut_multisample);
we can then use the glenable/gldisable combination to turn multi-sampling on or off: //Open multi-sample glenable (gl_multisample);
//Turn off multi-samplinggldisable ( gl_multisample);
A special note about multiple sampling is that when it is enabled, the smoothing properties of points, lines, and polygons are ignored (if turned on). This means that when using multiple samples, it is not possible to use the smoothing of points, lines, and polygons at the same time. In some cases, however, it may be better to use smoothing for points and lines than for multiple samples. Therefore, when we draw points and lines, we can turn off multi-sampling, and then turn on multiple samples when drawing other solid geometries. The code looks like this:
//Turn off multi-sampling gldisable (gl_multisample); //smoothing of open vertices glenable (gl_point_smooth); //Draw some smooth points // ...
//Turn off smoothing of vertices gldisable (gl_point_smooth); //Open multi-sample glenable (gl_multisample);
Note that if there is no multi-sampling buffer, OpenGL will treat gl_multisample as disabled. The multi-sample buffer uses the fragment's RGB value by default and does not include the alpha component of the color. We can modify this behavior by calling the Glenable method with the following parameters:
gl_sample_alpha_to_coverage using ALPHA valuesGl_sample_alpha_to_one Set the ALPHA value to 1 and use itGl_sample_coverage The value set by using the Glsamplecoverage function
when Gl_sample_coverage is enabled, the Glsamplecoverage function allows you to specify a specific value, which is the result of a bitwise and (and) operation with the fragment override value.
void Glsamplecoverage (Glclampf value, Glboolean invert);
This optimization of multi-sampling is not strictly defined by the OpenGL specification, and its exact results may vary depending on the OpenGL implementation.
status sequencing in OpenGLturning the different OpenGL features on or off will modify the internal state of the driver, and this change in state may affect the performance of the rendering. Therefore, programmers who are very sensitive to performance often take the trouble to sort all the drawing commands so that geometries that require the same state are drawn together. This sort of status is one of the most common ways that game programmers use to improve rendering speed.
not to be continued ...
This article is from Du Xiaomeng's blog, do not use for any commercial purposes, reproduced please maintain integrity and identify the source: Http://blog.csdn.net/haohan_meng
Multi-sampling in OpenGL