Begin move mesh + Vertex and Camera into core

This commit is contained in:
Florian RICHER 2025-04-04 13:38:27 +02:00
parent 2fbf4e6ce2
commit 852d72d716
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
11 changed files with 64 additions and 3 deletions

38
src/core/render/vertex.rs Normal file
View file

@ -0,0 +1,38 @@
use std::sync::Arc;
use vulkano::buffer::{
AllocateBufferError, Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer,
};
use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator};
use vulkano::pipeline::graphics::vertex_input::Vertex;
use vulkano::Validated;
#[derive(BufferContents, Vertex)]
#[repr(C)]
pub struct Vertex2D {
#[format(R32G32_SFLOAT)]
pub position: [f32; 2],
#[format(R32G32B32_SFLOAT)]
pub color: [f32; 3],
}
impl Vertex2D {
pub fn create_buffer(
vertices: Vec<Vertex2D>,
memory_allocator: &Arc<StandardMemoryAllocator>,
) -> Result<Subbuffer<[Vertex2D]>, Validated<AllocateBufferError>> {
Buffer::from_iter(
memory_allocator.clone(),
BufferCreateInfo {
usage: BufferUsage::VERTEX_BUFFER,
..Default::default()
},
AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
},
vertices,
)
}
}