Skip to main content

Module blend

Module blend 

Source
Expand description

Blend mode pipeline variants and runtime blend-state selection.

OxiUI’s oxiui_core::paint::DrawCommand::SetBlendMode allows UI elements to be composited with custom blend operations (Multiply, Screen, Overlay, etc.). This module provides:

  • blend_state_for_mode — map a BlendMode to a wgpu::BlendState.
  • BlendPipelineSet — a set of pre-compiled solid-pass pipelines, one per supported blend mode. Switching blend modes within a frame is achieved by calling set_pipeline with the appropriate variant rather than recreating a pipeline at runtime.

§wgpu blend-state mapping

BlendModewgpu colour blend equation
NormalSrc + Dst × (1 − SrcAlpha) (standard source-over)
MultiplySrc × Dst + Dst × 0
ScreenSrc + Dst − Src × Dst (approx: Src + Dst × (1-Src))
OverlayNot directly expressible in fixed-function blend;
falls back to Normal in hardware blend mode.
Darkenmin(Src, Dst) — not expressible; falls back.
Lightenmax(Src, Dst) — not expressible; falls back.
CopySrc × 1 + Dst × 0 (replace).
DestinationSrc × 0 + Dst × 1 (no change).

Modes that require per-pixel arithmetic beyond what fixed-function hardware supports (Overlay, Darken, Lighten) fall back to Normal. A future improvement could implement them via custom fragment shader variants.

Structs§

BlendPipelineSet
A set of pre-compiled solid-pass pipeline variants, one per blend mode.

Functions§

blend_state_for_mode
Return the wgpu::BlendState that best approximates mode.