Search code examples
openglglsl

What is the role of mask parameter in glStencilFunc


In the function

glStencilFunc(GLenum func, GLint ref, GLuint mask)

what is the role of mask , we are sending the ref value and the buffer content is being compared to the ref value than why do we need to send mask value ?

what i read about the mask value is "mask that is ANDed with both the reference value and the stored stencil value" but why do we need that?


Solution

  • It all depends on what you're doing with the stencil. Some stencil operations treat the stencil value as just an integer, incrementing and/or decrementing the stencil value for some effect or purpose. Other operations use it as a bitmask, where each bit or group of bits in the stencil value represents something in particular. That is, from a semantic perspective, you have multiple values that just so happen to be stored in the same 8 bits of space.

    The mask value is for cases like that. You might have 8 separate masking regions, and you want to render some geometry against one of the region. You use the mask parameter to specify which bit (that specifies a region) to mask off a piece of geometry.