diff --git a/source/lib/sysdep/os/win/wsdl.cpp b/source/lib/sysdep/os/win/wsdl.cpp index 9b3b49bd29..38bcae0fc1 100644 --- a/source/lib/sysdep/os/win/wsdl.cpp +++ b/source/lib/sysdep/os/win/wsdl.cpp @@ -259,7 +259,26 @@ static HWND wnd_CreateWindow(int w, int h) static DEVMODE dm; // current video mode static HGLRC hGLRC = (HGLRC)INVALID_HANDLE_VALUE; -static int depth_bits = 24; // depth buffer size; set via SDL_GL_SetAttribute +// set via SDL_GL_SetAttribute: +static int depthBufferBits = 24; +static int vsyncEnabled = 1; + +int SDL_GL_SetAttribute(SDL_GLattr attr, int value) +{ + switch(attr) + { + case SDL_GL_DEPTH_SIZE: + depthBufferBits = value; + break; + + case SDL_GL_SWAP_CONTROL: + vsyncEnabled = value; + break; + } + + return 0; +} + // check if resolution needs to be changed static bool video_NeedsChange(int w, int h, int cur_w, int cur_h, bool fullscreen) @@ -280,15 +299,6 @@ static bool video_NeedsChange(int w, int h, int cur_w, int cur_h, bool fullscree } -int SDL_GL_SetAttribute(SDL_GLattr attr, int value) -{ - if(attr == SDL_GL_DEPTH_SIZE) - depth_bits = value; - - return 0; -} - - static void video_SetPixelFormat(HDC g_hDC, int bpp) { const DWORD dwFlags = PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_DOUBLEBUFFER; @@ -300,7 +310,7 @@ static void video_SetPixelFormat(HDC g_hDC, int bpp) cAlphaBits = 8; } const BYTE cAccumBits = 0; - const BYTE cDepthBits = (BYTE)depth_bits; + const BYTE cDepthBits = (BYTE)depthBufferBits; const BYTE cStencilBits = 0; const BYTE cAuxBuffers = 0; @@ -405,6 +415,12 @@ SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, Uint32 flags) screen.w = rect.right; screen.h = rect.bottom; + // (required for ogl_HaveExtension, but callers should also invoke + // ogl_Init in case the real SDL is being used.) + ogl_Init(); + if(ogl_HaveExtension("WGL_EXT_swap_control") && pwglSwapIntervalEXT) + pwglSwapIntervalEXT(vsyncEnabled); + return &screen; } diff --git a/source/lib/sysdep/os/win/wsdl.h b/source/lib/sysdep/os/win/wsdl.h index 457453d02f..10f2cbf92d 100644 --- a/source/lib/sysdep/os/win/wsdl.h +++ b/source/lib/sysdep/os/win/wsdl.h @@ -55,7 +55,7 @@ typedef enum { SDL_GL_DEPTH_SIZE, SDL_GL_DOUBLEBUFFER, // ignored - always double buffered - SDL_GL_SWAP_CONTROL // not implemented yet + SDL_GL_SWAP_CONTROL } SDL_GLattr; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index ff0f1f55db..c177806046 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -871,13 +871,6 @@ void Init(const CmdLineArgs& args, int flags) g_Shadows = false; } - // enable/disable VSync - // note: "GL_EXT_SWAP_CONTROL" is "historical" according to dox. -#if OS_WIN - if(ogl_HaveExtension("WGL_EXT_swap_control")) - pwglSwapIntervalEXT(g_VSync? 1 : 0); -#endif - ogl_WarnIfError(); InitRenderer();