Create build file for shaders
This commit is contained in:
parent
e87b6a4ec6
commit
13aa2ba04d
13 changed files with 88 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
Cargo.lock
|
||||
target/
|
||||
|
||||
*.spv
|
53
build.rs
Normal file
53
build.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use std::{fs, path::Path, process::Command};
|
||||
|
||||
const FILE_ENDINGS: &'static [&'static str] = &[
|
||||
"vert", "frag", "geom", "comp", "rchit", "rmiss", "rgen", "rahit",
|
||||
];
|
||||
|
||||
fn find_shader_files(path: impl AsRef<Path>) -> Vec<String> {
|
||||
let mut v = Vec::new();
|
||||
|
||||
if !path.as_ref().is_dir() {
|
||||
panic!("path ({:?}) is not a directory!", path.as_ref());
|
||||
}
|
||||
|
||||
for entry in fs::read_dir(path).unwrap() {
|
||||
let child_path = entry.unwrap().path();
|
||||
|
||||
if child_path.is_dir() {
|
||||
v.extend(find_shader_files(child_path));
|
||||
} else if child_path.is_file() {
|
||||
for ending in FILE_ENDINGS.iter() {
|
||||
if child_path.extension().unwrap() == *ending {
|
||||
v.push(child_path.to_str().unwrap().to_string());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
fn compile_shader(shader_files: &[String]) {
|
||||
Command::new("glslangValidator")
|
||||
.arg("--help")
|
||||
.output()
|
||||
.expect("Failed to execute glslangValidator. Maybe you need to install it first?");
|
||||
|
||||
for shader in shader_files {
|
||||
Command::new("glslangValidator")
|
||||
.arg("-V")
|
||||
.arg(shader)
|
||||
.arg("-o")
|
||||
.arg(&format!("{}.spv", shader))
|
||||
.output()
|
||||
.expect(&format!("Failed to compile {}", shader));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let shader_files = find_shader_files("src");
|
||||
compile_shader(&shader_files);
|
||||
}
|
12
src/element_creator/generator.frag
Normal file
12
src/element_creator/generator.frag
Normal file
|
@ -0,0 +1,12 @@
|
|||
#version 450
|
||||
|
||||
layout (set = 0, binding = 0) uniform Descriptor {
|
||||
vec3 color;
|
||||
} descriptor;
|
||||
|
||||
layout (location = 0) out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = vec4(descriptor.color, 1.0);
|
||||
}
|
8
src/element_creator/generator.vert
Normal file
8
src/element_creator/generator.vert
Normal file
|
@ -0,0 +1,8 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = position;
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12
src/guihandler/guishader/text.vert
Normal file
12
src/guihandler/guishader/text.vert
Normal file
|
@ -0,0 +1,12 @@
|
|||
#version 450
|
||||
|
||||
layout (location = 0) in vec4 position;
|
||||
layout (location = 1) in vec2 texcoord;
|
||||
|
||||
layout (location = 0) out vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
uv = texcoord;
|
||||
gl_Position = position;
|
||||
}
|
Binary file not shown.
Loading…
Reference in a new issue