I'm writing a 2D UI library with OpenGL. Now, I want to make parent view clips it's children by "Stencil Test", I need test it's parent layer value, and write the layer value belong it self for next test.
For example test 0, and write 1. test 0, write 2.
Is there any way to do that? Or I can't use "Stencil Test" to solve my problem? If I can't use this, Any one have a good idea to solve my problem? Thanks a lot.
How can I write a different value to "Stencil Buffer"?
Addition: Like the picture below, I draw the three rect with three step. I first draw the red rect with stencil test 0 less or equal to the value in stencil buffer(After now,I will only show the value) and write 0 value. Second, draw the green rect with stencil test 0 and write 1. Third, draw blue rect with stencil test 0 and write 2.