ajout material et pipeline_cache
This commit is contained in:
+15
@@ -1,14 +1,28 @@
|
||||
//! # Mesh Module
|
||||
//!
|
||||
//! Defines `Mesh`, a persistent GPU geometry container. Mesh data is uploaded to the GPU once at creation time
|
||||
//! and remains valid across all frames until dropped. It holds no rendering knowledge—only raw geometric data.
|
||||
|
||||
use crate::vertex::Vertex;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
/// Persistent GPU geometry: vertex positions, optional indices, and draw call counters.
|
||||
/// Created once via `Mesh::new()` during scene setup; referenced by Renderer for every frame.
|
||||
pub struct Mesh {
|
||||
/// GPU buffer containing vertex attribute data (position, UV, color).
|
||||
pub vertex_buffer: wgpu::Buffer,
|
||||
/// Optional GPU buffer for indexed drawing. Present when the mesh uses index-based rendering instead of simple vertex iteration.
|
||||
pub index_buffer: Option<wgpu::Buffer>,
|
||||
/// Number of vertices in the mesh. Used as `0..num_vertices` for non-indexed draws.
|
||||
pub num_vertices: u32,
|
||||
/// Number of indices in the index buffer. Used as `0..num_indices` for indexed draws.
|
||||
pub num_indices: u32,
|
||||
}
|
||||
|
||||
impl Mesh {
|
||||
/// Creates a new Mesh by uploading vertex and optional index data to GPU buffers.
|
||||
/// Inputs: device (GPU command source), vertices (CPU-side vertex array), indices (optional CPU-side index array).
|
||||
/// Returns a Mesh with two GPU buffers ready for rendering. Called at scene initialization time only.
|
||||
pub fn new(device: &wgpu::Device, vertices: &[Vertex], indices: Option<&[u16]>) -> Self {
|
||||
let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Mesh Vertex Buffer"),
|
||||
@@ -16,6 +30,7 @@ impl Mesh {
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
|
||||
// Create optional index buffer and count indices if provided
|
||||
let (index_buffer, num_indices) = if let Some(data) = indices {
|
||||
let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Mesh Index Buffer"),
|
||||
|
||||
Reference in New Issue
Block a user