summaryrefslogtreecommitdiff
path: root/src/renderer/mod.rs
blob: 05f7e259b27e7691f16927047c2bffe23ed511e7 (plain)
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
43
44
45
46
#![allow(unused)]

pub mod backend;
pub mod dummy;
pub mod error;
pub mod text;
pub mod vulkan;

use backend::RendererBackend;
use text::TextSpan;

pub struct Renderer<'a> {
    pub backend: Box<dyn RendererBackend + 'a>,
    pub width: i32,
    pub height: i32,
}

impl<'a> Renderer<'a> {
    pub fn new<B>(mut backend: B, width: i32, height: i32) -> Self
    where
        B: RendererBackend + 'a,
    {
        backend.init(width, height);
        Self {
            backend: Box::new(backend),
            width,
            height,
        }
    }

    pub fn clear(&mut self) {
        self.backend.clear();
    }

    pub fn draw_text(&mut self, span: &TextSpan) {
        self.backend.draw_text(span);
    }

    pub fn present(&mut self) {
        self.backend.present();
    }

    pub fn shutdown(&mut self) {
        self.backend.shutdown();
    }
}