pub struct MaterialParameters { /* private fields */ }Expand description
A fixed-size, finite parameter block tied to one material’s declared layout.
Create one with ShaderMaterial::parameters. Cloning copies the values and
retains the material handle; updates never allocate or change renderer state.
Bind explicitly with ShaderMaterial::begin_checked.
Implementations§
Source§impl MaterialParameters
impl MaterialParameters
Sourcepub fn set(
&mut self,
slot: usize,
value: ParameterValue,
) -> Result<(), ParameterError>
pub fn set( &mut self, slot: usize, value: ParameterValue, ) -> Result<(), ParameterError>
Replace one slot, rejecting invalid indices, undeclared slots, wrong types and nonfinite components before changing any values.
use ferravex_render::material::{ParameterError, ParameterValue, ShaderMaterial};
let material = ShaderMaterial::new(Default::default(), Default::default())?;
let mut params = material.parameters(); // Legacy materials declare four vec4 slots.
params.set(3, ParameterValue::Vec4([1., 2., 3., 4.]))?;
assert_eq!(params.set(4, ParameterValue::Float(1.)),
Err(ParameterError::SlotOutOfRange { slot: 4 }));
assert_eq!(params.as_rows()[3], [1., 2., 3., 4.]);Sourcepub fn update(
&mut self,
updates: &[(usize, ParameterValue)],
) -> Result<(), ParameterError>
pub fn update( &mut self, updates: &[(usize, ParameterValue)], ) -> Result<(), ParameterError>
Apply all updates or leave the entire block unchanged on the first error. Repeated slots are validated in order; the last valid value wins on success. An empty update is a no-op. Storage remains bounded to four slots.
use ferravex_render::material::{ParameterError, ParameterValue, ShaderMaterial};
let material = ShaderMaterial::new(Default::default(), Default::default())?;
let mut params = material.parameters();
let before = *params.as_rows();
assert_eq!(params.update(&[
(0, ParameterValue::Vec4([1.; 4])),
(1, ParameterValue::Vec4([0., f32::NAN, 0., 0.])),
]), Err(ParameterError::NonFinite { slot: 1, component: 1 }));
assert_eq!(*params.as_rows(), before);Trait Implementations§
Source§impl Clone for MaterialParameters
impl Clone for MaterialParameters
Source§fn clone(&self) -> MaterialParameters
fn clone(&self) -> MaterialParameters
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MaterialParameters
impl !RefUnwindSafe for MaterialParameters
impl !Send for MaterialParameters
impl !Sync for MaterialParameters
impl Unpin for MaterialParameters
impl !UnwindSafe for MaterialParameters
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
Mutably borrows from an owned value. Read more