moved over to the enum method of drawing. Not flexible, but type safe

This commit is contained in:
2020-02-12 00:42:30 -08:00
parent 80c0d323be
commit 659cd98a1f
23 changed files with 192 additions and 570 deletions

78
src/util/vertex.rs Normal file
View File

@@ -0,0 +1,78 @@
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle};
use std::sync::Arc;
use vulkano::buffer::BufferAccess;
use std::collections::HashMap;
#[derive(Default, Debug, Clone, Copy)]
pub struct TextureVertex2D {
pub v_position: [f32; 2],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(TextureVertex2D, v_position, ti_position);
#[derive(Default, Debug, Clone, Copy)]
pub struct ColorVertex2D {
pub v_position: [f32; 2],
pub color: [f32; 4],
}
vulkano::impl_vertex!(ColorVertex2D, v_position, color);
#[derive(Default, Debug, Clone, Copy)]
pub struct ImageVertex2D {
pub v_position: [f32; 2],
pub color: [f32; 4],
}
vulkano::impl_vertex!(ImageVertex2D, v_position, color);
#[derive(Default, Debug, Clone, Copy)]
pub struct Vertex3D {
pub v_position: [f32; 3],
pub color : [f32; 4],
pub ti_position: [f32; 2],
}
vulkano::impl_vertex!(Vertex3D, v_position, color, ti_position);
/// Text vertex 3d with vertex position
#[derive(Default, Debug, Clone, Copy)]
pub struct TextVertex3D {
pub position: [f32; 3],
}
vulkano::impl_vertex!(TextVertex3D, position);
// ==============================================================================
#[derive(Debug, Clone)]
pub enum VertexTypes {
TextureType(Vec<TextureVertex2D>, Arc<CanvasTextureHandle>),
ImageType(Vec<ImageVertex2D>, Arc<CanvasImageHandle>),
ColorType(Vec<ColorVertex2D>),
ThreeDType(Vec<Vertex3D>),
}
#[derive(Clone)]
pub struct CanvasFrameAllocation {
pub colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>>,
pub textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
pub image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
pub text_instances: HashMap<Arc<CanvasFontHandle>, Arc<(dyn BufferAccess + Send + Sync)>>,
}