summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTerminalJack <TerminalJack@sbcglobal.net>2019-11-06 20:18:55 -0600
committerRémi Verschelde <rverschelde@gmail.com>2019-12-04 11:14:21 +0100
commite1dda5195cb2b8620a61740e8491cbb243aa653c (patch)
tree82a09611dfef0b3855b880f970ec9af7563f4fb1 /platform
parent10481046e52cbb7a90dd084fc51633388ba7ea6e (diff)
Added support for vertical syncing via the Windows OS compositor (DWM.)
Diffstat (limited to 'platform')
-rw-r--r--platform/windows/context_gl_windows.cpp41
-rw-r--r--platform/windows/context_gl_windows.h3
-rw-r--r--platform/windows/detect.py5
-rwxr-xr-xplatform/windows/os_windows.cpp1
4 files changed, 47 insertions, 3 deletions
diff --git a/platform/windows/context_gl_windows.cpp b/platform/windows/context_gl_windows.cpp
index e715999378..34a5698394 100644
--- a/platform/windows/context_gl_windows.cpp
+++ b/platform/windows/context_gl_windows.cpp
@@ -34,6 +34,8 @@
#include "context_gl_windows.h"
+#include <dwmapi.h>
+
#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092
#define WGL_CONTEXT_FLAGS_ARB 0x2094
@@ -63,16 +65,52 @@ int ContextGL_Windows::get_window_height() {
return OS::get_singleton()->get_video_mode().height;
}
+bool ContextGL_Windows::should_vsync_via_compositor() {
+
+ if (OS::get_singleton()->is_window_fullscreen() || !OS::get_singleton()->is_vsync_via_compositor_enabled()) {
+ return false;
+ }
+
+ // Note: All Windows versions supported by Godot have a compositor.
+ // It can be disabled on earlier Windows versions.
+ BOOL dwm_enabled;
+
+ if (SUCCEEDED(DwmIsCompositionEnabled(&dwm_enabled))) {
+ return dwm_enabled;
+ }
+
+ return false;
+}
+
void ContextGL_Windows::swap_buffers() {
SwapBuffers(hDC);
+
+ if (use_vsync) {
+ bool vsync_via_compositor_now = should_vsync_via_compositor();
+
+ if (vsync_via_compositor_now) {
+ DwmFlush();
+ }
+
+ if (vsync_via_compositor_now != vsync_via_compositor) {
+ // The previous frame had a different operating mode than this
+ // frame. Set the 'vsync_via_compositor' member variable and the
+ // OpenGL swap interval to their proper values.
+ set_use_vsync(true);
+ }
+ }
}
void ContextGL_Windows::set_use_vsync(bool p_use) {
+ vsync_via_compositor = p_use && should_vsync_via_compositor();
+
if (wglSwapIntervalEXT) {
- wglSwapIntervalEXT(p_use ? 1 : 0);
+ int swap_interval = (p_use && !vsync_via_compositor) ? 1 : 0;
+ wglSwapIntervalEXT(swap_interval);
}
+
use_vsync = p_use;
}
@@ -177,6 +215,7 @@ ContextGL_Windows::ContextGL_Windows(HWND hwnd, bool p_opengl_3_context) {
opengl_3_context = p_opengl_3_context;
hWnd = hwnd;
use_vsync = false;
+ vsync_via_compositor = false;
}
ContextGL_Windows::~ContextGL_Windows() {
diff --git a/platform/windows/context_gl_windows.h b/platform/windows/context_gl_windows.h
index d23fba50e1..e65ea1928f 100644
--- a/platform/windows/context_gl_windows.h
+++ b/platform/windows/context_gl_windows.h
@@ -50,9 +50,12 @@ class ContextGL_Windows {
HWND hWnd;
bool opengl_3_context;
bool use_vsync;
+ bool vsync_via_compositor;
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
+ static bool should_vsync_via_compositor();
+
public:
void release_current();
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 9a2b2bcb98..b37a21f37f 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -221,7 +221,8 @@ def configure_msvc(env, manual_msvc_config):
LIBS = ['winmm', 'opengl32', 'dsound', 'kernel32', 'ole32', 'oleaut32',
'user32', 'gdi32', 'IPHLPAPI', 'Shlwapi', 'wsock32', 'Ws2_32',
- 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt','Avrt']
+ 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt','Avrt',
+ 'dwmapi']
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS])
if manual_msvc_config:
@@ -348,7 +349,7 @@ def configure_mingw(env):
env.Append(CCFLAGS=['-mwindows'])
env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'OPENGL_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
env.Append(CPPDEFINES=[('WINVER', env['target_win_version']), ('_WIN32_WINNT', env['target_win_version'])])
- env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid'])
+ env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
env.Append(CPPDEFINES=['MINGW_ENABLED', ('MINGW_HAS_SECURE_API', 1)])
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 9c1514f541..f749134f3c 100755
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1480,6 +1480,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
video_driver_index = p_video_driver;
gl_context->set_use_vsync(video_mode.use_vsync);
+ set_vsync_via_compositor(video_mode.vsync_via_compositor);
#endif
visual_server = memnew(VisualServerRaster);