Correctly propagate errors when creating shader module

This commit is contained in:
Pierre Krieger 2016-02-18 21:23:26 +01:00
parent bbda9a98d4
commit 41847a1b99
2 changed files with 8 additions and 6 deletions

View File

@ -32,7 +32,9 @@ pub struct {name} {{
impl {name} {{
/// Loads the shader in Vulkan as a `ShaderModule`.
#[inline]
pub fn load(device: &::std::sync::Arc<::vulkano::device::Device>) -> {name} {{
pub fn load(device: &::std::sync::Arc<::vulkano::device::Device>)
-> Result<{name}, ::vulkano::OomError>
{{
"#, name = name));
@ -54,9 +56,9 @@ impl {name} {{
unsafe {{
let data = [{spirv_data}];
{name} {{
shader: ::vulkano::shader::ShaderModule::new(device, &data).unwrap() // FIXME: try!()
}}
Ok({name} {{
shader: try!(::vulkano::shader::ShaderModule::new(device, &data))
}})
}}
}}

View File

@ -130,9 +130,9 @@ fn main() {
//
// Because of some restrictions with the `include!` macro, we need to use a module.
mod vs { include!{concat!(env!("OUT_DIR"), "/examples-triangle_vs.rs")} }
let vs = vs::TriangleShader::load(&device);
let vs = vs::TriangleShader::load(&device).expect("failed to create shader module");
mod fs { include!{concat!(env!("OUT_DIR"), "/examples-triangle_fs.rs")} }
let fs = fs::TriangleShader::load(&device);
let fs = fs::TriangleShader::load(&device).expect("failed to create shader module");
// At this point, OpenGL initialization would be finished. However in Vulkan it is not. OpenGL
// implicitely does a lot of computation whenever you draw. In Vulkan, you have to do all this