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

master
mitchellhansen 5 years ago
parent 1551a53d1e
commit 595937d68f

@ -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
@ -55,3 +52,24 @@ 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()));
}
}

@ -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<V, H> {
// 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_handle(&self) -> Vec<H>;
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
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)>;

@ -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);
{

@ -97,12 +97,16 @@ impl Sprite {
}
}
impl<V, H> DrawableTest<V, H> for Sprite {
impl<V, H, In> DrawableTest<V, H, In> for Sprite {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_handle(&self) -> Vec<H> {
fn get_instances(&self) -> Vec<In> {
unimplemented!()
}
fn get_handle(&self) -> H {
unimplemented!()
}
}
@ -285,12 +289,28 @@ impl Text {
}
}
impl<V, H> DrawableTest<V, H> 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<V: TextVertex, H: TextHandle, In: TextInstance> DrawableTest<V, H, In> for Text {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_handle(&self) -> Vec<H> {
fn get_instances(&self) -> Vec<In> {
unimplemented!()
}
fn get_handle(&self) -> H {
unimplemented!()
}
}
Loading…
Cancel
Save