|
|
@ -1,4 +1,4 @@
|
|
|
|
use crate::util::vertex_3d::{Vertex3D};
|
|
|
|
use crate::util::vertex_3d::Vertex3D;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::hash::Hash;
|
|
|
|
use std::hash::Hash;
|
|
|
@ -7,6 +7,8 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
|
|
|
|
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
|
|
|
|
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
|
|
|
|
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
|
|
|
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
|
|
|
use vulkano::pipeline::vertex::Vertex;
|
|
|
|
use vulkano::pipeline::vertex::Vertex;
|
|
|
|
|
|
|
|
use std::any::Any;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// I don't think this is going to work without getting into Box'ing
|
|
|
|
// I don't think this is going to work without getting into Box'ing
|
|
|
|
pub trait DrawableTest<V, H> where H: Handle {
|
|
|
|
pub trait DrawableTest<V, H> where H: Handle {
|
|
|
@ -15,48 +17,78 @@ pub trait DrawableTest<V, H> where H: Handle{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct DrawableTestee {
|
|
|
|
|
|
|
|
pub vertices: Vec<ImplVertexData>,
|
|
|
|
mod dynhash {
|
|
|
|
pub handle: Arc<CanvasTextureHandle>
|
|
|
|
use std::any::Any;
|
|
|
|
|
|
|
|
use std::hash::{Hash, Hasher};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub trait DynEq: Any {
|
|
|
|
|
|
|
|
fn dyn_eq(&self, other: &dyn DynEq) -> bool;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn as_any(&self) -> &dyn Any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<V, H: Handle> DrawableTest<V, H> for DrawableTestee {
|
|
|
|
pub trait DynHash: DynEq {
|
|
|
|
fn get_vertices(&self) -> Vec<V> {
|
|
|
|
fn dyn_hash(&self, hasher: &mut dyn Hasher);
|
|
|
|
unimplemented!()
|
|
|
|
|
|
|
|
|
|
|
|
fn as_dyn_eq(&self) -> &dyn DynEq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_handle(&self) -> H {
|
|
|
|
impl<H: Eq + Any> DynEq for H {
|
|
|
|
unimplemented!()
|
|
|
|
fn dyn_eq(&self, other: &dyn DynEq) -> bool {
|
|
|
|
|
|
|
|
if let Some(other) = other.as_any().downcast_ref::<H>() {
|
|
|
|
|
|
|
|
self == other
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct ImplVertexData {
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
|
|
pub x: i32,
|
|
|
|
self
|
|
|
|
pub y: i32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl VertexData for ImplVertexData {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<H: Hash + DynEq> DynHash for H {
|
|
|
|
|
|
|
|
fn dyn_hash(&self, mut hasher: &mut dyn Hasher) {
|
|
|
|
|
|
|
|
H::hash(self, &mut hasher)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub trait VertexData : Sized {
|
|
|
|
fn as_dyn_eq(&self) -> &dyn DynEq {
|
|
|
|
|
|
|
|
self
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl PartialEq for dyn DynHash {
|
|
|
|
|
|
|
|
fn eq(&self, other: &dyn DynHash) -> bool {
|
|
|
|
|
|
|
|
self.dyn_eq(other.as_dyn_eq())
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
|
|
|
|
impl Eq for dyn DynHash {}
|
|
|
|
pub struct CanvasFrameTest<V: VertexData + Sized, H: Handle + Sized> {
|
|
|
|
|
|
|
|
pub map: HashMap<H, Vec<V>>,
|
|
|
|
impl Hash for dyn DynHash {
|
|
|
|
|
|
|
|
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
|
|
|
|
|
|
|
self.dyn_hash(hasher)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
use crate::canvas::canvas_frame::dynhash::DynHash;
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
|
|
|
|
|
|
|
|
pub struct CanvasFrameTest<VTypes> {
|
|
|
|
|
|
|
|
pub map: HashMap<Box<dyn DynHash>, Vec<VTypes>>,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<VTypes> CanvasFrameTest<VTypes> {
|
|
|
|
|
|
|
|
pub fn draw(&mut self, drawable: Vec<VTypes>) {
|
|
|
|
|
|
|
|
self.map.insert(Box::new(10), drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub trait Drawable {
|
|
|
|
pub trait Drawable {
|
|
|
|
|
|
|
|
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
|
|
|
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
|
|
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
|
|
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
|
|
|
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
|
|
|
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
|
|
@ -80,30 +112,24 @@ pub trait Drawable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub trait VertexDefinitionAndData {}
|
|
|
|
|
|
|
|
|
|
|
|
pub trait VertexDefinitionAndData {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub struct CanvasFrame {
|
|
|
|
pub struct CanvasFrame {
|
|
|
|
pub colored_drawables: Vec<RuntimeVertexDef>,
|
|
|
|
pub colored_drawables: Vec<RuntimeVertexDef>,
|
|
|
|
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
|
|
|
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
|
|
|
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
|
|
|
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
|
|
|
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
|
|
|
|
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CanvasFrame {
|
|
|
|
impl CanvasFrame {
|
|
|
|
|
|
|
|
|
|
|
|
/// Creates a bare canvas frame with empty accumulators a
|
|
|
|
/// Creates a bare canvas frame with empty accumulators a
|
|
|
|
pub fn new() -> CanvasFrame {
|
|
|
|
pub fn new() -> CanvasFrame {
|
|
|
|
CanvasFrame {
|
|
|
|
CanvasFrame {
|
|
|
|
colored_drawables: vec![],
|
|
|
|
colored_drawables: vec![],
|
|
|
|
textured_drawables: Default::default(),
|
|
|
|
textured_drawables: Default::default(),
|
|
|
|
image_drawables: Default::default(),
|
|
|
|
image_drawables: Default::default(),
|
|
|
|
text_drawables: Default::default()
|
|
|
|
text_drawables: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|