802: adds size function for VertexFormat r=kvark a=bootra-dev

Addresses https://github.com/gfx-rs/wgpu/issues/801

This PR adds a simple size function to the VertexFormat enum. It returns a u64 so that it can be conveniently used with the VertexAttributeDescriptor offset.


Co-authored-by: bootra-dev <bootragames@gmail.com>
This commit is contained in:
bors[bot]
2020-07-16 19:23:14 +00:00
committed by GitHub

View File

@@ -941,6 +941,39 @@ pub enum VertexFormat {
Int4 = 29,
}
impl VertexFormat {
pub fn size(&self) -> u64 {
match self {
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,
}
}
}
bitflags::bitflags! {
/// Different ways that you can use a buffer.
///