Render Trait

To prevent coupling any one specific backend to the rest of the application, the render library can expose the renderer via a Render interface and consumers of the library can request a specific backend via a Backend enum. The Render interface is not intended to be a low level common abstraction over various graphics API's, but rather a high level abstraction meant to render the 3D world we will be creating later in this book.

There is an excellent cross-platform graphics and compute abstraction library in the rust ecosystem named gfx-rs.

The Render Module

Create a new module named

touch crates/obsidian_render/src/

Update the crates/obsidian_render/src/ to list the new module:

pub mod render;
pub use crate::render::{Backend, Render};

We can list our graphics backends with an enum:

pub enum Backend {

The Render trait can be written as:

pub trait Render {
    fn render(
        &mut self,
        dimensions: &[u32; 2],
    ) -> Result<()>;

The render call will eventually be given a parameter containing a description of our World to render. The World implementation will come in a later chapter.