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
#![allow(missing_docs)]
#[cfg(not(target_arch = "wasm32"))]
mod ogl;
#[doc(inline)]
#[cfg(not(target_arch = "wasm32"))]
pub use ogl::*;
#[cfg(target_arch = "wasm32")]
mod wgl2;
#[doc(inline)]
#[cfg(target_arch = "wasm32")]
pub use wgl2::*;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ShaderType {
Vertex,
Fragment,
}
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub enum DataType {
HalfFloat,
Float,
Byte,
UnsignedByte,
Short,
UnsignedShort,
Int,
UnsignedInt,
}
impl DataType {
fn byte_size(&self) -> u32 {
match self {
DataType::HalfFloat => 2,
DataType::Float => std::mem::size_of::<f32>() as u32,
DataType::UnsignedByte => std::mem::size_of::<u8>() as u32,
DataType::UnsignedShort => std::mem::size_of::<u16>() as u32,
DataType::UnsignedInt => std::mem::size_of::<u32>() as u32,
DataType::Byte => std::mem::size_of::<i8>() as u32,
DataType::Short => std::mem::size_of::<i16>() as u32,
DataType::Int => std::mem::size_of::<i32>() as u32,
}
}
}
impl DataType {
fn to_const(&self) -> u32 {
match self {
DataType::Float => consts::FLOAT,
DataType::HalfFloat => consts::HALF_FLOAT,
DataType::Byte => consts::BYTE,
DataType::UnsignedByte => consts::UNSIGNED_BYTE,
DataType::Short => consts::SHORT,
DataType::UnsignedShort => consts::UNSIGNED_SHORT,
DataType::Int => consts::INT,
DataType::UnsignedInt => consts::UNSIGNED_INT,
}
}
}