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
pub use lambda_platform::shaderc::{
ShaderCompiler,
ShaderCompilerBuilder,
ShaderKind,
VirtualShader,
};
#[macro_export]
macro_rules! vertex_shader {
($source:ident) => {
VirtualShader::Source {
source: String::from($stringify!($source)),
kind: ShaderKind::Vertex,
name: String::from("vertex-shader"),
entry_point: String::from("main"),
}
};
}
pub struct ShaderBuilder {
compiler: ShaderCompiler,
}
impl ShaderBuilder {
pub fn new() -> Self {
let compiler = ShaderCompilerBuilder::new().build();
return Self { compiler };
}
pub fn build(&mut self, virtual_shader: VirtualShader) -> Shader {
let binary = self.compiler.compile_into_binary(&virtual_shader);
return Shader {
binary,
virtual_shader,
};
}
}
pub struct Shader {
binary: Vec<u32>,
virtual_shader: VirtualShader,
}
impl Shader {
pub fn as_binary(&self) -> Vec<u32> {
return self.binary.clone();
}
}