1#![warn(missing_docs)]
9
10use kurbo::Affine;
11use oxframe_2d::SceneGraph;
12use oxframe_core::Color;
13
14#[cfg(feature = "cpu")]
15mod blur;
16#[cfg(feature = "cpu")]
17mod cpu;
18#[cfg(feature = "cpu")]
19pub use cpu::CpuRenderer;
20
21#[cfg(feature = "gpu")]
22mod gpu;
23#[cfg(feature = "gpu")]
24pub use gpu::{GpuError, GpuRenderer};
25
26#[derive(Clone, PartialEq, Eq)]
28pub struct Image {
29 pub width: u32,
31 pub height: u32,
33 pub data: Vec<u8>,
35}
36
37impl std::fmt::Debug for Image {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 write!(f, "Image({}x{})", self.width, self.height)
40 }
41}
42
43#[derive(Debug, Clone, Copy)]
45pub struct RenderOptions {
46 pub width: u32,
48 pub height: u32,
50 pub background: Color,
52}
53
54pub trait Renderer {
56 fn render(&mut self, graph: &SceneGraph, options: &RenderOptions) -> Image;
58}
59
60pub fn scene_to_pixels(scene: (u32, u32), out: (u32, u32)) -> Affine {
62 let (sw, sh) = (f64::from(scene.0), f64::from(scene.1));
63 let (ow, oh) = (f64::from(out.0), f64::from(out.1));
64 let k = (ow / sw).min(oh / sh);
65 Affine::translate((ow / 2.0, oh / 2.0)) * Affine::scale(k)
66}