From 478164962fc01fa3a2e3018d97ffd8e7c1115cee Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Fri, 24 Dec 2021 08:02:27 +0000 Subject: [PATCH] Removes static linking of OpenGL library. Tested By: Langbart, Stan Differential Revision: https://code.wildfiregames.com/D4387 This was SVN commit r26104. --- build/premake/extern_libs5.lua | 29 ------------------- build/premake/premake5.lua | 9 +----- source/lib/ogl.cpp | 4 --- source/renderer/backend/gl/Device.cpp | 4 ++- .../Handlers/GraphicsSetupHandlers.cpp | 17 +++++++---- 5 files changed, 15 insertions(+), 48 deletions(-) diff --git a/build/premake/extern_libs5.lua b/build/premake/extern_libs5.lua index 33ba6bd4f8..4728738d5c 100644 --- a/build/premake/extern_libs5.lua +++ b/build/premake/extern_libs5.lua @@ -579,35 +579,6 @@ extern_lib_defs = { end end, }, - opengl = { - compile_settings = function() - if os.istarget("windows") then - add_default_include_paths("opengl") - elseif _OPTIONS["gles"] then - pkgconfig.add_includes("glesv2") - elseif not os.istarget("macosx") then - pkgconfig.add_includes("gl") - end - end, - link_settings = function() - if os.istarget("windows") then - add_default_lib_paths("opengl") - add_default_links({ - win_names = { "opengl32", "gdi32" }, - dbg_suffix = "", - no_delayload = 1, -- delayload seems to cause errors on startup - }) - elseif os.istarget("macosx") then - add_default_links({ - osx_frameworks = { "OpenGL" }, - }) - elseif _OPTIONS["gles"] then - pkgconfig.add_links("glesv2") - else - pkgconfig.add_links("gl") - end - end, - }, sdl = { compile_settings = function() if os.istarget("windows") then diff --git a/build/premake/premake5.lua b/build/premake/premake5.lua index 96763afc19..bf1fd730c8 100644 --- a/build/premake/premake5.lua +++ b/build/premake/premake5.lua @@ -706,7 +706,6 @@ function setup_all_libs () } extern_libs = { "boost", - "opengl", "spidermonkey", "fmt", } @@ -747,7 +746,6 @@ function setup_all_libs () "spidermonkey", "sdl", -- key definitions "libxml2", - "opengl", "zlib", "boost", "enet", @@ -779,7 +777,6 @@ function setup_all_libs () "third_party/ogre3d_preprocessor" } extern_libs = { - "opengl", "sdl", -- key definitions "spidermonkey", -- for graphics/scripting "boost", @@ -800,7 +797,6 @@ function setup_all_libs () extern_libs = { "boost", "sdl", -- key definitions - "opengl", "spidermonkey", "fmt", } @@ -818,7 +814,6 @@ function setup_all_libs () extern_libs = { "spidermonkey", "sdl", -- key definitions - "opengl", "boost", "enet", "tinygettext", @@ -853,7 +848,6 @@ function setup_all_libs () "boost", "sdl", "openal", - "opengl", "libpng", "zlib", "valgrind", @@ -917,7 +911,7 @@ function setup_all_libs () setup_static_lib_project("lowlevel", source_dirs, extern_libs, extra_params) - setup_static_lib_project("gladwrapper", {}, { "opengl", "glad" }, { no_pch = 1 }) + setup_static_lib_project("gladwrapper", {}, { "glad" }, { no_pch = 1 }) glad_path = libraries_source_dir.."glad/" sysincludedirs { glad_path.."include" } if _OPTIONS["gles"] then @@ -964,7 +958,6 @@ end -- used for main EXE as well as test used_extern_libs = { - "opengl", "sdl", "libpng", diff --git a/source/lib/ogl.cpp b/source/lib/ogl.cpp index d225855ed3..2ba216db38 100644 --- a/source/lib/ogl.cpp +++ b/source/lib/ogl.cpp @@ -46,10 +46,6 @@ #include #include -#if MSC_VERSION -#pragma comment(lib, "opengl32.lib") -#endif - //---------------------------------------------------------------------------- // extensions diff --git a/source/renderer/backend/gl/Device.cpp b/source/renderer/backend/gl/Device.cpp index 843deac305..cc12a9f6b5 100644 --- a/source/renderer/backend/gl/Device.cpp +++ b/source/renderer/backend/gl/Device.cpp @@ -133,6 +133,9 @@ std::unique_ptr CDevice::Create(SDL_Window* window) if (window) { + // According to https://wiki.libsdl.org/SDL_CreateWindow we don't need to + // call SDL_GL_LoadLibrary if we have a window with SDL_WINDOW_OPENGL, + // because it'll be called internally for the first created window. device->m_Window = window; device->m_Context = SDL_GL_CreateContext(device->m_Window); if (!device->m_Context) @@ -150,7 +153,6 @@ std::unique_ptr CDevice::Create(SDL_Window* window) } else { - // SDL_GL_GetProcAddress is available because we called SDL_GL_LoadLibrary. #if OS_WIN ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); #elif defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp index 7f7d2daced..6e8f96613e 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp @@ -32,6 +32,7 @@ #include "lib/timer.h" #include "maths/MathUtil.h" #include "ps/CConsole.h" +#include "ps/CLogger.h" #include "ps/Filesystem.h" #include "ps/Profile.h" #include "ps/Profiler2.h" @@ -97,14 +98,18 @@ MESSAGEHANDLER(InitSDL) // When running in Atlas, we skip the SDL video initialisation code // which loads the library, and so SDL_GL_GetProcAddress fails (in // ogl.cpp importExtensionFunctions). - // (TODO: I think this is meant to be context-independent, i.e. it - // doesn't matter that we're getting extensions from SDL-initialised - // GL stuff instead of from the wxWidgets-initialised GL stuff, but that - // should be checked.) // So, make sure it's loaded: SDL_InitSubSystem(SDL_INIT_VIDEO); - SDL_GL_LoadLibrary(NULL); // NULL = use default - // (it shouldn't hurt if this is called multiple times, I think) + // wxWidgets doesn't use a proper approach to dynamically load functions and + // doesn't provide GetProcAddr-like function. Technically we need to call + // SDL_GL_LoadLibrary inside GL device creation, but that might lead to a + // crash on Windows because of a wrong order of initialization between SDL + // and wxWidgets context management. So leave the call as is while it works. + // Refs: + // http://trac.wxwidgets.org/ticket/9213 + // http://trac.wxwidgets.org/ticket/9215 + if (SDL_GL_LoadLibrary(nullptr) && g_Logger) + LOGERROR("SDL failed to load GL library: '%s'", SDL_GetError()); } MESSAGEHANDLER(InitGraphics)