mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
Added sharing of glyph atlas entries between shaped glyph entries that need the same texture
This commit is contained in:
parent
91d3f3a43a
commit
16697c0503
|
@ -1109,7 +1109,20 @@ Font::Glyph* Font::getGlyphByIndex(const unsigned int id, hb_font_t* fontArg, in
|
|||
FontTexture* tex {nullptr};
|
||||
glm::ivec2 cursor {0, 0};
|
||||
const glm::ivec2 glyphSize {glyphSlot->bitmap.width, glyphSlot->bitmap.rows};
|
||||
getTextureForNewGlyph(glyphSize, tex, cursor);
|
||||
|
||||
// Check if there is already a texture entry for the glyph, otherwise create it.
|
||||
// This makes sure we don't create multiple identical glyph atlas entries and waste VRAM.
|
||||
auto it2 = mGlyphTextureMap.find(std::make_pair(id, fontArg));
|
||||
if (it2 != mGlyphTextureMap.end()) {
|
||||
tex = (*it2).second.texture;
|
||||
cursor = (*it2).second.cursor;
|
||||
}
|
||||
else {
|
||||
getTextureForNewGlyph(glyphSize, tex, cursor);
|
||||
GlyphTexture& glyphTexture {mGlyphTextureMap[std::make_pair(id, returnedFont)]};
|
||||
glyphTexture.texture = tex;
|
||||
glyphTexture.cursor = cursor;
|
||||
}
|
||||
|
||||
// This should (hopefully) never occur as size constraints are enforced earlier on.
|
||||
if (tex == nullptr) {
|
||||
|
|
|
@ -182,6 +182,11 @@ private:
|
|||
int rows;
|
||||
};
|
||||
|
||||
struct GlyphTexture {
|
||||
FontTexture* texture;
|
||||
glm::ivec2 cursor;
|
||||
};
|
||||
|
||||
struct FallbackFontCache {
|
||||
std::string path;
|
||||
std::shared_ptr<FontFace> face;
|
||||
|
@ -240,6 +245,7 @@ private:
|
|||
std::vector<std::unique_ptr<FontTexture>> mTextures;
|
||||
std::map<unsigned int, Glyph> mGlyphMap;
|
||||
std::map<std::tuple<unsigned int, hb_font_t*, int>, Glyph> mGlyphMapByIndex;
|
||||
std::map<std::pair<unsigned int, hb_font_t*>, GlyphTexture> mGlyphTextureMap;
|
||||
|
||||
const std::string mPath;
|
||||
hb_font_t* mFontHB;
|
||||
|
|
Loading…
Reference in a new issue