If the stencil test passes, then the depth test is applied. 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 test controls which fragments continue towards the framebuffer, and the stencil operation controls how the stencil buffer is updated by the results of both the stencil test and the depth test. This allows an application to apply stencil tests without the results affecting the stencil values. There are three other important ways of controlling and accessing the stencil buffer.
Different machines support different numbers of stencil bits per pixel.
This allows the application to store separate stencil values per pixel within the same stencil buffer.