Fix alpha mode configuration in iced_wgpu
This commit is contained in:
parent
7ee00e751a
commit
712c8e53f2
2 changed files with 83 additions and 20 deletions
|
|
@ -15,6 +15,7 @@ pub struct Compositor {
|
|||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
format: wgpu::TextureFormat,
|
||||
alpha_mode: wgpu::CompositeAlphaMode,
|
||||
}
|
||||
|
||||
impl Compositor {
|
||||
|
|
@ -61,25 +62,43 @@ impl Compositor {
|
|||
|
||||
log::info!("Selected: {:#?}", adapter.get_info());
|
||||
|
||||
let format = compatible_surface.as_ref().and_then(|surface| {
|
||||
let capabilities = surface.get_capabilities(&adapter);
|
||||
let (format, alpha_mode) =
|
||||
compatible_surface.as_ref().and_then(|surface| {
|
||||
let capabilities = surface.get_capabilities(&adapter);
|
||||
|
||||
let mut formats = capabilities.formats.iter().copied();
|
||||
let mut formats = capabilities.formats.iter().copied();
|
||||
|
||||
let format = if color::GAMMA_CORRECTION {
|
||||
formats.find(wgpu::TextureFormat::is_srgb)
|
||||
} else {
|
||||
formats.find(|format| !wgpu::TextureFormat::is_srgb(format))
|
||||
};
|
||||
let format = if color::GAMMA_CORRECTION {
|
||||
formats.find(wgpu::TextureFormat::is_srgb)
|
||||
} else {
|
||||
formats.find(|format| !wgpu::TextureFormat::is_srgb(format))
|
||||
};
|
||||
|
||||
format.or_else(|| {
|
||||
log::warn!("No format found!");
|
||||
let format = format.or_else(|| {
|
||||
log::warn!("No format found!");
|
||||
|
||||
capabilities.formats.first().copied()
|
||||
})
|
||||
})?;
|
||||
capabilities.formats.first().copied()
|
||||
});
|
||||
|
||||
log::info!("Selected format: {format:?}");
|
||||
let alphas = capabilities.alpha_modes;
|
||||
let preferred_alpha = if alphas
|
||||
.contains(&wgpu::CompositeAlphaMode::PostMultiplied)
|
||||
{
|
||||
wgpu::CompositeAlphaMode::PostMultiplied
|
||||
} else if alphas
|
||||
.contains(&wgpu::CompositeAlphaMode::PreMultiplied)
|
||||
{
|
||||
wgpu::CompositeAlphaMode::PreMultiplied
|
||||
} else {
|
||||
wgpu::CompositeAlphaMode::Auto
|
||||
};
|
||||
|
||||
format.zip(Some(preferred_alpha))
|
||||
})?;
|
||||
|
||||
log::info!(
|
||||
"Selected format: {format:?} with alpha mode: {alpha_mode:?}"
|
||||
);
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let limits = [wgpu::Limits::downlevel_webgl2_defaults()
|
||||
|
|
@ -120,6 +139,7 @@ impl Compositor {
|
|||
device,
|
||||
queue,
|
||||
format,
|
||||
alpha_mode,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +269,7 @@ impl graphics::Compositor for Compositor {
|
|||
present_mode: self.settings.present_mode,
|
||||
width,
|
||||
height,
|
||||
alpha_mode: wgpu::CompositeAlphaMode::Auto,
|
||||
alpha_mode: self.alpha_mode,
|
||||
view_formats: vec![],
|
||||
desired_maximum_frame_latency: 2,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue