In android opengl es 2.0 I'm drawing scene by standard renderer (implements GLSurfaceView.Renderer)
@Override
public void onDrawFrame(GL10 gl10)
{
GLES20.glEnable(GLES20.GL_STENCIL_TEST);
GLES20.glClearStencil(1);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_STENCIL_BUFFER_BIT);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
glStencilMask(0x00);
shaderTexture2.useProgram();
GLES20.glStencilOp(GLES20.GL_KEEP, GLES20.GL_KEEP, GLES20.GL_REPLACE);
GLES20. glStencilFunc(GLES20.GL_ALWAYS, 1, 0xFF);
GLES20.glStencilMask(0xFF);
//1 step. draw red triangle
shaderTexture2.draw(buf_slim, mvp, mLightPosInEyeSpace, tex1);
GLES20.glStencilFunc(GLES20.GL_NOTEQUAL, 1, 0xFF);
GLES20.glStencilMask(0x00);
//2 step. draw blue triangle
shaderTexture2.draw(buf_big, mvp, mLightPosInEyeSpace, tex1);
GLES20.glStencilMask(0xFF);
}
If in first line of method turn off stencil (for examle comment GLES20.glEnable(GLES20.GL_STENCIL_TEST);) then both triangles draws( first pic).If stencil turned on then I'm expect at step 1 that at drawing red triangle stencil buffer will be filled with ones, and at step 2 blue triangle will be cuted only in area where was ones from first step (second pic). Instead when stencil turned on simply drawing full red triangle, without any blue triangle (third pic). When and which funcs and masks of stencil I should use to draw as i expect?


