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: Improve glow context switching #4814

Merged
merged 2 commits into from
Jul 11, 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
20 changes: 15 additions & 5 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ impl GlowWinitRunning {
let GlutinWindowContext {
viewports,
current_gl_context,
not_current_gl_context,
..
} = &mut *glutin;
let viewport = &viewports[&viewport_id];
Expand All @@ -602,7 +603,7 @@ impl GlowWinitRunning {

{
frame_timer.pause();
change_gl_context(current_gl_context, gl_surface);
change_gl_context(current_gl_context, not_current_gl_context, gl_surface);
frame_timer.resume();
}

Expand Down Expand Up @@ -645,6 +646,7 @@ impl GlowWinitRunning {
let GlutinWindowContext {
viewports,
current_gl_context,
not_current_gl_context,
..
} = &mut *glutin;

Expand All @@ -664,7 +666,7 @@ impl GlowWinitRunning {
{
// We may need to switch contexts again, because of immediate viewports:
frame_timer.pause();
change_gl_context(current_gl_context, gl_surface);
change_gl_context(current_gl_context, not_current_gl_context, gl_surface);
frame_timer.resume();
}

Expand Down Expand Up @@ -866,6 +868,7 @@ impl GlowWinitRunning {

fn change_gl_context(
current_gl_context: &mut Option<glutin::context::PossiblyCurrentContext>,
not_current_gl_context: &mut Option<glutin::context::NotCurrentContext>,
gl_surface: &glutin::surface::Surface<glutin::surface::WindowSurface>,
) {
crate::profile_function!();
Expand All @@ -884,7 +887,9 @@ fn change_gl_context(
}
}

let not_current = {
let not_current = if let Some(not_current_context) = not_current_gl_context.take() {
not_current_context
} else {
crate::profile_scope!("make_not_current");
current_gl_context
.take()
Expand Down Expand Up @@ -1227,7 +1232,11 @@ impl GlutinWindowContext {

if let Some(viewport) = self.viewports.get(&viewport_id) {
if let Some(gl_surface) = &viewport.gl_surface {
change_gl_context(&mut self.current_gl_context, gl_surface);
change_gl_context(
&mut self.current_gl_context,
&mut self.not_current_gl_context,
gl_surface,
);
gl_surface.resize(
self.current_gl_context
.as_ref()
Expand Down Expand Up @@ -1459,6 +1468,7 @@ fn render_immediate_viewport(

let GlutinWindowContext {
current_gl_context,
not_current_gl_context,
viewports,
..
} = &mut *glutin;
Expand All @@ -1479,7 +1489,7 @@ fn render_immediate_viewport(

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

change_gl_context(current_gl_context, gl_surface);
change_gl_context(current_gl_context, not_current_gl_context, gl_surface);

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

Expand Down
Loading