Fix crash in billboard text when using legacy opengl
Notice: freetype glyph metrics are not supported
This commit is contained in:
parent
a52c4699a1
commit
9734c2e890
@ -95,6 +95,8 @@ public:
|
|||||||
\param s String of symbols which are not send down to the videodriver
|
\param s String of symbols which are not send down to the videodriver
|
||||||
*/
|
*/
|
||||||
virtual void setInvisibleCharacters( const wchar_t *s ) = 0;
|
virtual void setInvisibleCharacters( const wchar_t *s ) = 0;
|
||||||
|
|
||||||
|
virtual void addLazyLoadCharacters(const wchar_t *s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace gui
|
} // end namespace gui
|
||||||
|
@ -114,10 +114,12 @@ CBillboardTextSceneNode::CBillboardTextSceneNode(ISceneNode* parent, ISceneManag
|
|||||||
{
|
{
|
||||||
Font = (gui::IGUIFontBitmap*)font;
|
Font = (gui::IGUIFontBitmap*)font;
|
||||||
Font->grab();
|
Font->grab();
|
||||||
|
u32 old_texture_count = Font->getSpriteBank()->getTextureCount();
|
||||||
|
Font->addLazyLoadCharacters(text);
|
||||||
|
|
||||||
// mesh with one buffer per texture
|
// mesh with one buffer per texture
|
||||||
Mesh = new SMesh();
|
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();
|
SMeshBuffer *mb = new SMeshBuffer();
|
||||||
mb->Material = Material;
|
mb->Material = Material;
|
||||||
|
@ -29,8 +29,6 @@ class FaceTTF;
|
|||||||
class DigitFace : public FontWithFace
|
class DigitFace : public FontWithFace
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
virtual bool supportLazyLoadChar() const OVERRIDE { return false; }
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
virtual unsigned int getGlyphPageSize() const OVERRIDE { return 256; }
|
virtual unsigned int getGlyphPageSize() const OVERRIDE { return 256; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual float getScalingFactorOne() const OVERRIDE { return 0.7f; }
|
virtual float getScalingFactorOne() const OVERRIDE { return 0.7f; }
|
||||||
@ -45,6 +43,8 @@ public:
|
|||||||
virtual void init() OVERRIDE;
|
virtual void init() OVERRIDE;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
virtual void reset() OVERRIDE;
|
virtual void reset() OVERRIDE;
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
virtual bool supportLazyLoadChar() const OVERRIDE { return false; }
|
||||||
|
|
||||||
}; // DigitFace
|
}; // DigitFace
|
||||||
|
|
||||||
|
@ -92,39 +92,6 @@ protected:
|
|||||||
/** Used in top side bearing calculation. */
|
/** Used in top side bearing calculation. */
|
||||||
int m_glyph_max_height;
|
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
|
/** 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.
|
* this font, it will use that fallback font to try rendering it.
|
||||||
@ -239,8 +206,6 @@ private:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void loadGlyphInfo(wchar_t c);
|
void loadGlyphInfo(wchar_t c);
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void createNewGlyphPage();
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
/** Add a character into \ref m_new_char_holder for lazy loading later. */
|
/** Add a character into \ref m_new_char_holder for lazy loading later. */
|
||||||
void addLazyLoadChar(wchar_t c) { m_new_char_holder.insert(c); }
|
void addLazyLoadChar(wchar_t c) { m_new_char_holder.insert(c); }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -248,9 +213,6 @@ private:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setDPI();
|
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
|
/** Defined by sub-class about the texture size of glyph page, it should be
|
||||||
* a power of two. */
|
* a power of two. */
|
||||||
virtual unsigned int getGlyphPageSize() const = 0;
|
virtual unsigned int getGlyphPageSize() const = 0;
|
||||||
@ -304,6 +266,44 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Return the dpi of this face. */
|
/** Return the dpi of this face. */
|
||||||
unsigned int getDPI() const { return m_face_dpi; }
|
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
|
}; // FontWithFace
|
||||||
|
|
||||||
|
@ -125,5 +125,16 @@ u32 ScalableFont::getSpriteNoFromChar(const wchar_t *c) const
|
|||||||
return area.spriteno;
|
return area.spriteno;
|
||||||
} // getSpriteNoFromChar
|
} // 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 gui
|
||||||
} // end namespace irr
|
} // end namespace irr
|
||||||
|
@ -86,6 +86,8 @@ public:
|
|||||||
/** returns the sprite number from a given character */
|
/** returns the sprite number from a given character */
|
||||||
virtual u32 getSpriteNoFromChar(const wchar_t *c) const;
|
virtual u32 getSpriteNoFromChar(const wchar_t *c) const;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
virtual void addLazyLoadCharacters(const wchar_t *s);
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
// Below is not used:
|
// Below is not used:
|
||||||
/** set an Pixel Offset on Drawing ( scale position on width ) */
|
/** set an Pixel Offset on Drawing ( scale position on width ) */
|
||||||
virtual void setKerningWidth (s32 kerning) {}
|
virtual void setKerningWidth (s32 kerning) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user