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
use device::shade::{CreateShaderError, CreateProgramError, ShaderModel};
#[derive(Clone, PartialEq, Debug)]
pub enum ProgramError {
Vertex(CreateShaderError),
Fragment(CreateShaderError),
Link(CreateProgramError),
}
#[allow(missing_docs)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct ShaderSource<'a> {
pub glsl_120: Option<&'a [u8]>,
pub glsl_130: Option<&'a [u8]>,
pub glsl_140: Option<&'a [u8]>,
pub glsl_150: Option<&'a [u8]>,
pub glsl_430: Option<&'a [u8]>,
pub targets: &'a [&'a str],
}
impl<'a> ShaderSource<'a> {
pub fn empty() -> ShaderSource<'a> {
ShaderSource {
glsl_120: None,
glsl_130: None,
glsl_140: None,
glsl_150: None,
glsl_430: None,
targets: &[],
}
}
pub fn choose(&self, model: ShaderModel) -> Result<&'a [u8], ()> {
let version = model.to_number();
Ok(match *self {
ShaderSource { glsl_430: Some(s), .. } if version >= 50 => s,
ShaderSource { glsl_150: Some(s), .. } if version >= 40 => s,
ShaderSource { glsl_140: Some(s), .. } if version >= 40 => s,
ShaderSource { glsl_130: Some(s), .. } if version >= 30 => s,
ShaderSource { glsl_120: Some(s), .. } if version >= 20 => s,
_ => return Err(()),
})
}
}