diff --git a/crates/eframe/src/epi/mod.rs b/crates/eframe/src/epi/mod.rs index 75380cd1..0f6f4229 100644 --- a/crates/eframe/src/epi/mod.rs +++ b/crates/eframe/src/epi/mod.rs @@ -799,6 +799,7 @@ impl Frame { /// * Called in [`App::update`] /// * [`Frame::request_screenshot`] wasn't called on this frame during [`App::update`] /// * The rendering backend doesn't support this feature (yet). Currently implemented for wgpu and glow, but not with wasm as target. + /// * Wgpu's GL target is active (not yet supported) /// * Retrieving the data was unsuccessful in some way. /// /// See also [`egui::ColorImage::region`] diff --git a/crates/egui-wgpu/CHANGELOG.md b/crates/egui-wgpu/CHANGELOG.md index 883178ba..ecae53cf 100644 --- a/crates/egui-wgpu/CHANGELOG.md +++ b/crates/egui-wgpu/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to the `egui-wgpu` integration will be noted in this file. ## Unreleased +* Fix panic on wgpu GL backend due to new screenshot capability ([#3068](https://github.com/emilk/egui/issues/3068), [#3078](https://github.com/emilk/egui/pull/3078) ## 0.22.0 - 2023-05-23 diff --git a/crates/egui-wgpu/src/winit.rs b/crates/egui-wgpu/src/winit.rs index bac920f1..7b6a9b18 100644 --- a/crates/egui-wgpu/src/winit.rs +++ b/crates/egui-wgpu/src/winit.rs @@ -7,6 +7,7 @@ struct SurfaceState { alpha_mode: wgpu::CompositeAlphaMode, width: u32, height: u32, + supports_screenshot: bool, } /// A texture and a buffer for reading the rendered frame back to the cpu. @@ -136,10 +137,15 @@ impl Painter { render_state: &RenderState, present_mode: wgpu::PresentMode, ) { + let usage = if surface_state.supports_screenshot { + wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST + } else { + wgpu::TextureUsages::RENDER_ATTACHMENT + }; surface_state.surface.configure( &render_state.device, &wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, + usage, format: render_state.target_format, width: surface_state.width, height: surface_state.height, @@ -218,12 +224,16 @@ impl Painter { wgpu::CompositeAlphaMode::Auto }; + let supports_screenshot = + !matches!(render_state.adapter.get_info().backend, wgpu::Backend::Gl); + let size = window.inner_size(); self.surface_state = Some(SurfaceState { surface, width: size.width, height: size.height, alpha_mode, + supports_screenshot, }); self.resize_and_generate_depth_texture_view_and_msaa_view(size.width, size.height); } @@ -485,6 +495,15 @@ impl Painter { ) }; + let capture = match (capture, surface_state.supports_screenshot) { + (false, _) => false, + (true, true) => true, + (true, false) => { + log::error!("The active render surface doesn't support taking screenshots."); + false + } + }; + { let renderer = render_state.renderer.read(); let frame_view = if capture { @@ -566,7 +585,7 @@ impl Painter { } else { None }; - // Redraw egui + { crate::profile_scope!("present"); output_frame.present();