diff --git a/Cargo.toml b/Cargo.toml index 4747efb..1de307e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,14 @@ keywords = ["vulkan", "vulkano", "shaders", "hotloading"] version = "4" [dependencies.shaderc] -version = "0.5" +version = "0.6.1" [dependencies.spirv-reflect] version = "0.2" [dependencies.vulkano] -version = "0.13.0" +#version = "0.14.0" +path = "../vulkano/vulkano" [dev-dependencies.color-backtrace] version = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 9f075b3..7ab5c10 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,27 +16,61 @@ use vulkano as vk; use std::path::Path; use shaderc::ShaderKind; +#[derive(Clone)] pub struct CompiledShaders { pub vertex: Vec, pub fragment: Vec, pub compute: Vec, } -/// Loads and compiles the vertex and fragment GLSL shaders from files -pub fn load(vertex: T, fragment: T) -> Result -where - T: AsRef, -{ - let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); +#[derive(Clone)] +pub struct CompiledShader { + pub spriv: Vec, +} +/// Loads and compiles the vertex shader +pub fn load_vertex(vertex: T) -> Result + where + T: AsRef, +{ let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?; - let fragment = compiler::compile(fragment, ShaderKind::Fragment).map_err(Error::Compile)?; + Ok(CompiledShader{ spriv: vertex }) +} - Ok(CompiledShaders{ - vertex, - fragment, - compute: Vec::new(), - }) +/// Loads and compiles the fragment shader +pub fn load_fragment(fragment: T) -> Result + where + T: AsRef, +{ + let fragment = compiler::compile(vertex, ShaderKind::Fragment).map_err(Error::Compile)?; + Ok(CompiledShader{ spriv: fragment }) +} + +/// Loads and compiles the geometry shader +pub fn load_geometry(geometry: T) -> Result + where + T: AsRef, +{ + let geometry = compiler::compile(vertex, ShaderKind::Geometry).map_err(Error::Compile)?; + Ok(CompiledShader{ spriv: geometry }) +} + +/// Loads and compiles the tessellation shader +pub fn load_tessellation_control(geometry: T) -> Result + where + T: AsRef, +{ + let tess = compiler::compile(vertex, ShaderKind::TessControl).map_err(Error::Compile)?; + Ok(CompiledShader{ spriv: tess }) +} + +/// Loads and compiles the tessellation shader +pub fn load_tessellation_evaluation(geometry: T) -> Result + where + T: AsRef, +{ + let tess = compiler::compile(vertex, ShaderKind::TessEvaluation).map_err(Error::Compile)?; + Ok(CompiledShader{ spriv: tess }) } // TODO this should be incorpoarted into load but that would be