Skip to main content

awsm_renderer/
load_phase.rs

1//! Coarse load-time progress phases a scene/asset loader reports so a host can
2//! show "what's happening now" while a bundle or model materializes.
3//!
4//! Player-agnostic: the loader (`populate_awsm_scene`, and in time the glTF
5//! loader) emits these through a caller-supplied callback; the editor maps them
6//! to its activity pill, a headless player can log them. Driving it by callback
7//! (rather than a render-loop-polled field) means the host sees live updates
8//! even while a loader holds the renderer lock across its awaits — the awaits
9//! yield to the event loop, so a reactive UI signal the callback updates still
10//! renders.
11
12use crate::pipeline_scheduler::CompileProgress;
13
14/// One stage of a scene/asset load, in the order a phased loader runs them.
15#[derive(Clone, Debug)]
16pub enum LoadPhase {
17    /// Lowering authored materials to renderer materials + inserting them.
18    BuildingMaterials { done: usize, total: usize },
19    /// Committing all staged texture images to the GPU (one batched upload).
20    UploadingTextures,
21    /// Uploading mesh geometry (+ skins) referencing the already-built materials.
22    UploadingMeshes { done: usize, total: usize },
23    /// Driving pipeline compilation to completion (wraps the renderer's
24    /// [`CompileProgress`] snapshot).
25    CompilingPipelines(CompileProgress),
26}
27
28impl LoadPhase {
29    /// A short human label for an activity indicator / log line.
30    pub fn label(&self) -> String {
31        match self {
32            LoadPhase::BuildingMaterials { done, total } => {
33                format!("Building materials {done}/{total}…")
34            }
35            LoadPhase::UploadingTextures => "Uploading textures…".to_string(),
36            LoadPhase::UploadingMeshes { done, total } => {
37                format!("Uploading meshes {done}/{total}…")
38            }
39            LoadPhase::CompilingPipelines(p) => {
40                let n = p.materials_pending + p.in_flight_subcompiles as usize;
41                format!("Compiling pipelines ({n})…")
42            }
43        }
44    }
45}