render: Add AsBindableDescriptorSet
This commit is contained in:
parent
b7bc6478e2
commit
5539381f46
4 changed files with 115 additions and 47 deletions
|
@ -31,7 +31,7 @@ use vulkano::{
|
|||
};
|
||||
|
||||
use crate::core::render::{
|
||||
primitives::{mvp::Mvp, transform::TransformRaw, vertex::Vertex3D},
|
||||
primitives::{AsBindableDescriptorSet, mvp::Mvp, transform::TransformRaw, vertex::Vertex3D},
|
||||
texture::Texture,
|
||||
};
|
||||
|
||||
|
@ -130,29 +130,8 @@ impl Square {
|
|||
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_bindings = Mvp::as_descriptor_set_layout_bindings();
|
||||
let texture_bindings = Texture::as_descriptor_set_layout_bindings();
|
||||
|
||||
let vertex_descriptor_set_layout = DescriptorSetLayoutCreateInfo {
|
||||
bindings: vertex_bindings,
|
||||
|
@ -160,7 +139,7 @@ impl Square {
|
|||
};
|
||||
|
||||
let fragment_descriptor_set_layout = DescriptorSetLayoutCreateInfo {
|
||||
bindings: fragment_bindings,
|
||||
bindings: texture_bindings,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
@ -220,22 +199,11 @@ impl Square {
|
|||
) -> Result<(), Box<dyn Error>> {
|
||||
let layouts = self.pipeline.layout().set_layouts();
|
||||
|
||||
let uniform_descriptor_set = DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
layouts[0].clone(),
|
||||
[WriteDescriptorSet::buffer(0, mvp_uniform.clone())],
|
||||
[],
|
||||
)?;
|
||||
let uniform_descriptor_set =
|
||||
Mvp::as_descriptor_set(descriptor_set_allocator, &layouts[0], mvp_uniform)?;
|
||||
|
||||
let texture_descriptor_set = DescriptorSet::new(
|
||||
descriptor_set_allocator.clone(),
|
||||
layouts[1].clone(),
|
||||
[
|
||||
WriteDescriptorSet::sampler(0, texture.get_sampler().clone()),
|
||||
WriteDescriptorSet::image_view(1, texture.get_texture().clone()),
|
||||
],
|
||||
[],
|
||||
)?;
|
||||
let texture_descriptor_set =
|
||||
Texture::as_descriptor_set(descriptor_set_allocator, &layouts[1], texture)?;
|
||||
|
||||
command_buffer.bind_pipeline_graphics(self.pipeline.clone())?;
|
||||
command_buffer.bind_descriptor_sets(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue