pipeline: Refactor square pipeline + add support of indexes
This commit is contained in:
parent
122f577a26
commit
131811a539
9 changed files with 270 additions and 217 deletions
|
@ -19,7 +19,7 @@ use vulkano_util::context::VulkanoContext;
|
|||
use vulkano_util::renderer::VulkanoWindowRenderer;
|
||||
use vulkano_util::window::{VulkanoWindows, WindowDescriptor};
|
||||
use winit::application::ApplicationHandler;
|
||||
use winit::event::{DeviceEvent, WindowEvent};
|
||||
use winit::event::WindowEvent;
|
||||
use winit::event_loop::ActiveEventLoop;
|
||||
use winit::window::WindowId;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
pub mod pipelines;
|
||||
pub mod primitives;
|
||||
pub mod render_context;
|
||||
pub mod texture;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
pub mod triangle_pipeline;
|
|
@ -1,140 +0,0 @@
|
|||
use std::collections::BTreeMap;
|
||||
use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
use vulkano::descriptor_set::layout::{
|
||||
DescriptorSetLayoutBinding, DescriptorSetLayoutCreateInfo, DescriptorType,
|
||||
};
|
||||
use vulkano::device::Device;
|
||||
use vulkano::format::Format;
|
||||
use vulkano::pipeline::graphics::GraphicsPipelineCreateInfo;
|
||||
use vulkano::pipeline::graphics::color_blend::{ColorBlendAttachmentState, ColorBlendState};
|
||||
use vulkano::pipeline::graphics::input_assembly::{InputAssemblyState, PrimitiveTopology};
|
||||
use vulkano::pipeline::graphics::multisample::MultisampleState;
|
||||
use vulkano::pipeline::graphics::rasterization::RasterizationState;
|
||||
use vulkano::pipeline::graphics::subpass::PipelineRenderingCreateInfo;
|
||||
use vulkano::pipeline::graphics::vertex_input::{Vertex, VertexDefinition};
|
||||
use vulkano::pipeline::graphics::viewport::ViewportState;
|
||||
use vulkano::pipeline::layout::{PipelineDescriptorSetLayoutCreateInfo, PipelineLayoutCreateFlags};
|
||||
use vulkano::pipeline::{
|
||||
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
|
||||
};
|
||||
use vulkano::shader::{EntryPoint, ShaderStages};
|
||||
|
||||
use crate::core::render::primitives::vertex::Vertex2D;
|
||||
|
||||
pub mod shaders {
|
||||
pub mod vs {
|
||||
vulkano_shaders::shader! {
|
||||
ty: "vertex",
|
||||
path: r"res/shaders/vertex.vert",
|
||||
generate_structs: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod fs {
|
||||
vulkano_shaders::shader! {
|
||||
ty: "fragment",
|
||||
path: r"res/shaders/vertex.frag",
|
||||
generate_structs: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_triangle_pipeline(
|
||||
device: &Arc<Device>,
|
||||
swapchain_format: Format,
|
||||
) -> Result<Arc<GraphicsPipeline>, Box<dyn Error>> {
|
||||
let (vs, fs) = load_shaders(device)?;
|
||||
let vertex_input_state = Vertex2D::per_vertex().definition(&vs)?;
|
||||
log::trace!("vertex_input_state: {:#?}", vertex_input_state);
|
||||
|
||||
let stages = [
|
||||
PipelineShaderStageCreateInfo::new(vs),
|
||||
PipelineShaderStageCreateInfo::new(fs),
|
||||
];
|
||||
|
||||
let vertex_bindings = BTreeMap::<u32, DescriptorSetLayoutBinding>::from_iter([(
|
||||
0,
|
||||
DescriptorSetLayoutBinding {
|
||||
stages: ShaderStages::VERTEX,
|
||||
..DescriptorSetLayoutBinding::descriptor_type(DescriptorType::UniformBuffer)
|
||||
},
|
||||
)]);
|
||||
let fragment_bindings = BTreeMap::<u32, DescriptorSetLayoutBinding>::from_iter([
|
||||
(
|
||||
0,
|
||||
DescriptorSetLayoutBinding {
|
||||
stages: ShaderStages::FRAGMENT,
|
||||
..DescriptorSetLayoutBinding::descriptor_type(DescriptorType::Sampler)
|
||||
},
|
||||
),
|
||||
(
|
||||
1,
|
||||
DescriptorSetLayoutBinding {
|
||||
stages: ShaderStages::FRAGMENT,
|
||||
..DescriptorSetLayoutBinding::descriptor_type(DescriptorType::SampledImage)
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
let vertex_descriptor_set_layout = DescriptorSetLayoutCreateInfo {
|
||||
bindings: vertex_bindings,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let fragment_descriptor_set_layout = DescriptorSetLayoutCreateInfo {
|
||||
bindings: fragment_bindings,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let create_info = PipelineDescriptorSetLayoutCreateInfo {
|
||||
set_layouts: vec![vertex_descriptor_set_layout, fragment_descriptor_set_layout],
|
||||
flags: PipelineLayoutCreateFlags::default(),
|
||||
push_constant_ranges: vec![],
|
||||
}
|
||||
.into_pipeline_layout_create_info(device.clone())?;
|
||||
|
||||
let layout = PipelineLayout::new(device.clone(), create_info)?;
|
||||
|
||||
let subpass = PipelineRenderingCreateInfo {
|
||||
color_attachment_formats: vec![Some(swapchain_format)],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let pipeline = GraphicsPipeline::new(
|
||||
device.clone(),
|
||||
None,
|
||||
GraphicsPipelineCreateInfo {
|
||||
stages: stages.into_iter().collect(),
|
||||
vertex_input_state: Some(vertex_input_state),
|
||||
input_assembly_state: Some(InputAssemblyState {
|
||||
topology: PrimitiveTopology::TriangleStrip,
|
||||
..Default::default()
|
||||
}),
|
||||
viewport_state: Some(ViewportState::default()),
|
||||
rasterization_state: Some(RasterizationState::default()),
|
||||
multisample_state: Some(MultisampleState::default()),
|
||||
color_blend_state: Some(ColorBlendState::with_attachment_states(
|
||||
subpass.color_attachment_formats.len() as u32,
|
||||
ColorBlendAttachmentState::default(),
|
||||
)),
|
||||
dynamic_state: [DynamicState::Viewport].into_iter().collect(),
|
||||
subpass: Some(subpass.into()),
|
||||
..GraphicsPipelineCreateInfo::layout(layout)
|
||||
},
|
||||
)?;
|
||||
|
||||
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("Failed find main entry point of vertex shader".to_string())?;
|
||||
|
||||
let fs = shaders::fs::load(device.clone())?
|
||||
.entry_point("main")
|
||||
.ok_or("Failed find main entry point of fragment shader".to_string())?;
|
||||
|
||||
Ok((vs, fs))
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
pub mod camera;
|
||||
mod mvp;
|
||||
pub mod mvp;
|
||||
pub mod transform;
|
||||
pub mod vertex;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue