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
use {
    super::{native::ShaderNative, scalar::boolean},
    bytemuck::{Pod, Zeroable},
};

/// Generic vector type.
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct vec<T, const N: usize>(pub [T; N]);

impl<T: Default + Copy, const N: usize> Default for vec<T, N> {
    fn default() -> Self {
        vec([Default::default(); N])
    }
}

unsafe impl<T: Zeroable, const N: usize> Zeroable for vec<T, N> {}
unsafe impl<T: Pod, const N: usize> Pod for vec<T, N> {}

impl<T: Pod, const N: usize> From<[T; N]> for vec<T, N> {
    fn from(value: [T; N]) -> Self {
        vec(value)
    }
}

/// Vector with 2-elements.
pub type vec2<T = f32> = vec<T, 2>;

unsafe impl ShaderNative for vec2<boolean> {
    const ALIGN_MASK: usize = 1;
    const ARRAY_PADDING_140: usize = 14;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 14];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec2<i32> {
    const ALIGN_MASK: usize = 7;
    const ARRAY_PADDING_140: usize = 8;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 8];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec2<u32> {
    const ALIGN_MASK: usize = 7;
    const ARRAY_PADDING_140: usize = 8;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 8];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec2<f32> {
    const ALIGN_MASK: usize = 7;
    const ARRAY_PADDING_140: usize = 8;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 8];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec2<f64> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 0;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 0];
    type ArrayPadding430 = [u8; 0];
}

/// Vector with 3-elements.
pub type vec3<T = f32> = vec<T, 3>;

unsafe impl ShaderNative for vec3<boolean> {
    const ALIGN_MASK: usize = 3;
    const ARRAY_PADDING_140: usize = 13;
    const ARRAY_PADDING_430: usize = 1;
    type ArrayPadding140 = [u8; 13];
    type ArrayPadding430 = [u8; 1];
}
unsafe impl ShaderNative for vec3<i32> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 4;
    const ARRAY_PADDING_430: usize = 4;
    type ArrayPadding140 = [u8; 4];
    type ArrayPadding430 = [u8; 4];
}
unsafe impl ShaderNative for vec3<u32> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 4;
    const ARRAY_PADDING_430: usize = 4;
    type ArrayPadding140 = [u8; 4];
    type ArrayPadding430 = [u8; 4];
}
unsafe impl ShaderNative for vec3<f32> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 4;
    const ARRAY_PADDING_430: usize = 4;
    type ArrayPadding140 = [u8; 4];
    type ArrayPadding430 = [u8; 4];
}
unsafe impl ShaderNative for vec3<f64> {
    const ALIGN_MASK: usize = 31;
    const ARRAY_PADDING_140: usize = 8;
    const ARRAY_PADDING_430: usize = 8;
    type ArrayPadding140 = [u8; 8];
    type ArrayPadding430 = [u8; 8];
}

/// Vector with 4-elements.
pub type vec4<T = f32> = vec<T, 4>;

unsafe impl ShaderNative for vec4<boolean> {
    const ALIGN_MASK: usize = 3;
    const ARRAY_PADDING_140: usize = 12;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 12];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec4<i32> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 0;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 0];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec4<u32> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 0;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 0];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec4<f32> {
    const ALIGN_MASK: usize = 15;
    const ARRAY_PADDING_140: usize = 0;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 0];
    type ArrayPadding430 = [u8; 0];
}
unsafe impl ShaderNative for vec4<f64> {
    const ALIGN_MASK: usize = 31;
    const ARRAY_PADDING_140: usize = 0;
    const ARRAY_PADDING_430: usize = 0;
    type ArrayPadding140 = [u8; 0];
    type ArrayPadding430 = [u8; 0];
}

pub type bvec2 = vec2<bool>;
pub type bvec3 = vec3<bool>;
pub type bvec4 = vec4<bool>;
pub type ivec2 = vec2<i32>;
pub type ivec3 = vec3<i32>;
pub type ivec4 = vec4<i32>;
pub type uvec2 = vec2<u32>;
pub type uvec3 = vec3<u32>;
pub type uvec4 = vec4<u32>;
pub type dvec2 = vec2<f64>;
pub type dvec3 = vec3<f64>;
pub type dvec4 = vec4<f64>;