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
//! Prepares GPU-owned resources by initializing them if they are uninitialized or out-of-date.
use crate::{
    context::MapContext,
    raster::resource::RasterResources,
    render::{
        eventually::Eventually,
        resource::{RenderPipeline, TilePipeline},
        settings::Msaa,
        shaders,
        shaders::Shader,
        RenderResources, Renderer,
    },
};

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

    raster_resources.initialize(|| {
        let shader = shaders::RasterTileShader {
            format: surface.surface_format(),
        };

        RasterResources::new(
            Msaa { samples: 1 },
            device,
            TilePipeline::new(
                "raster_pipeline".into(),
                *settings,
                shader.describe_vertex(),
                shader.describe_fragment(),
                true,
                false,
                false,
                false,
                surface.is_multisampling_supported(settings.msaa),
                true,
            )
            .describe_render_pipeline()
            .initialize(device),
        )
    });
}