The API needs some work

master
mitchellhansen 5 years ago
parent 0f0c29fac9
commit d1c3a5f562

@ -14,13 +14,14 @@ keywords = ["vulkan", "vulkano", "shaders", "hotloading"]
version = "4" version = "4"
[dependencies.shaderc] [dependencies.shaderc]
version = "0.5" version = "0.6.1"
[dependencies.spirv-reflect] [dependencies.spirv-reflect]
version = "0.2" version = "0.2"
[dependencies.vulkano] [dependencies.vulkano]
version = "0.13.0" #version = "0.14.0"
path = "../vulkano/vulkano"
[dev-dependencies.color-backtrace] [dev-dependencies.color-backtrace]
version = "0.1" version = "0.1"

@ -16,27 +16,61 @@ use vulkano as vk;
use std::path::Path; use std::path::Path;
use shaderc::ShaderKind; use shaderc::ShaderKind;
#[derive(Clone)]
pub struct CompiledShaders { pub struct CompiledShaders {
pub vertex: Vec<u32>, pub vertex: Vec<u32>,
pub fragment: Vec<u32>, pub fragment: Vec<u32>,
pub compute: Vec<u32>, pub compute: Vec<u32>,
} }
/// Loads and compiles the vertex and fragment GLSL shaders from files #[derive(Clone)]
pub fn load<T>(vertex: T, fragment: T) -> Result<CompiledShaders, Error> pub struct CompiledShader {
where pub spriv: Vec<u32>,
T: AsRef<Path>, }
{
let options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap();
/// Loads and compiles the vertex shader
pub fn load_vertex<T>(vertex: T) -> Result<CompiledShader, Error>
where
T: AsRef<Path>,
{
let vertex = compiler::compile(vertex, ShaderKind::Vertex).map_err(Error::Compile)?; 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{ /// Loads and compiles the fragment shader
vertex, pub fn load_fragment<T>(fragment: T) -> Result<CompiledShader, Error>
fragment, where
compute: Vec::new(), T: AsRef<Path>,
}) {
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<T>(geometry: T) -> Result<CompiledShader, Error>
where
T: AsRef<Path>,
{
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<T>(geometry: T) -> Result<CompiledShader, Error>
where
T: AsRef<Path>,
{
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<T>(geometry: T) -> Result<CompiledShader, Error>
where
T: AsRef<Path>,
{
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 // TODO this should be incorpoarted into load but that would be

Loading…
Cancel
Save