mirror of
https://github.com/glfw/glfw.git
synced 2026-09-19 23:43:15 +00:00
Use DwmFlush when DWM is enabled.
Use DwmFlush instead of WGL_EXT_swap_control when desktop compositing is enabled, to avoid the jitter of DWM and WGL vsync fighting. Fixes #516.
This commit is contained in:
@@ -57,8 +57,6 @@
|
||||
// Define this to 1 if building as a shared library / dynamic library / DLL
|
||||
#cmakedefine _GLFW_BUILD_DLL
|
||||
|
||||
// Define this to 1 if glfwSwapInterval should ignore DWM compositing status
|
||||
#cmakedefine _GLFW_USE_DWM_SWAP_INTERVAL
|
||||
// Define this to 1 to force use of high-performance GPU on Optimus systems
|
||||
#cmakedefine _GLFW_USE_OPTIMUS_HPG
|
||||
|
||||
|
||||
+14
-6
@@ -570,6 +570,14 @@ void _glfwPlatformMakeContextCurrent(_GLFWwindow* window)
|
||||
|
||||
void _glfwPlatformSwapBuffers(_GLFWwindow* window)
|
||||
{
|
||||
// HACK: Use DwmFlush when desktop composition is enabled
|
||||
if (_glfwIsCompositionEnabled())
|
||||
{
|
||||
int count = window->wgl.interval;
|
||||
while (count--)
|
||||
_glfw_DwmFlush();
|
||||
}
|
||||
|
||||
SwapBuffers(window->wgl.dc);
|
||||
}
|
||||
|
||||
@@ -577,12 +585,12 @@ void _glfwPlatformSwapInterval(int interval)
|
||||
{
|
||||
_GLFWwindow* window = _glfwPlatformGetCurrentContext();
|
||||
|
||||
#if !defined(_GLFW_USE_DWM_SWAP_INTERVAL)
|
||||
// HACK: Don't enabled vsync when desktop compositing is enabled, as it
|
||||
// leads to severe frame jitter on some cards
|
||||
if (_glfwIsCompositionEnabled() && interval)
|
||||
return;
|
||||
#endif
|
||||
window->wgl.interval = interval;
|
||||
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
||||
// avoid interfering with DWM vsync
|
||||
if (_glfwIsCompositionEnabled())
|
||||
interval = 0;
|
||||
|
||||
if (window->wgl.EXT_swap_control)
|
||||
window->wgl.SwapIntervalEXT(interval);
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef struct _GLFWcontextWGL
|
||||
{
|
||||
HDC dc; // Private GDI device context
|
||||
HGLRC context; // Permanent rendering context
|
||||
int interval;
|
||||
|
||||
// WGL extensions (context specific)
|
||||
PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT;
|
||||
|
||||
@@ -96,6 +96,8 @@ static GLboolean initLibraries(void)
|
||||
{
|
||||
_glfw.win32.dwmapi.DwmIsCompositionEnabled = (DWMISCOMPOSITIONENABLED_T)
|
||||
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmIsCompositionEnabled");
|
||||
_glfw.win32.dwmapi.DwmFlush = (DWMFLUSH_T)
|
||||
GetProcAddress(_glfw.win32.dwmapi.instance, "DwmFlush");
|
||||
}
|
||||
|
||||
return GL_TRUE;
|
||||
|
||||
@@ -121,7 +121,9 @@ typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFIL
|
||||
|
||||
// dwmapi.dll function pointer typedefs
|
||||
typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*);
|
||||
typedef HRESULT (WINAPI * DWMFLUSH_T)(VOID);
|
||||
#define _glfw_DwmIsCompositionEnabled _glfw.win32.dwmapi.DwmIsCompositionEnabled
|
||||
#define _glfw_DwmFlush _glfw.win32.dwmapi.DwmFlush
|
||||
|
||||
|
||||
#define _GLFW_RECREATION_NOT_NEEDED 0
|
||||
@@ -195,6 +197,7 @@ typedef struct _GLFWlibraryWin32
|
||||
struct {
|
||||
HINSTANCE instance;
|
||||
DWMISCOMPOSITIONENABLED_T DwmIsCompositionEnabled;
|
||||
DWMFLUSH_T DwmFlush;
|
||||
} dwmapi;
|
||||
|
||||
} _GLFWlibraryWin32;
|
||||
|
||||
+6
-9
@@ -565,15 +565,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
case WM_DWMCOMPOSITIONCHANGED:
|
||||
{
|
||||
if (_glfwIsCompositionEnabled())
|
||||
{
|
||||
_GLFWwindow* previous = _glfwPlatformGetCurrentContext();
|
||||
_glfwPlatformMakeContextCurrent(window);
|
||||
_glfwPlatformSwapInterval(0);
|
||||
_glfwPlatformMakeContextCurrent(previous);
|
||||
}
|
||||
|
||||
// TODO: Restore vsync if compositing was disabled
|
||||
// HACK: Re-apply interval when desktop composition is toggled to
|
||||
// ensure WGL swap interval is disabled when necessary
|
||||
_GLFWwindow* previous = _glfwPlatformGetCurrentContext();
|
||||
_glfwPlatformMakeContextCurrent(window);
|
||||
_glfwPlatformSwapInterval(window->wgl.interval);
|
||||
_glfwPlatformMakeContextCurrent(previous);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user