in the middle of expirimenting with was to implement this drawable api

This commit is contained in:
2019-10-11 22:46:35 -07:00
parent 1551a53d1e
commit 595937d68f
4 changed files with 63 additions and 20 deletions

View File

@@ -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<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
}
pub struct GenericCanvasFrame<V, H, Im, In, T> {
frame_data: HashMap<Arc<H>, Vec<(V, Im, In, T)>>
}
impl CanvasFrame {
/// Creates a bare canvas frame with empty accumulators
@@ -54,4 +51,25 @@ impl CanvasFrame {
}
}
}
}
pub struct GenericCanvasFrame<H, V, In> {
frame_data: HashMap<H, Vec<(Vec<V>, Vec<In>)>>
}
impl<H, V, In> GenericCanvasFrame<H, V, In> {
/// Creates a bare canvas frame with empty accumulators
pub fn new() -> GenericCanvasFrame<H, V, In> where H: Eq + Hash {
GenericCanvasFrame {
frame_data: Default::default()
}
}
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, H, In>) where H: Eq + Hash + Clone {
self.frame_data
.entry(drawable.get_handle().clone())
.or_insert(Vec::new())
.push((drawable.get_vertices(), drawable.get_instances()));
}
}

View File

@@ -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};
// I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<V, H, In> {
fn get_vertices(&self) -> Vec<V>;
fn get_instances(&self) -> Vec<In>;
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
/// Split out to two drawables?
///
//
pub trait DrawableTest<V, H> {
fn get_vertices(&self) -> Vec<V>;
fn get_handle(&self) -> Vec<H>;
}
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)>;