什么相当于 Metal 中的 glStencilFunc?

What the equivalent of glStencilFunc in Metal?

如何在金属中翻译这条 OpenGL 指令:

glStencilFunc(Func, Ref, Mask);

MTLStencilDescriptor 定义深度和模板状态对象的正面或背面模板操作的对象。

A stencil test is a comparison between a masked reference value and a masked value stored in a stencil attachment. (A value is masked by performing a logical AND operation on it with the readMask value.) The MTLStencilDescriptor object defines how to update the contents of the stencil attachment, based on the results of the stencil test and the depth test.

The stencilCompareFunction property defines the stencil test. The stencilFailureOperation, depthFailureOperation, and depthStencilPassOperation properties specify what to do to a stencil value stored in the stencil attachment for three different test outcomes: if the stencil test fails, if the stencil test passes and the depth test fails, or if both stencil and depth tests succeed, respectively. writeMask determines which stencil bits can be modified as the result of a stencil operation.


I see where to put the value of Func and Mask with MTLStencilDescriptor, but where go the value of REF ?

setStencilReferenceValue 为正面和背面模板比较测试设置模板参考值。