use anyhow::Result; use vulkan_rs::prelude::*; use std::sync::Arc; use super::PositionOnlyVertex; pub struct SingleColorPipeline { pipeline: Arc, descriptor_layout: Arc, } impl SingleColorPipeline { pub fn new( device: Arc, renderpass: &Arc, width: u32, height: u32, ) -> Result { let vertex_shader = ShaderModule::from_slice(device.clone(), include_bytes!("single_color.vert.spv"))?; let fragment_shader = ShaderModule::from_slice(device.clone(), include_bytes!("single_color.frag.spv"))?; let descriptor_layout = DescriptorSetLayout::builder() .add_layout_binding( 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 0, ) .build(device.clone())?; let pipeline_layout = PipelineLayout::builder() .add_descriptor_set_layout(&descriptor_layout) .build(device.clone())?; let viewport = VkViewport { x: 0.0, y: 0.0, width: width as f32, height: height as f32, minDepth: 0.0, maxDepth: 1.0, }; let scissor = VkRect2D { offset: VkOffset2D { x: 0, y: 0 }, extent: VkExtent2D { width: width, height: height, }, }; let pipeline = Pipeline::new_graphics() .set_vertex_shader::(vertex_shader.clone()) .set_fragment_shader(fragment_shader.clone()) .input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false) .default_depth_stencil(false, false) .default_color_blend(vec![VkPipelineColorBlendAttachmentState::default()]) .default_rasterization(VK_CULL_MODE_NONE, VK_FRONT_FACE_COUNTER_CLOCKWISE) .default_multisample(VK_SAMPLE_COUNT_1_BIT) .add_viewport(viewport) .add_scissor(scissor) .build(device, &pipeline_layout, &renderpass, 0)?; Ok(Self { descriptor_layout, pipeline, }) } pub fn pipeline(&self) -> &Arc { &self.pipeline } pub fn descriptor_layout(&self) -> &Arc { &self.descriptor_layout } }