Allow customizing the shader struct name

This commit is contained in:
Pierre Krieger 2016-02-05 14:37:14 +01:00
parent 964ad0a27e
commit 3836c318dd
2 changed files with 6 additions and 6 deletions

View File

@ -27,6 +27,6 @@ void main() {
"#;
let content = glsl_to_spirv::compile(Some((shader, glsl_to_spirv::ShaderType::Fragment))).unwrap();
let output = shader_parser::reflect(content).unwrap();
let output = shader_parser::reflect("Shader", content).unwrap();
println!("{}", output);
}

View File

@ -6,7 +6,7 @@ pub use parse::ParseError;
mod enums;
mod parse;
pub fn reflect<R>(mut spirv: R) -> Result<String, Error>
pub fn reflect<R>(name: &str, mut spirv: R) -> Result<String, Error>
where R: Read
{
let mut data = Vec::new();
@ -22,18 +22,18 @@ pub fn reflect<R>(mut spirv: R) -> Result<String, Error>
.collect::<Vec<String>>()
.join(", ");
output.push_str(&format!(r#"
pub struct Shader;
pub struct {name};
impl Shader {{
impl {name} {{
pub fn load(device: &::std::sync::Arc<::vulkano::Device>) {{
unsafe {{
let data = [{spirv_data}];
::vulkano::Shader::new(device, &data)
::vulkano::ShaderModule::new(device, &data)
}}
}}
}}
"#, spirv_data = spirv_data));
"#, name = name, spirv_data = spirv_data));
}
println!("{:#?}", doc);