From 6cb668f546413b655daea9e601373448f2d66628 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 12 Jul 2025 14:26:37 -0500 Subject: [PATCH 1/5] Add submodule for glad --- .gitmodules | 3 +++ ACKNOWLEDGEMENTS.md | 1 + external/glad | 1 + 3 files changed, 5 insertions(+) create mode 160000 external/glad diff --git a/.gitmodules b/.gitmodules index dc9749dc..a6f47235 100644 --- a/.gitmodules +++ b/.gitmodules @@ -40,3 +40,6 @@ [submodule "external/qt6ct"] path = external/qt6ct url = https://github.com/AdenKoperczak/qt6ct.git +[submodule "external/glad"] + path = external/glad + url = https://github.com/Dav1dde/glad.git diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md index 6f7cd4ef..b0225bbe 100644 --- a/ACKNOWLEDGEMENTS.md +++ b/ACKNOWLEDGEMENTS.md @@ -23,6 +23,7 @@ Supercell Wx uses code from the following dependencies: | [FreeType GL](https://github.com/rougier/freetype-gl) | [BSD 2-Clause with views sentence](https://spdx.org/licenses/BSD-2-Clause-Views.html) | | [GeographicLib](https://geographiclib.sourceforge.io/) | [MIT License](https://spdx.org/licenses/MIT.html) | | [geos](https://libgeos.org/) | [GNU Lesser General Public License v2.1 or later](https://spdx.org/licenses/LGPL-2.1-or-later.html) | +| [GLAD](https://github.com/Dav1dde/glad) | [MIT License](https://spdx.org/licenses/MIT.html) | | [GLEW](https://www.opengl.org/sdk/libs/GLEW/) | [MIT License](https://spdx.org/licenses/MIT.html) | | [GLM](https://github.com/g-truc/glm) | [MIT License](https://spdx.org/licenses/MIT.html) | | [GoogleTest](https://google.github.io/googletest/) | [BSD 3-Clause "New" or "Revised" License](https://spdx.org/licenses/BSD-3-Clause.html) | diff --git a/external/glad b/external/glad new file mode 160000 index 00000000..73db193f --- /dev/null +++ b/external/glad @@ -0,0 +1 @@ +Subproject commit 73db193f853e2ee079bf3ca8a64aa2eaf6459043 From d5cda9b353f58787c3004edb22db08366ba522ec Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 12 Jul 2025 16:23:02 -0500 Subject: [PATCH 2/5] Use glad instead of GLEW to load OpenGL --- external/CMakeLists.txt | 2 ++ external/glad.cmake | 11 +++++++++++ scwx-qt/scwx-qt.cmake | 5 +++-- scwx-qt/source/scwx/qt/gl/gl.hpp | 2 +- scwx-qt/source/scwx/qt/gl/gl_context.cpp | 18 +++++++++--------- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 external/glad.cmake diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 2137ae62..1039e96e 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -6,6 +6,7 @@ set_property(DIRECTORY PROPERTY CMAKE_CONFIGURE_DEPENDS aws-sdk-cpp.cmake date.cmake + glad.cmake hsluv-c.cmake imgui.cmake maplibre-native-qt.cmake @@ -16,6 +17,7 @@ set_property(DIRECTORY include(aws-sdk-cpp.cmake) include(date.cmake) +include(glad.cmake) include(hsluv-c.cmake) include(imgui.cmake) include(maplibre-native-qt.cmake) diff --git a/external/glad.cmake b/external/glad.cmake new file mode 100644 index 00000000..59ceb179 --- /dev/null +++ b/external/glad.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.24) +set(PROJECT_NAME scwx-glad) + +# Path to glad directory +set(GLAD_SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/glad/") + +# Path to glad CMake files +add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake) + +# Specify glad settings +glad_add_library(glad_gl_core_33 LOADER REPRODUCIBLE API gl:core=3.3) diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index c1dba7f2..7bd2d089 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -745,7 +745,7 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets GeographicLib::GeographicLib GEOS::geos GEOS::geos_cxx_flags - GLEW::GLEW + glad_gl_core_33 glm::glm imgui qt6ct-common @@ -753,7 +753,8 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets SQLite::SQLite3 wxdata) -target_link_libraries(supercell-wx PRIVATE scwx-qt +target_link_libraries(supercell-wx PRIVATE GLEW::GLEW + scwx-qt wxdata) if (LINUX) diff --git a/scwx-qt/source/scwx/qt/gl/gl.hpp b/scwx-qt/source/scwx/qt/gl/gl.hpp index 3361094b..ef5d0053 100644 --- a/scwx-qt/source/scwx/qt/gl/gl.hpp +++ b/scwx-qt/source/scwx/qt/gl/gl.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #define SCWX_GL_CHECK_ERROR() \ { \ diff --git a/scwx-qt/source/scwx/qt/gl/gl_context.cpp b/scwx-qt/source/scwx/qt/gl/gl_context.cpp index 4729eab5..8cdd08b4 100644 --- a/scwx-qt/source/scwx/qt/gl/gl_context.cpp +++ b/scwx-qt/source/scwx/qt/gl/gl_context.cpp @@ -57,21 +57,21 @@ void GlContext::Impl::InitializeGL() return; } - const GLenum error = glewInit(); - if (error != GLEW_OK) + const int gladVersion = gladLoaderLoadGL(); + if (!gladVersion) { - auto glewErrorString = - reinterpret_cast(glewGetErrorString(error)); - logger_->error("glewInit failed: {}", glewErrorString); + logger_->error("gladLoaderLoadGL failed"); QMessageBox::critical( - nullptr, - "Supercell Wx", - QString("Unable to initialize OpenGL: %1").arg(glewErrorString)); + nullptr, "Supercell Wx", "Unable to initialize OpenGL"); throw std::runtime_error("Unable to initialize OpenGL"); } + logger_->info("GLAD initialization complete: OpenGL {}.{}", + GLAD_VERSION_MAJOR(gladVersion), + GLAD_VERSION_MINOR(gladVersion)); + auto glVersion = reinterpret_cast(glGetString(GL_VERSION)); auto glVendor = reinterpret_cast(glGetString(GL_VENDOR)); auto glRenderer = reinterpret_cast(glGetString(GL_RENDERER)); @@ -86,7 +86,7 @@ void GlContext::Impl::InitializeGL() glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); - if (major < 3 || (major == 3 && minor < 3)) + if (major < 3 || (major == 3 && minor < 3) || !GLAD_GL_VERSION_3_3) { logger_->error( "OpenGL 3.3 or greater is required, found {}.{}", major, minor); From 40fc41b7245d1d09ee58c12faa1614eda31bf64e Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 12 Jul 2025 16:45:43 -0500 Subject: [PATCH 3/5] Move GLEW dependency back to scwx-qt (provides GLU) --- scwx-qt/scwx-qt.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 7bd2d089..e96e828a 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -746,6 +746,7 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets GEOS::geos GEOS::geos_cxx_flags glad_gl_core_33 + GLEW::GLEW glm::glm imgui qt6ct-common @@ -753,8 +754,7 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets SQLite::SQLite3 wxdata) -target_link_libraries(supercell-wx PRIVATE GLEW::GLEW - scwx-qt +target_link_libraries(supercell-wx PRIVATE scwx-qt wxdata) if (LINUX) From 4e74a8d38e717bb7ea3ab860dac43b345bf0af92 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 12 Jul 2025 23:09:23 -0500 Subject: [PATCH 4/5] Build glad_gl_core_33 as part of autogenerate step --- .github/workflows/clang-tidy-review.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang-tidy-review.yml b/.github/workflows/clang-tidy-review.yml index 2137b451..4feb238e 100644 --- a/.github/workflows/clang-tidy-review.yml +++ b/.github/workflows/clang-tidy-review.yml @@ -113,7 +113,8 @@ jobs: -DCONAN_HOST_PROFILE="${{ matrix.conan_profile }}" ` -DCONAN_BUILD_PROFILE="${{ matrix.conan_profile }}" ` -DCMAKE_EXPORT_COMPILE_COMMANDS=on - ninja scwx-qt_generate_counties_db ` + ninja glad_gl_core_33 ` + scwx-qt_generate_counties_db ` scwx-qt_generate_versions ` scwx-qt_autogen From 6b09b7cb9b852087a61ca012663f76da522758a5 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 12 Jul 2025 23:22:08 -0500 Subject: [PATCH 5/5] Specify OpenGL as the renderable type --- scwx-qt/source/scwx/qt/main/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index fbb716c9..3df56a0d 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -246,6 +246,7 @@ static void InitializeOpenGL() QSurfaceFormat surfaceFormat = QSurfaceFormat::defaultFormat(); surfaceFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); + surfaceFormat.setRenderableType(QSurfaceFormat::RenderableType::OpenGL); #if defined(__APPLE__) // For macOS, we must choose between OpenGL 4.1 Core and OpenGL 2.1