Skip to content

Commit

Permalink
Fix Resize
Browse files Browse the repository at this point in the history
  • Loading branch information
qlurkin committed Oct 15, 2024
1 parent b815d49 commit 2bb929b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ impl Context {
self.config.height = new_size.height;

self.surface.configure(&self.device, &self.config);
match self.depth_texture_view {
None => {}
Some(_) => {
self.depth_texture_view = Some(create_depth_texture(
self.size,
self.depth_format,
self.device(),
));
}
};

println!("Resized to {:?} from state!", new_size);
}
Expand Down
13 changes: 13 additions & 0 deletions src/egui_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use winit::event::WindowEvent;
pub struct EguiLayer {
platform: Platform,
render_pass: RenderPass,
tdelta: Option<egui::TexturesDelta>,
}

impl EguiLayer {
Expand All @@ -25,6 +26,7 @@ impl EguiLayer {
Self {
platform,
render_pass,
tdelta: None,
}
}

Expand Down Expand Up @@ -93,5 +95,16 @@ impl EguiLayer {
.unwrap();

context.queue().submit(std::iter::once(encoder.finish()));

self.tdelta = Some(tdelta);
}

pub fn cleanup(&mut self) {
let tdelta = self.tdelta.take();
if let Some(tdelta) = tdelta {
self.render_pass()
.remove_textures(tdelta)
.expect("remove texture ok");
}
}
}
3 changes: 3 additions & 0 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl ApplicationHandler for Runner {
}
WindowEvent::Resized(physical_size) => {
context.resize(physical_size);
app.resize(context, physical_size);
}
WindowEvent::RedrawRequested => {
let now = Instant::now();
Expand Down Expand Up @@ -144,6 +145,8 @@ impl ApplicationHandler for Runner {
// .render_pass()
// .remove_textures(tdelta)
// .expect("remove texture ok");

egui_layer.cleanup();
}
_ => {}
}
Expand Down

0 comments on commit 2bb929b

Please sign in to comment.