use std::collections::HashMap;
use std::sync::{Arc, Mutex, OnceLock};
use crate::RenderTier;
#[derive(Debug, Clone)]
pub struct Material {
pub name: String,
pub min_tier: RenderTier,
pub shader_id: String,
pub params: HashMap<String, f32>,
}
pub struct MaterialRegistry {
materials: HashMap<String, Material>,
}
static REGISTRY: OnceLock<Arc<Mutex<MaterialRegistry>>> = OnceLock::new();
impl Default for MaterialRegistry {
fn default() -> Self {
Self::new()
}
}
impl MaterialRegistry {
pub fn new() -> Self {
let mut registry = Self {
materials: HashMap::new(),
};
registry.register_defaults();
registry
}
pub fn global() -> Arc<Mutex<Self>> {
REGISTRY.get_or_init(|| Arc::new(Mutex::new(Self::new()))).clone()
}
fn register_defaults(&mut self) {
self.register(Material {
name: "bifrost_standard".to_string(),
min_tier: RenderTier::Tier1GPU,
shader_id: "bifrost".to_string(),
params: [("blur".to_string(), 20.0)].into(),
});
self.register(Material {
name: "gungnir_neon".to_string(),
min_tier: RenderTier::Tier2GPU,
shader_id: "gungnir".to_string(),
params: [("glow".to_string(), 10.0)].into(),
});
}
pub fn register(&mut self, material: Material) {
self.materials.insert(material.name.clone(), material);
}
pub fn get(&self, name: &str) -> Option<&Material> {
self.materials.get(name)
}
}