-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ | |
|
||
# MacOS | ||
.DS_Store | ||
|
||
# SPIR-V | ||
*.spv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#version 450 | ||
|
||
layout(location = 0) in vec3 frag_color; | ||
|
||
layout(location = 0) out vec4 out_color; | ||
|
||
void main() { | ||
out_color = vec4(frag_color, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#version 450 | ||
|
||
layout(location = 0) out vec3 frag_color; | ||
|
||
vec2 positions[3] = vec2[]( | ||
vec2(0.0, -0.5), | ||
vec2(0.5, 0.5), | ||
vec2(-0.5, 0.5) | ||
); | ||
|
||
vec3 colors[3] = vec3[]( | ||
vec3(1.0, 0.0, 0.0), | ||
vec3(0.0, 1.0, 0.0), | ||
vec3(0.0, 0.0, 1.0) | ||
); | ||
|
||
void main() { | ||
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); | ||
frag_color = colors[gl_VertexIndex]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use std::{fs::{self, DirEntry}, path::Path}; | ||
|
||
pub fn main() -> anyhow::Result<()> { | ||
let compiler = shaderc::Compiler::new().unwrap(); | ||
let options = shaderc::CompileOptions::new().unwrap(); | ||
let shader_files = recurse_dir("./assets/shader")?; | ||
|
||
for file in shader_files { | ||
let path = file.path(); | ||
let source = fs::read_to_string(path.clone())?; | ||
let file_name = path.to_string_lossy().to_string(); | ||
let extension = file_name.split(".").last().expect("shader files must have an extension"); | ||
let shader_binary = compiler.compile_into_spirv( | ||
&source, | ||
extension_to_shader_kind(extension), | ||
&file_name, | ||
"main", | ||
Some(&options), | ||
)?; | ||
fs::write(Path::new(format!("{}_{extension}.spv", path.with_extension("").to_string_lossy().to_string()).as_str()), shader_binary.as_binary_u8())?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn extension_to_shader_kind(extension: &str) -> shaderc::ShaderKind { | ||
match extension { | ||
"frag" => shaderc::ShaderKind::Fragment, | ||
"vert" => shaderc::ShaderKind::Vertex, | ||
_ => panic!("unsupported shader kind"), | ||
} | ||
} | ||
|
||
fn recurse_dir(path: impl AsRef<Path>) -> std::io::Result<Vec<DirEntry>> { | ||
let mut entries = Vec::new(); | ||
let dir = fs::read_dir(path)?; | ||
|
||
dir | ||
.into_iter() | ||
// Fallibly extract entry metadata | ||
.map(|entry| { | ||
let entry = entry?; | ||
Ok((entry.metadata()?, entry)) | ||
}) | ||
.collect::<std::io::Result<Vec<_>>>()? | ||
.into_iter() | ||
// Add files to entries and discard them | ||
.filter_map(|(metadata, entry)| { | ||
if metadata.is_file() { | ||
entries.push(entry); | ||
return None | ||
} | ||
metadata.is_dir().then_some(entry) | ||
}) | ||
.collect::<Vec<_>>() | ||
.iter() | ||
// Recurse child directories | ||
.try_for_each(|entry| { | ||
entries.extend(recurse_dir(entry.path())?); | ||
Ok::<(), std::io::Error>(()) | ||
})?; | ||
|
||
Ok(entries) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! # Graphics Pipeline | ||
//! An interface with the graphics pipeline. | ||
pub struct Pipeline {} |