Fix for broken text when the font is reloaded.

This commit is contained in:
Maximilian Wagenbach 2018-01-15 17:37:50 +01:00
parent b6c1acab3c
commit c24de5fcaf
3 changed files with 19 additions and 8 deletions

View File

@ -393,6 +393,7 @@ private:
mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
mutable Uint64 m_fontTextureId; ///< The font texture id
};
} // namespace sf

View File

@ -35,10 +35,11 @@
namespace sf
{
class Window;
class InputStream;
class RenderTarget;
class RenderTexture;
class InputStream;
class Text;
class Window;
////////////////////////////////////////////////////////////
/// \brief Image living on the graphics card that can be used for drawing
@ -584,6 +585,7 @@ public:
private:
friend class Text;
friend class RenderTexture;
friend class RenderTarget;

View File

@ -84,7 +84,8 @@ m_outlineThickness (0),
m_vertices (Triangles),
m_outlineVertices (Triangles),
m_bounds (),
m_geometryNeedUpdate(false)
m_geometryNeedUpdate(false),
m_fontTextureId (0)
{
}
@ -102,7 +103,8 @@ m_outlineThickness (0),
m_vertices (Triangles),
m_outlineVertices (Triangles),
m_bounds (),
m_geometryNeedUpdate(true)
m_geometryNeedUpdate(true),
m_fontTextureId (0)
{
}
@ -346,10 +348,16 @@ void Text::draw(RenderTarget& target, RenderStates states) const
////////////////////////////////////////////////////////////
void Text::ensureGeometryUpdate() const
{
// Do nothing, if geometry has not changed
if (!m_geometryNeedUpdate)
if (!m_font)
return;
// Do nothing, if geometry has not changed and the font texture has not changed
if (!m_geometryNeedUpdate && m_font->getTexture(m_characterSize).m_cacheId == m_fontTextureId)
return;
// Save the current fonts texture id
m_fontTextureId = m_font->getTexture(m_characterSize).m_cacheId;
// Mark geometry as updated
m_geometryNeedUpdate = false;
@ -358,8 +366,8 @@ void Text::ensureGeometryUpdate() const
m_outlineVertices.clear();
m_bounds = FloatRect();
// No font or text: nothing to draw
if (!m_font || m_string.isEmpty())
// No text: nothing to draw
if (m_string.isEmpty())
return;
// Compute values related to the text style