Skip to content

Instantly share code, notes, and snippets.

@raphlinus
Created December 27, 2019 15:09
Show Gist options
  • Save raphlinus/ca8cee59229798c510adbf4b208fd465 to your computer and use it in GitHub Desktop.
Save raphlinus/ca8cee59229798c510adbf4b208fd465 to your computer and use it in GitHub Desktop.
very rough draft of scene graph description for piet-metal

Scene graph

enum Node {
    Group(Group),
    Fill(Fill),
    Stroke(Stroke),
    Clip(Clip),
}

struct Group {
    translation: Translation,
    n: usize,
    nodes: Ref<[Node; n]>,
    bbox: [Bbox; n],
}

struct Bbox {
    left: i16,
    top: i16,
    right: i16,
    bottom: i16,
}

/// This is really optimized for UI, where we can expect translations to be quantized
/// to integer coordinates. More general transforms can be envisioned.
struct Translation {
    dx: i16,
    dy: i16,
}

struct Fill {
    brush: Brush,
    n_points: usize,
    points: Ref<[Point; n_points]>,
}

/// Very similar to Fill; could be refactored for DRY.
struct Clip {
    child: Ref<Node>,
    n_points: usize,
    points: Ref<[Point; n_points]>,
}

struct Stroke {
    brush: Brush,
    width: f32,
    n_points: usize,
    points: Ref<[Point; n_points]>,
}

struct Point {
    x: f32,
    y: f32,
}

enum Brush {
    Rgba(u32),
    // TODO: gradients
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment