# resource_system.rs - source
Source of the Rust file `maplibre/src/vector/resource_system.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

    //! Prepares GPU-owned resources by initializing them if they are uninitialized or out-of-date.
    use crate::{
        context::MapContext,
        render::{
            eventually::Eventually,
            resource::{RenderPipeline, TilePipeline},
            shaders,
            shaders::Shader,
            RenderResources, Renderer,
        },
        vector::{resource::BufferPool, VectorBufferPool, VectorPipeline},
    };

    pub fn resource_system(
        MapContext {
            world,
            renderer:
                Renderer {
                    device,
                    resources: RenderResources { surface, .. },
                    settings,
                    ..
                },
            ..
        }: &mut MapContext,
    ) {
        let Some((buffer_pool, vector_pipeline)) = world.resources.query_mut::<(
            &mut Eventually<VectorBufferPool>,
            &mut Eventually<VectorPipeline>,
        )>() else {
            return;
        };

        buffer_pool.initialize(|| BufferPool::from_device(device));

        vector_pipeline.initialize(|| {
            let tile_shader = shaders::VectorTileShader {
                format: surface.surface_format(),
            };

            let pipeline = TilePipeline::new(
                "vector_pipeline".into(),
                *settings,
                tile_shader.describe_vertex(),
                tile_shader.describe_fragment(),
                true,
                false,
                false,
                false,
                surface.is_multisampling_supported(settings.msaa),
                false,
            )
            .describe_render_pipeline()
            .initialize(device);

            VectorPipeline(pipeline)
        });
    }