Split Mesh data and Pipeline
This commit is contained in:
parent
4f96a1e4b5
commit
078e9daba9
13 changed files with 331 additions and 109 deletions
63
src/game/assets/meshs/square.rs
Normal file
63
src/game/assets/meshs/square.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use std::{error::Error, sync::Arc};
|
||||
|
||||
use vulkano::{buffer::Subbuffer, memory::allocator::StandardMemoryAllocator};
|
||||
|
||||
use crate::core::render::primitives::{
|
||||
AsIndexBuffer, AsRenderableMesh, AsVertexBuffer, vertex::Vertex3D,
|
||||
};
|
||||
|
||||
const VERTICES: [Vertex3D; 4] = [
|
||||
Vertex3D {
|
||||
position: [-0.5, -0.5, 0.0],
|
||||
uv: [0.0, 0.0],
|
||||
},
|
||||
Vertex3D {
|
||||
position: [-0.5, 0.5, 0.0],
|
||||
uv: [0.0, 1.0],
|
||||
},
|
||||
Vertex3D {
|
||||
position: [0.5, -0.5, 0.0],
|
||||
uv: [1.0, 0.0],
|
||||
},
|
||||
Vertex3D {
|
||||
position: [0.5, 0.5, 0.0],
|
||||
uv: [1.0, 1.0],
|
||||
},
|
||||
];
|
||||
|
||||
const INDICES: [u32; 6] = [0, 2, 1, 2, 3, 1];
|
||||
|
||||
pub struct Square {
|
||||
vertex_buffer: Subbuffer<[Vertex3D]>,
|
||||
index_buffer: Subbuffer<[u32]>,
|
||||
}
|
||||
|
||||
impl Square {
|
||||
pub fn new(memory_allocator: &Arc<StandardMemoryAllocator>) -> Result<Self, Box<dyn Error>> {
|
||||
let vertex_buffer = Vertex3D::create_vertex_buffer(memory_allocator, &VERTICES)?;
|
||||
let index_buffer = u32::create_index_buffer(memory_allocator, &INDICES)?;
|
||||
|
||||
Ok(Self {
|
||||
vertex_buffer,
|
||||
index_buffer,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRenderableMesh<Vertex3D, u32> for Square {
|
||||
fn vertex_buffer(&self) -> &Subbuffer<[Vertex3D]> {
|
||||
&self.vertex_buffer
|
||||
}
|
||||
|
||||
fn index_buffer(&self) -> Option<&Subbuffer<[u32]>> {
|
||||
Some(&self.index_buffer)
|
||||
}
|
||||
|
||||
fn vertex_count(&self) -> u32 {
|
||||
VERTICES.len() as u32
|
||||
}
|
||||
|
||||
fn index_count(&self) -> u32 {
|
||||
INDICES.len() as u32
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue