how far is it possible to have or simulate multiple stencil buffers ?
…Not possible to have, there is one (hardware accelerated)stencil attachment to framebuffers. Simulate if you can write to a buffer and read simultaneously you can discard fragments based on buffer values. Not sure if this is allowed however.
What I want to do is to do some stencil stuff during a rendering and to combine the rendering with the stencil buffer with a second pass, so something like this:
void Render()
{
DoSomeStencilStuff();
Draw();
DoSomeStencilStuff2();
Draw();
}
void Draw()
{
DoSomeStencilStuff3();
DrawThings();
DoSomeStencilStuff4();
DrawThings2();
}
So, this is impossible ?
you can combine values with f.e. INCR/DECR for as long as possible (2^8 times) as long as you don’t clear the stencil buffer.
What I want to do is to do some stencil stuff during a rendering and to combine the rendering with the stencil buffer with a second pass
This is exactly the purpose of the stencil buffer, why would you want multiple stencil buffers attached to your framebuffer?
Well, I forgot to tell that I need to clear the stencil buffer between the 2 passes.
There is no problem with that, you can do it, call glClear.
So, it’s okay as long as I clear between the 2 passes. But if, for some reasons, I also need to clear between the 2 drawings (so clearing in between the 2 passes) there aren’t any solution ?
glClear gets a bitmask. You can choose to clear only color and/or depth and keep your stencil buffer intact as long as you want.