From ee0e4850fd2d869ae7aab7004c759fdbe555dee5 Mon Sep 17 00:00:00 2001 From: bootra-dev Date: Thu, 16 Jul 2020 11:45:48 -0400 Subject: [PATCH 1/2] add size function for VertexFormat --- wgpu-types/src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 6ac0130cf8..3c40ada660 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -941,6 +941,43 @@ pub enum VertexFormat { Int4 = 29, } +impl VertexFormat { + pub fn 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 => 4, + VertexFormat::Ushort4 => 8, + VertexFormat::Short2 => 4, + VertexFormat::Short4 => 8, + VertexFormat::Ushort2Norm => 4, + VertexFormat::Ushort4Norm => 8, + VertexFormat::Short2Norm => 4, + VertexFormat::Short4Norm => 8, + VertexFormat::Half2 => 4, + VertexFormat::Half4 => 8, + VertexFormat::Float => 4, + VertexFormat::Float2 => 8, + VertexFormat::Float3 => 12, + VertexFormat::Float4 => 16, + VertexFormat::Uint => 4, + VertexFormat::Uint2 => 8, + VertexFormat::Uint3 => 12, + VertexFormat::Uint4 => 16, + VertexFormat::Int => 4, + VertexFormat::Int2 => 8, + VertexFormat::Int3 => 12, + VertexFormat::Int4 => 16, + } + } +} + bitflags::bitflags! { /// Different ways that you can use a buffer. /// From 215c9fe75050d574041ad526b4ad378cb6e379d8 Mon Sep 17 00:00:00 2001 From: bootra-dev Date: Thu, 16 Jul 2020 14:00:06 -0400 Subject: [PATCH 2/2] refactor to group by size --- wgpu-types/src/lib.rs | 56 ++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 3c40ada660..7ebb7c4457 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -944,36 +944,32 @@ pub enum VertexFormat { impl VertexFormat { pub fn 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 => 4, - VertexFormat::Ushort4 => 8, - VertexFormat::Short2 => 4, - VertexFormat::Short4 => 8, - VertexFormat::Ushort2Norm => 4, - VertexFormat::Ushort4Norm => 8, - VertexFormat::Short2Norm => 4, - VertexFormat::Short4Norm => 8, - VertexFormat::Half2 => 4, - VertexFormat::Half4 => 8, - VertexFormat::Float => 4, - VertexFormat::Float2 => 8, - VertexFormat::Float3 => 12, - VertexFormat::Float4 => 16, - VertexFormat::Uint => 4, - VertexFormat::Uint2 => 8, - VertexFormat::Uint3 => 12, - VertexFormat::Uint4 => 16, - VertexFormat::Int => 4, - VertexFormat::Int2 => 8, - VertexFormat::Int3 => 12, - VertexFormat::Int4 => 16, + VertexFormat::Uchar2 + | VertexFormat::Char2 + | VertexFormat::Uchar2Norm + | VertexFormat::Char2Norm => 2, + VertexFormat::Uchar4 + | VertexFormat::Char4 + | VertexFormat::Uchar4Norm + | VertexFormat::Char4Norm + | VertexFormat::Ushort2 + | VertexFormat::Short2 + | VertexFormat::Ushort2Norm + | VertexFormat::Short2Norm + | VertexFormat::Half2 + | VertexFormat::Float + | VertexFormat::Uint + | VertexFormat::Int => 4, + VertexFormat::Ushort4 + | VertexFormat::Short4 + | VertexFormat::Ushort4Norm + | VertexFormat::Short4Norm + | VertexFormat::Half4 + | VertexFormat::Float2 + | VertexFormat::Uint2 + | VertexFormat::Int2 => 8, + VertexFormat::Float3 | VertexFormat::Uint3 | VertexFormat::Int3 => 12, + VertexFormat::Float4 | VertexFormat::Uint4 | VertexFormat::Int4 => 16, } } }