Changes
4 changed files (+54/-2)
-
-
@@ -20,6 +20,10 @@ pub fn compress_base<A, B>(&mut self, base: A) -> B {todo!("Turn Base Cell into a vector B"); } pub fn color_base<A>(&mut self, base: &A) -> [u8; 4] { todo!(); } /// Compresses a single node into a vector representation. /// Returns `None` if node has already been compressed and trimmed from tree. /// To recover a trimmed node, use `expand` on the compressed representation.
-
-
-
@@ -5,6 +5,11 @@ mod render;fn main() { println!("Warming up..."); // let mut ctx = ctx::Ctx::new_empty(); // let quad: quad::Node<u8, u8> = quad::Node::new_empty(&mut ctx); render::graphics(); println!("Hello!"); }
-
-
-
@@ -14,6 +14,7 @@ }/// Represends a node in a quadtree. /// Has a depth denoting the number of nodes below it. /// The base node has a depth of 0 /// Nodes should only be siblings of nodes with the same depth. /// Data stored inside a quadtree node, including children, are in `data`. pub struct Node<A: Default, B: Copy> {
-
@@ -23,6 +24,42 @@ pub data: Quad<A, B>,} impl<A: Default, B: Copy> Node<A, B> { /// Bytes must be of size (2**depth)**2 * 4 pub fn write_rgba8( self, ctx: &mut Ctx, bytes: &mut [u8], depth: usize, x: usize, y: usize, ) -> Self { let mut expanded = ctx.expand(self); expanded.data = match expanded.data { // Base cell in grid. Quad::Base(base) => { let mut color = ctx.color_base(&base); let idx = ((1 << depth) * y + x) * 4; bytes[idx..(idx + 4)].swap_with_slice(&mut color); Quad::Base(base) }, // Node with 4 children. Quad::Node(children) => { let size = 1 << expanded.depth; let half = size / 2; let c = [ children[0].write_rgba8(ctx, bytes, depth, x, y ), children[1].write_rgba8(ctx, bytes, depth, x + half, y ), children[2].write_rgba8(ctx, bytes, depth, x, y + half), children[3].write_rgba8(ctx, bytes, depth, x + half, y + half), ]; todo!() }, // Children may be generated from Node. Cached => { unreachable!(); }, }; expanded } /// Creates a new tree from a single base node pub fn new_base(base: A, ctx: &mut Ctx) -> Self { Node {
-
-
-
@@ -14,6 +14,7 @@struct Stage { pipeline: Pipeline, bindings: Bindings, texture: Texture, } impl Stage {
-
@@ -51,12 +52,17 @@ ],shader, ); Stage { pipeline, bindings } Stage { pipeline, bindings, texture } } } impl EventHandler for Stage { fn update(&mut self, _ctx: &mut Context) {} fn update(&mut self, ctx: &mut Context) { let t = date::now(); let bright = t.sin()*0.5+0.5; let bytes = [(bright * 255.0) as u8; 512*512*4]; self.texture.update(ctx, &bytes) } fn draw(&mut self, ctx: &mut Context) { ctx.begin_default_pass(Default::default());
-