From e782b6f20e2ba87f062ea20d73fa6e13991ccefb Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 16 Jun 2013 23:45:06 +0200 Subject: [PATCH] Add VSync option in Windows. Turns itself off when unthrottled. --- Core/Config.cpp | 2 ++ Core/Config.h | 1 + GPU/GLES/DisplayListInterpreter.cpp | 15 +++++++++++++-- GPU/GLES/DisplayListInterpreter.h | 1 + Windows/OpenGLBase.cpp | 21 +++++---------------- Windows/OpenGLBase.h | 1 + Windows/WndMainWindow.cpp | 5 +++++ Windows/ppsspp.rc | Bin 39448 -> 39580 bytes Windows/resource.h | Bin 22786 -> 22882 bytes native | 2 +- 10 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index f9c793b871..6db53a4567 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -123,6 +123,7 @@ void Config::Load(const char *iniFileName) graphics->Get("TexScalingLevel", &iTexScalingLevel, 1); graphics->Get("TexScalingType", &iTexScalingType, 0); graphics->Get("TexDeposterize", &bTexDeposterize, false); + graphics->Get("VSyncInterval", &iVSyncInterval, 0); IniFile::Section *sound = iniFile.GetOrCreateSection("Sound"); sound->Get("Enable", &bEnableSound, true); @@ -221,6 +222,7 @@ void Config::Save() graphics->Set("TexScalingLevel", iTexScalingLevel); graphics->Set("TexScalingType", iTexScalingType); graphics->Set("TexDeposterize", bTexDeposterize); + graphics->Set("VSyncInterval", iVSyncInterval); IniFile::Section *sound = iniFile.GetOrCreateSection("Sound"); sound->Set("Enable", bEnableSound); diff --git a/Core/Config.h b/Core/Config.h index 43a9f61239..1b2347e05d 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -67,6 +67,7 @@ public: bool bPartialStretch; #endif bool bStretchToDisplay; + int iVSyncInterval; int iFrameSkip; int iWindowX; diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index 59434680b5..118575425e 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -172,8 +172,10 @@ static const u8 flushBeforeCommandList[] = { }; GLES_GPU::GLES_GPU() -: resized_(false) -{ +: resized_(false) { + lastVsync_ = g_Config.iVSyncInterval; + glstate.SetVSyncInterval(g_Config.iVSyncInterval); + shaderManager_ = new ShaderManager(); transformDraw_.SetShaderManager(shaderManager_); transformDraw_.SetTextureCache(&textureCache_); @@ -251,6 +253,15 @@ void GLES_GPU::DumpNextFrame() { } void GLES_GPU::BeginFrame() { + // Turn off vsync when unthrottled + int desiredVSyncInterval = g_Config.iVSyncInterval; + if (PSP_CoreParameter().unthrottle) + desiredVSyncInterval = 0; + if (desiredVSyncInterval != lastVsync_) { + glstate.SetVSyncInterval(desiredVSyncInterval); + lastVsync_ = desiredVSyncInterval; + } + textureCache_.StartFrame(); transformDraw_.DecimateTrackedVertexArrays(); diff --git a/GPU/GLES/DisplayListInterpreter.h b/GPU/GLES/DisplayListInterpreter.h index d8340abc60..f1da2ea9c0 100644 --- a/GPU/GLES/DisplayListInterpreter.h +++ b/GPU/GLES/DisplayListInterpreter.h @@ -83,6 +83,7 @@ private: u8 *flushBeforeCommand_; bool resized_; + int lastVsync_; std::string reportingPrimaryInfo_; std::string reportingFullInfo_; diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index ee271bfc00..34092506a6 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -8,29 +8,21 @@ #include "OpenGLBase.h" -static HDC hDC=NULL; // Private GDI Device Context -static HGLRC hRC=NULL; // Permanent Rendering Context -static HWND hWnd=NULL; // Holds Our Window Handle -static HINSTANCE hInstance; // Holds The Instance Of The Application +static HDC hDC; // Private GDI Device Context +static HGLRC hRC; // Permanent Rendering Context +static HWND hWnd; // Holds Our Window Handle static int xres, yres; // TODO: Make config? static bool enableGLDebug = false; - -//typedef BOOL (APIENTRY *PFNWGLSWAPINTERVALFARPROC)( int ); -//static PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0; - -void setVSync(int interval=1) +void GL_SetVSyncInterval(int interval=1) { - const char *extensions = (const char *)glGetString( GL_EXTENSIONS ); - if( wglSwapIntervalEXT ) wglSwapIntervalEXT(interval); } -// Resize And Initialize The GL Window void GL_Resized() { if (!hWnd) return; @@ -39,8 +31,6 @@ void GL_Resized() { xres = rc.right - rc.left; //account for border :P yres = rc.bottom - rc.top; - //swidth=width; // Set Scissor Width To Window Width - //sheight=height; // Set Scissor Height To Window Height if (yres == 0) yres = 1; glstate.viewport.set(0, 0, xres, yres); @@ -105,7 +95,6 @@ bool GL_Init(HWND window, std::string *error_message) { hWnd = window; GLuint PixelFormat; - hInstance = GetModuleHandle(NULL); static const PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number @@ -205,7 +194,7 @@ bool GL_Init(HWND window, std::string *error_message) { glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1]); glstate.Initialize(); - setVSync(0); + GL_SetVSyncInterval(0); if (enableGLDebug && glewIsSupported("GL_ARB_debug_output")) { glDebugMessageCallbackARB((GLDEBUGPROCARB)&DebugCallbackARB, 0); // print debug output to stderr glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); diff --git a/Windows/OpenGLBase.h b/Windows/OpenGLBase.h index bf19199b49..a946a16039 100644 --- a/Windows/OpenGLBase.h +++ b/Windows/OpenGLBase.h @@ -6,6 +6,7 @@ #include bool GL_Init(HWND window, std::string *error_message); + void GL_Shutdown(); void GL_Resized(); void GL_SwapBuffers(); diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 23cbe0b860..34a0176c77 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -586,6 +586,10 @@ namespace MainWindow g_Config.bMipMap = !g_Config.bMipMap; break; + case ID_OPTIONS_VSYNC: + g_Config.iVSyncInterval = !g_Config.iVSyncInterval; + break; + case ID_TEXTURESCALING_OFF: setTexScalingLevel(1); break; @@ -897,6 +901,7 @@ namespace MainWindow CHECKITEM(ID_OPTIONS_SHOWFPS, g_Config.bShowFPSCounter); CHECKITEM(ID_OPTIONS_FRAMESKIP, g_Config.iFrameSkip != 0); CHECKITEM(ID_OPTIONS_MIPMAP, g_Config.bMipMap); + CHECKITEM(ID_OPTIONS_VSYNC, g_Config.iVSyncInterval != 0); CHECKITEM(ID_OPTIONS_TOPMOST, g_Config.bTopMost); CHECKITEM(ID_EMULATION_SOUND, g_Config.bEnableSound); CHECKITEM(ID_TEXTURESCALING_DEPOSTERIZE, g_Config.bTexDeposterize); diff --git a/Windows/ppsspp.rc b/Windows/ppsspp.rc index e7bb609c133761baabf39f55a4cd29e7fb811450..8520b2b3e522bb9b8a93f16b2c9aa0cdf646d18d 100644 GIT binary patch delta 52 zcmbQSg=x-KrVU-ylLJyjxWgEN8Ppgm8S)sCCpTuAPZlT=-~@?9GWan#Po5|yy1A>m GPYwXS%R9Qd1U_ K;8z%vR9LRWjS+$X delta 33 pcmaE~iLq%Dj3P$4Nw38 diff --git a/native b/native index bebb3ae397..4c2f26ff35 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit bebb3ae397212883cf3c51a93ef803b72aca1860 +Subproject commit 4c2f26ff35b9833752d956a97265261f1e149e58