StencilGL 1.0
glStencilMask
Chooses which bits of the stencil buffer can be written; 0x00 makes it read-only.
Signature
void glStencilMask(GLuint mask);
How it works
Each written stencil value is ANDed with this mask before it is stored. 0xFF (the default) lets every bit through; 0x00 freezes the buffer, so you can test against a mask without spoiling it.
Masks with only some bits set let one stencil buffer hold several independent masks: 0x01 for one effect, 0x02 for another.
Parameters
maskGLuint
Bits that may be written. 0xFF = all (default), 0x00 = none.
Tips & pitfalls
glClearrespects this mask too: set it back to 0xFF before clearing, or the stencil buffer is not fully cleared.Do not confuse it with the mask argument of
glStencilFunc, which only selects the bits compared.
Example
example.cpp
1glStencilMask(0xFF); // allow writes, so the clear works
2glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);