Try refactor with cursor
This commit is contained in:
parent
62275f20d9
commit
42db1a33a0
18 changed files with 855 additions and 594 deletions
71
src/renderer/components.rs
Normal file
71
src/renderer/components.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
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<GraphicsPipeline>,
|
||||
pub descriptor_set: Arc<DescriptorSet>,
|
||||
}
|
||||
|
||||
#[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<Device>,
|
||||
pub memory_allocator: Arc<StandardMemoryAllocator>,
|
||||
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
pub uniform_buffer_allocator: Arc<SubbufferAllocator>,
|
||||
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
}
|
||||
|
||||
pub struct Entity {
|
||||
pub mesh: Mesh,
|
||||
pub material: Material,
|
||||
pub transform: Transform,
|
||||
}
|
||||
|
||||
pub fn render_system(
|
||||
_resources: &RenderResources,
|
||||
builder: &mut AutoCommandBufferBuilder<PrimaryAutoCommandBuffer>,
|
||||
entities: &[Entity],
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
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(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue