ursus_materials/layout.rs
1use crate::material::MaterialHandle;
2use crate::strategy::ShadingStrategy;
3use crate::value::MaterialValue;
4
5/// Consumes resolved material values and decides how they are laid out in
6/// memory - as a single array-of-structs blob (see the `pack::aos` module),
7/// as per-field structure-of-arrays buffers, or otherwise. `ShadingStrategy`
8/// describes what fields exist and what their values are; `MaterialLayout`
9/// decides where those values live.
10pub trait MaterialLayout: Send + Sync {
11 /// Prepares this layout to store values for `strategy`'s fields. Called
12 /// once per strategy, before any `upload` for a material using it.
13 fn register_strategy(&mut self, strategy: &dyn ShadingStrategy);
14
15 /// Writes `values` (as resolved by `strategy.resolve()`, in
16 /// `strategy.fields()` order) into this layout's storage for `handle`.
17 fn upload(&mut self, handle: MaterialHandle, strategy: &dyn ShadingStrategy, values: &[MaterialValue]);
18}