Expand description
Stencil-buffer clipping for non-rectangular clip paths.
Rectangular scissors are already handled by the hardware set_scissor_rect
API (see exec.rs and geometry.rs). This module provides stencil-based
clipping for non-rectangular shapes: rounded-rectangle clip masks,
arbitrary path clip masks, and ellipses.
§Strategy
- Create a depth + stencil texture (
Depth24PlusStencil8) alongside the colour target. - A stencil-fill pass renders the clip geometry into the stencil buffer
(colour writes disabled) with
StencilOperation::Replace. The reference value is 1. - The content pass renders normally but with a stencil test: only pixels where the stencil value equals 1 pass.
- A stencil-clear pass resets the stencil to 0 when the clip is popped.
§Limitations
- Nested non-rectangular clips are supported by incrementing the stencil reference value up to 255 (hardware limit).
- Interaction with MSAA: the depth/stencil texture must use the same
sample_countas the colour target.
Structs§
- Stencil
Clip State - Tracks the current stencil clip depth.
- Stencil
Target - Owns the depth+stencil texture and view for one render target.
- Stencil
Write Pipeline - A render pipeline variant that writes to the stencil buffer.
Constants§
- DEPTH_
STENCIL_ FORMAT - The depth+stencil format used for stencil-based clipping.