问题描述
当我尝试使用模板缓冲功能时,我在android设备上面临非常奇怪的行为. (GLES20.glEnable(GLES20.GL_STENCIL_TEST);)
I'm facing very strange behaviour on my android device when I am trying to use stencil buffer feature. (GLES20.glEnable(GLES20.GL_STENCIL_TEST);)
这是我的代码:
GLES20.glEnable(GLES20.GL_STENCIL_TEST);
GLES20.glStencilFunc(GLES20.GL_GEQUAL, 1, 0xff);
GLES20.glStencilOp(GLES20.GL_KEEP, GLES20.GL_INCR, GLES20.GL_INCR);
GLES20.glStencilMask(0xff);
m_index_buffer.position(start_index);
GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP,
n_indicies,
GLES20.GL_UNSIGNED_SHORT,
m_index_buffer);
GLES20.glDisable(GLES20.GL_STENCIL_TEST);
我得到以下结果:
起初,我怀疑自己的代码,然后尝试从以下位置访问模板示例: google模具测试一个>并得到以下结果:
At first I was suspecting my code then I tried stencil example from:google stencil testand got the following result:
opengl和模板缓冲功能似乎存在一些问题...我在Android 4.4.4中使用Motorola MotoG.这是某种已知的错误吗?有什么解决方法吗?
It looks like there is some problem with opengl and stencil buffer feature...I'm using Motorola Moto G with android 4.4.4.Is this some kind of known bug?Is there some workaround?
推荐答案
问题是模板缓冲区未正确清除.在调用glClear(GL_STENCIL_BUFFER_BIT)
清除模板缓冲区的所有位之前,必须设置模板掩码glStencilMask(0xff)
.某些设备可能会忽略模板掩码,并在清除模板缓冲区时始终使用0xff.甚至Google的模具测试示例也有以下错误:(
The problem was that the stencil buffer wasn't cleared correctly. It is necessary to set stencil mask glStencilMask(0xff)
before calling glClear(GL_STENCIL_BUFFER_BIT)
to clear all bits of stencil buffer. Some devices might ignore stencil mask and always use 0xff when clearing stencil buffer. Even google's stencil test example has this bug :(
这篇关于android opengl 2.0模具缓冲区不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!