Reduce Generics in pipeline rendering
This commit is contained in:
parent
90a5b5d117
commit
0174aeb60e
8 changed files with 92 additions and 76 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{error::Error, sync::Arc};
|
||||
use std::{collections::HashMap, error::Error, sync::Arc};
|
||||
|
||||
use vulkano::{
|
||||
buffer::Subbuffer,
|
||||
|
@ -28,17 +28,12 @@ use vulkano::{
|
|||
|
||||
use crate::core::render::{
|
||||
primitives::{
|
||||
AsBindableDescriptorSet, AsRecordable, AsRenderableMesh, AsRenderableMeshInstance,
|
||||
mvp::Mvp, transform::TransformRaw, vertex::Vertex3D,
|
||||
AsDescriptorSet, AsDescriptorSetLayoutBindings, AsRecordable, AsRenderableMesh,
|
||||
AsRenderableMeshInstance, mvp::Mvp, transform::TransformRaw, vertex::Vertex3D,
|
||||
},
|
||||
resources::texture::Texture,
|
||||
};
|
||||
|
||||
pub struct SimplePipelineRenderData<'a> {
|
||||
pub mvp_uniform: &'a Subbuffer<[Mvp]>,
|
||||
pub texture: &'a Texture,
|
||||
}
|
||||
|
||||
pub struct SimplePipeline {
|
||||
pipeline: Arc<GraphicsPipeline>,
|
||||
}
|
||||
|
@ -125,33 +120,35 @@ impl SimplePipeline {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRecordable<SimplePipelineRenderData<'a>, Vertex3D, Subbuffer<[u32]>, TransformRaw>
|
||||
for SimplePipeline
|
||||
{
|
||||
impl AsRecordable<Vertex3D, Subbuffer<[u32]>, TransformRaw> for SimplePipeline {
|
||||
fn record_bind_commands(
|
||||
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
descriptor_set_allocator: &Arc<StandardDescriptorSetAllocator>,
|
||||
pipeline: &Arc<GraphicsPipeline>,
|
||||
mesh: &impl AsRenderableMesh<Vertex3D, Subbuffer<[u32]>>,
|
||||
instances: &impl AsRenderableMeshInstance<TransformRaw>,
|
||||
data: &SimplePipelineRenderData<'a>,
|
||||
descriptor_sets: Vec<Arc<dyn AsDescriptorSet>>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let layouts = pipeline.layout().set_layouts();
|
||||
|
||||
let uniform_descriptor_set =
|
||||
Mvp::as_descriptor_set(descriptor_set_allocator, &layouts[0], data.mvp_uniform)?;
|
||||
|
||||
let texture_descriptor_set =
|
||||
Texture::as_descriptor_set(descriptor_set_allocator, &layouts[1], data.texture)?;
|
||||
|
||||
builder.bind_pipeline_graphics(pipeline.clone())?;
|
||||
|
||||
builder.bind_descriptor_sets(
|
||||
PipelineBindPoint::Graphics,
|
||||
pipeline.layout().clone(),
|
||||
0,
|
||||
vec![uniform_descriptor_set, texture_descriptor_set],
|
||||
)?;
|
||||
if !descriptor_sets.is_empty() {
|
||||
let layouts = pipeline.layout().set_layouts();
|
||||
|
||||
let descriptor_sets = descriptor_sets
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(layout_index, data)| {
|
||||
data.as_descriptor_set(descriptor_set_allocator, &layouts[layout_index])
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
builder.bind_descriptor_sets(
|
||||
PipelineBindPoint::Graphics,
|
||||
pipeline.layout().clone(),
|
||||
0,
|
||||
descriptor_sets,
|
||||
)?;
|
||||
}
|
||||
|
||||
builder.bind_vertex_buffers(
|
||||
0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue