From c24de5fcaf70012c507dcc6ed6b011732c1d7b8f Mon Sep 17 00:00:00 2001 From: Maximilian Wagenbach Date: Mon, 15 Jan 2018 17:37:50 +0100 Subject: [PATCH] Fix for broken text when the font is reloaded. --- include/SFML/Graphics/Text.hpp | 1 + include/SFML/Graphics/Texture.hpp | 6 ++++-- src/SFML/Graphics/Text.cpp | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index 7b7cf611..b135ceb8 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -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 diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index 20a8ede8..551dde6b 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -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; diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 5ad50c1f..6b6344c8 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -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