Скачиваний:
47
Добавлен:
17.03.2015
Размер:
2.46 Mб
Скачать

4.1. PER-FRAGMENT OPERATIONS

199

Fragment

 

Pixel

 

 

 

Scissor

 

 

 

 

 

 

 

Alpha

 

 

 

+

 

 

 

Ownership

 

 

 

 

 

 

 

 

 

 

Test

 

 

 

 

 

 

 

 

 

 

Test

 

 

 

 

 

 

 

 

 

 

Associated

 

Test

 

 

 

 

 

 

 

 

 

(RGBA Only)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Depth buffer

 

 

 

Stencil

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Test

 

 

 

 

 

Test

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Framebuffer

 

 

 

Framebuffer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Blending

 

 

 

Dithering

 

 

 

 

 

 

Logicop

 

 

To

 

 

 

 

(RGBA Only)

 

 

 

 

 

 

 

 

 

 

 

Framebuffer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Framebuffer

 

 

 

 

 

 

 

 

Framebuffer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 4.1. Per-fragment operations.

4.1Per-Fragment Operations

A fragment produced by rasterization with window coordinates of (xw, yw) modifies the pixel in the framebuffer at that location based on a number of parameters and conditions. We describe these modifications and tests, diagrammed in figure 4.1, in the order in which they are performed. Figure 4.1 diagrams these modifications and tests.

4.1.1 Pixel Ownership Test

The first test is to determine if the pixel at location (xw, yw) in the framebuffer is currently owned by the GL (more precisely, by this GL context). If it is not, the window system decides the fate the incoming fragment. Possible results are that the fragment is discarded or that some subset of the subsequent per-fragment operations are applied to the fragment. This test allows the window system to control the GL’s behavior, for instance, when a GL window is obscured.

Version 2.0 - October 22, 2004

4.1. PER-FRAGMENT OPERATIONS

200

4.1.2 Scissor Test

The scissor test determines if (xw, yw) lies within the scissor rectangle defined by four values. These values are set with

void Scissor( int left, int bottom, sizei width, sizei height );

If left ≤ xw < left + width and bottom ≤ yw < bottom + height, then the scissor test passes. Otherwise, the test fails and the fragment is discarded. The test is enabled or disabled using Enable or Disable using the constant SCISSOR TEST. When disabled, it is as if the scissor test always passes. If either width or height is less than zero, then the error INVALID VALUE is generated. The state required consists of four integer values and a bit indicating whether the test is enabled or disabled. In the initial state left = bottom = 0; width and height are determined by the size of the GL window. Initially, the scissor test is disabled.

4.1.3 Multisample Fragment Operations

This step modifies fragment alpha and coverage values based on the values of SAMPLE ALPHA TO COVERAGE, SAMPLE ALPHA TO ONE, SAMPLE COVERAGE, SAMPLE COVERAGE VALUE, and SAMPLE COVERAGE INVERT. No changes to the fragment alpha or coverage values are made at this step if MULTISAMPLE is disabled, or if the value of SAMPLE BUFFERS is not one.

SAMPLE ALPHA TO COVERAGE, SAMPLE ALPHA TO ONE, and

SAMPLE COVERAGE are enabled and disabled by calling Enable and Disable with cap specified as one of the three token values. All three values are queried by calling IsEnabled with cap set to the desired token value. If SAMPLE ALPHA TO COVERAGE is enabled, a temporary coverage value is generated where each bit is determined by the alpha value at the corresponding sample location. The temporary coverage value is then ANDed with the fragment coverage value. Otherwise the fragment coverage value is unchanged at this point. If multiple colors are written by a fragment shader, the alpha value of fragment color zero is used to determine the temporary coverage value.

No specific algorithm is required for converting the sample alpha values to a temporary coverage value. It is intended that the number of 1’s in the temporary coverage be proportional to the set of alpha values for the fragment, with all 1’s corresponding to the maximum of all alpha values, and all 0’s corresponding to all alpha values being 0. It is also intended that the algorithm be pseudo-random in nature, to avoid image artifacts due to regular coverage sample locations. The algorithm can and probably should be different at different pixel locations. If it

Version 2.0 - October 22, 2004

4.1. PER-FRAGMENT OPERATIONS

201

does differ, it should be defined relative to window, not screen, coordinates, so that rendering results are invariant with respect to window position.

Next, if SAMPLE ALPHA TO ONE is enabled, each alpha value is replaced by the maximum representable alpha value. Otherwise, the alpha values are not changed.

Finally, if SAMPLE COVERAGE is enabled, the fragment coverage is ANDed

with another

temporary coverage. This temporary

coverage

is

generated

in

the same

manner as the one described above,

but as a function of

the

value of

SAMPLE COVERAGE VALUE. The function

need not

be

identical,

but it must have the same properties of proportionality and invariance. If SAMPLE COVERAGE INVERT is TRUE, the temporary coverage is inverted (all bit values are inverted) before it is ANDed with the fragment coverage.

The values of SAMPLE COVERAGE VALUE and SAMPLE COVERAGE INVERT are specified by calling

void SampleCoverage( clampf value, boolean invert );

with value set to the desired coverage value, and invert set to TRUE or FALSE. value is clamped to [0,1] before being stored as SAMPLE COVERAGE VALUE. SAMPLE COVERAGE VALUE is queried by calling GetFloatv with pname set to

SAMPLE COVERAGE VALUE. SAMPLE COVERAGE INVERT is queried by calling GetBooleanv with pname set to SAMPLE COVERAGE INVERT.

4.1.4 Alpha Test

This step applies only in RGBA mode. In color index mode, proceed to the next operation. The alpha test discards a fragment conditional on the outcome of a comparison between the incoming fragment’s alpha value and a constant value. If multiple colors are written by a fragment shader, the alpha value of fragment color zero is used to determine the result of the alpha test. The comparison is enabled or disabled with the generic Enable and Disable commands using the symbolic constant ALPHA TEST. When disabled, it is as if the comparison always passes. The test is controlled with

void AlphaFunc( enum func, clampf ref );

func is a symbolic constant indicating the alpha test function; ref is a reference value. ref is clamped to lie in [0, 1], and then converted to a fixed-point value according to the rules given for an A component in section 2.14.9. For purposes of the alpha test, the fragment’s alpha value is also rounded to the nearest integer. The possible constants specifying the test function are NEVER, ALWAYS, LESS,

LEQUAL, EQUAL, GEQUAL, GREATER, or NOTEQUAL, meaning pass the fragment

Version 2.0 - October 22, 2004

4.1. PER-FRAGMENT OPERATIONS

202

never, always, if the fragment’s alpha value is less than, less than or equal to, equal to, greater than or equal to, greater than, or not equal to the reference value, respectively.

The required state consists of the floating-point reference value, an eightvalued integer indicating the comparison function, and a bit indicating if the comparison is enabled or disabled. The initial state is for the reference value to be 0 and the function to be ALWAYS. Initially, the alpha test is disabled.

4.1.5 Stencil Test

The stencil test conditionally discards a fragment based on the outcome of a comparison between the value in the stencil buffer at location (xw, yw) and a reference value. The test is enabled or disabled with the Enable and Disable commands, using the symbolic constant STENCIL TEST. When disabled, the stencil test and associated modifications are not made, and the fragment is always passed.

The stencil test is controlled with

void StencilFunc( enum func, int ref, uint mask ); void StencilFuncSeparate( enum face, enum func, int ref,

uint mask );

void StencilOp( enum sfail, enum dpfail, enum dppass ); void StencilOpSeparate( enum face, enum sfail, enum dpfail,

enum dppass );

There are two sets of stencil-related state, the front stencil state set and the back stencil state set. Stencil tests and writes use the front set of stencil state when processing fragments rasterized from non-polygon primitives (points, lines, bitmaps, image rectangles) and front-facing polygon primitives while the back set of stencil state is used when processing fragments rasterized from back-facing polygon primitives. For the purposes of stencil testing, a primitive is still considered a polygon even if the polygon is to be rasterized as points or lines due to the current polygon mode. Whether a polygon is frontor back-facing is determined in the same manner used for two-sided lighting and face culling (see sections 2.14.1 and 3.5.1).

StencilFuncSeparate and StencilOpSeparate take a face argument which can be FRONT, BACK, or FRONT AND BACK and indicates which set of state is affected. StencilFunc and StencilOp set front and back stencil state to identical values.

StencilFunc and StencilFuncSeparate take three arguments that control whether the stencil test passes or fails. ref is an integer reference value that is used in the unsigned stencil comparison. It is clamped to the range [0, 2s − 1], where s is the number of bits in the stencil buffer. The s least significant bits of

Version 2.0 - October 22, 2004

Соседние файлы в папке OpenGL