OpenGL ES2.0将8位图像加载到模板缓冲区

时间:2014-07-19 12:46:56

标签: opengl-es

我正在学习OpenGL ES2.0。我的项目中需要一个模板缓冲区。

What I am going to do:
1) Create a stencil buffer.
2) Load a 8-bit gray color image into this stencil buffer (which is also 8-bit per pixel).
3) The gray color image has different area (by setting different part a different value),       so I can render for each area by changing the stencil test value.

我已经搜索了很多时间,仍然不知道如何将图像加载到模板缓冲区。

enter image description here Image 2

因此,对于上图,我将蓝色区域的模板值设置为1,并为绿色区域设置2。如何实现这个?

1 个答案:

答案 0 :(得分:1)

如果您的位图是1位,只需编写一个着色器discard s或允许像素继续进行alpha测试,或者如果在固定管道下使用glAlphaFunc做同样的事情,并使用适当的glStencilFunc绘制合适的四边形。

如果它是8位并且你真的希望所有8个转移到模板,那么我能想到的最好的跨平台解决方案要么涉及8次绘制 - 从0开始,使用glStencilMask来隔离单个位,将glStencilOp设置为反转,在着色器中的相关位中测试非零 - 或者仅使用常规纹理并在着色器中直接执行模板测试。

相关问题