PDA

View Full Version : put value in the stencil buffer



jaketehsnake
08-20-2015, 02:55 AM
So, I've got a FBO with a stencil buffer. How do I put values in the stencil buffer with modern openGL (just shaders).

Let's say I have a trangle or quad I want to render to the stencil buffer with value V. How would I go about that? Do I need a specific shader? There's no specific openGl command that lets you just write values without a shader? kind of like glScissors?

GClements
08-20-2015, 05:04 AM
Let's say I have a triangle or quad I want to render to the stencil buffer with value V. How would I go about that?
Use glStencilFunc(GL_ALWAYS, V, ~0U) to set the reference value to V, glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE) to cause the reference value to be copied to the stencil buffer when the depth and stencil tests pass, then draw the primitives.

It doesn't matter whether shaders are used as a shader cannot directly affect stencil buffer updates.