1use super::data_buffer::Writable;
2use super::texture::Texture;
3use super::types::{DataType, TypeMark};
4use crate::uniforms::{IntoUniform, UniformValue};
5
6impl Writable for f32 {
9 fn write(&self, output: &mut Vec<f32>) {
10 output.push(*self);
11 }
12 fn stride() -> usize {
13 return 1;
14 }
15}
16
17impl TypeMark for f32 {
18 fn data_type() -> DataType {
19 DataType::Float
20 }
21}
22
23impl IntoUniform for f32 {
24 fn into_uniform(&self) -> UniformValue {
25 UniformValue::Float(*self)
26 }
27}
28
29impl TypeMark for Texture {
32 fn data_type() -> DataType {
33 DataType::Sampler
34 }
35}
36
37impl IntoUniform for Texture {
38 fn into_uniform(&self) -> UniformValue {
39 UniformValue::Texture(self.clone())
40 }
41}
42
43impl TypeMark for Option<Texture> {
46 fn data_type() -> DataType {
47 DataType::Sampler
48 }
49}
50
51impl IntoUniform for Option<Texture> {
52 fn into_uniform(&self) -> UniformValue {
53 self.as_ref()
54 .map(|texture| UniformValue::Texture(texture.clone()))
55 .unwrap_or(UniformValue::None)
56 }
57}
58
59impl TypeMark for bool {
62 fn data_type() -> DataType {
63 DataType::Boolean
64 }
65}
66
67impl From<bool> for UniformValue {
68 fn from(value: bool) -> Self {
69 UniformValue::Boolean(value)
70 }
71}
72
73impl IntoUniform for bool {
74 fn into_uniform(&self) -> UniformValue {
75 UniformValue::Boolean(*self)
76 }
77}
78
79impl TypeMark for [f32; 2] {
82 fn data_type() -> DataType {
83 DataType::Vec2
84 }
85}
86
87impl IntoUniform for [f32; 2] {
88 fn into_uniform(&self) -> UniformValue {
89 UniformValue::Vec2(*self)
90 }
91}
92
93impl Writable for [f32; 2] {
94 fn write(&self, output: &mut Vec<f32>) {
95 for v in self {
96 output.push(*v);
97 }
98 }
99 fn stride() -> usize {
100 2
101 }
102}
103
104impl TypeMark for [f32; 3] {
107 fn data_type() -> DataType {
108 DataType::Vec3
109 }
110}
111
112impl IntoUniform for [f32; 3] {
113 fn into_uniform(&self) -> UniformValue {
114 UniformValue::Vec3(*self)
115 }
116}
117
118impl Writable for [f32; 3] {
119 fn write(&self, output: &mut Vec<f32>) {
120 for v in self {
121 output.push(*v);
122 }
123 }
124 fn stride() -> usize {
125 3
126 }
127}
128
129impl TypeMark for [f32; 4] {
132 fn data_type() -> DataType {
133 DataType::Vec4
134 }
135}
136
137impl IntoUniform for [f32; 4] {
138 fn into_uniform(&self) -> UniformValue {
139 UniformValue::Vec4(*self)
140 }
141}
142
143impl Writable for [f32; 4] {
144 fn write(&self, output: &mut Vec<f32>) {
145 for v in self {
146 output.push(*v);
147 }
148 }
149 fn stride() -> usize {
150 4
151 }
152}
153
154impl TypeMark for (f32, f32) {
157 fn data_type() -> DataType {
158 DataType::Vec2
159 }
160}
161
162impl IntoUniform for (f32, f32) {
163 fn into_uniform(&self) -> UniformValue {
164 UniformValue::Vec2([self.0, self.1])
165 }
166}
167
168impl Writable for (f32, f32) {
169 fn write(&self, output: &mut Vec<f32>) {
170 output.push(self.0);
171 output.push(self.1);
172 }
173 fn stride() -> usize {
174 2
175 }
176}
177
178impl TypeMark for (f32, f32, f32) {
181 fn data_type() -> DataType {
182 DataType::Vec3
183 }
184}
185
186impl IntoUniform for (f32, f32, f32) {
187 fn into_uniform(&self) -> UniformValue {
188 UniformValue::Vec3([self.0, self.1, self.2])
189 }
190}
191
192impl Writable for (f32, f32, f32) {
193 fn write(&self, output: &mut Vec<f32>) {
194 output.push(self.0);
195 output.push(self.1);
196 output.push(self.2);
197 }
198 fn stride() -> usize {
199 3
200 }
201}
202
203impl TypeMark for (f32, f32, f32, f32) {
206 fn data_type() -> DataType {
207 DataType::Vec4
208 }
209}
210
211impl IntoUniform for (f32, f32, f32, f32) {
212 fn into_uniform(&self) -> UniformValue {
213 UniformValue::Vec4([self.0, self.1, self.2, self.3])
214 }
215}
216
217impl Writable for (f32, f32, f32, f32) {
218 fn write(&self, output: &mut Vec<f32>) {
219 output.push(self.0);
220 output.push(self.1);
221 output.push(self.2);
222 output.push(self.3);
223 }
224 fn stride() -> usize {
225 4
226 }
227}