Skip to main content

Module stencil

Module stencil 

Source
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

  1. Create a depth + stencil texture (Depth24PlusStencil8) alongside the colour target.
  2. A stencil-fill pass renders the clip geometry into the stencil buffer (colour writes disabled) with StencilOperation::Replace. The reference value is 1.
  3. The content pass renders normally but with a stencil test: only pixels where the stencil value equals 1 pass.
  4. 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_count as the colour target.

Structs§

StencilClipState
Tracks the current stencil clip depth.
StencilTarget
Owns the depth+stencil texture and view for one render target.
StencilWritePipeline
A render pipeline variant that writes to the stencil buffer.

Constants§

DEPTH_STENCIL_FORMAT
The depth+stencil format used for stencil-based clipping.