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
use super::*;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VertexFormat
{
/// One 32-bit wide float (equivalent to `f32`)
Float1,
/// Two 32-bit wide floats (equivalent to `[f32; 2]`)
Float2,
/// Three 32-bit wide floats (equivalent to `[f32; 3]`)
Float3,
/// Four 32-bit wide floats (equivalent to `[f32; 4]`)
Float4,
/// One unsigned 8-bit integer (equivalent to `u8`)
Byte1,
/// Two unsigned 8-bit integers (equivalent to `[u8; 2]`)
Byte2,
/// Three unsigned 8-bit integers (equivalent to `[u8; 3]`)
Byte3,
/// Four unsigned 8-bit integers (equivalent to `[u8; 4]`)
Byte4,
/// One unsigned 16-bit integer (equivalent to `u16`)
Short1,
/// Two unsigned 16-bit integers (equivalent to `[u16; 2]`)
Short2,
/// Tree unsigned 16-bit integers (equivalent to `[u16; 3]`)
Short3,
/// Four unsigned 16-bit integers (equivalent to `[u16; 4]`)
Short4,
/// One unsigned 32-bit integers (equivalent to `[u32; 1]`)
Int1,
/// Two unsigned 32-bit integers (equivalent to `[u32; 2]`)
Int2,
/// Three unsigned 32-bit integers (equivalent to `[u32; 3]`)
Int3,
/// Four unsigned 32-bit integers (equivalent to `[u32; 4]`)
Int4,
/// Four by four matrix of 32-bit floats
Mat4,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct VertexAttribute {
pub name: String,
pub format: VertexFormat,
pub buffer_index: RawBufferID,
/// This flag affects integer VertexFormats, Byte*, Short*, Int*
/// Taking Byte4 as an example:
/// On Metal, it might be received as either `float4` or `uint4`
/// On OpenGl and `gl_pass_as_float = true` shaders should receive it as `vec4`
/// With `gl_pass_as_float = false`, as `uvec4`
///
/// Note that `uvec4` requires at least `150` glsl version
/// Before setting `gl_pass_as_float` to false, better check `context.info().has_integer_attributes()` and double check that shaders are at least `150`
pub gl_pass_as_float: bool,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum VertexStep {
#[default]
PerVertex,
PerInstance,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct VertexBufferLayout {
pub stride: i32,
pub step_func: VertexStep,
pub step_rate: i32,
}
impl Default for VertexBufferLayout {
fn default() -> VertexBufferLayout {
VertexBufferLayout {
stride: 0,
step_func: VertexStep::PerVertex,
step_rate: 1,
}
}
}