From 17ed585c1f1edc94fa3a0c695bbedf40447a95de Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 19 Nov 2016 12:30:58 +0100 Subject: [PATCH] Fix vsync not working --- src/gl/system/gl_swframebuffer.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/gl/system/gl_swframebuffer.cpp b/src/gl/system/gl_swframebuffer.cpp index 0d82aa221..38d7d3679 100644 --- a/src/gl/system/gl_swframebuffer.cpp +++ b/src/gl/system/gl_swframebuffer.cpp @@ -1543,20 +1543,21 @@ void OpenGLSWFrameBuffer::GetFlashedPalette(PalEntry pal[256]) void OpenGLSWFrameBuffer::SetVSync(bool vsync) { - if (VSync != vsync) - { - VSync = vsync; - Reset(); - } + // Switch to the default frame buffer because Nvidia's driver associates the vsync state with the bound FB object. + GLint oldDrawFramebufferBinding = 0, oldReadFramebufferBinding = 0; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDrawFramebufferBinding); + glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldReadFramebufferBinding); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + Super::SetVSync(vsync); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDrawFramebufferBinding); + glBindFramebuffer(GL_READ_FRAMEBUFFER, oldReadFramebufferBinding); } void OpenGLSWFrameBuffer::NewRefreshRate() { - if (IsFullscreen()) - { - Reset(); - } } void OpenGLSWFrameBuffer::SetBlendingRect(int x1, int y1, int x2, int y2)