From e395eae9571b1ec1ba2a0112e4476ba695449f80 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 5 Jun 2015 17:52:45 +1000 Subject: [PATCH] Added BeginFrame/EndFrame to IGraphicsApi. --- Game/Game.cs | 3 ++- GraphicsAPI/DirectXApi.cs | 9 +++++++++ GraphicsAPI/IGraphicsApi.cs | 4 ++++ GraphicsAPI/OpenGLApi.cs | 7 +++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Game/Game.cs b/Game/Game.cs index 833551bc0..6aa6fcfca 100644 --- a/Game/Game.cs +++ b/Game/Game.cs @@ -179,6 +179,7 @@ namespace ClassicalSharp { double ticksAccumulator = 0, imageCheckAccumulator = 0; protected override void OnRenderFrame( FrameEventArgs e ) { + Graphics.BeginFrame( this ); accumulator += e.Time; imageCheckAccumulator += e.Time; ticksAccumulator += e.Time; @@ -253,7 +254,7 @@ namespace ClassicalSharp { Graphics.TakeScreenshot( path, ClientSize ); screenshotRequested = false; } - SwapBuffers(); + Graphics.EndFrame( this ); } void RenderPlayers( double deltaTime, float t ) { diff --git a/GraphicsAPI/DirectXApi.cs b/GraphicsAPI/DirectXApi.cs index 8a2b4b3d6..5798236d7 100644 --- a/GraphicsAPI/DirectXApi.cs +++ b/GraphicsAPI/DirectXApi.cs @@ -386,6 +386,15 @@ namespace ClassicalSharp.GraphicsAPI { #endregion + public override void BeginFrame( Game game ) { + device.BeginScene(); + } + + public override void EndFrame( Game game ) { + device.EndScene(); + device.Present(); + } + public override void OnWindowResize( int newWidth, int newHeight ) { throw new NotSupportedException(); } diff --git a/GraphicsAPI/IGraphicsApi.cs b/GraphicsAPI/IGraphicsApi.cs index 6e7a02acc..8cba9f185 100644 --- a/GraphicsAPI/IGraphicsApi.cs +++ b/GraphicsAPI/IGraphicsApi.cs @@ -191,6 +191,10 @@ namespace ClassicalSharp.GraphicsAPI { public virtual void PrintApiSpecificInfo() { } + public abstract void BeginFrame( Game game ); + + public abstract void EndFrame( Game game ); + public abstract void OnWindowResize( int newWidth, int newHeight ); protected void InitDynamicBuffers() { diff --git a/GraphicsAPI/OpenGLApi.cs b/GraphicsAPI/OpenGLApi.cs index 2a3a08f47..f9bf2281d 100644 --- a/GraphicsAPI/OpenGLApi.cs +++ b/GraphicsAPI/OpenGLApi.cs @@ -432,6 +432,13 @@ namespace ClassicalSharp.GraphicsAPI { } #endif + public override void BeginFrame( Game game ) { + } + + public override void EndFrame( Game game ) { + game.SwapBuffers(); + } + public override void PrintApiSpecificInfo() { Console.WriteLine( "OpenGL vendor: " + GL.GetString( StringName.Vendor ) ); Console.WriteLine( "OpenGL renderer: " + GL.GetString( StringName.Renderer ) );