covalent/graphics/backend.rs
1use crate::graphics::{RenderVertex, Renderable};
2
3/// Covalent supports the use of "graphics backends", distinct rendering engines for use with covalent.
4/// They all support the same rendering API, so similar code can run on multiple platforms
5/// with limited, or zero, edits.
6///
7/// Code for this backend should not be called directly by your application, due to potential synchronisation issues
8/// between threads. Also, some graphics backends require that all graphics code be executed only on the main application
9/// thread.
10///
11/// If implementing a custom backend for covalent, you will need to make an implementation for this trait.
12pub trait Backend {
13 /// This function will only be called once.
14 /// Should create a render context, then enter a loop that will not be terminated until the application itself quits.
15 /// Every loop iteration, the following steps must be taken.
16 /// - Render a single frame on the back buffer. To do this, call `ctx.render_phases` to retrieve the graphics pipeline's
17 /// current list of phases.
18 /// - Swap the back and front buffers.
19 fn main_loop(self, ctx: crate::Context);
20
21 /// Groups a list of triangles together to form a mesh. This is an optimised rendering primitive where all of the data
22 /// has been proactively sent to the GPU, so that the object can be rendered very quickly.
23 ///
24 /// Use this for large, unchanging renderables. Do not use this for small, dynamic renderables or ones that will be
25 /// quickly thrown away after at most a few frames.
26 ///
27 /// The `verts` parameter is a list of vertices that the mesh uses.
28 /// The `inds` parameter is a list of indices into the first parameter; each group of three entries in `inds` represents
29 /// a single triangle represented by the given indexed vertices.
30 fn create_mesh(&self, verts: Vec<RenderVertex>, inds: Vec<u32>) -> Renderable;
31}