From c4b4ea006ebc8165c85acb4987f900b859ea2eec Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 9 Jan 2017 13:16:40 +0800 Subject: [PATCH] We don't need to add a new glyph page for billboard text anymore --- lib/irrlicht/include/IGUIFont.h | 2 - .../source/Irrlicht/CTextSceneNode.cpp | 4 +- src/font/digit_face.hpp | 4 +- src/font/font_with_face.hpp | 76 +++++++++---------- src/graphics/stk_texture.cpp | 3 +- src/guiengine/scalable_font.cpp | 28 ------- src/guiengine/scalable_font.hpp | 2 - 7 files changed, 42 insertions(+), 77 deletions(-) diff --git a/lib/irrlicht/include/IGUIFont.h b/lib/irrlicht/include/IGUIFont.h index b8ef7a070..4746c81a7 100644 --- a/lib/irrlicht/include/IGUIFont.h +++ b/lib/irrlicht/include/IGUIFont.h @@ -95,8 +95,6 @@ public: \param s String of symbols which are not send down to the videodriver */ virtual void setInvisibleCharacters( const wchar_t *s ) = 0; - - 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 88ff8cb05..7edf2f5fe 100644 --- a/lib/irrlicht/source/Irrlicht/CTextSceneNode.cpp +++ b/lib/irrlicht/source/Irrlicht/CTextSceneNode.cpp @@ -114,12 +114,10 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag { Font = (gui::IGUIFontBitmap*)font; Font->grab(); - 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; igetSpriteBank()->getTextureCount(); ++i) { SMeshBuffer *mb = new SMeshBuffer(); mb->Material = Material; diff --git a/src/font/digit_face.hpp b/src/font/digit_face.hpp index bfb62bc3a..a5aed4dab 100644 --- a/src/font/digit_face.hpp +++ b/src/font/digit_face.hpp @@ -29,6 +29,8 @@ class FaceTTF; class DigitFace : public FontWithFace { private: + virtual bool supportLazyLoadChar() const OVERRIDE { return false; } + // ------------------------------------------------------------------------ virtual unsigned int getGlyphPageSize() const OVERRIDE { return 256; } // ------------------------------------------------------------------------ virtual float getScalingFactorOne() const OVERRIDE { return 0.7f; } @@ -43,8 +45,6 @@ public: virtual void init() OVERRIDE; // ------------------------------------------------------------------------ virtual void reset() OVERRIDE; - // ------------------------------------------------------------------------ - virtual bool supportLazyLoadChar() const OVERRIDE { return false; } }; // DigitFace diff --git a/src/font/font_with_face.hpp b/src/font/font_with_face.hpp index 6ba70c2a4..ca960c218 100644 --- a/src/font/font_with_face.hpp +++ b/src/font/font_with_face.hpp @@ -92,6 +92,39 @@ protected: /** Used in top side bearing calculation. */ int m_glyph_max_height; + // ------------------------------------------------------------------------ + /** Check characters to see if they are loaded in font, if not load them. + * For font that doesn't need lazy loading, nothing will be done. + * \param in_ptr Characters to check. + * \param first_load If true, it will ignore \ref supportLazyLoadChar, + * which is called in \ref reset. */ + void insertCharacters(const wchar_t* in_ptr, bool first_load = false) + { + if (!supportLazyLoadChar() && !first_load) return; + + for (const wchar_t* p = in_ptr; *p; ++p) + { + if (*p == L'\r' || *p == L'\n' || *p < (wchar_t)32) + continue; + if (!loadedChar(*p)) + { + loadGlyphInfo(*p); + if (supportChar(*p)) + addLazyLoadChar(*p); + else if (m_fallback_font != NULL) + { + if (!m_fallback_font->loadedChar(*p)) + { + m_fallback_font->loadGlyphInfo(*p); + if (m_fallback_font->supportChar(*p)) + m_fallback_font->addLazyLoadChar(*p); + } + } + } + } + } + // ------------------------------------------------------------------------ + void updateCharactersList(); // ------------------------------------------------------------------------ /** Set the fallback font for this font, so if some character is missing in * this font, it will use that fallback font to try rendering it. @@ -203,6 +236,8 @@ private: // ------------------------------------------------------------------------ void loadGlyphInfo(wchar_t c); // ------------------------------------------------------------------------ + void createNewGlyphPage(); + // ------------------------------------------------------------------------ /** Add a character into \ref m_new_char_holder for lazy loading later. */ void addLazyLoadChar(wchar_t c) { m_new_char_holder.insert(c); } // ------------------------------------------------------------------------ @@ -210,6 +245,9 @@ private: // ------------------------------------------------------------------------ void setDPI(); // ------------------------------------------------------------------------ + /** Override it if sub-class should not do lazy loading characters. */ + virtual bool supportLazyLoadChar() const { return true; } + // ------------------------------------------------------------------------ /** Defined by sub-class about the texture size of glyph page, it should be * a power of two. */ virtual unsigned int getGlyphPageSize() const = 0; @@ -263,44 +301,6 @@ public: // ------------------------------------------------------------------------ /** Return the dpi of this face. */ unsigned int getDPI() const { return m_face_dpi; } - // ------------------------------------------------------------------------ - /** Override it if sub-class should not do lazy loading characters. */ - virtual bool supportLazyLoadChar() const { return true; } - // ------------------------------------------------------------------------ - /** Check characters to see if they are loaded in font, if not load them. - * For font that doesn't need lazy loading, nothing will be done. - * \param in_ptr Characters to check. - * \param first_load If true, it will ignore \ref supportLazyLoadChar, - * which is called in \ref reset. */ - void insertCharacters(const wchar_t* in_ptr, bool first_load = false) - { - if (!supportLazyLoadChar() && !first_load) return; - - for (const wchar_t* p = in_ptr; *p; ++p) - { - if (*p == L'\r' || *p == L'\n' || *p < (wchar_t)32) - continue; - if (!loadedChar(*p)) - { - loadGlyphInfo(*p); - if (supportChar(*p)) - addLazyLoadChar(*p); - else if (m_fallback_font != NULL) - { - if (!m_fallback_font->loadedChar(*p)) - { - m_fallback_font->loadGlyphInfo(*p); - if (m_fallback_font->supportChar(*p)) - m_fallback_font->addLazyLoadChar(*p); - } - } - } - } - } - // ------------------------------------------------------------------------ - void updateCharactersList(); - // ------------------------------------------------------------------------ - void createNewGlyphPage(); }; // FontWithFace diff --git a/src/graphics/stk_texture.cpp b/src/graphics/stk_texture.cpp index 2b00388c6..11d9e39c8 100644 --- a/src/graphics/stk_texture.cpp +++ b/src/graphics/stk_texture.cpp @@ -518,9 +518,8 @@ u64 STKTexture::getHandle() if (!glIsTextureHandleResidentARB(m_texture_handle)) glMakeTextureHandleResidentARB(m_texture_handle); - - return m_texture_handle; #endif + return m_texture_handle; } // getHandle //----------------------------------------------------------------------------- diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index 037941d4a..7173e177d 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -127,33 +127,5 @@ u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const return area.spriteno; } // getSpriteNoFromChar -// ------------------------------------------------------------------------ -u32 ScalableFont::addLazyLoadCharacters(const wchar_t *c) -{ - IGUISpriteBank* sp = m_face->getSpriteBank(); - u32 tex_count = sp->getTextureCount(); - if (!m_face->supportLazyLoadChar()) return tex_count; - - m_face->insertCharacters(c); - m_face->updateCharactersList(); - - // 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 - } // end namespace gui } // end namespace irr diff --git a/src/guiengine/scalable_font.hpp b/src/guiengine/scalable_font.hpp index dae0b9728..2f03508a8 100644 --- a/src/guiengine/scalable_font.hpp +++ b/src/guiengine/scalable_font.hpp @@ -86,8 +86,6 @@ public: /** returns the sprite number from a given character */ virtual u32 getSpriteNoFromChar(const wchar_t *c) const; // ------------------------------------------------------------------------ - virtual u32 addLazyLoadCharacters(const wchar_t *s); - // ------------------------------------------------------------------------ // Below is not used: /** set an Pixel Offset on Drawing ( scale position on width ) */ virtual void setKerningWidth (s32 kerning) {}