Fix crash in billboard text when using legacy opengl

Notice: freetype glyph metrics are not supported
This commit is contained in:
Benau 2016-11-19 15:59:58 +08:00
parent a52c4699a1
commit 9734c2e890
6 changed files with 58 additions and 41 deletions

View File

@ -95,6 +95,8 @@ public:
\param s String of symbols which are not send down to the videodriver
*/
virtual void setInvisibleCharacters( const wchar_t *s ) = 0;
virtual void addLazyLoadCharacters(const wchar_t *s) {}
};
} // end namespace gui

View File

@ -114,10 +114,12 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag
{
Font = (gui::IGUIFontBitmap*)font;
Font->grab();
u32 old_texture_count = Font->getSpriteBank()->getTextureCount();
Font->addLazyLoadCharacters(text);
// mesh with one buffer per texture
Mesh = new SMesh();
for (u32 i=0; i<Font->getSpriteBank()->getTextureCount(); ++i)
for (u32 i=0; i<old_texture_count; ++i)
{
SMeshBuffer *mb = new SMeshBuffer();
mb->Material = Material;

View File

@ -29,8 +29,6 @@ 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; }
@ -45,6 +43,8 @@ public:
virtual void init() OVERRIDE;
// ------------------------------------------------------------------------
virtual void reset() OVERRIDE;
// ------------------------------------------------------------------------
virtual bool supportLazyLoadChar() const OVERRIDE { return false; }
}; // DigitFace

View File

@ -92,39 +92,6 @@ 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.
@ -239,8 +206,6 @@ 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); }
// ------------------------------------------------------------------------
@ -248,9 +213,6 @@ 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;
@ -304,6 +266,44 @@ 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

View File

@ -125,5 +125,16 @@ u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const
return area.spriteno;
} // getSpriteNoFromChar
// ------------------------------------------------------------------------
void ScalableFont::addLazyLoadCharacters(const wchar_t *c)
{
if (!m_face->supportLazyLoadChar()) return;
m_face->insertCharacters(c);
m_face->updateCharactersList();
m_face->createNewGlyphPage();
} // addLazyLoadCharacters
} // end namespace gui
} // end namespace irr

View File

@ -86,6 +86,8 @@ public:
/** returns the sprite number from a given character */
virtual u32 getSpriteNoFromChar(const wchar_t *c) const;
// ------------------------------------------------------------------------
virtual void addLazyLoadCharacters(const wchar_t *s);
// ------------------------------------------------------------------------
// Below is not used:
/** set an Pixel Offset on Drawing ( scale position on width ) */
virtual void setKerningWidth (s32 kerning) {}