From a8b8bc82838ffeda1c65d14e4ecd7873c6b8873f Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Fri, 1 May 2020 18:00:30 +0200 Subject: [PATCH] Implement `From` for `TextureComponentType` --- wgpu-types/src/lib.rs | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index e9463199d..3c197414f 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -934,5 +934,52 @@ pub enum TextureComponentType { Uint, } +impl From for TextureComponentType { + fn from(format: TextureFormat) -> Self { + match format { + TextureFormat::R8Uint + | TextureFormat::R16Uint + | TextureFormat::Rg8Uint + | TextureFormat::R32Uint + | TextureFormat::Rg16Uint + | TextureFormat::Rgba8Uint + | TextureFormat::Rg32Uint + | TextureFormat::Rgba16Uint + | TextureFormat::Rgba32Uint => Self::Uint, + + TextureFormat::R8Sint + | TextureFormat::R16Sint + | TextureFormat::Rg8Sint + | TextureFormat::R32Sint + | TextureFormat::Rg16Sint + | TextureFormat::Rgba8Sint + | TextureFormat::Rg32Sint + | TextureFormat::Rgba16Sint + | TextureFormat::Rgba32Sint => Self::Sint, + + TextureFormat::R8Unorm + | TextureFormat::R8Snorm + | TextureFormat::R16Float + | TextureFormat::R32Float + | TextureFormat::Rg8Unorm + | TextureFormat::Rg8Snorm + | TextureFormat::Rg16Float + | TextureFormat::Rg11b10Float + | TextureFormat::Rg32Float + | TextureFormat::Rgba8Snorm + | TextureFormat::Rgba16Float + | TextureFormat::Rgba32Float + | TextureFormat::Rgba8Unorm + | TextureFormat::Rgba8UnormSrgb + | TextureFormat::Bgra8Unorm + | TextureFormat::Bgra8UnormSrgb + | TextureFormat::Rgb10a2Unorm + | TextureFormat::Depth32Float + | TextureFormat::Depth24Plus + | TextureFormat::Depth24PlusStencil8 => Self::Float, + } + } +} + /// Bound uniform/storage buffer offsets must be aligned to this number. pub const BIND_BUFFER_ALIGNMENT: u64 = 256;