-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
73 lines (60 loc) · 1.83 KB
/
build.rs
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
extern crate shaderc;
use std::env;
use std::io::Write;
use std::path::PathBuf;
fn main() {
let vert_source = r#"
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec3 inColour;
const vec2 POSITIONS[4] = vec2[](
vec2(-1.0, -1.0),
vec2(-1.0, 1.0),
vec2(1.0, -1.0),
vec2(1.0, 1.0)
);
layout(location = 0) out vec3 fragColour;
void main() {
gl_Position = vec4(POSITIONS[gl_VertexIndex], 0.0, 1.0);
fragColour = inColour;
}
"#;
let frag_source = r#"
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 fragColour;
layout(location = 0) out vec4 outColour;
void main() {
outColour = vec4(fragColour, 1.0);
//outColour = vec4(1.0, 1.0, 1.0, 1.0);
}
"#;
let mut compiler = shaderc::Compiler::new().unwrap();
let vert_artifact = compiler
.compile_into_spirv(
vert_source,
shaderc::ShaderKind::Vertex,
"shader.glsl",
"main",
None,
)
.unwrap();
let frag_artifact = compiler
.compile_into_spirv(
frag_source,
shaderc::ShaderKind::Fragment,
"shader.glsl",
"main",
None,
)
.unwrap();
let vert_bytes = vert_artifact.as_binary_u8();
let frag_bytes = frag_artifact.as_binary_u8();
let vert_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("vert.spv");
let frag_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("frag.spv");
let mut vert_file = std::fs::File::create(vert_path).expect("create failed");
let mut frag_file = std::fs::File::create(frag_path).expect("create failed");
vert_file.write_all(vert_bytes).expect("write failed");
frag_file.write_all(frag_bytes).expect("write failed");
}