Skip to main content

mln_webgpu/
renderer_backend.rs

1use mln_gfx::renderer_backend;
2
3use crate::device::Device;
4use crate::gpu::WebGpu;
5
6/// A renderer's backend on a [`Device`]: the [`WebGpu`] that its resources
7/// belong to, and that the targets built on it import their textures into.
8pub struct RendererBackend {
9    gpu: WebGpu,
10    device: Device,
11}
12
13impl RendererBackend {
14    /// A backend on `device`. Backends on one device render independently,
15    /// each submitting to the device's queue.
16    #[must_use]
17    pub fn new(device: &Device) -> Self {
18        RendererBackend { gpu: WebGpu::new(device), device: device.clone() }
19    }
20
21    /// The device the backend renders on.
22    #[must_use]
23    pub fn device(&self) -> &Device {
24        &self.device
25    }
26}
27
28impl renderer_backend::RendererBackend for RendererBackend {
29    type Gpu = WebGpu;
30    type Scope<'a> = &'a mut WebGpu;
31
32    fn gpu(&mut self) -> &mut WebGpu {
33        &mut self.gpu
34    }
35}