What I'm trying to achieve is illustrated on the image below:
Let's say we have stencil buffer in a state so only red section is filled at the moment. What actions do I need to perform when I update stencil buffer with a section which is marked yellow, so in the end only green section would be the final state of the stencil buffer?
I need this to achieve nested element content clipping, to prevent content of the element to be rendered beyond the boundaries of them both combined.
So far I have tried various boolean operations involving stencil test to no avail, which brought more confusion than any progress.
Please note that scissor test is not actual for this task, because elements may have arbitrary shape and rotation.