gpt4 book ai didi

opengl - 根据模板操作,掩码如何影响模板值?

转载 作者:行者123 更新时间:2023-12-01 02:07:29 25 4
gpt4 key购买 nike

OpenGL 引用 pdf(OpenGL 3.3 和 4.5 规范)中的文档对于应用蒙版时存储的模板值会发生什么情况并不十分清楚。

例如,如果我有以下面具:

glStencilMask( 0x06);

并存储在模板缓冲区中已经有这个值:
0x06

如果模板操作是 GL_INCR_WRAP
当在该像素上正确调用 StencilOp 时会发生什么?

基本上我有面具:
00000110

和值(value)
00000110

我尝试增加它,它被包裹了吗?
00000010

还是只是归零? (00000110 + 1) & mask
00000000

最佳答案

OpenGL 4.5 core profile specification 的第 17.4.2 节“缓冲区更新的精细控制”状态:

The commands void StencilMask( uint mask ); void StencilMaskSeparate( enum face, uint mask ); control the writing of particular bits into the stencil planes. The least significant s bits of mask, where s is the number of bits in the stencil buffer, specify an integer mask. Where a 1 appears in this mask, the corresponding bit in the stencil buffer is written; where a 0 appears, the bit is not written.


glStencilMask()参数控制将哪些位平面写入模板缓冲区。它不控制读取的内容或方式 glStencilOp运作。

第 17.3.5 节“模板测试”指出(我的重点):

For purposes of increment and decrement, the stencil bits are considered as an unsigned integer. Incrementing or decrementing with saturation clamps the stencil value at 0 and the maximum representable value. Incrementing or decrementing without saturation will wrap such that incrementing the maximum representable value results in 0, and decrementing 0 results in the maximum representable value.



模板掩码本身在管道的那个阶段不相关。它仅在片段最终写入帧缓冲区时应用,就像所有 gl*Mask() 一样。职能。

因此具有值 0110在缓冲区中并应用 GL_INCR_WRAP导致 0111当写入缓冲区时,会应用掩码,因此您基本上会得到 0110再次(而不是 0)。

另请注意,还有一个 mask glStencilFunc() 中的参数定义在模板测试之前应用的位掩码。再次引用第 17.3.5 节:(我的重点):

StencilFunc and StencilFuncSeparate take three arguments that control whether the stencil test passes or fails. ref is an integer reference value that is used in the unsigned stencil comparison. Stencil comparison operations and queries of ref clamp its value to the range [0; 2^s - 1], where s is the number of bits in the stencil buffer attached to the draw framebuffer. The s least significant bits of mask are bitwise ANDed with both the reference and the stored stencil value, and the resulting masked values are those that participate in the comparison controlled by func.



因此,如果您想在某个值 2^n-1 处环绕 a,您可以简单地忽略模板缓冲区中的其他位,并在模板测试中测试这些位。

关于opengl - 根据模板操作,掩码如何影响模板值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31346733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com