2023-01-12 12:52:44 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use vulkan_rs::prelude::*;
|
|
|
|
|
2023-01-27 13:04:06 +00:00
|
|
|
use std::sync::Arc;
|
2023-01-12 12:52:44 +00:00
|
|
|
|
2023-01-18 08:19:55 +00:00
|
|
|
use super::PositionOnlyVertex;
|
2023-01-13 07:11:53 +00:00
|
|
|
|
2023-01-12 12:52:44 +00:00
|
|
|
pub struct SingleColorPipeline {
|
|
|
|
pipeline: Arc<Pipeline>,
|
2023-01-13 07:11:53 +00:00
|
|
|
descriptor_layout: Arc<DescriptorSetLayout>,
|
2023-01-12 12:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SingleColorPipeline {
|
2023-01-17 11:18:53 +00:00
|
|
|
pub fn new(
|
|
|
|
device: Arc<Device>,
|
|
|
|
renderpass: &Arc<RenderPass>,
|
|
|
|
width: u32,
|
|
|
|
height: u32,
|
|
|
|
) -> Result<Self> {
|
2023-01-27 13:04:06 +00:00
|
|
|
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"))?;
|
2023-01-12 12:52:44 +00:00
|
|
|
|
2023-01-13 07:11:53 +00:00
|
|
|
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())?;
|
2023-01-12 12:52:44 +00:00
|
|
|
|
2023-01-17 11:18:53 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-01-12 12:52:44 +00:00
|
|
|
let pipeline = Pipeline::new_graphics()
|
2023-01-27 13:04:06 +00:00
|
|
|
.set_vertex_shader::<PositionOnlyVertex>(vertex_shader.clone())
|
2023-01-12 12:52:44 +00:00
|
|
|
.set_fragment_shader(fragment_shader.clone())
|
|
|
|
.input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false)
|
|
|
|
.default_depth_stencil(false, false)
|
2023-01-12 16:45:06 +00:00
|
|
|
.default_color_blend(vec![VkPipelineColorBlendAttachmentState::default()])
|
2023-01-12 12:52:44 +00:00
|
|
|
.default_rasterization(VK_CULL_MODE_NONE, VK_FRONT_FACE_COUNTER_CLOCKWISE)
|
|
|
|
.default_multisample(VK_SAMPLE_COUNT_1_BIT)
|
2023-01-17 11:18:53 +00:00
|
|
|
.add_viewport(viewport)
|
|
|
|
.add_scissor(scissor)
|
2023-01-12 12:52:44 +00:00
|
|
|
.build(device, &pipeline_layout, &renderpass, 0)?;
|
|
|
|
|
|
|
|
Ok(Self {
|
2023-01-13 07:11:53 +00:00
|
|
|
descriptor_layout,
|
2023-01-12 12:52:44 +00:00
|
|
|
pipeline,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pipeline(&self) -> &Arc<Pipeline> {
|
|
|
|
&self.pipeline
|
|
|
|
}
|
2023-01-13 07:11:53 +00:00
|
|
|
|
|
|
|
pub fn descriptor_layout(&self) -> &Arc<DescriptorSetLayout> {
|
|
|
|
&self.descriptor_layout
|
|
|
|
}
|
2023-01-12 12:52:44 +00:00
|
|
|
}
|