use anyhow::Result; use vulkan_rs::prelude::*; use std::{mem, sync::Arc}; pub struct SingleColorPipeline { pipeline: Arc, pipeline_layout: Arc, vertex_shader: Arc, fragment_shader: Arc, } impl SingleColorPipeline { pub fn new(device: Arc, renderpass: &Arc) -> Result { let vertex_shader = ShaderModule::from_slice( device.clone(), include_bytes!("shader/single_color.vert.spv"), ShaderType::Vertex, )?; let fragment_shader = ShaderModule::from_slice( device.clone(), include_bytes!("shader/single_color.frag.spv"), ShaderType::Fragment, )?; let pipeline_layout = PipelineLayout::builder().build(device.clone())?; let pipeline = Pipeline::new_graphics() .set_vertex_shader( vertex_shader.clone(), vec![VkVertexInputBindingDescription { binding: 0, stride: mem::size_of::<[f32; 4]>() as u32, inputRate: VK_VERTEX_INPUT_RATE_VERTEX, }], vec![ // position VkVertexInputAttributeDescription { location: 0, binding: 0, format: VK_FORMAT_R32G32B32A32_SFLOAT, offset: 0, }, ], ) .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) .build(device, &pipeline_layout, &renderpass, 0)?; Ok(Self { vertex_shader, fragment_shader, pipeline, pipeline_layout, }) } pub fn pipeline(&self) -> &Arc { &self.pipeline } }