From 376b5b869bc531910583ff8bf68d8aabeb048497 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 12 Feb 2018 13:46:47 +0200 Subject: [PATCH] set vsync after window creation (it should work better this way) --- src/game/g_menu.pas | 10 +--------- src/game/g_window.pas | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index ff57a39..0a9cc7f 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -107,7 +107,6 @@ var menu: TGUIMenu; i: Integer; ovs: Boolean; - v: Byte; begin menu := TGUIMenu(g_GUI_GetWindow('OptionsVideoMenu').GetControl('mOptionsVideoMenu')); @@ -118,14 +117,7 @@ begin ovs := gVSync; gVSync := TGUISwitch(menu.GetControl('swVSync')).ItemIndex = 0; - {$IF not DEFINED(HEADLESS)} - if (ovs <> gVSync) then - begin - if (gVSync) then v := 1 else v := 0; - if (SDL_GL_SetSwapInterval(v) <> 0) then writeln('oops; can''t change vsync option, restart required') - else writeln('vsync changed'); - end; - {$ENDIF} + if (ovs <> gVSync) then g_SetVSync(gVSync); gTextureFilter := TGUISwitch(menu.GetControl('swTextureFilter')).ItemIndex = 0; glLegacyNPOT := not (TGUISwitch(menu.GetControl('swLegacyNPOT')).ItemIndex = 0); diff --git a/src/game/g_window.pas b/src/game/g_window.pas index e2fec17..56df2d1 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -32,6 +32,7 @@ procedure Sleep (ms: LongWord); function GetDisplayModes (dbpp: LongWord; var selres: LongWord): SSArray; function g_Window_SetDisplay (preserveGL: Boolean=false): Boolean; function g_Window_SetSize (w, h: Word; fullscreen: Boolean): Boolean; +procedure g_SetVSync (vsync: Boolean); procedure ProcessLoading (forceUpdate: Boolean=false); @@ -522,6 +523,7 @@ begin fuiScrWdt := gScreenWidth; fuiScrHgt := gScreenHeight; if (assigned(oglInitCB)) then oglInitCB(); + g_SetVSync(gVSync); {$ENDIF} e_ResizeWindow(gScreenWidth, gScreenHeight); @@ -749,7 +751,7 @@ begin end; -procedure InitOpenGL (vsync: Boolean); +procedure g_SetVSync (vsync: Boolean); {$IF not DEFINED(HEADLESS)} var v: Byte; @@ -757,6 +759,21 @@ var begin {$IF not DEFINED(HEADLESS)} if vsync then v := 1 else v := 0; + if (SDL_GL_SetSwapInterval(v) <> 0) then + begin + e_WriteLog('oops; can''t change vsync option, restart required', TMsgType.Warning); + end + else + begin + if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify); + end; +{$ENDIF} +end; + + +procedure InitOpenGL (); +begin +{$IF not DEFINED(HEADLESS)} SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); @@ -765,7 +782,6 @@ begin SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but... - SDL_GL_SetSwapInterval(v); {$ENDIF} end; @@ -913,7 +929,7 @@ begin end; e_WriteLog('Initializing OpenGL', TMsgType.Notify); - InitOpenGL(gVSync); + InitOpenGL(); e_WriteLog('Creating GL window', TMsgType.Notify); if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION]))) then -- 2.29.2