Then the stencil operation associated with the stencil test failing is applied to that stencil value. If the depth test passes, the fragment continues on the pixel pipeline, and the stencil operation corresponding to both stencil and depth passing is applied to the stencil value for that pixel, if the depth test fails, the stencil operation set for stencil passing but depth failing is applied to the pixel's stencil value. Thus the stencil buffer both applies tests to control which fragments get to continue towards the frame buffer, and is updated by the results of those tests, in concert with the results of the depth buffer tests. This allows an application to apply stencil tests without the results affecting the stencil values. There are two other important ways of controlling the stencil buffer.
Different machines support a different number of stencil bits per pixel.
This allows the application to store the stencil values of different tests separately within the same stencil value.