glium_types/
vert_types.rs1use glium::implement_vertex;
2use crate::prelude::*;
3
4#[derive(Debug, Clone, Copy)]
5pub struct Vertex{
7 pub position: (f32, f32, f32)
8}
9impl Vertex{
10 pub const fn new(x: f32, y: f32, z: f32) -> Self{
11 Vertex { position: (x, y, z) }
12 }
13}
14impl From<Vec3> for Vertex {
15 fn from(value: Vec3) -> Self {
16 Vertex { position: (value.x, value.y, value.z) }
17 }
18}
19implement_vertex!(Vertex, position);
20
21
22
23#[derive(Debug, Clone, Copy)]
24pub struct Normal{
26 pub normal: (f32, f32, f32)
27}
28impl From<Vec3> for Normal{
29 fn from(value: Vec3) -> Self {
30 Self { normal: (value.x, value.y, value.z) }
31 }
32}
33impl Normal{
34 pub const fn new(x: f32, y: f32, z: f32) -> Self{
35 Self { normal: (x, y, z) }
36 }
37}
38implement_vertex!(Normal, normal);
39
40
41
42#[derive(Clone, Copy, Debug)]
43pub struct TextureCoords{
45 pub texture_coords: (f32, f32)
46}
47impl From<Vec2> for TextureCoords {
48 fn from(value: Vec2) -> Self {
49 Self { texture_coords: (value.x, value.y) }
50 }
51}
52impl TextureCoords{
53 pub const fn new(u: f32, v: f32) -> Self{
54 Self { texture_coords: (u, v) }
55 }
56}
57implement_vertex!(TextureCoords, texture_coords);
58
59
60
61#[derive(Clone, Copy, Debug)]
62pub struct VertexColour{
64 pub colour: (f32, f32, f32, f32)
65}
66impl From<Vec4> for VertexColour{
67 fn from(value: Vec4) -> Self {
68 Self { colour: (value.x, value.y, value.z, value.w) }
69 }
70}
71impl VertexColour{
72 pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self{
73 Self { colour: (r, g, b, a) }
74 }
75}
76implement_vertex!(VertexColour, colour);
77
78
79#[macro_export]
88macro_rules! mesh {
89 ($display: expr, $indices: expr, $( $x: expr ),*) => {
90 {
91 use glium::{index::PrimitiveType, IndexBuffer, VertexBuffer};
92 let display = $display;
93 (
94 IndexBuffer::new(display, PrimitiveType::TrianglesList, $indices).unwrap(),
95 $(
96 VertexBuffer::new(display, $x).unwrap(),
97 )*
98 )
99 }
100 }
101}