From 700393b6883a719138c223ece2a3ae962cca713d Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sun, 23 Sep 2007 12:37:07 +0000 Subject: [PATCH] Added GameWindow.SwapBuffers(). Fixed T02_Vertex_Array_Cube to 60Hz. --- .../Tutorial/T02_Vertex_Array_Cube.cs | 2 +- Source/OpenTK/GameWindow.cs | 61 ++++++++++++++----- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Source/Examples/Tutorial/T02_Vertex_Array_Cube.cs b/Source/Examples/Tutorial/T02_Vertex_Array_Cube.cs index d5c73e0f..368c0bf5 100644 --- a/Source/Examples/Tutorial/T02_Vertex_Array_Cube.cs +++ b/Source/Examples/Tutorial/T02_Vertex_Array_Cube.cs @@ -136,7 +136,7 @@ namespace Examples.Tutorial /// public void Launch() { - // Run the main loop calling UpdateFrame and RenderFrame 60 times per second. + // Lock UpdateFrame and RenderFrame at 60Hz. Run(60.0, 60.0); } diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 36d96ac2..b8d8e08e 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -295,12 +295,40 @@ namespace OpenTK #region public virtual void Run() /// - /// Runs the default game loop on GameWindow at the maximum possible update and render speed. + /// Enters the game loop of GameWindow, updating and rendering at the maximum possible frequency. /// + /// + public void Run() + { + Run(0.0, 0.0); + } + + /// + /// Runs the default game loop on GameWindow at the specified update frequency, maintaining the + /// maximum possible render frequency. + /// + /// + public void Run(double updateFrequency) + { + Run(updateFrequency, 0.0); + } + + /// + /// Runs the default game loop on GameWindow at the specified update and render frequency. + /// + /// If greater than zero, indicates how many times UpdateFrame will be called per second. If less than or equal to zero, UpdateFrame is raised at maximum possible frequency. + /// If greater than zero, indicates how many times RenderFrame will be called per second. If less than or equal to zero, RenderFrame is raised at maximum possible frequency. /// /// - /// A default game loop consists of three parts: Event processing, - /// a frame update and a frame render. + /// A default game loop consists of three parts: Event processing, frame updating and a frame rendering. + /// This function will try to maintain the requested updateFrequency at all costs, dropping the renderFrequency if + /// there is not enough CPU time. + /// + /// + /// It is recommended that you specify a target for update- and renderFrequency. + /// Doing so, will yield unused CPU time to other processes, dropping power consumption + /// and maximizing batter life. If either frequency is left unspecified, the GameWindow + /// will consume all available CPU time (only useful for benchmarks and stress tests). /// /// /// Override this function if you want to change the behaviour of the @@ -309,18 +337,7 @@ namespace OpenTK /// to Operating System events. /// /// - /// - public void Run() - { - Run(0.0f, 0.0f); - } - - /// - /// Runs the default game loop on GameWindow at the specified update and render speed. - /// - /// Indicates how many times UpdateFrame will be called per second. - /// Indicates how many times RenderFrame will be called per second. - public virtual void Run(double update_frequency, double render_frequency) + public virtual void Run(double updateFrequency, double renderFrequency) { this.OnLoad(EventArgs.Empty); resizeEventArgs.Width = this.Width; @@ -504,6 +521,20 @@ namespace OpenTK #endregion + #region public void SwapBuffers() + + /// + /// Swaps the front and back buffer, presenting the rendered scene to the user. + /// Only useful in double- or triple-buffered formats. + /// + /// Calling this function is equivalent to calling Context.SwapBuffers() + public void SwapBuffers() + { + Context.SwapBuffers(); + } + + #endregion + #region public bool IsExiting ///