From 9f48927ea87b08a6c7b6c1cb886bb606d0030236 Mon Sep 17 00:00:00 2001 From: pogokeen Date: Thu, 22 Feb 2018 23:25:56 +0000 Subject: [PATCH] sdlayer.cpp: fix vsync heartbeat issue on some NVidia & Intel drivers git-svn-id: https://svn.eduke32.com/eduke32@6689 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/src/sdlayer.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index f181eefc4..ca410f969 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -101,6 +101,7 @@ char nogl=0; #endif static int32_t vsync_renderlayer; int32_t maxrefreshfreq=0; +static uint32_t currentVBlankInterval=0; // last gamma, contrast, brightness static float lastvidgcb[3]; @@ -1521,6 +1522,8 @@ void setrefreshrate(void) initprintf("Refresh rate: %dHz\n", newmode.refresh_rate); SDL_SetWindowDisplayMode(sdl_window, &newmode); } + + currentVBlankInterval = 1000/newmode.refresh_rate; } static void sdl_trycreaterenderer_fail(char const * const failurepoint) @@ -1789,7 +1792,15 @@ void showframe(int32_t w) #ifdef __ANDROID__ AndroidDrawControls(); #endif + + static uint32_t lastSwapTime = 0; SDL_GL_SwapWindow(sdl_window); + if (vsync) + { + // busy loop until we're ready to update again + while (SDL_GetTicks()-lastSwapTime < currentVBlankInterval) {} + } + lastSwapTime = SDL_GetTicks(); return; } #endif