Document new Mesh system
This commit is contained in:
parent
c1e8fea84a
commit
e4ccf95a2f
@ -82,7 +82,19 @@ impl ColorVertex {
|
||||
}
|
||||
}
|
||||
|
||||
//--GpuMesh struct----------------------------------------------------------------------------------
|
||||
//--Mesh struct-------------------------------------------------------------------------------------
|
||||
|
||||
/// Handles the buffers to be used to draw a Mesh
|
||||
///
|
||||
/// The mesh consist of an array of vertices, and its ccorresponding indices.
|
||||
///
|
||||
/// A vertex can be any type that can be converted to a byte array using the bytemuck crate.
|
||||
/// Generaly, adding `#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]` to a struct
|
||||
/// is enough for that.
|
||||
///
|
||||
/// An index is a standard u16
|
||||
///
|
||||
/// A mesh can be used with, and only with, the renderer for wich it was created
|
||||
pub struct Mesh<V, const V_NB: usize, const I_NB: usize>
|
||||
where
|
||||
V: Copy + Clone + bytemuck::Pod + bytemuck::Zeroable,
|
||||
@ -97,6 +109,7 @@ impl <V, const V_NB: usize, const I_NB: usize> Mesh<V, V_NB, I_NB>
|
||||
where
|
||||
V: Copy + Clone + bytemuck::Pod + bytemuck::Zeroable + std::fmt::Debug
|
||||
{
|
||||
/// Creates a new mesh using the [Device] from the renderer to be used
|
||||
pub fn new(device: &wgpu::Device) -> Self {
|
||||
use std::mem::size_of;
|
||||
use wgpu_types::BufferUsages as Usages;
|
||||
@ -126,18 +139,26 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the vertices of the [Mesh]. The modification will be applied before the next
|
||||
/// rendering of the [Mesh]. The function will fail if the given slice has more elements than
|
||||
/// specified at the [Mesh] creation
|
||||
pub fn set_vertices(&mut self, renderer: &WgpuRenderer, vertices: &[V]) {
|
||||
renderer.queue.write_buffer(&self.vertex_buffer, 0, bytemuck::cast_slice(vertices));
|
||||
}
|
||||
|
||||
/// Updates the indices of the [Mesh]. The modification will be applied before the next
|
||||
/// rendering of the [Mesh]. The function will fail if the given slice has more elements than
|
||||
/// specified at the [Mesh] creation
|
||||
pub fn set_indices(&mut self, renderer: &WgpuRenderer, indices: &[u16]) {
|
||||
renderer.queue.write_buffer(&self.index_buffer, 0, bytemuck::cast_slice(indices));
|
||||
}
|
||||
|
||||
/// Returns a [BufferSlice] containing the vertices, to be used in a render pass
|
||||
pub fn get_vertex_buffer_slice(&self) -> wgpu::BufferSlice {
|
||||
self.vertex_buffer.slice(..)
|
||||
}
|
||||
|
||||
/// Returns a [BufferSlice] containing the indices, to be used in a render pass
|
||||
pub fn get_index_buffer_slice(&self) -> wgpu::BufferSlice {
|
||||
self.index_buffer.slice(..)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user