Skip to content

Commit

Permalink
auto choose supported CompositeAlphaMode capability
Browse files Browse the repository at this point in the history
  • Loading branch information
panekj committed May 13, 2024
1 parent 7459d7b commit 11426e8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion vger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,36 @@ impl VgerRenderer {
let queue = Arc::new(queue);

let surface_caps = surface.get_capabilities(&adapter);

tracing::trace!("surface caps: {surface_caps:?}");

let texture_format = surface_caps
.formats
.into_iter()
.find(|it| matches!(it, TextureFormat::Rgba8Unorm | TextureFormat::Bgra8Unorm))
.ok_or_else(|| anyhow::anyhow!("surface should support Rgba8Unorm or Bgra8Unorm"))?;

let alpha_mode = if surface_caps
.alpha_modes
.contains(&wgpu::CompositeAlphaMode::PostMultiplied)
{
wgpu::CompositeAlphaMode::PostMultiplied
} else if surface_caps
.alpha_modes
.contains(&wgpu::CompositeAlphaMode::PreMultiplied)
{
wgpu::CompositeAlphaMode::PreMultiplied
} else {
wgpu::CompositeAlphaMode::Auto
};

let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: texture_format,
width,
height,
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
alpha_mode,
view_formats: vec![],
desired_maximum_frame_latency: 2,
};
Expand Down

0 comments on commit 11426e8

Please sign in to comment.