Skip to main content

mln_gfx/
renderer_backend.rs

1use std::ops::DerefMut;
2
3use crate::gpu::Gpu;
4
5/// What a renderer draws with on a device: the backend's [`Gpu`], which the
6/// backend owns and lends. What it draws into is a `FrameTarget` built on
7/// it, which takes the same `Gpu` for each call.
8pub trait RendererBackend: 'static {
9    /// The backend's `Gpu`, which owns the renderer's resources and runs its
10    /// frames.
11    type Gpu: Gpu;
12
13    /// The lend of [`gpu`](Self::gpu): it derefs to the backend's `Gpu`,
14    /// and keeps what the `Gpu`'s calls need ready until it drops, such as
15    /// OpenGL's context current.
16    type Scope<'a>: DerefMut<Target = Self::Gpu>
17    where
18        Self: 'a;
19
20    /// Lends the backend's `Gpu` until the returned scope drops. A caller
21    /// takes one scope around many calls rather than one for each, since a
22    /// backend may make its device ready for each scope.
23    fn gpu(&mut self) -> Self::Scope<'_>;
24}