Archived

This topic is now archived and is closed to further replies.

Tree Penguin

StencilFunc ?

Recommended Posts

Tree Penguin    262
Hi, what''s the meaning of the ''ref'' argument in the glStencilFunc function, i know the first argument is the stencil test function which uses the 3rd argument (mask) for testing. Thanks in advance!

Share this post


Link to post
Share on other sites
Brother Bob    10344
The ref parameter is the reference value for the test function. For example, if the test function is < (GL_LESS), then the stencil test passes if ref<stencil. stencil is the value in the stencil buffer being tested, and both ref and stencil are masked by mask before the test.

Share this post


Link to post
Share on other sites
Tree Penguin    262
Could you give an examples on that and describe exactly what the arguments are being used for (i failed to really understand your explanation as it is something completely different from what i thought).

Thanks in advance !

Share this post


Link to post
Share on other sites
Brother Bob    10344
Let''s say you have three pixels in the frame buffer whose stencil value is 1, 2 and 3, respectively. Then you set the stencil function to GL_EQUAL, and the reference to 2, i.e. glStencilFunc(GL_EQUAL, 2, ...). The first pixel will have a value of 1, which is not equal to 2 (the reference), and the stencil test till fail. The second pixel have a stencil value of 2, and 2==2, so the stencil test passes. The test for the third pixel will fail, because 3!=2.

Now let''s say the stencil function is GL_LESS instead, i.e. glStencilFunc(GL_LESS, 2, ...). The first pixel have a value of 1, but since the reference is not less than 1, the test will fail. The second pixel have a stencil value of 2, and since the 2 is not less than 2, the test will, again, fail. The third test will pass, because the reference is less than the stencil value in the third pixel.

Share this post


Link to post
Share on other sites
Monder    993
mask(the third argument) is bitwise ANDed with both the existing stencil value and the reference value before the test takes place. It's probably best to put it as 0xffffffff

[edited by - Monder on January 18, 2004 2:03:53 PM]

Share this post


Link to post
Share on other sites