Skip to main content

osmic_render/
scene.rs

1use osmic_core::Color;
2
3/// A backend-agnostic scene graph describing what to render.
4///
5/// The scene graph is built from map features and styles, then passed
6/// to a `RenderBackend` for actual rasterization.
7#[derive(Debug, Clone)]
8pub struct SceneGraph {
9    pub background: Color,
10    pub layers: Vec<RenderLayer>,
11}
12
13impl SceneGraph {
14    pub fn new(background: Color) -> Self {
15        Self {
16            background,
17            layers: Vec::new(),
18        }
19    }
20
21    pub fn add_layer(&mut self, layer: RenderLayer) {
22        self.layers.push(layer);
23    }
24}
25
26/// A z-ordered rendering layer.
27#[derive(Debug, Clone)]
28pub struct RenderLayer {
29    pub z_order: i32,
30    pub features: Vec<RenderFeature>,
31}
32
33impl RenderLayer {
34    pub fn new(z_order: i32) -> Self {
35        Self {
36            z_order,
37            features: Vec::new(),
38        }
39    }
40
41    pub fn push(&mut self, feature: RenderFeature) {
42        self.features.push(feature);
43    }
44}
45
46/// A renderable feature with geometry and style.
47#[derive(Debug, Clone)]
48pub enum RenderFeature {
49    /// Filled polygon.
50    Fill {
51        coords: Vec<Vec<[f32; 2]>>,
52        color: Color,
53    },
54    /// Stroked line.
55    Stroke {
56        coords: Vec<[f32; 2]>,
57        color: Color,
58        width: f32,
59        cap: LineCap,
60        join: LineJoin,
61    },
62    /// Text label.
63    Label {
64        position: [f32; 2],
65        text: String,
66        font_size: f32,
67        color: Color,
68        halo_color: Option<Color>,
69        halo_width: f32,
70    },
71}
72
73#[derive(Debug, Clone, Copy)]
74pub enum LineCap {
75    Butt,
76    Round,
77    Square,
78}
79
80#[derive(Debug, Clone, Copy)]
81pub enum LineJoin {
82    Miter,
83    Round,
84    Bevel,
85}