Multiple sampling in OpenGL and multiple sampling in OpenGL

Source: Internet
Author: User

Multiple sampling in OpenGL and multiple sampling in OpenGL
Multiple sampling in OpenGL
One of the biggest advantages of anti-sawtooth processing is that it can make the edge of the polygon smoother and make the rendering effect more realistic and natural. Point-and-line anti-sawtooth processing is widely supported, but unfortunately, the smooth processing of polygon is not implemented on all platforms. In addition, even when GL_POLYGON_SMOOTH can be used, anti-sawtooth processing for the entire scenario is not as convenient as imagined. This is because the anti-sawtooth processing is based on hybrid operations, which requires sorting all elements from the front to the back, which is very troublesome.
In OpenGL, there is also a function called multi-sample, which can be used to solve this problem in anti-sawtooth processing. In the multi-sample OpenGL implementation, an additional buffer is added to the frame buffer that already contains the color, depth, and template value, all elements are sampled multiple times on each pixel, and the results are stored in the newly added buffer. Each time a pixel is updated, the sampled values are parsed to generate a separate value. This processing is "behind the scenes", which will bring additional memory and processor overhead and will have a certain impact on performance. Therefore, some OpenGL implementations may not support multi-sample processing in Multi-rendering environments.
To perform multi-sample, you must first obtain a rendering environment that supports multi-sample frame buffers, which may be different on different platforms. GLUT provides a single-bit segment (glu_multisample) that allows requests to such a frame buffer. For example, to request a multi-sample, full color, and dual-buffer frame buffer with depth, you can call:
Fig );
Then, we can use the combination of glable and glDisable to enable or disable multi-sample: // enable the multi-sample glable (GL_MULTISAMPLE );
// Disable multiple sampling glDisable (GL_MULTISAMPLE );
Note that when multi-sampling is enabled, the smoothness of vertices, straight lines, and polygon will be ignored (if enabled ). This means that when multi-sampling is used, smooth processing of points, straight lines, and polygon cannot be used at the same time. However, in some cases, smooth processing of vertices and straight lines may be better than multi-sampling. Therefore, when we draw points and straight lines, we can turn off multiple sampling and enable multiple sampling when drawing other solid ry. The Code is as follows:
// Disable multiple sampling glDisable (GL_MULTISAMPLE); // enable the smooth processing of vertex glable (GL_POINT_SMOOTH); // draw some smooth points //...
// Disable glDisable (GL_POINT_SMOOTH) for smooth processing of vertices; // enable the multi-sample glEnable (GL_MULTISAMPLE );
NOTE: If there is no multi-sample buffer, OpenGL will disable GL_MULTISAMPLE. By default, the multi-sample buffer uses the RGB values of segments, excluding the alpha components of the color. We can modify this behavior by calling the glEnable method with the following parameters:
GL_SAMPLE_ALPHA_TO_COVERAGE use the alpha value GL_SAMPLE_ALPHA_TO_ONE to set the alpha value to 1, and use its GL_SAMPLE_COVERAGE to use the value set by the glSampleCoverage function.
When GL_SAMPLE_COVERAGE is enabled, the glSampleCoverage function allows you to specify a specific value, which is the result of bitwise AND (AND) operations with the segment overwrite value.
Void glSampleCoverage (GLclampf value, GLboolean invert );
This multi-sample optimization is not strictly defined by OpenGL specifications. The exact results may vary with OpenGL implementations.
In OpenGL, enabling or disabling different OpenGL Features Changes the internal state of the driver, which may affect rendering performance. Therefore, programmers who are very sensitive to performance often sort all the drawing commands, so that they need to draw geometric figures in the same state together. This sort of state is one of the most common ways for game programmers to increase rendering speeds.
To be continued...

This article from du Xiaomeng's blog, please do not for any commercial purposes, reproduced please maintain integrity and indicate the source: http://blog.csdn.net/haohan_meng

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.