mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user