Fix panic on wgpu GL backend due to new screenshot capability (#3078)

* Triage for GL backend

* And cargo-fmt

* Changelog update with PR and issue

* Update crates/eframe/src/epi/mod.rs

Co-authored-by: Andreas Reich <r_andreas2@web.de>

* Update crates/egui-wgpu/src/winit.rs

Co-authored-by: Andreas Reich <r_andreas2@web.de>

* Add "supports_screenshot" to surface state

* Cranky fix

* fmt

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
amfaber 2023-06-15 11:16:25 +02:00 committed by GitHub
parent 9774d4af2c
commit 9478e50d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -799,6 +799,7 @@ impl Frame {
/// * Called in [`App::update`] /// * Called in [`App::update`]
/// * [`Frame::request_screenshot`] wasn't called on this frame during [`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. /// * 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. /// * Retrieving the data was unsuccessful in some way.
/// ///
/// See also [`egui::ColorImage::region`] /// See also [`egui::ColorImage::region`]

View File

@ -3,6 +3,7 @@ All notable changes to the `egui-wgpu` integration will be noted in this file.
## Unreleased ## 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 ## 0.22.0 - 2023-05-23

View File

@ -7,6 +7,7 @@ struct SurfaceState {
alpha_mode: wgpu::CompositeAlphaMode, alpha_mode: wgpu::CompositeAlphaMode,
width: u32, width: u32,
height: u32, height: u32,
supports_screenshot: bool,
} }
/// A texture and a buffer for reading the rendered frame back to the cpu. /// A texture and a buffer for reading the rendered frame back to the cpu.
@ -136,10 +137,15 @@ impl Painter {
render_state: &RenderState, render_state: &RenderState,
present_mode: wgpu::PresentMode, 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( surface_state.surface.configure(
&render_state.device, &render_state.device,
&wgpu::SurfaceConfiguration { &wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, usage,
format: render_state.target_format, format: render_state.target_format,
width: surface_state.width, width: surface_state.width,
height: surface_state.height, height: surface_state.height,
@ -218,12 +224,16 @@ impl Painter {
wgpu::CompositeAlphaMode::Auto wgpu::CompositeAlphaMode::Auto
}; };
let supports_screenshot =
!matches!(render_state.adapter.get_info().backend, wgpu::Backend::Gl);
let size = window.inner_size(); let size = window.inner_size();
self.surface_state = Some(SurfaceState { self.surface_state = Some(SurfaceState {
surface, surface,
width: size.width, width: size.width,
height: size.height, height: size.height,
alpha_mode, alpha_mode,
supports_screenshot,
}); });
self.resize_and_generate_depth_texture_view_and_msaa_view(size.width, size.height); 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 renderer = render_state.renderer.read();
let frame_view = if capture { let frame_view = if capture {
@ -566,7 +585,7 @@ impl Painter {
} else { } else {
None None
}; };
// Redraw egui
{ {
crate::profile_scope!("present"); crate::profile_scope!("present");
output_frame.present(); output_frame.present();