mod3d_gl/
types.rs

1//tp UniformId
2/// An enumeration of uniforms - that this crate particularly cares about
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum UniformId {
5    /// The view matrix uniform - once per framebuffer render
6    ViewMatrix,
7    /// The model matrix uniform - once per model instance
8    ModelMatrix,
9    /// The mesh matrix uniform - once per model mesh
10    MeshMatrix,
11    /// The Bone data uniform - once per model
12    BoneScale,
13    /// The Bone data uniform - once per model
14    BoneMatrices,
15    /// The Material data uniform - once per model, and it may have
16    /// many forms, but it must start with ShaderMaterialBaseData
17    Material,
18    /// Texure uniform - dependent on the program.
19    Texture(TextureId),
20    /// User uniform - dependent on the program.
21    User(u8),
22    /// User uniform buffer - dependent on the program.
23    Buffer(u8),
24}
25
26impl std::str::FromStr for UniformId {
27    type Err = String;
28    fn from_str(s: &str) -> Result<Self, Self::Err> {
29        use UniformId::*;
30        let v = match s {
31            "ViewMatrix" => ViewMatrix,
32            "ModelMatrix" => ModelMatrix,
33            "MeshMatrix" => MeshMatrix,
34            "BoneScale" => BoneScale,
35            "BoneMatrices" => BoneMatrices,
36            "Material" => Material,
37            _ => Err(format!("Cannot interpret {s} as a UniformID"))?,
38        };
39        Ok(v)
40    }
41}
42
43//tp TextureId
44/// An enumeration of texures - that this crate particularly cares about
45#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
46#[repr(u8)]
47#[non_exhaustive]
48pub enum TextureId {
49    /// None
50    #[default]
51    None,
52    /// The base color texture
53    BaseColor,
54    /// A normal texture
55    Normal,
56    /// The occlusion texture (as per Gltf)
57    Occlusion,
58    /// The emission texture (as per Gltf)
59    Emission,
60    /// The metallic-roughness texture (as per Gltf)
61    MetallicRoughness,
62    /// User 0
63    User0,
64}
65
66impl std::str::FromStr for TextureId {
67    type Err = String;
68    fn from_str(s: &str) -> Result<Self, Self::Err> {
69        use TextureId::*;
70        let v = match s {
71            "BaseColor" => BaseColor,
72            "Normal" => Normal,
73            "Occlusion" => Occlusion,
74            "Emission" => Emission,
75            "MetallicRoughness" => MetallicRoughness,
76            "User0" => User0,
77            _ => Err(format!("Cannot interpret {s} as a TextureId"))?,
78        };
79        Ok(v)
80    }
81}
82
83impl TextureId {
84    pub fn of_material_aspect(m: mod3d_base::MaterialAspect) -> Self {
85        use mod3d_base::MaterialAspect::*;
86        #[allow(unreachable_patterns)]
87        match m {
88            Color => Self::BaseColor,
89            Normal => Self::Normal,
90            MetallicRoughness => Self::MetallicRoughness,
91            Occlusion => Self::Occlusion,
92            Emission => Self::Emission,
93            _ => Self::None,
94        }
95    }
96}