std140/
lib.rs

1#![allow(non_camel_case_types)]
2
3//! This module contains types that may be used to define Rust struct types that match the GLSL
4//! std140 memory layout.
5//!
6//! Std140 is a standardized memory layout for GLSL shader interface blocks (e.g. uniform blocks).
7//! An interface block is a group op typed GLSL variables. For details on the layout rules for
8//! std140, please refer to the section 2.12.6.4 "Standard Uniform Block Layout" of the
9//! [OpenGL ES 3.0 Specification](https://www.khronos.org/registry/OpenGL/specs/es/3.0/es_spec_3.0.pdf).
10//!
11//! This module aims to make it easy to construct and manipulate a block of std140 compatible memory
12//! as a Rust struct, such that the struct's memory layout will match a GLSL interface block if
13//! every block member is pairwise type-compatible with the struct field in the corresponding
14//! position. Position here relates to the order in which block members and struct fields are
15//! declared, e.g.: the 1st block member must be compatible with the 1st struct field, the 2nd block
16//! member must be compatible with the 2nd struct field, etc. The struct itself has to be marked
17//! with the [`#[repr_std140]`][repr_std140] attribute: this ensures the rust compiler will
18//! correctly order and align the fields.
19//!
20//! For GLSL primitive types, compatibility is defined by the following mapping from GLSL types to
21//! `std140` types:
22//!
23//! - `float`: [float]
24//! - `vec2`: [vec2]
25//! - `vec3`: [vec3]
26//! - `vec4`: [vec4]
27//! - `mat2`: [mat2x2][struct@mat2x2]
28//! - `mat3`: [mat3x3][struct@mat3x3]
29//! - `mat4`: [mat4x4][struct@mat4x4]
30//! - `mat2x2`: [mat2x2][struct@mat2x2]
31//! - `mat2x3`: [mat2x3][struct@mat2x3]
32//! - `mat2x4`: [mat2x4][struct@mat2x4]
33//! - `mat3x2`: [mat3x2][struct@mat3x2]
34//! - `mat3x3`: [mat3x3][struct@mat3x3]
35//! - `mat3x4`: [mat3x4][struct@mat3x4]
36//! - `mat4x2`: [mat4x2][struct@mat4x2]
37//! - `mat4x3`: [mat4x3][struct@mat4x3]
38//! - `mat4x4`: [mat4x4][struct@mat4x4]
39//! - `int`: [int]
40//! - `ivec2`: [ivec2]
41//! - `ivec3`: [ivec3]
42//! - `ivec4`: [ivec4]
43//! - `uint`: [uint]
44//! - `uvec2`: [uvec2]
45//! - `uvec3`: [uvec3]
46//! - `uvec4`: [uvec4]
47//! - `bool`: [boolean]
48//! - `bvec2`: [bvec2]
49//! - `bvec3`: [bvec3]
50//! - `bvec4`: [bvec4]
51//!
52//! A GLSL struct type is compatible with a field if this field's type is a Rust struct marked with
53//! [`#[repr_std140]`][repr_std140] and this struct's fields are pair-wise compatible with the GLSL
54//! struct field in the corresponding position.
55//!
56//! A GLSL array of GLSL type `T` with compatible type `T_c` (as defined above) and length `N` is
57//! compatible with a field of type `std140::array<T_c, N>`.
58//!
59//! # Example
60//!
61//! Given the following GLSL declaration of an (uniform) interface block:
62//!
63//! ```glsl
64//! struct PointLight {
65//!     vec3 position;
66//!     float intensity;
67//! }
68//!
69//! layout(std140) uniform Uniforms {
70//!     mat4 transform;
71//!     vec3 ambient_light_color;
72//!     PointLight lights[2];
73//! }
74//! ```
75//!
76//! The following will produce a Rust struct instance with a compatible memory layout:
77//!
78//! ```rust
79//! #[std140::repr_std140]
80//! struct PointLight {
81//!     position: std140::vec3,
82//!     intensity: std140::float,
83//! }
84//!
85//! #[std140::repr_std140]
86//! struct Uniforms {
87//!     transform: std140::mat4x4,
88//!     ambient_light_color: std140::vec3,
89//!     lights: std140::array<PointLight, 2>
90//! }
91//!
92//! let instance = Uniforms {
93//!     transform: std140::mat4x4(
94//!         std140::vec4(1.0, 0.0, 0.0, 0.0),
95//!         std140::vec4(0.0, 1.0, 0.0, 0.0),
96//!         std140::vec4(0.0, 0.0, 1.0, 0.0),
97//!         std140::vec4(0.0, 0.0, 0.0, 1.0),
98//!     ),
99//!     ambient_light_color: std140::vec3(0.2, 0.2, 0.2),
100//!     lights: std140::array![
101//!         PointLight {
102//!             position: std140::vec3(10.0, 0.0, 10.0),
103//!             intensity: std140::float(0.5)
104//!         },
105//!         PointLight {
106//!             position: std140::vec3(0.0, 10.0, 10.0),
107//!             intensity: std140::float(0.8)
108//!         },
109//!     ]
110//! };
111//! ```
112//!
113//! Note that although the field names match the block member names in this example, this is not
114//! strictly necessary: only pairwise field-type compatibility is required.
115//!
116//! [repr_std140]: attr.repr_std140.html
117
118use std::fmt;
119use std::ops::{Deref, DerefMut, Index, IndexMut};
120
121/// Attribute macro that can be applied to a struct to ensure its representation is compatible with
122/// the std140 memory layout convention.
123///
124/// Can only be applied to a struct if all of its fields implement [ReprStd140].
125///
126/// Any struct marked with this attribute will automatically implement [Std140Struct]
127///
128/// # Example
129///
130/// ```rust
131/// #[std140::repr_std140]
132/// struct PointLight {
133///     position: std140::vec3,
134///     intensity: std140::float,
135/// }
136/// ```
137pub use std140_macros::repr_std140;
138
139/// Marker trait for types that can be used as fields in structs marked with
140/// [`#[repr_std140]`][repr_std140].
141///
142/// [repr_std140]: attr.repr_std140.html
143pub unsafe trait ReprStd140 {}
144
145/// Marker trait for types that can be used as the element type for std140 [array][struct@array]s.
146pub unsafe trait Std140ArrayElement: ReprStd140 {}
147
148/// Marker trait for struct types that were marked with [`#[repr_std140]`][repr_std140].
149///
150/// [repr_std140]: attr.repr_std140.html
151pub unsafe trait Std140Struct {}
152
153unsafe impl<T> ReprStd140 for T where T: Std140Struct {}
154unsafe impl<T> Std140ArrayElement for T where T: Std140Struct {}
155
156/// Represents an std140 compatible array.
157///
158/// All elements in an std140 array are aligned to at least 16 bytes.
159///
160/// The [array!][macro@array] macro may be used to initialize an array.
161///
162/// # Example
163///
164/// ```
165/// let std140_array: std140::array<std140::vec2, 2> = std140::array![
166///     std140::vec2(1.0, 0.0),
167///     std140::vec2(0.0, 1.0),
168/// ];
169/// ```
170#[derive(Clone, Copy)]
171pub struct array<T, const LEN: usize>
172where
173    T: Std140ArrayElement,
174{
175    internal: [ArrayElementWrapper<T>; LEN],
176}
177
178impl<T, const LEN: usize> array<T, { LEN }>
179where
180    T: Std140ArrayElement,
181{
182    #[doc(hidden)]
183    pub fn from_wrapped(wrapped: [ArrayElementWrapper<T>; LEN]) -> Self {
184        array { internal: wrapped }
185    }
186}
187
188impl<T, const LEN: usize> PartialEq for array<T, { LEN }>
189where
190    T: Std140ArrayElement + PartialEq,
191{
192    fn eq(&self, other: &Self) -> bool {
193        for i in 0..LEN {
194            if self.internal[i] != other.internal[i] {
195                return false;
196            }
197        }
198
199        true
200    }
201}
202
203impl<T, const LEN: usize> fmt::Debug for array<T, { LEN }>
204where
205    T: Std140ArrayElement + fmt::Debug,
206{
207    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
208        f.debug_list().entries(self.internal.iter()).finish()
209    }
210}
211
212// TODO: something like this? (if that ever becomes possible)
213//impl<T, const LEN: usize> Unsize<slice<T>> for array<T, {LEN}> {}
214//
215//pub struct slice<T> where T: Std140ArrayElement {
216//    internal: *mut [ArrayElementWrapper<T>]
217//}
218
219#[doc(hidden)]
220#[derive(Clone, Copy, PartialEq, Eq, Hash)]
221#[repr(C, align(16))]
222pub struct ArrayElementWrapper<T>
223where
224    T: Std140ArrayElement,
225{
226    pub element: T,
227}
228
229impl<T> fmt::Debug for ArrayElementWrapper<T>
230where
231    T: Std140ArrayElement + fmt::Debug,
232{
233    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
234        <T as fmt::Debug>::fmt(&self.element, f)
235    }
236}
237
238/// Initializes a `std140` [array][struct@array].
239///
240/// # Example
241///
242/// ```
243/// let std140_array: std140::array<std140::vec2, 2> = std140::array![
244///     std140::vec2(1.0, 0.0),
245///     std140::vec2(0.0, 1.0),
246/// ];
247/// ```
248#[macro_export]
249macro_rules! array {
250    ($elem:expr; $n:expr) => {
251        $crate::array::from_wrapped([$crate::ArrayElementWrapper {
252            element: $elem
253        }; $n])
254    };
255    ($($x:expr),*) => {
256        $crate::array::from_wrapped([
257            $(
258                $crate::ArrayElementWrapper {
259                    element: $x
260                }
261            ),*
262        ])
263    };
264    ($($x:expr,)*) => ($crate::array![$($x),*])
265}
266
267unsafe impl<T, const LEN: usize> ReprStd140 for array<T, { LEN }> where T: Std140ArrayElement {}
268
269/// A 32-bit floating point value.
270///
271/// # Example
272///
273/// ```
274/// let value = std140::float(0.5);
275/// ```
276#[repr(C, align(4))]
277#[derive(Clone, Copy, PartialEq, Debug)]
278pub struct float(pub f32);
279
280unsafe impl ReprStd140 for float {}
281unsafe impl Std140ArrayElement for float {}
282
283/// A column vector of 2 [float] values.
284///
285/// # Example
286///
287/// ```
288/// let value = std140::vec2(0.0, 1.0);
289/// ```
290#[repr(C, align(8))]
291#[derive(Clone, Copy, PartialEq, Debug)]
292pub struct vec2(pub f32, pub f32);
293
294impl vec2 {
295    /// Creates a new [vec2] with zeros in all positions.
296    pub fn zero() -> Self {
297        vec2(0.0, 0.0)
298    }
299}
300
301unsafe impl ReprStd140 for vec2 {}
302unsafe impl Std140ArrayElement for vec2 {}
303
304impl Index<usize> for vec2 {
305    type Output = f32;
306
307    fn index(&self, index: usize) -> &Self::Output {
308        match index {
309            0 => &self.0,
310            1 => &self.1,
311            _ => panic!("Index out of bounds"),
312        }
313    }
314}
315
316impl IndexMut<usize> for vec2 {
317    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
318        match index {
319            0 => &mut self.0,
320            1 => &mut self.1,
321            _ => panic!("Index out of bounds"),
322        }
323    }
324}
325
326/// A column vector of 3 [float] values.
327///
328/// # Example
329///
330/// ```
331/// let value = std140::vec3(0.0, 0.0, 1.0);
332/// ```
333#[repr(C, align(16))]
334#[derive(Clone, Copy, PartialEq, Debug)]
335pub struct vec3(pub f32, pub f32, pub f32);
336
337impl vec3 {
338    /// Creates a new [vec3] with zeros in all positions.
339    pub fn zero() -> Self {
340        vec3(0.0, 0.0, 0.0)
341    }
342}
343
344unsafe impl ReprStd140 for vec3 {}
345unsafe impl Std140ArrayElement for vec3 {}
346
347impl Index<usize> for vec3 {
348    type Output = f32;
349
350    fn index(&self, index: usize) -> &Self::Output {
351        match index {
352            0 => &self.0,
353            1 => &self.1,
354            2 => &self.2,
355            _ => panic!("Index out of bounds"),
356        }
357    }
358}
359
360impl IndexMut<usize> for vec3 {
361    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
362        match index {
363            0 => &mut self.0,
364            1 => &mut self.1,
365            2 => &mut self.2,
366            _ => panic!("Index out of bounds"),
367        }
368    }
369}
370
371/// A column vector of 4 [float] values.
372///
373/// # Example
374///
375/// ```
376/// let value = std140::vec4(0.0, 0.0, 0.0, 1.0);
377/// ```
378#[repr(C, align(16))]
379#[derive(Clone, Copy, PartialEq, Debug)]
380pub struct vec4(pub f32, pub f32, pub f32, pub f32);
381
382impl vec4 {
383    /// Creates a new [vec4] with zeros in all positions.
384    pub fn zero() -> Self {
385        vec4(0.0, 0.0, 0.0, 0.0)
386    }
387}
388
389unsafe impl ReprStd140 for vec4 {}
390unsafe impl Std140ArrayElement for vec4 {}
391
392impl Index<usize> for vec4 {
393    type Output = f32;
394
395    fn index(&self, index: usize) -> &Self::Output {
396        match index {
397            0 => &self.0,
398            1 => &self.1,
399            2 => &self.2,
400            3 => &self.3,
401            _ => panic!("Index out of bounds"),
402        }
403    }
404}
405
406impl IndexMut<usize> for vec4 {
407    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
408        match index {
409            0 => &mut self.0,
410            1 => &mut self.1,
411            2 => &mut self.2,
412            3 => &mut self.3,
413            _ => panic!("Index out of bounds"),
414        }
415    }
416}
417
418/// A 32-bit signed integer value.
419///
420/// # Example
421///
422/// ```
423/// let value = std140::int(1);
424/// ```
425#[repr(C, align(4))]
426#[derive(Clone, Copy, PartialEq, Debug)]
427pub struct int(pub i32);
428
429unsafe impl ReprStd140 for int {}
430unsafe impl Std140ArrayElement for int {}
431
432/// A column vector of 2 [int] values.
433///
434/// # Example
435///
436/// ```
437/// let value = std140::ivec2(0, 1);
438/// ```
439#[repr(C, align(8))]
440#[derive(Clone, Copy, PartialEq, Debug)]
441pub struct ivec2(pub i32, pub i32);
442
443impl ivec2 {
444    /// Creates a new [ivec2] with zeros in all positions.
445    pub fn zero() -> Self {
446        ivec2(0, 0)
447    }
448}
449
450unsafe impl ReprStd140 for ivec2 {}
451unsafe impl Std140ArrayElement for ivec2 {}
452
453impl Index<usize> for ivec2 {
454    type Output = i32;
455
456    fn index(&self, index: usize) -> &Self::Output {
457        match index {
458            0 => &self.0,
459            1 => &self.1,
460            _ => panic!("Index out of bounds"),
461        }
462    }
463}
464
465impl IndexMut<usize> for ivec2 {
466    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
467        match index {
468            0 => &mut self.0,
469            1 => &mut self.1,
470            _ => panic!("Index out of bounds"),
471        }
472    }
473}
474
475/// A column vector of 3 [int] values.
476///
477/// # Example
478///
479/// ```
480/// let value = std140::ivec3(0, 0, 1);
481/// ```
482#[repr(C, align(16))]
483#[derive(Clone, Copy, PartialEq, Debug)]
484pub struct ivec3(pub i32, pub i32, pub i32);
485
486impl ivec3 {
487    /// Creates a new [ivec3] with zeros in all positions.
488    pub fn zero() -> Self {
489        ivec3(0, 0, 0)
490    }
491}
492
493unsafe impl ReprStd140 for ivec3 {}
494unsafe impl Std140ArrayElement for ivec3 {}
495
496impl Index<usize> for ivec3 {
497    type Output = i32;
498
499    fn index(&self, index: usize) -> &Self::Output {
500        match index {
501            0 => &self.0,
502            1 => &self.1,
503            2 => &self.2,
504            _ => panic!("Index out of bounds"),
505        }
506    }
507}
508
509impl IndexMut<usize> for ivec3 {
510    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
511        match index {
512            0 => &mut self.0,
513            1 => &mut self.1,
514            2 => &mut self.2,
515            _ => panic!("Index out of bounds"),
516        }
517    }
518}
519
520/// A column vector of 4 [int] values.
521///
522/// # Example
523///
524/// ```
525/// let value = std140::ivec4(0, 0, 0, 1);
526/// ```
527#[repr(C, align(16))]
528#[derive(Clone, Copy, PartialEq, Debug)]
529pub struct ivec4(pub i32, pub i32, pub i32, pub i32);
530
531impl ivec4 {
532    /// Creates a new [ivec4] with zeros in all positions.
533    pub fn zero() -> Self {
534        ivec4(0, 0, 0, 0)
535    }
536}
537
538unsafe impl ReprStd140 for ivec4 {}
539unsafe impl Std140ArrayElement for ivec4 {}
540
541impl Index<usize> for ivec4 {
542    type Output = i32;
543
544    fn index(&self, index: usize) -> &Self::Output {
545        match index {
546            0 => &self.0,
547            1 => &self.1,
548            2 => &self.2,
549            3 => &self.3,
550            _ => panic!("Index out of bounds"),
551        }
552    }
553}
554
555impl IndexMut<usize> for ivec4 {
556    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
557        match index {
558            0 => &mut self.0,
559            1 => &mut self.1,
560            2 => &mut self.2,
561            3 => &mut self.3,
562            _ => panic!("Index out of bounds"),
563        }
564    }
565}
566
567/// A 32-bit unsigned integer value.
568///
569/// # Example
570///
571/// ```
572/// let value = std140::uint(1);
573/// ```
574#[repr(C, align(4))]
575#[derive(Clone, Copy, PartialEq, Debug)]
576pub struct uint(pub u32);
577
578unsafe impl ReprStd140 for uint {}
579unsafe impl Std140ArrayElement for uint {}
580
581/// A column vector of 2 [uint] values.
582///
583/// # Example
584///
585/// ```
586/// let value = std140::uvec2(0, 1);
587/// ```
588#[repr(C, align(8))]
589#[derive(Clone, Copy, PartialEq, Debug)]
590pub struct uvec2(pub u32, pub u32);
591
592impl uvec2 {
593    /// Creates a new [uvec2] with zeros in all positions.
594    pub fn zero() -> Self {
595        uvec2(0, 0)
596    }
597}
598
599unsafe impl ReprStd140 for uvec2 {}
600unsafe impl Std140ArrayElement for uvec2 {}
601
602impl Index<usize> for uvec2 {
603    type Output = u32;
604
605    fn index(&self, index: usize) -> &Self::Output {
606        match index {
607            0 => &self.0,
608            1 => &self.1,
609            _ => panic!("Index out of bounds"),
610        }
611    }
612}
613
614impl IndexMut<usize> for uvec2 {
615    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
616        match index {
617            0 => &mut self.0,
618            1 => &mut self.1,
619            _ => panic!("Index out of bounds"),
620        }
621    }
622}
623
624/// A column vector of 3 [uint] values.
625///
626/// # Example
627///
628/// ```
629/// let value = std140::uvec3(0, 0, 1);
630/// ```
631#[repr(C, align(16))]
632#[derive(Clone, Copy, PartialEq, Debug)]
633pub struct uvec3(pub u32, pub u32, pub u32);
634
635impl uvec3 {
636    /// Creates a new [uvec3] with zeros in all positions.
637    pub fn zero() -> Self {
638        uvec3(0, 0, 0)
639    }
640}
641
642unsafe impl ReprStd140 for uvec3 {}
643unsafe impl Std140ArrayElement for uvec3 {}
644
645impl Index<usize> for uvec3 {
646    type Output = u32;
647
648    fn index(&self, index: usize) -> &Self::Output {
649        match index {
650            0 => &self.0,
651            1 => &self.1,
652            2 => &self.2,
653            _ => panic!("Index out of bounds"),
654        }
655    }
656}
657
658impl IndexMut<usize> for uvec3 {
659    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
660        match index {
661            0 => &mut self.0,
662            1 => &mut self.1,
663            2 => &mut self.2,
664            _ => panic!("Index out of bounds"),
665        }
666    }
667}
668
669/// A column vector of 4 [uint] values.
670///
671/// # Example
672///
673/// ```
674/// let value = std140::uvec4(0, 0, 0, 1);
675/// ```
676#[repr(C, align(16))]
677#[derive(Clone, Copy, PartialEq, Debug)]
678pub struct uvec4(pub u32, pub u32, pub u32, pub u32);
679
680impl uvec4 {
681    /// Creates a new [uvec4] with zeros in all positions.
682    pub fn zero() -> Self {
683        uvec4(0, 0, 0, 0)
684    }
685}
686
687unsafe impl ReprStd140 for uvec4 {}
688unsafe impl Std140ArrayElement for uvec4 {}
689
690impl Index<usize> for uvec4 {
691    type Output = u32;
692
693    fn index(&self, index: usize) -> &Self::Output {
694        match index {
695            0 => &self.0,
696            1 => &self.1,
697            2 => &self.2,
698            3 => &self.3,
699            _ => panic!("Index out of bounds"),
700        }
701    }
702}
703
704impl IndexMut<usize> for uvec4 {
705    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
706        match index {
707            0 => &mut self.0,
708            1 => &mut self.1,
709            2 => &mut self.2,
710            3 => &mut self.3,
711            _ => panic!("Index out of bounds"),
712        }
713    }
714}
715
716/// A 32-bit boolean value.
717///
718/// [boolean::False] is stored identically to a [uint] of `0`; [boolean::True] is stored identically
719/// to a [uint] of `1`.
720///
721/// # Example
722///
723/// ```
724/// let value = std140::uint(1);
725/// ```
726#[repr(u32)]
727#[derive(Clone, Copy, PartialEq, Debug)]
728pub enum boolean {
729    True = 1,
730    False = 0,
731}
732
733unsafe impl ReprStd140 for boolean {}
734unsafe impl Std140ArrayElement for boolean {}
735
736impl From<bool> for boolean {
737    fn from(value: bool) -> Self {
738        match value {
739            true => boolean::True,
740            false => boolean::False,
741        }
742    }
743}
744
745/// A column vector of 2 [boolean] values.
746///
747/// # Example
748///
749/// ```
750/// let value = std140::bvec2(std140::boolean::False, std140::boolean::True);
751/// ```
752#[repr(C, align(8))]
753#[derive(Clone, Copy, PartialEq, Debug)]
754pub struct bvec2(pub boolean, pub boolean);
755
756unsafe impl ReprStd140 for bvec2 {}
757unsafe impl Std140ArrayElement for bvec2 {}
758
759impl Index<usize> for bvec2 {
760    type Output = boolean;
761
762    fn index(&self, index: usize) -> &Self::Output {
763        match index {
764            0 => &self.0,
765            1 => &self.1,
766            _ => panic!("Index out of bounds"),
767        }
768    }
769}
770
771impl IndexMut<usize> for bvec2 {
772    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
773        match index {
774            0 => &mut self.0,
775            1 => &mut self.1,
776            _ => panic!("Index out of bounds"),
777        }
778    }
779}
780
781/// A column vector of 3 [boolean] values.
782///
783/// # Example
784///
785/// ```
786/// let value = std140::bvec3(std140::boolean::False, std140::boolean::False, std140::boolean::True);
787/// ```
788#[repr(C, align(16))]
789#[derive(Clone, Copy, PartialEq, Debug)]
790pub struct bvec3(pub boolean, pub boolean, pub boolean);
791
792unsafe impl ReprStd140 for bvec3 {}
793unsafe impl Std140ArrayElement for bvec3 {}
794
795impl Index<usize> for bvec3 {
796    type Output = boolean;
797
798    fn index(&self, index: usize) -> &Self::Output {
799        match index {
800            0 => &self.0,
801            1 => &self.1,
802            2 => &self.2,
803            _ => panic!("Index out of bounds"),
804        }
805    }
806}
807
808impl IndexMut<usize> for bvec3 {
809    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
810        match index {
811            0 => &mut self.0,
812            1 => &mut self.1,
813            2 => &mut self.2,
814            _ => panic!("Index out of bounds"),
815        }
816    }
817}
818
819/// A column vector of 4 [boolean] values.
820///
821/// # Example
822///
823/// ```
824/// let value = std140::bvec4(
825///     std140::boolean::False,
826///     std140::boolean::False,
827///     std140::boolean::False,
828///     std140::boolean::True
829/// );
830/// ```
831#[repr(C, align(16))]
832#[derive(Clone, Copy, PartialEq, Debug)]
833pub struct bvec4(pub boolean, pub boolean, pub boolean, pub boolean);
834
835unsafe impl ReprStd140 for bvec4 {}
836unsafe impl Std140ArrayElement for bvec4 {}
837
838impl Index<usize> for bvec4 {
839    type Output = boolean;
840
841    fn index(&self, index: usize) -> &Self::Output {
842        match index {
843            0 => &self.0,
844            1 => &self.1,
845            2 => &self.2,
846            3 => &self.3,
847            _ => panic!("Index out of bounds"),
848        }
849    }
850}
851
852impl IndexMut<usize> for bvec4 {
853    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
854        match index {
855            0 => &mut self.0,
856            1 => &mut self.1,
857            2 => &mut self.2,
858            3 => &mut self.3,
859            _ => panic!("Index out of bounds"),
860        }
861    }
862}
863
864/// A 64-bit floating point value.
865///
866/// # Example
867///
868/// ```
869/// let value = std140::double(0.5);
870/// ```
871#[repr(C, align(8))]
872#[derive(Clone, Copy, PartialEq, Debug)]
873pub struct double(pub f64);
874
875unsafe impl ReprStd140 for double {}
876unsafe impl Std140ArrayElement for double {}
877
878/// A column vector of 2 [double] values.
879///
880/// # Example
881///
882/// ```
883/// let value = std140::dvec2(0.0, 1.0);
884/// ```
885#[repr(C, align(16))]
886#[derive(Clone, Copy, PartialEq, Debug)]
887pub struct dvec2(pub f64, pub f64);
888
889impl dvec2 {
890    /// Creates a new [dvec2] with zeros in all positions.
891    pub fn zero() -> Self {
892        dvec2(0.0, 0.0)
893    }
894}
895
896unsafe impl ReprStd140 for dvec2 {}
897unsafe impl Std140ArrayElement for dvec2 {}
898
899impl Index<usize> for dvec2 {
900    type Output = f64;
901
902    fn index(&self, index: usize) -> &Self::Output {
903        match index {
904            0 => &self.0,
905            1 => &self.1,
906            _ => panic!("Index out of bounds"),
907        }
908    }
909}
910
911impl IndexMut<usize> for dvec2 {
912    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
913        match index {
914            0 => &mut self.0,
915            1 => &mut self.1,
916            _ => panic!("Index out of bounds"),
917        }
918    }
919}
920
921/// A column vector of 3 [double] values.
922///
923/// # Example
924///
925/// ```
926/// let value = std140::dvec3(0.0, 0.0, 1.0);
927/// ```
928#[repr(C, align(32))]
929#[derive(Clone, Copy, PartialEq, Debug)]
930pub struct dvec3(pub f64, pub f64, pub f64);
931
932impl dvec3 {
933    /// Creates a new [dvec3] with zeros in all positions.
934    pub fn zero() -> Self {
935        dvec3(0.0, 0.0, 0.0)
936    }
937}
938
939unsafe impl ReprStd140 for dvec3 {}
940unsafe impl Std140ArrayElement for dvec3 {}
941
942impl Index<usize> for dvec3 {
943    type Output = f64;
944
945    fn index(&self, index: usize) -> &Self::Output {
946        match index {
947            0 => &self.0,
948            1 => &self.1,
949            2 => &self.2,
950            _ => panic!("Index out of bounds"),
951        }
952    }
953}
954
955impl IndexMut<usize> for dvec3 {
956    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
957        match index {
958            0 => &mut self.0,
959            1 => &mut self.1,
960            2 => &mut self.2,
961            _ => panic!("Index out of bounds"),
962        }
963    }
964}
965
966/// A column vector of 4 [double] values.
967///
968/// # Example
969///
970/// ```
971/// let value = std140::dvec4(0.0, 0.0, 0.0, 1.0);
972/// ```
973#[repr(C, align(32))]
974#[derive(Clone, Copy, PartialEq, Debug)]
975pub struct dvec4(pub f64, pub f64, pub f64, pub f64);
976
977impl dvec4 {
978    /// Creates a new [dvec4] with zeros in all positions.
979    pub fn zero() -> Self {
980        dvec4(0.0, 0.0, 0.0, 0.0)
981    }
982}
983
984unsafe impl ReprStd140 for dvec4 {}
985unsafe impl Std140ArrayElement for dvec4 {}
986
987impl Index<usize> for dvec4 {
988    type Output = f64;
989
990    fn index(&self, index: usize) -> &Self::Output {
991        match index {
992            0 => &self.0,
993            1 => &self.1,
994            2 => &self.2,
995            3 => &self.3,
996            _ => panic!("Index out of bounds"),
997        }
998    }
999}
1000
1001impl IndexMut<usize> for dvec4 {
1002    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1003        match index {
1004            0 => &mut self.0,
1005            1 => &mut self.1,
1006            2 => &mut self.2,
1007            3 => &mut self.3,
1008            _ => panic!("Index out of bounds"),
1009        }
1010    }
1011}
1012
1013/// A matrix with 2 columns and 2 rows, represented by 2 [vec2] vectors.
1014///
1015/// # Example
1016///
1017/// ```
1018/// let value = std140::mat2x2(
1019///     std140::vec2(0.0, 1.0),
1020///     std140::vec2(0.0, 1.0),
1021/// );
1022/// ```
1023#[derive(Clone, Copy, PartialEq)]
1024pub struct mat2x2 {
1025    columns: array<vec2, 2>,
1026}
1027
1028impl mat2x2 {
1029    /// Creates a new [mat2x2] with zeros in all positions.
1030    pub fn zero() -> Self {
1031        mat2x2(vec2::zero(), vec2::zero())
1032    }
1033}
1034
1035/// Initializes a [mat2x2][struct@mat2x2]
1036///
1037/// # Example
1038///
1039/// See [mat2x2][struct@mat2x2].
1040pub fn mat2x2(c0: vec2, c1: vec2) -> mat2x2 {
1041    mat2x2 {
1042        columns: array![c0, c1],
1043    }
1044}
1045
1046unsafe impl ReprStd140 for mat2x2 {}
1047unsafe impl Std140ArrayElement for mat2x2 {}
1048
1049impl Deref for mat2x2 {
1050    type Target = array<vec2, 2>;
1051
1052    fn deref(&self) -> &Self::Target {
1053        &self.columns
1054    }
1055}
1056
1057impl DerefMut for mat2x2 {
1058    fn deref_mut(&mut self) -> &mut Self::Target {
1059        &mut self.columns
1060    }
1061}
1062
1063impl fmt::Debug for mat2x2 {
1064    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1065        f.write_fmt(format_args!("mat2x2{:?}", &self.columns))
1066    }
1067}
1068
1069/// A matrix with 2 columns and 3 rows, represented by 2 [vec3] vectors.
1070///
1071/// # Example
1072///
1073/// ```
1074/// let value = std140::mat2x3(
1075///     std140::vec3(0.0, 0.0, 1.0),
1076///     std140::vec3(0.0, 0.0, 1.0),
1077/// );
1078/// ```
1079#[derive(Clone, Copy, PartialEq)]
1080pub struct mat2x3 {
1081    columns: array<vec3, 2>,
1082}
1083
1084impl mat2x3 {
1085    /// Creates a new [mat2x3] with zeros in all positions.
1086    pub fn zero() -> Self {
1087        mat2x3(vec3::zero(), vec3::zero())
1088    }
1089}
1090
1091/// Initializes a [mat2x3][struct@mat2x3]
1092///
1093/// # Example
1094///
1095/// See [mat2x3][struct@mat2x3].
1096pub fn mat2x3(c0: vec3, c1: vec3) -> mat2x3 {
1097    mat2x3 {
1098        columns: array![c0, c1],
1099    }
1100}
1101
1102unsafe impl ReprStd140 for mat2x3 {}
1103unsafe impl Std140ArrayElement for mat2x3 {}
1104
1105impl Deref for mat2x3 {
1106    type Target = array<vec3, 2>;
1107
1108    fn deref(&self) -> &Self::Target {
1109        &self.columns
1110    }
1111}
1112
1113impl DerefMut for mat2x3 {
1114    fn deref_mut(&mut self) -> &mut Self::Target {
1115        &mut self.columns
1116    }
1117}
1118
1119impl fmt::Debug for mat2x3 {
1120    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1121        f.write_fmt(format_args!("mat2x3{:?}", &self.columns))
1122    }
1123}
1124
1125/// A matrix with 2 columns and 4 rows, represented by 2 [vec4] vectors.
1126///
1127/// # Example
1128///
1129/// ```
1130/// let value = std140::mat2x4(
1131///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1132///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1133/// );
1134/// ```
1135#[derive(Clone, Copy, PartialEq)]
1136pub struct mat2x4 {
1137    columns: array<vec4, 2>,
1138}
1139
1140impl mat2x4 {
1141    /// Creates a new [mat2x4] with zeros in all positions.
1142    pub fn zero() -> Self {
1143        mat2x4(vec4::zero(), vec4::zero())
1144    }
1145}
1146
1147/// Initializes a [mat2x4][struct@mat2x4]
1148///
1149/// # Example
1150///
1151/// See [mat2x4][struct@mat2x4].
1152pub fn mat2x4(c0: vec4, c1: vec4) -> mat2x4 {
1153    mat2x4 {
1154        columns: array![c0, c1],
1155    }
1156}
1157
1158unsafe impl ReprStd140 for mat2x4 {}
1159unsafe impl Std140ArrayElement for mat2x4 {}
1160
1161impl Deref for mat2x4 {
1162    type Target = array<vec4, 2>;
1163
1164    fn deref(&self) -> &Self::Target {
1165        &self.columns
1166    }
1167}
1168
1169impl DerefMut for mat2x4 {
1170    fn deref_mut(&mut self) -> &mut Self::Target {
1171        &mut self.columns
1172    }
1173}
1174
1175impl fmt::Debug for mat2x4 {
1176    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1177        f.write_fmt(format_args!("mat2x4{:?}", &self.columns))
1178    }
1179}
1180
1181/// A matrix with 3 columns and 2 rows, represented by 3 [vec2] vectors.
1182///
1183/// # Example
1184///
1185/// ```
1186/// let value = std140::mat3x2(
1187///     std140::vec2(0.0, 1.0),
1188///     std140::vec2(0.0, 1.0),
1189///     std140::vec2(0.0, 1.0),
1190/// );
1191/// ```
1192#[derive(Clone, Copy, PartialEq)]
1193pub struct mat3x2 {
1194    columns: array<vec2, 3>,
1195}
1196
1197impl mat3x2 {
1198    /// Creates a new [mat3x2] with zeros in all positions.
1199    pub fn zero() -> Self {
1200        mat3x2(vec2::zero(), vec2::zero(), vec2::zero())
1201    }
1202}
1203
1204/// Initializes a [mat3x2][struct@mat3x2]
1205///
1206/// # Example
1207///
1208/// See [mat3x2][struct@mat3x2].
1209pub fn mat3x2(c0: vec2, c1: vec2, c2: vec2) -> mat3x2 {
1210    mat3x2 {
1211        columns: array![c0, c1, c2],
1212    }
1213}
1214
1215unsafe impl ReprStd140 for mat3x2 {}
1216unsafe impl Std140ArrayElement for mat3x2 {}
1217
1218impl Deref for mat3x2 {
1219    type Target = array<vec2, 3>;
1220
1221    fn deref(&self) -> &Self::Target {
1222        &self.columns
1223    }
1224}
1225
1226impl DerefMut for mat3x2 {
1227    fn deref_mut(&mut self) -> &mut Self::Target {
1228        &mut self.columns
1229    }
1230}
1231
1232impl fmt::Debug for mat3x2 {
1233    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1234        f.write_fmt(format_args!("mat3x2{:?}", &self.columns))
1235    }
1236}
1237
1238/// A matrix with 3 columns and 3 rows, represented by 3 [vec3] vectors.
1239///
1240/// # Example
1241///
1242/// ```
1243/// let value = std140::mat3x3(
1244///     std140::vec3(0.0, 0.0, 1.0),
1245///     std140::vec3(0.0, 0.0, 1.0),
1246///     std140::vec3(0.0, 0.0, 1.0),
1247/// );
1248/// ```
1249#[derive(Clone, Copy, PartialEq)]
1250pub struct mat3x3 {
1251    columns: array<vec3, 3>,
1252}
1253
1254impl mat3x3 {
1255    /// Creates a new [mat3x3] with zeros in all positions.
1256    pub fn zero() -> Self {
1257        mat3x3(vec3::zero(), vec3::zero(), vec3::zero())
1258    }
1259}
1260
1261/// Initializes a [mat3x3][struct@mat3x3]
1262///
1263/// # Example
1264///
1265/// See [mat3x3][struct@mat3x3].
1266pub fn mat3x3(c0: vec3, c1: vec3, c2: vec3) -> mat3x3 {
1267    mat3x3 {
1268        columns: array![c0, c1, c2],
1269    }
1270}
1271
1272unsafe impl ReprStd140 for mat3x3 {}
1273unsafe impl Std140ArrayElement for mat3x3 {}
1274
1275impl Deref for mat3x3 {
1276    type Target = array<vec3, 3>;
1277
1278    fn deref(&self) -> &Self::Target {
1279        &self.columns
1280    }
1281}
1282
1283impl DerefMut for mat3x3 {
1284    fn deref_mut(&mut self) -> &mut Self::Target {
1285        &mut self.columns
1286    }
1287}
1288
1289impl fmt::Debug for mat3x3 {
1290    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1291        f.write_fmt(format_args!("mat3x3{:?}", &self.columns))
1292    }
1293}
1294
1295/// A matrix with 3 columns and 4 rows, represented by 3 [vec4] vectors.
1296///
1297/// # Example
1298///
1299/// ```
1300/// let value = std140::mat3x4(
1301///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1302///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1303///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1304/// );
1305/// ```
1306#[derive(Clone, Copy, PartialEq)]
1307pub struct mat3x4 {
1308    columns: array<vec4, 3>,
1309}
1310
1311impl mat3x4 {
1312    /// Creates a new [mat3x4] with zeros in all positions.
1313    pub fn zero() -> Self {
1314        mat3x4(vec4::zero(), vec4::zero(), vec4::zero())
1315    }
1316}
1317
1318/// Initializes a [mat3x4][struct@mat3x4]
1319///
1320/// # Example
1321///
1322/// See [mat3x4][struct@mat3x4].
1323pub fn mat3x4(c0: vec4, c1: vec4, c2: vec4) -> mat3x4 {
1324    mat3x4 {
1325        columns: array![c0, c1, c2],
1326    }
1327}
1328
1329unsafe impl ReprStd140 for mat3x4 {}
1330unsafe impl Std140ArrayElement for mat3x4 {}
1331
1332impl Deref for mat3x4 {
1333    type Target = array<vec4, 3>;
1334
1335    fn deref(&self) -> &Self::Target {
1336        &self.columns
1337    }
1338}
1339
1340impl DerefMut for mat3x4 {
1341    fn deref_mut(&mut self) -> &mut Self::Target {
1342        &mut self.columns
1343    }
1344}
1345
1346impl fmt::Debug for mat3x4 {
1347    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1348        f.write_fmt(format_args!("mat3x4{:?}", &self.columns))
1349    }
1350}
1351
1352/// A matrix with 4 columns and 2 rows, represented by 4 [vec2] vectors.
1353///
1354/// # Example
1355///
1356/// ```
1357/// let value = std140::mat4x2(
1358///     std140::vec2(0.0, 1.0),
1359///     std140::vec2(0.0, 1.0),
1360///     std140::vec2(0.0, 1.0),
1361///     std140::vec2(0.0, 1.0),
1362/// );
1363/// ```
1364#[derive(Clone, Copy, PartialEq)]
1365pub struct mat4x2 {
1366    columns: array<vec2, 4>,
1367}
1368
1369impl mat4x2 {
1370    /// Creates a new [mat4x2] with zeros in all positions.
1371    pub fn zero() -> Self {
1372        mat4x2(vec2::zero(), vec2::zero(), vec2::zero(), vec2::zero())
1373    }
1374}
1375
1376/// Initializes a [mat4x2][struct@mat4x2]
1377///
1378/// # Example
1379///
1380/// See [mat4x2][struct@mat4x2].
1381pub fn mat4x2(c0: vec2, c1: vec2, c2: vec2, c3: vec2) -> mat4x2 {
1382    mat4x2 {
1383        columns: array![c0, c1, c2, c3],
1384    }
1385}
1386
1387unsafe impl ReprStd140 for mat4x2 {}
1388unsafe impl Std140ArrayElement for mat4x2 {}
1389
1390impl Deref for mat4x2 {
1391    type Target = array<vec2, 4>;
1392
1393    fn deref(&self) -> &Self::Target {
1394        &self.columns
1395    }
1396}
1397
1398impl DerefMut for mat4x2 {
1399    fn deref_mut(&mut self) -> &mut Self::Target {
1400        &mut self.columns
1401    }
1402}
1403
1404impl fmt::Debug for mat4x2 {
1405    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1406        f.write_fmt(format_args!("mat4x2{:?}", &self.columns))
1407    }
1408}
1409
1410/// A matrix with 4 columns and 3 rows, represented by 4 [vec3] vectors.
1411///
1412/// # Example
1413///
1414/// ```
1415/// let value = std140::mat4x3(
1416///     std140::vec3(0.0, 0.0, 1.0),
1417///     std140::vec3(0.0, 0.0, 1.0),
1418///     std140::vec3(0.0, 0.0, 1.0),
1419///     std140::vec3(0.0, 0.0, 1.0),
1420/// );
1421/// ```
1422#[derive(Clone, Copy, PartialEq)]
1423pub struct mat4x3 {
1424    columns: array<vec3, 4>,
1425}
1426
1427impl mat4x3 {
1428    /// Creates a new [mat4x3] with zeros in all positions.
1429    pub fn zero() -> Self {
1430        mat4x3(vec3::zero(), vec3::zero(), vec3::zero(), vec3::zero())
1431    }
1432}
1433
1434/// Initializes a [mat4x3][struct@mat4x3]
1435///
1436/// # Example
1437///
1438/// See [mat4x3][struct@mat4x3].
1439pub fn mat4x3(c0: vec3, c1: vec3, c2: vec3, c3: vec3) -> mat4x3 {
1440    mat4x3 {
1441        columns: array![c0, c1, c2, c3],
1442    }
1443}
1444
1445unsafe impl ReprStd140 for mat4x3 {}
1446unsafe impl Std140ArrayElement for mat4x3 {}
1447
1448impl Deref for mat4x3 {
1449    type Target = array<vec3, 4>;
1450
1451    fn deref(&self) -> &Self::Target {
1452        &self.columns
1453    }
1454}
1455
1456impl DerefMut for mat4x3 {
1457    fn deref_mut(&mut self) -> &mut Self::Target {
1458        &mut self.columns
1459    }
1460}
1461
1462impl fmt::Debug for mat4x3 {
1463    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1464        f.write_fmt(format_args!("mat4x3{:?}", &self.columns))
1465    }
1466}
1467
1468/// A matrix with 4 columns and 4 rows, represented by 4 [vec4] vectors.
1469///
1470/// # Example
1471///
1472/// ```
1473/// let value = std140::mat4x4(
1474///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1475///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1476///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1477///     std140::vec4(0.0, 0.0, 0.0, 1.0),
1478/// );
1479/// ```
1480#[derive(Clone, Copy, PartialEq)]
1481pub struct mat4x4 {
1482    columns: array<vec4, 4>,
1483}
1484
1485impl mat4x4 {
1486    /// Creates a new [mat4x4] with zeros in all positions.
1487    pub fn zero() -> Self {
1488        mat4x4(vec4::zero(), vec4::zero(), vec4::zero(), vec4::zero())
1489    }
1490}
1491
1492/// Initializes a [mat4x4][struct@mat4x4]
1493///
1494/// # Example
1495///
1496/// See [mat4x4][struct@mat4x4].
1497pub fn mat4x4(c0: vec4, c1: vec4, c2: vec4, c3: vec4) -> mat4x4 {
1498    mat4x4 {
1499        columns: array![c0, c1, c2, c3],
1500    }
1501}
1502
1503unsafe impl ReprStd140 for mat4x4 {}
1504unsafe impl Std140ArrayElement for mat4x4 {}
1505
1506impl Deref for mat4x4 {
1507    type Target = array<vec4, 4>;
1508
1509    fn deref(&self) -> &Self::Target {
1510        &self.columns
1511    }
1512}
1513
1514impl DerefMut for mat4x4 {
1515    fn deref_mut(&mut self) -> &mut Self::Target {
1516        &mut self.columns
1517    }
1518}
1519
1520impl fmt::Debug for mat4x4 {
1521    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1522        f.write_fmt(format_args!("mat4x4{:?}", &self.columns))
1523    }
1524}
1525
1526/// A matrix with 2 columns and 2 rows, represented by 2 [dvec2] vectors.
1527///
1528/// # Example
1529///
1530/// ```
1531/// let value = std140::dmat2x2(
1532///     std140::dvec2(0.0, 1.0),
1533///     std140::dvec2(0.0, 1.0),
1534/// );
1535/// ```
1536#[derive(Clone, Copy, PartialEq)]
1537pub struct dmat2x2 {
1538    columns: array<dvec2, 2>,
1539}
1540
1541impl dmat2x2 {
1542    /// Creates a new [dmat2x2] with zeros in all positions.
1543    pub fn zero() -> Self {
1544        dmat2x2(dvec2::zero(), dvec2::zero())
1545    }
1546}
1547
1548/// Initializes a [dmat2x2][struct@dmat2x2]
1549///
1550/// # Example
1551///
1552/// See [dmat2x2][struct@dmat2x2].
1553pub fn dmat2x2(c0: dvec2, c1: dvec2) -> dmat2x2 {
1554    dmat2x2 {
1555        columns: array![c0, c1],
1556    }
1557}
1558
1559unsafe impl ReprStd140 for dmat2x2 {}
1560unsafe impl Std140ArrayElement for dmat2x2 {}
1561
1562impl Deref for dmat2x2 {
1563    type Target = array<dvec2, 2>;
1564
1565    fn deref(&self) -> &Self::Target {
1566        &self.columns
1567    }
1568}
1569
1570impl DerefMut for dmat2x2 {
1571    fn deref_mut(&mut self) -> &mut Self::Target {
1572        &mut self.columns
1573    }
1574}
1575
1576impl fmt::Debug for dmat2x2 {
1577    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1578        f.write_fmt(format_args!("dmat2x2{:?}", &self.columns))
1579    }
1580}
1581
1582/// A matrix with 2 columns and 3 rows, represented by 2 [dvec3] vectors.
1583///
1584/// # Example
1585///
1586/// ```
1587/// let value = std140::dmat2x3(
1588///     std140::dvec3(0.0, 0.0, 1.0),
1589///     std140::dvec3(0.0, 0.0, 1.0),
1590/// );
1591/// ```
1592#[derive(Clone, Copy, PartialEq)]
1593pub struct dmat2x3 {
1594    columns: array<dvec3, 2>,
1595}
1596
1597impl dmat2x3 {
1598    /// Creates a new [dmat2x3] with zeros in all positions.
1599    pub fn zero() -> Self {
1600        dmat2x3(dvec3::zero(), dvec3::zero())
1601    }
1602}
1603
1604/// Initializes a [dmat2x3][struct@dmat2x3]
1605///
1606/// # Example
1607///
1608/// See [dmat2x3][struct@dmat2x3].
1609pub fn dmat2x3(c0: dvec3, c1: dvec3) -> dmat2x3 {
1610    dmat2x3 {
1611        columns: array![c0, c1],
1612    }
1613}
1614
1615unsafe impl ReprStd140 for dmat2x3 {}
1616unsafe impl Std140ArrayElement for dmat2x3 {}
1617
1618impl Deref for dmat2x3 {
1619    type Target = array<dvec3, 2>;
1620
1621    fn deref(&self) -> &Self::Target {
1622        &self.columns
1623    }
1624}
1625
1626impl DerefMut for dmat2x3 {
1627    fn deref_mut(&mut self) -> &mut Self::Target {
1628        &mut self.columns
1629    }
1630}
1631
1632impl fmt::Debug for dmat2x3 {
1633    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1634        f.write_fmt(format_args!("dmat2x3{:?}", &self.columns))
1635    }
1636}
1637
1638/// A matrix with 2 columns and 4 rows, represented by 2 [dvec4] vectors.
1639///
1640/// # Example
1641///
1642/// ```
1643/// let value = std140::dmat2x4(
1644///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1645///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1646/// );
1647/// ```
1648#[derive(Clone, Copy, PartialEq)]
1649pub struct dmat2x4 {
1650    columns: array<dvec4, 2>,
1651}
1652
1653impl dmat2x4 {
1654    /// Creates a new [dmat2x4] with zeros in all positions.
1655    pub fn zero() -> Self {
1656        dmat2x4(dvec4::zero(), dvec4::zero())
1657    }
1658}
1659
1660/// Initializes a [dmat2x4][struct@dmat2x4]
1661///
1662/// # Example
1663///
1664/// See [dmat2x4][struct@dmat2x4].
1665pub fn dmat2x4(c0: dvec4, c1: dvec4) -> dmat2x4 {
1666    dmat2x4 {
1667        columns: array![c0, c1],
1668    }
1669}
1670
1671unsafe impl ReprStd140 for dmat2x4 {}
1672unsafe impl Std140ArrayElement for dmat2x4 {}
1673
1674impl Deref for dmat2x4 {
1675    type Target = array<dvec4, 2>;
1676
1677    fn deref(&self) -> &Self::Target {
1678        &self.columns
1679    }
1680}
1681
1682impl DerefMut for dmat2x4 {
1683    fn deref_mut(&mut self) -> &mut Self::Target {
1684        &mut self.columns
1685    }
1686}
1687
1688impl fmt::Debug for dmat2x4 {
1689    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1690        f.write_fmt(format_args!("dmat2x4{:?}", &self.columns))
1691    }
1692}
1693
1694/// A matrix with 3 columns and 2 rows, represented by 3 [dvec2] vectors.
1695///
1696/// # Example
1697///
1698/// ```
1699/// let value = std140::dmat3x2(
1700///     std140::dvec2(0.0, 1.0),
1701///     std140::dvec2(0.0, 1.0),
1702///     std140::dvec2(0.0, 1.0),
1703/// );
1704/// ```
1705#[derive(Clone, Copy, PartialEq)]
1706pub struct dmat3x2 {
1707    columns: array<dvec2, 3>,
1708}
1709
1710impl dmat3x2 {
1711    /// Creates a new [dmat3x2] with zeros in all positions.
1712    pub fn zero() -> Self {
1713        dmat3x2(dvec2::zero(), dvec2::zero(), dvec2::zero())
1714    }
1715}
1716
1717/// Initializes a [dmat3x2][struct@dmat3x2]
1718///
1719/// # Example
1720///
1721/// See [dmat3x2][struct@dmat3x2].
1722pub fn dmat3x2(c0: dvec2, c1: dvec2, c2: dvec2) -> dmat3x2 {
1723    dmat3x2 {
1724        columns: array![c0, c1, c2],
1725    }
1726}
1727
1728unsafe impl ReprStd140 for dmat3x2 {}
1729unsafe impl Std140ArrayElement for dmat3x2 {}
1730
1731impl Deref for dmat3x2 {
1732    type Target = array<dvec2, 3>;
1733
1734    fn deref(&self) -> &Self::Target {
1735        &self.columns
1736    }
1737}
1738
1739impl DerefMut for dmat3x2 {
1740    fn deref_mut(&mut self) -> &mut Self::Target {
1741        &mut self.columns
1742    }
1743}
1744
1745impl fmt::Debug for dmat3x2 {
1746    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1747        f.write_fmt(format_args!("dmat3x2{:?}", &self.columns))
1748    }
1749}
1750
1751/// A matrix with 3 columns and 3 rows, represented by 3 [dvec3] vectors.
1752///
1753/// # Example
1754///
1755/// ```
1756/// let value = std140::dmat3x3(
1757///     std140::dvec3(0.0, 0.0, 1.0),
1758///     std140::dvec3(0.0, 0.0, 1.0),
1759///     std140::dvec3(0.0, 0.0, 1.0),
1760/// );
1761/// ```
1762#[derive(Clone, Copy, PartialEq)]
1763pub struct dmat3x3 {
1764    columns: array<dvec3, 3>,
1765}
1766
1767impl dmat3x3 {
1768    /// Creates a new [dmat3x3] with zeros in all positions.
1769    pub fn zero() -> Self {
1770        dmat3x3(dvec3::zero(), dvec3::zero(), dvec3::zero())
1771    }
1772}
1773
1774/// Initializes a [dmat3x3][struct@dmat3x3]
1775///
1776/// # Example
1777///
1778/// See [dmat3x3][struct@dmat3x3].
1779pub fn dmat3x3(c0: dvec3, c1: dvec3, c2: dvec3) -> dmat3x3 {
1780    dmat3x3 {
1781        columns: array![c0, c1, c2],
1782    }
1783}
1784
1785unsafe impl ReprStd140 for dmat3x3 {}
1786unsafe impl Std140ArrayElement for dmat3x3 {}
1787
1788impl Deref for dmat3x3 {
1789    type Target = array<dvec3, 3>;
1790
1791    fn deref(&self) -> &Self::Target {
1792        &self.columns
1793    }
1794}
1795
1796impl DerefMut for dmat3x3 {
1797    fn deref_mut(&mut self) -> &mut Self::Target {
1798        &mut self.columns
1799    }
1800}
1801
1802impl fmt::Debug for dmat3x3 {
1803    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1804        f.write_fmt(format_args!("dmat3x3{:?}", &self.columns))
1805    }
1806}
1807
1808/// A matrix with 3 columns and 4 rows, represented by 3 [dvec4] vectors.
1809///
1810/// # Example
1811///
1812/// ```
1813/// let value = std140::dmat3x4(
1814///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1815///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1816///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1817/// );
1818/// ```
1819#[derive(Clone, Copy, PartialEq)]
1820pub struct dmat3x4 {
1821    columns: array<dvec4, 3>,
1822}
1823
1824impl dmat3x4 {
1825    /// Creates a new [dmat3x4] with zeros in all positions.
1826    pub fn zero() -> Self {
1827        dmat3x4(dvec4::zero(), dvec4::zero(), dvec4::zero())
1828    }
1829}
1830
1831/// Initializes a [dmat3x4][struct@dmat3x4]
1832///
1833/// # Example
1834///
1835/// See [dmat3x4][struct@dmat3x4].
1836pub fn dmat3x4(c0: dvec4, c1: dvec4, c2: dvec4) -> dmat3x4 {
1837    dmat3x4 {
1838        columns: array![c0, c1, c2],
1839    }
1840}
1841
1842unsafe impl ReprStd140 for dmat3x4 {}
1843unsafe impl Std140ArrayElement for dmat3x4 {}
1844
1845impl Deref for dmat3x4 {
1846    type Target = array<dvec4, 3>;
1847
1848    fn deref(&self) -> &Self::Target {
1849        &self.columns
1850    }
1851}
1852
1853impl DerefMut for dmat3x4 {
1854    fn deref_mut(&mut self) -> &mut Self::Target {
1855        &mut self.columns
1856    }
1857}
1858
1859impl fmt::Debug for dmat3x4 {
1860    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1861        f.write_fmt(format_args!("dmat3x4{:?}", &self.columns))
1862    }
1863}
1864
1865/// A matrix with 4 columns and 2 rows, represented by 4 [dvec2] vectors.
1866///
1867/// # Example
1868///
1869/// ```
1870/// let value = std140::dmat4x2(
1871///     std140::dvec2(0.0, 1.0),
1872///     std140::dvec2(0.0, 1.0),
1873///     std140::dvec2(0.0, 1.0),
1874///     std140::dvec2(0.0, 1.0),
1875/// );
1876/// ```
1877#[derive(Clone, Copy, PartialEq)]
1878pub struct dmat4x2 {
1879    columns: array<dvec2, 4>,
1880}
1881
1882impl dmat4x2 {
1883    /// Creates a new [dmat4x2] with zeros in all positions.
1884    pub fn zero() -> Self {
1885        dmat4x2(dvec2::zero(), dvec2::zero(), dvec2::zero(), dvec2::zero())
1886    }
1887}
1888
1889/// Initializes a [dmat4x2][struct@dmat4x2]
1890///
1891/// # Example
1892///
1893/// See [dmat4x2][struct@dmat4x2].
1894pub fn dmat4x2(c0: dvec2, c1: dvec2, c2: dvec2, c3: dvec2) -> dmat4x2 {
1895    dmat4x2 {
1896        columns: array![c0, c1, c2, c3],
1897    }
1898}
1899
1900unsafe impl ReprStd140 for dmat4x2 {}
1901unsafe impl Std140ArrayElement for dmat4x2 {}
1902
1903impl Deref for dmat4x2 {
1904    type Target = array<dvec2, 4>;
1905
1906    fn deref(&self) -> &Self::Target {
1907        &self.columns
1908    }
1909}
1910
1911impl DerefMut for dmat4x2 {
1912    fn deref_mut(&mut self) -> &mut Self::Target {
1913        &mut self.columns
1914    }
1915}
1916
1917impl fmt::Debug for dmat4x2 {
1918    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1919        f.write_fmt(format_args!("dmat4x2{:?}", &self.columns))
1920    }
1921}
1922
1923/// A matrix with 4 columns and 3 rows, represented by 4 [dvec3] vectors.
1924///
1925/// # Example
1926///
1927/// ```
1928/// let value = std140::dmat4x3(
1929///     std140::dvec3(0.0, 0.0, 1.0),
1930///     std140::dvec3(0.0, 0.0, 1.0),
1931///     std140::dvec3(0.0, 0.0, 1.0),
1932///     std140::dvec3(0.0, 0.0, 1.0),
1933/// );
1934/// ```
1935#[derive(Clone, Copy, PartialEq)]
1936pub struct dmat4x3 {
1937    columns: array<dvec3, 4>,
1938}
1939
1940impl dmat4x3 {
1941    /// Creates a new [dmat4x3] with zeros in all positions.
1942    pub fn zero() -> Self {
1943        dmat4x3(dvec3::zero(), dvec3::zero(), dvec3::zero(), dvec3::zero())
1944    }
1945}
1946
1947/// Initializes a [dmat4x3][struct@dmat4x3]
1948///
1949/// # Example
1950///
1951/// See [dmat4x3][struct@dmat4x3].
1952pub fn dmat4x3(c0: dvec3, c1: dvec3, c2: dvec3, c3: dvec3) -> dmat4x3 {
1953    dmat4x3 {
1954        columns: array![c0, c1, c2, c3],
1955    }
1956}
1957
1958unsafe impl ReprStd140 for dmat4x3 {}
1959unsafe impl Std140ArrayElement for dmat4x3 {}
1960
1961impl Deref for dmat4x3 {
1962    type Target = array<dvec3, 4>;
1963
1964    fn deref(&self) -> &Self::Target {
1965        &self.columns
1966    }
1967}
1968
1969impl DerefMut for dmat4x3 {
1970    fn deref_mut(&mut self) -> &mut Self::Target {
1971        &mut self.columns
1972    }
1973}
1974
1975impl fmt::Debug for dmat4x3 {
1976    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1977        f.write_fmt(format_args!("dmat4x3{:?}", &self.columns))
1978    }
1979}
1980
1981/// A matrix with 4 columns and 4 rows, represented by 4 [dvec4] vectors.
1982///
1983/// # Example
1984///
1985/// ```
1986/// let value = std140::dmat4x4(
1987///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1988///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1989///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1990///     std140::dvec4(0.0, 0.0, 0.0, 1.0),
1991/// );
1992/// ```
1993#[derive(Clone, Copy, PartialEq)]
1994pub struct dmat4x4 {
1995    columns: array<dvec4, 4>,
1996}
1997
1998impl dmat4x4 {
1999    /// Creates a new [dmat4x4] with zeros in all positions.
2000    pub fn zero() -> Self {
2001        dmat4x4(dvec4::zero(), dvec4::zero(), dvec4::zero(), dvec4::zero())
2002    }
2003}
2004
2005/// Initializes a [dmat4x4][struct@dmat4x4]
2006///
2007/// # Example
2008///
2009/// See [dmat4x4][struct@dmat4x4].
2010pub fn dmat4x4(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4) -> dmat4x4 {
2011    dmat4x4 {
2012        columns: array![c0, c1, c2, c3],
2013    }
2014}
2015
2016unsafe impl ReprStd140 for dmat4x4 {}
2017unsafe impl Std140ArrayElement for dmat4x4 {}
2018
2019impl Deref for dmat4x4 {
2020    type Target = array<dvec4, 4>;
2021
2022    fn deref(&self) -> &Self::Target {
2023        &self.columns
2024    }
2025}
2026
2027impl DerefMut for dmat4x4 {
2028    fn deref_mut(&mut self) -> &mut Self::Target {
2029        &mut self.columns
2030    }
2031}
2032
2033impl fmt::Debug for dmat4x4 {
2034    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2035        f.write_fmt(format_args!("dmat4x4{:?}", &self.columns))
2036    }
2037}