Begin work on uniform data

This commit is contained in:
Florian RICHER 2024-12-17 23:41:33 +01:00
parent 864c558db7
commit ec6e0c28be
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
2 changed files with 26 additions and 7 deletions

View file

@ -1 +1 @@
#version 450 layout (location = 0) in vec2 position; layout (location = 1) in vec3 color; layout (location = 0) out vec3 fragColor; void main() { gl_Position = vec4(position, 0.0, 1.0); fragColor = color; }
#version 450 layout (location = 0) in vec2 position; layout (location = 1) in vec3 color; layout (location = 0) out vec3 fragColor; layout (set = 0, binding = 0) uniform MVP_Data { mat4 model; mat4 view; mat4 projection; } uniforms; void main() { gl_Position = vec4(position, 0.0, 1.0); fragColor = color; }

View file

@ -1,5 +1,9 @@
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::pipeline::graphics::color_blend::{ColorBlendAttachmentState, ColorBlendState};
use vulkano::pipeline::graphics::input_assembly::InputAssemblyState;
@ -9,11 +13,11 @@ use vulkano::pipeline::graphics::subpass::PipelineRenderingCreateInfo;
use vulkano::pipeline::graphics::vertex_input::{Vertex, VertexDefinition};
use vulkano::pipeline::graphics::viewport::ViewportState;
use vulkano::pipeline::graphics::GraphicsPipelineCreateInfo;
use vulkano::pipeline::layout::PipelineDescriptorSetLayoutCreateInfo;
use vulkano::pipeline::layout::{PipelineDescriptorSetLayoutCreateInfo, PipelineLayoutCreateFlags};
use vulkano::pipeline::{
DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo,
};
use vulkano::shader::EntryPoint;
use vulkano::shader::{EntryPoint, ShaderStages};
use vulkano::swapchain::Swapchain;
use crate::renderer::Vertex2D;
@ -46,8 +50,23 @@ pub fn create_triangle_pipeline(
PipelineShaderStageCreateInfo::new(fs),
];
let create_info = PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())?;
let mut bindings = BTreeMap::<u32, DescriptorSetLayoutBinding>::new();
let mut descriptor_set_layout_binding =
DescriptorSetLayoutBinding::descriptor_type(DescriptorType::UniformBufferDynamic);
descriptor_set_layout_binding.stages = ShaderStages::VERTEX;
bindings.insert(0, descriptor_set_layout_binding);
let descriptor_set_layout = DescriptorSetLayoutCreateInfo {
bindings,
..Default::default()
};
let create_info = PipelineDescriptorSetLayoutCreateInfo {
set_layouts: vec![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)?;
@ -82,11 +101,11 @@ pub fn create_triangle_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(format!("Failed find main entry point of vertex shader"))?;
.ok_or("Failed find main entry point of vertex shader".to_string())?;
let fs = shaders::fs::load(device.clone())?
.entry_point("main")
.ok_or(format!("Failed find main entry point of fragment shader"))?;
.ok_or("Failed find main entry point of fragment shader".to_string())?;
Ok((vs, fs))
}