diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 575ef968d..f0c9677ba 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -176,12 +176,12 @@ void GLPortal::DrawPortalStencil() bool GLPortal::Start(bool usestencil, bool doquery) { rendered_portals++; - PortalAll.Clock(); +// PortalAll.Clock(); if (usestencil) { if (!gl_portals) { - PortalAll.Unclock(); +// PortalAll.Unclock(); return false; } @@ -297,7 +297,7 @@ bool GLPortal::Start(bool usestencil, bool doquery) GLRenderer->mCurrentPortal = this; if (PrevPortal != NULL) PrevPortal->PushState(); - PortalAll.Unclock(); +// PortalAll.Unclock(); return true; } diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 94eba0817..08aca521f 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -209,13 +209,13 @@ void OpenGLFrameBuffer::Swap() { Finish.Reset(); Finish.Clock(); - glFinish(); if (needsetgamma) { //DoSetGamma(); needsetgamma = false; } SwapBuffers(); + glFinish(); Finish.Unclock(); swapped = true; FHardwareTexture::UnbindAll(); diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp index 59ef471d3..d78986cb5 100644 --- a/src/win32/win32gliface.cpp +++ b/src/win32/win32gliface.cpp @@ -37,7 +37,9 @@ extern int NewWidth, NewHeight, NewBits, DisplayBits; // these get used before GLEW is initialized so we have to use separate pointers with different names PFNWGLCHOOSEPIXELFORMATARBPROC myWglChoosePixelFormatARB; // = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); PFNWGLCREATECONTEXTATTRIBSARBPROC myWglCreateContextAttribsARB; -PFNWGLSWAPINTERVALEXTPROC vsyncfunc; +PFNWGLSWAPINTERVALEXTPROC myWglSwapIntervalExtProc; + + CUSTOM_CVAR(Bool, gl_debug, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) @@ -934,10 +936,32 @@ Win32GLFrameBuffer::Win32GLFrameBuffer(void *hMonitor, int width, int height, in vid_renderer = 0; return; } - - vsyncfunc = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); - HDC hDC = GetDC(Window); + const char *wglext = nullptr; + + myWglSwapIntervalExtProc = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); + auto myWglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); + if (myWglGetExtensionsStringARB) + { + wglext = myWglGetExtensionsStringARB(hDC); + } + else + { + auto myWglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC)wglGetProcAddress("wglGetExtensionsStringEXT"); + if (myWglGetExtensionsStringEXT) + { + wglext = myWglGetExtensionsStringEXT(); + } + } + SwapInterval = 1; + if (wglext != nullptr) + { + if (strstr(wglext, "WGL_EXT_swap_control_tear")) + { + SwapInterval = -1; + } + } + m_supportsGamma = !!GetDeviceGammaRamp(hDC, (void *)m_origGamma); ReleaseDC(Window, hDC); } @@ -1092,7 +1116,7 @@ void Win32GLFrameBuffer::ReleaseResources () void Win32GLFrameBuffer::SetVSync (bool vsync) { - if (vsyncfunc != NULL) vsyncfunc(vsync ? 1 : 0); + if (myWglSwapIntervalExtProc != NULL) myWglSwapIntervalExtProc(vsync ? SwapInterval : 0); } void Win32GLFrameBuffer::SwapBuffers() diff --git a/src/win32/win32gliface.h b/src/win32/win32gliface.h index 87eb10de6..d16c0dcc3 100644 --- a/src/win32/win32gliface.h +++ b/src/win32/win32gliface.h @@ -148,6 +148,7 @@ protected: int m_Lock; char m_displayDeviceNameBuffer[CCHDEVICENAME]; char *m_displayDeviceName; + int SwapInterval; friend class Win32GLVideo;