From 1e18c3fb9f45afbd9dce4c86b6c942eea8ab5a71 Mon Sep 17 00:00:00 2001 From: rogerman Date: Mon, 19 Nov 2018 02:49:31 -0800 Subject: [PATCH] Windows Port: When running OpenGL display method, properly initialize V-sync to match wantVsync rather than assuming that the default setting for wantVsync will match the default setting of the video driver. --- desmume/src/frontend/windows/ogl_display.cpp | 23 +++++++++++++++----- desmume/src/frontend/windows/ogl_display.h | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) mode change 100644 => 100755 desmume/src/frontend/windows/ogl_display.cpp mode change 100644 => 100755 desmume/src/frontend/windows/ogl_display.h diff --git a/desmume/src/frontend/windows/ogl_display.cpp b/desmume/src/frontend/windows/ogl_display.cpp old mode 100644 new mode 100755 index 107f8ef38..acba8d611 --- a/desmume/src/frontend/windows/ogl_display.cpp +++ b/desmume/src/frontend/windows/ogl_display.cpp @@ -26,6 +26,17 @@ bool GLDISPLAY::initialize(HWND hwnd) if (initContext(hwnd, &privateContext)) { this->hwnd = hwnd; + privateDC = GetDC(hwnd); + wglMakeCurrent(privateDC, privateContext); + + // Certain video drivers may try to set the V-sync setting to whatever they want on + // initialization, and so we can't assume that wantVsync will match whatever the video + // driver is doing. + // + // And so we need to force the V-sync to be whatever default value wantVsync is in + // order to ensure that the actual V-sync setting in OpenGL matches wantVsync. + this->_setvsync(wantVsync); + return true; } else @@ -49,11 +60,8 @@ bool GLDISPLAY::WGLExtensionSupported(const char *extension_name) // extension is supported return true; } -void GLDISPLAY::_setvsync() +void GLDISPLAY::_setvsync(bool isVsyncEnabled) { - //even if it doesn't work, we'll track it - haveVsync = wantVsync; - if (!WGLExtensionSupported("WGL_EXT_swap_control")) return; //http://stackoverflow.com/questions/589064/how-to-enable-vertical-sync-in-opengl @@ -67,7 +75,7 @@ void GLDISPLAY::_setvsync() wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT"); } - wglSwapIntervalEXT(wantVsync ? 1 : 0); + wglSwapIntervalEXT(isVsyncEnabled ? 1 : 0); } @@ -105,7 +113,10 @@ bool GLDISPLAY::begin(HWND hwnd) //go ahead and sync the vsync setting while we have the context if (wantVsync != haveVsync) - _setvsync(); + { + _setvsync(wantVsync); + haveVsync = wantVsync; + } if (filter) { diff --git a/desmume/src/frontend/windows/ogl_display.h b/desmume/src/frontend/windows/ogl_display.h old mode 100644 new mode 100755 index 0b84c26c9..6627db26e --- a/desmume/src/frontend/windows/ogl_display.h +++ b/desmume/src/frontend/windows/ogl_display.h @@ -34,7 +34,7 @@ private: HWND hwnd; bool initialize(HWND hwnd); bool WGLExtensionSupported(const char *extension_name); - void _setvsync(); + void _setvsync(bool isVsyncEnabled); public: bool active;