diff --git a/nel/include/nel/3d/texture_font.h b/nel/include/nel/3d/texture_font.h index 9ca423315..61e92fa58 100644 --- a/nel/include/nel/3d/texture_font.h +++ b/nel/include/nel/3d/texture_font.h @@ -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 _GlyphCache; + std::map _GlyphCache; SGlyphInfo* findLetterGlyph(SLetterInfo *letter, bool insert); // render letter glyph into glyph cache diff --git a/nel/src/3d/texture_font.cpp b/nel/src/3d/texture_font.cpp index dd966eb8d..9aa08ca15 100644 --- a/nel/src/3d/texture_font.cpp +++ b/nel/src/3d/texture_font.cpp @@ -161,15 +161,15 @@ void CTextureFont::repackAtlas(uint32 newW, uint32 newH) _AtlasNodes.push_back(CRect(0, 0, _TextureSizeX, _TextureSizeY)); CObjectVector&src = btm.getPixels(); - for(std::list::iterator it = _GlyphCache.begin(); it != _GlyphCache.end(); ++it) + for(std::map::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::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::iterator it = _GlyphCache.begin(); it != _GlyphCache.end(); ++it) + SLetterKey g = *letter; + g.Size = bitmapFontSize; + + std::map::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)