From c15cf30abf450626cde18769953acf457dccbad8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Jan 2024 17:39:44 +0000 Subject: Always set pixel unpack alignment before generating font texture content --- ui/font.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'ui/font.cpp') diff --git a/ui/font.cpp b/ui/font.cpp index 305e0f3..f610a1b 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -77,6 +77,7 @@ Font::generateChars(const utf8_string_view chars) const if (charsData.find(codepoint) == charsData.end()) { if (!ft) { ft.emplace(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); } if (!face) { face.emplace(*ft, path.c_str()); -- cgit v1.2.3 From 30f58cc3832bd1b5a5cadf4b0a4a9d47d024f9f7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Jan 2024 17:48:11 +0000 Subject: Remove the static font cache Each thing can own/share a font rendering itself --- ui/editNetwork.cpp | 5 +++-- ui/editNetwork.h | 2 +- ui/font.cpp | 2 -- ui/font.h | 5 ----- ui/gameMainSelector.cpp | 12 +++++++----- ui/gameMainSelector.h | 3 ++- ui/text.cpp | 10 ++-------- ui/text.h | 3 ++- 8 files changed, 17 insertions(+), 25 deletions(-) (limited to 'ui/font.cpp') diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp index 7fbde32..ac2d93d 100644 --- a/ui/editNetwork.cpp +++ b/ui/editNetwork.cpp @@ -8,6 +8,7 @@ #include #include +const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"}; constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200}; EditNetwork::EditNetwork(Network * n) : @@ -17,7 +18,7 @@ EditNetwork::EditNetwork(Network * n) : {"ui/icon/network.png", mode.toggle()}, {"ui/icon/network.png", mode.toggle()}, }, - blue {1, 1, &TRANSPARENT_BLUE} + blue {1, 1, &TRANSPARENT_BLUE}, font {fontpath, 15} { } @@ -66,7 +67,7 @@ void EditNetwork::render(const UIShader & shader, const UIComponent::Position & parentPos) const { if (builder) { - Text {builder->hint(), {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos); + Text {builder->hint(), font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos); } builderToolbar.render(shader, parentPos); } diff --git a/ui/editNetwork.h b/ui/editNetwork.h index 23dcf43..ec06fa7 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -7,7 +7,6 @@ #include #include #include -#include template class Ray; @@ -43,6 +42,7 @@ private: Mode mode {builder}; Toolbar builderToolbar; Texture blue; + const Font font; }; template class EditNetworkOf : public EditNetwork { diff --git a/ui/font.cpp b/ui/font.cpp index f610a1b..237c22d 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -60,8 +60,6 @@ using Face = glRef; -Cache Font::cachedFontRenderings; - Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {getTextureSize(s)} { generateChars(BASIC_CHARS); diff --git a/ui/font.h b/ui/font.h index 2f3337f..3254f80 100644 --- a/ui/font.h +++ b/ui/font.h @@ -1,22 +1,17 @@ #pragma once #include -#include #include -#include #include #include #include #include #include -#include #include #include class Font { public: - static Cache cachedFontRenderings; - Font(std::filesystem::path path, unsigned int height); using Quad = std::array; diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index a577838..5bef48d 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -8,14 +8,16 @@ #include #include // IWYU pragma: keep #include -#include #include -#include #include #include -#include -GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { } +const std::filesystem::path fontpath {"/usr/share/fonts/hack/Hack-Regular.ttf"}; + +GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : + UIComponent {{{}, size}}, camera {c}, font {fontpath, 15} +{ +} constexpr ScreenAbsCoord TargetPos {5, 45}; @@ -26,7 +28,7 @@ GameMainSelector::render(const UIShader & shader, const Position & parentPos) co target->render(shader, parentPos + position + TargetPos); } if (!clicked.empty()) { - Text {clicked, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos); + Text {clicked, font, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, parentPos); } } diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index cc30707..ccf0fa0 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -2,7 +2,7 @@ #include "SDL_events.h" #include "config/types.h" -#include "special_members.h" +#include "font.h" #include "uiComponent.h" #include "worldOverlay.h" #include @@ -40,5 +40,6 @@ public: private: const Camera * camera; + const Font font; std::string clicked; }; diff --git a/ui/text.cpp b/ui/text.cpp index b776b90..7cb7d30 100644 --- a/ui/text.cpp +++ b/ui/text.cpp @@ -4,19 +4,13 @@ #include "uiComponent.h" #include #include -#include #include #include -#include -#include #include -const std::filesystem::path font {"/usr/share/fonts/hack/Hack-Regular.ttf"}; - -Text::Text(std::string_view s, Position pos, glm::vec3 c) : UIComponent {pos}, colour {c} +Text::Text(std::string_view s, const Font & font, Position pos, glm::vec3 c) : UIComponent {pos}, colour {c} { - for (const auto & textureQuads : - Font::cachedFontRenderings.get(font, static_cast(pos.size.y))->render(s)) { + for (const auto & textureQuads : font.render(s)) { auto & rendering = models.emplace_back(textureQuads.first, static_cast(6 * textureQuads.second.size())); glBindVertexArray(rendering.vao); diff --git a/ui/text.h b/ui/text.h index de2fe2e..5217050 100644 --- a/ui/text.h +++ b/ui/text.h @@ -1,5 +1,6 @@ #pragma once +#include "font.h" #include "uiComponent.h" #include #include @@ -12,7 +13,7 @@ union SDL_Event; class Text : public UIComponent { public: - Text(std::string_view s, Position, glm::vec3 colour); + Text(std::string_view s, const Font &, Position, glm::vec3 colour); void render(const UIShader &, const Position & parentPos) const override; bool handleInput(const SDL_Event &, const Position & parentPos) override; -- cgit v1.2.3 From 14d82ff67eab5d94b69fb38ea6a0bc634674245c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 26 Jan 2024 17:56:52 +0000 Subject: Remove the generic cache completely --- game/network/network.cpp | 1 - game/terrain.cpp | 2 -- game/vehicles/railVehicleClass.cpp | 14 -------------- lib/cache.cpp | 1 - lib/cache.h | 39 -------------------------------------- ui/font.cpp | 1 - ui/text.cpp | 1 - 7 files changed, 59 deletions(-) delete mode 100644 lib/cache.cpp delete mode 100644 lib/cache.h (limited to 'ui/font.cpp') diff --git a/game/network/network.cpp b/game/network/network.cpp index 500742c..b6c52b8 100644 --- a/game/network/network.cpp +++ b/game/network/network.cpp @@ -1,7 +1,6 @@ #include "network.h" #include "routeWalker.h" #include -#include #include #include #include diff --git a/game/terrain.cpp b/game/terrain.cpp index a4b6510..d2c8593 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -2,9 +2,7 @@ #include "game/geoData.h" #include "gfx/models/texture.h" #include -#include #include -#include #include #include #include diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 5fd7580..34c1359 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -2,26 +2,12 @@ #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" #include "gfx/gl/vertexArrayObject.h" -#include "gfx/models/mesh.h" -#include "gfx/models/texture.h" -#include "stream_support.h" -#include #include -#include -#include -#include -#include #include -#include #include #include -#include #include #include -#include -#include -#include -#include bool RailVehicleClass::persist(Persistence::PersistenceStore & store) diff --git a/lib/cache.cpp b/lib/cache.cpp deleted file mode 100644 index 05b26b0..0000000 --- a/lib/cache.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "cache.h" diff --git a/lib/cache.h b/lib/cache.h deleted file mode 100644 index f5fd227..0000000 --- a/lib/cache.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "special_members.h" -#include -#include -#include -#include - -template class Cache { -public: - using Ptr = std::shared_ptr; - using Key = std::tuple; - - Cache() = default; - virtual ~Cache() = default; - DEFAULT_MOVE(Cache); - NO_COPY(Cache); - - [[nodiscard]] Ptr - get(const KeyParts &... keyparts) - { - auto key = std::tie(keyparts...); - if (auto e = cached.find(key); e != cached.end()) { - return e->second; - } - return cached.emplace(key, construct(keyparts...)).first->second; - } - - [[nodiscard]] virtual Ptr - construct(const KeyParts &... keyparts) const - { - return std::make_shared(keyparts...); - } - -private: - std::map> cached; -}; - -// IWYU pragma: no_forward_declare Cache diff --git a/ui/font.cpp b/ui/font.cpp index 237c22d..b6669b0 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -1,6 +1,5 @@ #include "font.h" #include -#include #include #include #include FT_FREETYPE_H diff --git a/ui/text.cpp b/ui/text.cpp index 7cb7d30..5b9e591 100644 --- a/ui/text.cpp +++ b/ui/text.cpp @@ -3,7 +3,6 @@ #include "gfx/gl/uiShader.h" #include "uiComponent.h" #include -#include #include #include #include -- cgit v1.2.3