Skip to content

Commit

Permalink
eframe: Early-out from context switching the glow backend (#4284)
Browse files Browse the repository at this point in the history
* Closes #4173
  • Loading branch information
emilk authored Mar 30, 2024
1 parent 549b243 commit e03ea2e
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,13 @@ fn change_gl_context(
) {
crate::profile_function!();

if let Some(current_gl_context) = current_gl_context {
crate::profile_scope!("is_current");
if gl_surface.is_current(current_gl_context) {
return; // Early-out to save a lot of time.
}
}

let not_current = {
crate::profile_scope!("make_not_current");
current_gl_context
Expand All @@ -844,6 +851,7 @@ fn change_gl_context(
.make_not_current()
.unwrap()
};

crate::profile_scope!("make_current");
*current_gl_context = Some(not_current.make_current(gl_surface).unwrap());
}
Expand Down Expand Up @@ -1178,15 +1186,7 @@ impl GlutinWindowContext {

if let Some(viewport) = self.viewports.get(&viewport_id) {
if let Some(gl_surface) = &viewport.gl_surface {
self.current_gl_context = Some(
self.current_gl_context
.take()
.unwrap()
.make_not_current()
.unwrap()
.make_current(gl_surface)
.unwrap(),
);
change_gl_context(&mut self.current_gl_context, gl_surface);
gl_surface.resize(
self.current_gl_context
.as_ref()
Expand Down Expand Up @@ -1436,18 +1436,7 @@ fn render_immediate_viewport(

let screen_size_in_pixels: [u32; 2] = window.inner_size().into();

{
crate::profile_function!("context-switch");
*current_gl_context = Some(
current_gl_context
.take()
.unwrap()
.make_not_current()
.unwrap()
.make_current(gl_surface)
.unwrap(),
);
}
change_gl_context(current_gl_context, gl_surface);

let current_gl_context = current_gl_context.as_ref().unwrap();

Expand Down

0 comments on commit e03ea2e

Please sign in to comment.