summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-12-08 13:21:22 +0000
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-10 16:31:19 +0000
commit1c9d92ecbb5d132313905c68914384674099ec29 (patch)
tree0312861cce3110e6a4238be9d0444a13cad953af /src
parent0de007ab0e9c23bfeb9eba26798df05a06439821 (diff)
Work around QML -> C++ float to int conversion
QML converts values of reals that have zero fractional parts e.g. 2.0 to integers when passing them to C++. This can result in Qt 3D and the Uniform class passing these to uniform floats in GLSL by reinterpret_casting the integer to a float which results in a garbage value in the shader which in turn leads to very difficult to debug shader issues. This commit handles this particular case (in a hacky way) for the Qt 5.8.0 release. We need to find a more fully featured solution for converting Uniform's to the correct introspected GLSL types. This will require being in position of the introspected shader interface when building the RenderViews. This is too large of a change to do in time for the 5.8.0 release. Hence this work around solution for now. Task-number: QTBUG-57510 Change-Id: I6631879fff8259a32960e461bad4c692ca630220 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/render/backend/uniform.cpp1
-rw-r--r--src/render/backend/uniform_p.h4
-rw-r--r--src/render/graphicshelpers/graphicscontext.cpp9
3 files changed, 13 insertions, 1 deletions
diff --git a/src/render/backend/uniform.cpp b/src/render/backend/uniform.cpp
index 0369f3f5e..821dd6992 100644
--- a/src/render/backend/uniform.cpp
+++ b/src/render/backend/uniform.cpp
@@ -121,6 +121,7 @@ UniformValue UniformValue::fromVariant(const QVariant &variant)
case QMetaType::Char:
case QMetaType::UChar:
v.data<int>()[0] = variant.toInt();
+ v.m_storedType = Int;
break;
case QMetaType::Float:
case QMetaType::Double: // Convert double to floats
diff --git a/src/render/backend/uniform_p.h b/src/render/backend/uniform_p.h
index 56a50aea2..6b5ae4172 100644
--- a/src/render/backend/uniform_p.h
+++ b/src/render/backend/uniform_p.h
@@ -169,6 +169,7 @@ public:
}
ValueType valueType() const { return m_valueType; }
+ UniformType storedType() const { return m_storedType; }
static UniformValue fromVariant(const QVariant &variant);
@@ -199,6 +200,9 @@ private:
QVarLengthArray<float, 4> m_data;
ValueType m_valueType = ScalarValue;
+
+ // TODO: Replace this hack see QTBUG-57510
+ UniformType m_storedType = Unknown;
};
} // namespace Render
diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp
index 8c0803a79..9ec544b11 100644
--- a/src/render/graphicshelpers/graphicscontext.cpp
+++ b/src/render/graphicshelpers/graphicscontext.cpp
@@ -1205,7 +1205,14 @@ void GraphicsContext::applyUniform(const ShaderUniform &description, const Unifo
switch (type) {
case UniformType::Float:
- applyUniformHelper<UniformType::Float>(description.m_location, description.m_size, v);
+ // See QTBUG-57510 and uniform_p.h
+ if (v.storedType() == Int) {
+ float value = float(*v.constData<int>());
+ UniformValue floatV(value);
+ applyUniformHelper<UniformType::Float>(description.m_location, description.m_size, floatV);
+ } else {
+ applyUniformHelper<UniformType::Float>(description.m_location, description.m_size, v);
+ }
break;
case UniformType::Vec2:
applyUniformHelper<UniformType::Vec2>(description.m_location, description.m_size, v);