From de95db5c9397cec28749a2c0217a240dd33e036e Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 20 Nov 2016 10:08:59 +0800 Subject: [PATCH] Avoid creating new glyph page too many times --- lib/irrlicht/include/IGUIFont.h | 2 +- .../source/Irrlicht/CTextSceneNode.cpp | 6 ++--- src/guiengine/scalable_font.cpp | 23 ++++++++++++++++--- src/guiengine/scalable_font.hpp | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/irrlicht/include/IGUIFont.h b/lib/irrlicht/include/IGUIFont.h index 99d7670ab..b8ef7a070 100644 --- a/lib/irrlicht/include/IGUIFont.h +++ b/lib/irrlicht/include/IGUIFont.h @@ -96,7 +96,7 @@ public: */ virtual void setInvisibleCharacters( const wchar_t *s ) = 0; - virtual void addLazyLoadCharacters(const wchar_t *s) {} + virtual u32 addLazyLoadCharacters(const wchar_t *s) { return 0; } }; } // end namespace gui diff --git a/lib/irrlicht/source/Irrlicht/CTextSceneNode.cpp b/lib/irrlicht/source/Irrlicht/CTextSceneNode.cpp index ddccaacab..88ff8cb05 100644 --- a/lib/irrlicht/source/Irrlicht/CTextSceneNode.cpp +++ b/lib/irrlicht/source/Irrlicht/CTextSceneNode.cpp @@ -114,12 +114,12 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag { Font = (gui::IGUIFontBitmap*)font; Font->grab(); - u32 old_texture_count = Font->getSpriteBank()->getTextureCount(); - Font->addLazyLoadCharacters(text); + u32 texture_count = Font->addLazyLoadCharacters(text); + _IRR_DEBUG_BREAK_IF(texture_count==0); // mesh with one buffer per texture Mesh = new SMesh(); - for (u32 i=0; iMaterial = Material; diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index 12784a31c..331cc6ed8 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -126,13 +126,30 @@ u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const } // getSpriteNoFromChar // ------------------------------------------------------------------------ -void ScalableFont::addLazyLoadCharacters(const wchar_t *c) +u32 ScalableFont::addLazyLoadCharacters(const wchar_t *c) { - if (!m_face->supportLazyLoadChar()) return; + IGUISpriteBank* sp = m_face->getSpriteBank(); + u32 tex_count = sp->getTextureCount(); + if (!m_face->supportLazyLoadChar()) return tex_count; m_face->insertCharacters(c); m_face->updateCharactersList(); - m_face->createNewGlyphPage(); + + // Make sure text of billboard wasn't located in the last texture + for (const wchar_t p = *c; *c; c++) + { + const core::array& s = sp->getSprites(); + const FontWithFace::FontArea& area = + m_face->getAreaFromCharacter(p, NULL/*fallback_font*/); + u32 cur_tex_no = s[area.spriteno].Frames[0].textureNumber; + if (cur_tex_no == (tex_count -1)) + { + m_face->createNewGlyphPage(); + return tex_count; + } + } + + return tex_count -1; } // addLazyLoadCharacters diff --git a/src/guiengine/scalable_font.hpp b/src/guiengine/scalable_font.hpp index 7ef1b3faf..dae0b9728 100644 --- a/src/guiengine/scalable_font.hpp +++ b/src/guiengine/scalable_font.hpp @@ -86,7 +86,7 @@ public: /** returns the sprite number from a given character */ virtual u32 getSpriteNoFromChar(const wchar_t *c) const; // ------------------------------------------------------------------------ - virtual void addLazyLoadCharacters(const wchar_t *s); + virtual u32 addLazyLoadCharacters(const wchar_t *s); // ------------------------------------------------------------------------ // Below is not used: /** set an Pixel Offset on Drawing ( scale position on width ) */