diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-01-16 16:43:18 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-02-22 22:16:07 +0100 |
commit | b1818596294346a87bcb2ddb23d0b471c5c31284 (patch) | |
tree | 38cd657acb71ded902050cf05a0f11601838c738 | |
parent | 9a069faa0135b02f3ea8601594e174ada73fcd74 (diff) | |
download | openttd-b1818596294346a87bcb2ddb23d0b471c5c31284.tar.xz |
Change: [Win32] Disable VSync for OpenGL by default.
-rw-r--r-- | src/video/win32_v.cpp | 12 | ||||
-rw-r--r-- | src/video/win32_v.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 975fee974..e32b80497 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1328,6 +1328,7 @@ void VideoDriver_Win32GDI::PaintThread() #endif static PFNWGLCREATECONTEXTATTRIBSARBPROC _wglCreateContextAttribsARB = nullptr; +static PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = nullptr; static bool _hasWGLARBCreateContextProfile = false; ///< Is WGL_ARB_create_context_profile supported? /** Platform-specific callback to get an OpenGL funtion pointer. */ @@ -1398,6 +1399,9 @@ static void LoadWGLExtensions() _wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); } _hasWGLARBCreateContextProfile = FindStringInExtensionList(wgl_exts, "WGL_ARB_create_context_profile") != nullptr; + if (FindStringInExtensionList(wgl_exts, "WGL_EXT_swap_control") != nullptr) { + _wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); + } } wglMakeCurrent(nullptr, nullptr); @@ -1416,6 +1420,7 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList ¶m) if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 32) return "Only 32bpp blitters supported"; Dimension old_res = _cur_resolution; // Save current screen resolution in case of errors, as MakeWindow invalidates it. + this->vsync = GetDriverParamBool(param, "vsync"); LoadWGLExtensions(); @@ -1487,6 +1492,13 @@ const char *VideoDriver_Win32OpenGL::AllocateContext() } if (!wglMakeCurrent(this->dc, rc)) return "Can't active GL context"; + /* Enable/disable Vsync if supported. */ + if (_wglSwapIntervalEXT != nullptr) { + _wglSwapIntervalEXT(this->vsync ? 1 : 0); + } else if (vsync) { + DEBUG(driver, 0, "OpenGL: Vsync requested, but not supported by driver"); + } + this->gl_rc = rc; return OpenGLBackend::Create(&GetOGLProcAddressCallback); } diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 061f39c0a..1ec3517d1 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -143,6 +143,7 @@ public: protected: HDC dc; ///< Window device context. HGLRC gl_rc; ///< OpenGL context. + bool vsync; ///< Enable VSync? uint8 GetFullscreenBpp() override { return 32; } // OpenGL is always 32 bpp. |