summaryrefslogtreecommitdiff
path: root/ui/font.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-01-02 01:32:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-01-02 01:32:02 +0000
commitcf64ce9a1312de5e9a76bb3f43105a4eac59eb15 (patch)
tree7ddf3d3bfc7a7add7a8eacde3862206cd2fd5ec4 /ui/font.cpp
parentCache allows multiple key parts (diff)
downloadilt-cf64ce9a1312de5e9a76bb3f43105a4eac59eb15.tar.bz2
ilt-cf64ce9a1312de5e9a76bb3f43105a4eac59eb15.tar.xz
ilt-cf64ce9a1312de5e9a76bb3f43105a4eac59eb15.zip
Use Cache system to persist font rendering for Text
Diffstat (limited to 'ui/font.cpp')
-rw-r--r--ui/font.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/ui/font.cpp b/ui/font.cpp
index 5596f20..712818d 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -1,13 +1,16 @@
#include "font.h"
#include <algorithm>
+#include <cache.h>
#include <cctype>
#include <ft2build.h>
#include FT_FREETYPE_H
+#include "glArrays.h"
#include <glRef.hpp>
#include <maths.h>
#include <memory>
#include <optional>
#include <stdexcept>
+#include <string>
#include <unicode.h>
#include <utility>
// IWYU pragma: no_forward_declare FT_LibraryRec_
@@ -56,7 +59,9 @@ using Face = glRef<FT_Face,
},
FT_Done_Face>;
-Font::Font(const char * const p, unsigned s) : path {p}, size {getTextureSize(s)}
+Cache<Font, std::filesystem::path, unsigned int> Font::cachedFontRenderings;
+
+Font::Font(std::filesystem::path p, unsigned s) : path {std::move(p)}, size {getTextureSize(s)}
{
generateChars(BASIC_CHARS);
}
@@ -115,7 +120,6 @@ Font::getTextureWithSpace(unsigned int adv) const
}
auto & texture = fontTextures.emplace_back();
- glGenTextures(1, &texture.texture);
glBindTexture(GL_TEXTURE_2D, texture.texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, static_cast<GLsizei>(size.x), static_cast<GLsizei>(size.y), 0, GL_RED,
GL_UNSIGNED_BYTE, nullptr);