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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! GLSL types.

use crate::graphics::csfml_graphics_sys as ffi;
use crate::graphics::Color;
use crate::system::{Vector2, Vector3};

/// 2D float vector (`vec2` in GLSL).
pub type Vec2 = Vector2<f32>;
/// 2D int vector (`ivec2` in GLSL).
pub type IVec2 = Vector2<i32>;
/// 2D bool vector (`bvec2` in GLSL).
pub type BVec2 = Vector2<bool>;
/// 3D float vector (`vec3` in GLSL).
pub type Vec3 = Vector3<f32>;
/// 3D int vector (`ivec3` in GLSL).
pub type IVec3 = Vector3<i32>;
/// 3D bool vector (`bvec3` in GLSL).
pub type BVec3 = Vector3<bool>;

#[derive(Debug, Copy, Clone)]
#[repr(C)]
/// GLSL `vec4` type.
pub struct Vec4 {
    /// `x` field.
    pub x: f32,
    /// `y` field.
    pub y: f32,
    /// `z` field.
    pub z: f32,
    /// `w` field.
    pub w: f32,
}

impl Vec4 {
    pub(super) fn raw(&self) -> ffi::sfGlslVec4 {
        ffi::sfGlslVec4 {
            x: self.x,
            y: self.y,
            z: self.z,
            w: self.w,
        }
    }
}

impl From<Color> for Vec4 {
    fn from(src: Color) -> Self {
        Self {
            x: f32::from(src.r) / 255.0,
            y: f32::from(src.g) / 255.0,
            z: f32::from(src.b) / 255.0,
            w: f32::from(src.a) / 255.0,
        }
    }
}

#[derive(Debug, Copy, Clone)]
/// GLSL `ivec4` type.
pub struct IVec4 {
    /// `x` field.
    pub x: i32,
    /// `y` field.
    pub y: i32,
    /// `z` field.
    pub z: i32,
    /// `w` field.
    pub w: i32,
}

impl IVec4 {
    pub(super) fn raw(&self) -> ffi::sfGlslIvec4 {
        ffi::sfGlslIvec4 {
            x: self.x,
            y: self.y,
            z: self.z,
            w: self.w,
        }
    }
}

impl From<Color> for IVec4 {
    fn from(src: Color) -> Self {
        Self {
            x: src.r.into(),
            y: src.g.into(),
            z: src.b.into(),
            w: src.a.into(),
        }
    }
}

impl Into<ffi::sfGlslIvec3> for IVec3 {
    fn into(self) -> ffi::sfGlslIvec3 {
        ffi::sfGlslIvec3 {
            x: self.x,
            y: self.y,
            z: self.z,
        }
    }
}

impl Into<ffi::sfGlslBvec2> for BVec2 {
    fn into(self) -> ffi::sfGlslBvec2 {
        use crate::sf_bool_ext::SfBoolExt;
        ffi::sfGlslBvec2 {
            x: SfBoolExt::from_bool(self.x),
            y: SfBoolExt::from_bool(self.y),
        }
    }
}

impl Into<ffi::sfGlslBvec3> for BVec3 {
    fn into(self) -> ffi::sfGlslBvec3 {
        use crate::sf_bool_ext::SfBoolExt;
        ffi::sfGlslBvec3 {
            x: SfBoolExt::from_bool(self.x),
            y: SfBoolExt::from_bool(self.y),
            z: SfBoolExt::from_bool(self.z),
        }
    }
}

#[derive(Debug, Copy, Clone)]
/// GLSL `bvec4` type.
pub struct BVec4 {
    /// `x` field.
    pub x: bool,
    /// `y` field.
    pub y: bool,
    /// `z` field.
    pub z: bool,
    /// `w` field.
    pub w: bool,
}

impl Into<ffi::sfGlslBvec4> for BVec4 {
    fn into(self) -> ffi::sfGlslBvec4 {
        use crate::sf_bool_ext::SfBoolExt;
        ffi::sfGlslBvec4 {
            x: SfBoolExt::from_bool(self.x),
            y: SfBoolExt::from_bool(self.y),
            z: SfBoolExt::from_bool(self.z),
            w: SfBoolExt::from_bool(self.w),
        }
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
/// GLSL `mat3` type.
pub struct Mat3(pub [f32; 9]);

impl From<crate::graphics::Transform> for Mat3 {
    fn from(src: crate::graphics::Transform) -> Self {
        Mat3(src.0.matrix)
    }
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
/// GLSL `mat4` type.
pub struct Mat4(pub [f32; 16]);

impl From<crate::graphics::Transform> for Mat4 {
    fn from(src: crate::graphics::Transform) -> Self {
        let mut mat = [0.0; 16];
        src.get_matrix(&mut mat);
        Mat4(mat)
    }
}