Sorta want this type of API, but, CanvasFrame would be tied to a single type...

This commit is contained in:
2020-02-05 22:10:38 -08:00
parent 0c1f513225
commit 1597f0e380
5 changed files with 71 additions and 27 deletions

View File

@@ -6,37 +6,54 @@ use crate::canvas::*;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use crate::canvas::managed::shader::text_shader::GlyphInstance;
use vulkano::pipeline::vertex::Vertex;
// I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<V, H, In> where H: Handle{
pub trait DrawableTest<V, H> where H: Handle{
fn get_vertices(&self) -> Vec<V>;
fn get_instances(&self) -> Vec<In>;
fn get_handle(&self) -> H;
}
pub struct DrawableTestee {
pub vertices: Vec<u32>,
pub instances: Vec<u32>,
pub vertices: Vec<ImplVertexData>,
pub handle: Arc<CanvasTextureHandle>
}
impl<V, H: Handle, In> DrawableTest<V, H, In> for DrawableTestee {
impl<V, H: Handle> DrawableTest<V, H> for DrawableTestee {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_instances(&self) -> Vec<In> {
unimplemented!()
}
fn get_handle(&self) -> H {
unimplemented!()
}
}
pub struct ImplVertexData {
pub x: i32,
pub y: i32,
}
impl VertexData for ImplVertexData {
}
pub trait VertexData : Sized {
}
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
pub struct CanvasFrameTest<V: VertexData + Sized, H: Handle + Sized> {
pub map: HashMap<H, Vec<V>>,
}
impl<V: VertexData + Sized, H: Handle + Sized + Eq + Hash> CanvasFrameTest<V, H> {
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, H>) {
drawable.get_vertices();
self.map.insert(drawable.get_handle(), drawable.get_vertices());
}
}
pub trait Drawable {
@@ -62,10 +79,15 @@ pub trait Drawable {
}
}
pub trait VertexDefinitionAndData {
}
pub struct CanvasFrame {
pub colored_drawables: Vec<RuntimeVertexDef>,
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
@@ -85,7 +107,6 @@ impl CanvasFrame {
}
}
//
// pub fn draw_test<V : VertexDefinitionAndData, H: Handle, In>(&mut self, drawable: &dyn DrawableTest<V, H, In>) {
// let h = drawable.get_handle();
//