easy_gltf/scene/model/
mode.rs

1use std::fmt;
2
3/// The type of primitives to render.
4///
5/// To find more information for each mode and how to render them check
6/// [Khronos Primitive Documentation](https://www.khronos.org/opengl/wiki/Primitive).
7#[derive(Clone, Debug, PartialEq, Default)]
8pub enum Mode {
9    /// Corresponds to `GL_POINTS`.
10    Points,
11    /// Corresponds to `GL_LINES`.
12    Lines,
13    /// Corresponds to `GL_LINE_LOOP`.
14    LineLoop,
15    /// Corresponds to `GL_LINE_STRIP`.
16    LineStrip,
17    /// Corresponds to `GL_TRIANGLES`.
18    #[default]
19    Triangles,
20    /// Corresponds to `GL_TRIANGLE_STRIP`.
21    TriangleStrip,
22    /// Corresponds to `GL_TRIANGLE_FAN`.
23    TriangleFan,
24}
25
26impl From<gltf::mesh::Mode> for Mode {
27    fn from(mode: gltf::mesh::Mode) -> Self {
28        match mode {
29            gltf::mesh::Mode::Points => Self::Points,
30            gltf::mesh::Mode::Lines => Self::Lines,
31            gltf::mesh::Mode::LineLoop => Self::LineLoop,
32            gltf::mesh::Mode::LineStrip => Self::LineStrip,
33            gltf::mesh::Mode::Triangles => Self::Triangles,
34            gltf::mesh::Mode::TriangleFan => Self::TriangleFan,
35            gltf::mesh::Mode::TriangleStrip => Self::TriangleStrip,
36        }
37    }
38}
39
40/// Represents a runtime error. This error is triggered when an expected mode
41/// doesn't match the model mode .
42#[derive(Clone, Debug)]
43pub struct BadMode {
44    /// The current mode of the model.
45    pub mode: Mode,
46}
47
48impl fmt::Display for BadMode {
49    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50        write!(f, "Invalid mode \"{:?}\"", self.mode,)
51    }
52}