Make sure SwapInterval is only ever called while the default frame buffer is bound to avoid problems with some drivers

This commit is contained in:
Magnus Norddahl 2017-03-03 16:30:04 +01:00 committed by Christoph Oelckers
parent 1761da6079
commit 6055f136d8
2 changed files with 24 additions and 1 deletions

View file

@ -83,7 +83,7 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, int width, int height, int
{ {
// SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver. // SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver.
// If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed! // If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed!
SetVSync(vid_vsync); Super::SetVSync(vid_vsync);
// Make sure all global variables tracking OpenGL context state are reset.. // Make sure all global variables tracking OpenGL context state are reset..
FHardwareTexture::InitGlobalState(); FHardwareTexture::InitGlobalState();
@ -230,6 +230,27 @@ void OpenGLFrameBuffer::Swap()
mDebug->Update(); mDebug->Update();
} }
//==========================================================================
//
// Enable/disable vertical sync
//
//==========================================================================
void OpenGLFrameBuffer::SetVSync(bool vsync)
{
// Switch to the default frame buffer because some drivers associate 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);
}
//=========================================================================== //===========================================================================
// //
// DoSetGamma // DoSetGamma

View file

@ -83,6 +83,8 @@ public:
bool Is8BitMode() { return false; } bool Is8BitMode() { return false; }
bool IsHWGammaActive() const { return HWGammaActive; } bool IsHWGammaActive() const { return HWGammaActive; }
void SetVSync(bool vsync);
private: private:
PalEntry Flash; PalEntry Flash;