Merge pull request #484 from dpaulat/feature/opengl-glad

Use glad to load OpenGL instead of GLEW
This commit is contained in:
Dan Paulat 2025-07-13 09:30:43 -05:00 committed by GitHub
commit 51806d1742
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 32 additions and 11 deletions

View file

@ -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

3
.gitmodules vendored
View file

@ -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

View file

@ -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) |

View file

@ -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)

1
external/glad vendored Submodule

@ -0,0 +1 @@
Subproject commit 73db193f853e2ee079bf3ca8a64aa2eaf6459043

11
external/glad.cmake vendored Normal file
View file

@ -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)

View file

@ -745,6 +745,7 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets
GeographicLib::GeographicLib
GEOS::geos
GEOS::geos_cxx_flags
glad_gl_core_33
GLEW::GLEW
glm::glm
imgui

View file

@ -1,6 +1,6 @@
#pragma once
#include <GL/glew.h>
#include <glad/gl.h>
#define SCWX_GL_CHECK_ERROR() \
{ \

View file

@ -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<const char*>(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<const char*>(glGetString(GL_VERSION));
auto glVendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
auto glRenderer = reinterpret_cast<const char*>(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);

View file

@ -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