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
use crate::{vertex::Vertex, CommonSprite, *};
use riddle_common::Color;
use riddle_math::{Rect, Vector2};
pub trait CommonRenderer: Sized {
type RenderContext: RenderContext<Self>;
type Sprite: CommonSprite<Self>;
type Texture;
type Shader;
type SpriteFont;
fn dimensions(&self) -> Vector2<f32>;
fn render<R, F>(&self, f: F) -> Result<R>
where
F: FnOnce(&mut Self::RenderContext) -> Result<R>;
}
pub trait RenderContext<R: CommonRenderer> {
fn set_transform(&mut self, transform: mint::ColumnMatrix4<f32>) -> Result<()>;
fn clear(&mut self, color: Color<f32>) -> Result<()>;
fn draw(&mut self, renderable: &Renderable<'_, R>) -> Result<()>;
fn fill_rect(&mut self, rect: &Rect<f32>, color: Color<f32>) -> Result<()>;
fn present(self) -> Result<()>;
}
pub struct Renderable<'a, R: CommonRenderer> {
pub texture: R::Texture,
pub shader: R::Shader,
pub verts: &'a [Vertex],
pub indices: &'a [u16],
}