Products are grouped together so that as many partial products can be rendered between depth buffer saves and restores as the stencil buffer has capacity. For each group, writes to the color buffer are disabled, the contents of the depth buffer are saved, and the depth buffer is cleared. Then, every target in the group is classified against its trimming primitives. The depth buffer is then restored, and every target in the group is rendered against the trimming mask. In practice, most CSG primitives are convex, so the algorithm is optimized for that case.
Depth testing is enabled and writes to the depth buffer are disabled.
Stencil operations are masked to and the bit in the stencil is cleared to 0. The stencil function and operation are set so that is toggled every time the depth test for a fragment from the trimming primitive succeeds. The bit for that primitive is set to 1 everywhere that the depth value for a pixel is not equal to , and 0 otherwise. Each target primitive in the group is finally rendered into the framebuffer with depth testing and depth writes enabled, the color buffer enabled, and the stencil function and operation set to write depth and color only where the depth test succeeds and is 1. Only the pixels inside the volumes of all the trimming primitives are drawn.