pub struct ShaderMaterial(/* private fields */);Implementations§
Source§impl ShaderMaterial
impl ShaderMaterial
Sourcepub fn new(
source: ShaderSource,
options: MaterialOptions,
) -> Result<ShaderMaterial, &'static str>
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.
Sourcepub fn new_with_layout(
source: ShaderSource,
options: MaterialOptions,
parameter_layout: [Option<ParameterType>; 4],
) -> Result<ShaderMaterial, &'static str>
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(¶ms)?;
// Retained mesh draws here capture these parameter values.
material.end();pub fn id(&self) -> u32
pub fn status(&self) -> MaterialStatus
Sourcepub fn parameter_layout(&self) -> [Option<ParameterType>; 4]
pub fn parameter_layout(&self) -> [Option<ParameterType>; 4]
Return the immutable authored slot contract; see Self::new_with_layout.
Sourcepub fn parameters(&self) -> MaterialParameters
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.
Sourcepub fn begin_checked(
&self,
params: &MaterialParameters,
) -> Result<(), ParameterError>
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(¶ms)?;
assert_eq!(b.begin_checked(¶ms), Err(ParameterError::MaterialMismatch {
expected: b.id(), provided: a.id(),
}));
a.end();Sourcepub fn reload(&self, source: ShaderSource) -> Result<u32, &'static str>
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.
Sourcepub fn begin(&self, params: [[f32; 4]; 4]) -> Result<(), &'static str>
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.
pub fn end(&self)
Trait Implementations§
Source§impl Clone for ShaderMaterial
impl Clone for ShaderMaterial
Source§fn clone(&self) -> ShaderMaterial
fn clone(&self) -> ShaderMaterial
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more