Change glyph cache to map lookup, ryzom/ryzomcore#626

develop
Nimetu 4 years ago
parent 990c38ca81
commit f39038f98d

@ -67,13 +67,14 @@ public:
} }
}; };
// Holds info for glyphs rendered on atlas // Holds info for glyphs rendered on atlas
struct SGlyphInfo struct SGlyphInfo : SLetterKey
{ {
// font atlas info // font atlas info
uint32 CacheVersion; uint32 CacheVersion;
uint32 GlyphIndex;
// atlas region with padding // atlas region with padding
uint32 X, Y, W, H; uint32 X, Y, W, H;
@ -84,17 +85,10 @@ public:
// UV coords for rendered glyph without padding // UV coords for rendered glyph without padding
float U0, V0, U1, V1; float U0, V0, U1, V1;
uint32 GlyphIndex;
sint Size;
bool Embolden;
bool Oblique;
CFontGenerator *FontGenerator;
SGlyphInfo() SGlyphInfo()
: CacheVersion(0), : CacheVersion(0), GlyphIndex(0),
U0(0.f), V0(0.f), U1(0.f), V1(0.f), U0(0.f), V0(0.f), U1(0.f), V1(0.f),
X(0), Y(0), W(0), H(0), CharWidth(0), CharHeight(0), X(0), Y(0), W(0), H(0), CharWidth(0), CharHeight(0)
GlyphIndex(0), Size(0), Embolden(false), Oblique(false), FontGenerator(NULL)
{ {
} }
}; };
@ -172,7 +166,7 @@ private:
uint _GlyphSizeStep; uint _GlyphSizeStep;
// rendered glyph cache // rendered glyph cache
std::list<SGlyphInfo> _GlyphCache; std::map<SLetterKey, SGlyphInfo> _GlyphCache;
SGlyphInfo* findLetterGlyph(SLetterInfo *letter, bool insert); SGlyphInfo* findLetterGlyph(SLetterInfo *letter, bool insert);
// render letter glyph into glyph cache // render letter glyph into glyph cache

@ -161,15 +161,15 @@ void CTextureFont::repackAtlas(uint32 newW, uint32 newH)
_AtlasNodes.push_back(CRect(0, 0, _TextureSizeX, _TextureSizeY)); _AtlasNodes.push_back(CRect(0, 0, _TextureSizeX, _TextureSizeY));
CObjectVector<uint8>&src = btm.getPixels(); CObjectVector<uint8>&src = btm.getPixels();
for(std::list<SGlyphInfo>::iterator it = _GlyphCache.begin(); it != _GlyphCache.end(); ++it) for(std::map<SLetterKey, SGlyphInfo>::iterator it = _GlyphCache.begin(); it != _GlyphCache.end(); ++it)
{ {
if (it->CacheVersion != _CacheVersion) if (it->second.CacheVersion != _CacheVersion)
{ {
// TODO: must remove glyph from all letters before removing glyph from cache // TODO: must remove glyph from all letters before removing glyph from cache
//continue; //continue;
} }
SGlyphInfo &glyph = *it; SGlyphInfo &glyph = it->second;
glyph.CacheVersion = newCacheVersion; glyph.CacheVersion = newCacheVersion;
@ -403,18 +403,10 @@ CTextureFont::SGlyphInfo* CTextureFont::renderLetterGlyph(SLetterInfo *letter, u
} }
copyGlyphBitmap(bitmap, charWidth, charHeight, atlasX, atlasY); copyGlyphBitmap(bitmap, charWidth, charHeight, atlasX, atlasY);
SGlyphInfo* glyphInfo = NULL; SLetterKey k = *letter;
{ k.Size = bitmapFontSize;
// keep cache sorted by height (smaller first)
std::list<SGlyphInfo>::iterator it = _GlyphCache.begin();
while(it != _GlyphCache.end() && it->CharHeight < charHeight)
{
++it;
}
it = _GlyphCache.insert(it, SGlyphInfo()); SGlyphInfo* glyphInfo = &_GlyphCache[k];
glyphInfo = &(*it);
}
glyphInfo->GlyphIndex = glyphIndex; glyphInfo->GlyphIndex = glyphIndex;
glyphInfo->Size = bitmapFontSize; glyphInfo->Size = bitmapFontSize;
@ -450,16 +442,13 @@ CTextureFont::SGlyphInfo* CTextureFont::findLetterGlyph(SLetterInfo *letter, boo
} }
// CacheVersion not checked, all glyphs in cache must be rendered on texture // CacheVersion not checked, all glyphs in cache must be rendered on texture
for(std::list<SGlyphInfo>::iterator it = _GlyphCache.begin(); it != _GlyphCache.end(); ++it) SLetterKey g = *letter;
{ g.Size = bitmapFontSize;
if (it->GlyphIndex == letter->GlyphIndex &&
it->Size == bitmapFontSize && std::map<SLetterKey, SGlyphInfo>::iterator it = _GlyphCache.find(g);
it->Embolden == letter->Embolden && if (it != _GlyphCache.end())
it->Oblique == letter->Oblique &&
it->FontGenerator == letter->FontGenerator)
{ {
return &(*it); return &(it->second);
}
} }
if (insert) if (insert)

Loading…
Cancel
Save