depth and stencil buffer

How can I get a copy of the depth buffer in the stencil buffer?

Im guessing but I’d say you can’t.

Depth buffer is 16/24bit and stencil buffer is (typically) 8 bit. The only way you might be able to do it is to read the depth buffer, reduce it’s precision then set each pixel in the stencil buffer individually. Which’d take a matter of hours per frame I’d expect.

And the Depth buffer is 0.0->1.0 while the stencil buffer is 0->255 AFAIK.

That’s assuming I understood your question. Why would you want to do such an operation?

ok, thanks
I found another way to render my scene in function of a zbuffer content. I draw objects from back to front with this depth function :


So only the nearest objects behind the depth value in the zbuffer are drawn.