I'm using the stencil buffer for two jobs. The first is to allow masking to happen, and the second is to write masks for objects that can be 'seen' through. In this particular case, the reserved bit is 0x80
, the very last bit in the byte, with the rest left for regular masking.
The first purpose requires that the buffer be cleared after around 127 uses, or else past stencils will become "valid" again when testing, since the value must wrap back to 1. The second purpose requires the reserved bits in the buffer to stay alive through the entire frame.
Is there any way to clear the entire stencil buffer, while keeping the reserved bits set?
Your theory in the comment is correct.
glStencilMask()
is applied to the values written byglClear()
andglClearBuffer()
.From section "17.4.3 Clearing the Buffers" in the OpenGL 4.5 spec (emphasis added):
Where section 17.4.2 is titled "Fine Control of Buffer Updates", and includes the documentation of
glStencilMask()
. ForglStencilMaskSeparate()
, which is a more general version ofglStencilMask()
, it even says explicitly:So to clear the bottom 7 bits of the stencil buffer, you can use: