re-org en App
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
//! # Material Module — Appearance Descriptor (shader_id → RenderPipeline)
|
||||
//!
|
||||
//! Defines `Material`, a lightweight appearance descriptor that pairs a shader identifier with
|
||||
//! a shared RenderPipeline. Materials are created via PipelineCache to ensure pipeline reuse—
|
||||
//! multiple materials referencing the same shader_id point to the identical compiled GPU pipeline.
|
||||
//!
|
||||
//! ## Architecture Notes (per ARCHI_APP.md)
|
||||
//! - **Identifiants**: Each Material is registered in Scene by string identifier, enabling dynamic access
|
||||
//! during the render loop without borrow checker issues. The shader_id serves as the Handle<T> key.
|
||||
//! - **Phase de Déclaration**: Materials are instantiated once in the declarative phase before the render loop begins.
|
||||
|
||||
use crate::pipeline::PipelineCache;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Lightweight appearance descriptor: links a shader ID to a shared RenderPipeline.
|
||||
/// Does not own the pipeline; holds an Arc for zero-copy sharing across objects using the same shader.
|
||||
pub struct Material {
|
||||
/// Unique shader identifier used to look up or create a compiled RenderPipeline in PipelineCache.
|
||||
pub shader_id: String,
|
||||
/// Shared reference to the compiled GPU render pipeline. Multiple Materials can share one through Arc cloning.
|
||||
pub pipeline: Arc<wgpu::RenderPipeline>,
|
||||
}
|
||||
|
||||
impl Material {
|
||||
/// Creates a new Material by requesting the cache to provide (or create) its RenderPipeline.
|
||||
/// Inputs: device (GPU command source for pipeline creation), format (surface texture format),
|
||||
/// shader_id (unique key into PipelineCache), cache (mutable ref for potential insertion).
|
||||
/// Returns a Material holding the Arc-wrapped pipeline. Called at scene initialization time.
|
||||
pub fn new(
|
||||
device: &wgpu::Device,
|
||||
format: wgpu::TextureFormat,
|
||||
shader_id: &str,
|
||||
cache: &mut PipelineCache,
|
||||
) -> Self {
|
||||
// Request pipeline from cache — returns cached instance if already exists, creates new otherwise
|
||||
let pipeline = cache.get_or_create(device, format, shader_id);
|
||||
Self {
|
||||
shader_id: shader_id.to_string(),
|
||||
pipeline,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user