mod3d_gl/
material.rs

1//a Imports
2use mod3d_base::ShortIndex;
3
4use crate::{Gl, ShaderMaterialBaseData, TextureId};
5
6//a Material
7//tp Material
8/// A null material for now
9#[derive(Debug)]
10pub struct Material {
11    // <G: Gl> {
12    base_data: ShaderMaterialBaseData,
13    textures: [(TextureId, ShortIndex); 8],
14}
15
16// impl<G: Gl> Material<G> {
17impl Material {
18    //cp create
19    /// Create a GL material for a given context within the object
20    ///
21    /// This is invoked when the object is being made instantiable;
22    pub fn create<M, G: Gl>(
23        _context: &mut G,
24        _object: &mod3d_base::Object<M, G>,
25        material: &M,
26    ) -> Result<Self, ()>
27    where
28        M: mod3d_base::Material,
29    {
30        let base_data = ShaderMaterialBaseData::of_material(material);
31        let mut textures = [(TextureId::None, ShortIndex::none()); 8];
32        let mut i = 0;
33        for aspect in [
34            mod3d_base::MaterialAspect::Color,
35            mod3d_base::MaterialAspect::Normal,
36            mod3d_base::MaterialAspect::MetallicRoughness,
37            mod3d_base::MaterialAspect::Occlusion,
38            mod3d_base::MaterialAspect::Emission,
39        ] {
40            let ti = material.texture(aspect);
41            if ti.is_some() {
42                textures[i] = (TextureId::of_material_aspect(aspect), ti);
43                i += 1;
44            };
45        }
46        eprintln!("Textures {textures:?}");
47        Ok(Self {
48            base_data,
49            textures,
50        })
51    }
52    pub fn base_data(&self) -> &ShaderMaterialBaseData {
53        &self.base_data
54    }
55    pub fn textures(&self) -> &[(TextureId, ShortIndex)] {
56        &self.textures
57    }
58}
59
60//ip Display for Material
61// impl<G: Gl> std::fmt::Display for Material<G> {
62impl std::fmt::Display for Material {
63    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
64        std::fmt::Debug::fmt(self, f)
65    }
66}
67
68//ip MaterialClient for Material
69// impl<G: Gl> mod3d_base::MaterialClient for Material<G> {}
70impl mod3d_base::MaterialClient for Material {}