问题描述
OpenGL参考pdf(OpenGL 3.3和4.5规范)中的文档对于应用蒙版时存储的模具值会发生什么不太清楚.
The documentation in OpenGL reference pdf (both OpenGL 3.3 and 4.5 specs) is not much clear about what happens to the stored stencil value when a mask is applied.
在示例中,如果我有以下遮罩:
In example If I have the following mask:
glStencilMask( 0x06);
并存储在模板缓冲区中已经有该值:
and stored in the stencil buffer there is already this value:
0x06
如果模具操作为GL_INCR_WRAP
在该像素上正确调用StencilOp时会发生什么?
what should happens when StencilOp is correctly invoked on that pixel?
基本上我有面具:
00000110
和值
00000110
然后我尝试增加它,是否包裹好了?
and I try to increment it, is it wrapped?
00000010
还是只是归零? (00000110 + 1) & mask
00000000
推荐答案
glStencilMask()
参数控制将哪些位平面写入到模板缓冲区.它不控制读取的内容或glStencilOp
的操作方式.
The glStencilMask()
parameter controls which bit planes are written to the stencil buffer. It does not control what is read, or how glStencilOp
operates.
第17.3.5节模版测试"指出(我的重点):
Section 17.3.5 "Stencil Test" states (my emphasis):
模板掩码本身与管道的那个阶段无关.像所有gl*Mask()
函数一样,仅当片段最终写入帧缓冲区时才应用它.
The stencil mask itself is not relevant in that stage of the pipeline. It is only applied when the fragment is finally written to the framebuffer, like all gl*Mask()
functions.
因此在缓冲区中具有值0110
并应用GL_INCR_WRAP
会导致0111
,并且在写入缓冲区时,将应用掩码,因此您基本上再次以0110
结尾(而不是0) ).
So having the value 0110
in the buffer and applying GL_INCR_WRAP
leads to 0111
and when this is written the buffer, the mask is applied, so you basically end up with 0110
again (and not 0).
还请注意,在glStencilFunc()
中还有一个mask
参数,用于定义在模板测试之前要应用的位掩码.再次引用第17.3.5节:(我的重点):
Also note that there is also a mask
parameter in glStencilFunc()
defining a bit mask to be applied before the stencil test. Quoting section 17.3.5 again: (my emphasis):
因此,如果要以2 ^ n-1的值换行,则可以简单地忽略模板缓冲区中的其他位,而只需在模板测试中测试这些位.
So if you want to wrap around a at some value 2^n-1, you can simply ignore the additional bits in the stencil buffer and just test these bits in the stencil test.
这篇关于根据模板操作,遮罩如何影响模板值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!