pub struct ShaderProgram { /* private fields */ }Expand description
A runtime fragment-shader program (WGSL source) — the Frust analog of
Flutter’s FragmentProgram.
This is a renderer contract, not a scene-layer dependency: the WGSL
source is carried here as an opaque string (precedent:
frust_theme::GlassMaterial::blur_radius_intent, a future-backend
contract that is likewise plain data rather than a compiled resource) —
only the render backend compiles it into a GPU pipeline.
Alpha contract: the shader’s output is taken as premultiplied —
the convention every paint in a Frust frame travels in. A shader returning
vec4(rgb, a) must have already multiplied rgb by a; the result is
composited over what is behind it, so a translucent or fully transparent
fragment shows the scene beneath rather than black. Opaque output
(a = 1.0) is unaffected by the convention and needs nothing done to it.
Implementations§
Source§impl ShaderProgram
impl ShaderProgram
Sourcepub fn new(wgsl: impl Into<Arc<str>>) -> Self
pub fn new(wgsl: impl Into<Arc<str>>) -> Self
Wraps wgsl in a new program handle, minting a fresh process-unique
id.
Clone shares the id — see the id field’s doc comment.
§Cache-once contract
Call this once per distinct shader and retain (or Clone) the
result — never mint a fresh ShaderProgram every frame or rebuild.
The renderer’s shader-effects engine compiles and caches a GPU
pipeline keyed by id(): a fresh id every frame is a
permanent cache miss, forcing a full pipeline recompile (plus
target/registration churn) every single frame instead of the
intended compile-once-then-reuse cost.
Create it once in retained state — a Component’s init, or other
Widget/View state built once and reused — and clone the handle
(cheap: an Arc handle copy, sharing the id) wherever it’s drawn
thereafter. A View’s own build method is a correct create-once
hook too: it constructs the retained widget exactly once, so minting
a program there is fine. Do not call ShaderProgram::new inline
inside a widget’s paint method (runs every frame) or inside a
Component’s build (re-runs every rebuild) — both mint a new id on
every call. See examples/shadertoy/src/shaders.rs’s all() for the
reference pattern: a registry built once and reused.