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()));
}
}