summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2020-11-13 11:02:50 +0200
committerTomi Korpipaa <tomi.korpipaa@qt.io>2020-11-18 14:08:01 +0200
commit0ac26f8f9726281f7bff01f3c07a9c6b99d9e9d5 (patch)
treee77bc0d24a307938725f3b10282aa7752052c532
parentfd4aa9570ab88b55f4c41b112708a4bc4ab8fd33 (diff)
Fix getting wrong text texture
eastl::hash occasionally returns the same hash for different numerical strings for some reason. Replace eastl::hash with qHashBits for CRegisteredString. Task-number: QT3DS-4203 Change-Id: Ied943d7489233792b84fb0f612e6019f11532909 Reviewed-by: Antti Määttä <antti.maatta@qt.io>
-rw-r--r--src/foundation/StringTable.h2
-rw-r--r--src/render/Qt3DSRenderContext.h8
-rw-r--r--src/runtimerender/Qt3DSRenderTextTextureCache.cpp76
-rw-r--r--src/runtimerender/Qt3DSRenderTextTypes.h2
-rw-r--r--src/runtimerender/Qt3DSRenderUIPSharedTranslation.h1
-rw-r--r--src/runtimerender/graphobjects/Qt3DSRenderText.cpp1
6 files changed, 34 insertions, 56 deletions
diff --git a/src/foundation/StringTable.h b/src/foundation/StringTable.h
index 8f7fa84..0a25a32 100644
--- a/src/foundation/StringTable.h
+++ b/src/foundation/StringTable.h
@@ -146,7 +146,7 @@ namespace foundation {
answer = *inStr - *myStr;
return answer < 0;
}
- size_t hash() const { return eastl::hash<size_t>()(reinterpret_cast<size_t>(m_String)); }
+ size_t hash() const { return qHashBits(m_String, strlen(m_String) * sizeof(char8_t)); }
operator Qt3DSBCharPtr() const { return c_str(); }
Qt3DSBCharPtr c_str() const { return m_String ? m_String : ""; }
bool IsValid() const { return m_String && *m_String; }
diff --git a/src/render/Qt3DSRenderContext.h b/src/render/Qt3DSRenderContext.h
index e729ad1..47b860f 100644
--- a/src/render/Qt3DSRenderContext.h
+++ b/src/render/Qt3DSRenderContext.h
@@ -1063,9 +1063,9 @@ namespace render {
// copy framebuffer content between read target and render target
void BlitFramebuffer(QT3DSI32 srcX0, QT3DSI32 srcY0, QT3DSI32 srcX1, QT3DSI32 srcY1,
- QT3DSI32 dstX0, QT3DSI32 dstY0, QT3DSI32 dstX1, QT3DSI32 dstY1,
- NVRenderClearFlags flags,
- NVRenderTextureMagnifyingOp::Enum filter) override;
+ QT3DSI32 dstX0, QT3DSI32 dstY0, QT3DSI32 dstX1, QT3DSI32 dstY1,
+ NVRenderClearFlags flags,
+ NVRenderTextureMagnifyingOp::Enum filter) override;
void Draw(NVRenderDrawMode::Enum drawMode, QT3DSU32 count, QT3DSU32 offset) override;
void DrawIndirect(NVRenderDrawMode::Enum drawMode, QT3DSU32 offset) override;
@@ -1077,7 +1077,7 @@ namespace render {
{
return m_backend->format();
}
- virtual void resetStates()
+ virtual void resetStates() override
{
PushPropertySet();
PopPropertySet(true);
diff --git a/src/runtimerender/Qt3DSRenderTextTextureCache.cpp b/src/runtimerender/Qt3DSRenderTextTextureCache.cpp
index 8edbeca..91a841a 100644
--- a/src/runtimerender/Qt3DSRenderTextTextureCache.cpp
+++ b/src/runtimerender/Qt3DSRenderTextTextureCache.cpp
@@ -37,32 +37,41 @@
#include "render/Qt3DSRenderContext.h"
#include "foundation/Qt3DSInvasiveLinkedList.h"
#include "foundation/Qt3DSPool.h"
+#include <functional> // for std::hash
using namespace qt3ds::render;
+// Copied from boost
+template <class T>
+inline void hashCombine(std::size_t &seed, const T &v)
+{
+ std::hash<T> hasher;
+ seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+}
+
namespace eastl {
template <>
struct hash<STextRenderInfo>
{
size_t operator()(const qt3ds::render::STextRenderInfo &inInfo) const
{
- size_t retval = hash<size_t>()(reinterpret_cast<size_t>(inInfo.m_Text.c_str()));
- retval = retval ^ hash<size_t>()(reinterpret_cast<size_t>(inInfo.m_Font.c_str()));
- retval = retval ^ hash<float>()(inInfo.m_FontSize);
- retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_HorizontalAlignment));
- retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_VerticalAlignment));
- retval = retval ^ hash<float>()(inInfo.m_Leading);
- retval = retval ^ hash<float>()(inInfo.m_Tracking);
- retval = retval ^ hash<bool>()(inInfo.m_DropShadow);
- retval = retval ^ hash<float>()(inInfo.m_DropShadowStrength);
- retval = retval ^ hash<float>()(inInfo.m_DropShadowOffsetX);
- retval = retval ^ hash<float>()(inInfo.m_DropShadowOffsetY);
- retval = retval ^ hash<float>()(inInfo.m_BoundingBox.x);
- retval = retval ^ hash<float>()(inInfo.m_BoundingBox.y);
- retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_Elide));
- retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_WordWrap));
- retval = retval ^ hash<bool>()(inInfo.m_EnableAcceleratedFont);
- return retval;
+ size_t hashValue = 0;
+ hashCombine(hashValue, std::string(inInfo.m_Font.c_str()));
+ hashCombine(hashValue, std::string(inInfo.m_Text.c_str()));
+ hashCombine(hashValue, int(inInfo.m_Elide));
+ hashCombine(hashValue, inInfo.m_Leading);
+ hashCombine(hashValue, inInfo.m_FontSize);
+ hashCombine(hashValue, inInfo.m_Tracking);
+ hashCombine(hashValue, int(inInfo.m_WordWrap));
+ hashCombine(hashValue, inInfo.m_DropShadow);
+ hashCombine(hashValue, inInfo.m_BoundingBox.x);
+ hashCombine(hashValue, inInfo.m_BoundingBox.y);
+ hashCombine(hashValue, inInfo.m_DropShadowOffsetX);
+ hashCombine(hashValue, inInfo.m_DropShadowOffsetY);
+ hashCombine(hashValue, inInfo.m_DropShadowStrength);
+ hashCombine(hashValue, int(inInfo.m_VerticalAlignment));
+ hashCombine(hashValue, int(inInfo.m_HorizontalAlignment));
+ return hashValue;
}
};
}
@@ -81,20 +90,7 @@ struct STextRenderInfoAndHash
}
bool operator==(const STextRenderInfoAndHash &inOther) const
{
- return m_Info.m_Text == inOther.m_Info.m_Text && m_Info.m_Font == inOther.m_Info.m_Font
- && m_Info.m_FontSize == inOther.m_Info.m_FontSize
- && m_Info.m_HorizontalAlignment == inOther.m_Info.m_HorizontalAlignment
- && m_Info.m_VerticalAlignment == inOther.m_Info.m_VerticalAlignment
- && m_Info.m_Leading == inOther.m_Info.m_Leading
- && m_Info.m_Tracking == inOther.m_Info.m_Tracking
- && m_Info.m_DropShadow == inOther.m_Info.m_DropShadow
- && m_Info.m_DropShadowStrength == inOther.m_Info.m_DropShadowStrength
- && m_Info.m_DropShadowOffsetX == inOther.m_Info.m_DropShadowOffsetX
- && m_Info.m_DropShadowOffsetY == inOther.m_Info.m_DropShadowOffsetY
- && m_Info.m_BoundingBox == inOther.m_Info.m_BoundingBox
- && m_Info.m_WordWrap == inOther.m_Info.m_WordWrap
- && m_Info.m_EnableAcceleratedFont == inOther.m_Info.m_EnableAcceleratedFont
- && m_ScaleFactor == inOther.m_ScaleFactor;
+ return m_Hashcode == inOther.m_Hashcode;
}
};
}
@@ -189,7 +185,6 @@ struct STextTextureCache : public ITextTextureCache
STextCacheNode &theEnd = m_LRUList.back();
if (theEnd.m_FrameCount != m_FrameCount) {
nextTexture = theEnd.m_TextInfo.second.second;
- STextureDetails theDetails = nextTexture->GetTextureDetails();
m_TextureTotalBytes -= GetNumBytes(*nextTexture.mPtr);
m_LRUList.remove(theEnd);
// copy the key because the next statement will destroy memory
@@ -204,8 +199,7 @@ struct STextTextureCache : public ITextTextureCache
TTPathObjectAndTexture RenderText(const STextRenderInfo &inText, QT3DSF32 inScaleFactor) override
{
STextRenderInfoAndHash theKey(inText, inScaleFactor);
- TTextureInfoHash::iterator theFind(
- m_TextureCache.find(theKey));
+ TTextureInfoHash::iterator theFind(m_TextureCache.find(theKey));
STextCacheNode *retval = NULL;
if (theFind != m_TextureCache.end()) {
retval = theFind->second;
@@ -220,23 +214,11 @@ struct STextTextureCache : public ITextTextureCache
NVScopedRefCounted<NVRenderPathFontItem> nextPathFontItemObject;
NVScopedRefCounted<NVRenderPathFontSpecification> nextPathFontObject;
- // HW acceleration for fonts not supported
- //if (m_CanUsePathRendering && inText.m_EnableAcceleratedFont) {
- // nextPathFontItemObject = m_RenderContext->CreatePathFontItem();
- // nextPathFontObject = m_RenderContext->CreatePathFontSpecification(inText.m_Font);
- //}
STextRenderInfo theTextInfo(inText);
theTextInfo.m_FontSize *= inScaleFactor;
STextTextureDetails theDetails;
-
-
- // HW acceleration for fonts not supported
- //if (!m_CanUsePathRendering || !inText.m_EnableAcceleratedFont)
- theDetails = m_TextRenderer->RenderText(theTextInfo, *nextTexture.mPtr);
- //else
- // theDetails = m_TextRenderer->RenderText(theTextInfo, *nextPathFontItemObject.mPtr,
- // *nextPathFontObject.mPtr);
+ theDetails = m_TextRenderer->RenderText(theTextInfo, *nextTexture.mPtr);
if (fabs(inScaleFactor - 1.0f) > .001f) {
TTPathObjectAndTexture theCanonicalDetails = RenderText(inText, 1.0f);
diff --git a/src/runtimerender/Qt3DSRenderTextTypes.h b/src/runtimerender/Qt3DSRenderTextTypes.h
index bbaaa38..f663e50 100644
--- a/src/runtimerender/Qt3DSRenderTextTypes.h
+++ b/src/runtimerender/Qt3DSRenderTextTypes.h
@@ -182,8 +182,6 @@ namespace render {
QT3DSF32 m_ScaleX; // Pixel scale in X
QT3DSF32 m_ScaleY; // Pixel scale in Y
- bool m_EnableAcceleratedFont; // use NV path rendering
-
STextRenderInfo();
~STextRenderInfo();
};
diff --git a/src/runtimerender/Qt3DSRenderUIPSharedTranslation.h b/src/runtimerender/Qt3DSRenderUIPSharedTranslation.h
index 11299c9..e7c9c28 100644
--- a/src/runtimerender/Qt3DSRenderUIPSharedTranslation.h
+++ b/src/runtimerender/Qt3DSRenderUIPSharedTranslation.h
@@ -493,7 +493,6 @@ namespace render {
HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Text, Elide, TextDirty) \
HANDLE_QT3DS_RENDER_COLOR_VEC3_PROPERTY(Text, TextColor, Dirty) \
HANDLE_QT3DS_RENDER_COLOR_PROPERTY(Text, TextColor, Dirty) \
- HANDLE_QT3DS_RENDER_PROPERTY(Text, EnableAcceleratedFont, Dirty)
#define ITERATE_QT3DS_RENDER_PATH_PROPERTIES \
HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Path, PathType, Dirty) \
diff --git a/src/runtimerender/graphobjects/Qt3DSRenderText.cpp b/src/runtimerender/graphobjects/Qt3DSRenderText.cpp
index 40a20c4..68e453b 100644
--- a/src/runtimerender/graphobjects/Qt3DSRenderText.cpp
+++ b/src/runtimerender/graphobjects/Qt3DSRenderText.cpp
@@ -46,7 +46,6 @@ STextRenderInfo::STextRenderInfo()
, m_Elide(TextElide::ElideNone)
, m_ScaleX(0)
, m_ScaleY(0)
- , m_EnableAcceleratedFont(false)
{
}