3.3
Antialiasing
The R, G, and B values of the rasterized fragment are left unaffected, but the A value is multiplied by a floating-point value in the range [0,1] that describes a fragment’s screen pixel coverage. The per-fragment stage of the GL can be set up to use the A value to blend the incoming fragment with the corresponding pixel already present in the framebuffer.
The details of how antialiased fragment coverage values are computed are dif- ficult to specify in general. The reason is that high-quality antialiasing may take into account perceptual issues as well as characteristics of the monitor on which the contents of the framebuffer are displayed. Such details cannot be addressed within the scope of this document. Further, the coverage value computed for a fragment of some primitive may depend on the primitive’s relationship to a num- ber of grid squares neighboring the one corresponding to the fragment, and not just on the fragment’s grid square. Another consideration is that accurate calculation of coverage values may be computationally expensive; consequently we allow a given GL implementation to approximate true coverage values by using a fast but not entirely accurate coverage computation.
In light of these considerations, we chose to specify the behavior of exact an- tialiasing in the prototypical case that each displayed pixel is a perfect square of uniform intensity. The square is called afragment squareand has lower left corner
(x, y)and upper right corner(x+ 1, y+ 1). We recognize that this simple box filter may not produce the most favorable antialiasing results, but it provides a simple, well-defined model.
A GL implementation may use other methods to perform antialiasing, subject to the following conditions:
1. Iff1andf2are two fragments, and the portion off1covered by some prim- itive is a subset of the corresponding portion off2covered by the primitive, then the coverage computed forf1 must be less than or equal to that com- puted forf2.
2. The coverage computation for a fragment f must be local: it may depend only onf’s relationship to the boundary of the primitive being rasterized. It may not depend onf’sxandycoordinates.
Another property that is desirable, but not required, is:
3. The sum of the coverage values for all fragments produced by rasterizing a particular primitive must be constant, independent of any rigid motions in window coordinates, as long as none of those fragments lies along window edges.
3.3. ANTIALIASING 88
In some implementations, varying degrees of antialiasing quality may be obtained by providing GL hints (section 5.2), allowing a user to make an image quality versus speed tradeoff.
3.3.1 Multisampling
Multisampling is a mechanism to antialias all GL primitives: points, lines, and polygons. The technique is to sample all primitives multiple times at each pixel. The color sample values are resolved to a single, displayable color each time a pixel is updated, so the antialiasing appears to be automatic at the application level. Because each sample includes color, depth, and stencil information, the color (in- cluding texture operation), depth, and stencil functions perform equivalently to the single-sample mode.
An additional buffer, called the multisample buffer, is added to the framebuffer. Pixel sample values, including color, depth, and stencil values, are stored in this buffer. Samples contain separate color values for each fragment color. When the framebuffer includes a multisample buffer, it does not include depth or sten- cil buffers, even if the multisample buffer does not store depth or stencil values. Color buffers do coexist with the multisample buffer, however.
Multisample antialiasing is most valuable for rendering polygons, because it requires no sorting for hidden surface elimination, and it correctly handles adja- cent polygons, object silhouettes, and even intersecting polygons. If only lines are being rendered, the “smooth” antialiasing mechanism provided by the base GL may result in a higher quality image. This mechanism is designed to allow multi- sample and smooth antialiasing techniques to be alternated during the rendering of a single scene.
If the value of SAMPLE BUFFERS is one, the rasterization of all primi- tives is changed, and is referred to as multisample rasterization. Otherwise, primitive rasterization is referred to as single-sample rasterization. The value of SAMPLE BUFFERS is queried by calling GetIntegerv with pname set to
SAMPLE BUFFERS.
During multisample rendering the contents of a pixel fragment are changed in two ways. First, each fragment includes a coverage value withSAMPLESbits. The value ofSAMPLESis an implementation-dependent constant, and is queried by callingGetIntegervwithpnameset toSAMPLES.
Second, each fragment includesSAMPLESdepth values, color values, and sets of texture coordinates, instead of the single depth value, color value, and set of texture coordinates that is maintained in single-sample rendering mode. An imple- mentation may choose to assign the same color value and the same set of texture coordinates to more than one sample. The location for evaluating the color value