piping everything through. Almost done

This commit is contained in:
2019-10-09 23:06:55 -07:00
parent e5ba27c353
commit 1551a53d1e
9 changed files with 259 additions and 309 deletions

View File

@@ -1,10 +1,11 @@
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest};
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest, CanvasFontHandle};
use std::sync::Arc;
use crate::canvas::shader::text_shader::GlyphInstance;
use crate::canvas::canvas_buffer::CanvasFont;
use crate::util::vertex_3d::Vertex3D;
#[derive(Debug, Clone)]
pub struct Sprite {
pub vertices: [(f32, f32, f32); 6],
pub ti_position: [(f32, f32); 6],
@@ -20,36 +21,34 @@ pub struct Sprite {
/// Container class which implements drawable.
impl Sprite {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Sprite {
Sprite::new_with_color(position, size, 0, (0.,0.,0.,0.))
Sprite::new_with_color(position, size, 0, (0., 0., 0., 0.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1 + size.1 , normalized_depth), // bottom left
(position.0, position.1, normalized_depth), // top left
(position.0, position.1 + size.1, normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1, normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1 , normalized_depth), // top right
(position.0 + size.0, position.1, normalized_depth), // top right
],
position: position,
ti_position: [
(-0.0, -0.0), // top left
(-0.0, 1.0), // bottom left
( 1.0, 1.0), // bottom right
(-0.0, 1.0), // bottom left
(1.0, 1.0), // bottom right
(-0.0, -0.0), // top left
( 1.0, 1.0), // bottom right
( 1.0, -0.0), // top right
(1.0, 1.0), // bottom right
(1.0, -0.0), // top right
],
size: size,
color: color,
@@ -59,8 +58,8 @@ impl Sprite {
screen_position: (0.0, 0.0),
atlas_position: (0.0, 0.0),
atlas_size: (0.0, 0.0),
scale: 0.0
}
scale: 0.0,
},
}
}
@@ -69,41 +68,38 @@ impl Sprite {
size: (f32, f32),
depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
vertices: [
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1 + size.1 , normalized_depth), // bottom left
(position.0, position.1, normalized_depth), // top left
(position.0, position.1 + size.1, normalized_depth), // bottom left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0, position.1 , normalized_depth), // top left
(position.0, position.1, normalized_depth), // top left
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
(position.0 + size.0, position.1 , normalized_depth), // top right
(position.0 + size.0, position.1, normalized_depth), // top right
],
position: position,
ti_position: [
(-0.0, -0.0), // top left
(-0.0, 1.0), // bottom left
( 1.0, 1.0), // bottom right
(-0.0, 1.0), // bottom left
(1.0, 1.0), // bottom right
(-0.0, -0.0), // top left
( 1.0, 1.0), // bottom right
( 1.0, -0.0), // top right
(1.0, 1.0), // bottom right
(1.0, -0.0), // top right
],
size: size,
color: (1.0, 0.0, 0.0, 1.0),
textured: true,
texture_handle: Some(texture_handle.clone())
texture_handle: Some(texture_handle.clone()),
value: Default::default(),
}
}
}
impl<V, H> DrawableTest<V, H> for Sprite {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_handle(&self) -> Vec<H> {
@@ -112,8 +108,7 @@ impl<V, H> DrawableTest<V, H> for Sprite {
}
impl Drawable for Sprite {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec()
}
@@ -129,7 +124,7 @@ impl Drawable for Sprite {
match self.textured {
true => {
self.texture_handle.clone()
},
}
false => None,
}
}
@@ -142,7 +137,6 @@ impl Drawable for Sprite {
#[derive(Debug, Clone)]
pub struct Poly {
pub vertices: Vec<(f32, f32, f32)>,
pub ti_position: Vec<(f32, f32)>,
@@ -154,97 +148,85 @@ pub struct Poly {
texture_handle: Option<Arc<CanvasTextureHandle>>,
// ==================================
}
/// Container class which implements drawable.
impl Poly {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
Poly::new_with_color(position, size, 0, (0.,0.,0.,0.))
Poly::new_with_color(position, size, 0, (0., 0., 0., 0.))
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Poly {
let normalized_depth = (depth as f32 / 255.0);
Poly {
vertices: vec![
(-0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(-0.25 , 0.0 , normalized_depth),
(-0.25 , 0.0 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , 0.5 , normalized_depth),
(0.25 , 0.0 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , 0.5 , normalized_depth),
(0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.25 , 0.0 , normalized_depth),
(0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.5 , -0.5 , normalized_depth),
(0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , -0.1 , normalized_depth),
(-0.25 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(0.0 , -0.1 , normalized_depth),
(-0.5 , -0.5 , normalized_depth),
(-1.0 , 1.0 , normalized_depth),
(-0.25 , -0.5 , normalized_depth),
(-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(-0.25, 0.0, normalized_depth),
(-0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth),
(0.25, 0.0, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, 0.5, normalized_depth),
(0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.25, 0.0, normalized_depth),
(0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.5, -0.5, normalized_depth),
(0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth),
(-0.25, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(0.0, -0.1, normalized_depth),
(-0.5, -0.5, normalized_depth),
(-1.0, 1.0, normalized_depth),
(-0.25, -0.5, normalized_depth),
],
position: position,
ti_position: vec![
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0,0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
(0.0, 0.0),
],
size: size,
color: color,
textured: false,
texture_handle: None
texture_handle: None,
}
}
}
impl Drawable for Poly {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
self.vertices.to_vec()
}
@@ -260,7 +242,7 @@ impl Drawable for Poly {
match self.textured {
true => {
self.texture_handle.clone()
},
}
false => None,
}
}
@@ -272,74 +254,43 @@ impl Drawable for Poly {
#[derive(Debug, Clone)]
pub struct Poly {
pub vertices: Vec<(f32, f32, f32)>,
pub ti_position: Vec<(f32, f32)>,
position: (f32, f32),
size: (f32, f32),
pub struct Text {
position: (f32, f32, f32),
scale: f32,
color: (f32, f32, f32, f32),
textured: bool,
texture_handle: Option<Arc<CanvasTextureHandle>>,
// ==================================
text_handle: Arc<CanvasFontHandle>,
}
/// Container class which implements drawable.
impl Poly {
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
Poly::new_with_color(position, size, 0, (0.,0.,0.,0.))
impl Text {
pub fn new(position: (f32, f32), size: (f32, f32), font_handle: Arc<CanvasFontHandle>) -> Text {
Text::new_with_color(position, size, 0, (0., 0., 0., 0.), font_handle)
}
pub fn new_with_color(position: (f32, f32),
size: (f32, f32),
depth: u32,
color: (f32, f32, f32, f32)) -> Poly {
color: (f32, f32, f32, f32),
handle: Arc<CanvasFontHandle>) -> Text {
let normalized_depth = (depth as f32 / 255.0);
Poly {
vertices: vec![],
position: position,
ti_position: vec![],
size: size,
color: color,
textured: false,
texture_handle: None
Text {
position: (position.0, position.1, normalized_depth),
scale: 0.0,
color,
text_handle: handle,
}
}
}
impl Drawable for Poly {
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
self.vertices.to_vec()
impl<V, H> DrawableTest<V, H> for Text {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_color(&self) -> (f32, f32, f32, f32) {
self.color.clone()
fn get_handle(&self) -> Vec<H> {
unimplemented!()
}
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
self.ti_position.to_vec()
}
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
match self.textured {
true => {
self.texture_handle.clone()
},
false => None,
}
}
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
None
}
}
}