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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
use rin_math::{vec2, Vec2, vec3, Vec3, zero};
use color::{Rgba,ToRgba, rgba};
#[cfg(feature="meshopt")]
use meshopt;
#[cfg(any(feature="gl", feature="gles", feature="webgl"))]
use glin::VertexFormat;
#[cfg(feature="serialize")]
use serde_derive::{Serialize, Deserialize};

pub trait Vertex{
    type Position;
    fn position(&self) -> &Self::Position;
    fn position_mut(&mut self) -> &mut Self::Position;
}
pub trait Normal{
    type Normal;
    fn normal(&self) -> &Self::Normal;
    fn normal_mut(&mut self) -> &mut Self::Normal;
}

#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2D{
    pub position: Vec2,
}

pub fn vertex2d(position: Vec2) -> Vertex2D{
    Vertex2D{position: position}
}

impl Default for Vertex2D{
    fn default() -> Vertex2D{
        vertex2d(vec2!(0.))
    }
}

impl Vertex for Vertex2D{
    type Position = Vec2;
    fn position(&self) -> &Vec2 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec2{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3D{
    pub position: Vec3,
}

pub fn vertex3d(position: Vec3) -> Vertex3D{
    Vertex3D{position: position}
}

impl Default for Vertex3D{
    fn default() -> Vertex3D{
        vertex3d(vec3!(0.))
    }
}

impl Vertex for Vertex3D{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DTex{
    pub position: Vec2,
    pub texcoord: Vec2
}

pub fn vertex2dtex(position: Vec2, texcoord: Vec2) -> Vertex2DTex{
    Vertex2DTex{position: position, texcoord: texcoord}
}

impl Default for Vertex2DTex{
    fn default() -> Vertex2DTex{
        vertex2dtex(vec2!(0.), vec2!(0.))
    }
}

impl Vertex for Vertex2DTex{
    type Position = Vec2;
    fn position(&self) -> &Vec2 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec2{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DTex3D{
    pub position: Vec2,
    pub texcoord: Vec3
}

pub fn vertex2dtex3d(position: Vec2, texcoord: Vec3) -> Vertex2DTex3D{
    Vertex2DTex3D{position: position, texcoord: texcoord}
}

impl Default for Vertex2DTex3D{
    fn default() -> Vertex2DTex3D{
        vertex2dtex3d(vec2!(0.), vec3!(0.))
    }
}

impl Vertex for Vertex2DTex3D{
    type Position = Vec2;
    fn position(&self) -> &Vec2 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec2{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DColor{
    pub position: Vec2,
    pub color: Rgba<f32>,
}

pub fn vertex2dcolor<C: ToRgba>(position: Vec2, color: &C) -> Vertex2DColor{
    Vertex2DColor{position: position, color: color.to_rgba().to_standard()}
}

impl Default for Vertex2DColor{
    fn default() -> Vertex2DColor{
        vertex2dcolor(vec2!(0.), &rgba!(1.,1.,1.,1.))
    }
}

impl Vertex for Vertex2DColor{
    type Position = Vec2;
    fn position(&self) -> &Vec2 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec2{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DTexColor{
    pub position: Vec2,
    pub texcoord: Vec2,
    pub color: Rgba<f32>
}

pub fn vertex2dtexcolor<C: ToRgba>(position: Vec2, texcoord: Vec2, color: &C) -> Vertex2DTexColor{
    Vertex2DTexColor{position: position, texcoord: texcoord, color: color.to_rgba().to_standard()}
}

impl Default for Vertex2DTexColor{
    fn default() -> Vertex2DTexColor{
        vertex2dtexcolor(vec2!(0.), vec2!(0.), &rgba!(1.,1.,1.,1.))
    }
}

impl Vertex for Vertex2DTexColor{
    type Position = Vec2;
    fn position(&self) -> &Vec2 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec2{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DTex{
    pub position: Vec3,
    pub texcoord: Vec2,
    pub pad: Vec3
}

pub fn vertex3dtex(position: Vec3, texcoord: Vec2) -> Vertex3DTex{
    Vertex3DTex{position: position, texcoord: texcoord, pad: zero()}
}

impl Default for Vertex3DTex{
    fn default() -> Vertex3DTex{
        vertex3dtex(vec3!(0.), vec2!(0.))
    }
}

impl Vertex for Vertex3DTex{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DColor{
    pub position: Vec3,
    pub color: Rgba<f32>,
    pub pad: f32
}

pub fn vertex3dcolor<C: ToRgba>(position: Vec3, color: &C) -> Vertex3DColor{
    Vertex3DColor{position: position, color: color.to_rgba().to_standard(), pad: 0f32}
}

impl Default for Vertex3DColor{
    fn default() -> Vertex3DColor{
        vertex3dcolor(vec3!(0.), &rgba!(1.,1.,1.,1.))
    }
}

impl Vertex for Vertex3DColor{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DTexNormal{
    pub position: Vec3,
    pub texcoord: Vec2,
    pub normal: Vec3
}

pub fn vertex3dtexnormal(position: Vec3, texcoord: Vec2, normal: Vec3) -> Vertex3DTexNormal{
    Vertex3DTexNormal{position: position, texcoord: texcoord, normal: normal}
}

impl Default for Vertex3DTexNormal{
    fn default() -> Vertex3DTexNormal{
        vertex3dtexnormal(vec3!(0.), vec2!(0.), vec3!(0.))
    }
}

impl Vertex for Vertex3DTexNormal{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}

impl Normal for Vertex3DTexNormal{
    type Normal = Vec3;

    fn normal(&self) -> &Vec3 {
        &self.normal
    }

    fn normal_mut(&mut self) -> &mut Vec3{
        &mut self.normal
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DNormal{
    pub position: Vec3,
    pub normal: Vec3,
}

pub fn vertex3dnormal(position: Vec3, normal: Vec3) -> Vertex3DNormal{
    Vertex3DNormal{position: position, normal: normal }
}

impl Default for Vertex3DNormal{
    fn default() -> Vertex3DNormal{
        vertex3dnormal(vec3!(0.), vec3!(0.))
    }
}

impl Vertex for Vertex3DNormal{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}

impl Normal for Vertex3DNormal{
    type Normal = Vec3;

    fn normal(&self) -> &Vec3 {
        &self.normal
    }

    fn normal_mut(&mut self) -> &mut Vec3{
        &mut self.normal
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DColorNormal{
    pub position: Vec3,
    pub pad0: f32,
    pub color: Rgba<f32>,
    pub normal: Vec3,
    pub pad1: f32,
}

pub fn vertex3dcolornormal<C: ToRgba>(position: Vec3, color: &C, normal: Vec3) -> Vertex3DColorNormal{
    Vertex3DColorNormal{
        position: position,
        pad0: 0.,
        color: color.to_rgba().to_standard(),
        normal: normal,
        pad1: 0.,
    }
}

impl Default for Vertex3DColorNormal{
    fn default() -> Vertex3DColorNormal{
        vertex3dcolornormal(vec3!(0.), &rgba!(1.,1.,1.,1.), vec3!(0.))
    }
}

impl Vertex for Vertex3DColorNormal{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}

impl Normal for Vertex3DColorNormal{
    type Normal = Vec3;

    fn normal(&self) -> &Vec3 {
        &self.normal
    }

    fn normal_mut(&mut self) -> &mut Vec3{
        &mut self.normal
    }
}


#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DTexColor{
    pub position: Vec3,
    pub texcoord: Vec2,
    pub color: Rgba<f32>,
    pub pad: [f32;7]
}

pub fn vertex3dtexcolor<C: ToRgba>(position: Vec3, texcoord: Vec2, color: &C) -> Vertex3DTexColor{
    Vertex3DTexColor{position: position, color: color.to_rgba().to_standard(), texcoord: texcoord, pad: [0f32;7]}
}

impl Default for Vertex3DTexColor{
    fn default() -> Vertex3DTexColor{
        vertex3dtexcolor(vec3!(0.), vec2!(0.), &rgba!(1.,1.,1.,1.))
    }
}

impl Vertex for Vertex3DTexColor{
    type Position = Vec3;
    fn position(&self) -> &Vec3 {
        &self.position
    }

    fn position_mut(&mut self) -> &mut Vec3{
        &mut self.position
    }
}



#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3D{
    fn decode_position(&self) -> [f32;3]{
        [self.position.x, self.position.y, self.position.z]
    }
}

#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DNormal{
    fn decode_position(&self) -> [f32;3]{
        [self.position.x, self.position.y, self.position.z]
    }
}

#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DTexNormal{
    fn decode_position(&self) -> [f32;3]{
        [self.position.x, self.position.y, self.position.z]
    }
}

#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DColor{
    fn decode_position(&self) -> [f32;3]{
        [self.position.x, self.position.y, self.position.z]
    }
}

#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DColorNormal{
    fn decode_position(&self) -> [f32;3]{
        [self.position.x, self.position.y, self.position.z]
    }
}

#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DTexColor{
    fn decode_position(&self) -> [f32;3]{
        [self.position.x, self.position.y, self.position.z]
    }
}