From 3c1c392ab177566f09d11a380210e1937741fad2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 28 May 2023 11:45:01 +0100 Subject: Swap GLEW for more modern glad --- Jamroot.jam | 3 +-- assetFactory/modelFactoryMesh.h | 2 +- assetFactory/texturePacker.cpp | 4 ++-- game/network/rail.cpp | 2 +- gfx/gl/program.h | 2 +- gfx/gl/shader.h | 4 ++-- gfx/gl/uiShader.h | 2 +- gfx/gl/vertexArrayObject.h | 2 +- gfx/models/mesh.h | 2 +- gfx/models/texture.cpp | 2 +- gfx/models/vertex.h | 2 +- lib/embed-glsl.cpp.m4 | 12 ++++++------ lib/glArrays.h | 2 +- lib/gl_traits.h | 2 +- lib/strlen.h | 2 +- test/Jamfile.jam | 4 ++-- test/test-glContextBhvr.cpp | 4 ++-- test/test-lib.cpp | 2 +- test/test-network.cpp | 5 +++++ test/test-text.cpp | 5 +++++ ui/font.h | 2 +- ui/gameMainWindow.cpp | 2 +- ui/icon.cpp | 2 +- ui/iconButton.cpp | 2 +- ui/text.h | 2 +- ui/window.cpp | 10 +++++----- ui/window.h | 6 +++--- 27 files changed, 50 insertions(+), 41 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 0273fe2..8a111ee 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -7,7 +7,6 @@ import sequence ; import glsl ; pkg-config.import sdl2 ; -pkg-config.import glew ; pkg-config.import freetype2 ; pkg-config.import glib-2.0 ; pkg-config.import mxml ; @@ -92,7 +91,6 @@ lib ilt : thirdparty//glad thirdparty//glad sdl2 - glew freetype2 glib-2.0 mxml @@ -102,6 +100,7 @@ lib ilt : : : . lib + thirdparty//glad ; build-project test ; diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 012977a..32e7ab5 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -1,9 +1,9 @@ #pragma once #include "modelFactoryMesh_fwd.h" -#include #include #include +#include #include #include #include diff --git a/assetFactory/texturePacker.cpp b/assetFactory/texturePacker.cpp index 1d533c1..dbafc4b 100644 --- a/assetFactory/texturePacker.cpp +++ b/assetFactory/texturePacker.cpp @@ -1,8 +1,8 @@ #include "texturePacker.h" #include "collections.h" -#include #include #include +#include #include #include #include @@ -65,7 +65,7 @@ TexturePacker::pack(Size size) const return {}; } } - if (GLEW_ARB_texture_non_power_of_two) { + if (GL_ARB_texture_non_power_of_two) { // Crop the size back to minimum size size = std::transform_reduce( result.begin(), result.end(), inputImages.begin(), Size {}, diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 4454600..bd24a2b 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -1,6 +1,5 @@ #include "rail.h" #include "network.h" -#include #include #include #include @@ -8,6 +7,7 @@ #include #include // IWYU pragma: keep #include +#include #include #include #include diff --git a/gfx/gl/program.h b/gfx/gl/program.h index 2708ff0..76b6742 100644 --- a/gfx/gl/program.h +++ b/gfx/gl/program.h @@ -1,8 +1,8 @@ #pragma once #include "shader.h" -#include #include +#include #include #include diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index cb8065b..0810e6b 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -1,13 +1,13 @@ #pragma once -#include #include +#include #include #include class Shader { public: - using ShaderRef = glRef; + using ShaderRef = glRef; constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { } [[nodiscard]] ShaderRef compile() const; diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h index 054c944..2766af8 100644 --- a/gfx/gl/uiShader.h +++ b/gfx/gl/uiShader.h @@ -1,8 +1,8 @@ #pragma once #include "program.h" -#include #include +#include #include #include diff --git a/gfx/gl/vertexArrayObject.h b/gfx/gl/vertexArrayObject.h index 1d27588..fa6baa3 100644 --- a/gfx/gl/vertexArrayObject.h +++ b/gfx/gl/vertexArrayObject.h @@ -3,7 +3,7 @@ #include "collections.h" #include "gl_traits.h" #include "special_members.h" -#include +#include class VertexArrayObject { public: diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 972fe30..71f6dce 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -1,8 +1,8 @@ #pragma once #include "gfx/gl/vertexArrayObject.h" -#include #include +#include #include #include #include diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 3003319..380f2e0 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -1,11 +1,11 @@ #include "texture.h" #include "glArrays.h" #include "tga.h" -#include #include #include #include #include +#include #include #include #include diff --git a/gfx/models/vertex.h b/gfx/models/vertex.h index 181e7e7..0464ea7 100644 --- a/gfx/models/vertex.h +++ b/gfx/models/vertex.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include class Vertex { diff --git a/lib/embed-glsl.cpp.m4 b/lib/embed-glsl.cpp.m4 index 8407132..60fb56b 100644 --- a/lib/embed-glsl.cpp.m4 +++ b/lib/embed-glsl.cpp.m4 @@ -1,12 +1,12 @@ -changecom()dnl +changecom() dnl // NAME -#include "substr(TYPE,1)-NAME.h" -#include #include "gfx/gl/shader.h" #include "lib/strlen.h" +#include "substr(TYPE,1)-NAME.h" +#include -constexpr const GLchar * src { R"GLSL-EMBED(dnl -include(SOURCE))GLSL-EMBED" }; -constexpr auto len { constexpr_strlen (src) }; + constexpr const GLchar * src {R"GLSL-EMBED(dnl +include(SOURCE))GLSL-EMBED"}; +constexpr auto len {constexpr_strlen(src)}; const Shader NAME`_'substr(TYPE,1) { src, len, GLTYPE }; diff --git a/lib/glArrays.h b/lib/glArrays.h index 8c8c0bc..86385d9 100644 --- a/lib/glArrays.h +++ b/lib/glArrays.h @@ -1,9 +1,9 @@ #pragma once -#include #include // IWYU pragma: keep #include #include +#include #include template class glArraysBase { diff --git a/lib/gl_traits.h b/lib/gl_traits.h index 6ff8905..a930eba 100644 --- a/lib/gl_traits.h +++ b/lib/gl_traits.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #include diff --git a/lib/strlen.h b/lib/strlen.h index 0053cce..2090d25 100644 --- a/lib/strlen.h +++ b/lib/strlen.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include constexpr auto constexpr_strlen(const GLchar * const s) diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 3b4e891..e221af7 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -47,9 +47,9 @@ run test-collection.cpp ; run test-maths.cpp ; run test-lib.cpp ; run test-geo.cpp ; -run test-network.cpp ; +run test-network.cpp : : : test ; run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob-tree fixtures : *.json ] ] : test ; -run test-text.cpp ; +run test-text.cpp : : : test ; run test-enumDetails.cpp ; run test-render.cpp : -- : test-assetFactory : test ; run test-glContextBhvr.cpp ; diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp index 9716f54..1f1215c 100644 --- a/test/test-glContextBhvr.cpp +++ b/test/test-glContextBhvr.cpp @@ -24,12 +24,12 @@ BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1) const SDL_WindowPtr window {TEST_WINDOW_PARAMS}; BOOST_REQUIRE(window); BOOST_REQUIRE(!glCreateProgram); - BOOST_REQUIRE_NE(glewInit(), GLEW_OK); // No context yet + BOOST_REQUIRE_EQUAL(gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)), 0); // No context yet { const SDL_GLContextPtr context {window}; BOOST_REQUIRE(context); BOOST_REQUIRE(!glCreateProgram); - BOOST_REQUIRE_EQUAL(glewInit(), GLEW_OK); + BOOST_REQUIRE_EQUAL(gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)), 40006); BOOST_REQUIRE(glCreateProgram); CreateProgramTest(); } // Context destroyed diff --git a/test/test-lib.cpp b/test/test-lib.cpp index 73ed53a..aaf6292 100644 --- a/test/test-lib.cpp +++ b/test/test-lib.cpp @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include std::set active; diff --git a/test/test-network.cpp b/test/test-network.cpp index e6241e4..a8db2b6 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -4,6 +4,8 @@ #include #include +#include "testMainWindow.h" +#include "ui/applicationBase.h" #include #include #include @@ -18,6 +20,9 @@ #include #include +BOOST_GLOBAL_FIXTURE(ApplicationBase); +BOOST_GLOBAL_FIXTURE(TestMainWindow); + struct TestLink : public LinkStraight { TestLink(const Node::Ptr & a, const Node::Ptr & b) : TestLink {a, b, (a->pos - b->pos)} { } TestLink(Node::Ptr a, Node::Ptr b, glm::vec2 l) : Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)} { } diff --git a/test/test-text.cpp b/test/test-text.cpp index 3a23818..629892f 100644 --- a/test/test-text.cpp +++ b/test/test-text.cpp @@ -5,6 +5,8 @@ #include #include +#include "testMainWindow.h" +#include "ui/applicationBase.h" #include #include #include @@ -12,6 +14,9 @@ #include #include +BOOST_GLOBAL_FIXTURE(ApplicationBase); +BOOST_GLOBAL_FIXTURE(TestMainWindow); + BOOST_AUTO_TEST_CASE(utf8_string_view_iter) { static constexpr utf8_string_view text {"Some UTF-8 €£²¹ text."}; diff --git a/ui/font.h b/ui/font.h index 52b92a7..6c86e18 100644 --- a/ui/font.h +++ b/ui/font.h @@ -1,12 +1,12 @@ #pragma once -#include #include #include #include #include #include #include +#include #include #include #include diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index a7f17dc..c35c9c6 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -6,13 +6,13 @@ #include "modeHelper.h" #include "toolbar.h" #include "window.h" -#include #include #include #include #include #include // IWYU pragma: keep #include +#include #include #include #include diff --git a/ui/icon.cpp b/ui/icon.cpp index be1a63c..38f4bf9 100644 --- a/ui/icon.cpp +++ b/ui/icon.cpp @@ -1,7 +1,7 @@ #include "icon.h" #include "glArrays.h" -#include #include +#include #include #include diff --git a/ui/iconButton.cpp b/ui/iconButton.cpp index f74b3fc..fe8c817 100644 --- a/ui/iconButton.cpp +++ b/ui/iconButton.cpp @@ -2,11 +2,11 @@ #include "glArrays.h" #include "ui/icon.h" #include "ui/uiComponent.h" -#include #include #include #include #include +#include #include #include diff --git a/ui/text.h b/ui/text.h index cbe49de..9fe87d1 100644 --- a/ui/text.h +++ b/ui/text.h @@ -1,8 +1,8 @@ #pragma once #include "uiComponent.h" -#include #include +#include #include #include #include diff --git a/ui/window.cpp b/ui/window.cpp index 731996a..93e85bd 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -1,20 +1,20 @@ #include "window.h" #include "uiComponent.h" #include "worldOverlay.h" -#include +#include #include #include #include #include -Window::GlewInitHelper::GlewInitHelper() +Window::GLInitHelper::GLInitHelper() { [[maybe_unused]] static auto init = []() { - if (const auto r = glewInit(); r != GLEW_OK) { - throw std::runtime_error {reinterpret_cast(glewGetErrorString(r))}; + if (const auto version = gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)); version != 40006) { + throw std::runtime_error {std::to_string(version)}; } else { - return r; + return version; } }(); } diff --git a/ui/window.h b/ui/window.h index be9e114..369228a 100644 --- a/ui/window.h +++ b/ui/window.h @@ -31,14 +31,14 @@ public: protected: virtual void render() const; - struct GlewInitHelper { - GlewInitHelper(); + struct GLInitHelper { + GLInitHelper(); }; const glm::ivec2 size; SDL_WindowPtr m_window; SDL_GLContextPtr glContext; - GlewInitHelper glewinithelper; + GLInitHelper glInithelper; Collection uiComponents; UIShader uiShader; }; -- cgit v1.2.3