Exported QSGShaderEffectMesh.
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>
Wed, 31 Aug 2011 15:40:42 +0000 (17:40 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 2 Sep 2011 09:23:02 +0000 (11:23 +0200)
Reintroduced the possibility to set the ShaderEffect::mesh
property to any object deriving from QSGShaderEffectMesh.

Change-Id: Idf91b2289d4e7b8fd12993a4a2bc1647dfba0ae0
Reviewed-on: http://codereview.qt.nokia.com/4003
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>

src/declarative/items/qsgitemsmodule.cpp
src/declarative/items/qsgshadereffect.cpp
src/declarative/items/qsgshadereffect_p.h
src/declarative/items/qsgshadereffectmesh.cpp
src/declarative/items/qsgshadereffectmesh_p.h

index 9359906..bca0437 100644 (file)
@@ -174,8 +174,8 @@ static void qt_sgitems_defineModule(const char *uri, int major, int minor)
     qmlRegisterType<QSGShaderEffectItem>("QtQuick", 2, 0, "ShaderEffectItem"); // TODO: Remove after grace period.
     qmlRegisterType<QSGShaderEffect>("QtQuick", 2, 0, "ShaderEffect");
     qmlRegisterType<QSGShaderEffectSource>("QtQuick", 2, 0, "ShaderEffectSource");
-    qmlRegisterUncreatableType<QSGShaderEffectMesh>("QtQuick", 2, 0, "ShaderEffectMesh", QSGShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh.")); // TODO: Remove after grace period.
-    qmlRegisterType<QSGGridMesh>("QtQuick", 2, 0, "GridMesh"); // TODO: Remove after grace period.
+    qmlRegisterUncreatableType<QSGShaderEffectMesh>("QtQuick", 2, 0, "ShaderEffectMesh", QSGShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh."));
+    qmlRegisterType<QSGGridMesh>("QtQuick", 2, 0, "GridMesh");
 
     qmlRegisterUncreatableType<QSGPaintedItem>("QtQuick", 2, 0, "PaintedItem", QSGPaintedItem::tr("Cannot create instance of abstract class PaintedItem"));
 
index c5ea64d..015d724 100644 (file)
@@ -188,7 +188,7 @@ QSGShaderEffectItem::QSGShaderEffectItem(QSGItem *parent)
 QSGShaderEffect::QSGShaderEffect(QSGItem *parent)
     : QSGItem(parent)
     , m_meshResolution(1, 1)
-    , m_deprecatedMesh(0)
+    , m_mesh(0)
     , m_cullMode(NoCulling)
     , m_blending(true)
     , m_dirtyData(true)
@@ -272,63 +272,34 @@ void QSGShaderEffect::setBlending(bool enable)
 }
 
 /*!
-    \qmlproperty size QtQuick2::ShaderEffect::mesh
+    \qmlproperty variant QtQuick2::ShaderEffect::mesh
 
-    This property holds the mesh resolution. The default resolution is 1x1
-    which is the minimum and corresponds to a mesh with four vertices.
-    For non-linear vertex transformations, you probably want to set the
-    resolution higher.
+    This property defines the mesh used to draw the ShaderEffect. It can hold
+    any mesh object deriving from \l QSGShaderEffectMesh, such as \l GridMesh.
+    If a size value is assigned to this property, the ShaderEffect implicitly
+    uses a \l GridMesh with the value as
+    \l{GridMesh::resolution}{mesh resolution}. By default, this property is
+    the size 1x1.
 
-    \row
-    \o \image declarative-gridmesh.png
-    \o \qml
-        import QtQuick 2.0
-
-        ShaderEffect {
-            width: 200
-            height: 200
-            mesh: Qt.size(20, 20)
-            property variant source: Image {
-                source: "qt-logo.png"
-                sourceSize { width: 200; height: 200 }
-                smooth: true
-            }
-            vertexShader: "
-                uniform highp mat4 qt_Matrix;
-                attribute highp vec4 qt_Vertex;
-                attribute highp vec2 qt_MultiTexCoord0;
-                varying highp vec2 qt_TexCoord0;
-                uniform highp float width;
-                void main() {
-                    highp vec4 pos = qt_Vertex;
-                    highp float d = .5 * smoothstep(0., 1., qt_MultiTexCoord0.y);
-                    pos.x = width * mix(d, 1.0 - d, qt_MultiTexCoord0.x);
-                    gl_Position = qt_Matrix * pos;
-                    qt_TexCoord0 = qt_MultiTexCoord0;
-                }"
-        }
-        \endqml
-    \endrow
+    \sa GridMesh
 */
 
 QVariant QSGShaderEffect::mesh() const
 {
-    return m_deprecatedMesh ? qVariantFromValue(static_cast<QObject *>(m_deprecatedMesh))
-                            : qVariantFromValue(m_meshResolution);
+    return m_mesh ? qVariantFromValue(static_cast<QObject *>(m_mesh))
+                  : qVariantFromValue(m_meshResolution);
 }
 
 void QSGShaderEffect::setMesh(const QVariant &mesh)
 {
-    // TODO: Replace QVariant with QSize after grace period.
     QSGShaderEffectMesh *newMesh = qobject_cast<QSGShaderEffectMesh *>(qVariantValue<QObject *>(mesh));
-    if (newMesh && newMesh == m_deprecatedMesh)
+    if (newMesh && newMesh == m_mesh)
         return;
-    if (m_deprecatedMesh)
-        disconnect(m_deprecatedMesh, SIGNAL(geometryChanged()), this, 0);
-    m_deprecatedMesh = newMesh;
-    if (m_deprecatedMesh) {
-        qWarning("ShaderEffect: Setting the mesh to something other than a size is deprecated.");
-        connect(m_deprecatedMesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
+    if (m_mesh)
+        disconnect(m_mesh, SIGNAL(geometryChanged()), this, 0);
+    m_mesh = newMesh;
+    if (m_mesh) {
+        connect(m_mesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
     } else {
         if (qVariantCanConvert<QSize>(mesh)) {
             m_meshResolution = mesh.toSize();
@@ -344,7 +315,7 @@ void QSGShaderEffect::setMesh(const QVariant &mesh)
                 }
             }
             if (!ok)
-                qWarning("ShaderEffect: mesh resolution must be a size.");
+                qWarning("ShaderEffect: mesh property must be size or object deriving from QSGShaderEffectMesh.");
         }
         m_defaultMesh.setResolution(m_meshResolution);
     }
@@ -505,10 +476,9 @@ void QSGShaderEffect::updateProperties()
     lookThroughShaderCode(vertexCode);
     lookThroughShaderCode(fragmentCode);
 
-    // TODO: Remove !m_deprecatedMesh check after grace period.
-    if (!m_deprecatedMesh && !m_source.attributeNames.contains(qt_position_attribute_name))
+    if (!m_mesh && !m_source.attributeNames.contains(qt_position_attribute_name))
         qWarning("QSGShaderEffect: Missing reference to \'%s\'.", qt_position_attribute_name);
-    if (!m_deprecatedMesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name))
+    if (!m_mesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name))
         qWarning("QSGShaderEffect: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
     if (!m_source.respectsMatrix)
         qWarning("QSGShaderEffect: Missing reference to \'qt_Matrix\'.");
@@ -594,7 +564,7 @@ QSGNode *QSGShaderEffect::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
         node->setFlag(QSGNode::OwnsGeometry, false);
         QSGGeometry *geometry = node->geometry();
         QRectF rect(0, 0, width(), height());
-        QSGShaderEffectMesh *mesh = m_deprecatedMesh ? m_deprecatedMesh : &m_defaultMesh;
+        QSGShaderEffectMesh *mesh = m_mesh ? m_mesh : &m_defaultMesh;
 
         geometry = mesh->updateGeometry(geometry, m_source.attributeNames, rect);
         if (!geometry) {
index 0cced9a..9fe9f13 100644 (file)
@@ -131,7 +131,7 @@ private:
 
     QSGShaderEffectProgram m_source;
     QSize m_meshResolution;
-    QSGShaderEffectMesh *m_deprecatedMesh; // TODO: Remove after grace period.
+    QSGShaderEffectMesh *m_mesh;
     QSGGridMesh m_defaultMesh;
     CullMode m_cullMode;
 
index 6d3d17e..53fd917 100644 (file)
@@ -51,8 +51,9 @@ QSGShaderEffectMesh::QSGShaderEffectMesh(QObject *parent)
 }
 
 /*!
-    \class QSGGridMesh
-    \since 5.0
+    \qmlclass GridMesh QSGGridMesh
+    \inqmlmodule QtQuick 2
+    \ingroup qml-utility-elements
     \brief GridMesh defines a mesh with vertices arranged in a grid.
 
     GridMesh defines a rectangular mesh consisting of vertices arranged in an
@@ -152,12 +153,47 @@ QSGGeometry *QSGGridMesh::updateGeometry(QSGGeometry *geometry, const QVector<QB
 }
 
 /*!
-    \property QSGGridMesh::resolution
+    \qmlproperty size QtQuick2::GridMesh::resolution
 
     This property holds the grid resolution. The resolution's width and height
     specify the number of cells or spacings between vertices horizontally and
     vertically respectively. The minimum and default is 1x1, which corresponds
     to four vertices in total, one in each corner.
+    For non-linear vertex transformations, you probably want to set the
+    resolution higher.
+
+    \row
+    \o \image declarative-gridmesh.png
+    \o \qml
+        import QtQuick 2.0
+
+        ShaderEffect {
+            width: 200
+            height: 200
+            mesh: GridMesh {
+                resolution: Qt.size(20, 20)
+            }
+            property variant source: Image {
+                source: "qt-logo.png"
+                sourceSize { width: 200; height: 200 }
+                smooth: true
+            }
+            vertexShader: "
+                uniform highp mat4 qt_Matrix;
+                attribute highp vec4 qt_Vertex;
+                attribute highp vec2 qt_MultiTexCoord0;
+                varying highp vec2 qt_TexCoord0;
+                uniform highp float width;
+                void main() {
+                    highp vec4 pos = qt_Vertex;
+                    highp float d = .5 * smoothstep(0., 1., qt_MultiTexCoord0.y);
+                    pos.x = width * mix(d, 1.0 - d, qt_MultiTexCoord0.x);
+                    gl_Position = qt_Matrix * pos;
+                    qt_TexCoord0 = qt_MultiTexCoord0;
+                }"
+        }
+        \endqml
+    \endrow
 */
 
 void QSGGridMesh::setResolution(const QSize &res)
index 463c3d9..eb485cf 100644 (file)
@@ -58,7 +58,7 @@ QT_MODULE(Declarative)
 class QSGGeometry;
 class QRectF;
 
-class QSGShaderEffectMesh : public QObject
+class Q_DECLARATIVE_EXPORT QSGShaderEffectMesh : public QObject
 {
     Q_OBJECT
 public: