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
use format::Format;
pub unsafe trait Vertex: 'static + Send + Sync {
fn member(name: &str) -> Option<VertexMemberInfo>;
}
unsafe impl Vertex for () {
#[inline]
fn member(_: &str) -> Option<VertexMemberInfo> {
None
}
}
pub struct VertexMemberInfo {
pub offset: usize,
pub ty: VertexMemberTy,
pub array_size: usize,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[allow(missing_docs)]
pub enum VertexMemberTy {
I8,
U8,
I16,
U16,
I32,
U32,
F32,
F64,
}
impl VertexMemberTy {
#[inline]
pub fn matches(&self, array_size: usize, format: Format, num_locs: u32) -> bool {
let my_size = match *self {
VertexMemberTy::I8 => 1,
VertexMemberTy::U8 => 1,
VertexMemberTy::I16 => 2,
VertexMemberTy::U16 => 2,
VertexMemberTy::I32 => 4,
VertexMemberTy::U32 => 4,
VertexMemberTy::F32 => 4,
VertexMemberTy::F64 => 8,
};
let format_size = match format.size() {
None => return false,
Some(s) => s,
};
array_size * my_size == format_size * num_locs as usize
}
}