Skip to main content

osmic_render/
backend.rs

1use osmic_core::error::OsmicResult;
2
3use crate::scene::SceneGraph;
4
5/// Configuration for rendering.
6#[derive(Debug, Clone)]
7pub struct RenderConfig {
8    pub width: u32,
9    pub height: u32,
10    pub background: osmic_core::Color,
11    /// Device pixel ratio (1.0 = standard, 2.0 = retina).
12    pub pixel_ratio: f32,
13}
14
15impl Default for RenderConfig {
16    fn default() -> Self {
17        Self {
18            width: 1024,
19            height: 1024,
20            background: osmic_core::Color::from_hex("#f8f4f0").unwrap(),
21            pixel_ratio: 1.0,
22        }
23    }
24}
25
26/// Abstraction over rendering backends (software, GPU).
27pub trait RenderBackend {
28    /// Initialize the backend with the given configuration.
29    fn init(config: &RenderConfig) -> OsmicResult<Self>
30    where
31        Self: Sized;
32
33    /// Render a scene graph to the internal buffer.
34    fn render(&mut self, scene: &SceneGraph) -> OsmicResult<()>;
35
36    /// Read the rendered pixels as RGBA bytes.
37    fn read_pixels(&self) -> Option<Vec<u8>>;
38
39    /// Resize the render target.
40    fn resize(&mut self, width: u32, height: u32);
41}