diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index 9cc9e37d..e1dded8b 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -1,8 +1,9 @@ use crate::util::vertex_3d::{Vertex3D}; use std::sync::Arc; use std::collections::HashMap; -use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle}; +use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, DrawableTest}; use crate::canvas::shader::text_shader::GlyphInstance; +use std::hash::Hash; /// pub struct CanvasFrame { @@ -12,10 +13,6 @@ pub struct CanvasFrame { pub text_drawables: HashMap, Vec> } -pub struct GenericCanvasFrame { - frame_data: HashMap, Vec<(V, Im, In, T)>> -} - impl CanvasFrame { /// Creates a bare canvas frame with empty accumulators @@ -54,4 +51,25 @@ impl CanvasFrame { } } } +} + +pub struct GenericCanvasFrame { + frame_data: HashMap, Vec)>> +} + +impl GenericCanvasFrame { + + /// Creates a bare canvas frame with empty accumulators + pub fn new() -> GenericCanvasFrame where H: Eq + Hash { + GenericCanvasFrame { + frame_data: Default::default() + } + } + + pub fn draw(&mut self, drawable: &dyn DrawableTest) where H: Eq + Hash + Clone { + self.frame_data + .entry(drawable.get_handle().clone()) + .or_insert(Vec::new()) + .push((drawable.get_vertices(), drawable.get_instances())); + } } \ No newline at end of file diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index 0493e7b1..ff19f64e 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -31,19 +31,23 @@ use crate::canvas::shader::text_shader::GlyphInstance; use std::fs::File; use std::io::Read; use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId}; -/// A drawable object can be passed into a CanvasFrame to be rendered -/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color -/// Provides Image and Texture handles for drawing -/// Split out to two drawables? -/// -// -pub trait DrawableTest { + +// I don't think this is going to work without getting into Box'ing +pub trait DrawableTest { fn get_vertices(&self) -> Vec; - fn get_handle(&self) -> Vec; + fn get_instances(&self) -> Vec; + fn get_handle(&self) -> H; } + + +/// A drawable object can be passed into a CanvasFrame to be rendered +/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color +/// Provides Image and Texture handles for drawing + pub trait Drawable { + fn get_vertices(&self) -> Vec<(f32, f32, f32)>; fn get_color(&self) -> (f32, f32, f32, f32); fn get_ti_coords(&self) -> Vec<(f32, f32)>; diff --git a/src/main.rs b/src/main.rs index 41b34737..dd6e4962 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,11 +22,11 @@ use sprite::Sprite; use crate::util::load_raw; -use crate::sprite::{Poly, Text}; +use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance}; use vulkano::instance::debug::DebugCallback; use crate::compute::compu_sprite::CompuSprite; use crate::compute::compu_frame::CompuFrame; -use crate::canvas::canvas_frame::CanvasFrame; +use crate::canvas::canvas_frame::{CanvasFrame, GenericCanvasFrame}; pub mod util; @@ -169,7 +169,8 @@ pub fn main() { canvas.draw(&funky_sprite); canvas.draw(&test_polygon); - + let mut gencanvas = GenericCanvasFrame::new(); + gencanvas.draw(&text_sprite); { diff --git a/src/sprite.rs b/src/sprite.rs index e0b46511..5d4f4213 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -97,12 +97,16 @@ impl Sprite { } } -impl DrawableTest for Sprite { +impl DrawableTest for Sprite { fn get_vertices(&self) -> Vec { unimplemented!() } - fn get_handle(&self) -> Vec { + fn get_instances(&self) -> Vec { + unimplemented!() + } + + fn get_handle(&self) -> H { unimplemented!() } } @@ -285,12 +289,28 @@ impl Text { } } -impl DrawableTest for Text { +pub trait TextHandle { + fn do_nothing() -> u32; +} + +pub trait TextInstance { + fn get_thing() -> Vec<(u32, u32, u32)>; +} + +pub trait TextVertex { + fn get_vertices() -> Vec<(u32, u32, u32)>; +} + +impl DrawableTest for Text { fn get_vertices(&self) -> Vec { unimplemented!() } - fn get_handle(&self) -> Vec { + fn get_instances(&self) -> Vec { + unimplemented!() + } + + fn get_handle(&self) -> H { unimplemented!() } } \ No newline at end of file