Struct ShaderMaterial

Source
pub struct ShaderMaterial(/* private fields */);

Implementations§

Source§

impl ShaderMaterial

Source

pub fn new( source: ShaderSource, options: MaterialOptions, ) -> Result<ShaderMaterial, &'static str>

Validates storage/metadata. Actual shader compilation occurs when presented by a GPU host. Checked parameter blocks from this constructor use four ParameterType::Vec4 slots.

Source

pub fn new_with_layout( source: ShaderSource, options: MaterialOptions, parameter_layout: [Option<ParameterType>; 4], ) -> Result<ShaderMaterial, &'static str>

Declare how shader hooks consume each existing u_params slot. None reserves an unused, zero-filled slot in checked parameter blocks.

This is an author-declared contract, not shader reflection or compilation. It remains fixed across Self::reload; create a new material when changing the contract. The legacy Self::begin accepts raw rows without checking types.

use ferravex_render::material::{ParameterType, ParameterValue, ShaderMaterial, ShaderSource};
let material = ShaderMaterial::new_with_layout(
    ShaderSource::fragment(r#"
        vec4 ferravex_fragment(vec4 color, vec3 world, vec3 normal) {
            return vec4(color.rgb * u_params[1].xyz, color.a * u_params[0].x);
        }
    "#),
    Default::default(),
    [Some(ParameterType::Float), Some(ParameterType::Vec3), None, None],
)?;
assert_eq!(material.parameter_layout()[0], Some(ParameterType::Float));
let mut params = material.parameters();
params.set(0, ParameterValue::Float(0.5))?;
params.set(1, ParameterValue::Vec3([1., 0.8, 0.6]))?;
material.begin_checked(&params)?;
// Retained mesh draws here capture these parameter values.
material.end();
Source

pub fn id(&self) -> u32

Source

pub fn status(&self) -> MaterialStatus

Source

pub fn parameter_layout(&self) -> [Option<ParameterType>; 4]

Return the immutable authored slot contract; see Self::new_with_layout.

Source

pub fn parameters(&self) -> MaterialParameters

Create a zero-filled, independent parameter block bound to this material. Clones of this shader handle accept the same block; another material cannot. The block retains this handle and its registry slot until dropped. See Self::new_with_layout for an example.

Source

pub fn begin_checked( &self, params: &MaterialParameters, ) -> Result<(), ParameterError>

Bind checked values, preserving the active shader and values on a material mismatch. Does not require or imply GPU compilation; existing pending/fallback behavior applies. Updating the block after binding does not change the active values until bound again.

use ferravex_render::material::{ParameterError, ShaderMaterial};
let a = ShaderMaterial::new(Default::default(), Default::default())?;
let b = ShaderMaterial::new(Default::default(), Default::default())?;
let params = a.parameters();
a.clone().begin_checked(&params)?;
assert_eq!(b.begin_checked(&params), Err(ParameterError::MaterialMismatch {
    expected: b.id(), provided: a.id(),
}));
a.end();
Source

pub fn reload(&self, source: ShaderSource) -> Result<u32, &'static str>

Queue a source replacement. Bad metadata leaves the request unchanged; GPU errors retain each host’s last valid program. The latest request is applied at presentation time. Checked parameter layouts are immutable: authored replacements must keep the same contract.

Source

pub fn begin(&self, params: [[f32; 4]; 4]) -> Result<(), &'static str>

Bind raw ABI rows after a finite-value check, preserving the active binding on failure. This compatibility API does not enforce the layout; use Self::begin_checked for that.

Source

pub fn end(&self)

Trait Implementations§

Source§

impl Clone for ShaderMaterial

Source§

fn clone(&self) -> ShaderMaterial

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.