1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Add needs_reconfigure

This commit is contained in:
lucasmerlin
2026-03-23 18:10:02 +01:00
parent 65657941e2
commit 490da4aba2
3 changed files with 21 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ pub(crate) struct WebPainterWgpu {
capture_tx: CaptureSender, capture_tx: CaptureSender,
capture_rx: CaptureReceiver, capture_rx: CaptureReceiver,
ctx: egui::Context, ctx: egui::Context,
needs_reconfigure: bool,
} }
impl WebPainterWgpu { impl WebPainterWgpu {
@@ -110,6 +111,7 @@ impl WebPainterWgpu {
capture_tx, capture_tx,
capture_rx, capture_rx,
ctx, ctx,
needs_reconfigure: false,
}) })
} }
} }
@@ -195,11 +197,16 @@ impl WebPainter for WebPainterWgpu {
); );
} }
if self.needs_reconfigure {
self.surface
.configure(&render_state.device, &self.surface_configuration);
self.needs_reconfigure = false;
}
let output_frame = match self.surface.get_current_texture() { let output_frame = match self.surface.get_current_texture() {
wgpu::CurrentSurfaceTexture::Success(frame) => frame, wgpu::CurrentSurfaceTexture::Success(frame) => frame,
wgpu::CurrentSurfaceTexture::Suboptimal(frame) => { wgpu::CurrentSurfaceTexture::Suboptimal(frame) => {
self.surface self.needs_reconfigure = true;
.configure(&render_state.device, &self.surface_configuration);
frame frame
} }
other => { other => {

View File

@@ -307,8 +307,9 @@ pub struct WgpuConfiguration {
/// ///
/// Called with the [`wgpu::CurrentSurfaceTexture`] result whenever acquiring a frame /// Called with the [`wgpu::CurrentSurfaceTexture`] result whenever acquiring a frame
/// does not return [`wgpu::CurrentSurfaceTexture::Success`]. For /// does not return [`wgpu::CurrentSurfaceTexture::Success`]. For
/// [`wgpu::CurrentSurfaceTexture::Suboptimal`], egui automatically reconfigures the /// [`wgpu::CurrentSurfaceTexture::Suboptimal`], egui uses the frame as-is and
/// surface and uses the frame — the callback is not invoked in that case. /// defers surface reconfiguration to the next frame — the callback is not invoked
/// in that case either.
pub on_surface_status: pub on_surface_status:
Arc<dyn Fn(&wgpu::CurrentSurfaceTexture) -> SurfaceErrorAction + Send + Sync>, Arc<dyn Fn(&wgpu::CurrentSurfaceTexture) -> SurfaceErrorAction + Send + Sync>,
} }

View File

@@ -17,6 +17,7 @@ struct SurfaceState {
width: u32, width: u32,
height: u32, height: u32,
resizing: bool, resizing: bool,
needs_reconfigure: bool,
} }
/// Everything you need to paint egui with [`wgpu`] on [`winit`]. /// Everything you need to paint egui with [`wgpu`] on [`winit`].
@@ -234,6 +235,7 @@ impl Painter {
height: size.height, height: size.height,
alpha_mode, alpha_mode,
resizing: false, resizing: false,
needs_reconfigure: false,
}, },
); );
let Some(width) = NonZeroU32::new(size.width) else { let Some(width) = NonZeroU32::new(size.width) else {
@@ -454,7 +456,7 @@ impl Painter {
commands_submitted: false, commands_submitted: false,
}; };
let Some(surface_state) = self.surfaces.get(&viewport_id) else { let Some(surface_state) = self.surfaces.get_mut(&viewport_id) else {
return vsync_sec; return vsync_sec;
}; };
@@ -491,6 +493,11 @@ impl Painter {
) )
}; };
if surface_state.needs_reconfigure {
Self::configure_surface(surface_state, render_state, &self.configuration);
surface_state.needs_reconfigure = false;
}
let output_frame = { let output_frame = {
profiling::scope!("get_current_texture"); profiling::scope!("get_current_texture");
// This is what vsync-waiting happens on my Mac. // This is what vsync-waiting happens on my Mac.
@@ -503,7 +510,7 @@ impl Painter {
let output_frame = match output_frame { let output_frame = match output_frame {
wgpu::CurrentSurfaceTexture::Success(frame) => frame, wgpu::CurrentSurfaceTexture::Success(frame) => frame,
wgpu::CurrentSurfaceTexture::Suboptimal(frame) => { wgpu::CurrentSurfaceTexture::Suboptimal(frame) => {
Self::configure_surface(surface_state, render_state, &self.configuration); surface_state.needs_reconfigure = true;
frame frame
} }
other => { other => {