Four commands are used to mask the writing of bits to each of the logical framebuffers after all per-fragment operations have been performed. The commands
void IndexMask ( uint mask ) ;
void ColorMask ( boolean r, boolean g, boolean b, boolean a ) ;
control the color buffer or buffers (depending on which buffers are currently indicated for writing). The least significant n bits of mask, where n is the number of bits in a color index buffer, specify a mask. Where a 1 appears in this mask, the corresponding bit in the color index buffer (or buffers) is written; where a 0 appears, the bit is not written. This mask applies only in color index mode. In RGBA mode, ColorMask is used to mask the writing of R, G, B and A values to the color buffer or buffers. r, g, b, and a indicate whether R, G, B, or A values, respectively, are written or not (a value of TRUE means that the corresponding value is written). In the initial state, all bits (in color index mode) and all color values (in RGBA mode) are enabled for writing.
The depth buffer can be enabled or disabled for writing values using
void DepthMask ( boolean mask ) ;
If mask is non-zero, the depth buffer is enabled for writing; otherwise, it is disabled. In the initial state, the depth buffer is enabled for writing.
void StencilMask ( uint mask ) ;
controls the writing of particular bits into the stencil planes. The least significant s bits of mask comprise an integer mask (s is the number of bits in the stencil buffer), just as for IndexMask . The initial state is for the stencil plane mask to be all ones.
The state required for the various masking operations is two integers and a bit: an integer for color indices, an integer for stencil values, and a bit for depth values. A set of four bits is also required indicating which color components of an RGBA value should be written. In the initial state, the integer masks are all ones as are the bits controlling depth value and RGBA component writing.