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
//! Shader uniforms.
/// Uniform type.
#[derive(Clone, Copy, Debug)]
pub enum UniformKind {
/// 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 32-bit integer (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,
}
impl UniformKind {
/// Byte size for a given uniform type.
pub fn size(&self) -> usize {
match self {
UniformKind::Float1 => 4,
UniformKind::Float2 => 8,
UniformKind::Float3 => 12,
UniformKind::Float4 => 16,
UniformKind::Int1 => 4,
UniformKind::Int2 => 8,
UniformKind::Int3 => 12,
UniformKind::Int4 => 16,
UniformKind::Mat4 => 64,
}
}
}
/// Describes a shader uniform.
#[derive(Debug, Clone)]
pub struct UniformDescriptor {
/// Uniform name.
pub name: String,
/// Uniform type.
pub kind: UniformKind,
/// Array length, for arrays.
pub arity: usize,
}
/// A uniform block layout descriptor.
#[derive(Debug, Clone)]
pub struct UniformBlockLayout {
/// The uniforms in the block.
pub uniforms: Vec<UniformDescriptor>,
}
impl UniformDescriptor {
/// New descriptor.
pub fn new(name: &str, uniform_type: UniformKind) -> UniformDescriptor {
UniformDescriptor {
name: name.to_string(),
kind: uniform_type,
arity: 1,
}
}
/// Specify uniform arity.
pub fn arity(self, arity: usize) -> UniformDescriptor {
UniformDescriptor { arity, ..self }
}
}