From 23a0e1251e276c28680fdfd364113f325ccda7d1 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Tue, 5 Mar 2019 14:25:50 -0600 Subject: [PATCH] win32:opengl: Use DWM sync in windowed, Vsync in fullscreen exclusive. --- win32/COpenGL.cpp | 6 ++++++ win32/COpenGL.h | 3 ++- win32/win32_display.cpp | 19 ++++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/win32/COpenGL.cpp b/win32/COpenGL.cpp index b06b67a8..a9cb58a2 100644 --- a/win32/COpenGL.cpp +++ b/win32/COpenGL.cpp @@ -384,6 +384,12 @@ bool COpenGL::ChangeRenderSize(unsigned int newWidth, unsigned int newHeight) return true; } +void COpenGL::SetSwapInterval(int frames) +{ + if (wglSwapIntervalEXT) + wglSwapIntervalEXT(frames); +} + bool COpenGL::ApplyDisplayChanges(void) { if(wglSwapIntervalEXT) { diff --git a/win32/COpenGL.h b/win32/COpenGL.h index b01a5df2..20cf2971 100644 --- a/win32/COpenGL.h +++ b/win32/COpenGL.h @@ -81,7 +81,8 @@ public: bool ApplyDisplayChanges(void); bool SetFullscreen(bool fullscreen); void SetSnes9xColorFormat(void); - void EnumModes(std::vector *modeVector); + void EnumModes(std::vector *modeVector); + void SetSwapInterval(int frames); GLSLShader *GetActiveShader() { return glslShader; diff --git a/win32/win32_display.cpp b/win32/win32_display.cpp index 10d487d7..5e413743 100644 --- a/win32/win32_display.cpp +++ b/win32/win32_display.cpp @@ -286,17 +286,26 @@ bool8 S9xDeinitUpdate (int Width, int Height) LastWidth = Width; LastHeight = Height; } - - WinRefreshDisplay(); - if (GUI.DWMSync) + if (GUI.DWMSync && GUI.outputMethod == OPENGL) { BOOL DWMEnabled = false; - DwmIsCompositionEnabledProc(&DWMEnabled); - if (DWMEnabled) + + if (GUI.FullScreen || !DWMEnabled) + ((COpenGL *)S9xDisplayOutput)->SetSwapInterval(GUI.Vsync ? 1 : 0); + else + ((COpenGL *)S9xDisplayOutput)->SetSwapInterval(0); + + WinRefreshDisplay(); + + if (DWMEnabled && !GUI.FullScreen) DwmFlushProc(); } + else + { + WinRefreshDisplay(); + } return (true); }