summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Clayton2022-01-22 14:41:33 +0100
committerIsaac Clayton2022-01-22 14:41:33 +0100
commit995a8539056e087af6f088ad24db8f89219d626a (patch)
tree8a3f88308acc2358470b4a0acda2019e7d43b5fc
parent7add9d30bd06be1988cbe1dd206a6ae247c1b953 (diff)
Need to figure out how to move node between graphics thread and main thread
-rw-r--r--src/main.rs4
-rw-r--r--src/render.rs28
2 files changed, 19 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 6134893..e30aa12 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,7 +17,7 @@ fn main() {
&mut ctx, base,
);
- // render::graphics();
-
println!("{:#?}", quad);
+
+ // render::graphics();
}
diff --git a/src/render.rs b/src/render.rs
index 6939ee8..db6704a 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -1,4 +1,5 @@
use miniquad::*;
+use crate::quad::{Node, Embed};
#[repr(C)]
struct Vec2 {
@@ -11,14 +12,17 @@ struct Vertex {
uv: Vec2,
}
-struct Stage {
+struct Stage<A: Embed, B: Embed> {
pipeline: Pipeline,
bindings: Bindings,
texture: Texture,
+ node: Node<A, B>,
}
-impl Stage {
- pub fn new(ctx: &mut Context) -> Stage {
+const SIZE: usize = 4;
+
+impl<A: Embed, B: Embed> Stage<A, B> {
+ pub fn new(ctx: &mut Context) -> Self {
#[rustfmt::skip]
let vertices: [Vertex; 4] = [
Vertex { pos : Vec2 { x: -1., y: -1. }, uv: Vec2 { x: 0., y: 0. } },
@@ -31,8 +35,8 @@ impl Stage {
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];
let index_buffer = Buffer::immutable(ctx, BufferType::IndexBuffer, &indices);
- let pixels: [u8; 512*512*4] = [0x77; 512*512*4];
- let texture = Texture::from_rgba8(ctx, 512, 512, &pixels);
+ let pixels: [u8; SIZE*SIZE*4] = [0x77; SIZE*SIZE*4];
+ let texture = Texture::from_rgba8(ctx, SIZE as u16, SIZE as u16, &pixels);
let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
@@ -52,15 +56,16 @@ impl Stage {
shader,
);
- Stage { pipeline, bindings, texture }
+ Stage { pipeline, bindings, texture, node: todo!() }
}
}
-impl EventHandler for Stage {
+impl<A: Embed, B: Embed> EventHandler for Stage<A, B> {
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];
+ let bytes = [(bright * 255.0) as u8; SIZE*SIZE*4];
+
self.texture.update(ctx, &bytes)
}
@@ -79,9 +84,10 @@ impl EventHandler for Stage {
}
pub fn graphics() {
- miniquad::start(conf::Conf::default(), |mut ctx| {
- UserData::owning(Stage::new(&mut ctx), ctx)
- });
+ // assert_eq!((2 as usize).pow(node.depth as u32), SIZE);
+ // miniquad::start(conf::Conf::default(), move |mut ctx| {
+ // UserData::owning(Stage::new(&mut ctx), ctx)
+ // });
}
mod shader {