use crate::define_store;
use crate::errors::AleaticoResult;
use crate::renderer::resources::pipelines::PipelineId;
use crate::renderer::resources::texture::TextureId;
define_store!(Material);
#[derive(Debug, Clone)]
pub struct MaterialDescriptor {
pub label: Option<String>,
pub textures: MaterialTextures,
}
#[derive(Debug, Default, Clone)]
pub struct MaterialTextures {
pub albedo: Option<TextureId>,
pub normal: Option<TextureId>,
}
impl MaterialDescriptor {
pub fn new() -> Self {
Self {
label: None,
textures: MaterialTextures::default(),
}
}
pub fn textured(albedo: TextureId) -> Self {
Self {
textures: MaterialTextures {
albedo: Some(albedo),
..MaterialTextures::default()
},
..Self::new()
}
}
pub fn with_label(mut self, label: impl Into<String>) -> Self {
self.label = Some(label.into());
self
}
pub fn with_albedo(mut self, texture: TextureId) -> Self {
self.textures.albedo = Some(texture);
self
}
pub fn with_normal(mut self, texture: TextureId) -> Self {
self.textures.normal = Some(texture);
self
}
}
pub struct Material {
#[allow(unused)]
pub(crate) label: Option<String>,
pub(crate) pipeline_id: PipelineId,
pub(crate) textures: MaterialTextures,
}
impl Material {
pub fn new(pipeline_id: PipelineId, descriptor: MaterialDescriptor) -> AleaticoResult<Self> {
Ok(Self {
label: descriptor.label,
pipeline_id,
textures: descriptor.textures,
})
}
}