How to access the Stencil Buffer using C++? [Portals]

Thanks for pointing me to this thread.
I actually experimented with CustomDepth and CustomStencil but I never had the idea to put it on the actual mesh.

Also thanks for uploading your solution.
I’ll try it later and report back then!