swamp_render_wgpu/
plugin.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
/*
 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp
 * Licensed under the MIT License. See LICENSE in the project root for license information.
 */
use crate::Render;

use limnus_app::prelude::{App, Plugin};
use limnus_screen::{Window, WindowMessage};
use limnus_system_params::{Msg, ReM};
use limnus_system_runner::UpdatePhase;
use limnus_wgpu_window::WgpuWindow;
use monotonic_time_rs::Millis;
use std::sync::Arc;
use tracing::debug;

fn tick(mut wgpu_render: ReM<Render>, window_messages: Msg<WindowMessage>) {
    for msg in window_messages.iter_previous() {
        if let WindowMessage::Resized(size) = msg {
            debug!("wgpu_render detected resized to {:?}", size);
            wgpu_render.resize(*size)
        }
    }
}

pub struct RenderWgpuPlugin;

impl Plugin for RenderWgpuPlugin {
    fn post_initialization(&self, app: &mut App) {
        let window = app.resource::<WgpuWindow>();
        let window_settings = app.resource::<Window>();
        let wgpu_render = Render::new(
            Arc::clone(window.device()),
            Arc::clone(window.queue()),
            window.texture_format(),
            window_settings.requested_surface_size,
            window_settings.minimal_surface_size,
            Millis::new(0),
        );
        app.insert_resource(wgpu_render);
        app.add_system(UpdatePhase::First, tick);
    }
}