summaryrefslogtreecommitdiff
path: root/engine/src/renderer/opengl/vertex.rs
blob: 499b94b9e2498755d1230a0d3f70003c05a36ec2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::vector::{Vec2, Vec3};

#[derive(Debug, Clone)]
#[repr(C)]
pub struct Vertex
{
    pub pos: Vec3<f32>,
    pub texture_coords: Vec2<f32>,
    pub normal: Vec3<f32>,
}

impl Vertex
{
    pub fn attrs() -> &'static [Attribute]
    {
        #[allow(clippy::cast_possible_truncation)]
        &[
            Attribute {
                index: 0,
                component_type: AttributeComponentType::Float,
                component_cnt: AttributeComponentCnt::Three,
                component_size: size_of::<f32>() as u32,
            },
            Attribute {
                index: 1,
                component_type: AttributeComponentType::Float,
                component_cnt: AttributeComponentCnt::Two,
                component_size: size_of::<f32>() as u32,
            },
            Attribute {
                index: 2,
                component_type: AttributeComponentType::Float,
                component_cnt: AttributeComponentCnt::Three,
                component_size: size_of::<f32>() as u32,
            },
        ]
    }
}

#[derive(Debug)]
pub struct Attribute
{
    pub index: u32,
    pub component_type: AttributeComponentType,
    pub component_cnt: AttributeComponentCnt,
    pub component_size: u32,
}

#[derive(Debug)]
pub enum AttributeComponentType
{
    Float,
}

#[derive(Debug, Clone, Copy)]
#[repr(u32)]
#[allow(dead_code)]
pub enum AttributeComponentCnt
{
    One = 1,
    Two = 2,
    Three = 3,
    Four = 4,
}