Skip to content

Commit

Permalink
egui-wgpu cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 7, 2023
1 parent 522cfb5 commit 85c8708
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,7 @@ mod wgpu_integration {
viewport_maps
.borrow_mut()
.retain(|_, id| active_viewports_ids.contains(id));
painter.borrow_mut().clean_surfaces(&active_viewports_ids);
painter.borrow_mut().gc_viewports(&active_viewports_ids);

let Some(
Viewport {
Expand Down
18 changes: 10 additions & 8 deletions crates/egui-wgpu/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ pub struct Painter {
msaa_samples: u32,
support_transparent_backbuffer: bool,
depth_format: Option<wgpu::TextureFormat>,
depth_texture_view: ViewportIdMap<wgpu::TextureView>,
msaa_texture_view: ViewportIdMap<wgpu::TextureView>,
screen_capture_state: Option<CaptureState>,

instance: wgpu::Instance,
render_state: Option<RenderState>,

// Per viewport/window:
depth_texture_view: ViewportIdMap<wgpu::TextureView>,
msaa_texture_view: ViewportIdMap<wgpu::TextureView>,
surfaces: ViewportIdMap<SurfaceState>,
}

Expand Down Expand Up @@ -120,11 +122,12 @@ impl Painter {
msaa_samples,
support_transparent_backbuffer,
depth_format,
depth_texture_view: Default::default(),
screen_capture_state: None,

instance,
render_state: None,

depth_texture_view: Default::default(),
surfaces: Default::default(),
msaa_texture_view: Default::default(),
}
Expand Down Expand Up @@ -625,13 +628,12 @@ impl Painter {
screenshot
}

pub fn clean_surfaces(&mut self, available_viewports: &ViewportIdSet) {
self.surfaces
.retain(|id, _| available_viewports.contains(id));
pub fn gc_viewports(&mut self, active_viewports: &ViewportIdSet) {
self.surfaces.retain(|id, _| active_viewports.contains(id));
self.depth_texture_view
.retain(|id, _| available_viewports.contains(id));
.retain(|id, _| active_viewports.contains(id));
self.msaa_texture_view
.retain(|id, _| available_viewports.contains(id));
.retain(|id, _| active_viewports.contains(id));
}

#[allow(clippy::unused_self)]
Expand Down

0 comments on commit 85c8708

Please sign in to comment.