diff --git a/Cargo.lock b/Cargo.lock index 5e2ac814c2..1032d6ddfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1688,9 +1688,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -2320,6 +2320,7 @@ dependencies = [ "bitflags", "bitflags_serde_shim", "serde", + "serde_json", ] [[package]] diff --git a/player/tests/data/clear-buffer-texture.ron b/player/tests/data/clear-buffer-texture.ron index 023164282f..7d32a688e7 100644 --- a/player/tests/data/clear-buffer-texture.ron +++ b/player/tests/data/clear-buffer-texture.ron @@ -29,7 +29,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 27, )), // First fill the texture to ensure it wasn't just zero initialized or "happened" to be zero. diff --git a/player/tests/data/quad.ron b/player/tests/data/quad.ron index 11b6378300..1f7cb266f4 100644 --- a/player/tests/data/quad.ron +++ b/player/tests/data/quad.ron @@ -26,7 +26,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 27, )), CreateTextureView( @@ -67,7 +67,7 @@ ), targets: [ Some(( - format: rgba8unorm, + format: "rgba8unorm", )), ], )), @@ -129,4 +129,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/player/tests/data/zero-init-texture-binding.ron b/player/tests/data/zero-init-texture-binding.ron index f1e51396f4..c6f8c40a53 100644 --- a/player/tests/data/zero-init-texture-binding.ron +++ b/player/tests/data/zero-init-texture-binding.ron @@ -26,7 +26,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 5, // SAMPLED + COPY_SRC )), CreateTextureView( @@ -52,7 +52,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 9, // STORAGE + COPY_SRC )), CreateTextureView( @@ -89,7 +89,7 @@ visibility: 4, // COMPUTE ty: StorageTexture ( access: r#write-only, - format: rgba8unorm, + format: "rgba8unorm", view_dimension: r#2d, ), count: None, @@ -194,4 +194,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/player/tests/data/zero-init-texture-copytobuffer.ron b/player/tests/data/zero-init-texture-copytobuffer.ron index 684272140f..e3f72f1a08 100644 --- a/player/tests/data/zero-init-texture-copytobuffer.ron +++ b/player/tests/data/zero-init-texture-copytobuffer.ron @@ -19,7 +19,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 1, // COPY_SRC )), CreateBuffer( @@ -53,4 +53,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/player/tests/data/zero-init-texture-rendertarget.ron b/player/tests/data/zero-init-texture-rendertarget.ron index 4239acc6aa..5741c7c33c 100644 --- a/player/tests/data/zero-init-texture-rendertarget.ron +++ b/player/tests/data/zero-init-texture-rendertarget.ron @@ -19,7 +19,7 @@ mip_level_count: 1, sample_count: 1, dimension: r#2d, - format: rgba8unorm, + format: "rgba8unorm", usage: 17, // RENDER_ATTACHMENT + COPY_SRC )), CreateTextureView( @@ -82,4 +82,4 @@ ), ]), ], -) \ No newline at end of file +) diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 2712a884ec..eed39e7c1d 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -19,3 +19,6 @@ replay = ["serde", "bitflags_serde_shim"] bitflags = "1.0" serde = { version = "1.0", features = ["serde_derive"], optional = true } bitflags_serde_shim = { version = "0.2", optional = true } + +[dev-dependencies] +serde_json = "1.0.85" diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 3026053f17..46fe905fa2 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1770,176 +1770,127 @@ pub enum AstcChannel { /// https://gpuweb.github.io/gpuweb/#enumdef-gputextureformat). #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] pub enum TextureFormat { // Normal 8 bit formats /// Red channel only. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8unorm"))] R8Unorm, /// Red channel only. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8snorm"))] R8Snorm, /// Red channel only. 8 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8uint"))] R8Uint, /// Red channel only. 8 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "r8sint"))] R8Sint, // Normal 16 bit formats /// Red channel only. 16 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "r16uint"))] R16Uint, /// Red channel only. 16 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "r16sint"))] R16Sint, /// Red channel only. 16 bit integer per channel. [0, 65535] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "r16unorm"))] R16Unorm, /// Red channel only. 16 bit integer per channel. [0, 65535] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "r16snorm"))] R16Snorm, /// Red channel only. 16 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "r16float"))] R16Float, /// Red and green channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8unorm"))] Rg8Unorm, /// Red and green channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8snorm"))] Rg8Snorm, /// Red and green channels. 8 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8uint"))] Rg8Uint, /// Red and green channels. 8 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg8sint"))] Rg8Sint, // Normal 32 bit formats /// Red channel only. 32 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "r32uint"))] R32Uint, /// Red channel only. 32 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "r32sint"))] R32Sint, /// Red channel only. 32 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "r32float"))] R32Float, /// Red and green channels. 16 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg16uint"))] Rg16Uint, /// Red and green channels. 16 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg16sint"))] Rg16Sint, /// Red and green channels. 16 bit integer per channel. [0, 65535] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rg16unorm"))] Rg16Unorm, /// Red and green channels. 16 bit integer per channel. [0, 65535] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rg16snorm"))] Rg16Snorm, /// Red and green channels. 16 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg16float"))] Rg16Float, /// Red, green, blue, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8unorm"))] Rgba8Unorm, /// Red, green, blue, and alpha channels. 8 bit integer per channel. Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8unorm-srgb"))] Rgba8UnormSrgb, /// Red, green, blue, and alpha channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8snorm"))] Rgba8Snorm, /// Red, green, blue, and alpha channels. 8 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8uint"))] Rgba8Uint, /// Red, green, blue, and alpha channels. 8 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba8sint"))] Rgba8Sint, /// Blue, green, red, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "bgra8unorm"))] Bgra8Unorm, /// Blue, green, red, and alpha channels. 8 bit integer per channel. Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "bgra8unorm-srgb"))] Bgra8UnormSrgb, // Packed 32 bit formats /// Packed unsigned float with 9 bits mantisa for each RGB component, then a common 5 bits exponent - #[cfg_attr(feature = "serde", serde(rename = "rgb9e5ufloat"))] Rgb9e5Ufloat, /// Red, green, blue, and alpha channels. 10 bit integer for RGB channels, 2 bit integer for alpha channel. [0, 1023] ([0, 3] for alpha) converted to/from float [0, 1] in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgb10a2unorm"))] Rgb10a2Unorm, /// Red, green, and blue channels. 11 bit float with no sign bit for RG channels. 10 bit float with no sign bit for blue channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg11b10ufloat"))] Rg11b10Float, // Normal 64 bit formats /// Red and green channels. 32 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg32uint"))] Rg32Uint, /// Red and green channels. 32 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg32sint"))] Rg32Sint, /// Red and green channels. 32 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rg32float"))] Rg32Float, /// Red, green, blue, and alpha channels. 16 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba16uint"))] Rgba16Uint, /// Red, green, blue, and alpha channels. 16 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba16sint"))] Rgba16Sint, /// Red, green, blue, and alpha channels. 16 bit integer per channel. [0, 65535] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rgba16unorm"))] Rgba16Unorm, /// Red, green, blue, and alpha. 16 bit integer per channel. [0, 65535] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_FORMAT_16BIT_NORM`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "rgba16snorm"))] Rgba16Snorm, /// Red, green, blue, and alpha channels. 16 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba16float"))] Rgba16Float, // Normal 128 bit formats /// Red, green, blue, and alpha channels. 32 bit integer per channel. Unsigned in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba32uint"))] Rgba32Uint, /// Red, green, blue, and alpha channels. 32 bit integer per channel. Signed in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba32sint"))] Rgba32Sint, /// Red, green, blue, and alpha channels. 32 bit float per channel. Float in shader. - #[cfg_attr(feature = "serde", serde(rename = "rgba32float"))] Rgba32Float, // Depth and stencil formats /// Stencil format with 8 bit integer stencil. - //#[cfg_attr(feature = "serde", serde(rename = "stencil8"))] //Stencil8, /// Special depth format with 16 bit integer depth. - #[cfg_attr(feature = "serde", serde(rename = "depth16unorm"))] Depth16Unorm, /// Special depth format with at least 24 bit integer depth. - #[cfg_attr(feature = "serde", serde(rename = "depth24plus"))] Depth24Plus, /// Special depth/stencil format with at least 24 bit integer depth and 8 bits integer stencil. - #[cfg_attr(feature = "serde", serde(rename = "depth24plus-stencil8"))] Depth24PlusStencil8, /// Special depth format with 32 bit floating point depth. - #[cfg_attr(feature = "serde", serde(rename = "depth32float"))] Depth32Float, /// Special depth/stencil format with 32 bit floating point depth and 8 bits integer stencil. - #[cfg_attr(feature = "serde", serde(rename = "depth32float-stencil8"))] Depth32FloatStencil8, // Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. @@ -1949,7 +1900,6 @@ pub enum TextureFormat { /// Also known as DXT1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc1-rgba-unorm"))] Bc1RgbaUnorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 4 color + alpha pallet. 5 bit R + 6 bit G + 5 bit B + 1 bit alpha. /// Srgb-color [0, 63] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -1957,7 +1907,6 @@ pub enum TextureFormat { /// Also known as DXT1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc1-rgba-unorm-srgb"))] Bc1RgbaUnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet. 5 bit R + 6 bit G + 5 bit B + 4 bit alpha. /// [0, 63] ([0, 15] for alpha) converted to/from float [0, 1] in shader. @@ -1965,7 +1914,6 @@ pub enum TextureFormat { /// Also known as DXT3. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc2-rgba-unorm"))] Bc2RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet. 5 bit R + 6 bit G + 5 bit B + 4 bit alpha. /// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -1973,7 +1921,6 @@ pub enum TextureFormat { /// Also known as DXT3. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc2-rgba-unorm-srgb"))] Bc2RgbaUnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet + 8 alpha pallet. 5 bit R + 6 bit G + 5 bit B + 8 bit alpha. /// [0, 63] ([0, 255] for alpha) converted to/from float [0, 1] in shader. @@ -1981,7 +1928,6 @@ pub enum TextureFormat { /// Also known as DXT5. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc3-rgba-unorm"))] Bc3RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet + 8 alpha pallet. 5 bit R + 6 bit G + 5 bit B + 8 bit alpha. /// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -1989,7 +1935,6 @@ pub enum TextureFormat { /// Also known as DXT5. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc3-rgba-unorm-srgb"))] Bc3RgbaUnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R. /// [0, 255] converted to/from float [0, 1] in shader. @@ -1997,7 +1942,6 @@ pub enum TextureFormat { /// Also known as RGTC1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc4-r-unorm"))] Bc4RUnorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R. /// [-127, 127] converted to/from float [-1, 1] in shader. @@ -2005,7 +1949,6 @@ pub enum TextureFormat { /// Also known as RGTC1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc4-r-snorm"))] Bc4RSnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG. /// [0, 255] converted to/from float [0, 1] in shader. @@ -2013,7 +1956,6 @@ pub enum TextureFormat { /// Also known as RGTC2. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc5-rg-unorm"))] Bc5RgUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG. /// [-127, 127] converted to/from float [-1, 1] in shader. @@ -2021,21 +1963,18 @@ pub enum TextureFormat { /// Also known as RGTC2. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc5-rg-snorm"))] Bc5RgSnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit unsigned float RGB. Float in shader. /// /// Also known as BPTC (float). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc6h-rgb-ufloat"))] Bc6hRgbUfloat, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit signed float RGB. Float in shader. /// /// Also known as BPTC (float). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc6h-rgb-float"))] Bc6hRgbSfloat, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA. /// [0, 255] converted to/from float [0, 1] in shader. @@ -2043,7 +1982,6 @@ pub enum TextureFormat { /// Also known as BPTC (unorm). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc7-rgba-unorm"))] Bc7RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. @@ -2051,67 +1989,56 @@ pub enum TextureFormat { /// Also known as BPTC (unorm). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "bc7-rgba-unorm-srgb"))] Bc7RgbaUnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8unorm"))] Etc2Rgb8Unorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8unorm-srgb"))] Etc2Rgb8UnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB + 1 bit alpha. /// [0, 255] ([0, 1] for alpha) converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8a1unorm"))] Etc2Rgb8A1Unorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB + 1 bit alpha. /// Srgb-color [0, 255] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgb8a1unorm-srgb"))] Etc2Rgb8A1UnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGB + 8 bit alpha. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgba8unorm"))] Etc2Rgba8Unorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 8 bit integer RGB + 8 bit alpha. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "etc2-rgba8unorm-srgb"))] Etc2Rgba8UnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 11 bit integer R. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-r11unorm"))] EacR11Unorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 11 bit integer R. /// [-127, 127] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-r11snorm"))] EacR11Snorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 11 bit integer R + 11 bit integer G. /// [0, 255] converted to/from float [0, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-rg11unorm"))] EacRg11Unorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Complex pallet. 11 bit integer R + 11 bit integer G. /// [-127, 127] converted to/from float [-1, 1] in shader. /// /// [`Features::TEXTURE_COMPRESSION_ETC2`] must be enabled to use this texture format. - #[cfg_attr(feature = "serde", serde(rename = "eac-rg11snorm"))] EacRg11Snorm, /// block compressed texture. 16 bytes per block. /// @@ -2128,6 +2055,253 @@ pub enum TextureFormat { }, } +#[cfg(feature = "serde")] +impl<'de> Deserialize<'de> for TextureFormat { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + use serde::de::{self, Error, Unexpected}; + + struct TextureFormatVisitor; + + impl<'de> de::Visitor<'de> for TextureFormatVisitor { + type Value = TextureFormat; + + fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + formatter.write_str("a valid texture format") + } + + fn visit_str(self, s: &str) -> Result { + let format = match s { + "r8unorm" => TextureFormat::R8Unorm, + "r8snorm" => TextureFormat::R8Snorm, + "r8uint" => TextureFormat::R8Uint, + "r8sint" => TextureFormat::R8Sint, + "r16uint" => TextureFormat::R16Uint, + "r16sint" => TextureFormat::R16Sint, + "r16unorm" => TextureFormat::R16Unorm, + "r16snorm" => TextureFormat::R16Snorm, + "r16float" => TextureFormat::R16Float, + "rg8unorm" => TextureFormat::Rg8Unorm, + "rg8snorm" => TextureFormat::Rg8Snorm, + "rg8uint" => TextureFormat::Rg8Uint, + "rg8sint" => TextureFormat::Rg8Sint, + "r32uint" => TextureFormat::R32Uint, + "r32sint" => TextureFormat::R32Sint, + "r32float" => TextureFormat::R32Float, + "rg16uint" => TextureFormat::Rg16Uint, + "rg16sint" => TextureFormat::Rg16Sint, + "rg16unorm" => TextureFormat::Rg16Unorm, + "rg16snorm" => TextureFormat::Rg16Snorm, + "rg16float" => TextureFormat::Rg16Float, + "rgba8unorm" => TextureFormat::Rgba8Unorm, + "rgba8unorm-srgb" => TextureFormat::Rgba8UnormSrgb, + "rgba8snorm" => TextureFormat::Rgba8Snorm, + "rgba8uint" => TextureFormat::Rgba8Uint, + "rgba8sint" => TextureFormat::Rgba8Sint, + "bgra8unorm" => TextureFormat::Bgra8Unorm, + "bgra8unorm-srgb" => TextureFormat::Bgra8UnormSrgb, + "rgb10a2unorm" => TextureFormat::Rgb10a2Unorm, + "rg11b10ufloat" => TextureFormat::Rg11b10Float, + "rg32uint" => TextureFormat::Rg32Uint, + "rg32sint" => TextureFormat::Rg32Sint, + "rg32float" => TextureFormat::Rg32Float, + "rgba16uint" => TextureFormat::Rgba16Uint, + "rgba16sint" => TextureFormat::Rgba16Sint, + "rgba16unorm" => TextureFormat::Rgba16Unorm, + "rgba16snorm" => TextureFormat::Rgba16Snorm, + "rgba16float" => TextureFormat::Rgba16Float, + "rgba32uint" => TextureFormat::Rgba32Uint, + "rgba32sint" => TextureFormat::Rgba32Sint, + "rgba32float" => TextureFormat::Rgba32Float, + "depth32float" => TextureFormat::Depth32Float, + "depth32float-stencil8" => TextureFormat::Depth32FloatStencil8, + "depth16unorm" => TextureFormat::Depth16Unorm, + "depth24plus" => TextureFormat::Depth24Plus, + "depth24plus-stencil8" => TextureFormat::Depth24PlusStencil8, + "rgb9e5ufloat" => TextureFormat::Rgb9e5Ufloat, + "bc1-rgba-unorm" => TextureFormat::Bc1RgbaUnorm, + "bc1-rgba-unorm-srgb" => TextureFormat::Bc1RgbaUnormSrgb, + "bc2-rgba-unorm" => TextureFormat::Bc2RgbaUnorm, + "bc2-rgba-unorm-srgb" => TextureFormat::Bc2RgbaUnormSrgb, + "bc3-rgba-unorm" => TextureFormat::Bc3RgbaUnorm, + "bc3-rgba-unorm-srgb" => TextureFormat::Bc3RgbaUnormSrgb, + "bc4-r-unorm" => TextureFormat::Bc4RUnorm, + "bc4-r-snorm" => TextureFormat::Bc4RSnorm, + "bc5-rg-unorm" => TextureFormat::Bc5RgUnorm, + "bc5-rg-snorm" => TextureFormat::Bc5RgSnorm, + "bc6h-rgb-ufloat" => TextureFormat::Bc6hRgbUfloat, + "bc6h-rgb-float" => TextureFormat::Bc6hRgbSfloat, + "bc7-rgba-unorm" => TextureFormat::Bc7RgbaUnorm, + "bc7-rgba-unorm-srgb" => TextureFormat::Bc7RgbaUnormSrgb, + "etc2-rgb8unorm" => TextureFormat::Etc2Rgb8Unorm, + "etc2-rgb8unorm-srgb" => TextureFormat::Etc2Rgb8UnormSrgb, + "etc2-rgb8a1unorm" => TextureFormat::Etc2Rgb8A1Unorm, + "etc2-rgb8a1unorm-srgb" => TextureFormat::Etc2Rgb8A1UnormSrgb, + "etc2-rgba8unorm" => TextureFormat::Etc2Rgba8Unorm, + "etc2-rgba8unorm-srgb" => TextureFormat::Etc2Rgba8UnormSrgb, + "eac-r11unorm" => TextureFormat::EacR11Unorm, + "eac-r11snorm" => TextureFormat::EacR11Snorm, + "eac-rg11unorm" => TextureFormat::EacRg11Unorm, + "eac-rg11snorm" => TextureFormat::EacRg11Snorm, + other => { + if let Some(parts) = other.strip_prefix("astc-") { + let (block, channel) = parts + .split_once('-') + .ok_or_else(|| E::invalid_value(Unexpected::Str(s), &self))?; + + let block = match block { + "4x4" => AstcBlock::B4x4, + "5x4" => AstcBlock::B5x4, + "5x5" => AstcBlock::B5x5, + "6x5" => AstcBlock::B6x5, + "6x6" => AstcBlock::B6x6, + "8x5" => AstcBlock::B8x5, + "8x6" => AstcBlock::B8x6, + "8x8" => AstcBlock::B8x8, + "10x5" => AstcBlock::B10x5, + "10x6" => AstcBlock::B10x6, + "10x8" => AstcBlock::B10x8, + "10x10" => AstcBlock::B10x10, + "12x10" => AstcBlock::B12x10, + "12x12" => AstcBlock::B12x12, + _ => return Err(E::invalid_value(Unexpected::Str(s), &self)), + }; + + let channel = match channel { + "unorm" => AstcChannel::Unorm, + "unorm-srgb" => AstcChannel::UnormSrgb, + "hdr" => AstcChannel::Hdr, + _ => return Err(E::invalid_value(Unexpected::Str(s), &self)), + }; + + TextureFormat::Astc { block, channel } + } else { + return Err(E::invalid_value(Unexpected::Str(s), &self)); + } + } + }; + + Ok(format) + } + } + + deserializer.deserialize_str(TextureFormatVisitor) + } +} + +#[cfg(feature = "serde")] +impl Serialize for TextureFormat { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + let s: String; + let name = match *self { + TextureFormat::R8Unorm => "r8unorm", + TextureFormat::R8Snorm => "r8snorm", + TextureFormat::R8Uint => "r8uint", + TextureFormat::R8Sint => "r8sint", + TextureFormat::R16Uint => "r16uint", + TextureFormat::R16Sint => "r16sint", + TextureFormat::R16Unorm => "r16unorm", + TextureFormat::R16Snorm => "r16snorm", + TextureFormat::R16Float => "r16float", + TextureFormat::Rg8Unorm => "rg8unorm", + TextureFormat::Rg8Snorm => "rg8snorm", + TextureFormat::Rg8Uint => "rg8uint", + TextureFormat::Rg8Sint => "rg8sint", + TextureFormat::R32Uint => "r32uint", + TextureFormat::R32Sint => "r32sint", + TextureFormat::R32Float => "r32float", + TextureFormat::Rg16Uint => "rg16uint", + TextureFormat::Rg16Sint => "rg16sint", + TextureFormat::Rg16Unorm => "rg16unorm", + TextureFormat::Rg16Snorm => "rg16snorm", + TextureFormat::Rg16Float => "rg16float", + TextureFormat::Rgba8Unorm => "rgba8unorm", + TextureFormat::Rgba8UnormSrgb => "rgba8unorm-srgb", + TextureFormat::Rgba8Snorm => "rgba8snorm", + TextureFormat::Rgba8Uint => "rgba8uint", + TextureFormat::Rgba8Sint => "rgba8sint", + TextureFormat::Bgra8Unorm => "bgra8unorm", + TextureFormat::Bgra8UnormSrgb => "bgra8unorm-srgb", + TextureFormat::Rgb10a2Unorm => "rgb10a2unorm", + TextureFormat::Rg11b10Float => "rg11b10ufloat", + TextureFormat::Rg32Uint => "rg32uint", + TextureFormat::Rg32Sint => "rg32sint", + TextureFormat::Rg32Float => "rg32float", + TextureFormat::Rgba16Uint => "rgba16uint", + TextureFormat::Rgba16Sint => "rgba16sint", + TextureFormat::Rgba16Unorm => "rgba16unorm", + TextureFormat::Rgba16Snorm => "rgba16snorm", + TextureFormat::Rgba16Float => "rgba16float", + TextureFormat::Rgba32Uint => "rgba32uint", + TextureFormat::Rgba32Sint => "rgba32sint", + TextureFormat::Rgba32Float => "rgba32float", + TextureFormat::Depth32Float => "depth32float", + TextureFormat::Depth16Unorm => "depth16unorm", + TextureFormat::Depth32FloatStencil8 => "depth32float-stencil8", + TextureFormat::Depth24Plus => "depth24plus", + TextureFormat::Depth24PlusStencil8 => "depth24plus-stencil8", + TextureFormat::Rgb9e5Ufloat => "rgb9e5ufloat", + TextureFormat::Bc1RgbaUnorm => "bc1-rgba-unorm", + TextureFormat::Bc1RgbaUnormSrgb => "bc1-rgba-unorm-srgb", + TextureFormat::Bc2RgbaUnorm => "bc2-rgba-unorm", + TextureFormat::Bc2RgbaUnormSrgb => "bc2-rgba-unorm-srgb", + TextureFormat::Bc3RgbaUnorm => "bc3-rgba-unorm", + TextureFormat::Bc3RgbaUnormSrgb => "bc3-rgba-unorm-srgb", + TextureFormat::Bc4RUnorm => "bc4-r-unorm", + TextureFormat::Bc4RSnorm => "bc4-r-snorm", + TextureFormat::Bc5RgUnorm => "bc5-rg-unorm", + TextureFormat::Bc5RgSnorm => "bc5-rg-snorm", + TextureFormat::Bc6hRgbUfloat => "bc6h-rgb-ufloat", + TextureFormat::Bc6hRgbSfloat => "bc6h-rgb-float", + TextureFormat::Bc7RgbaUnorm => "bc7-rgba-unorm", + TextureFormat::Bc7RgbaUnormSrgb => "bc7-rgba-unorm-srgb", + TextureFormat::Etc2Rgb8Unorm => "etc2-rgb8unorm", + TextureFormat::Etc2Rgb8UnormSrgb => "etc2-rgb8unorm-srgb", + TextureFormat::Etc2Rgb8A1Unorm => "etc2-rgb8a1unorm", + TextureFormat::Etc2Rgb8A1UnormSrgb => "etc2-rgb8a1unorm-srgb", + TextureFormat::Etc2Rgba8Unorm => "etc2-rgba8unorm", + TextureFormat::Etc2Rgba8UnormSrgb => "etc2-rgba8unorm-srgb", + TextureFormat::EacR11Unorm => "eac-r11unorm", + TextureFormat::EacR11Snorm => "eac-r11snorm", + TextureFormat::EacRg11Unorm => "eac-rg11unorm", + TextureFormat::EacRg11Snorm => "eac-rg11snorm", + TextureFormat::Astc { block, channel } => { + let block = match block { + AstcBlock::B4x4 => "4x4", + AstcBlock::B5x4 => "5x4", + AstcBlock::B5x5 => "5x5", + AstcBlock::B6x5 => "6x5", + AstcBlock::B6x6 => "6x6", + AstcBlock::B8x5 => "8x5", + AstcBlock::B8x6 => "8x6", + AstcBlock::B8x8 => "8x8", + AstcBlock::B10x5 => "10x5", + AstcBlock::B10x6 => "10x6", + AstcBlock::B10x8 => "10x8", + AstcBlock::B10x10 => "10x10", + AstcBlock::B12x10 => "12x10", + AstcBlock::B12x12 => "12x12", + }; + + let channel = match channel { + AstcChannel::Unorm => "unorm", + AstcChannel::UnormSrgb => "unorm-srgb", + AstcChannel::Hdr => "hdr", + }; + + s = format!("astc-{block}-{channel}"); + &s + } + }; + serializer.serialize_str(name) + } +} + impl TextureFormat { /// Get useful information about the texture format. pub fn describe(&self) -> TextureFormatInfo { @@ -2315,6 +2489,582 @@ impl TextureFormat { } } +#[test] +fn texture_format_serialize() { + assert_eq!( + serde_json::to_string(&TextureFormat::R8Unorm).unwrap(), + "\"r8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R8Snorm).unwrap(), + "\"r8snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R8Uint).unwrap(), + "\"r8uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R8Sint).unwrap(), + "\"r8sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Uint).unwrap(), + "\"r16uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Sint).unwrap(), + "\"r16sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Unorm).unwrap(), + "\"r16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Snorm).unwrap(), + "\"r16snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R16Float).unwrap(), + "\"r16float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Unorm).unwrap(), + "\"rg8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Snorm).unwrap(), + "\"rg8snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Uint).unwrap(), + "\"rg8uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg8Sint).unwrap(), + "\"rg8sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R32Uint).unwrap(), + "\"r32uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R32Sint).unwrap(), + "\"r32sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::R32Float).unwrap(), + "\"r32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Uint).unwrap(), + "\"rg16uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Sint).unwrap(), + "\"rg16sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Unorm).unwrap(), + "\"rg16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Snorm).unwrap(), + "\"rg16snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg16Float).unwrap(), + "\"rg16float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Unorm).unwrap(), + "\"rgba8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8UnormSrgb).unwrap(), + "\"rgba8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Snorm).unwrap(), + "\"rgba8snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Uint).unwrap(), + "\"rgba8uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba8Sint).unwrap(), + "\"rgba8sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bgra8Unorm).unwrap(), + "\"bgra8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bgra8UnormSrgb).unwrap(), + "\"bgra8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgb10a2Unorm).unwrap(), + "\"rgb10a2unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg11b10Float).unwrap(), + "\"rg11b10ufloat\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg32Uint).unwrap(), + "\"rg32uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg32Sint).unwrap(), + "\"rg32sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rg32Float).unwrap(), + "\"rg32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Uint).unwrap(), + "\"rgba16uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Sint).unwrap(), + "\"rgba16sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Unorm).unwrap(), + "\"rgba16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Snorm).unwrap(), + "\"rgba16snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba16Float).unwrap(), + "\"rgba16float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba32Uint).unwrap(), + "\"rgba32uint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba32Sint).unwrap(), + "\"rgba32sint\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgba32Float).unwrap(), + "\"rgba32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth32Float).unwrap(), + "\"depth32float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth16Unorm).unwrap(), + "\"depth16unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth32FloatStencil8).unwrap(), + "\"depth32float-stencil8\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth24Plus).unwrap(), + "\"depth24plus\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Depth24PlusStencil8).unwrap(), + "\"depth24plus-stencil8\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Rgb9e5Ufloat).unwrap(), + "\"rgb9e5ufloat\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc1RgbaUnorm).unwrap(), + "\"bc1-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc1RgbaUnormSrgb).unwrap(), + "\"bc1-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc2RgbaUnorm).unwrap(), + "\"bc2-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc2RgbaUnormSrgb).unwrap(), + "\"bc2-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc3RgbaUnorm).unwrap(), + "\"bc3-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc3RgbaUnormSrgb).unwrap(), + "\"bc3-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc4RUnorm).unwrap(), + "\"bc4-r-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc4RSnorm).unwrap(), + "\"bc4-r-snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc5RgUnorm).unwrap(), + "\"bc5-rg-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc5RgSnorm).unwrap(), + "\"bc5-rg-snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc6hRgbUfloat).unwrap(), + "\"bc6h-rgb-ufloat\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc6hRgbSfloat).unwrap(), + "\"bc6h-rgb-float\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc7RgbaUnorm).unwrap(), + "\"bc7-rgba-unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Bc7RgbaUnormSrgb).unwrap(), + "\"bc7-rgba-unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8Unorm).unwrap(), + "\"etc2-rgb8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8UnormSrgb).unwrap(), + "\"etc2-rgb8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8A1Unorm).unwrap(), + "\"etc2-rgb8a1unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgb8A1UnormSrgb).unwrap(), + "\"etc2-rgb8a1unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgba8Unorm).unwrap(), + "\"etc2-rgba8unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::Etc2Rgba8UnormSrgb).unwrap(), + "\"etc2-rgba8unorm-srgb\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacR11Unorm).unwrap(), + "\"eac-r11unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacR11Snorm).unwrap(), + "\"eac-r11snorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacRg11Unorm).unwrap(), + "\"eac-rg11unorm\"".to_string() + ); + assert_eq!( + serde_json::to_string(&TextureFormat::EacRg11Snorm).unwrap(), + "\"eac-rg11snorm\"".to_string() + ); +} + +#[test] +fn texture_format_deserialize() { + assert_eq!( + serde_json::from_str::("\"r8unorm\"").unwrap(), + TextureFormat::R8Unorm + ); + assert_eq!( + serde_json::from_str::("\"r8snorm\"").unwrap(), + TextureFormat::R8Snorm + ); + assert_eq!( + serde_json::from_str::("\"r8uint\"").unwrap(), + TextureFormat::R8Uint + ); + assert_eq!( + serde_json::from_str::("\"r8sint\"").unwrap(), + TextureFormat::R8Sint + ); + assert_eq!( + serde_json::from_str::("\"r16uint\"").unwrap(), + TextureFormat::R16Uint + ); + assert_eq!( + serde_json::from_str::("\"r16sint\"").unwrap(), + TextureFormat::R16Sint + ); + assert_eq!( + serde_json::from_str::("\"r16unorm\"").unwrap(), + TextureFormat::R16Unorm + ); + assert_eq!( + serde_json::from_str::("\"r16snorm\"").unwrap(), + TextureFormat::R16Snorm + ); + assert_eq!( + serde_json::from_str::("\"r16float\"").unwrap(), + TextureFormat::R16Float + ); + assert_eq!( + serde_json::from_str::("\"rg8unorm\"").unwrap(), + TextureFormat::Rg8Unorm + ); + assert_eq!( + serde_json::from_str::("\"rg8snorm\"").unwrap(), + TextureFormat::Rg8Snorm + ); + assert_eq!( + serde_json::from_str::("\"rg8uint\"").unwrap(), + TextureFormat::Rg8Uint + ); + assert_eq!( + serde_json::from_str::("\"rg8sint\"").unwrap(), + TextureFormat::Rg8Sint + ); + assert_eq!( + serde_json::from_str::("\"r32uint\"").unwrap(), + TextureFormat::R32Uint + ); + assert_eq!( + serde_json::from_str::("\"r32sint\"").unwrap(), + TextureFormat::R32Sint + ); + assert_eq!( + serde_json::from_str::("\"r32float\"").unwrap(), + TextureFormat::R32Float + ); + assert_eq!( + serde_json::from_str::("\"rg16uint\"").unwrap(), + TextureFormat::Rg16Uint + ); + assert_eq!( + serde_json::from_str::("\"rg16sint\"").unwrap(), + TextureFormat::Rg16Sint + ); + assert_eq!( + serde_json::from_str::("\"rg16unorm\"").unwrap(), + TextureFormat::Rg16Unorm + ); + assert_eq!( + serde_json::from_str::("\"rg16snorm\"").unwrap(), + TextureFormat::Rg16Snorm + ); + assert_eq!( + serde_json::from_str::("\"rg16float\"").unwrap(), + TextureFormat::Rg16Float + ); + assert_eq!( + serde_json::from_str::("\"rgba8unorm\"").unwrap(), + TextureFormat::Rgba8Unorm + ); + assert_eq!( + serde_json::from_str::("\"rgba8unorm-srgb\"").unwrap(), + TextureFormat::Rgba8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"rgba8snorm\"").unwrap(), + TextureFormat::Rgba8Snorm + ); + assert_eq!( + serde_json::from_str::("\"rgba8uint\"").unwrap(), + TextureFormat::Rgba8Uint + ); + assert_eq!( + serde_json::from_str::("\"rgba8sint\"").unwrap(), + TextureFormat::Rgba8Sint + ); + assert_eq!( + serde_json::from_str::("\"bgra8unorm\"").unwrap(), + TextureFormat::Bgra8Unorm + ); + assert_eq!( + serde_json::from_str::("\"bgra8unorm-srgb\"").unwrap(), + TextureFormat::Bgra8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"rgb10a2unorm\"").unwrap(), + TextureFormat::Rgb10a2Unorm + ); + assert_eq!( + serde_json::from_str::("\"rg11b10ufloat\"").unwrap(), + TextureFormat::Rg11b10Float + ); + assert_eq!( + serde_json::from_str::("\"rg32uint\"").unwrap(), + TextureFormat::Rg32Uint + ); + assert_eq!( + serde_json::from_str::("\"rg32sint\"").unwrap(), + TextureFormat::Rg32Sint + ); + assert_eq!( + serde_json::from_str::("\"rg32float\"").unwrap(), + TextureFormat::Rg32Float + ); + assert_eq!( + serde_json::from_str::("\"rgba16uint\"").unwrap(), + TextureFormat::Rgba16Uint + ); + assert_eq!( + serde_json::from_str::("\"rgba16sint\"").unwrap(), + TextureFormat::Rgba16Sint + ); + assert_eq!( + serde_json::from_str::("\"rgba16unorm\"").unwrap(), + TextureFormat::Rgba16Unorm + ); + assert_eq!( + serde_json::from_str::("\"rgba16snorm\"").unwrap(), + TextureFormat::Rgba16Snorm + ); + assert_eq!( + serde_json::from_str::("\"rgba16float\"").unwrap(), + TextureFormat::Rgba16Float + ); + assert_eq!( + serde_json::from_str::("\"rgba32uint\"").unwrap(), + TextureFormat::Rgba32Uint + ); + assert_eq!( + serde_json::from_str::("\"rgba32sint\"").unwrap(), + TextureFormat::Rgba32Sint + ); + assert_eq!( + serde_json::from_str::("\"rgba32float\"").unwrap(), + TextureFormat::Rgba32Float + ); + assert_eq!( + serde_json::from_str::("\"depth32float\"").unwrap(), + TextureFormat::Depth32Float + ); + assert_eq!( + serde_json::from_str::("\"depth16unorm\"").unwrap(), + TextureFormat::Depth16Unorm + ); + assert_eq!( + serde_json::from_str::("\"depth32float-stencil8\"").unwrap(), + TextureFormat::Depth32FloatStencil8 + ); + assert_eq!( + serde_json::from_str::("\"depth24plus\"").unwrap(), + TextureFormat::Depth24Plus + ); + assert_eq!( + serde_json::from_str::("\"depth24plus-stencil8\"").unwrap(), + TextureFormat::Depth24PlusStencil8 + ); + assert_eq!( + serde_json::from_str::("\"rgb9e5ufloat\"").unwrap(), + TextureFormat::Rgb9e5Ufloat + ); + assert_eq!( + serde_json::from_str::("\"bc1-rgba-unorm\"").unwrap(), + TextureFormat::Bc1RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc1-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc1RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"bc2-rgba-unorm\"").unwrap(), + TextureFormat::Bc2RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc2-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc2RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"bc3-rgba-unorm\"").unwrap(), + TextureFormat::Bc3RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc3-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc3RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"bc4-r-unorm\"").unwrap(), + TextureFormat::Bc4RUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc4-r-snorm\"").unwrap(), + TextureFormat::Bc4RSnorm + ); + assert_eq!( + serde_json::from_str::("\"bc5-rg-unorm\"").unwrap(), + TextureFormat::Bc5RgUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc5-rg-snorm\"").unwrap(), + TextureFormat::Bc5RgSnorm + ); + assert_eq!( + serde_json::from_str::("\"bc6h-rgb-ufloat\"").unwrap(), + TextureFormat::Bc6hRgbUfloat + ); + assert_eq!( + serde_json::from_str::("\"bc6h-rgb-float\"").unwrap(), + TextureFormat::Bc6hRgbSfloat + ); + assert_eq!( + serde_json::from_str::("\"bc7-rgba-unorm\"").unwrap(), + TextureFormat::Bc7RgbaUnorm + ); + assert_eq!( + serde_json::from_str::("\"bc7-rgba-unorm-srgb\"").unwrap(), + TextureFormat::Bc7RgbaUnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8unorm\"").unwrap(), + TextureFormat::Etc2Rgb8Unorm + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8unorm-srgb\"").unwrap(), + TextureFormat::Etc2Rgb8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8a1unorm\"").unwrap(), + TextureFormat::Etc2Rgb8A1Unorm + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgb8a1unorm-srgb\"").unwrap(), + TextureFormat::Etc2Rgb8A1UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgba8unorm\"").unwrap(), + TextureFormat::Etc2Rgba8Unorm + ); + assert_eq!( + serde_json::from_str::("\"etc2-rgba8unorm-srgb\"").unwrap(), + TextureFormat::Etc2Rgba8UnormSrgb + ); + assert_eq!( + serde_json::from_str::("\"eac-r11unorm\"").unwrap(), + TextureFormat::EacR11Unorm + ); + assert_eq!( + serde_json::from_str::("\"eac-r11snorm\"").unwrap(), + TextureFormat::EacR11Snorm + ); + assert_eq!( + serde_json::from_str::("\"eac-rg11unorm\"").unwrap(), + TextureFormat::EacRg11Unorm + ); + assert_eq!( + serde_json::from_str::("\"eac-rg11snorm\"").unwrap(), + TextureFormat::EacRg11Snorm + ); +} + bitflags::bitflags! { /// Color write mask. Disabled color channels will not be written to. ///