1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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)>>,
}