# debug_pass.rs - source
Source of the Rust file `maplibre/src/debug/debug_pass.rs`.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79

    use std::ops::Deref;

    use wgpu::StoreOp;

    use crate::{
        debug::TileDebugItem,
        render::{
            eventually::Eventually::Initialized,
            graph::{Node, NodeRunError, RenderContext, RenderGraphContext, SlotInfo},
            render_phase::RenderPhase,
            resource::TrackedRenderPass,
            RenderResources,
        },
        tcs::world::World,
    };

    /// Pass which renders debug information on top of the map.
    pub struct DebugPassNode {}

    impl DebugPassNode {
        pub fn new() -> Self {
            Self {}
        }
    }

    impl Node for DebugPassNode {
        fn input(&self) -> Vec<SlotInfo> {
            vec![]
        }

        fn update(&mut self, _state: &mut RenderResources) {}

        fn run(
            &self,
            _graph: &mut RenderGraphContext,
            render_context: &mut RenderContext,
            resources: &RenderResources,
            world: &World,
        ) -> Result<(), NodeRunError> {
            let Initialized(render_target) = &resources.render_target else {
                return Ok(());
            };

            let color_attachment = wgpu::RenderPassColorAttachment {
                view: render_target.deref(),
                ops: wgpu::Operations {
                    // Draws on-top of previously rendered data
                    load: wgpu::LoadOp::Load,
                    store: StoreOp::Store,
                },
                resolve_target: None,
            };

            let render_pass =
                render_context
                    .command_encoder
                    .begin_render_pass(&wgpu::RenderPassDescriptor {
                        label: Some("debug_pass"),
                        color_attachments: &[Some(color_attachment)],
                        depth_stencil_attachment: None,
                        timestamp_writes: None,
                        occlusion_query_set: None,
                    });

            let mut tracked_pass = TrackedRenderPass::new(render_pass);

            if let Some(debug_items) = world.resources.get::<RenderPhase<TileDebugItem>>() {
                log::trace!(
                    "RenderPhase<TileDebugItem>::size() = {}",
                    debug_items.size()
                );
                for item in debug_items {
                    item.draw_function.draw(&mut tracked_pass, world, item);
                }
            }

            Ok(())
        }
    }