win: improve fps timing and fix glfw vsync
parent
80f773ec01
commit
c7c347fa90
|
@ -56017,14 +56017,12 @@ static void swapBuffersWGL(_GLFWwindow* window)
|
|||
{
|
||||
if (!window->monitor)
|
||||
{
|
||||
if (IsWindowsVistaOrGreater())
|
||||
// HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7
|
||||
if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater())
|
||||
{
|
||||
// DWM Composition is always enabled on Win8+
|
||||
BOOL enabled = IsWindows8OrGreater();
|
||||
BOOL enabled = FALSE;
|
||||
|
||||
// HACK: Use DwmFlush when desktop composition is enabled
|
||||
if (enabled ||
|
||||
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
||||
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
{
|
||||
int count = abs(window->context.wgl.interval);
|
||||
while (count--)
|
||||
|
@ -56039,20 +56037,19 @@ static void swapBuffersWGL(_GLFWwindow* window)
|
|||
static void swapIntervalWGL(int interval)
|
||||
{
|
||||
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
|
||||
assert(window != NULL);
|
||||
|
||||
window->context.wgl.interval = interval;
|
||||
|
||||
if (!window->monitor)
|
||||
{
|
||||
if (IsWindowsVistaOrGreater())
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled on Windows
|
||||
// Vista and 7 to avoid interfering with DWM vsync
|
||||
if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater())
|
||||
{
|
||||
// DWM Composition is always enabled on Win8+
|
||||
BOOL enabled = IsWindows8OrGreater();
|
||||
BOOL enabled = FALSE;
|
||||
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
||||
// avoid interfering with DWM vsync
|
||||
if (enabled ||
|
||||
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
||||
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
interval = 0;
|
||||
}
|
||||
}
|
||||
|
@ -379093,7 +379090,8 @@ int fps__timing_thread(void *arg) {
|
|||
int64_t tt = (int64_t)(1e9/(float)framerate) - ns_excess;
|
||||
uint64_t took = -time_ns();
|
||||
#if is(win32)
|
||||
timeBeginPeriod(1); Sleep( tt > 0 ? tt/1e6 : 0 );
|
||||
do_once timeBeginPeriod(1);
|
||||
sleep_ns( (float)tt );
|
||||
#else
|
||||
sleep_ns( (float)tt );
|
||||
#endif
|
||||
|
@ -379452,7 +379450,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) {
|
|||
//glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate)
|
||||
flags |= optioni("--vsync", 1) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||
flags |= optioni("--vsync", 0) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||
flags |= optioni("--vsync-adaptive", 0) || flag("--vsync-adaptive") ? WINDOW_VSYNC_ADAPTIVE : 0;
|
||||
int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear");
|
||||
int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE);
|
||||
|
|
|
@ -23097,14 +23097,12 @@ static void swapBuffersWGL(_GLFWwindow* window)
|
|||
{
|
||||
if (!window->monitor)
|
||||
{
|
||||
if (IsWindowsVistaOrGreater())
|
||||
// HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7
|
||||
if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater())
|
||||
{
|
||||
// DWM Composition is always enabled on Win8+
|
||||
BOOL enabled = IsWindows8OrGreater();
|
||||
BOOL enabled = FALSE;
|
||||
|
||||
// HACK: Use DwmFlush when desktop composition is enabled
|
||||
if (enabled ||
|
||||
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
||||
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
{
|
||||
int count = abs(window->context.wgl.interval);
|
||||
while (count--)
|
||||
|
@ -23119,20 +23117,19 @@ static void swapBuffersWGL(_GLFWwindow* window)
|
|||
static void swapIntervalWGL(int interval)
|
||||
{
|
||||
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
|
||||
assert(window != NULL);
|
||||
|
||||
window->context.wgl.interval = interval;
|
||||
|
||||
if (!window->monitor)
|
||||
{
|
||||
if (IsWindowsVistaOrGreater())
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled on Windows
|
||||
// Vista and 7 to avoid interfering with DWM vsync
|
||||
if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater())
|
||||
{
|
||||
// DWM Composition is always enabled on Win8+
|
||||
BOOL enabled = IsWindows8OrGreater();
|
||||
BOOL enabled = FALSE;
|
||||
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
||||
// avoid interfering with DWM vsync
|
||||
if (enabled ||
|
||||
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
||||
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
interval = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ int fps__timing_thread(void *arg) {
|
|||
int64_t tt = (int64_t)(1e9/(float)framerate) - ns_excess;
|
||||
uint64_t took = -time_ns();
|
||||
#if is(win32)
|
||||
timeBeginPeriod(1); Sleep( tt > 0 ? tt/1e6 : 0 );
|
||||
do_once timeBeginPeriod(1);
|
||||
sleep_ns( (float)tt );
|
||||
#else
|
||||
sleep_ns( (float)tt );
|
||||
#endif
|
||||
|
@ -374,7 +375,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) {
|
|||
//glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate)
|
||||
flags |= optioni("--vsync", 1) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||
flags |= optioni("--vsync", 0) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||
flags |= optioni("--vsync-adaptive", 0) || flag("--vsync-adaptive") ? WINDOW_VSYNC_ADAPTIVE : 0;
|
||||
int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear");
|
||||
int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE);
|
||||
|
|
23
engine/v4k
23
engine/v4k
|
@ -37132,14 +37132,12 @@ static void swapBuffersWGL(_GLFWwindow* window)
|
|||
{
|
||||
if (!window->monitor)
|
||||
{
|
||||
if (IsWindowsVistaOrGreater())
|
||||
// HACK: Use DwmFlush when desktop composition is enabled on Windows Vista and 7
|
||||
if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater())
|
||||
{
|
||||
// DWM Composition is always enabled on Win8+
|
||||
BOOL enabled = IsWindows8OrGreater();
|
||||
BOOL enabled = FALSE;
|
||||
|
||||
// HACK: Use DwmFlush when desktop composition is enabled
|
||||
if (enabled ||
|
||||
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
||||
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
{
|
||||
int count = abs(window->context.wgl.interval);
|
||||
while (count--)
|
||||
|
@ -37154,20 +37152,19 @@ static void swapBuffersWGL(_GLFWwindow* window)
|
|||
static void swapIntervalWGL(int interval)
|
||||
{
|
||||
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
|
||||
assert(window != NULL);
|
||||
|
||||
window->context.wgl.interval = interval;
|
||||
|
||||
if (!window->monitor)
|
||||
{
|
||||
if (IsWindowsVistaOrGreater())
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled on Windows
|
||||
// Vista and 7 to avoid interfering with DWM vsync
|
||||
if (!IsWindows8OrGreater() && IsWindowsVistaOrGreater())
|
||||
{
|
||||
// DWM Composition is always enabled on Win8+
|
||||
BOOL enabled = IsWindows8OrGreater();
|
||||
BOOL enabled = FALSE;
|
||||
|
||||
// HACK: Disable WGL swap interval when desktop composition is enabled to
|
||||
// avoid interfering with DWM vsync
|
||||
if (enabled ||
|
||||
(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled))
|
||||
if (SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
interval = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26234,7 +26234,8 @@ int fps__timing_thread(void *arg) {
|
|||
int64_t tt = (int64_t)(1e9/(float)framerate) - ns_excess;
|
||||
uint64_t took = -time_ns();
|
||||
#if is(win32)
|
||||
timeBeginPeriod(1); Sleep( tt > 0 ? tt/1e6 : 0 );
|
||||
do_once timeBeginPeriod(1);
|
||||
sleep_ns( (float)tt );
|
||||
#else
|
||||
sleep_ns( (float)tt );
|
||||
#endif
|
||||
|
@ -26593,7 +26594,7 @@ bool window_create_from_handle(void *handle, float scale, unsigned flags) {
|
|||
//glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// 0:disable vsync, 1:enable vsync, <0:adaptive (allow vsync when framerate is higher than syncrate and disable vsync when framerate drops below syncrate)
|
||||
flags |= optioni("--vsync", 1) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||
flags |= optioni("--vsync", 0) || flag("--vsync") ? WINDOW_VSYNC : WINDOW_VSYNC_DISABLED;
|
||||
flags |= optioni("--vsync-adaptive", 0) || flag("--vsync-adaptive") ? WINDOW_VSYNC_ADAPTIVE : 0;
|
||||
int has_adaptive_vsync = glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear") || glfwExtensionSupported("EXT_swap_control_tear");
|
||||
int wants_adaptive_vsync = (flags & WINDOW_VSYNC_ADAPTIVE);
|
||||
|
|
Loading…
Reference in New Issue