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
use crate::Color; use bevy_math::{Mat4, Vec2, Vec3, Vec4}; #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum VertexFormat { Uchar2 = 1, Uchar4 = 3, Char2 = 5, Char4 = 7, Uchar2Norm = 9, Uchar4Norm = 11, Char2Norm = 14, Char4Norm = 16, Ushort2 = 18, Ushort4 = 20, Short2 = 22, Short4 = 24, Ushort2Norm = 26, Ushort4Norm = 28, Short2Norm = 30, Short4Norm = 32, Half2 = 34, Half4 = 36, Float = 37, Float2 = 38, Float3 = 39, Float4 = 40, Uint = 41, Uint2 = 42, Uint3 = 43, Uint4 = 44, Int = 45, Int2 = 46, Int3 = 47, Int4 = 48, } impl VertexFormat { pub fn get_size(&self) -> u64 { match *self { VertexFormat::Uchar2 => 2, VertexFormat::Uchar4 => 4, VertexFormat::Char2 => 2, VertexFormat::Char4 => 4, VertexFormat::Uchar2Norm => 2, VertexFormat::Uchar4Norm => 4, VertexFormat::Char2Norm => 2, VertexFormat::Char4Norm => 4, VertexFormat::Ushort2 => 2 * 2, VertexFormat::Ushort4 => 2 * 4, VertexFormat::Short2 => 2 * 2, VertexFormat::Short4 => 2 * 4, VertexFormat::Ushort2Norm => 2 * 2, VertexFormat::Ushort4Norm => 2 * 4, VertexFormat::Short2Norm => 2 * 2, VertexFormat::Short4Norm => 2 * 4, VertexFormat::Half2 => 2 * 2, VertexFormat::Half4 => 2 * 4, VertexFormat::Float => 4, VertexFormat::Float2 => 4 * 2, VertexFormat::Float3 => 4 * 3, VertexFormat::Float4 => 4 * 4, VertexFormat::Uint => 4, VertexFormat::Uint2 => 4 * 2, VertexFormat::Uint3 => 4 * 3, VertexFormat::Uint4 => 4 * 4, VertexFormat::Int => 4, VertexFormat::Int2 => 4 * 2, VertexFormat::Int3 => 4 * 3, VertexFormat::Int4 => 4 * 4, } } } pub trait AsVertexFormats { fn as_vertex_formats() -> &'static [VertexFormat]; } impl AsVertexFormats for f32 { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float] } } impl AsVertexFormats for Vec2 { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float2] } } impl AsVertexFormats for Vec3 { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float3] } } impl AsVertexFormats for Vec4 { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float4] } } impl AsVertexFormats for Mat4 { fn as_vertex_formats() -> &'static [VertexFormat] { &[ VertexFormat::Float4, VertexFormat::Float4, VertexFormat::Float4, VertexFormat::Float4, ] } } impl AsVertexFormats for Color { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float4] } } impl AsVertexFormats for [f32; 2] { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float2] } } impl AsVertexFormats for [f32; 3] { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float3] } } impl AsVertexFormats for [f32; 4] { fn as_vertex_formats() -> &'static [VertexFormat] { &[VertexFormat::Float4] } }