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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use super::*;

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum AttributeType {
    Float = raw::FLOAT as _,
}

/// # Safety
/// Don't implement yourself
pub unsafe trait VertexAttributePrimitive {
    const SIZE: usize;
    const ROWS: usize;
    const TYPE: AttributeType;
}

pub trait VertexAttribute {
    type Primitive: VertexAttributePrimitive;
    fn primitive_offset() -> usize;
}

impl<T: VertexAttributePrimitive> VertexAttribute for T {
    type Primitive = Self;
    fn primitive_offset() -> usize {
        0
    }
}

unsafe impl VertexAttributePrimitive for f32 {
    const SIZE: usize = 1;
    const ROWS: usize = 1;
    const TYPE: AttributeType = AttributeType::Float;
}

unsafe impl VertexAttributePrimitive for [f32; 2] {
    const SIZE: usize = 2;
    const ROWS: usize = 1;
    const TYPE: AttributeType = AttributeType::Float;
}

unsafe impl VertexAttributePrimitive for [f32; 3] {
    const SIZE: usize = 3;
    const ROWS: usize = 1;
    const TYPE: AttributeType = AttributeType::Float;
}

unsafe impl VertexAttributePrimitive for [f32; 4] {
    const SIZE: usize = 4;
    const ROWS: usize = 1;
    const TYPE: AttributeType = AttributeType::Float;
}

unsafe impl VertexAttributePrimitive for [[f32; 3]; 3] {
    const SIZE: usize = 3;
    const ROWS: usize = 3;
    const TYPE: AttributeType = AttributeType::Float;
}

unsafe impl VertexAttributePrimitive for [[f32; 4]; 4] {
    const SIZE: usize = 4;
    const ROWS: usize = 4;
    const TYPE: AttributeType = AttributeType::Float;
}

mod batbox {
    use super::*;

    impl VertexAttribute for vec2<f32> {
        type Primitive = [f32; 2];
        fn primitive_offset() -> usize {
            0
        }
    }

    impl VertexAttribute for vec3<f32> {
        type Primitive = [f32; 3];
        fn primitive_offset() -> usize {
            0
        }
    }

    impl VertexAttribute for vec4<f32> {
        type Primitive = [f32; 4];
        fn primitive_offset() -> usize {
            0
        }
    }

    impl VertexAttribute for Rgba<f32> {
        type Primitive = [f32; 4];
        fn primitive_offset() -> usize {
            0
        }
    }

    impl VertexAttribute for mat3<f32> {
        type Primitive = [[f32; 3]; 3];
        fn primitive_offset() -> usize {
            0
        }
    }

    impl VertexAttribute for mat4<f32> {
        type Primitive = [[f32; 4]; 4];
        fn primitive_offset() -> usize {
            0
        }
    }
}