Scene: manage error

This commit is contained in:
Florian RICHER 2024-12-11 21:07:47 +01:00
parent d9f70caec0
commit 7cbc785888
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
3 changed files with 53 additions and 42 deletions

View file

@ -1,3 +1,4 @@
use std::error::Error;
use std::sync::Arc;
use vulkano::device::Device;
use vulkano::pipeline::graphics::color_blend::{ColorBlendAttachmentState, ColorBlendState};
@ -12,6 +13,7 @@ use vulkano::pipeline::layout::PipelineDescriptorSetLayoutCreateInfo;
use vulkano::pipeline::{
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
};
use vulkano::shader::EntryPoint;
use vulkano::swapchain::Swapchain;
use crate::renderer::Vertex2D;
@ -35,37 +37,26 @@ mod shaders {
pub fn create_triangle_pipeline(
device: &Arc<Device>,
swapchain: &Arc<Swapchain>,
) -> Arc<GraphicsPipeline> {
let vs = shaders::vs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let fs = shaders::fs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let vertex_input_state = Vertex2D::per_vertex().definition(&vs).unwrap();
) -> Result<Arc<GraphicsPipeline>, Box<dyn Error>> {
let (vs, fs) = load_shaders(device)?;
let vertex_input_state = Vertex2D::per_vertex().definition(&vs)?;
let stages = [
PipelineShaderStageCreateInfo::new(vs),
PipelineShaderStageCreateInfo::new(fs),
];
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
let create_info = PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())?;
let layout = PipelineLayout::new(device.clone(), create_info)?;
let subpass = PipelineRenderingCreateInfo {
color_attachment_formats: vec![Some(swapchain.image_format())],
..Default::default()
};
GraphicsPipeline::new(
let pipeline = GraphicsPipeline::new(
device.clone(),
None,
GraphicsPipelineCreateInfo {
@ -83,6 +74,19 @@ pub fn create_triangle_pipeline(
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
)?;
Ok(pipeline)
}
fn load_shaders(device: &Arc<Device>) -> Result<(EntryPoint, EntryPoint), Box<dyn Error>> {
let vs = shaders::vs::load(device.clone())?
.entry_point("main")
.ok_or(format!("Failed find main entry point of vertex shader"))?;
let fs = shaders::fs::load(device.clone())?
.entry_point("main")
.ok_or(format!("Failed find main entry point of fragment shader"))?;
Ok((vs, fs))
}