Results 1 to 2 of 2

Thread: glStencilFunc Definition

  1. #1
    Member Newbie
    Join Date
    May 2008
    Posts
    36

    glStencilFunc Definition

    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,

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,660

    Re: glStencilFunc Definition

    Quote Originally Posted by Tanji
    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):

    Code :
           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.

Similar Threads

  1. KHR - definition
    By .black in forum Vulkan
    Replies: 2
    Last Post: 12-08-2016, 03:30 AM
  2. multiple glStencilFunc
    By bocos in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-02-2008, 02:17 AM
  3. Definition of Normals
    By in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-29-2002, 10:06 PM
  4. What's the Philosophy behind multiple glStencilFunc() parameters???
    By Olumide in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-07-2002, 07:48 AM
  5. What's the Philosophy of glStencilFunc() parameters???
    By Olumide in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-05-2002, 08:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean