-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Switch to winit and wgpu (#35)
* feat: Switch to winit and wgpu * feat: Add colors to the vertices * feat: fmt * feat: Rework on the pipeline to make things more abstract * feat: Add transform as an uniform AND CLOSES #16
- Loading branch information
Showing
29 changed files
with
1,023 additions
and
414 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<img src="repo/banner.png" alt="Scion Engine" /> | ||
|
||
Scion is a minimalist, **easy** to use, modulable game engine built on top of legion and miniquad. | ||
Scion is a minimalist, **easy** to use, modulable game engine built on top of legion, wgpu and winit. | ||
|
||
|
||
|
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,81 @@ | ||
use anyhow::*; | ||
use glob::glob; | ||
use std::fs::{read_to_string, write}; | ||
use std::path::PathBuf; | ||
|
||
struct ShaderData { | ||
src: String, | ||
src_path: PathBuf, | ||
spv_path: PathBuf, | ||
kind: shaderc::ShaderKind, | ||
} | ||
|
||
impl ShaderData { | ||
pub fn load(src_path: PathBuf) -> Result<Self> { | ||
let extension = src_path | ||
.extension() | ||
.context("File has no extension")? | ||
.to_str() | ||
.context("Extension cannot be converted to &str")?; | ||
let kind = match extension { | ||
"vert" => shaderc::ShaderKind::Vertex, | ||
"frag" => shaderc::ShaderKind::Fragment, | ||
"comp" => shaderc::ShaderKind::Compute, | ||
_ => bail!("Unsupported shader: {}", src_path.display()), | ||
}; | ||
|
||
let src = read_to_string(src_path.clone())?; | ||
let spv_path = src_path.with_extension(format!("{}.spv", extension)); | ||
|
||
Ok(Self { | ||
src, | ||
src_path, | ||
spv_path, | ||
kind, | ||
}) | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
// Collect all shaders recursively within /src/ | ||
let mut shader_paths = [ | ||
glob("./src/**/*.vert")?, | ||
glob("./src/**/*.frag")?, | ||
glob("./src/**/*.comp")?, | ||
]; | ||
|
||
// This could be parallelized | ||
let shaders = shader_paths | ||
.iter_mut() | ||
.flatten() | ||
.map(|glob_result| ShaderData::load(glob_result?)) | ||
.collect::<Vec<Result<_>>>() | ||
.into_iter() | ||
.collect::<Result<Vec<_>>>()?; | ||
|
||
let mut compiler = shaderc::Compiler::new().context("Unable to create shader compiler")?; | ||
|
||
// This can't be parallelized. The [shaderc::Compiler] is not | ||
// thread safe. Also, it creates a lot of resources. You could | ||
// spawn multiple processes to handle this, but it would probably | ||
// be better just to only compile shaders that have been changed | ||
// recently. | ||
for shader in shaders { | ||
// This tells cargo to rerun this script if something in /src/ changes. | ||
println!( | ||
"cargo:rerun-if-changed={}", | ||
shader.src_path.as_os_str().to_str().unwrap() | ||
); | ||
|
||
let compiled = compiler.compile_into_spirv( | ||
&shader.src, | ||
shader.kind, | ||
&shader.src_path.to_str().unwrap(), | ||
"main", | ||
None, | ||
)?; | ||
write(shader.spv_path, compiled.as_binary_u8())?; | ||
} | ||
|
||
Ok(()) | ||
} |
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
Oops, something went wrong.