2023-01-12 12:52:44 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use vulkan_rs::prelude::*;
|
|
|
|
|
|
|
|
use std::{mem, sync::Arc};
|
|
|
|
|
|
|
|
pub struct SingleColorPipeline {
|
|
|
|
pipeline: Arc<Pipeline>,
|
|
|
|
pipeline_layout: Arc<PipelineLayout>,
|
|
|
|
|
|
|
|
vertex_shader: Arc<ShaderModule>,
|
|
|
|
fragment_shader: Arc<ShaderModule>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SingleColorPipeline {
|
|
|
|
pub fn new(device: Arc<Device>, renderpass: &Arc<RenderPass>) -> Result<Self> {
|
|
|
|
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)
|
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)
|
|
|
|
.build(device, &pipeline_layout, &renderpass, 0)?;
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
pipeline,
|
|
|
|
pipeline_layout,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pipeline(&self) -> &Arc<Pipeline> {
|
|
|
|
&self.pipeline
|
|
|
|
}
|
|
|
|
}
|