简体   繁体   English

Android的OpenGL 2.0模具缓冲区不起作用

[英]android opengl 2.0 stencil buffer not working

I'm facing very strange behaviour on my android device when I am trying to use stencil buffer feature. 当我尝试使用模板缓冲区功能时,我在Android设备上面临非常奇怪的行为。 (GLES20.glEnable(GLES20.GL_STENCIL_TEST);) (GLES20.glEnable(GLES20.GL_STENCIL_TEST))

here is my code: 这是我的代码:

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);

I got the following result: 我得到以下结果: 我的代码的结果

At first I was suspecting my code then I tried stencil example from: google stencil test and got the following result: 最初,我怀疑我的代码,然后尝试使用以下模板示例: google stencil test ,得到以下结果:

Google在我的设备上进行模版测试的结果

It looks like there is some problem with opengl and stencil buffer feature... I'm using Motorola Moto G with android 4.4.4. 看来opengl和模板缓冲功能存在一些问题...我正在将Motorola Moto G与android 4.4.4结合使用。 Is this some kind of known bug? 这是某种已知的错误吗? Is there some workaround? 有一些解决方法吗?

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. 在调用glClear(GL_STENCIL_BUFFER_BIT)清除模板缓冲区的所有位之前,必须设置模板掩码glStencilMask(0xff) Some devices might ignore stencil mask and always use 0xff when clearing stencil buffer. 某些设备可能会忽略模板掩码,并在清除模板缓冲区时始终使用0xff。 Even google's stencil test example has this bug :( 甚至谷歌的模具测试示例也有此错误:(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM