maplibre/debug/
mod.rs

1use std::{ops::Deref, rc::Rc};
2
3use crate::{
4    debug::{
5        cleanup_system::cleanup_system, debug_pass::DebugPassNode, fps_system::fps_system,
6        queue_system::queue_system, resource_system::resource_system,
7    },
8    environment::Environment,
9    kernel::Kernel,
10    plugin::Plugin,
11    render::{
12        eventually::Eventually,
13        graph::RenderGraph,
14        render_phase::{Draw, PhaseItem, RenderPhase},
15        tile_view_pattern::TileShape,
16        RenderStageLabel,
17    },
18    schedule::Schedule,
19    tcs::world::World,
20    util::FPSMeter,
21};
22
23mod cleanup_system;
24mod debug_pass;
25mod fps_system;
26mod queue_system;
27mod render_commands;
28mod resource_system;
29
30/// Labels for the "draw" graph
31mod draw_graph {
32    pub const NAME: &str = "draw";
33    // Labels for input nodes
34    pub mod input {}
35    // Labels for non-input nodes
36    pub mod node {
37        pub const MAIN_PASS: &str = "main_pass";
38        pub const DEBUG_PASS: &str = "debug_pass";
39    }
40}
41
42struct DebugPipeline(wgpu::RenderPipeline);
43impl Deref for DebugPipeline {
44    type Target = wgpu::RenderPipeline;
45
46    fn deref(&self) -> &Self::Target {
47        &self.0
48    }
49}
50
51struct TileDebugItem {
52    pub draw_function: Box<dyn Draw<TileDebugItem>>,
53    pub source_shape: TileShape,
54}
55
56impl PhaseItem for TileDebugItem {
57    type SortKey = u32;
58
59    fn sort_key(&self) -> Self::SortKey {
60        0
61    }
62
63    fn draw_function(&self) -> &dyn Draw<TileDebugItem> {
64        self.draw_function.as_ref()
65    }
66}
67
68#[derive(Default)]
69pub struct DebugPlugin;
70
71impl<E: Environment> Plugin<E> for DebugPlugin {
72    fn build(
73        &self,
74        schedule: &mut Schedule,
75        _kernel: Rc<Kernel<E>>,
76        world: &mut World,
77        graph: &mut RenderGraph,
78    ) {
79        let resources = &mut world.resources;
80
81        let draw_graph = graph.get_sub_graph_mut(draw_graph::NAME).unwrap();
82        draw_graph.add_node(draw_graph::node::DEBUG_PASS, DebugPassNode::new());
83
84        // FIXME: remove this dependency to translucent pass
85        draw_graph
86            .add_node_edge("translucent_pass", draw_graph::node::DEBUG_PASS)
87            .unwrap();
88
89        resources.init::<RenderPhase<TileDebugItem>>();
90        resources.insert(Eventually::<DebugPipeline>::Uninitialized);
91
92        schedule.add_system_to_stage(RenderStageLabel::Prepare, resource_system);
93        schedule.add_system_to_stage(RenderStageLabel::Queue, queue_system);
94        schedule.add_system_to_stage(RenderStageLabel::Cleanup, cleanup_system);
95
96        resources.insert(FPSMeter::new());
97        schedule.add_system_to_stage(RenderStageLabel::Cleanup, fps_system);
98    }
99}