View Full Version : Issue with stencil buffer

10-16-2014, 05:46 AM
Hi.I am working on Linux environment and I am using OpenGLES2.0. My target GPU is Fujitsu Ruby MB86298 . I am developing a small application using stencil buffer. It works perfectly but its rendering 4 small primitives which are in shape of the stencil pattern,I mention in the code.If stencil pattern is circle ,the it renders 4 small dark circles on the screen ,if stencil pattern is square it draws four small squares.This problem happens when I run the code in a loop.If the code is run only for one time I am not getting those small primitives.Kindly please help me to solve this problem.

10-16-2014, 06:37 AM
There is flickering with ghost image of the stencil

carsten neumann
10-16-2014, 06:47 AM
I'm afraid I don't really understand your problem description, perhaps you could post a pseudo code description showing your stencil test settings and the general steps you are doing? Since you mentioned it only happens when running things in a loop, as a random guess: are you perhaps not clearing the stencil buffer between frames or steps of your algorithm?

10-17-2014, 01:51 AM

glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1
glStencilMask(0xFF); // Write to stencil buffer
glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default)

/*** Draw Stencil pattern *******/
draw_stencil pattern();

glStencilFunc(GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1
glStencilMask(0x00); // Don't write anything to stencil buffer
glDepthMask(GL_TRUE); // Write to depth buffer
/*********************** draw actual network ************************/

There is flickering of ghost images of stencil pattern when I execute the above piece of code in a loop

carsten neumann
10-17-2014, 04:11 AM
Thanks, that makes it clearer to me what you are doing :) - please use
around source snippets to preserve formatting.

Hmm, unfortunately I don't see what could be the problem here. Is the depth test enabled for the whole duration of the posted code? When is the depth buffer cleared with respect to the above, e.g. before the shown part?

10-17-2014, 06:30 AM
depth color and stencil buffer bits are cleared in every run of the loop using glClear(). I read somewhere that stencils doesn't work properly on few GPU's.The same piece of code is working properly on inte(R) HD graphics but its not working properly on ruby.When I checked the errata of the graphic card (refer E17), they suggest to use flush command before setting the masks,but it didn't give the desired output.http://www.fujitsu.com/downloads/MICRO/fme/displaycontrollers/es-mb86298-rev1-21.pdf