pub trait ShadingStrategy: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn requirements(&self) -> &Requirements;
fn fields(&self) -> &[FieldDesc];
fn resolve(
&self,
material: &Material,
) -> Result<Vec<MaterialValue>, MaterialError>;
// Provided method
fn validate(&self, material: &Material) -> Result<(), MaterialError> { ... }
}Expand description
Interprets a Material’s properties for a specific way of shading it.
A strategy describes what GPU fields it needs (fields) and how to
resolve each one from a material (resolve); it does not decide how
those fields are laid out in memory - that is the responsibility of a
separate packing module (see pack::aos) that consumes both methods.
Custom strategies are ordinary implementations of this trait, registered
into a StrategyRegistry - no changes to ursus-materials are needed to
add one.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable name used for lookup in StrategyRegistry and stored on
Material::strategy.
Sourcefn requirements(&self) -> &Requirements
fn requirements(&self) -> &Requirements
What this strategy needs from a material to be able to resolve it.
Sourcefn fields(&self) -> &[FieldDesc]
fn fields(&self) -> &[FieldDesc]
The fields this strategy produces, in a fixed order. resolve()
returns one value per field, in this same order.
Sourcefn resolve(
&self,
material: &Material,
) -> Result<Vec<MaterialValue>, MaterialError>
fn resolve( &self, material: &Material, ) -> Result<Vec<MaterialValue>, MaterialError>
Resolves this material’s value for every field in fields(),
applying this strategy’s own fallbacks for missing properties.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".