summaryrefslogtreecommitdiff
path: root/opengl-bindings/src/data_types.rs
blob: a6c65fc743933ab410a069f40b5929d36a9eca57 (plain)
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
use std::fmt::Display;

use safer_ffi::derive_ReprC;
use safer_ffi::layout::ReprC;

#[derive(Debug, Clone)]
#[derive_ReprC]
#[repr(C)]
pub struct Matrix<Value: ReprC, const ROWS: usize, const COLUMNS: usize>
{
    /// Items must be layed out this way for it to work with OpenGL shaders.
    pub items: [[Value; ROWS]; COLUMNS],
}

#[derive(Debug, Clone)]
#[derive_ReprC]
#[repr(C)]
pub struct Vec3<Value: ReprC>
{
    pub x: Value,
    pub y: Value,
    pub z: Value,
}

#[derive(Debug, Clone, Copy)]
#[derive_ReprC]
#[repr(C)]
pub struct Vec2<Value>
{
    pub x: Value,
    pub y: Value,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct Dimens<Value>
{
    pub width: Value,
    pub height: Value,
}

impl<Value: Display> Display for Dimens<Value>
{
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
    {
        write!(formatter, "{}x{}", self.width, self.height)
    }
}