Remove all generics in AsRecordable

This commit is contained in:
Florian RICHER 2025-06-09 16:26:14 +02:00
parent 883014998f
commit 50aabaa6ee
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
5 changed files with 36 additions and 30 deletions

View file

@ -1,7 +1,7 @@
use std::{error::Error, sync::Arc}; use std::{error::Error, sync::Arc};
use vulkano::{ use vulkano::{
buffer::{IndexBuffer, Subbuffer}, buffer::{BufferContents, IndexBuffer, Subbuffer},
command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer}, command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer},
descriptor_set::allocator::StandardDescriptorSetAllocator, descriptor_set::allocator::StandardDescriptorSetAllocator,
pipeline::GraphicsPipeline, pipeline::GraphicsPipeline,
@ -9,23 +9,20 @@ use vulkano::{
use super::AsDescriptorSet; use super::AsDescriptorSet;
pub trait AsRecordable<V, MI, I> pub trait AsRecordable {
where
MI: Into<IndexBuffer> + Clone,
{
fn record_bind_commands( fn record_bind_commands(
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>, builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
descriptor_set_allocator: &Arc<StandardDescriptorSetAllocator>, descriptor_set_allocator: &Arc<StandardDescriptorSetAllocator>,
pipeline: &Arc<GraphicsPipeline>, pipeline: &Arc<GraphicsPipeline>,
mesh: &impl AsRenderableMesh<V, MI>, mesh: &impl AsRenderableMesh,
instances: &impl AsRenderableMeshInstance<I>, instances: &impl AsRenderableMeshInstance,
descriptor_sets: Vec<Arc<dyn AsDescriptorSet>>, descriptor_sets: Vec<Arc<dyn AsDescriptorSet>>,
) -> Result<(), Box<dyn Error>>; ) -> Result<(), Box<dyn Error>>;
fn record_draw_commands( fn record_draw_commands(
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>, builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
mesh: &impl AsRenderableMesh<V, MI>, mesh: &impl AsRenderableMesh,
instances: &impl AsRenderableMeshInstance<I>, instances: &impl AsRenderableMeshInstance,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
match mesh.index_buffer() { match mesh.index_buffer() {
Some(index_buffer) => { Some(index_buffer) => {
@ -54,11 +51,11 @@ where
} }
} }
pub trait AsRenderableMesh<V, I> pub trait AsRenderableMesh {
where type VertexBufferContentsType: BufferContents + Clone;
I: Into<IndexBuffer> + Clone, type IndexBufferType: Into<IndexBuffer> + Clone;
{
fn vertex_buffer(&self) -> &Subbuffer<[V]>; fn vertex_buffer(&self) -> &Subbuffer<[Self::VertexBufferContentsType]>;
fn vertex_count(&self) -> u32; fn vertex_count(&self) -> u32;
@ -70,7 +67,7 @@ where
0 0
} }
fn index_buffer(&self) -> Option<&I> { fn index_buffer(&self) -> Option<&Self::IndexBufferType> {
None None
} }
@ -83,8 +80,10 @@ where
} }
} }
pub trait AsRenderableMeshInstance<T> { pub trait AsRenderableMeshInstance {
fn instance_buffer(&self) -> &Subbuffer<[T]>; type InstanceBufferContents: BufferContents + Clone;
fn instance_buffer(&self) -> &Subbuffer<[Self::InstanceBufferContents]>;
fn instance_count(&self) -> u32; fn instance_count(&self) -> u32;

View file

@ -164,8 +164,10 @@ impl AsBindableBuffer<TransformRaw> for TransformRaw {
impl AsVertexBuffer<TransformRaw> for TransformRaw {} impl AsVertexBuffer<TransformRaw> for TransformRaw {}
impl AsRenderableMeshInstance<TransformRaw> for Subbuffer<[TransformRaw]> { impl AsRenderableMeshInstance for Subbuffer<[TransformRaw]> {
fn instance_buffer(&self) -> &Subbuffer<[TransformRaw]> { type InstanceBufferContents = TransformRaw;
fn instance_buffer(&self) -> &Subbuffer<[Self::InstanceBufferContents]> {
self self
} }

View file

@ -57,12 +57,15 @@ impl ObjMesh {
} }
} }
impl AsRenderableMesh<Vertex3D, Subbuffer<[u32]>> for ObjMesh { impl AsRenderableMesh for ObjMesh {
fn vertex_buffer(&self) -> &Subbuffer<[Vertex3D]> { type VertexBufferContentsType = Vertex3D;
type IndexBufferType = Subbuffer<[u32]>;
fn vertex_buffer(&self) -> &Subbuffer<[Self::VertexBufferContentsType]> {
&self.vertex_buffer &self.vertex_buffer
} }
fn index_buffer(&self) -> Option<&Subbuffer<[u32]>> { fn index_buffer(&self) -> Option<&Self::IndexBufferType> {
Some(&self.index_buffer) Some(&self.index_buffer)
} }

View file

@ -44,12 +44,15 @@ impl SquareMesh {
} }
} }
impl AsRenderableMesh<Vertex3D, Subbuffer<[u32]>> for SquareMesh { impl AsRenderableMesh for SquareMesh {
fn vertex_buffer(&self) -> &Subbuffer<[Vertex3D]> { type VertexBufferContentsType = Vertex3D;
type IndexBufferType = Subbuffer<[u32]>;
fn vertex_buffer(&self) -> &Subbuffer<[Self::VertexBufferContentsType]> {
&self.vertex_buffer &self.vertex_buffer
} }
fn index_buffer(&self) -> Option<&Subbuffer<[u32]>> { fn index_buffer(&self) -> Option<&Self::IndexBufferType> {
Some(&self.index_buffer) Some(&self.index_buffer)
} }

View file

@ -1,7 +1,6 @@
use std::{collections::HashMap, error::Error, sync::Arc}; use std::{error::Error, sync::Arc};
use vulkano::{ use vulkano::{
buffer::Subbuffer,
command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer}, command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer},
descriptor_set::{ descriptor_set::{
allocator::StandardDescriptorSetAllocator, layout::DescriptorSetLayoutCreateInfo, allocator::StandardDescriptorSetAllocator, layout::DescriptorSetLayoutCreateInfo,
@ -120,13 +119,13 @@ impl SimplePipeline {
} }
} }
impl AsRecordable<Vertex3D, Subbuffer<[u32]>, TransformRaw> for SimplePipeline { impl AsRecordable for SimplePipeline {
fn record_bind_commands( fn record_bind_commands(
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>, builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
descriptor_set_allocator: &Arc<StandardDescriptorSetAllocator>, descriptor_set_allocator: &Arc<StandardDescriptorSetAllocator>,
pipeline: &Arc<GraphicsPipeline>, pipeline: &Arc<GraphicsPipeline>,
mesh: &impl AsRenderableMesh<Vertex3D, Subbuffer<[u32]>>, mesh: &impl AsRenderableMesh,
instances: &impl AsRenderableMeshInstance<TransformRaw>, instances: &impl AsRenderableMeshInstance,
descriptor_sets: Vec<Arc<dyn AsDescriptorSet>>, descriptor_sets: Vec<Arc<dyn AsDescriptorSet>>,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
builder.bind_pipeline_graphics(pipeline.clone())?; builder.bind_pipeline_graphics(pipeline.clone())?;