From 2dff84fddcffde95e882faceb45d5797dc5c63b9 Mon Sep 17 00:00:00 2001 From: Jere Tuliniemi Date: Mon, 10 Feb 2020 13:08:13 +0200 Subject: Fix distance field text caching logic For whatever reason EndFrame is called without the text being rendered in the frame, so we need to keep both text and glyph caches alive during those passes. Previously only text hashes were saved, so now the glyphs are too to prevent building meshes again. Text and glyph hashes are also now not added twice to the lists. Task-number: QT3DS-4062 Change-Id: I3e5cddab788a0d974c98e533d131ed8ae24569ac Reviewed-by: Janne Koskinen Reviewed-by: Janne Kangas Reviewed-by: Miikka Heikkinen --- src/runtimerender/Qt3DSDistanceFieldRenderer.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp b/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp index 5ceb9fa..12c46c3 100644 --- a/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp +++ b/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp @@ -986,10 +986,12 @@ void Q3DSDistanceFieldRenderer::renderText(SText &text, const QT3DSMat44 &mvp) glyphInfo.fontScale * float(m_pixelRatio), textColor); } - m_renderedGlyphs += glyphHashValue; + if (!m_renderedGlyphs.contains(glyphHashValue)) + m_renderedGlyphs += glyphHashValue; } - m_renderedTexts += textHashValue; + if (!m_renderedTexts.contains(textHashValue)) + m_renderedTexts += textHashValue; text.m_Bounds = NVBounds3(minimum, maximum); } @@ -1013,9 +1015,20 @@ ITextRendererCore &ITextRendererCore::createDistanceFieldRenderer(NVFoundationBa void Q3DSDistanceFieldRenderer::checkAndAddRenderedTexts(SText &text) { - auto hashVal = getTextHashValue(text); - if (m_glyphCache.contains(hashVal)) - m_renderedTexts += hashVal; + auto textHashVal = getTextHashValue(text); + if (m_glyphCache.contains(textHashVal)) { + m_renderedTexts += textHashVal; + + QHash &glyphsPerTexture + = m_glyphCache[textHashVal]; + QHash::const_iterator it; + for (it = glyphsPerTexture.constBegin(); it != glyphsPerTexture.constEnd(); ++it) { + const GlyphInfo &glyphInfo = it.value(); + size_t glyphHashValue = getGlyphHashValue(glyphInfo); + if (m_meshCache.contains(glyphHashValue)) + m_renderedGlyphs += glyphHashValue; + } + } } // Unused methods: -- cgit v1.2.3