From 276fb7dbb2f43fcb0db6a5fc276495af6254316f Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 22 Aug 2016 20:03:08 +0200 Subject: [PATCH] Add vid_maxfps support for Windows and Linux --- src/posix/sdl/sdlglvideo.cpp | 7 +++++++ src/win32/win32gliface.cpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 29c96d3eae..0635002e17 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -459,6 +459,13 @@ void SDLGLFB::NewRefreshRate () void SDLGLFB::SwapBuffers() { +#ifndef __APPLE__ + if (vid_maxfps && !cl_capfps) + { + SEMAPHORE_WAIT(FPSLimitSemaphore) + } +#endif + SDL_GL_SwapWindow (Screen); } diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp index 2edd896316..bec2a19cf1 100644 --- a/src/win32/win32gliface.cpp +++ b/src/win32/win32gliface.cpp @@ -1149,6 +1149,11 @@ void Win32GLFrameBuffer::SetVSync (bool vsync) void Win32GLFrameBuffer::SwapBuffers() { + // Limiting the frame rate is as simple as waiting for the timer to signal this event. + if (FPSLimitEvent != NULL) + { + WaitForSingleObject(FPSLimitEvent, 1000); + } ::SwapBuffers(static_cast(Video)->m_hDC); }