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:
parent
9774d4af2c
commit
9478e50d01
|
|
@ -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`]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue