Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eframe: Early-out from context switching the glow backend #4284

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading