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
struct SGlyphInfo
struct SGlyphInfo : SLetterKey
{
// font atlas info
uint32 CacheVersion;
uint32 GlyphIndex;
// atlas region with padding
uint32 X, Y, W, H;
@ -84,17 +85,10 @@ public:
// UV coords for rendered glyph without padding
float U0, V0, U1, V1;
uint32 GlyphIndex;
sint Size;
bool Embolden;
bool Oblique;
CFontGenerator *FontGenerator;
SGlyphInfo()
: CacheVersion(0),
: CacheVersion(0), GlyphIndex(0),
U0(0.f), V0(0.f), U1(0.f), V1(0.f),
X(0), Y(0), W(0), H(0), CharWidth(0), CharHeight(0),
GlyphIndex(0), Size(0), Embolden(false), Oblique(false), FontGenerator(NULL)
X(0), Y(0), W(0), H(0), CharWidth(0), CharHeight(0)
{
}
};
@ -172,7 +166,7 @@ private:
uint _GlyphSizeStep;
// rendered glyph cache
std::list<SGlyphInfo> _GlyphCache;
std::map<SLetterKey, SGlyphInfo> _GlyphCache;
SGlyphInfo* findLetterGlyph(SLetterInfo *letter, bool insert);
// 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));
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
//continue;
}
SGlyphInfo &glyph = *it;
SGlyphInfo &glyph = it->second;
glyph.CacheVersion = newCacheVersion;
@ -403,18 +403,10 @@ CTextureFont::SGlyphInfo* CTextureFont::renderLetterGlyph(SLetterInfo *letter, u
}
copyGlyphBitmap(bitmap, charWidth, charHeight, atlasX, atlasY);
SGlyphInfo* glyphInfo = NULL;
{
// keep cache sorted by height (smaller first)
std::list<SGlyphInfo>::iterator it = _GlyphCache.begin();
while(it != _GlyphCache.end() && it->CharHeight < charHeight)
{
++it;
}
SLetterKey k = *letter;
k.Size = bitmapFontSize;
it = _GlyphCache.insert(it, SGlyphInfo());
glyphInfo = &(*it);
}
SGlyphInfo* glyphInfo = &_GlyphCache[k];
glyphInfo->GlyphIndex = glyphIndex;
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
for(std::list<SGlyphInfo>::iterator it = _GlyphCache.begin(); it != _GlyphCache.end(); ++it)
SLetterKey g = *letter;
g.Size = bitmapFontSize;
std::map<SLetterKey, SGlyphInfo>::iterator it = _GlyphCache.find(g);
if (it != _GlyphCache.end())
{
if (it->GlyphIndex == letter->GlyphIndex &&
it->Size == bitmapFontSize &&
it->Embolden == letter->Embolden &&
it->Oblique == letter->Oblique &&
it->FontGenerator == letter->FontGenerator)
{
return &(*it);
}
return &(it->second);
}
if (insert)

Loading…
Cancel
Save