diff --git a/src/glass.rs b/src/glass.rs index d789c7d..50fee51 100644 --- a/src/glass.rs +++ b/src/glass.rs @@ -56,12 +56,14 @@ impl Glass { if !event_loop.exiting() { self.app.input(&mut context, event_loop, &event); } + let mut end_of_frame = false; match event { Event::WindowEvent { window_id, event: window_event, .. } => { + let mut redraw = false; if let Some(window) = context.windows.get_mut(&window_id) { match window_event { WindowEvent::Resized(physical_size) => { @@ -104,27 +106,15 @@ impl Glass { request_window_close = true; remove_windows.push(window_id); } + WindowEvent::RedrawRequested => { + redraw = true; + end_of_frame = true; + } _ => (), } } - } - Event::AboutToWait => { - if !event_loop.exiting() { - self.app.update(&mut context); - // Close window(s) - if request_window_close || context.exit { - for window in remove_windows.iter() { - context.windows.remove(window); - } - remove_windows.clear(); - request_window_close = false; - // Exit - if context.windows.is_empty() || context.exit { - event_loop.exit(); - } - } - // Render - for (_, window) in context.windows.iter() { + if redraw { + if let Some(window) = context.windows.get(&window_id) { match window.surface().get_current_texture() { Ok(frame) => { let mut encoder = context @@ -158,10 +148,30 @@ impl Glass { } } } + } + } + } + Event::AboutToWait => { + if !event_loop.exiting() { + self.app.update(&mut context); + + // Redraw + for (_, window) in context.windows.iter() { window.window().request_redraw(); } - // End of frame - self.app.end_of_frame(&mut context); + + // Close window(s) + if request_window_close || context.exit { + for window in remove_windows.iter() { + context.windows.remove(window); + } + remove_windows.clear(); + request_window_close = false; + // Exit + if context.windows.is_empty() || context.exit { + event_loop.exit(); + } + } } } Event::LoopExiting => { @@ -170,6 +180,9 @@ impl Glass { } _ => {} } + if end_of_frame { + self.app.end_of_frame(&mut context); + } }) { Err(e) => Err(GlassError::EventLoopError(e)), Ok(a) => Ok(a),