cgmath_std140/
lib.rs

1use cgmath::{Vector1, Vector2, Vector3, Vector4, Matrix2, Matrix3, Matrix4};
2
3/// Implemented for types that can be represented as [st140] values.
4pub trait AsStd140 {
5    /// The `std140` that this type converts to.
6    type Std140: std140::ReprStd140;
7
8    /// Converts this value into an [st140] value.
9    fn as_std140(&self) -> Self::Std140;
10}
11
12impl AsStd140 for Vector1<f32> {
13    type Std140 = std140::float;
14
15    fn as_std140(&self) -> Self::Std140 {
16        std140::float(self.x)
17    }
18}
19
20impl AsStd140 for Vector2<f32> {
21    type Std140 = std140::vec2;
22
23    fn as_std140(&self) -> Self::Std140 {
24        std140::vec2(self.x, self.y)
25    }
26}
27
28impl AsStd140 for Vector3<f32> {
29    type Std140 = std140::vec3;
30
31    fn as_std140(&self) -> Self::Std140 {
32        std140::vec3(self.x, self.y, self.z)
33    }
34}
35
36impl AsStd140 for Vector4<f32> {
37    type Std140 = std140::vec4;
38
39    fn as_std140(&self) -> Self::Std140 {
40        std140::vec4(self.x, self.y, self.z, self.w)
41    }
42}
43
44impl AsStd140 for Vector1<i32> {
45    type Std140 = std140::int;
46
47    fn as_std140(&self) -> Self::Std140 {
48        std140::int(self.x)
49    }
50}
51
52impl AsStd140 for Vector2<i32> {
53    type Std140 = std140::ivec2;
54
55    fn as_std140(&self) -> Self::Std140 {
56        std140::ivec2(self.x, self.y)
57    }
58}
59
60impl AsStd140 for Vector3<i32> {
61    type Std140 = std140::ivec3;
62
63    fn as_std140(&self) -> Self::Std140 {
64        std140::ivec3(self.x, self.y, self.z)
65    }
66}
67
68impl AsStd140 for Vector4<i32> {
69    type Std140 = std140::ivec4;
70
71    fn as_std140(&self) -> Self::Std140 {
72        std140::ivec4(self.x, self.y, self.z, self.w)
73    }
74}
75
76impl AsStd140 for Vector1<u32> {
77    type Std140 = std140::uint;
78
79    fn as_std140(&self) -> Self::Std140 {
80        std140::uint(self.x)
81    }
82}
83
84impl AsStd140 for Vector2<u32> {
85    type Std140 = std140::uvec2;
86
87    fn as_std140(&self) -> Self::Std140 {
88        std140::uvec2(self.x, self.y)
89    }
90}
91
92impl AsStd140 for Vector3<u32> {
93    type Std140 = std140::uvec3;
94
95    fn as_std140(&self) -> Self::Std140 {
96        std140::uvec3(self.x, self.y, self.z)
97    }
98}
99
100impl AsStd140 for Vector4<u32> {
101    type Std140 = std140::uvec4;
102
103    fn as_std140(&self) -> Self::Std140 {
104        std140::uvec4(self.x, self.y, self.z, self.w)
105    }
106}
107
108impl AsStd140 for Vector1<bool> {
109    type Std140 = std140::boolean;
110
111    fn as_std140(&self) -> Self::Std140 {
112        self.x.into()
113    }
114}
115
116impl AsStd140 for Vector2<bool> {
117    type Std140 = std140::bvec2;
118
119    fn as_std140(&self) -> Self::Std140 {
120        std140::bvec2(self.x.into(), self.y.into())
121    }
122}
123
124impl AsStd140 for Vector3<bool> {
125    type Std140 = std140::bvec3;
126
127    fn as_std140(&self) -> Self::Std140 {
128        std140::bvec3(self.x.into(), self.y.into(), self.z.into())
129    }
130}
131
132impl AsStd140 for Vector4<bool> {
133    type Std140 = std140::bvec4;
134
135    fn as_std140(&self) -> Self::Std140 {
136        std140::bvec4(self.x.into(), self.y.into(), self.z.into(), self.w.into())
137    }
138}
139
140impl AsStd140 for Matrix2<f32> {
141    type Std140 = std140::mat2x2;
142
143    fn as_std140(&self) -> Self::Std140 {
144        std140::mat2x2(
145            self.x.as_std140(),
146            self.y.as_std140(),
147        )
148    }
149}
150
151impl AsStd140 for Matrix3<f32> {
152    type Std140 = std140::mat3x3;
153
154    fn as_std140(&self) -> Self::Std140 {
155        std140::mat3x3(
156            self.x.as_std140(),
157            self.y.as_std140(),
158            self.z.as_std140(),
159        )
160    }
161}
162
163impl AsStd140 for Matrix4<f32> {
164    type Std140 = std140::mat4x4;
165
166    fn as_std140(&self) -> Self::Std140 {
167        std140::mat4x4(
168            self.x.as_std140(),
169            self.y.as_std140(),
170            self.z.as_std140(),
171            self.w.as_std140(),
172        )
173    }
174}