From e565c26d23694783974b5b8a971213e24a820654 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 19 Feb 2020 03:34:42 +0300 Subject: [PATCH] SDL: separated GL loading code --- src/game/sdl/g_system.pas | 38 +++++++++++++++++++++++++++----------- src/game/sdl2/g_system.pas | 38 +++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index bba2cae..b866972 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -24,6 +24,7 @@ interface procedure sys_Delay (ms: Integer); (* --- Graphics --- *) + function sys_LoadGL: Boolean; function sys_GetDisplayModes (bpp: Integer): SSArray; function sys_SetDisplayMode (w, h, bpp: Integer; fullscreen, maximized: Boolean): Boolean; procedure sys_EnableVSync (yes: Boolean); @@ -70,6 +71,28 @@ implementation (* --------- Graphics --------- *) + function LoadGL: Boolean; + begin + result := true; + {$IFDEF NOGL_INIT} + nogl_Init; + if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then + {$ELSE} + if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then + {$ENDIF} + begin + e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering'); + glRenderToFBO := false; + end; + end; + + procedure FreeGL; + begin + {$IFDEF NOGL_INIT} + nogl_Quit(); + {$ENDIF} + end; + procedure UpdateSize (w, h: Integer); begin gWinSizeX := w; @@ -125,15 +148,10 @@ implementation screen := SDL_SetVideoMode(w, h, bpp, flags); if screen <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Init; - if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then - {$ELSE} - if glRenderToFBO and (not Load_GL_ARB_framebuffer_object()) then - {$ENDIF} + if not LoadGL then begin - e_LogWriteln('SDL: no framebuffer object support detected'); - glRenderToFBO := False + e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal); + exit; end; SDL_WM_SetCaption(GetTitle(), nil); gFullScreen := fullscreen; @@ -497,9 +515,7 @@ implementation RemoveJoystick(i); if screen <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Quit; - {$ENDIF} + FreeGL; SDL_FreeSurface(screen) end; SDL_Quit diff --git a/src/game/sdl2/g_system.pas b/src/game/sdl2/g_system.pas index 29a81b0..31c5b1c 100644 --- a/src/game/sdl2/g_system.pas +++ b/src/game/sdl2/g_system.pas @@ -74,6 +74,28 @@ implementation (* --------- Graphics --------- *) + function LoadGL: Boolean; + begin + result := true; + {$IFDEF NOGL_INIT} + nogl_Init; + if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then + {$ELSE} + if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then + {$ENDIF} + begin + e_LogWriteln('GL: framebuffer objects not supported; disabling FBO rendering'); + glRenderToFBO := false; + end; + end; + + procedure FreeGL; + begin + {$IFDEF NOGL_INIT} + nogl_Quit(); + {$ENDIF} + end; + procedure UpdateSize (w, h: Integer); begin gWinSizeX := w; @@ -156,15 +178,11 @@ implementation context := SDL_GL_CreateContext(window); if context <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Init; - if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then - {$ELSE} - if glRenderToFBO and (not Load_GL_ARB_framebuffer_object()) then - {$ENDIF} + if not LoadGL then begin - e_LogWriteln('SDL: no framebuffer object support detected'); - glRenderToFBO := False + e_LogWriteln('GL: unable to load OpenGL functions', TMsgType.Fatal); + SDL_GL_DeleteContext(context); context := nil; + exit; end; if (fullscreen = false) and (maximized = false) and (wc = false) then begin @@ -564,9 +582,7 @@ implementation e_WriteLog('Releasing SDL2', TMsgType.Notify); if context <> nil then begin - {$IFDEF NOGL_INIT} - nogl_Quit; - {$ENDIF} + FreeGL; SDL_GL_DeleteContext(context); context := nil; end; -- 2.29.2