Skip to main content

gl_utils/
vertex.rs

1//! Vertex related utilities including vertex specifications.
2
3use std;
4use bytemuck::{Pod, Zeroable};
5use glium;
6use rs_utils::show;
7
8#[derive(Clone, Copy, Debug, Default, PartialEq)]
9pub struct Vert2d {
10  pub position : [f32; 2]
11}
12glium::implement_vertex!(Vert2d, position);
13
14#[derive(Clone, Copy, Debug, Default, PartialEq)]
15pub struct Vert2dColor {
16  pub position : [f32; 2],
17  pub color    : [f32; 4]
18}
19glium::implement_vertex!(Vert2dColor, position, color);
20
21#[derive(Clone, Copy, Debug, Default, PartialEq)]
22pub struct Vert2dLayer {
23  pub position : [f32; 2],
24  pub layer    : u16
25}
26glium::implement_vertex!(Vert2dLayer, position, layer);
27
28#[derive(Clone, Copy, Debug, Default, PartialEq)]
29pub struct Vert2dRectColor {
30  pub bottom_left : [f32; 2],
31  pub dimensions  : [f32; 2],
32  pub color       : [f32; 4]
33}
34glium::implement_vertex!(Vert2dRectColor, bottom_left, dimensions, color);
35
36#[derive(Clone, Copy, Debug, Default, PartialEq)]
37pub struct Vert2dRectUv {
38  pub bottom_left : [f32; 2],
39  pub dimensions  : [f32; 2],
40  pub uv          : [f32; 2]
41}
42glium::implement_vertex!(Vert2dRectUv, bottom_left, dimensions, uv);
43
44#[derive(Clone, Copy, Debug, Default, PartialEq)]
45pub struct Vert2dRectUvLayer {
46  pub bottom_left : [f32; 2],
47  pub dimensions  : [f32; 2],
48  pub uv          : [f32; 2],
49  pub layer       : u16
50}
51glium::implement_vertex!(Vert2dRectUvLayer, bottom_left, dimensions, uv, layer);
52
53#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
54pub struct Vert2dTile {
55  pub row    : i32,
56  pub column : i32,
57  pub tile   : u8
58}
59glium::implement_vertex!(Vert2dTile, row, column, tile);
60
61#[derive(Clone, Copy, Debug, Default, PartialEq)]
62pub struct Vert2dTileColor {
63  pub row    : i32,
64  pub column : i32,
65  pub tile   : u8,
66  pub fg     : [f32; 4],
67  pub bg     : [f32; 4]
68}
69glium::implement_vertex!(Vert2dTileColor, row, column, tile, fg, bg);
70
71#[derive(Clone, Copy, Debug, Default, PartialEq)]
72pub struct Vert3d {
73  pub position : [f32; 3]
74}
75glium::implement_vertex!(Vert3d, position);
76
77#[derive(Clone, Copy, Debug, Default, PartialEq)]
78pub struct Vert3dColor {
79  pub position : [f32; 3],
80  pub color    : [f32; 4]
81}
82glium::implement_vertex!(Vert3dColor, position, color);
83
84#[derive(Clone, Copy, Debug, Default, PartialEq)]
85pub struct Vert3dScaleColor {
86  pub position : [f32; 3],
87  pub scale    : [f32; 3],
88  pub color    : [f32; 4]
89}
90glium::implement_vertex!(Vert3dScaleColor, position, scale, color);
91
92#[derive(Clone, Copy, Debug, Default, PartialEq)]
93pub struct Vert3dOrientationScaleColor {
94  pub position    : [f32; 3],
95  pub orientation : [[f32; 3]; 3],
96  pub scale       : [f32; 3],
97  pub color       : [f32; 4]
98}
99glium::implement_vertex!(Vert3dOrientationScaleColor,
100  position, orientation, scale, color);
101
102#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
103#[repr(C)]
104pub struct Vert3dInstanced {
105  pub inst_position : [f32; 3]
106}
107glium::implement_vertex!(Vert3dInstanced, inst_position);
108
109pub fn report_sizes() {
110  use std::mem::size_of;
111  println!("vertex report sizes...");
112  show!(size_of::<Vert2d>());
113  show!(size_of::<Vert2dColor>());
114  show!(size_of::<Vert2dLayer>());
115  show!(size_of::<Vert2dRectColor>());
116  show!(size_of::<Vert2dRectUvLayer>());
117  show!(size_of::<Vert2dTile>());
118  show!(size_of::<Vert2dTileColor>());
119  show!(size_of::<Vert3dScaleColor>());
120  show!(size_of::<Vert3dOrientationScaleColor>());
121  show!(size_of::<Vert3dInstanced>());
122  println!("...vertex report sizes");
123}