Browse Source

Added C++ and Console Functions to get Vertical Sync status.

capnlove 10 years ago
parent
commit
5668ec2b32

+ 7 - 0
engine/source/platform/platformVideo.cc

@@ -465,6 +465,13 @@ bool Video::setGammaCorrection(F32 g)
    return false;	
    return false;	
 }
 }
 
 
+//------------------------------------------------------------------------------
+bool Video::getVerticalSync()
+{
+    if (smCurrentDevice)
+        return smCurrentDevice->getVerticalSync();
+}
+
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 bool Video::setVerticalSync( bool on )
 bool Video::setVerticalSync( bool on )
 {
 {

+ 3 - 1
engine/source/platform/platformVideo.h

@@ -76,6 +76,7 @@ public:
    static void swapBuffers();                         // page flip
    static void swapBuffers();                         // page flip
    static bool getGammaCorrection(F32 &g);            // get gamma correction
    static bool getGammaCorrection(F32 &g);            // get gamma correction
    static bool setGammaCorrection(F32 g);             // set gamma correction
    static bool setGammaCorrection(F32 g);             // set gamma correction
+   static bool getVerticalSync();                     // get current state of vertical sync
    static bool setVerticalSync( bool on );            // enable/disable vertical sync
    static bool setVerticalSync( bool on );            // enable/disable vertical sync
 };
 };
 
 
@@ -129,9 +130,10 @@ class DisplayDevice
       virtual bool setResolution( U32 width, U32 height, U32 bpp );
       virtual bool setResolution( U32 width, U32 height, U32 bpp );
       virtual bool toggleFullScreen();
       virtual bool toggleFullScreen();
       virtual void swapBuffers() = 0;
       virtual void swapBuffers() = 0;
-     virtual const char* getDriverInfo() = 0;
+      virtual const char* getDriverInfo() = 0;
       virtual bool getGammaCorrection(F32 &g) = 0;
       virtual bool getGammaCorrection(F32 &g) = 0;
       virtual bool setGammaCorrection(F32 g) = 0;
       virtual bool setGammaCorrection(F32 g) = 0;
+      virtual bool getVerticalSync() = 0;
       virtual bool setVerticalSync( bool on ) = 0;
       virtual bool setVerticalSync( bool on ) = 0;
 
 
       bool prevRes();
       bool prevRes();

+ 8 - 0
engine/source/platform/platformVideo_ScriptBinding.h

@@ -254,6 +254,14 @@ ConsoleFunctionWithDocs(videoSetGammaCorrection, ConsoleVoid, 2, 2, ( gamma ))
     sgGammaCorrection = d;
     sgGammaCorrection = d;
 }
 }
 
 
+/*! Use the getVerticalSync function to determine if the application's framerate is currently synchronized to the vertical refresh rate.
+@return Returns true if Vertical sync is enabled, false otherwise
+*/
+ConsoleFunctionWithDocs(getVerticalSync, ConsoleBool, 1, 1, "")
+    {
+    return(Video::getVerticalSync());
+    }
+
 /*! Use the setVerticalSync function to force the framerate to sync up with the vertical refresh rate.
 /*! Use the setVerticalSync function to force the framerate to sync up with the vertical refresh rate.
     This is used to reduce excessive swapping/rendering. There is generally no purpose in rendering any faster than the monitor will support. Those extra 'ergs' can be used for something else
     This is used to reduce excessive swapping/rendering. There is generally no purpose in rendering any faster than the monitor will support. Those extra 'ergs' can be used for something else
     @param enable A boolean value. If set to true, the engine will only swap front and back buffers on or before a vertical refresh pass.
     @param enable A boolean value. If set to true, the engine will only swap front and back buffers on or before a vertical refresh pass.

+ 11 - 0
engine/source/platformWin32/winOGLVideo.cc

@@ -646,6 +646,17 @@ bool OpenGLDevice::setGammaCorrection(F32 g)
    return SetDeviceGammaRamp(winState.appDC, ramp);
    return SetDeviceGammaRamp(winState.appDC, ramp);
 }
 }
 
 
+//------------------------------------------------------------------------------
+bool OpenGLDevice::getVerticalSync()
+{
+    if ( !gGLState.suppSwapInterval )
+        return( false );
+
+    //Note that dwglGetSwapIntervalEXT returns the number of frames between Swaps.
+    //The function returns 0 / false if SwapInterval has not been specified.
+    return (dwglGetSwapIntervalEXT());
+}
+
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 bool OpenGLDevice::setVerticalSync( bool on )
 bool OpenGLDevice::setVerticalSync( bool on )
 {
 {

+ 1 - 0
engine/source/platformWin32/winOGLVideo.h

@@ -55,6 +55,7 @@ public:
    const char* getDriverInfo();
    const char* getDriverInfo();
    bool getGammaCorrection(F32 &g);
    bool getGammaCorrection(F32 &g);
    bool setGammaCorrection(F32 g);
    bool setGammaCorrection(F32 g);
+   bool getVerticalSync();
    bool setVerticalSync( bool on );
    bool setVerticalSync( bool on );
 
 
    static DisplayDevice* create();
    static DisplayDevice* create();