From 5bf1ad3901d48a57d923e7958ec471558a1635e8 Mon Sep 17 00:00:00 2001 From: Elabajaba Date: Tue, 24 Jan 2023 14:29:47 -0500 Subject: [PATCH 1/2] implement add_srgb_suffix for TextureFormat --- wgpu-types/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 6338ae176e..5d0d722c98 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2580,6 +2580,29 @@ impl TextureFormat { _ => *self, } } + + /// Adds an `Srgb` suffix to the given texture format, if the format supports it. + pub fn add_srgb_suffix(&self) -> TextureFormat { + match *self { + Self::Rgba8Unorm => Self::Rgba8UnormSrgb, + Self::Bgra8Unorm => Self::Bgra8UnormSrgb, + Self::Bc1RgbaUnorm => Self::Bc1RgbaUnormSrgb, + Self::Bc2RgbaUnorm => Self::Bc2RgbaUnormSrgb, + Self::Bc3RgbaUnorm => Self::Bc3RgbaUnormSrgb, + Self::Bc7RgbaUnorm => Self::Bc7RgbaUnormSrgb, + Self::Etc2Rgb8Unorm => Self::Etc2Rgb8UnormSrgb, + Self::Etc2Rgb8A1Unorm => Self::Etc2Rgb8A1UnormSrgb, + Self::Etc2Rgba8Unorm => Self::Etc2Rgba8UnormSrgb, + Self::Astc { + block, + channel: AstcChannel::Unorm, + } => Self::Astc { + block, + channel: AstcChannel::UnormSrgb, + }, + _ => *self, + } + } } #[test] From 072c40b249df08293b6e984759f40a0fcfba0ac8 Mon Sep 17 00:00:00 2001 From: Elabajaba Date: Tue, 24 Jan 2023 14:36:22 -0500 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ccb3d8bc3..46271fbfc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -216,6 +216,7 @@ let texture = device.create_texture(&wgpu::TextureDescriptor { - Implemented correleation between user timestamps and platform specific presentation timestamps via [`Adapter::get_presentation_timestamp`]. By @cwfitzgerald in [#3240](https://github.com/gfx-rs/wgpu/pull/3240) - Added support for `Features::SHADER_PRIMITIVE_INDEX` on all backends. By @cwfitzgerald in [#3272](https://github.com/gfx-rs/wgpu/pull/3272) - Implemented `TextureFormat::Stencil8`, allowing for stencil testing without depth components. By @Dinnerbone in [#3343](https://github.com/gfx-rs/wgpu/pull/3343) +- Implemented `add_srgb_suffix()` for `TextureFormat` for converting linear formats to sRGB. By @Elabajaba in [#3419](https://github.com/gfx-rs/wgpu/pull/3419) #### GLES