You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Added support for vertical syncing via the Windows OS compositor (DWM.)
This commit is contained in:
committed by
Rémi Verschelde
parent
10481046e5
commit
e1dda5195c
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user