Skip to main content

ShaderProgram

Struct ShaderProgram 

Source
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

Source

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.

Source

pub fn id(&self) -> u64

The process-unique id, stable across Clone.

Source

pub fn source(&self) -> &str

The WGSL fragment source.

Trait Implementations§

Source§

impl Clone for ShaderProgram

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShaderProgram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.