PDA

View Full Version : glStencilFunc Definition



Tanji
01-02-2011, 06:08 AM
Hi all,

In the reference book for "void glStencilFunc(GLenum func,GLint ref, GLuint mask)" says that:


The reference value is compared with the value in the stencil buffer using the comparison function, but the comparison applies only to those bits for which the corresponding bits of the mask are 1.

If the stencil buffer contains s bitplanes, the low-order s bits of "mask" are bitwise ANDed with the value in the stencil buffer and with the reference value (ref) before the comparison is performed.

What am I supposed to deduce from this, if the mask is set somehow to 1 (probably from glStencilOp) then bitwise AND operator will be applied to ref value , stencil buffer and mask value, different values other than 1 for mask will be disregarded ?

Regards,

Dark Photon
01-02-2011, 02:54 PM
What am I supposed to deduce from this, if the mask is set somehow to 1 (probably from glStencilOp)...
No, glStencilOp doesn't take a mask. glStencilFunc takes an compare operation mask, and glStencilMask takes a write mask. They're talking about the glStencilFunc compare operation mask here I believe.


...then bitwise AND operator will be applied to ref value , stencil buffer and mask value, different values other than 1 for mask will be disregarded ?
Yes, or worded more precisely: different "bits" other than the 1st bit (0x1) will be disregarded. Not sure about your "for mask" reference, because you've just defined that you're passing in 1 for the compare operation mask. So it says that only the 1st bit will be used in comparisons.

The glStencilFunc man page has examples that describe exactly how this works, given different stencil test functions (also specified via glStencilFunc):


GL_NEVER Always fails
GL_LESS Passes if ( ref & mask ) < ( stencil & mask ).
GL_LEQUAL Passes if ( ref & mask ) <= ( stencil & mask ).
GL_GREATER Passes if ( ref & mask ) > ( stencil & mask ).
GL_GEQUAL Passes if ( ref & mask ) >= ( stencil & mask ).
GL_EQUAL Passes if ( ref & mask ) = ( stencil & mask ).
GL_NOTEQUAL Passes if ( ref & mask ) != ( stencil & mask ).
GL_ALWAYS Always passes.