Split Mesh data and Pipeline
This commit is contained in:
parent
4f96a1e4b5
commit
078e9daba9
13 changed files with 331 additions and 109 deletions
|
@ -86,6 +86,7 @@ pub struct SquareRenderData<'a> {
|
|||
pub square: &'a Square,
|
||||
pub mvp_uniform: &'a Subbuffer<[Mvp]>,
|
||||
pub transform_uniform: &'a Subbuffer<[TransformRaw]>,
|
||||
pub descriptor_sets: &'a [Arc<DescriptorSet>],
|
||||
pub texture: &'a Texture,
|
||||
}
|
||||
|
||||
|
@ -183,13 +184,6 @@ impl Square {
|
|||
transform_uniform: &Subbuffer<[TransformRaw]>,
|
||||
texture: &Texture,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let render_data = SquareRenderData {
|
||||
square: self,
|
||||
mvp_uniform,
|
||||
transform_uniform,
|
||||
texture,
|
||||
};
|
||||
|
||||
let layouts = self.pipeline.layout().set_layouts();
|
||||
|
||||
let uniform_descriptor_set =
|
||||
|
@ -198,50 +192,26 @@ impl Square {
|
|||
let texture_descriptor_set =
|
||||
Texture::as_descriptor_set(descriptor_set_allocator, &layouts[1], texture)?;
|
||||
|
||||
let render_data = SquareRenderData {
|
||||
square: self,
|
||||
mvp_uniform,
|
||||
transform_uniform,
|
||||
texture,
|
||||
descriptor_sets: &[uniform_descriptor_set, texture_descriptor_set],
|
||||
};
|
||||
|
||||
// Utiliser les nouveaux traits pour le rendu
|
||||
Self::record_render_commands(
|
||||
command_buffer,
|
||||
&render_data,
|
||||
&self.pipeline,
|
||||
&[uniform_descriptor_set, texture_descriptor_set],
|
||||
)?;
|
||||
Self::record_render_commands(command_buffer, &self.pipeline, &render_data)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Implémentation des nouveaux traits pour Square
|
||||
impl<'a> AsDrawable<SquareRenderData<'a>> for Square {
|
||||
type VertexBuffer = Subbuffer<[Vertex3D]>;
|
||||
type IndexBuffer = Subbuffer<[u32]>;
|
||||
|
||||
fn vertex_buffer(data: &SquareRenderData<'a>) -> &'a Self::VertexBuffer {
|
||||
&data.square.vertex_buffer
|
||||
}
|
||||
|
||||
fn index_buffer(data: &SquareRenderData<'a>) -> Option<&'a Self::IndexBuffer> {
|
||||
Some(&data.square.index_buffer)
|
||||
}
|
||||
|
||||
fn vertex_count(_data: &SquareRenderData<'a>) -> u32 {
|
||||
VERTICES.len() as u32
|
||||
}
|
||||
|
||||
fn index_count(_data: &SquareRenderData<'a>) -> u32 {
|
||||
INDICES.len() as u32
|
||||
}
|
||||
|
||||
fn instance_count(data: &SquareRenderData<'a>) -> u32 {
|
||||
data.transform_uniform.len() as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRecordable<SquareRenderData<'a>> for Square {
|
||||
fn record_render_commands(
|
||||
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
data: &SquareRenderData<'a>,
|
||||
pipeline: &Arc<GraphicsPipeline>,
|
||||
descriptor_sets: &[Arc<DescriptorSet>],
|
||||
data: &SquareRenderData<'a>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// Bind pipeline
|
||||
builder.bind_pipeline_graphics(pipeline.clone())?;
|
||||
|
@ -251,7 +221,7 @@ impl<'a> AsRecordable<SquareRenderData<'a>> for Square {
|
|||
PipelineBindPoint::Graphics,
|
||||
pipeline.layout().clone(),
|
||||
0,
|
||||
descriptor_sets.iter().cloned().collect::<Vec<_>>(),
|
||||
data.descriptor_sets.iter().cloned().collect::<Vec<_>>(),
|
||||
)?;
|
||||
|
||||
// Bind buffers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue