-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
41 lines (31 loc) · 1.26 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
extern crate glsl_to_spirv;
use std::error::Error;
use std::fs;
use glsl_to_spirv::ShaderType;
fn main() -> Result<(), Box<dyn Error>> {
// println!("cargo:rerun-if-changed=src/engine/shaders");
fs::create_dir_all("compiled_shaders")?;
for entry in fs::read_dir("src/engine/shaders")? {
let entry = entry?;
if entry.file_type()?.is_file() {
let in_path = entry.path();
let shader_type = in_path.extension().and_then(|ext| {
match ext.to_string_lossy().as_ref() {
"vert" => Some(ShaderType::Vertex),
"frag" => Some(ShaderType::Fragment),
_ => None,
}
});
if let Some(shader_type) = shader_type {
use std::io::Read;
let source = fs::read_to_string(&in_path)?;
let mut compiled_file = glsl_to_spirv::compile(&source, shader_type)?;
let mut compiled_bytes = Vec::new();
compiled_file.read_to_end(&mut compiled_bytes)?;
let out_path = format!("compiled_shaders/{}.spv", in_path.file_name().unwrap().to_string_lossy());
fs::write(&out_path, &compiled_bytes)?;
}
}
}
Ok(())
}