# queue_stage.rs - source
Source of the Rust file `maplibre/src/render/stages/queue_stage.rs`.
Keywords: rust, rustlang, rust-lang

     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

    //! Queues [PhaseItems](crate::render::render_phase::PhaseItem) for rendering.

    use crate::context::MapContext;
    use crate::coords::{ViewRegion, Zoom};
    use crate::io::tile_repository::TileRepository;
    use crate::render::camera::ViewProjection;
    use crate::render::resource::IndexEntry;
    use crate::render::shaders::{
        ShaderCamera, ShaderFeatureStyle, ShaderGlobals, ShaderLayerMetadata, Vec4f32,
    };
    use crate::render::tile_view_pattern::TileInView;
    use crate::render::util::Eventually::Initialized;
    use crate::schedule::Stage;
    use crate::{RenderState, Renderer, Style};
    use std::iter;

    #[derive(Default)]
    pub struct QueueStage;

    impl Stage for QueueStage {
        #[tracing::instrument(name = "QueueStage", skip_all)]
        fn run(
            &mut self,
            MapContext {
                view_state,
                renderer:
                    Renderer {
                        state:
                            RenderState {
                                mask_phase,
                                tile_phase,
                                tile_view_pattern,
                                buffer_pool,
                                ..
                            },
                        ..
                    },
                ..
            }: &mut MapContext,
        ) {
            mask_phase.items.clear();
            tile_phase.items.clear();

            if let (Initialized(tile_view_pattern), Initialized(buffer_pool)) =
                (tile_view_pattern, &buffer_pool)
            {
                let index = buffer_pool.index();

                for tile_in_view in tile_view_pattern.iter() {
                    let TileInView { shape, fallback } = &tile_in_view;
                    let coords = shape.coords;
                    tracing::trace!("Drawing tile at {coords}");

                    let shape_to_render = fallback.as_ref().unwrap_or(shape);

                    // Draw mask
                    mask_phase.add(tile_in_view.clone());

                    if let Some(entries) = index.get_layers(&shape_to_render.coords) {
                        let mut layers_to_render: Vec<&IndexEntry> = Vec::from_iter(entries);
                        layers_to_render.sort_by_key(|entry| entry.style_layer.index);

                        for entry in layers_to_render {
                            // Draw tile
                            tile_phase.add((entry.clone(), shape_to_render.clone()))
                        }
                    } else {
                        tracing::trace!("No layers found at {}", &shape_to_render.coords);
                    }
                }
            }
        }
    }