aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2011-08-31 17:40:42 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-02 11:23:02 +0200
commit3e18093886c567d0e83bac87185590bbc5eb9246 (patch)
tree8ebd821af5a128350a38414b93b4ac3b0227b2af
parente824620e9306d665b81cb12e167f50fb1090fddc (diff)
Exported QSGShaderEffectMesh.
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>
-rw-r--r--src/declarative/items/qsgitemsmodule.cpp4
-rw-r--r--src/declarative/items/qsgshadereffect.cpp72
-rw-r--r--src/declarative/items/qsgshadereffect_p.h2
-rw-r--r--src/declarative/items/qsgshadereffectmesh.cpp42
-rw-r--r--src/declarative/items/qsgshadereffectmesh_p.h2
5 files changed, 64 insertions, 58 deletions
diff --git a/src/declarative/items/qsgitemsmodule.cpp b/src/declarative/items/qsgitemsmodule.cpp
index 9359906f25..bca0437eb5 100644
--- a/src/declarative/items/qsgitemsmodule.cpp
+++ b/src/declarative/items/qsgitemsmodule.cpp
@@ -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"));
diff --git a/src/declarative/items/qsgshadereffect.cpp b/src/declarative/items/qsgshadereffect.cpp
index c5ea64dcd2..015d724c1e 100644
--- a/src/declarative/items/qsgshadereffect.cpp
+++ b/src/declarative/items/qsgshadereffect.cpp
@@ -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) {
diff --git a/src/declarative/items/qsgshadereffect_p.h b/src/declarative/items/qsgshadereffect_p.h
index 0cced9a229..9fe9f13251 100644
--- a/src/declarative/items/qsgshadereffect_p.h
+++ b/src/declarative/items/qsgshadereffect_p.h
@@ -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;
diff --git a/src/declarative/items/qsgshadereffectmesh.cpp b/src/declarative/items/qsgshadereffectmesh.cpp
index 6d3d17e4ff..53fd917e06 100644
--- a/src/declarative/items/qsgshadereffectmesh.cpp
+++ b/src/declarative/items/qsgshadereffectmesh.cpp
@@ -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)
diff --git a/src/declarative/items/qsgshadereffectmesh_p.h b/src/declarative/items/qsgshadereffectmesh_p.h
index 463c3d9073..eb485cf7d4 100644
--- a/src/declarative/items/qsgshadereffectmesh_p.h
+++ b/src/declarative/items/qsgshadereffectmesh_p.h
@@ -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: