Skip to content

Commit

Permalink
Simplify surface texture format selection (#336)
Browse files Browse the repository at this point in the history
- We require sRGB because that's the color space users expect when they are plotting their own pixels.
- It simplifies the fragment shader because we don't have to do a linear->gamma transformation. The hardware will do it for us.
  • Loading branch information
parasyte authored Jan 28, 2023
1 parent eede10b commit 8605592
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
*surface_capabilities
.formats
.iter()
.find(|format| texture_format_is_srgb(**format))
.find(|format| format.describe().srgb)
.unwrap_or(&wgpu::TextureFormat::Bgra8UnormSrgb)
});
let render_texture_format = self.render_texture_format.unwrap_or(surface_texture_format);
Expand Down Expand Up @@ -490,24 +490,6 @@ pub(crate) fn create_backing_texture(
))
}

#[inline]
const fn texture_format_is_srgb(texture_format: wgpu::TextureFormat) -> bool {
use wgpu::TextureFormat::*;

matches!(
texture_format,
Rgba8UnormSrgb
| Bgra8UnormSrgb
| Bc1RgbaUnormSrgb
| Etc2Rgb8UnormSrgb
| Etc2Rgb8A1UnormSrgb
| Bc2RgbaUnormSrgb
| Bc3RgbaUnormSrgb
| Bc7RgbaUnormSrgb
| Etc2Rgba8UnormSrgb
)
}

#[rustfmt::skip]
#[inline]
const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
Expand Down

0 comments on commit 8605592

Please sign in to comment.