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>>) -> ShaderProgram
pub fn new(wgsl: impl Into<Arc<str>>) -> ShaderProgram
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.
Trait Implementations§
Source§impl Clone for ShaderProgram
impl Clone for ShaderProgram
Source§fn clone(&self) -> ShaderProgram
fn clone(&self) -> ShaderProgram
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ShaderProgram
impl RefUnwindSafe for ShaderProgram
impl Send for ShaderProgram
impl Sync for ShaderProgram
impl Unpin for ShaderProgram
impl UnsafeUnpin for ShaderProgram
impl UnwindSafe for ShaderProgram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.