Skip to content

Commit

Permalink
Find preferred format and move it to the first position in the formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jun 23, 2023
1 parent b9cff4f commit b17e692
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,21 +1113,26 @@ impl crate::context::Context for Context {
_adapter: &Self::AdapterId,
_adapter_data: &Self::AdapterData,
) -> wgt::SurfaceCapabilities {
let format = self.0.get_preferred_canvas_format();
let (preferred, second) = if map_texture_format(wgt::TextureFormat::Bgra8Unorm) == format {
(
wgt::TextureFormat::Bgra8Unorm,
wgt::TextureFormat::Rgba8Unorm,
)
} else {
(
wgt::TextureFormat::Rgba8Unorm,
wgt::TextureFormat::Bgra8Unorm,
)
};
let preferred_format = self.0.get_preferred_canvas_format();
let mut formats = vec![
wgt::TextureFormat::Rgba8Unorm,
wgt::TextureFormat::Bgra8Unorm,
wgt::TextureFormat::Rgba16Float,
];
let mapped_formats: Vec<_> = formats
.iter()
.map(|format| map_texture_format(*format))
.collect();
if let Some(index) = mapped_formats
.iter()
.position(|format| *format == preferred_format)
{
formats.swap(0, index);
}

wgt::SurfaceCapabilities {
// https://gpuweb.github.io/gpuweb/#supported-context-formats
formats: vec![preferred, second, wgt::TextureFormat::Rgba16Float],
formats,
// Doesn't really have meaning on the web.
present_modes: vec![wgt::PresentMode::Fifo],
alpha_modes: vec![wgt::CompositeAlphaMode::Opaque],
Expand Down

0 comments on commit b17e692

Please sign in to comment.