mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Windows: reduce stuttering in windowed mode via DwmFlush
Resolves issue #1628
This commit is contained in:
@@ -1741,6 +1741,7 @@ if(MSVC)
|
|||||||
set(LOVE_LINK_LIBRARIES ${LOVE_LINK_LIBRARIES}
|
set(LOVE_LINK_LIBRARIES ${LOVE_LINK_LIBRARIES}
|
||||||
ws2_32.lib
|
ws2_32.lib
|
||||||
winmm.lib
|
winmm.lib
|
||||||
|
dwmapi.lib
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LOVE_RC
|
set(LOVE_RC
|
||||||
|
|||||||
@@ -44,6 +44,8 @@
|
|||||||
|
|
||||||
#if defined(LOVE_WINDOWS)
|
#if defined(LOVE_WINDOWS)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <dwmapi.h>
|
||||||
|
#include <VersionHelpers.h>
|
||||||
#elif defined(LOVE_MACOSX)
|
#elif defined(LOVE_MACOSX)
|
||||||
#include "common/macosx.h"
|
#include "common/macosx.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -1010,6 +1012,22 @@ bool Window::isMinimized() const
|
|||||||
void Window::swapBuffers()
|
void Window::swapBuffers()
|
||||||
{
|
{
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
|
|
||||||
|
#ifdef LOVE_WINDOWS
|
||||||
|
// https://github.com/love2d/love/issues/1628
|
||||||
|
// DwmFlush helps avoid apparent stuttering in windowed mode on Windows. Be careful to only call it when
|
||||||
|
// the compositor may be active and non-adaptive vsync is enabled (it syncs to nearest refresh which stops the
|
||||||
|
// "adaptive" part of adaptive vsync).
|
||||||
|
// Calling it directly after vsync seems to have less chance of dropping a frame than directly before.
|
||||||
|
if (context != nullptr && (!settings.fullscreen || settings.fstype == FULLSCREEN_DESKTOP) && getVSync() > 0)
|
||||||
|
{
|
||||||
|
// Desktop composition is always enabled in Windows 8+. But DwmIsCompositionEnabled won't always return true...
|
||||||
|
// (see DwmIsCompositionEnabled docs).
|
||||||
|
BOOL compositionEnabled = IsWindows8OrGreater();
|
||||||
|
if (compositionEnabled || (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled)) && compositionEnabled))
|
||||||
|
DwmFlush();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::hasFocus() const
|
bool Window::hasFocus() const
|
||||||
|
|||||||
Reference in New Issue
Block a user