A stencil buffer is an extra data buffer, in addition to the color buffer and Z-buffer, found on modern graphics hardware. The buffer is per pixel and works on integer values, usually with a depth of
In this image, there are white regions and black regions, representing 1s and 0s in the stencil buffer respectively. Shapes are then drawn on top of the stripes by inverting the value of the stencil buffer. If the buffer at that pixel has a value of 0 (black), color the pixel white (1) and vice versa.