Expose QMatrix4x4 properties as mat4 uniforms in shaders
authorChris Adams <chris.adams@jollamobile.com>
Mon, 19 Nov 2012 08:36:09 +0000 (18:36 +1000)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 22 Nov 2012 06:54:00 +0000 (07:54 +0100)
Previously, QMatrix4x4 properties were not exposed as uniforms in
shaders.  This commit adds conversion code for matrix 4x4 properties
so that they are automatically converted to mat4 uniforms.

Task-number: QTBUG-27952
Change-Id: I9b1de39fbbcb02743cf8c4e09b4d83c44f1dd438
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
src/quick/items/qquickshadereffectnode.cpp
tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp

index b810455..7d7955c 100644 (file)
@@ -193,6 +193,9 @@ void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMateri
                 case QMetaType::QVector4D:
                     program()->setUniformValue(loc, qvariant_cast<QVector4D>(d.value));
                     break;
+                case QMetaType::QMatrix4x4:
+                    program()->setUniformValue(loc, qvariant_cast<QMatrix4x4>(d.value));
+                    break;
                 default:
                     break;
                 }
index 909af20..f45f3dd 100644 (file)
@@ -56,8 +56,10 @@ class TestShaderEffect : public QQuickShaderEffect
     Q_PROPERTY(QVariant _0aA9zZ READ dummyRead NOTIFY dummyChanged)
     Q_PROPERTY(QVariant x86 READ dummyRead NOTIFY dummyChanged)
     Q_PROPERTY(QVariant X READ dummyRead NOTIFY dummyChanged)
+    Q_PROPERTY(QMatrix4x4 mat4x4 READ mat4x4Read NOTIFY dummyChanged)
 
 public:
+    QMatrix4x4 mat4x4Read() const { return QMatrix4x4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); }
     QVariant dummyRead() const { return QVariant(); }
     bool isConnected(const QMetaMethod &signal) const { return m_signals.contains(signal); }
 
@@ -248,6 +250,11 @@ void tst_qquickshadereffect::lookThroughShaderCode_data()
             << QByteArray("uniform lowp float X;")
             << QByteArray(" ")
             << int(PropertyPresent);
+
+    QTest::newRow("property name #4")
+            << QByteArray("uniform highp mat4 mat4x4;")
+            << QByteArray(" ")
+            << int(PropertyPresent);
 }
 
 void tst_qquickshadereffect::lookThroughShaderCode()