pub struct MaterialManager {
pub max_frames_not_used: usize,
/* private fields */
}Expand description
Manages compiled GPU materials (shaders), caching them by fragment source.
Equivalent to TextureManager but for materials. The renderer creates and uses
this to avoid recompiling shaders every frame.
Also holds a runtime shader storage (name → source) for [ShaderAsset::Stored]
shaders. Update stored sources with set_source; the old
compiled material is evicted automatically when the source changes.
Fields§
§max_frames_not_used: usizeHow many frames a material can go unused before being evicted.
Implementations§
Source§impl MaterialManager
impl MaterialManager
pub fn new() -> Self
Sourcepub fn get_or_create(&mut self, config: &ShaderConfig) -> &Material
pub fn get_or_create(&mut self, config: &ShaderConfig) -> &Material
Get or create a material for the given shader config. The material is cached by fragment source string.
Sourcepub fn set_source(&mut self, name: &str, fragment: &str)
pub fn set_source(&mut self, name: &str, fragment: &str)
Store or update a named shader source.
If the source changed compared to the previously stored value, the old compiled material is evicted from the cache so the next render pass recompiles automatically. No-ops if the source is unchanged.
Sourcepub fn get_source(&self, name: &str) -> Option<&str>
pub fn get_source(&self, name: &str) -> Option<&str>
Look up a stored shader source by name.