From e441e9d0675d476813ab3e36d499f9febd781156 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Wed, 7 Oct 2009 15:18:53 +0000 Subject: [PATCH] Generate Update/ResizeFrame events whenever the window is moved or resized. Partially fix for issue [#1218]: "[NativeWindow] Avoid modal loop during window resize/movement". --- Source/OpenTK/GameWindow.cs | 16 +++++++++++++--- Source/OpenTK/Platform/Windows/WinGLNative.cs | 13 +++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 8696d34f..4d2b2e64 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -372,7 +372,6 @@ namespace OpenTK Stopwatch update_watch = new Stopwatch(), render_watch = new Stopwatch(); double next_render = 0.0, next_update = 0.0; - int num_updates = 0; FrameEventArgs update_args = new FrameEventArgs(); FrameEventArgs render_args = new FrameEventArgs(); @@ -382,13 +381,24 @@ namespace OpenTK Visible = true; // Make sure the GameWindow is visible. OnLoadInternal(EventArgs.Empty); + // On some platforms, ProcessEvents() does not return while the user is resizing or moving + // the window. We can avoid this issue by raising UpdateFrame and RenderFrame events + // whenever we encounter a size or move event. + EventHandler DispatchUpdateAndRenderFrame = delegate(object sender, EventArgs e) + { + RaiseUpdateFrame(update_watch, ref next_update, update_args); + RaiseRenderFrame(render_watch, ref next_render, render_args); + }; + + Move += DispatchUpdateAndRenderFrame; + Resize += DispatchUpdateAndRenderFrame; + Debug.Print("Entering main loop."); while (!IsExiting && Exists) { ProcessEvents(); - RaiseUpdateFrame(update_watch, ref next_update, update_args); - RaiseRenderFrame(render_watch, ref next_render, render_args); + DispatchUpdateAndRenderFrame(this, EventArgs.Empty); } } finally diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 6c455288..b121f0d5 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -53,10 +53,7 @@ namespace OpenTK.Platform.Windows readonly UIntPtr ModalLoopTimerId = new UIntPtr(1); readonly uint ModalLoopTimerPeriod = 1; UIntPtr timer_handle; - readonly Functions.TimerProc ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time) - { - // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events. - }; + readonly Functions.TimerProc ModalLoopCallback; bool class_registered; bool disposed; @@ -99,6 +96,14 @@ namespace OpenTK.Platform.Windows // don't move it below the CreateWindow calls. WindowProcedureDelegate = WindowProcedure; + // This timer callback is called periodically when the window enters a sizing / moving modal loop. + ModalLoopCallback = delegate(IntPtr handle, WindowMessage msg, UIntPtr eventId, int time) + { + // Todo: find a way to notify the frontend that it should process queued up UpdateFrame/RenderFrame events. + if (Move != null) + Move(this, EventArgs.Empty); + }; + // To avoid issues with Ati drivers on Windows 6+ with compositing enabled, the context will not be // bound to the top-level window, but rather to a child window docked in the parent. window = new WinWindowInfo(