use std::sync::Arc; use vulkano::buffer::Subbuffer; use vulkano::buffer::allocator::SubbufferAllocator; use vulkano::command_buffer::allocator::StandardCommandBufferAllocator; use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer}; use vulkano::descriptor_set::DescriptorSet; use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator; use vulkano::device::Device; use vulkano::memory::allocator::StandardMemoryAllocator; use vulkano::pipeline::GraphicsPipeline; use vulkano::pipeline::Pipeline; use crate::vulkan::resources::vertex::Vertex2D; #[derive(Clone)] pub struct Mesh { pub vertex_buffer: Subbuffer<[Vertex2D]>, pub vertex_count: u32, pub instance_count: u32, } #[derive(Clone)] pub struct Material { pub pipeline: Arc, pub descriptor_set: Arc, } #[derive(Clone)] pub struct Transform { pub position: [f32; 3], pub rotation: [f32; 3], pub scale: [f32; 3], } #[derive(Clone)] pub struct RenderResources { pub device: Arc, pub memory_allocator: Arc, pub command_buffer_allocator: Arc, pub uniform_buffer_allocator: Arc, pub descriptor_set_allocator: Arc, } pub struct Entity { pub mesh: Mesh, pub material: Material, pub transform: Transform, } pub fn render_system( _resources: &RenderResources, builder: &mut AutoCommandBufferBuilder, entities: &[Entity], ) -> Result<(), Box> { for entity in entities { unsafe { builder .bind_pipeline_graphics(entity.material.pipeline.clone())? .bind_descriptor_sets( vulkano::pipeline::PipelineBindPoint::Graphics, entity.material.pipeline.layout().clone(), 0, entity.material.descriptor_set.clone(), )? .bind_vertex_buffers(0, entity.mesh.vertex_buffer.clone())? .draw(entity.mesh.vertex_count, entity.mesh.instance_count, 0, 0)?; } } Ok(()) }