summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Niemelä <marko.a.niemela@nokia.com>2011-05-25 14:19:14 +0300
committerMarko Niemelä <marko.a.niemela@nokia.com>2011-05-25 15:25:30 +0300
commitdb20b6c03b6a93ab3e483cd85d5d0a923c3d3430 (patch)
treeafbfe4daa2d8f2f6a1647f1573386a84c2b1b222
parent04cde562a0be446234e33725c999bdb61fab3ff2 (diff)
downloadqt4-tools-db20b6c03b6a93ab3e483cd85d5d0a923c3d3430.tar.gz
Backported QML ShaderEffectItem from QML2.0 into Qt Quick 1.1
This issue is about backporting Scenegraph's ShaderEffectItem and ShaderEffectSource elements into Qt Quick 1.1 as a Qt labs plugin. Purpose of these elements is to provide an interface for utilizing OpenGL shaders in QML applications. Task-number: QTBUG-18346 Reviewed-by: Kim Gronholm
-rw-r--r--src/imports/imports.pro1
-rwxr-xr-xsrc/imports/shaders/glfunctions.h75
-rw-r--r--src/imports/shaders/qmldir2
-rw-r--r--src/imports/shaders/qmlshadersplugin_plugin.cpp55
-rw-r--r--src/imports/shaders/qmlshadersplugin_plugin.h56
-rw-r--r--src/imports/shaders/scenegraph/qsggeometry.cpp310
-rw-r--r--src/imports/shaders/scenegraph/qsggeometry.h234
-rw-r--r--src/imports/shaders/shadereffect.cpp192
-rw-r--r--src/imports/shaders/shadereffect.h81
-rw-r--r--src/imports/shaders/shadereffectbuffer.cpp52
-rw-r--r--src/imports/shaders/shadereffectbuffer.h62
-rw-r--r--src/imports/shaders/shadereffectitem.cpp915
-rw-r--r--src/imports/shaders/shadereffectitem.h152
-rw-r--r--src/imports/shaders/shadereffectsource.cpp472
-rw-r--r--src/imports/shaders/shadereffectsource.h158
-rw-r--r--src/imports/shaders/shaders.pro38
-rw-r--r--tests/auto/declarative/declarative.pro2
-rw-r--r--tests/auto/declarative/qmlshadersplugin/main.qml80
-rw-r--r--tests/auto/declarative/qmlshadersplugin/qmlshadersplugin.pro18
-rw-r--r--tests/auto/declarative/qmlshadersplugin/tst_qmlshadersplugin.cpp205
-rw-r--r--tests/benchmarks/declarative/declarative.pro2
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml43
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml168
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml41
-rwxr-xr-xtests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml66
-rwxr-xr-xtests/benchmarks/declarative/qmlshadersplugin/TestWater.qml20
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/Water.qml85
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/bg.jpgbin0 -> 10189 bytes
-rwxr-xr-xtests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.pngbin0 -> 46081 bytes
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro23
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/sky.jpgbin0 -> 36734 bytes
-rw-r--r--tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp110
-rw-r--r--tests/manual/declarative/declarative.pro3
-rw-r--r--tests/manual/declarative/qmlshadersplugin/main.cpp67
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestActive.qml83
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBasic.qml57
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlending.qml82
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlendingModes.qml267
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectHierarchy.qml133
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectInsideAnotherEffect.qml119
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFormat.qml89
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFragmentShader.qml91
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestGrab.qml89
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHideOriginal.qml97
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHorizontalWrap.qml93
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageFiltering.qml84
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMargins.qml98
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMarginsWithTextureSize.qml96
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMipmap.qml95
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMargins.qml102
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml101
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestLive.qml104
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestMeshResolution.qml108
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOneSource.qml74
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOpacity.qml98
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestRotation.qml95
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestScale.qml95
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTextureSize.qml85
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwiceOnSameSource.qml92
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwoSources.qml95
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVertexShader.qml109
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVerticalWrap.qml92
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestWrapRepeat.qml92
-rwxr-xr-xtests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/back.svg11
-rwxr-xr-xtests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/green_image_transparent.pngbin0 -> 1153 bytes
-rwxr-xr-xtests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image.pngbin0 -> 219220 bytes
-rwxr-xr-xtests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_opaque.pngbin0 -> 293803 bytes
-rwxr-xr-xtests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_small.pngbin0 -> 40220 bytes
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/main.qml236
-rwxr-xr-xtests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/wallpaper.jpgbin0 -> 337569 bytes
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.cpp127
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.h28
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.pri152
-rw-r--r--tests/manual/declarative/qmlshadersplugin/qmlshadersplugin.pro29
74 files changed, 7285 insertions, 1 deletions
diff --git a/src/imports/imports.pro b/src/imports/imports.pro
index 5e50b08da8..c1298e214a 100644
--- a/src/imports/imports.pro
+++ b/src/imports/imports.pro
@@ -1,4 +1,5 @@
TEMPLATE = subdirs
SUBDIRS += folderlistmodel particles gestures
+contains(QT_CONFIG, opengl): SUBDIRS += shaders
diff --git a/src/imports/shaders/glfunctions.h b/src/imports/shaders/glfunctions.h
new file mode 100755
index 0000000000..03b88d1cbc
--- /dev/null
+++ b/src/imports/shaders/glfunctions.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GLFUNCTIONS_H
+#define GLFUNCTIONS_H
+
+#ifndef QT_OPENGL_ES
+
+#ifndef Q_WS_MAC
+# ifndef QGLF_APIENTRYP
+# ifdef QGLF_APIENTRY
+# define QGLF_APIENTRYP QGLF_APIENTRY *
+# else
+# define QGLF_APIENTRY
+# define QGLF_APIENTRYP *
+# endif
+# endif
+#else
+# define QGLF_APIENTRY
+# define QGLF_APIENTRYP *
+#endif
+
+#define GL_TEXTURE0 0x84C0
+#define GL_CLAMP_TO_EDGE 0x812F
+#define GL_BGRA 0x80E1
+
+typedef void (QGLF_APIENTRYP type_glActiveTexture)(GLenum texture);
+typedef void (QGLF_APIENTRYP type_glGenerateMipmap)(GLenum target);
+typedef void (QGLF_APIENTRYP type_glVertexAttribPointer)(GLuint, GLint, GLenum, GLboolean, GLsizei, const GLvoid *);
+
+#define glActiveTexture ((type_glActiveTexture)QGLContext::currentContext()->getProcAddress(QLatin1String("glActiveTexture")))
+#define glGenerateMipmap ((type_glGenerateMipmap)QGLContext::currentContext()->getProcAddress(QLatin1String("glGenerateMipmap")))
+#define glVertexAttribPointer ((type_glVertexAttribPointer)QGLContext::currentContext()->getProcAddress(QLatin1String("glVertexAttribPointer")))
+
+#endif
+
+#endif // GLFUNCTIONS_H
diff --git a/src/imports/shaders/qmldir b/src/imports/shaders/qmldir
new file mode 100644
index 0000000000..b2a9de2132
--- /dev/null
+++ b/src/imports/shaders/qmldir
@@ -0,0 +1,2 @@
+plugin qmlshadersplugin
+
diff --git a/src/imports/shaders/qmlshadersplugin_plugin.cpp b/src/imports/shaders/qmlshadersplugin_plugin.cpp
new file mode 100644
index 0000000000..c03ef2c8c6
--- /dev/null
+++ b/src/imports/shaders/qmlshadersplugin_plugin.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmlshadersplugin_plugin.h"
+#include "shadereffectitem.h"
+#include "shadereffectsource.h"
+
+#include <QtDeclarative/qdeclarative.h>
+
+void qmlshaderspluginPlugin::registerTypes(const char *uri)
+{
+ qmlRegisterType<ShaderEffectItem>(uri, 1, 0, "ShaderEffectItem");
+ qmlRegisterType<ShaderEffectSource>(uri, 1, 0, "ShaderEffectSource");
+}
+
+Q_EXPORT_PLUGIN2(qmlshadersplugin, qmlshaderspluginPlugin)
+
diff --git a/src/imports/shaders/qmlshadersplugin_plugin.h b/src/imports/shaders/qmlshadersplugin_plugin.h
new file mode 100644
index 0000000000..2614a448c4
--- /dev/null
+++ b/src/imports/shaders/qmlshadersplugin_plugin.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLSHADERSPLUGIN_PLUGIN_H
+#define QMLSHADERSPLUGIN_PLUGIN_H
+
+#include <QtDeclarative/QDeclarativeExtensionPlugin>
+
+class qmlshaderspluginPlugin : public QDeclarativeExtensionPlugin
+{
+ Q_OBJECT
+
+public:
+ void registerTypes(const char *uri);
+};
+
+#endif // QMLSHADERSPLUGIN_PLUGIN_H
+
diff --git a/src/imports/shaders/scenegraph/qsggeometry.cpp b/src/imports/shaders/scenegraph/qsggeometry.cpp
new file mode 100644
index 0000000000..14ee4db795
--- /dev/null
+++ b/src/imports/shaders/scenegraph/qsggeometry.cpp
@@ -0,0 +1,310 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt scene graph research project.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsggeometry.h"
+
+QT_BEGIN_NAMESPACE
+
+
+/*!
+ Convenience function which returns attributes to be used for 2D solid
+ color drawing.
+ */
+
+const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
+{
+ static Attribute data[] = {
+ { 0, 2, GL_FLOAT }
+ };
+ static AttributeSet attrs = { 1, sizeof(float) * 2, data };
+ return attrs;
+}
+
+/*!
+ Convenience function which returns attributes to be used for textured 2D drawing.
+ */
+
+const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D()
+{
+ static Attribute data[] = {
+ { 0, 2, GL_FLOAT },
+ { 1, 2, GL_FLOAT }
+ };
+ static AttributeSet attrs = { 2, sizeof(float) * 4, data };
+ return attrs;
+}
+
+/*!
+ Convenience function which returns attributes to be used for per vertex colored 2D drawing.
+ */
+
+const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D()
+{
+ static Attribute data[] = {
+ { 0, 2, GL_FLOAT },
+ { 1, 4, GL_UNSIGNED_BYTE }
+ };
+ static AttributeSet attrs = { 2, 2 * sizeof(float) + 4 * sizeof(char), data };
+ return attrs;
+}
+
+
+/*!
+ \class QSGGeometry
+ \brief The QSGGeometry class provides low-level storage for graphics primitives
+ in the QML Scene Graph.
+
+ The QSGGeometry class provides a few convenience attributes and attribute accessors
+ by default. The defaultAttributes_Point2D() function returns attributes to be used
+ in normal solid color rectangles, while the defaultAttributes_TexturedPoint2D function
+ returns attributes to be used for the common pixmap usecase.
+ */
+
+
+/*!
+ Constructs a geometry object based on \a attributes.
+
+ The object allocate space for \a vertexCount vertices based on the accumulated
+ size in \a attributes and for \a indexCount.
+
+ Geometry objects are constructed with GL_TRIANGLE_STRIP as default drawing mode.
+
+ The attribute structure is assumed to be POD and the geometry object
+ assumes this will not go away. There is no memory management involved.
+ */
+
+QSGGeometry::QSGGeometry(const QSGGeometry::AttributeSet &attributes,
+ int vertexCount,
+ int indexCount,
+ int indexType)
+ : m_drawing_mode(GL_TRIANGLE_STRIP)
+ , m_vertex_count(0)
+ , m_index_count(0)
+ , m_index_type(indexType)
+ , m_attributes(attributes)
+ , m_data(0)
+ , m_index_data_offset(-1)
+ , m_owns_data(false)
+{
+ Q_ASSERT(m_attributes.count > 0);
+ Q_ASSERT(m_attributes.stride > 0);
+
+ // Because allocate reads m_vertex_count, m_index_count and m_owns_data, these
+ // need to be set before calling allocate...
+ allocate(vertexCount, indexCount);
+}
+
+QSGGeometry::~QSGGeometry()
+{
+ if (m_owns_data)
+ qFree(m_data);
+}
+
+/*!
+ \fn int QSGGeometry::vertexCount() const
+
+ Returns the number of vertices in this geometry object.
+ */
+
+/*!
+ \fn int QSGGeometry::indexCount() const
+
+ Returns the number of indices in this geometry object.
+ */
+
+
+
+/*!
+ \fn void *QSGGeometry::vertexData()
+
+ Returns a pointer to the raw vertex data of this geometry object.
+
+ \sa vertexDataAsPoint2D(), vertexDataAsTexturedPoint2D
+ */
+
+/*!
+ \fn const void *QSGGeometry::vertexData() const
+
+ Returns a pointer to the raw vertex data of this geometry object.
+
+ \sa vertexDataAsPoint2D(), vertexDataAsTexturedPoint2D
+ */
+
+/*!
+ Returns a pointer to the raw index data of this geometry object.
+
+ \sa indexDataAsUShort(), indexDataAsUInt()
+ */
+void *QSGGeometry::indexData()
+{
+ return m_index_data_offset < 0
+ ? 0
+ : ((char *) m_data + m_index_data_offset);
+}
+
+/*!
+ Returns a pointer to the raw index data of this geometry object.
+
+ \sa indexDataAsUShort(), indexDataAsUInt()
+ */
+const void *QSGGeometry::indexData() const
+{
+ return m_index_data_offset < 0
+ ? 0
+ : ((char *) m_data + m_index_data_offset);
+}
+
+/*!
+ Sets the drawing mode to be used for this geometry.
+
+ The default value is GL_TRIANGLE_STRIP.
+ */
+void QSGGeometry::setDrawingMode(GLenum mode)
+{
+ m_drawing_mode = mode;
+}
+
+/*!
+ \fn int QSGGeometry::drawingMode() const
+
+ Returns the drawing mode of this geometry.
+
+ The default value is GL_TRIANGLE_STRIP.
+ */
+
+/*!
+ \fn int QSGGeometry::indexType() const
+
+ Returns the primitive type used for indices in this
+ geometry object.
+ */
+
+
+/*!
+ Resizes the vertex and index data of this geometry object to fit \a vertexCount
+ vertices and \a indexCount indices.
+
+ Vertex and index data will be invalidated after this call and the caller must
+ */
+void QSGGeometry::allocate(int vertexCount, int indexCount)
+{
+ if (vertexCount == m_vertex_count && indexCount == m_index_count)
+ return;
+
+ m_vertex_count = vertexCount;
+ m_index_count = indexCount;
+
+ bool canUsePrealloc = m_index_count <= 0;
+ int vertexByteSize = m_attributes.stride * m_vertex_count;
+
+ if (m_owns_data)
+ qFree(m_data);
+
+ if (canUsePrealloc && vertexByteSize <= (int) sizeof(m_prealloc)) {
+ m_data = (void *) &m_prealloc[0];
+ m_index_data_offset = -1;
+ m_owns_data = false;
+ } else {
+ Q_ASSERT(m_index_type == GL_UNSIGNED_INT || m_index_type == GL_UNSIGNED_SHORT);
+ int indexByteSize = indexCount * (m_index_type == GL_UNSIGNED_SHORT ? sizeof(quint16) : sizeof(quint32));
+ m_data = (void *) qMalloc(vertexByteSize + indexByteSize);
+ m_index_data_offset = vertexByteSize;
+ m_owns_data = true;
+ }
+
+}
+
+/*!
+ Updates the geometry \a g with the coordinates in \a rect.
+
+ The function assumes the geometry object contains a single triangle strip
+ of QSGGeometry::Point2D vertices
+ */
+void QSGGeometry::updateRectGeometry(QSGGeometry *g, const QRectF &rect)
+{
+ Point2D *v = g->vertexDataAsPoint2D();
+ v[0].x = rect.left();
+ v[0].y = rect.top();
+
+ v[1].x = rect.right();
+ v[1].y = rect.top();
+
+ v[2].x = rect.left();
+ v[2].y = rect.bottom();
+
+ v[3].x = rect.right();
+ v[3].y = rect.bottom();
+}
+
+/*!
+ Updates the geometry \a g with the coordinates in \a rect and texture
+ coordinates from \a textureRect.
+
+ \a textureRect should be in normalized coordinates.
+
+ \a g is assumed to be a triangle strip of four vertices of type
+ QSGGeometry::TexturedPoint2D.
+ */
+void QSGGeometry::updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &textureRect)
+{
+ TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
+ v[0].x = rect.left();
+ v[0].y = rect.top();
+ v[0].tx = textureRect.left();
+ v[0].ty = textureRect.top();
+
+ v[1].x = rect.right();
+ v[1].y = rect.top();
+ v[1].tx = textureRect.right();
+ v[1].ty = textureRect.top();
+
+ v[2].x = rect.left();
+ v[2].y = rect.bottom();
+ v[2].tx = textureRect.left();
+ v[2].ty = textureRect.bottom();
+
+ v[3].x = rect.right();
+ v[3].y = rect.bottom();
+ v[3].tx = textureRect.right();
+ v[3].ty = textureRect.bottom();
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/shaders/scenegraph/qsggeometry.h b/src/imports/shaders/scenegraph/qsggeometry.h
new file mode 100644
index 0000000000..0055392a49
--- /dev/null
+++ b/src/imports/shaders/scenegraph/qsggeometry.h
@@ -0,0 +1,234 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt scene graph research project.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGGEOMETRY_H
+#define QSGGEOMETRY_H
+
+#include <QtOpenGL/qgl.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QSGGeometry
+{
+public:
+ struct Attribute
+ {
+ int position;
+ int tupleSize;
+ int type;
+ };
+
+ struct AttributeSet {
+ int count;
+ int stride;
+ const Attribute *attributes;
+ };
+
+ struct Point2D { float x, y; };
+ struct TexturedPoint2D { float x, y; float tx, ty; };
+ struct ColoredPoint2D { float x, y; unsigned char r, g, b, a; };
+
+ static const AttributeSet &defaultAttributes_Point2D();
+ static const AttributeSet &defaultAttributes_TexturedPoint2D();
+ static const AttributeSet &defaultAttributes_ColoredPoint2D();
+
+ QSGGeometry(const QSGGeometry::AttributeSet &attribs,
+ int vertexCount,
+ int indexCount = 0,
+ int indexType = GL_UNSIGNED_SHORT);
+ ~QSGGeometry();
+
+ void setDrawingMode(GLenum mode);
+ inline GLenum drawingMode() const { return m_drawing_mode; }
+
+ void allocate(int vertexCount, int indexCount = 0);
+
+ int vertexCount() const { return m_vertex_count; }
+
+ void *vertexData() { return m_data; }
+ inline Point2D *vertexDataAsPoint2D();
+ inline TexturedPoint2D *vertexDataAsTexturedPoint2D();
+ inline ColoredPoint2D *vertexDataAsColoredPoint2D();
+
+ inline const void *vertexData() const { return m_data; }
+ inline const Point2D *vertexDataAsPoint2D() const;
+ inline const TexturedPoint2D *vertexDataAsTexturedPoint2D() const;
+ inline const ColoredPoint2D *vertexDataAsColoredPoint2D() const;
+
+ inline int indexType() const { return m_index_type; }
+
+ int indexCount() const { return m_index_count; }
+
+ void *indexData();
+ inline uint *indexDataAsUInt();
+ inline quint16 *indexDataAsUShort();
+
+ const void *indexData() const;
+ inline const uint *indexDataAsUInt() const;
+ inline const quint16 *indexDataAsUShort() const;
+
+ inline int attributeCount() const { return m_attributes.count; }
+ inline const Attribute *attributes() const { return m_attributes.attributes; }
+ inline int stride() const { return m_attributes.stride; }
+
+ static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
+ static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
+
+private:
+ int m_drawing_mode;
+ int m_vertex_count;
+ int m_index_count;
+ int m_index_type;
+ const AttributeSet &m_attributes;
+ void *m_data;
+ int m_index_data_offset;
+
+ void *m_reserved_pointer;
+
+ uint m_owns_data : 1;
+ uint m_reserved_bits : 31;
+
+ float m_prealloc[16];
+};
+
+inline uint *QSGGeometry::indexDataAsUInt()
+{
+ Q_ASSERT(m_index_type == GL_UNSIGNED_INT);
+ return (uint *) indexData();
+}
+
+inline quint16 *QSGGeometry::indexDataAsUShort()
+{
+ Q_ASSERT(m_index_type == GL_UNSIGNED_SHORT);
+ return (quint16 *) indexData();
+}
+
+inline const uint *QSGGeometry::indexDataAsUInt() const
+{
+ Q_ASSERT(m_index_type == GL_UNSIGNED_INT);
+ return (uint *) indexData();
+}
+
+inline const quint16 *QSGGeometry::indexDataAsUShort() const
+{
+ Q_ASSERT(m_index_type == GL_UNSIGNED_SHORT);
+ return (quint16 *) indexData();
+}
+
+inline QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D()
+{
+ Q_ASSERT(m_attributes.count == 1);
+ Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
+ Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[0].type == GL_FLOAT);
+ Q_ASSERT(m_attributes.attributes[0].position == 0);
+ return (Point2D *) m_data;
+}
+
+inline QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D()
+{
+ Q_ASSERT(m_attributes.count == 2);
+ Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
+ Q_ASSERT(m_attributes.attributes[0].position == 0);
+ Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[0].type == GL_FLOAT);
+ Q_ASSERT(m_attributes.attributes[1].position == 1);
+ Q_ASSERT(m_attributes.attributes[1].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[1].type == GL_FLOAT);
+ return (TexturedPoint2D *) m_data;
+}
+
+inline QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D()
+{
+ Q_ASSERT(m_attributes.count == 2);
+ Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
+ Q_ASSERT(m_attributes.attributes[0].position == 0);
+ Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[0].type == GL_FLOAT);
+ Q_ASSERT(m_attributes.attributes[1].position == 1);
+ Q_ASSERT(m_attributes.attributes[1].tupleSize == 4);
+ Q_ASSERT(m_attributes.attributes[1].type == GL_UNSIGNED_BYTE);
+ return (ColoredPoint2D *) m_data;
+}
+
+inline const QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() const
+{
+ Q_ASSERT(m_attributes.count == 1);
+ Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
+ Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[0].type == GL_FLOAT);
+ Q_ASSERT(m_attributes.attributes[0].position == 0);
+ return (const Point2D *) m_data;
+}
+
+inline const QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D() const
+{
+ Q_ASSERT(m_attributes.count == 2);
+ Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
+ Q_ASSERT(m_attributes.attributes[0].position == 0);
+ Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[0].type == GL_FLOAT);
+ Q_ASSERT(m_attributes.attributes[1].position == 1);
+ Q_ASSERT(m_attributes.attributes[1].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[1].type == GL_FLOAT);
+ return (const TexturedPoint2D *) m_data;
+}
+
+inline const QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D() const
+{
+ Q_ASSERT(m_attributes.count == 2);
+ Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
+ Q_ASSERT(m_attributes.attributes[0].position == 0);
+ Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
+ Q_ASSERT(m_attributes.attributes[0].type == GL_FLOAT);
+ Q_ASSERT(m_attributes.attributes[1].position == 1);
+ Q_ASSERT(m_attributes.attributes[1].tupleSize == 4);
+ Q_ASSERT(m_attributes.attributes[1].type == GL_UNSIGNED_BYTE);
+ return (const ColoredPoint2D *) m_data;
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QSGGEOMETRY_H
diff --git a/src/imports/shaders/shadereffect.cpp b/src/imports/shaders/shadereffect.cpp
new file mode 100644
index 0000000000..bbea43c0c7
--- /dev/null
+++ b/src/imports/shaders/shadereffect.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "shadereffect.h"
+#include "shadereffectbuffer.h"
+#include "shadereffectsource.h"
+
+#include <QDeclarativeItem>
+#include <QPainter>
+#include <QtOpenGL>
+
+static QTransform savedWorldTransform;
+
+ShaderEffect::ShaderEffect(QObject *parent)
+ : QGraphicsEffect(parent)
+ , m_changed(true)
+{
+}
+
+ShaderEffect::~ShaderEffect()
+{
+}
+
+void ShaderEffect::prepareBufferedDraw(QPainter *painter)
+{
+ // This workaround needed because QGraphicsEffect seems to always utilize default painters worldtransform
+ // instead of the active painters worldtransform.
+ const ShaderEffectBuffer *effectBuffer = dynamic_cast<ShaderEffectBuffer*> (painter->device());
+ if (effectBuffer) {
+ savedWorldTransform = painter->worldTransform() * savedWorldTransform;
+ painter->setWorldTransform(savedWorldTransform);
+ } else {
+ savedWorldTransform = painter->worldTransform();
+ }
+}
+
+void ShaderEffect::draw (QPainter *painter)
+{
+ const QGLContext *context = QGLContext::currentContext();
+
+ prepareBufferedDraw(painter);
+
+ if (context) {
+ updateRenderTargets();
+ }
+
+ if (!context || m_renderTargets.count() == 0 || !hideOriginal())
+ drawSource(painter);
+}
+
+void ShaderEffect::updateRenderTargets()
+{
+ if (!m_changed)
+ return;
+
+ m_changed = false;
+
+ int count = m_renderTargets.count();
+ for (int i = 0; i < count; i++) {
+ if (m_renderTargets[i]->isLive() || m_renderTargets[i]->isDirtyTexture()) {
+ m_renderTargets[i]->updateBackbuffer();
+ ShaderEffectBuffer* target = m_renderTargets[i]->fbo();
+ if (target && target->isValid() && target->width() > 0 && target->height() > 0) {
+ QPainter p(target);
+ p.setCompositionMode(QPainter::CompositionMode_Clear);
+ p.fillRect(QRect(QPoint(0, 0), target->size()), Qt::transparent);
+ p.setCompositionMode(QPainter::CompositionMode_SourceOver);
+
+ QRectF sourceRect = m_renderTargets[i]->sourceRect();
+ QSize textureSize = m_renderTargets[i]->textureSize();
+
+ qreal yflip = m_renderTargets[i]->isMirrored() ? -1.0 : 1.0; // flip y to match scenegraph, it also flips texturecoordinates
+ qreal xscale = 1.0;
+ qreal yscale = 1.0 * yflip;
+
+ qreal leftMargin = 0.0;
+ qreal rightMargin = 0.0;
+ qreal topMargin = 0.0;
+ qreal bottomMargin = 0.0;
+
+ qreal width = m_renderTargets[i]->sourceItem()->width();
+ qreal height = m_renderTargets[i]->sourceItem()->height();
+
+ if (!sourceRect.isEmpty()) {
+ leftMargin = -sourceRect.left();
+ rightMargin = sourceRect.right() - width;
+ topMargin = -sourceRect.top();
+ bottomMargin = sourceRect.bottom() - height;
+ }
+
+ if ((width + leftMargin + rightMargin) > 0 && (height + topMargin + bottomMargin) > 0) {
+ if (!textureSize.isEmpty()) {
+ qreal textureWidth = textureSize.width();
+ qreal textureHeight = textureSize.height();
+
+ xscale = width / (width + leftMargin + rightMargin);
+ yscale = height / (height + topMargin + bottomMargin);
+
+ p.translate(textureWidth / 2, textureHeight / 2);
+ p.scale(xscale, yscale * yflip);
+ p.translate(-textureWidth / 2, -textureHeight / 2);
+ p.scale(textureWidth / width, textureHeight / height);
+ } else {
+ xscale = width / (width + leftMargin + rightMargin);
+ yscale = height / (height + topMargin + bottomMargin);
+
+ p.translate(width / 2, height / 2);
+ p.scale(xscale, yscale * yflip);
+ p.translate(-width / 2, -height / 2);
+ }
+ }
+
+ drawSource(&p);
+ p.end();
+ m_renderTargets[i]->markSceneGraphDirty();
+ }
+ }
+ }
+}
+
+void ShaderEffect::sourceChanged (ChangeFlags flags)
+{
+ Q_UNUSED(flags);
+ m_changed = true;
+}
+
+void ShaderEffect::addRenderTarget(ShaderEffectSource *target)
+{
+ if (!m_renderTargets.contains(target))
+ m_renderTargets.append(target);
+}
+
+void ShaderEffect::removeRenderTarget(ShaderEffectSource *target)
+{
+ int index = m_renderTargets.indexOf(target);
+ if (index >= 0)
+ m_renderTargets.remove(index);
+ else
+ qWarning() << "ShaderEffect::removeRenderTarget - did not find target.";
+}
+
+bool ShaderEffect::hideOriginal() const
+{
+ if (m_renderTargets.count() == 0)
+ return false;
+
+ // Just like scenegraph version, if there is even one source that says "hide original" we hide it.
+ int count = m_renderTargets.count();
+ for (int i = 0; i < count; i++) {
+ if (m_renderTargets[i]->hideSource())
+ return true;
+ }
+ return false;
+}
diff --git a/src/imports/shaders/shadereffect.h b/src/imports/shaders/shadereffect.h
new file mode 100644
index 0000000000..35a697b136
--- /dev/null
+++ b/src/imports/shaders/shadereffect.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHADEREFFECT_H
+#define SHADEREFFECT_H
+
+#include <QGraphicsEffect>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class ShaderEffectSource;
+
+class ShaderEffect : public QGraphicsEffect
+{
+ Q_OBJECT
+
+public:
+ ShaderEffect(QObject *parent = 0);
+ ~ShaderEffect();
+ void addRenderTarget(ShaderEffectSource *target);
+ void removeRenderTarget(ShaderEffectSource *target);
+
+protected:
+ virtual void draw (QPainter *painter);
+ virtual void sourceChanged (ChangeFlags flags);
+
+private:
+ void prepareBufferedDraw(QPainter *painter);
+ void updateRenderTargets();
+ bool hideOriginal() const;
+
+public:
+ QVector<ShaderEffectSource*> m_renderTargets;
+ bool m_changed : 1;
+};
+
+QT_END_HEADER
+
+QT_END_NAMESPACE
+
+#endif // SHADEREFFECT_H
diff --git a/src/imports/shaders/shadereffectbuffer.cpp b/src/imports/shaders/shadereffectbuffer.cpp
new file mode 100644
index 0000000000..4c76adaae3
--- /dev/null
+++ b/src/imports/shaders/shadereffectbuffer.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "shadereffectbuffer.h"
+
+ShaderEffectBuffer::ShaderEffectBuffer(const QSize & size, const QGLFramebufferObjectFormat & format)
+ : QGLFramebufferObject(size, format)
+{
+}
+
+ShaderEffectBuffer::~ShaderEffectBuffer()
+{
+}
+
diff --git a/src/imports/shaders/shadereffectbuffer.h b/src/imports/shaders/shadereffectbuffer.h
new file mode 100644
index 0000000000..dcab6ec683
--- /dev/null
+++ b/src/imports/shaders/shadereffectbuffer.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHADEREFFECTBUFFER_H
+#define SHADEREFFECTBUFFER_H
+
+#include <QtOpenGL>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class ShaderEffectBuffer : public QGLFramebufferObject
+{
+public:
+ ShaderEffectBuffer(const QSize &size, const QGLFramebufferObjectFormat &format);
+ ~ShaderEffectBuffer();
+};
+
+QT_END_HEADER
+
+QT_END_NAMESPACE
+
+#endif // SHADEREFFECTBUFFER_H
diff --git a/src/imports/shaders/shadereffectitem.cpp b/src/imports/shaders/shadereffectitem.cpp
new file mode 100644
index 0000000000..a32168e9cd
--- /dev/null
+++ b/src/imports/shaders/shadereffectitem.cpp
@@ -0,0 +1,915 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "shadereffectitem.h"
+#include "shadereffect.h"
+#include "glfunctions.h"
+
+#include <QPainter>
+#include <QtOpenGL>
+
+static const char qt_default_vertex_code[] =
+ "uniform highp mat4 qt_ModelViewProjectionMatrix;\n"
+ "attribute highp vec4 qt_Vertex;\n"
+ "attribute highp vec2 qt_MultiTexCoord0;\n"
+ "varying highp vec2 qt_TexCoord0;\n"
+ "void main(void)\n"
+ "{\n"
+ "qt_TexCoord0 = qt_MultiTexCoord0;\n"
+ "gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n"
+ "}\n";
+
+static const char qt_default_fragment_code[] =
+ "varying highp vec2 qt_TexCoord0;\n"
+ "uniform lowp sampler2D source;\n"
+ "void main(void)\n"
+ "{\n"
+ "gl_FragColor = texture2D(source, qt_TexCoord0.st);\n"
+ "}\n";
+
+static const char qt_postion_attribute_name[] = "qt_Vertex";
+static const char qt_texcoord_attribute_name[] = "qt_MultiTexCoord0";
+static const char qt_emptyAttributeName[] = "";
+
+
+/*!
+ \qmlclass ShaderEffectItem ShaderEffectItem
+ \ingroup qmlshadersplugin
+ \brief The ShaderEffectItem object alters the output of given item with OpenGL shaders.
+ \inherits Item
+
+ ShaderEffectItem is available in the \bold{Qt.labs.shaders 1.0} module.
+ \e {Elements in the Qt.labs module are not guaranteed to remain compatible
+ in future versions.}
+
+ This element provides preliminary support for embedding OpenGL shader code into QML,
+ and may be heavily changed or removed in later versions.
+
+ Requirement for the use of shaders is that the application is either using
+ Qt OpenGL graphicssystem or is forced to use OpenGL by setting QGLWidget as the viewport to QDeclarativeView (recommened way).
+
+ ShaderEffectItem internal behaviour is such that during the paint event it first renders its
+ ShaderEffectSource items into a OpenGL framebuffer object which can be used as a texture. If the ShaderEffectSource is defined to be an image,
+ it is directly uploaded as a texture. The texture(s) containing the source pixelcontent are then bound to graphics
+ pipeline texture units. Finally a textured mesh is passed to the vertex- and fragmentshaders which
+ then produce the final output for the ShaderEffectItem. It is possible to alter the mesh structure by defining
+ the amount vertices it contains, but currently it is not possible to import complex 3D-models to be used as the mesh.
+
+ It is possible to define one or more ShaderEffectItems to be a ShaderEffectSource for other ShaderEffectItems, but ShaderEffectItem
+ should never be declared as a child element of its source item(s) because it would cause circular loop in the painting.
+
+ A standard set of vertex attributes are provided for the shaders:
+
+ \list
+ \o qt_Vertex - The primary position of the vertex.
+ \o qt_MultiTexCoord0 - The texture co-ordinate at each vertex for texture unit 0.
+ \endlist
+
+ Additionally following uniforms are available for shaders:
+
+ \list
+ \o qt_Opacity - Effective opacity of the item.
+ \o qt_ModelViewProjectionMatrix - current 4x4 transformation matrix of the item.
+ \endlist
+
+ Furthermore, it is possible to utilize automatic QML propertybinding into vertex- and fragment shader
+ uniforms. Conversions are done according to the table below:
+
+ \table
+ \header
+ \o QML property
+ \o GLSL uniform
+ \row
+ \o property double foo: 1.0
+ \o uniform highp float foo
+ \row
+ \o property real foo: 1.0
+ \o uniform highp float foo
+ \row
+ \o property bool foo: true
+ \o uniform bool foo
+ \row
+ \o property int foo: 1
+ \o uniform int foo
+ \row
+ \o property variant foo: Qt.point(1,1)
+ \o uniform highp vec2 foo
+ \row
+ \o property variant foo: Qt.size(1, 1)
+ \o uniform highp vec2 foo
+ \row
+ \o property variant foo: Qt.rect(1, 1, 2, 2)
+ \o uniform highp vec4 foo
+ \row
+ \o property color foo: "#00000000"
+ \o uniform lowp vec4 foo
+ \row
+ \o property variant foo: Qt.vector3d(1.0, 2.0, 0.0)
+ \o uniform highp vec3 foo
+ \row
+ \o property variant foo: ShaderEffectSource { SourceItem: bar }
+ \o uniform lowp sampler2D foo
+ \endtable
+ \note
+ The uniform precision definitions in the above table are not strict, it is possible to choose the uniform
+ precision based on what is the most suitable for the shader code for that particular uniform.
+
+
+ The below example uses fragment shader to create simple wiggly effect to a text label.
+ Automatic property binding takes care of binding the properties to the uniforms if their
+ names are identical. ShaderEffectSource referring to textLabel is bound to sampler2D uniform inside the fragment
+ shader code.
+
+ \qml
+import QtQuick 1.0
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ width: 300
+ height: 300
+ color: "black"
+
+ Text {
+ id: textLabel
+ text: "Hello World"
+ anchors.centerIn: parent
+ font.pixelSize: 32
+ color: "white"
+
+ }
+
+ ShaderEffectItem {
+ property variant source: ShaderEffectSource { sourceItem: textLabel; hideSource: true }
+ property real wiggleAmount: 0.005
+ anchors.fill: textLabel
+
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform highp float wiggleAmount;
+ void main(void)
+ {
+ highp vec2 wiggledTexCoord = qt_TexCoord0;
+ wiggledTexCoord.s += sin(4.0 * 3.141592653589 * wiggledTexCoord.t) * wiggleAmount;
+ gl_FragColor = texture2D(source, wiggledTexCoord.st);
+ }
+ "
+ }
+}
+ \endqml
+ \image Example1.png
+
+*/
+
+ShaderEffectItem::ShaderEffectItem(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+ , m_meshResolution(1, 1)
+ , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
+ , m_blending(true)
+ , m_program_dirty(true)
+ , m_active(true)
+ , m_respectsMatrix(false)
+ , m_respectsOpacity(false)
+ , m_checkedViewportUpdateMode(false)
+ , m_checkedOpenGL(false)
+ , m_checkedShaderPrograms(false)
+ , m_hasShaderPrograms(false)
+ , m_mirrored(false)
+ , m_defaultVertexShader(true)
+{
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+ connect(this, SIGNAL(visibleChanged()), this, SLOT(handleVisibilityChange()));
+ m_active = isVisible();
+}
+
+ShaderEffectItem::~ShaderEffectItem()
+{
+ reset();
+}
+
+
+/*!
+ \qmlproperty string ShaderEffectItem::fragmentShader
+ This property holds the OpenGL fragment shader code.
+
+ The default fragment shader is following:
+
+ \code
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ void main(void)
+ {
+ gl_FragColor = texture2D(source, qt_TexCoord0.st);
+ }
+ \endcode
+
+*/
+
+/*!
+ \property ShaderEffectItem::fragmentShader
+ \brief the OpenGL fragment shader code.
+*/
+
+void ShaderEffectItem::setFragmentShader(const QString &code)
+{
+ if (m_fragment_code.constData() == code.constData())
+ return;
+
+ m_fragment_code = code;
+ if (isComponentComplete()) {
+ reset();
+ updateProperties();
+ }
+ emit fragmentShaderChanged();
+}
+
+/*!
+ \qmlproperty string ShaderEffectItem::vertexShader
+ This property holds the OpenGL vertex shader code.
+
+ The default vertex shader is following:
+
+ \code
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ attribute highp vec4 qt_Vertex;
+ attribute highp vec2 qt_MultiTexCoord0;
+ varying highp vec2 qt_TexCoord0;
+ void main(void)
+ {
+ qt_TexCoord0 = qt_MultiTexCoord0;
+ gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
+ }
+ \endcode
+
+*/
+
+/*!
+ \property ShaderEffectItem::vertexShader
+ \brief the OpenGL vertex shader code.
+*/
+
+void ShaderEffectItem::setVertexShader(const QString &code)
+{
+ if (m_vertex_code.constData() == code.constData())
+ return;
+
+ m_vertex_code = code;
+ m_defaultVertexShader = false;
+ if (isComponentComplete()) {
+ reset();
+ updateProperties();
+ }
+ emit vertexShaderChanged();
+}
+
+/*!
+ \qmlproperty bool ShaderEffectItem::blending
+ This property defines wheter item is drawn using blending.
+
+ If true, the RGBA pixel output from the fragment shader is blended with
+ the pixel RGBA-values already in the framebuffer.
+
+ If false, fragment shader output is written to framebuffer as such.
+
+ Usually drawing without blending is slightly faster, thus disabling blending
+ might be a good choice when item is used as a background element.
+
+ \note
+ By default the pixel data in textures is stored in 32-bit premultiplied alpha format.
+ This should be taken into account when blending or reading the pixel values
+ in the fragment shader code.
+
+ The default value is true.
+*/
+
+/*!
+ \property ShaderEffectItem::blending
+ \brief the drawing is done using blending.
+*/
+
+void ShaderEffectItem::setBlending(bool enable)
+{
+ if (m_blending == enable)
+ return;
+
+ m_blending = enable;
+ m_changed = true;
+ emit blendingChanged();
+}
+
+
+/*!
+ \qmlproperty QSize ShaderEffectItem::meshResolution
+ This property defines to how many triangles the item is divided into before its
+ vertices are passed to the vertex shader.
+
+ Triangles are defined as triangle strips and the amount of triangles can be controlled
+ separately for x and y-axis.
+
+ The default value is QSize(1,1).
+*/
+
+/*!
+ \property ShaderEffectItem::meshResolution
+ \brief the amount of triangles in the mesh for both x and y-axis.
+*/
+
+void ShaderEffectItem::setMeshResolution(const QSize &size)
+{
+ if (size == m_meshResolution)
+ return;
+
+ m_meshResolution = size;
+ emit meshResolutionChanged();
+ updateGeometry();
+}
+
+void ShaderEffectItem::componentComplete()
+{
+ updateProperties();
+ QDeclarativeItem::componentComplete();
+}
+
+void ShaderEffectItem::checkViewportUpdateMode()
+{
+ if (!m_checkedViewportUpdateMode) {
+ QGraphicsScene *s = scene();
+ if (s){
+ QList<QGraphicsView*> views = s->views();
+ for (int i = 0; i < views.count(); i++) {
+ if (views[i]->viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
+ qWarning() << "ShaderEffectItem::checkViewportUpdateMode - consider setting QGraphicsView::FullViewportUpdate mode with OpenGL!";
+ }
+ }
+ }
+ m_checkedViewportUpdateMode = true;
+ }
+}
+
+void ShaderEffectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+{
+ if (!m_active) return;
+
+ const QGLContext *context = QGLContext::currentContext();
+
+ if (context) {
+ if (!m_checkedShaderPrograms) {
+ m_hasShaderPrograms = QGLShaderProgram::hasOpenGLShaderPrograms(context);
+ m_checkedShaderPrograms = true;
+
+ if (!m_hasShaderPrograms)
+ qWarning() << "ShaderEffectItem::paint - Shader programs are not supported";
+ }
+
+ if ( !m_hasShaderPrograms )
+ return;
+
+ checkViewportUpdateMode();
+ painter->save();
+ painter->beginNativePainting();
+ QMatrix4x4 combinedMatrix = QMatrix4x4(painter->transform());
+ renderEffect(painter, combinedMatrix);
+ painter->endNativePainting();
+ painter->restore();
+ } else {
+ if (!m_checkedOpenGL) {
+ qWarning() << "ShaderEffectItem::paint - OpenGL not available";
+ m_checkedOpenGL = true;
+ }
+ }
+}
+
+void ShaderEffectItem::renderEffect(QPainter *painter, const QMatrix4x4 &matrix)
+{
+ if (!painter || !painter->device())
+ return;
+
+ if (!m_program.isLinked() || m_program_dirty)
+ updateShaderProgram();
+
+ m_program.bind();
+
+ QMatrix4x4 combinedMatrix;
+ combinedMatrix.scale(2.0 / painter->device()->width(), -2.0 / painter->device()->height(), 1.0);
+ combinedMatrix.translate(-painter->device()->width() / 2.0, -painter->device()->height() / 2.0 );
+ combinedMatrix *= matrix;
+ updateEffectState(combinedMatrix);
+
+ for (int i = 0; i < m_attributeNames.size(); ++i) {
+ m_program.enableAttributeArray(m_geometry.attributes()[i].position);
+ }
+
+ bindGeometry();
+
+ // Optimization, disable depth test when we know we don't need it.
+ if (m_defaultVertexShader) {
+ glDepthMask(false);
+ glDisable(GL_DEPTH_TEST);
+ } else {
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_GREATER);
+ glDepthMask(true);
+#if defined(QT_OPENGL_ES)
+ glClearDepthf(0);
+#else
+ glClearDepth(0);
+#endif
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ }
+
+ if (m_blending){
+ glEnable(GL_BLEND);
+ glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ } else {
+ glDisable(GL_BLEND);
+ }
+
+ if (m_geometry.indexCount())
+ glDrawElements(m_geometry.drawingMode(), m_geometry.indexCount(), m_geometry.indexType(), m_geometry.indexData());
+ else
+ glDrawArrays(m_geometry.drawingMode(), 0, m_geometry.vertexCount());
+
+ glDepthMask(false);
+ glDisable(GL_DEPTH_TEST);
+
+ for (int i = 0; i < m_attributeNames.size(); ++i)
+ m_program.disableAttributeArray(m_geometry.attributes()[i].position);
+}
+
+void ShaderEffectItem::updateEffectState(const QMatrix4x4 &matrix)
+{
+ for (int i = m_sources.size() - 1; i >= 0; --i) {
+ const ShaderEffectItem::SourceData &source = m_sources.at(i);
+ if (!source.source)
+ continue;
+
+ glActiveTexture(GL_TEXTURE0 + i);
+ source.source->bind();
+ }
+
+ if (m_respectsOpacity)
+ m_program.setUniformValue("qt_Opacity", static_cast<float> (effectiveOpacity()));
+
+ if (m_respectsMatrix){
+ m_program.setUniformValue("qt_ModelViewProjectionMatrix", matrix);
+ }
+
+ QSet<QByteArray>::const_iterator it;
+ for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
+ const QByteArray &name = *it;
+ QVariant v = property(name.constData());
+
+ switch (v.type()) {
+ case QVariant::Color:
+ m_program.setUniformValue(name.constData(), qvariant_cast<QColor>(v));
+ break;
+ case QVariant::Double:
+ m_program.setUniformValue(name.constData(), (float) qvariant_cast<double>(v));
+ break;
+ case QVariant::Transform:
+ m_program.setUniformValue(name.constData(), qvariant_cast<QTransform>(v));
+ break;
+ case QVariant::Int:
+ m_program.setUniformValue(name.constData(), v.toInt());
+ break;
+ case QVariant::Bool:
+ m_program.setUniformValue(name.constData(), GLint(v.toBool()));
+ break;
+ case QVariant::Size:
+ case QVariant::SizeF:
+ m_program.setUniformValue(name.constData(), v.toSizeF());
+ break;
+ case QVariant::Point:
+ case QVariant::PointF:
+ m_program.setUniformValue(name.constData(), v.toPointF());
+ break;
+ case QVariant::Rect:
+ case QVariant::RectF:
+ {
+ QRectF r = v.toRectF();
+ m_program.setUniformValue(name.constData(), r.x(), r.y(), r.width(), r.height());
+ }
+ break;
+ case QVariant::Vector3D:
+ m_program.setUniformValue(name.constData(), qvariant_cast<QVector3D>(v));
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static inline int size_of_type(GLenum type)
+{
+ static int sizes[] = {
+ sizeof(char),
+ sizeof(unsigned char),
+ sizeof(short),
+ sizeof(unsigned short),
+ sizeof(int),
+ sizeof(unsigned int),
+ sizeof(float),
+ 2,
+ 3,
+ 4,
+ sizeof(double)
+ };
+ return sizes[type - GL_BYTE];
+}
+
+void ShaderEffectItem::bindGeometry()
+{
+ char const *const *attrNames = m_attributeNames.constData();
+ int offset = 0;
+ for (int j = 0; j < m_attributeNames.size(); ++j) {
+ if (!*attrNames[j])
+ continue;
+ Q_ASSERT_X(j < m_geometry.attributeCount(), "ShaderEffectItem::bindGeometry()", "Geometry lacks attribute required by material");
+ const QSGGeometry::Attribute &a = m_geometry.attributes()[j];
+ Q_ASSERT_X(j == a.position, "ShaderEffectItem::bindGeometry()", "Geometry does not have continous attribute positions");
+#if defined(QT_OPENGL_ES_2)
+ GLboolean normalize = a.type != GL_FLOAT;
+#else
+ GLboolean normalize = a.type != GL_FLOAT && a.type != GL_DOUBLE;
+#endif
+ if (normalize)
+ qWarning() << "ShaderEffectItem::bindGeometry() - non supported attribute type!";
+
+ m_program.setAttributeArray(a.position, (GLfloat*) (((char*) m_geometry.vertexData()) + offset), a.tupleSize, m_geometry.stride());
+ //glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, m_geometry.stride(), (char *) m_geometry.vertexData() + offset);
+ offset += a.tupleSize * size_of_type(a.type);
+ }
+}
+
+void ShaderEffectItem::updateGeometry()
+{
+ QRectF srcRect(0, 1, 1, -1);
+
+ if (m_mirrored)
+ srcRect = QRectF(0, 0, 1, 1);
+
+ QRectF dstRect = QRectF(0,0, width(), height());
+
+ int vmesh = m_meshResolution.height();
+ int hmesh = m_meshResolution.width();
+
+ QSGGeometry *g = &m_geometry;
+ if (vmesh == 1 && hmesh == 1) {
+ if (g->vertexCount() != 4)
+ g->allocate(4);
+ QSGGeometry::updateTexturedRectGeometry(g, dstRect, srcRect);
+ return;
+ }
+
+ g->allocate((vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2));
+
+ QSGGeometry::TexturedPoint2D *vdata = g->vertexDataAsTexturedPoint2D();
+
+ for (int iy = 0; iy <= vmesh; ++iy) {
+ float fy = iy / float(vmesh);
+ float y = float(dstRect.top()) + fy * float(dstRect.height());
+ float ty = float(srcRect.top()) + fy * float(srcRect.height());
+ for (int ix = 0; ix <= hmesh; ++ix) {
+ float fx = ix / float(hmesh);
+ vdata->x = float(dstRect.left()) + fx * float(dstRect.width());
+ vdata->y = y;
+ vdata->tx = float(srcRect.left()) + fx * float(srcRect.width());
+ vdata->ty = ty;
+ ++vdata;
+ }
+ }
+
+ quint16 *indices = (quint16 *)g->indexDataAsUShort();
+ int i = 0;
+ for (int iy = 0; iy < vmesh; ++iy) {
+ *(indices++) = i + hmesh + 1;
+ for (int ix = 0; ix <= hmesh; ++ix, ++i) {
+ *(indices++) = i + hmesh + 1;
+ *(indices++) = i;
+ }
+ *(indices++) = i - 1;
+ }
+}
+
+void ShaderEffectItem::setActive(bool enable)
+{
+ if (m_active == enable)
+ return;
+
+ if (m_active) {
+ for (int i = 0; i < m_sources.size(); ++i) {
+ ShaderEffectSource *source = m_sources.at(i).source;
+ if (!source)
+ continue;
+ disconnect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
+ source->derefFromEffectItem();
+ }
+ }
+
+ m_active = enable;
+
+ if (m_active) {
+ for (int i = 0; i < m_sources.size(); ++i) {
+ ShaderEffectSource *source = m_sources.at(i).source;
+ if (!source)
+ continue;
+ source->refFromEffectItem();
+ connect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
+ }
+ }
+
+ emit activeChanged();
+ markDirty();
+}
+
+void ShaderEffectItem::preprocess()
+{
+ for (int i = 0; i < m_sources.size(); ++i) {
+ ShaderEffectSource *source = m_sources.at(i).source;
+ if (source)
+ source->updateBackbuffer();
+ }
+}
+
+void ShaderEffectItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ if (newGeometry.size() != oldGeometry.size())
+ updateGeometry();
+ QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+}
+
+void ShaderEffectItem::changeSource(int index)
+{
+ Q_ASSERT(index >= 0 && index < m_sources.size());
+ QVariant v = property(m_sources.at(index).name.constData());
+ setSource(v, index);
+}
+
+void ShaderEffectItem::markDirty() {
+ update();
+}
+
+void ShaderEffectItem::setSource(const QVariant &var, int index)
+{
+ Q_ASSERT(index >= 0 && index < m_sources.size());
+
+ SourceData &source = m_sources[index];
+
+ source.source = 0;
+ source.item = 0;
+ if (var.isNull()) {
+ return;
+ } else if (!qVariantCanConvert<QObject *>(var)) {
+ qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData());
+ return;
+ }
+
+ QObject *obj = qVariantValue<QObject *>(var);
+
+ source.source = qobject_cast<ShaderEffectSource *>(obj);
+ source.item = qobject_cast<QDeclarativeItem *>(obj);
+
+ if (!source.item)
+ qWarning("Could not assign property '%s', did not implement QDeclarativeItem.", source.name.constData());
+
+ if (!source.source)
+ qWarning("Could not assign property '%s', did not implement ShaderEffectSource.", source.name.constData());
+
+ // TODO: Find better solution.
+ // 'source.item' needs a canvas to get a scenegraph node.
+ // The easiest way to make sure it gets a canvas is to
+ // make it a part of the same item tree as 'this'.
+ if (source.item && source.item->parentItem() == 0) {
+ source.item->setParentItem(this);
+ // Unlike in scenegraph, we cannot set item invisible here because qgraphicsview would optimize it away.
+ }
+
+ // Unlike in scenegraph, ref counting is used to optimize memory consumption. Sources themself may free fbos when not referenced.
+ if (m_active && source.source) {
+ source.source->refFromEffectItem();
+ connect(source.source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
+ }
+}
+
+void ShaderEffectItem::disconnectPropertySignals()
+{
+ disconnect(this, 0, this, SLOT(markDirty()));
+ for (int i = 0; i < m_sources.size(); ++i) {
+ SourceData &source = m_sources[i];
+ disconnect(this, 0, source.mapper, 0);
+ disconnect(source.mapper, 0, this, 0);
+ }
+}
+
+void ShaderEffectItem::connectPropertySignals()
+{
+ QSet<QByteArray>::const_iterator it;
+ for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
+ int pi = metaObject()->indexOfProperty(it->constData());
+ if (pi >= 0) {
+ QMetaProperty mp = metaObject()->property(pi);
+ if (!mp.hasNotifySignal())
+ qWarning("ShaderEffectItem: property '%s' does not have notification method!", it->constData());
+ QByteArray signalName("2");
+ signalName.append(mp.notifySignal().signature());
+ connect(this, signalName, this, SLOT(markDirty()));
+ } else {
+ qWarning("ShaderEffectItem: '%s' does not have a matching property!", it->constData());
+ }
+ }
+ for (int i = 0; i < m_sources.size(); ++i) {
+ SourceData &source = m_sources[i];
+ int pi = metaObject()->indexOfProperty(source.name.constData());
+ if (pi >= 0) {
+ QMetaProperty mp = metaObject()->property(pi);
+ QByteArray signalName("2");
+ signalName.append(mp.notifySignal().signature());
+ connect(this, signalName, source.mapper, SLOT(map()));
+ source.mapper->setMapping(this, i);
+ connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
+ } else {
+ qWarning("ShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
+ }
+ }
+}
+
+void ShaderEffectItem::reset()
+{
+ disconnectPropertySignals();
+
+ m_program.removeAllShaders();
+ m_attributeNames.clear();
+ m_uniformNames.clear();
+ for (int i = 0; i < m_sources.size(); ++i) {
+ const SourceData &source = m_sources.at(i);
+ if (m_active && source.source)
+ source.source->derefFromEffectItem();
+ delete source.mapper;
+ }
+
+ m_sources.clear();
+ m_program_dirty = true;
+}
+
+void ShaderEffectItem::updateProperties()
+{
+ QString vertexCode = m_vertex_code;
+ QString fragmentCode = m_fragment_code;
+
+ if (vertexCode.isEmpty())
+ vertexCode = qt_default_vertex_code;
+
+ if (fragmentCode.isEmpty())
+ fragmentCode = qt_default_fragment_code;
+
+ lookThroughShaderCode(vertexCode);
+ lookThroughShaderCode(fragmentCode);
+
+ if (!m_attributeNames.contains(qt_postion_attribute_name))
+ qWarning("ShaderEffectItem: Missing reference to \'%s\'.", qt_postion_attribute_name);
+ if (!m_attributeNames.contains(qt_texcoord_attribute_name))
+ qWarning("ShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
+ if (!m_respectsMatrix)
+ qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
+
+ for (int i = 0; i < m_sources.size(); ++i) {
+ QVariant v = property(m_sources.at(i).name);
+ setSource(v, i); // Property exists.
+ }
+
+ connectPropertySignals();
+}
+
+void ShaderEffectItem::updateShaderProgram()
+{
+ QString vertexCode = m_vertex_code;
+ QString fragmentCode = m_fragment_code;
+
+ if (vertexCode.isEmpty())
+ vertexCode = QString::fromLatin1(qt_default_vertex_code);
+
+ if (fragmentCode.isEmpty())
+ fragmentCode = QString::fromLatin1(qt_default_fragment_code);
+
+ m_program.addShaderFromSourceCode(QGLShader::Vertex, vertexCode);
+ m_program.addShaderFromSourceCode(QGLShader::Fragment, fragmentCode);
+
+ for (int i = 0; i < m_attributeNames.size(); ++i) {
+ m_program.bindAttributeLocation(m_attributeNames.at(i), m_geometry.attributes()[i].position);
+ }
+
+ if (!m_program.link()) {
+ qWarning("ShaderEffectItem: Shader compilation failed:");
+ qWarning() << m_program.log();
+ }
+
+ if (!m_attributeNames.contains(qt_postion_attribute_name))
+ qWarning("ShaderEffectItem: Missing reference to \'qt_Vertex\'.");
+ if (!m_attributeNames.contains(qt_texcoord_attribute_name))
+ qWarning("ShaderEffectItem: Missing reference to \'qt_MultiTexCoord0\'.");
+ if (!m_respectsMatrix)
+ qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
+
+ if (m_program.isLinked()) {
+ m_program.bind();
+ for (int i = 0; i < m_sources.size(); ++i)
+ m_program.setUniformValue(m_sources.at(i).name.constData(), i);
+ }
+
+ m_program_dirty = false;
+}
+
+void ShaderEffectItem::lookThroughShaderCode(const QString &code)
+{
+ // Regexp for matching attributes and uniforms.
+ // In human readable form: attribute|uniform [lowp|mediump|highp] <type> <name>
+ static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)"));
+ Q_ASSERT(re.isValid());
+
+ int pos = -1;
+
+ //QString wideCode = QString::fromLatin1(code.constData(), code.size());
+ QString wideCode = code;
+
+ while ((pos = re.indexIn(wideCode, pos + 1)) != -1) {
+ QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute
+ QByteArray type = re.cap(2).toLatin1(); // type
+ QByteArray name = re.cap(3).toLatin1(); // variable name
+
+ if (decl == "attribute") {
+ if (name == qt_postion_attribute_name) {
+ m_attributeNames.insert(0, qt_postion_attribute_name);
+ } else if (name == "qt_MultiTexCoord0") {
+ if (m_attributeNames.at(0) == 0) {
+ m_attributeNames.insert(0, qt_emptyAttributeName);
+ }
+ m_attributeNames.insert(1, qt_texcoord_attribute_name);
+ } else {
+ // TODO: Support user defined attributes.
+ qWarning("ShaderEffectItem: Attribute \'%s\' not recognized.", name.constData());
+ }
+ } else {
+ Q_ASSERT(decl == "uniform");
+
+ if (name == "qt_ModelViewProjectionMatrix") {
+ m_respectsMatrix = true;
+ } else if (name == "qt_Opacity") {
+ m_respectsOpacity = true;
+ } else {
+ m_uniformNames.insert(name);
+ if (type == "sampler2D") {
+ SourceData d;
+ d.mapper = new QSignalMapper;
+ d.source = 0;
+ d.name = name;
+ d.item = 0;
+ m_sources.append(d);
+ }
+ }
+ }
+ }
+}
+
+void ShaderEffectItem::handleVisibilityChange()
+{
+ setActive(isVisible());
+}
diff --git a/src/imports/shaders/shadereffectitem.h b/src/imports/shaders/shadereffectitem.h
new file mode 100644
index 0000000000..1d275439f2
--- /dev/null
+++ b/src/imports/shaders/shadereffectitem.h
@@ -0,0 +1,152 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHADEREFFECTITEM_H
+#define SHADEREFFECTITEM_H
+
+#include <QDeclarativeItem>
+#include <QtOpenGL>
+#include "shadereffectsource.h"
+#include "scenegraph/qsggeometry.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class ShaderEffectItem : public QDeclarativeItem
+{
+ Q_OBJECT
+ Q_INTERFACES(QDeclarativeParserStatus)
+ Q_PROPERTY(QString fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
+ Q_PROPERTY(QString vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
+ Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged)
+ Q_PROPERTY(QSize meshResolution READ meshResolution WRITE setMeshResolution NOTIFY meshResolutionChanged)
+
+public:
+ ShaderEffectItem(QDeclarativeItem* parent = 0);
+ ~ShaderEffectItem();
+
+ virtual void componentComplete();
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+ QString fragmentShader() const { return m_fragment_code; }
+ void setFragmentShader(const QString &code);
+
+ QString vertexShader() const { return m_vertex_code; }
+ void setVertexShader(const QString &code);
+
+ bool blending() const { return m_blending; }
+ void setBlending(bool enable);
+
+ QSize meshResolution() const { return m_meshResolution; }
+ void setMeshResolution(const QSize &size);
+
+ void preprocess();
+
+Q_SIGNALS:
+ void fragmentShaderChanged();
+ void vertexShaderChanged();
+ void blendingChanged();
+ void activeChanged();
+ void meshResolutionChanged();
+
+protected:
+ virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
+
+private Q_SLOTS:
+ void changeSource(int index);
+ void handleVisibilityChange();
+ void markDirty();
+
+private:
+ void checkViewportUpdateMode();
+ void renderEffect(QPainter *painter, const QMatrix4x4 &matrix);
+ void updateEffectState(const QMatrix4x4 &matrix);
+ void updateGeometry();
+ void bindGeometry();
+ void setSource(const QVariant &var, int index);
+ void disconnectPropertySignals();
+ void connectPropertySignals();
+ void reset();
+ void updateProperties();
+ void updateShaderProgram();
+ void lookThroughShaderCode(const QString &code);
+ bool active() const { return m_active; }
+ void setActive(bool enable);
+
+private:
+ QString m_fragment_code;
+ QString m_vertex_code;
+ QGLShaderProgram m_program;
+ QVector<const char *> m_attributeNames;
+ QSet<QByteArray> m_uniformNames;
+ QSize m_meshResolution;
+ QSGGeometry m_geometry;
+
+ struct SourceData
+ {
+ QSignalMapper *mapper;
+ QPointer<ShaderEffectSource> source;
+ QPointer<QDeclarativeItem> item;
+ QByteArray name;
+ };
+
+ QVector<SourceData> m_sources;
+
+ bool m_changed : 1;
+ bool m_blending : 1;
+ bool m_program_dirty : 1;
+ bool m_active : 1;
+ bool m_respectsMatrix : 1;
+ bool m_respectsOpacity : 1;
+ bool m_checkedViewportUpdateMode : 1;
+ bool m_checkedOpenGL : 1;
+ bool m_checkedShaderPrograms : 1;
+ bool m_hasShaderPrograms : 1;
+ bool m_mirrored : 1;
+ bool m_defaultVertexShader : 1;
+};
+
+QT_END_HEADER
+
+QT_END_NAMESPACE
+
+#endif // SHADEREFFECTITEM_H
diff --git a/src/imports/shaders/shadereffectsource.cpp b/src/imports/shaders/shadereffectsource.cpp
new file mode 100644
index 0000000000..0a133bd6c9
--- /dev/null
+++ b/src/imports/shaders/shadereffectsource.cpp
@@ -0,0 +1,472 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "shadereffectsource.h"
+#include "shadereffectbuffer.h"
+#include "shadereffect.h"
+#include "glfunctions.h"
+
+#include <QtOpenGL>
+
+/*!
+ \qmlclass ShaderEffectSource ShaderEffectSource
+ \ingroup qmlshadersplugin
+ \brief The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem.
+
+ ShaderEffectSource is available in the \bold{Qt.labs.shaders 1.0} module.
+ \e {Elements in the Qt.labs module are not guaranteed to remain compatible
+ in future versions.}
+
+ This element provides preliminary support for OpenGL shaders in QML,
+ and may be heavily changed or removed in later versions.
+
+ Requirement for the ability to use of shaders is that the application is either using
+ opengl graphicssystem or has set QGLWidget as the viewport to QDeclarativeView (recommended way).
+
+ ShaderEffectSource object encapsulates the source content so that it can be utilized in ShaderEffectItem.
+ Source content can be a live QML object tree, or a snapshot of QML object tree.
+
+*/
+
+ShaderEffectSource::ShaderEffectSource(QDeclarativeItem *parent)
+ : QDeclarativeItem(parent)
+ , m_sourceItem(0)
+ , m_wrapMode(ClampToEdge)
+ , m_sourceRect(0, 0, 0, 0)
+ , m_textureSize(0, 0)
+ , m_format(RGBA)
+ , m_size(0, 0)
+ , m_fbo(0)
+ , m_multisampledFbo(0)
+ , m_refs(0)
+ , m_dirtyTexture(true)
+ , m_dirtySceneGraph(true)
+ , m_multisamplingSupported(false)
+ , m_checkedForMultisamplingSupport(false)
+ , m_live(true)
+ , m_hideSource(false)
+ , m_mirrored(false)
+{
+}
+
+ShaderEffectSource::~ShaderEffectSource()
+{
+ if (m_refs && m_sourceItem)
+ detachSourceItem();
+
+ delete m_fbo;
+ delete m_multisampledFbo;
+}
+
+/*!
+ \qmlproperty Item ShaderEffectSource::sourceItem
+ This property holds the Item which is used as the source for the shader effect.
+ If the item has children, those are included as well.
+
+ \note When source item content is passed to the ShaderEffectItem(s), it is always clipped to the boundingrect of the
+ sourceItem regardless of its clipping property.
+*/
+
+/*!
+ \property ShaderEffectSource::sourceItem
+ \brief the Item which is the source for the effect.
+*/
+
+void ShaderEffectSource::setSourceItem(QDeclarativeItem *item)
+{
+ if (item == m_sourceItem)
+ return;
+
+ if (m_sourceItem) {
+ disconnect(m_sourceItem, SIGNAL(widthChanged()), this, SLOT(markSourceSizeDirty()));
+ disconnect(m_sourceItem, SIGNAL(heightChanged()), this, SLOT(markSourceSizeDirty()));
+
+ if (m_refs)
+ detachSourceItem();
+ }
+
+ m_sourceItem = item;
+
+ if (m_sourceItem) {
+
+ // Must have some item as parent
+ if (m_sourceItem->parentItem() == 0)
+ m_sourceItem->setParentItem(this);
+
+ if (m_refs)
+ attachSourceItem();
+
+ connect(m_sourceItem, SIGNAL(widthChanged()), this, SLOT(markSourceSizeDirty()));
+ connect(m_sourceItem, SIGNAL(heightChanged()), this, SLOT(markSourceSizeDirty()));
+ }
+
+ updateSizeAndTexture();
+ emit sourceItemChanged();
+ emit repaintRequired();
+}
+
+/*!
+ \qmlproperty QRectF ShaderEffectSource::sourceRect
+ This property can be used to specify margins for the source content.
+
+ If other value than Qt.rect(0,0,0,0) is assigned to this property, it is interpreted as
+ specifying a relative source rectangle for the source content.
+
+ For example, setting Qt.rect(-10.0, -10.0, 120.0, 120.0) for a source that has width and height
+ of 100 pixels would produce 10 pixels margins to each side of the source.
+
+ Margins are useful when the original content is wanted to be spread outside the original source area,
+ like when creating a dropshadow with the shader or in other similar effects.
+
+ The default value is Qt.rect(0,0,0,0).
+*/
+
+/*!
+ \property ShaderEffectSource::sourceRect
+ \brief the relative sourceRect for the source.
+*/
+
+void ShaderEffectSource::setSourceRect(const QRectF &rect)
+{
+ if (rect == m_sourceRect)
+ return;
+ m_sourceRect = rect;
+ updateSizeAndTexture();
+ updateBackbuffer();
+ emit sourceRectChanged();
+ emit repaintRequired();
+
+ if (m_sourceItem) {
+ ShaderEffect* effect = qobject_cast<ShaderEffect*> (m_sourceItem->graphicsEffect());
+ if (effect)
+ effect->m_changed = true;
+ }
+}
+
+/*!
+ \qmlproperty QSize ShaderEffectSource::textureSize
+ This property holds the size for the texture containing the source content.
+
+ If value QSize(0,0) is assigned to this property, texture is resized
+ according to the source size. Otherwise source content is scaled to
+ the given size.
+
+ The default value is QSize(0,0).
+*/
+
+/*!
+ \property ShaderEffectSource::textureSize
+ \brief the texture size for the source.
+*/
+
+void ShaderEffectSource::setTextureSize(const QSize &size)
+{
+ if (size == m_textureSize)
+ return;
+
+ m_textureSize = size;
+ updateSizeAndTexture();
+ emit textureSizeChanged();
+ emit repaintRequired();
+
+ if (m_sourceItem) {
+ ShaderEffect* effect = qobject_cast<ShaderEffect*> (m_sourceItem->graphicsEffect());
+ if (effect)
+ effect->m_changed = true;
+ }
+}
+
+/*!
+ \qmlproperty bool ShaderEffectSource::live
+ This property holds the optimization flag to define wheter the source item content is changing or
+ static.
+
+ If value true is assigned to this property, source item content is re-rendered into a
+ texture for every frame. Setting the value to false improves the performance as it skips
+ rendering the source item (and its chidleren) and instead immediately passes the previously
+ rendered and cached texture to the shaders.
+
+ The default value is true.
+*/
+
+/*!
+ \property ShaderEffectSource::live
+ \brief the flag tells wheter source item content is changing between frames.
+*/
+
+void ShaderEffectSource::setLive(bool s)
+{
+ if (s == m_live)
+ return;
+
+ m_live = s;
+
+ emit liveChanged();
+ emit repaintRequired();
+}
+
+/*!
+ \qmlproperty bool ShaderEffectSource::hideSource
+ This property holds the flag to define wheter the original source item is
+ hidden when the effect item is drawn.
+
+ The default value is false.
+*/
+
+/*!
+ \property ShaderEffectSource::hideSource
+ \brief the flag tells wheter original source item content should be hidden.
+*/
+
+void ShaderEffectSource::setHideSource(bool hide)
+{
+ if (hide == m_hideSource)
+ return;
+
+ m_hideSource = hide;
+
+ emit hideSourceChanged();
+ emit repaintRequired();
+}
+
+/*!
+ \qmlproperty enumeration ShaderEffectSource::wrapMode
+
+ This property defines the wrap parameter for the source after it has been mapped as a texture.
+
+ \list
+ \o WrapMode.ClampToEdge - Causes texturecoordinates to be clamped to the range [ 1/2*N , 1 - 1/2*N ], where N is the texture width.
+ \o WrapMode.RepeatHorizontally - Causes the integer part of the horizontal texturecoordinate to be ignored; the GL uses only the fractional part, thereby creating a horizontal repeating pattern.
+ \o WrapMode.RepeatVertically - Causes the integer part of the vertical texturecoordinate to be ignored; the GL uses only the fractional part, thereby creating a vertical repeating pattern.
+ \o WrapMode.Repeat - Causes the integer part of both the horizontal and vertical texturecoordinates to be ignored; the GL uses only the fractional part, thereby creating a repeating pattern.
+ \endlist
+
+ The default value is ClampToEdge.
+
+*/
+
+/*!
+ \property ShaderEffectSource::wrapMode
+ \brief the wrap parameter for the source after it has been mapped as a texture.
+*/
+
+void ShaderEffectSource::setWrapMode(WrapMode mode)
+{
+ if (mode == m_wrapMode)
+ return;
+
+ m_wrapMode = mode;
+ updateBackbuffer();
+ emit wrapModeChanged();
+}
+
+/*!
+ \qmlmethod ShaderEffectSource::grab()
+
+ Repaints the source item content into the texture.
+
+ This method is useful when ShaderEffectSource::live has been set to false and
+ the changes in the source item content is desired to be made visible for the shaders.
+
+*/
+
+void ShaderEffectSource::grab()
+{
+ m_dirtyTexture = true;
+ emit repaintRequired();
+}
+
+void ShaderEffectSource::bind() const
+{
+ GLint filtering = smooth() ? GL_LINEAR : GL_NEAREST;
+ GLuint hwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatHorizontally) ? GL_REPEAT : GL_CLAMP_TO_EDGE;
+ GLuint vwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatVertically) ? GL_REPEAT : GL_CLAMP_TO_EDGE;
+
+#if !defined(QT_OPENGL_ES_2)
+ glEnable(GL_TEXTURE_2D);
+#endif
+ if (m_fbo) {
+ glBindTexture(GL_TEXTURE_2D, m_fbo->texture());
+ } else {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, smooth() ? GL_LINEAR : GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, hwrap);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, vwrap);
+}
+
+void ShaderEffectSource::refFromEffectItem()
+{
+ if (m_refs++ == 0) {
+ attachSourceItem();
+ emit activeChanged();
+ }
+}
+
+void ShaderEffectSource::derefFromEffectItem()
+{
+ if (--m_refs == 0) {
+ detachSourceItem();
+ emit activeChanged();
+ }
+ Q_ASSERT(m_refs >= 0);
+}
+
+void ShaderEffectSource::updateBackbuffer()
+{
+ if (!m_sourceItem)
+ return;
+
+ // Multisampling is not (for now) supported.
+ QSize size = QSize(m_sourceItem->width(), m_sourceItem->height());
+ if (!m_textureSize.isEmpty())
+ size = m_textureSize;
+
+ if (size.height() > 0 && size.width() > 0) {
+ QGLFramebufferObjectFormat format;
+ format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
+ format.setInternalTextureFormat(m_format);
+
+ if (!m_fbo) {
+ m_fbo = new ShaderEffectBuffer(size, format);
+ } else {
+ if (m_fbo->size() != size || m_fbo->format().internalTextureFormat() != GLenum(m_format)) {
+ delete m_fbo;
+ m_fbo = 0;
+ m_fbo = new ShaderEffectBuffer(size, format);
+ }
+ }
+ }
+
+ // Note that real update for the source content happens in shadereffect.cpp
+ m_dirtyTexture = false;
+}
+
+void ShaderEffectSource::markSceneGraphDirty()
+{
+ m_dirtySceneGraph = true;
+ emit repaintRequired();
+}
+
+void ShaderEffectSource::markSourceSizeDirty()
+{
+ Q_ASSERT(m_sourceItem);
+ if (m_textureSize.isEmpty())
+ updateSizeAndTexture();
+ if (m_refs)
+ emit repaintRequired();
+}
+
+void ShaderEffectSource::updateSizeAndTexture()
+{
+ if (m_sourceItem) {
+ QSize size = m_textureSize;
+ if (size.isEmpty())
+ size = QSize(m_sourceItem->width(), m_sourceItem->height());
+ if (size.width() < 1)
+ size.setWidth(1);
+ if (size.height() < 1)
+ size.setHeight(1);
+ if (m_fbo && m_fbo->size() != size) {
+ delete m_fbo;
+ m_fbo = 0;
+ delete m_multisampledFbo;
+ m_fbo = m_multisampledFbo = 0;
+ }
+ if (m_size.width() != size.width()) {
+ m_size.setWidth(size.width());
+ emit widthChanged();
+ }
+ if (m_size.height() != size.height()) {
+ m_size.setHeight(size.height());
+ emit heightChanged();
+ }
+ m_dirtyTexture = true;
+ } else {
+ if (m_size.width() != 0) {
+ m_size.setWidth(0);
+ emit widthChanged();
+ }
+ if (m_size.height() != 0) {
+ m_size.setHeight(0);
+ emit heightChanged();
+ }
+ }
+}
+
+void ShaderEffectSource::attachSourceItem()
+{
+ if (!m_sourceItem)
+ return;
+
+ ShaderEffect *effect = qobject_cast<ShaderEffect*> (m_sourceItem->graphicsEffect());
+
+ if (!effect) {
+ effect = new ShaderEffect();
+ m_sourceItem->setGraphicsEffect(effect);
+ }
+
+ if (effect)
+ effect->addRenderTarget(this);
+
+ m_sourceItem->update();
+}
+
+void ShaderEffectSource::detachSourceItem()
+{
+ if (!m_sourceItem)
+ return;
+
+ ShaderEffect* effect = qobject_cast<ShaderEffect*> (m_sourceItem->graphicsEffect());
+
+ if (effect)
+ effect->removeRenderTarget(this);
+
+ delete m_fbo;
+ m_fbo = 0;
+
+ delete m_multisampledFbo;
+ m_multisampledFbo = 0;
+
+ m_dirtyTexture = true;
+}
diff --git a/src/imports/shaders/shadereffectsource.h b/src/imports/shaders/shadereffectsource.h
new file mode 100644
index 0000000000..275e5b2030
--- /dev/null
+++ b/src/imports/shaders/shadereffectsource.h
@@ -0,0 +1,158 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SHADEREFFECTSOURCE_H
+#define SHADEREFFECTSOURCE_H
+
+#include <QDeclarativeItem>
+#include <QtOpenGL>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class ShaderEffectBuffer;
+
+class ShaderEffectSource : public QDeclarativeItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QDeclarativeItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged)
+ Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
+ Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
+ Q_PROPERTY(bool live READ isLive WRITE setLive NOTIFY liveChanged)
+ Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
+ Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
+ Q_ENUMS(WrapMode)
+ Q_ENUMS(Format)
+
+public:
+ enum WrapMode {
+ ClampToEdge,
+ RepeatHorizontally,
+ RepeatVertically,
+ Repeat
+ };
+
+ enum Format {
+ Alpha = GL_ALPHA,
+ RGB = GL_RGB,
+ RGBA = GL_RGBA
+ };
+
+ ShaderEffectSource(QDeclarativeItem *parent = 0);
+ virtual ~ShaderEffectSource();
+
+ QDeclarativeItem *sourceItem() const { return m_sourceItem.data(); }
+ void setSourceItem(QDeclarativeItem *item);
+
+ QRectF sourceRect() const { return m_sourceRect; };
+ void setSourceRect(const QRectF &rect);
+
+ QSize textureSize() const { return m_textureSize; }
+ void setTextureSize(const QSize &size);
+
+ bool isLive() const { return m_live; }
+ void setLive(bool s);
+
+ bool hideSource() const { return m_hideSource; }
+ void setHideSource(bool hide);
+
+ WrapMode wrapMode() const { return m_wrapMode; };
+ void setWrapMode(WrapMode mode);
+
+ bool isActive() const { return m_refs; }
+ void bind() const;
+ void refFromEffectItem();
+ void derefFromEffectItem();
+ void updateBackbuffer();
+
+ ShaderEffectBuffer* fbo() { return m_fbo; }
+ bool isDirtyTexture() { return m_dirtyTexture; }
+ bool isMirrored() { return m_mirrored; }
+
+ Q_INVOKABLE void grab();
+
+Q_SIGNALS:
+ void sourceItemChanged();
+ void sourceRectChanged();
+ void textureSizeChanged();
+ void formatChanged();
+ void liveChanged();
+ void hideSourceChanged();
+ void activeChanged();
+ void repaintRequired();
+ void wrapModeChanged();
+
+public Q_SLOTS:
+ void markSceneGraphDirty();
+ void markSourceSizeDirty();
+
+private:
+ void updateSizeAndTexture();
+ void attachSourceItem();
+ void detachSourceItem();
+
+private:
+ QPointer<QDeclarativeItem> m_sourceItem;
+ WrapMode m_wrapMode;
+ QRectF m_sourceRect;
+ QSize m_textureSize;
+ Format m_format;
+ QSize m_size;
+
+ ShaderEffectBuffer *m_fbo;
+ ShaderEffectBuffer *m_multisampledFbo;
+ int m_refs;
+ bool m_dirtyTexture : 1;
+ bool m_dirtySceneGraph : 1;
+ bool m_multisamplingSupported : 1;
+ bool m_checkedForMultisamplingSupport : 1;
+ bool m_live : 1;
+ bool m_hideSource : 1;
+ bool m_mirrored : 1;
+};
+
+QT_END_HEADER
+
+QT_END_NAMESPACE
+
+
+#endif // SHADEREFFECTSOURCE_H
diff --git a/src/imports/shaders/shaders.pro b/src/imports/shaders/shaders.pro
new file mode 100644
index 0000000000..d7a6275af5
--- /dev/null
+++ b/src/imports/shaders/shaders.pro
@@ -0,0 +1,38 @@
+TARGET = qmlshadersplugin
+TARGETPATH = Qt/labs/shaders
+include(../qimportbase.pri)
+
+QT += declarative opengl
+
+SOURCES += \
+ qmlshadersplugin_plugin.cpp \
+ shadereffect.cpp \
+ shadereffectitem.cpp \
+ shadereffectsource.cpp \
+ scenegraph/qsggeometry.cpp \
+ shadereffectbuffer.cpp
+
+HEADERS += \
+ qmlshadersplugin_plugin.h \
+ glfunctions.h \
+ shadereffect.h \
+ shadereffectitem.h \
+ shadereffectsource.h \
+ scenegraph/qsggeometry.h \
+ shadereffectbuffer.h
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/$$TARGETPATH
+target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+qmldir.files += $$PWD/qmldir
+qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH
+
+symbian:{
+ TARGET.UID3 = 0x20034907
+ isEmpty(DESTDIR):importFiles.sources = qmlparticlesplugin$${QT_LIBINFIX}.dll qmldir
+ else:importFiles.sources = $$DESTDIR/qmlparticlesplugin$${QT_LIBINFIX}.dll qmldir
+ importFiles.path = $$QT_IMPORTS_BASE_DIR/$$TARGETPATH
+ DEPLOYMENT = importFiles
+}
+
+INSTALLS += target qmldir
diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro
index 1f0d32a3d0..1bcc26f8b4 100644
--- a/tests/auto/declarative/declarative.pro
+++ b/tests/auto/declarative/declarative.pro
@@ -79,5 +79,7 @@ contains(QT_CONFIG, webkit) {
qdeclarativewebview
}
+contains(QT_CONFIG, opengl): SUBDIRS += qmlshadersplugin
+
# Tests which should run in Pulse
PULSE_TESTS = $$SUBDIRS
diff --git a/tests/auto/declarative/qmlshadersplugin/main.qml b/tests/auto/declarative/qmlshadersplugin/main.qml
new file mode 100644
index 0000000000..fc80b39803
--- /dev/null
+++ b/tests/auto/declarative/qmlshadersplugin/main.qml
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 1.0
+import Qt.labs.shaders 1.0
+
+ Rectangle {
+ width: 300
+ height: 300
+
+ Text {
+ id: textLabel
+ text: "Hello World"
+ anchors.centerIn: parent
+ font.pixelSize: 48
+ }
+
+ ShaderEffectItem {
+ objectName: "effectItem"
+ property variant source: ShaderEffectSource { objectName: "effectSource"; sourceItem: textLabel; hideSource: true }
+ property real wiggleAmount: 0.01
+ anchors.fill: textLabel
+
+ SequentialAnimation on wiggleAmount {
+ loops: Animation.Infinite
+ NumberAnimation { to: -0.01; duration: 500 }
+ NumberAnimation { to: 0.01; duration: 500 }
+ }
+
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform highp float wiggleAmount;
+ void main(void)
+ {
+ highp vec2 wiggledTexCoord = qt_TexCoord0;
+ wiggledTexCoord.s += sin(4.0 * 3.141592653589 * wiggledTexCoord.t) * wiggleAmount;
+ gl_FragColor = texture2D(source, wiggledTexCoord.st);
+ }
+ "
+ }
+ }
diff --git a/tests/auto/declarative/qmlshadersplugin/qmlshadersplugin.pro b/tests/auto/declarative/qmlshadersplugin/qmlshadersplugin.pro
new file mode 100644
index 0000000000..6225a8f661
--- /dev/null
+++ b/tests/auto/declarative/qmlshadersplugin/qmlshadersplugin.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+
+QT += opengl declarative
+SOURCES += tst_qmlshadersplugin.cpp
+
+SOURCES += \
+ ../../../../src/imports/shaders/src/shadereffectitem.cpp \
+ ../../../../src/imports/shaders/src/shadereffectsource.cpp \
+ ../../../../src/imports/shaders/src/shadereffect.cpp \
+ ../../../../src/imports/shaders/src/shadereffectbuffer.cpp \
+ ../../../../src/imports/shaders/src/scenegraph/qsggeometry.cpp
+
+HEADERS += \
+ ../../../../src/imports/shaders/src/shadereffectitem.h \
+ ../../../../src/imports/shaders/src/shadereffectsource.h \
+ ../../../../src/imports/shaders/src/shadereffect.h \
+ ../../../../src/imports/shaders/src/shadereffectbuffer.h \
+ ../../../../src/imports/shaders/src/scenegraph/qsggeometry.h
diff --git a/tests/auto/declarative/qmlshadersplugin/tst_qmlshadersplugin.cpp b/tests/auto/declarative/qmlshadersplugin/tst_qmlshadersplugin.cpp
new file mode 100644
index 0000000000..61fe2ee19f
--- /dev/null
+++ b/tests/auto/declarative/qmlshadersplugin/tst_qmlshadersplugin.cpp
@@ -0,0 +1,205 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtDeclarative>
+#include "../../../../src/imports/shaders/src/shadereffectitem.h"
+#include "../../../../src/imports/shaders/src/shadereffectsource.h"
+#include "../../../../src/imports/shaders/src/shadereffect.h"
+
+static const char qt_default_vertex_code[] =
+ "uniform highp mat4 qt_ModelViewProjectionMatrix;\n"
+ "attribute highp vec4 qt_Vertex;\n"
+ "attribute highp vec2 qt_MultiTexCoord0;\n"
+ "varying highp vec2 qt_TexCoord0;\n"
+ "void main(void)\n"
+ "{\n"
+ "qt_TexCoord0 = qt_MultiTexCoord0;\n"
+ "gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n"
+ "}\n";
+
+static const char qt_default_fragment_code[] =
+ "varying highp vec2 qt_TexCoord0;\n"
+ "uniform lowp sampler2D source;\n"
+ "void main(void)\n"
+ "{\n"
+ "gl_FragColor = texture2D(source, qt_TexCoord0.st);\n"
+ "}\n";
+
+class tst_qmlshadersplugin : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void shaderEffectItemAPI();
+ void shaderEffectSourceAPI();
+ void combined();
+
+private:
+ QDeclarativeEngine engine;
+};
+
+void tst_qmlshadersplugin::initTestCase()
+{
+ const char *uri ="Qt.labs.shaders";
+ qmlRegisterType<ShaderEffectItem>(uri, 1, 0, "ShaderEffectItem");
+ qmlRegisterType<ShaderEffectSource>(uri, 1, 0, "ShaderEffectSource");
+}
+
+
+void tst_qmlshadersplugin::shaderEffectItemAPI()
+{
+ // Creation
+ QString componentStr = "import QtQuick 1.0\n"
+ "import Qt.labs.shaders 1.0\n"
+ "ShaderEffectItem {\n"
+ "property variant source\n"
+ "width: 200; height: 300\n"
+ "}";
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+
+ QObject *obj = component.create();
+ QTest::qWait(100);
+ QVERIFY(obj != 0);
+
+ // Default values
+ QCOMPARE(obj->property("width").toDouble(), 200.);
+ QCOMPARE(obj->property("height").toDouble(), 300.);
+ QCOMPARE(obj->property("fragmentShader").toString(), QString(""));
+ QCOMPARE(obj->property("vertexShader").toString(), QString(""));
+ QCOMPARE(obj->property("blending").toBool(), true);
+ QCOMPARE(obj->property("meshResolution").toSize(), QSize(1, 1));
+ QCOMPARE(obj->property("visible").toBool(), true);
+
+ // Seting the values
+ QVERIFY(obj->setProperty("fragmentShader", QString(qt_default_fragment_code)));
+ QVERIFY(obj->setProperty("vertexShader", QString(qt_default_vertex_code)));
+ QVERIFY(obj->setProperty("blending", false));
+ QVERIFY(obj->setProperty("meshResolution", QSize(20, 10)));
+ QVERIFY(obj->setProperty("visible", false));
+
+ QCOMPARE(obj->property("fragmentShader").toString(), QString(qt_default_fragment_code));
+ QCOMPARE(obj->property("vertexShader").toString(), QString(qt_default_vertex_code));
+ QCOMPARE(obj->property("blending").toBool(), false);
+ QCOMPARE(obj->property("meshResolution").toSize(), QSize(20, 10));
+ QCOMPARE(obj->property("visible").toBool(), false);
+
+ delete obj;
+}
+
+void tst_qmlshadersplugin::shaderEffectSourceAPI()
+{
+ // Creation
+ QString componentStr = "import QtQuick 1.0\n"
+ "import Qt.labs.shaders 1.0\n"
+ "ShaderEffectSource {}";
+ QDeclarativeComponent shaderEffectSourceComponent(&engine);
+ shaderEffectSourceComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+
+ QObject *obj = shaderEffectSourceComponent.create();
+ QTest::qWait(100);
+ QVERIFY(obj != 0);
+
+ // Default values
+ QCOMPARE(obj->property("sourceRect").toRect(), QRect(0, 0, 0, 0));
+ QCOMPARE(obj->property("textureSize").toSize(), QSize(0, 0));
+ QCOMPARE(obj->property("live").toBool(), true);
+ QCOMPARE(obj->property("hideSource").toBool(), false);
+ QCOMPARE(obj->property("wrapMode").toUInt(), static_cast<unsigned int>(ShaderEffectSource::ClampToEdge));
+
+ // Seting the values
+ componentStr = "import QtQuick 1.0\n"
+ "Item {}";
+ QDeclarativeComponent itemComponent(&engine);
+ itemComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeItem *item = qobject_cast<QDeclarativeItem *> (itemComponent.create());
+ QVERIFY(item != 0);
+
+ QVERIFY(obj->setProperty("sourceItem", QVariant::fromValue(item)));
+ QVERIFY(obj->setProperty("sourceRect", QRect(10, 20, 30, 40)));
+ QVERIFY(obj->setProperty("textureSize", QSize(50, 100)));
+ QVERIFY(obj->setProperty("live", false));
+ QVERIFY(obj->setProperty("hideSource", true));
+ QVERIFY(obj->setProperty("wrapMode", static_cast<unsigned int>(ShaderEffectSource::Repeat)));
+
+ QCOMPARE(obj->property("sourceItem"), QVariant::fromValue(item));
+ QCOMPARE(obj->property("sourceRect").toRect(), QRect(10, 20, 30, 40));
+ QCOMPARE(obj->property("textureSize").toSize(), QSize(50, 100));
+ QCOMPARE(obj->property("live").toBool(), false);
+ QCOMPARE(obj->property("hideSource").toBool(), true);
+ QCOMPARE(obj->property("wrapMode").toUInt(), static_cast<unsigned int>(ShaderEffectSource::Repeat));
+
+ delete item;
+ delete obj;
+}
+
+void tst_qmlshadersplugin::combined()
+{
+ QGLFormat format = QGLFormat::defaultFormat();
+ format.setSampleBuffers(false);
+ format.setSwapInterval(1);
+
+ QGLWidget* glWidget = new QGLWidget(format);
+ glWidget->setAutoFillBackground(false);
+
+ QDeclarativeView view;
+ view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+ view.setAttribute(Qt::WA_OpaquePaintEvent);
+ view.setAttribute(Qt::WA_NoSystemBackground);
+ view.setViewport(glWidget);
+ view.setSource(QUrl::fromLocalFile("main.qml"));
+ view.show();
+ QTest::qWait(1000);
+
+ QObject *item = view.rootObject()->findChild<QDeclarativeItem*>("effectItem");
+ QVERIFY(item != 0);
+
+ QObject *src = view.rootObject()->findChild<QDeclarativeItem*>("effectSource");
+ QVERIFY(src != 0);
+
+ QCOMPARE(item->property("source"), QVariant::fromValue(src));
+}
+
+QTEST_MAIN(tst_qmlshadersplugin)
+
+#include "tst_qmlshadersplugin.moc"
diff --git a/tests/benchmarks/declarative/declarative.pro b/tests/benchmarks/declarative/declarative.pro
index 5dd31f3d13..51bbfaefa1 100644
--- a/tests/benchmarks/declarative/declarative.pro
+++ b/tests/benchmarks/declarative/declarative.pro
@@ -10,6 +10,6 @@ SUBDIRS += \
script \
qmltime
-contains(QT_CONFIG, opengl): SUBDIRS += painting
+contains(QT_CONFIG, opengl): SUBDIRS += painting qmlshadersplugin
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml b/tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml
new file mode 100644
index 0000000000..4424b0b03d
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/GaussianBlur.qml
@@ -0,0 +1,43 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: gaussianBlur
+ property variant source: 0
+ property real radius: 8;
+ property real deviation: Math.sqrt(-((radius+1) * (radius+1)) / (2 * Math.log(1.0 / 255.0)))
+ property bool live: true
+
+ ShaderEffectItem {
+ id: cache
+ anchors.fill: parent
+ visible: !gaussianBlur.live
+ property variant source: ShaderEffectSource { sourceItem: verticalBlur; live: false; hideSource: true }
+ }
+
+ GaussianDirectionalBlur {
+ id: verticalBlur
+ anchors.fill: parent
+
+ deltaX: 0.0
+ deltaY: 1.0/parent.height
+
+ source: ShaderEffectSource { sourceItem: horizontalBlur; hideSource: true }
+ deviation: gaussianBlur.deviation
+ radius: gaussianBlur.radius
+ }
+
+ GaussianDirectionalBlur {
+ id: horizontalBlur
+ anchors.fill: parent
+ blending: false
+
+ deltaX: 1.0/parent.width
+ deltaY: 0.0
+
+ source: gaussianBlur.source
+ deviation: gaussianBlur.deviation
+ radius: gaussianBlur.radius
+ }
+
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml
new file mode 100644
index 0000000000..33f576b439
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDirectionalBlur.qml
@@ -0,0 +1,168 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+// Note 1. This shader implements gaussian blur without dynamic array access from inside shader loops (Optional feature in OpenGLES 2.0).
+// Note 2. Shader code is generated to avoid ecessive if-else structure in fragment shader. Code re-generation (very slow!) happens if blur radius is changed.
+
+ShaderEffectItem {
+ id: effect
+ property variant source: 0
+ property real deviation: Math.sqrt(-((radius+1) * (radius+1)) / (2 * Math.log(1.0 / 255.0)));
+ property real radius: 8;
+ property real deltaX: 0.0
+ property real deltaY: 0.0
+
+ property real gaussianSum: 0.0
+ property real startIndex: 0.0
+ property real samples: radius * 2
+
+ property variant gwts: []
+ property variant delta: Qt.vector3d(effect.deltaX, effect.deltaY, effect.startIndex);
+ property variant factor_0_2: Qt.vector3d(effect.gwts[0], effect.gwts[1], effect.gwts[2]);
+ property variant factor_3_5: Qt.vector3d(effect.gwts[3],effect.gwts[4],effect.gwts[5]);
+ property variant factor_6_8: Qt.vector3d(effect.gwts[6],effect.gwts[7],effect.gwts[8]);
+ property variant factor_9_11: Qt.vector3d(effect.gwts[9],effect.gwts[10],effect.gwts[11]);
+ property variant factor_12_14: Qt.vector3d(effect.gwts[12],effect.gwts[13],effect.gwts[14]);
+ property variant factor_15_17: Qt.vector3d(effect.gwts[15],effect.gwts[16],effect.gwts[17]);
+ property variant factor_18_20: Qt.vector3d(effect.gwts[18],effect.gwts[19],effect.gwts[20]);
+ property variant factor_21_23: Qt.vector3d(effect.gwts[21],effect.gwts[22],effect.gwts[23]);
+ property variant factor_24_26: Qt.vector3d(effect.gwts[24],effect.gwts[25],effect.gwts[26]);
+ property variant factor_27_29: Qt.vector3d(effect.gwts[27],effect.gwts[28],effect.gwts[29]);
+ property variant factor_30_32: Qt.vector3d(effect.gwts[30],effect.gwts[31],effect.gwts[32]);
+
+ //Gaussian function = h(x):=(1/sqrt(2*3.14159*(D^2))) * %e^(-(x^2)/(2*(D^2)));
+ function gausFunc(x){
+ return (1/Math.sqrt(2*3.1415926*(Math.pow(effect.deviation,2)))) * Math.pow(2.7182818,-((Math.pow(x,2))/(2*(Math.pow(effect.deviation,2)))));
+ }
+
+ function calcGWTS() {
+ var n = new Array(Math.floor(effect.samples));
+ var step
+ for (var i = 0; i < effect.samples; i++) {
+ step = -effect.samples/2 + i + 0.5
+ n[i] = gausFunc(step);
+ }
+ return n;
+ }
+
+ function buildFragmentShader() {
+
+ var shaderSteps = [
+ "gl_FragColor += texture2D(source, texCoord) * factor_0_2.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_0_2.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_0_2.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_3_5.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_3_5.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_3_5.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_6_8.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_6_8.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_6_8.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_9_11.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_9_11.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_9_11.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_12_14.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_12_14.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_12_14.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_15_17.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_15_17.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_15_17.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_18_20.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_18_20.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_18_20.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_21_23.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_21_23.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_21_23.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_24_26.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_24_26.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_24_26.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_27_29.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_27_29.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_27_29.z; texCoord += shift;",
+
+ "gl_FragColor += texture2D(source, texCoord) * factor_30_32.x; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_30_32.y; texCoord += shift;",
+ "gl_FragColor += texture2D(source, texCoord) * factor_30_32.z; texCoord += shift;"
+ ]
+
+ var shader = fragmentShader_begin
+ var samples = effect.samples
+ if (samples > 32) {
+ console.log("GaussianBlur: Maximum of 32 blur samples exceeded!")
+ samples = 32
+ }
+
+ for (var i = 0; i < samples; i++) {
+ shader += shaderSteps[i]
+ }
+
+ shader += fragmentShader_end
+ effect.fragmentShader = shader
+
+ }
+
+ onDeviationChanged:{
+ effect.startIndex = -effect.samples/2 + 0.5
+ effect.gwts = calcGWTS();
+ var sum = 0.0;
+ for (var j = 0; j < effect.samples; j++) {
+ sum += effect.gwts[j];
+ }
+ effect.gaussianSum = sum
+ }
+
+ Component.onCompleted:{
+ effect.startIndex = -effect.samples/2 + 0.5
+ effect.gwts = calcGWTS();
+ var sum = 0.0;
+ for (var j = 0; j < effect.samples; j++) {
+ sum += effect.gwts[j];
+ }
+ effect.gaussianSum = sum
+ buildFragmentShader()
+ }
+
+ onSamplesChanged: {
+ buildFragmentShader()
+ }
+
+ property string fragmentShader_begin:
+ "
+ varying mediump vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform highp vec3 delta;
+ uniform highp vec3 factor_0_2;
+ uniform highp vec3 factor_3_5;
+ uniform highp vec3 factor_6_8;
+ uniform highp vec3 factor_9_11;
+ uniform highp vec3 factor_12_14;
+ uniform highp vec3 factor_15_17;
+ uniform highp vec3 factor_18_20;
+ uniform highp vec3 factor_21_23;
+ uniform highp vec3 factor_24_26;
+ uniform highp vec3 factor_27_29;
+ uniform highp vec3 factor_30_32;
+ uniform highp float gaussianSum;
+
+ void main() {
+ highp vec2 shift = vec2(delta.x, delta.y);
+ highp float index = delta.z;
+ mediump vec2 texCoord = qt_TexCoord0 + (shift * index);
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
+ "
+
+ property string fragmentShader_end:
+ "
+ if (gaussianSum > 0.0)
+ gl_FragColor /= gaussianSum;
+ }
+ "
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml
new file mode 100644
index 0000000000..be78c86c24
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/GaussianDropShadow.qml
@@ -0,0 +1,41 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: gaussianDropShadow
+
+ property color shadowColor: Qt.rgba(0.5, 0.5, 0.5, 1.0)
+ property variant source: 0
+ property real radius: 8
+ property real deviation: Math.sqrt(-((radius+1) * (radius+1)) / (2 * Math.log(1.0 / 255.0)))
+ property bool live: true
+
+ GaussianBlur {
+ id: blur
+ anchors.fill: parent
+ radius: gaussianDropShadow.radius
+ deviation: gaussianDropShadow.deviation
+ source: gaussianDropShadow.source
+ live: gaussianDropShadow.live
+ }
+
+ ShaderEffectItem {
+ id: shadow
+ property color shadowColor: gaussianDropShadow.shadowColor
+ property variant source: ShaderEffectSource { sourceItem: blur; hideSource: true }
+ anchors.fill: parent
+
+ fragmentShader:
+ "
+ varying mediump vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform lowp vec4 shadowColor;
+
+ void main() {
+ lowp vec4 sourceColor = texture2D(source, qt_TexCoord0);
+ gl_FragColor = mix(vec4(0), shadowColor, sourceColor.a);
+ }
+ "
+ }
+}
+
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml b/tests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml
new file mode 100755
index 0000000000..5843d55358
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/TestGaussianDropShadow.qml
@@ -0,0 +1,66 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: main
+ width: 360
+ height: 640
+
+ property bool liveShadows: true
+ property real r: 0
+
+ NumberAnimation on r {
+ loops: Animation.Infinite
+ from: 0
+ to: 360
+ duration: 3000
+ }
+
+ Image {
+ id: background
+ width: main.width
+ height: main.height
+ fillMode: Image.Tile
+ source: "bg.jpg"
+ }
+
+ GaussianDropShadow {
+ x: image1.x + 50
+ y: image1.y + 50
+ width: image1.width
+ height: image1.height
+ shadowColor: "#88000000"
+ source: ShaderEffectSource { sourceItem: image1; hideSource: false; sourceRect: Qt.rect(-10, -10, image1.width + 20, image1.height + 20) }
+ radius: 12.0
+ deviation: 12
+ rotation: r
+ }
+
+ Image {
+ id: image1
+ anchors.fill: parent
+ source: "drop_shadow_small.png"
+ smooth: true
+ rotation: r
+ }
+
+ GaussianDropShadow {
+ x: image2.x + 50
+ y: image2.y + 50
+ width: image2.width
+ height: image2.height
+ shadowColor: "#88000000"
+ source: ShaderEffectSource { sourceItem: image2; hideSource: false; sourceRect: Qt.rect(-10, -10, image2.width + 20, image2.height + 20) }
+ radius: 12.0
+ deviation: 12
+ rotation: -r
+ }
+
+ Image {
+ id: image2
+ anchors.fill: parent
+ source: "drop_shadow_small.png"
+ smooth: true
+ rotation: -r
+ }
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/TestWater.qml b/tests/benchmarks/declarative/qmlshadersplugin/TestWater.qml
new file mode 100755
index 0000000000..4d90950102
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/TestWater.qml
@@ -0,0 +1,20 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ width: 360
+ height: 640
+
+ Image {
+ id: image
+ width: parent.width
+ height: parent.height * 0.65
+ source: "sky.jpg"
+ smooth: true
+ }
+ Water {
+ sourceItem: image
+ intensity: 5
+ height: parent.height - image.height
+ }
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/Water.qml b/tests/benchmarks/declarative/qmlshadersplugin/Water.qml
new file mode 100644
index 0000000000..02486dd0f7
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/Water.qml
@@ -0,0 +1,85 @@
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: root
+ property alias sourceItem: effectsource.sourceItem
+ property real intensity: 1
+ property bool waving: true
+ anchors.top: sourceItem.bottom
+ width: sourceItem.width
+ height: sourceItem.height
+
+ ShaderEffectItem {
+ anchors.fill: parent
+ property variant source: effectsource
+ property real f: 0
+ property real f2: 0
+ property alias intensity: root.intensity
+ smooth: true
+
+ ShaderEffectSource {
+ id: effectsource
+ hideSource: false
+ smooth: true
+ }
+
+ fragmentShader:
+ "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ uniform lowp float qt_Opacity;
+ uniform highp float f;
+ uniform highp float f2;
+ uniform highp float intensity;
+
+ void main() {
+ const highp float twopi = 3.141592653589 * 2.0;
+
+ highp float distanceFactorToPhase = pow(qt_TexCoord0.y + 0.5, 8.0) * 5.0;
+ highp float ofx = sin(f * twopi + distanceFactorToPhase) / 100.0;
+ highp float ofy = sin(f2 * twopi + distanceFactorToPhase * qt_TexCoord0.x) / 60.0;
+
+ highp float intensityDampingFactor = (qt_TexCoord0.x + 0.1) * (qt_TexCoord0.y + 0.2);
+ highp float distanceFactor = (1.0 - qt_TexCoord0.y) * 4.0 * intensity * intensityDampingFactor;
+
+ ofx *= distanceFactor;
+ ofy *= distanceFactor;
+
+ highp float x = qt_TexCoord0.x + ofx;
+ highp float y = 1.0 - qt_TexCoord0.y + ofy;
+
+ highp float fake = (sin((ofy + ofx) * twopi) + 0.5) * 0.05 * (1.2 - qt_TexCoord0.y) * intensity * intensityDampingFactor;
+
+ highp vec4 pix =
+ texture2D(source, vec2(x, y)) * 0.6 +
+ texture2D(source, vec2(x-fake, y)) * 0.15 +
+ texture2D(source, vec2(x, y-fake)) * 0.15 +
+ texture2D(source, vec2(x+fake, y)) * 0.15 +
+ texture2D(source, vec2(x, y+fake)) * 0.15;
+
+ highp float darken = 0.6 - (ofx - ofy) / 2.0;
+ pix.b *= 1.2 * darken;
+ pix.r *= 0.9 * darken;
+ pix.g *= darken;
+
+ gl_FragColor = qt_Opacity * vec4(pix.r, pix.g, pix.b, 1.0);
+ }
+ "
+
+ NumberAnimation on f {
+ running: root.waving
+ loops: Animation.Infinite
+ from: 0
+ to: 1
+ duration: 2410
+ }
+ NumberAnimation on f2 {
+ running: root.waving
+ loops: Animation.Infinite
+ from: 0
+ to: 1
+ duration: 1754
+ }
+ }
+}
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/bg.jpg b/tests/benchmarks/declarative/qmlshadersplugin/bg.jpg
new file mode 100644
index 0000000000..4d22143810
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/bg.jpg
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.png b/tests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.png
new file mode 100755
index 0000000000..4a9b2831aa
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/drop_shadow_small.png
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro b/tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro
new file mode 100644
index 0000000000..9fb8852c68
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/qmlshadersplugin.pro
@@ -0,0 +1,23 @@
+QT += opengl declarative testlib
+
+TARGET = tst_performance
+
+SOURCES += \
+ tst_performance.cpp \
+ ../../../../src/imports/shaders/src/shadereffectitem.cpp \
+ ../../../../src/imports/shaders/src/shadereffectsource.cpp \
+ ../../../../src/imports/shaders/src/shadereffect.cpp \
+ ../../../../src/imports/shaders/src/shadereffectbuffer.cpp \
+ ../../../../src/imports/shaders/src/scenegraph/qsggeometry.cpp
+
+HEADERS += \
+ ../../../../src/imports/shaders/src/shadereffectitem.h \
+ ../../../../src/imports/shaders/src/shadereffectsource.h \
+ ../../../../src/imports/shaders/src/shadereffect.h \
+ ../../../../src/imports/shaders/src/shadereffectbuffer.h \
+ ../../../../src/imports/shaders/src/scenegraph/qsggeometry.h
+
+OTHER_FILES += \
+ *.qml \
+ *.png \
+ *.jpg
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/sky.jpg b/tests/benchmarks/declarative/qmlshadersplugin/sky.jpg
new file mode 100644
index 0000000000..8fc19ed1be
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/sky.jpg
Binary files differ
diff --git a/tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp b/tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp
new file mode 100644
index 0000000000..6ee6979aef
--- /dev/null
+++ b/tests/benchmarks/declarative/qmlshadersplugin/tst_performance.cpp
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+#include <QtDeclarative>
+#include "../../../../src/imports/shaders/src/shadereffectitem.h"
+#include "../../../../src/imports/shaders/src/shadereffectsource.h"
+//#include "../../../src/shadereffect.h"
+
+class BenchmarkItem : public QDeclarativeItem
+{
+ Q_OBJECT
+
+public:
+ BenchmarkItem( QDeclarativeItem * parent = 0 ) : QDeclarativeItem(parent)
+ , m_frameCount(0)
+ {
+ setFlag(QGraphicsItem::ItemHasNoContents, false);
+ }
+
+ void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+ QDeclarativeItem::paint(painter, option, widget);
+ if (timer.restart() > 7) m_frameCount++;
+ }
+
+ int frameCount() { return m_frameCount; }
+
+private:
+ int m_frameCount;
+ QTime timer;
+};
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QDeclarativeView view;
+ view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+ view.setAttribute(Qt::WA_OpaquePaintEvent);
+ view.setAttribute(Qt::WA_NoSystemBackground);
+ view.setResizeMode(QDeclarativeView::SizeViewToRootObject);
+
+ qmlRegisterType<ShaderEffectItem>("Qt.labs.shaders", 1, 0, "ShaderEffectItem");
+ qmlRegisterType<ShaderEffectSource>("Qt.labs.shaders", 1, 0, "ShaderEffectSource");
+
+ QGLFormat format = QGLFormat::defaultFormat();
+ format.setSampleBuffers(false);
+ format.setSwapInterval(1);
+
+ QGLWidget* glWidget = new QGLWidget(format);
+ glWidget->setAutoFillBackground(false);
+ view.setViewport(glWidget);
+ view.show();
+
+ view.setSource(QUrl::fromLocalFile("TestWater.qml"));
+ BenchmarkItem *benchmarkItem;
+
+ qDebug() << "Sea Water benchmark:";
+ benchmarkItem = new BenchmarkItem(dynamic_cast<QDeclarativeItem *>(view.rootObject()));
+ QTest::qWait(5000);
+ qDebug() << "Rendered " << benchmarkItem->frameCount() << " frames in 5 seconds";
+ qDebug() << "Average " << benchmarkItem->frameCount() / 5.0 << " frames per second";
+
+ qDebug() << "Gaussian drop shadow benchmark:";
+ view.setSource(QUrl::fromLocalFile("TestGaussianDropShadow.qml"));
+ benchmarkItem = new BenchmarkItem(dynamic_cast<QDeclarativeItem *>(view.rootObject()));
+ QTest::qWait(5000);
+ qDebug() << "Rendered " << benchmarkItem->frameCount() << " frames in 5 seconds";
+ qDebug() << "Average " << benchmarkItem->frameCount() / 5.0 << " frames per second";
+}
+
+#include "tst_performance.moc"
diff --git a/tests/manual/declarative/declarative.pro b/tests/manual/declarative/declarative.pro
new file mode 100644
index 0000000000..337db2f9c0
--- /dev/null
+++ b/tests/manual/declarative/declarative.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+contains(QT_CONFIG, opengl): SUBDIRS += qmlshadersplugin
+
diff --git a/tests/manual/declarative/qmlshadersplugin/main.cpp b/tests/manual/declarative/qmlshadersplugin/main.cpp
new file mode 100644
index 0000000000..3f40e92e23
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+#include <QtOpenGL>
+#include "qmlapplicationviewer.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QGLFormat format = QGLFormat::defaultFormat();
+ format.setSampleBuffers(false);
+ format.setSwapInterval(1);
+
+ QGLWidget* glWidget = new QGLWidget(format);
+ glWidget->setAutoFillBackground(false);
+
+ QmlApplicationViewer viewer;
+ viewer.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+ viewer.setViewport(glWidget);
+ viewer.setAttribute(Qt::WA_OpaquePaintEvent);
+ viewer.setAttribute(Qt::WA_NoSystemBackground);
+ viewer.setOrientation(QmlApplicationViewer::Auto);
+ viewer.setMainQmlFile(QLatin1String("qml/qmlshadersplugintest/main.qml"));
+ viewer.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestActive.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestActive.qml
new file mode 100644
index 0000000000..8aaee0dfcb
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestActive.qml
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "red"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ //effect.active = !effect.active
+ effect.visible = !effect.visible
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+ }
+ "
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: effect.visible ? "Effect active (display should be green)" : "Effect not active (display should be red)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBasic.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBasic.qml
new file mode 100644
index 0000000000..c7ec9084a4
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBasic.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ anchors.fill: parent;
+
+ ShaderEffectItem {
+ anchors.fill: parent;
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(qt_TexCoord0.x, qt_TexCoord0.y, 1, 1);
+ }
+ "
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlending.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlending.qml
new file mode 100644
index 0000000000..d7ce837bf0
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlending.qml
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "green"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ effect.blending = !effect.blending
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);
+ }
+ "
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: effect.blending ? "Effect blending (display should be orange)" : "Effect not blending (display should be red)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlendingModes.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlendingModes.qml
new file mode 100644
index 0000000000..bd60c68172
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestBlendingModes.qml
@@ -0,0 +1,267 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Item {
+ id: blendModeTest
+ property real blendItemHeight: 60
+
+ anchors.fill: parent;
+
+ Rectangle {
+ width: parent.width / 6
+ height: parent.height
+ color: "black"
+ }
+ Rectangle {
+ x: parent.width/6 * 1
+ width: parent.width / 6
+ height: parent.height
+ color: "white"
+ }
+ Rectangle {
+ x: parent.width/6 * 2
+ width: parent.width / 6
+ height: parent.height
+ color: "gray"
+ }
+ Rectangle {
+ x: parent.width/6 * 3
+ width: parent.width / 6
+ height: parent.height
+ color: "red"
+ }
+ Rectangle {
+ x: parent.width/6 * 4
+ width: parent.width / 6
+ height: parent.height
+ color: "green"
+ }
+ Rectangle {
+ x: parent.width/6 * 5
+ width: parent.width / 6
+ height: parent.height
+ color: "blue"
+ }
+
+
+ Image {
+ anchors.fill: parent;
+ source: "image.png"
+
+ }
+
+ Rectangle {
+ id: first
+ anchors.top: parent.top
+ anchors.topMargin: 60
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ color: "#8000ff00"
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " Rectangle color #8000ff00"
+ color: "white"
+ }
+ }
+ Rectangle {
+ id: second
+ anchors.top: first.bottom
+ anchors.topMargin: 5
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ color: "#ff00ff00"
+ opacity: 0.5
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " Rectangle color #ff00ff00, opacity 0.5"
+ color: "white"
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.top: second.bottom
+ anchors.topMargin: 5
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(0.0, 1.0, 0.0, 0.5);
+ }
+ "
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " ShaderEffectItem gl_FragColor=vec4(0.0, 1.0, 0.0, 0.5)"
+ color: "white"
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect2
+ anchors.top: effect.bottom
+ anchors.topMargin: 5
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(0.0, 0.5, 0.0, 0.5);
+ }
+ "
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " ShaderEffectItem gl_FragColor=vec4(0.0, 0.5, 0.0, 0.5)"
+ color: "white"
+ }
+ }
+
+
+ Image {
+ id: image1
+ source: "green_image_transparent.png"
+ anchors.top: effect2.bottom
+ anchors.topMargin: 5
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ }
+ Text {
+ anchors.bottom: image1.bottom
+ anchors.bottomMargin: 5
+ text: " Image, green and 50% alpha"
+ color: "white"
+ }
+
+
+ ShaderEffectItem {
+ id: effect3
+ property variant source: ShaderEffectSource {
+ sourceItem: image1
+ hideSource: false
+ }
+ anchors.top: image1.bottom
+ anchors.topMargin: 5
+
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " ShaderEffectItem, source item green 50% alpha."
+ color: "white"
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect4
+ property variant source: ShaderEffectSource {
+ sourceItem: Image { source: "green_image_transparent.png" }
+ hideSource: true
+ }
+ anchors.top: effect3.bottom
+ anchors.topMargin: 5
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " ShaderEffectItem, source image green 50% alpha."
+ color: "white"
+ }
+ }
+
+
+ Rectangle {
+ id: greenRect2
+ anchors.top: effect4.bottom
+ anchors.topMargin: 5
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ opacity: 0.5
+ color: "green"
+ }
+
+
+ ShaderEffectItem {
+ id: effect5
+ property variant source: ShaderEffectSource { sourceItem: greenRect2; hideSource: true }
+ anchors.top: effect4.bottom
+ anchors.topMargin: 5
+
+ width: parent.width
+ height: blendModeTest.blendItemHeight
+ Text {
+ anchors.bottom: parent.bottom
+ anchors.bottomMargin: 5
+ text: " ShaderEffectItem, source item green rect with 0.5 opacity."
+ color: "white"
+ }
+ }
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ }
+ }
+
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Blending test"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectHierarchy.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectHierarchy.qml
new file mode 100644
index 0000000000..e3a4c80d11
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectHierarchy.qml
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ id :root
+ anchors.fill: parent;
+ color: "green"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ effect1.visible = !effect1.visible
+ effect2.visible = !effect2.visible
+ //effect3.visible = !effect3.visible
+ }
+ }
+
+ Rectangle {
+ id: a
+ x: 90
+ y: 90
+ color: "red"
+ width: 220
+ height: 220
+ Rectangle {
+ id: b
+ x: 10
+ y: 10
+ color: "blue"
+ width: 100
+ height: 100
+ rotation: 5
+ Rectangle {
+ id: c
+ x: 10
+ y: 10
+ color: "black"
+ width: 80
+ height: 80
+ }
+ }
+ Rectangle {
+ id: d
+ x: 10
+ y: 110
+ color: "yellow"
+ width: 100
+ height: 100
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect1
+ anchors.fill: a
+ property variant source: ShaderEffectSource{ sourceItem: a; hideSource: true }
+ }
+
+ ShaderEffectItem {
+ id: effect2
+ x: 100
+ y: 100
+ width: 100
+ height: 100
+ rotation: 5
+ property variant source: ShaderEffectSource{ sourceItem: b; hideSource: true }
+ }
+
+// ShaderEffectItem {
+// id: effect3
+// x: 110
+// y: 210
+// width: 80
+// height: 80
+// property variant source: ShaderEffectSource{ sourceItem: c; hideSource: true }
+// }
+
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: effect1.visible ? "Effects active" : "Effects NOT active"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectInsideAnotherEffect.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectInsideAnotherEffect.qml
new file mode 100644
index 0000000000..ab845570e5
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestEffectInsideAnotherEffect.qml
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "green"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+
+ }
+ }
+
+ Rectangle {
+ id: theSource
+ color: "red"
+ anchors.centerIn: parent;
+ width: parent.width/2
+ height: parent.height/2
+ }
+
+ ShaderEffectItem {
+ id: effect1
+ anchors.fill: theSource;
+ property variant source: ShaderEffectSource{ sourceItem: theSource; hideSource: true }
+ }
+
+ ShaderEffectItem {
+ id: effect2
+ anchors.fill: effect1;
+ property variant source: effect1
+
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ void main(void)
+ {
+ gl_FragColor = vec4(texture2D(source, qt_TexCoord0.st).rgb, 1.0);
+ }
+ "
+ }
+
+ ShaderEffectItem {
+ id: effect3
+ x: effect2.x
+ y: effect2.y
+ width: effect2.width
+ height: effect2.height
+
+ property variant source: ShaderEffectSource { sourceItem: effect2 ; hideSource: false }
+
+ fragmentShader:
+ "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ void main(void)
+ {
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+ }
+ "
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Red rect inside green fullscreen rect."
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFormat.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFormat.qml
new file mode 100644
index 0000000000..9b1c697a03
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFormat.qml
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "gray"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (theSource.format == ShaderEffectSource.Alpha)
+ theSource.format = ShaderEffectSource.RGB
+ else if (theSource.format == ShaderEffectSource.RGB)
+ theSource.format = ShaderEffectSource.RGBA
+ else if (theSource.format == ShaderEffectSource.RGBA)
+ theSource.format = ShaderEffectSource.Alpha
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.centerIn: parent
+ width: parent.width
+ height: parent.height
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Source format test: " + theSource.format
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFragmentShader.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFragmentShader.qml
new file mode 100644
index 0000000000..0a7f261af6
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestFragmentShader.qml
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ effect.fragmentShader == effect.redFragmentShader ? effect.fragmentShader = effect.greenFragmentShader : effect.fragmentShader = effect.redFragmentShader
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+
+ property string redFragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+ }
+ "
+
+ property string greenFragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+ }
+ "
+
+ fragmentShader: redFragmentShader
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: effect.fragmentShader == effect.redFragmentShader ? "Effect (display should be red)" : "Effect (display should be green)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestGrab.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestGrab.qml
new file mode 100644
index 0000000000..6a2083529a
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestGrab.qml
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ console.log("Grabbed!")
+ theSource.grab();
+ }
+ }
+
+ Image {
+ id: theSourcImage
+ source: "image_opaque.png"
+ opacity: 0.5
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: theSourcImage
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.centerIn: parent
+ width: parent.width
+ height: parent.height
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Effect with grab (opacity 0.5)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHideOriginal.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHideOriginal.qml
new file mode 100644
index 0000000000..40277459ae
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHideOriginal.qml
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "green"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ //theSource.hideOriginal = !theSource.hideOriginal
+ theSource.hideSource = !theSource.hideSource
+ }
+ }
+
+ Rectangle {
+ id: redRect
+ anchors.fill: parent;
+ color: "red"
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: redRect
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ uniform sampler2D source;
+ void main() {
+ // Empty fragmentshader, we do not write any pixels via this effect item. We only observe hideoriginal functionality.
+ }
+ "
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ //text: theSource.hideOriginal ? "Hideoriginal true (display should be green)" : "Hideoriginal false (display should be red)"
+ text: theSource.hideSource ? "HideSource true (display should be green)" : "HideSource false (display should be red)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHorizontalWrap.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHorizontalWrap.qml
new file mode 100644
index 0000000000..92436a8aa6
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestHorizontalWrap.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ theSource.wrapMode == ShaderEffectSource.RepeatHorizontally ? theSource.wrapMode = ShaderEffectSource.ClampToEdge : theSource.wrapMode = ShaderEffectSource.RepeatHorizontally
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image_small.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ vec2 tex = qt_TexCoord0 * 4.0;
+ gl_FragColor = texture2D(source, tex);
+ }
+ "
+
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.wrapMode == ShaderEffectSource.RepeatHorizontally ? "HorizontalWrap RepeatHorizontally" : "HorizontalWrap ClampToEdge"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageFiltering.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageFiltering.qml
new file mode 100644
index 0000000000..07da7b8f98
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageFiltering.qml
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ theSource.smooth = !theSource.smooth
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ width: parent.width * 2.0
+ height: parent.height * 2.0
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: !theSource.smooth ? "Filtering nearest (faster)" : "Filtering linear (better quality)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMargins.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMargins.qml
new file mode 100644
index 0000000000..8bfafa9624
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMargins.qml
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ id: imageMarginTester
+ anchors.fill: parent;
+ color: "green"
+ property real testMarginX: 10
+ property real testMarginY: 10
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+
+ onTriggered: {
+ if (imageMarginTester.testMarginX < 20) {
+ imageMarginTester.testMarginX = 50
+ imageMarginTester.testMarginY = 120
+ }
+ else {
+ imageMarginTester.testMarginX = 10
+ imageMarginTester.testMarginY = 10
+ }
+
+ console.log("onTriggered...")
+ theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2)
+ console.log("onTriggered done")
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceImage: "image_opaque.png"
+ sourceRect: Qt.rect(-10,-10, parent.width + 2*10, parent.height + 2*10)
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.sourceRect.width == 0 ? "No margins" : "Green margins " + imageMarginTester.testMarginX + "x" + imageMarginTester.testMarginY
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMarginsWithTextureSize.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMarginsWithTextureSize.qml
new file mode 100644
index 0000000000..61f947a7ee
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMarginsWithTextureSize.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ id: marginTester
+ anchors.fill: parent;
+ color: "green"
+ property real testMarginX: 10
+ property real testMarginY: 10
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (marginTester.testMarginX < 20) {
+ marginTester.testMarginX = 50
+ marginTester.testMarginY = 120
+ }
+ else {
+ marginTester.testMarginX = 10
+ marginTester.testMarginY = 10
+ }
+
+ theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2)
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceImage: "image_opaque.png"
+ textureSize: Qt.size(160,160)
+ sourceRect: Qt.rect(-10,-10, parent.width + 2*10, parent.height + 2*10)
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.sourceRect.width == 0 ? "No margins" : "Green margins " + marginTester.testMarginX + "x" + marginTester.testMarginY
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMipmap.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMipmap.qml
new file mode 100644
index 0000000000..56b81686e2
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestImageMipmap.qml
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (theSource.mipmap && theSource.smooth){
+ theSource.smooth = false
+ } else if (theSource.mipmap && !theSource.smooth){
+ theSource.smooth = true
+ theSource.mipmap = false
+ } else if (!theSource.mipmap && theSource.smooth){
+ theSource.smooth = false
+ } else if (!theSource.mipmap && !theSource.smooth){
+ theSource.smooth = true
+ theSource.mipmap = true
+ }
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceImage: "wallpaper.jpg"
+ mipmap: false
+ smooth: false
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.centerIn: parent;
+ width: parent.width * 0.8
+ height: parent.height * 0.8
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Mipmap: " + theSource.mipmap + ", Smooth: " + theSource.smooth
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMargins.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMargins.qml
new file mode 100644
index 0000000000..26c6f57dde
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMargins.qml
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ id: marginTester
+ anchors.fill: parent;
+ color: "green"
+ property real testMarginX: 10
+ property real testMarginY: 10
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (marginTester.testMarginX < 20) {
+ marginTester.testMarginX = 50
+ marginTester.testMarginY = 120
+ }
+ else {
+ marginTester.testMarginX = 10
+ marginTester.testMarginY = 10
+ }
+
+ theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2)
+ console.log("onTriggered")
+ }
+ }
+
+ Image {
+ id: redrect
+ source: "image_opaque.png"
+ }
+
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: redrect
+ sourceRect: Qt.rect(-10,-10, parent.width + 2*10, parent.height + 2*10)
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.sourceRect.width == 0 ? "No margins" : "Green margins " + marginTester.testMarginX + "x" + marginTester.testMarginY
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml
new file mode 100644
index 0000000000..abbf8f4833
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ id: marginTester
+ anchors.fill: parent;
+ color: "green"
+ property real testMarginX: 10
+ property real testMarginY: 10
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (marginTester.testMarginX < 20) {
+ marginTester.testMarginX = 50
+ marginTester.testMarginY = 120
+ }
+ else {
+ marginTester.testMarginX = 10
+ marginTester.testMarginY = 10
+ }
+
+ theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2)
+ }
+ }
+
+ Image {
+ id: redrect
+ source: "image_opaque.png"
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: redrect
+ textureSize: Qt.size(160,160)
+ sourceRect: Qt.rect(-10,-10, parent.width + 2*10, parent.height + 2*10)
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.sourceRect.width == 0 ? "No margins" : "Green margins " + marginTester.testMarginX + "x" + marginTester.testMarginY
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestLive.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestLive.qml
new file mode 100644
index 0000000000..0d3553b561
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestLive.qml
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ theSource.live = !theSource.live
+ theSource.grab() // This tests grabbing screenshot from static source
+ }
+ }
+
+ Rectangle {
+ id: greenRect
+ anchors.fill: parent;
+ color: theSource.live ? "green" : "red" // This works if we use grab()
+ property int counter: 0
+ Text {
+ id: counterText
+ anchors.centerIn: parent
+ text: greenRect.counter
+ font.pixelSize: 48
+ }
+ Timer {
+ running: true
+ interval: 100
+ repeat: true
+ onTriggered: {
+ greenRect.counter++
+ }
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: greenRect
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.live ? "live true (color green, number changes)" : "live false (color red, same number)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestMeshResolution.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestMeshResolution.qml
new file mode 100644
index 0000000000..e8ddc61d85
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestMeshResolution.qml
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "red"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ effect.meshResolution.width == 1 ? effect.meshResolution = Qt.size(40,40) : effect.meshResolution = Qt.size(1,1)
+ }
+ }
+
+ Rectangle {
+ id: thesource
+ anchors.centerIn: parent;
+ color: "green"
+ width: parent.width
+ height: parent.height
+ Image {
+ anchors.centerIn: parent;
+ source: "image_opaque.png"
+ }
+ }
+
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: thesource;
+ property variant source: ShaderEffectSource { sourceItem: thesource }
+
+ vertexShader: "
+ attribute highp vec4 qt_Vertex;
+ attribute highp vec2 qt_MultiTexCoord0;
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ qt_TexCoord0 = qt_MultiTexCoord0;
+
+ highp vec4 shift = vec4(cos(1071. * qt_MultiTexCoord0.x + 1.0) + sin(2051. * qt_MultiTexCoord0.y + 1.0),
+ cos(1131. * qt_MultiTexCoord0.x + 1.0) + sin(3039. * qt_MultiTexCoord0.x + 1.0), 0, 0) * 3.0;
+
+ if (qt_MultiTexCoord0.x < 0.01 || qt_MultiTexCoord0.x > 0.99)
+ shift.x = 0.;
+ if (qt_MultiTexCoord0.y < 0.01 || qt_MultiTexCoord0.y > 0.99)
+ shift.y = 0.;
+
+ gl_Position = qt_ModelViewProjectionMatrix * (qt_Vertex + shift);
+ }
+ "
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: effect.meshResolution.width == 1 ? "Resolution (1,1) (image looks normal)" : "Resolution (40,40) (image looks distorted)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOneSource.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOneSource.qml
new file mode 100644
index 0000000000..8b92247a49
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOneSource.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "black"
+
+ Text {
+ id: text
+ anchors.centerIn: parent
+ font.pixelSize: 80
+ text: "Shaderz!"
+ }
+
+ ShaderEffectSource {
+ id: source
+ sourceItem: text
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ anchors.fill: text;
+
+ property variant source: source
+
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(qt_TexCoord0.x, qt_TexCoord0.y, 1, 1) * texture2D(source, qt_TexCoord0).a;
+ }
+ "
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOpacity.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOpacity.qml
new file mode 100644
index 0000000000..af5ecf75b8
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestOpacity.qml
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (effect.opacity > 0.9)
+ effect.opacity = 0.0
+ else if (effect.opacity < 0.5)
+ effect.opacity = 0.5
+ else if (effect.opacity < 0.9)
+ effect.opacity = 1.0
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image_opaque.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.centerIn: parent
+ width: parent.width
+ height: parent.height
+ property variant source: theSource
+
+ fragmentShader: "
+ uniform highp float qt_Opacity;
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(texture2D(source, qt_TexCoord0).rgb, qt_Opacity);
+ }
+ "
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Effect with opacity: " + effect.opacity
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestRotation.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestRotation.qml
new file mode 100644
index 0000000000..4262ebc7cb
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestRotation.qml
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (effectWrapper.rotation < 45)
+ effectWrapper.rotation = 45
+ else if (effectWrapper.rotation < 90)
+ effectWrapper.rotation = 90
+ else if (effectWrapper.rotation < 180)
+ effectWrapper.rotation = 0
+
+ }
+ }
+
+ Item {
+ id: effectWrapper
+ anchors.fill: parent;
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image_opaque.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.centerIn: parent
+ width: parent.width - 50
+ height: parent.height - 50
+ property variant source: theSource
+ }
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Effect is rotated " + effectWrapper.rotation + " degrees"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestScale.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestScale.qml
new file mode 100644
index 0000000000..b60747c80c
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestScale.qml
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ if (effectWrapper.scale < 0.3)
+ effectWrapper.scale = 0.3
+ else if (effectWrapper.scale < 1.7)
+ effectWrapper.scale = 1.7
+ else if (effectWrapper.scale < 2.0)
+ effectWrapper.scale = 0.1
+ }
+ }
+
+ Item {
+ id: effectWrapper
+ anchors.fill: parent;
+ scale: 0.1
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image_opaque.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.centerIn: parent
+ width: parent.width - 50
+ height: parent.height - 50
+ property variant source: theSource
+ }
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "Effect is scaled " + effectWrapper.scale
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTextureSize.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTextureSize.qml
new file mode 100644
index 0000000000..5ca08cbd4f
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTextureSize.qml
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ theSource.textureSize.width == 64 ? theSource.textureSize = Qt.size(360,640) : theSource.textureSize = Qt.size(64,64)
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image.png" }
+ live: false
+ textureSize: Qt.size(64,64)
+ smooth: true
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: "textureSize:" + theSource.textureSize.width + "x" + theSource.textureSize.height
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwiceOnSameSource.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwiceOnSameSource.qml
new file mode 100644
index 0000000000..e84b84ba66
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwiceOnSameSource.qml
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "black"
+
+ Text {
+ id: text
+ anchors.centerIn: parent
+ font.pixelSize: 80
+ text: "Shaderz!"
+ }
+
+ ShaderEffectSource {
+ id: source
+ sourceItem: text
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ width: parent.width
+ height: parent.height / 2
+ blending: false
+
+ property variant source: source
+
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(0, qt_TexCoord0.y, 1, 1) * texture2D(source, qt_TexCoord0).a;
+ }
+ "
+ }
+
+ ShaderEffectItem {
+ width: parent.width
+ y: parent.height / 2
+ height: parent.height / 2
+
+ property variant source: source
+
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(qt_TexCoord0.x, 1, 0, 1) * texture2D(source, qt_TexCoord0).a;
+ }
+ "
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwoSources.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwoSources.qml
new file mode 100644
index 0000000000..c8f12af96f
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestTwoSources.qml
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "black"
+
+ Rectangle {
+ id: rect;
+ anchors.centerIn: parent
+ width: 1
+ height: 10
+
+ gradient: Gradient {
+ GradientStop { position: 0; color: "#ff0000" }
+ GradientStop { position: 0.5; color: "#00ff00" }
+ GradientStop { position: 1; color: "#0000ff" }
+ }
+ }
+
+ Text {
+ id: text
+ anchors.centerIn: parent
+ font.pixelSize: 80
+ text: "Shaderz!"
+ }
+
+ ShaderEffectSource {
+ id: maskSource
+ sourceItem: text
+ hideSource: true
+ }
+
+ ShaderEffectSource {
+ id: colorSource
+ sourceItem: rect;
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ anchors.fill: text;
+
+ property variant colorSource: colorSource
+ property variant maskSource: maskSource;
+
+ fragmentShader: "
+ uniform lowp sampler2D maskSource;
+ uniform lowp sampler2D colorSource;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = texture2D(maskSource, qt_TexCoord0).a * texture2D(colorSource, qt_TexCoord0.yx);
+ }
+ "
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVertexShader.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVertexShader.qml
new file mode 100644
index 0000000000..0e122574af
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVertexShader.qml
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "red"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ effect.vertexShader == effect.defaultVertexShader ? effect.vertexShader = effect.dummyVertexShader : effect.vertexShader = effect.defaultVertexShader
+ }
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+
+ property string defaultVertexShader: "
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ attribute highp vec4 qt_Vertex;
+ attribute highp vec2 qt_MultiTexCoord0;
+ varying highp vec2 qt_TexCoord0;
+ void main(void)
+ {
+ qt_TexCoord0 = qt_MultiTexCoord0;
+ gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
+ };
+ "
+
+ property string dummyVertexShader: "
+ uniform highp mat4 qt_ModelViewProjectionMatrix;
+ attribute highp vec4 qt_Vertex;
+ attribute highp vec2 qt_MultiTexCoord0;
+ varying highp vec2 qt_TexCoord0;
+ void main(void)
+ {
+ qt_TexCoord0 = qt_MultiTexCoord0;
+ gl_Position = qt_Vertex * vec4(0.0, 0.0, 0.0, 0.0001);
+ };
+ "
+
+ vertexShader: defaultVertexShader
+
+ fragmentShader: "
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+ }
+ "
+
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: effect.vertexShader == effect.defaultVertexShader ? "Effect (display shoud be green)" : "Effect (display shoud be red)"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVerticalWrap.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVerticalWrap.qml
new file mode 100644
index 0000000000..96171efa06
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestVerticalWrap.qml
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ theSource.wrapMode == ShaderEffectSource.RepeatVertically ? theSource.wrapMode = ShaderEffectSource.ClampToEdge : theSource.wrapMode = ShaderEffectSource.RepeatVertically
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image_small.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ vec2 tex = qt_TexCoord0 * 4.0;
+ gl_FragColor = texture2D(source, tex);
+ }
+ "
+
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.wrapMode == ShaderEffectSource.RepeatVertically ? "Wrap RepeatVertically" : "VerticalWrap ClampToEdge"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestWrapRepeat.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestWrapRepeat.qml
new file mode 100644
index 0000000000..35f6b92a06
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/TestWrapRepeat.qml
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+import Qt 4.7
+import Qt.labs.shaders 1.0
+
+Rectangle {
+ anchors.fill: parent;
+ color: "white"
+
+ Timer {
+ running: true
+ interval: 2000
+ repeat: true
+ onTriggered: {
+ theSource.wrapMode == ShaderEffectSource.Repeat ? theSource.wrapMode = ShaderEffectSource.ClampToEdge : theSource.wrapMode = ShaderEffectSource.Repeat
+ }
+ }
+
+ ShaderEffectSource {
+ id: theSource
+ sourceItem: Image { source: "image_small.png" }
+ live: false
+ hideSource: true
+ }
+
+ ShaderEffectItem {
+ id: effect
+ anchors.fill: parent;
+ property variant source: theSource
+ fragmentShader: "
+ uniform lowp sampler2D source;
+ varying highp vec2 qt_TexCoord0;
+ void main() {
+ vec2 tex = qt_TexCoord0 * 4.0;
+ gl_FragColor = texture2D(source, tex);
+ }
+ "
+
+ }
+
+ Rectangle {
+ width: parent.width
+ height: 40
+ color: "#cc000000"
+
+ Text {
+ id: label
+ anchors.centerIn: parent
+ text: theSource.wrapMode == ShaderEffectSource.Repeat ? "Wrap Repeat" : "Wrap ClampToEdge"
+ color: "white"
+ font.bold: true
+ }
+ }
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/back.svg b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/back.svg
new file mode 100755
index 0000000000..3005133b8e
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/back.svg
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ width="30px" height="30px" viewBox="0 0 30 30" enable-background="new 0 0 30 30" xml:space="preserve">
+<rect fill="none" width="30" height="30"/>
+<path fill="#FFFFFF" d="M19,8h-9V5c0-0.389-0.225-0.74-0.576-0.906C9.289,4.031,9.145,4,9,4C8.771,4,8.543,4.079,8.359,4.231
+ l-6,5.001C2.132,9.422,2,9.703,2,10s0.132,0.578,0.359,0.768l6,5C8.543,15.921,8.771,16,9,16c0.145,0,0.289-0.031,0.424-0.094
+ C9.775,15.741,10,15.389,10,15v-3h9c2.757,0,5,2.243,5,5s-2.243,5-5,5h-6.917c-1.104,0-2,0.896-2,2s0.896,2,2,2H19
+ c4.963,0,9-4.037,9-9S23.963,8,19,8z"/>
+</svg>
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/green_image_transparent.png b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/green_image_transparent.png
new file mode 100755
index 0000000000..f3024f7eeb
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/green_image_transparent.png
Binary files differ
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image.png b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image.png
new file mode 100755
index 0000000000..144c02d548
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image.png
Binary files differ
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_opaque.png b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_opaque.png
new file mode 100755
index 0000000000..c73d38927e
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_opaque.png
Binary files differ
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_small.png b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_small.png
new file mode 100755
index 0000000000..b2267737fd
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/image_small.png
Binary files differ
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/main.qml b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/main.qml
new file mode 100644
index 0000000000..2a857a9f56
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/main.qml
@@ -0,0 +1,236 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QML Shaders plugin of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+
+Item {
+ id: main
+ width: 360
+ height: 640
+
+ Rectangle {
+ id: background
+ visible: testCaseList.visible
+ anchors.fill: parent
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: "#EEEEEE" }
+ GradientStop { position: 1.0; color: "#AAAAAA" }
+ }
+ }
+
+ Loader {
+ id: testLoader
+ width: parent.width
+ height: parent.height
+ visible: !testCaseList.visible
+ }
+
+ ListModel {
+ id: testcaseModel
+ ListElement { name: "TestEffectHierarchy.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestGrab.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestLive.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestImageFiltering.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestWrapRepeat.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestHorizontalWrap.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestVerticalWrap.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestTextureSize.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestItemMargins.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestEffectInsideAnotherEffect.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestItemMarginsWithTextureSize.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestHideOriginal.qml"; group: "Effect source property tests" }
+ ListElement { name: "TestActive.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestBlending.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestBlendingModes.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestOpacity.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestFragmentShader.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestVertexShader.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestMeshResolution.qml"; group: "Effect item property tests" }
+ ListElement { name: "TestRotation.qml"; group: "Shader effect transformation tests" }
+ ListElement { name: "TestScale.qml"; group: "Shader effect transformation tests" }
+ ListElement { name: "TestBasic.qml"; group: "Scenegraph effect tests" }
+ ListElement { name: "TestOneSource.qml"; group: "Scenegraph effect tests" }
+ ListElement { name: "TestTwiceOnSameSource.qml"; group: "Scenegraph effect tests" }
+ ListElement { name: "TestTwoSources.qml"; group: "Scenegraph effect tests" }
+ }
+
+ Component {
+ id: sectionHeading
+ Rectangle {
+ width: testCaseList.width
+ height: 35
+ color: "#00000000"
+
+ Text {
+ text: section
+ verticalAlignment: Text.AlignVCenter
+ horizontalAlignment: Text.AlignLeft
+ anchors.fill: parent
+ anchors.leftMargin: 5
+ font.bold: true
+ style: Text.Raised
+ styleColor: "white"
+ }
+ }
+ }
+
+ ListView {
+ id: testCaseList
+
+ property int hideTranslation: 0
+ transform: Translate {
+ x: testCaseList.hideTranslation
+ }
+
+ anchors.fill: parent
+ anchors.topMargin: 10
+ anchors.leftMargin: 5
+ anchors.rightMargin: 5
+ anchors.bottomMargin: 10
+
+ model: testcaseModel
+ spacing: 3
+
+ state: "testStopped"
+
+ section.property: "group"
+ section.criteria: ViewSection.FullString
+ section.delegate: sectionHeading
+
+ delegate: Rectangle {
+ width: parent.width
+ height: 50
+ radius: 5
+ border.width: 1
+ border.color: "#888888"
+ color: delegateMouseArea.pressed ? "#AAAAFF" : "#FFFFFF"
+ Text {
+ id: delegateText;
+ text: " " + name
+ width: parent.width
+ height: parent.height
+ font.pixelSize: 16
+ verticalAlignment: Text.AlignVCenter
+ }
+ Text {
+ id: delegateText2;
+ text: "> "
+ width: parent.width
+ height: parent.height
+ font.pixelSize: 20
+ smooth: true
+ color: "gray"
+ verticalAlignment: Text.AlignVCenter
+ horizontalAlignment: Text.AlignRight
+ }
+
+ MouseArea {
+ id: delegateMouseArea
+ anchors.fill: parent;
+ onClicked: {
+ testCaseList.state = "testRunning"
+ testLoader.source = name
+ console.log(name)
+ }
+ }
+ }
+
+ states: [
+ State {
+ name: "testRunning"
+ PropertyChanges { target: testCaseList; visible: false; hideTranslation: -main.width }
+ },
+ State {
+ name: "testStopped"
+ PropertyChanges { target: testCaseList; visible: true; hideTranslation: 0 }
+ }
+ ]
+
+ transitions: [
+ Transition {
+ to: "testRunning"
+ SequentialAnimation {
+ NumberAnimation { properties: "hideTranslation"; easing.type: Easing.InQuad; duration: 300 }
+ PropertyAction { target: testCaseList; property: "visible"; value: false }
+ }
+ },
+ Transition {
+ to: "testStopped"
+ SequentialAnimation {
+ PropertyAction { target: testCaseList; property: "visible"; value: true }
+ NumberAnimation { properties: "hideTranslation"; easing.type: Easing.InQuad; duration: 300 }
+ }
+ }
+
+ ]
+ }
+
+ Rectangle {
+ visible: true
+ anchors.bottom: main.bottom
+ anchors.left: main.left
+ anchors.right: main.right
+ height: 40
+ color: "#cc000000"
+ Item {
+ anchors.top: parent.top
+ anchors.topMargin: 5
+ anchors.left: parent.left
+ anchors.leftMargin: 20
+ Image {
+ source: "back.svg"
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent;
+ onClicked: {
+ if (testCaseList.visible){
+ Qt.quit()
+ } else if (!testCaseList.state != "testStopped") {
+ testCaseList.state = "testStopped"
+ testLoader.source = ""
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/wallpaper.jpg b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/wallpaper.jpg
new file mode 100755
index 0000000000..5bc7b58550
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qml/qmlshadersplugintest/wallpaper.jpg
Binary files differ
diff --git a/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.cpp b/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.cpp
new file mode 100644
index 0000000000..51b5fcc835
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.cpp
@@ -0,0 +1,127 @@
+// checksum 0xdf1f version 0x10008
+#include "qmlapplicationviewer.h"
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDir>
+#include <QtCore/QFileInfo>
+#include <QtDeclarative/QDeclarativeComponent>
+#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeContext>
+
+#if defined(QMLJSDEBUGGER)
+#include <jsdebuggeragent.h>
+#endif
+#if defined(QMLOBSERVER)
+#include <qdeclarativeviewobserver.h>
+#endif
+
+#if defined(Q_OS_SYMBIAN) && defined(ORIENTATIONLOCK)
+#include <eikenv.h>
+#include <eikappui.h>
+#include <aknenv.h>
+#include <aknappui.h>
+#endif // Q_OS_SYMBIAN && ORIENTATIONLOCK
+
+class QmlApplicationViewerPrivate
+{
+ QString mainQmlFile;
+ friend class QmlApplicationViewer;
+ static QString adjustPath(const QString &path);
+};
+
+QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
+{
+#ifdef Q_OS_UNIX
+#ifdef Q_OS_MAC
+ if (!QDir::isAbsolutePath(path))
+ return QCoreApplication::applicationDirPath()
+ + QLatin1String("/../Resources/") + path;
+#else
+ const QString pathInShareDir = QCoreApplication::applicationDirPath()
+ + QLatin1String("/../share/")
+ + QFileInfo(QCoreApplication::applicationFilePath()).fileName()
+ + QLatin1Char('/') + path;
+ if (QFileInfo(pathInShareDir).exists())
+ return pathInShareDir;
+#endif
+#endif
+ return path;
+}
+
+QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) :
+ QDeclarativeView(parent),
+ m_d(new QmlApplicationViewerPrivate)
+{
+ connect(engine(), SIGNAL(quit()), SLOT(close()));
+ setResizeMode(QDeclarativeView::SizeRootObjectToView);
+#ifdef QMLJSDEBUGGER
+ new QmlJSDebugger::JSDebuggerAgent(engine());
+#endif
+#ifdef QMLOBSERVER
+ new QmlJSDebugger::QDeclarativeViewObserver(this, parent);
+#endif
+}
+
+QmlApplicationViewer::~QmlApplicationViewer()
+{
+ delete m_d;
+}
+
+void QmlApplicationViewer::setMainQmlFile(const QString &file)
+{
+ m_d->mainQmlFile = QmlApplicationViewerPrivate::adjustPath(file);
+ setSource(QUrl::fromLocalFile(m_d->mainQmlFile));
+}
+
+void QmlApplicationViewer::addImportPath(const QString &path)
+{
+ engine()->addImportPath(QmlApplicationViewerPrivate::adjustPath(path));
+}
+
+void QmlApplicationViewer::setOrientation(Orientation orientation)
+{
+#ifdef Q_OS_SYMBIAN
+ if (orientation != Auto) {
+#if defined(ORIENTATIONLOCK)
+ const CAknAppUiBase::TAppUiOrientation uiOrientation =
+ (orientation == LockPortrait) ? CAknAppUi::EAppUiOrientationPortrait
+ : CAknAppUi::EAppUiOrientationLandscape;
+ CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
+ TRAPD(error,
+ if (appUi)
+ appUi->SetOrientationL(uiOrientation);
+ );
+#else // ORIENTATIONLOCK
+ qWarning("'ORIENTATIONLOCK' needs to be defined on Symbian when locking the orientation.");
+#endif // ORIENTATIONLOCK
+ }
+#elif defined(Q_WS_MAEMO_5)
+ Qt::WidgetAttribute attribute;
+ switch (orientation) {
+ case LockPortrait:
+ attribute = Qt::WA_Maemo5PortraitOrientation;
+ break;
+ case LockLandscape:
+ attribute = Qt::WA_Maemo5LandscapeOrientation;
+ break;
+ case Auto:
+ default:
+ attribute = Qt::WA_Maemo5AutoOrientation;
+ break;
+ }
+ setAttribute(attribute, true);
+#else // Q_OS_SYMBIAN
+ Q_UNUSED(orientation);
+#endif // Q_OS_SYMBIAN
+}
+
+void QmlApplicationViewer::show()
+{
+#ifdef Q_OS_SYMBIAN
+ showFullScreen();
+#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
+ showMaximized();
+#else
+ QDeclarativeView::show();
+#endif
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.h b/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.h
new file mode 100644
index 0000000000..ea784310cf
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.h
@@ -0,0 +1,28 @@
+// checksum 0x39ee version 0x10008
+#ifndef QMLAPPLICATIONVIEWER_H
+#define QMLAPPLICATIONVIEWER_H
+
+#include <QtDeclarative/QDeclarativeView>
+
+class QmlApplicationViewer : public QDeclarativeView
+{
+public:
+ enum Orientation {
+ LockPortrait,
+ LockLandscape,
+ Auto
+ };
+
+ QmlApplicationViewer(QWidget *parent = 0);
+ virtual ~QmlApplicationViewer();
+
+ void setMainQmlFile(const QString &file);
+ void addImportPath(const QString &path);
+ void setOrientation(Orientation orientation);
+ void show();
+
+private:
+ class QmlApplicationViewerPrivate *m_d;
+};
+
+#endif // QMLAPPLICATIONVIEWER_H
diff --git a/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.pri b/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.pri
new file mode 100644
index 0000000000..79e6a9f820
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qmlapplicationviewer/qmlapplicationviewer.pri
@@ -0,0 +1,152 @@
+# checksum 0xc123 version 0x10008
+# This file should not be edited.
+# Future versions of Qt Creator might offer updated versions of this file.
+
+QT += declarative
+
+SOURCES += $$PWD/qmlapplicationviewer.cpp
+HEADERS += $$PWD/qmlapplicationviewer.h
+INCLUDEPATH += $$PWD
+
+contains(DEFINES, QMLOBSERVER) {
+ DEFINES *= QMLJSDEBUGGER
+}
+
+defineTest(minQtVersion) {
+ maj = $$1
+ min = $$2
+ patch = $$3
+ isEqual(QT_MAJOR_VERSION, $$maj) {
+ isEqual(QT_MINOR_VERSION, $$min) {
+ isEqual(QT_PATCH_VERSION, $$patch) {
+ return(true)
+ }
+ greaterThan(QT_PATCH_VERSION, $$patch) {
+ return(true)
+ }
+ }
+ greaterThan(QT_MINOR_VERSION, $$min) {
+ return(true)
+ }
+ }
+ return(false)
+}
+
+contains(DEFINES, QMLJSDEBUGGER) {
+ CONFIG(debug, debug|release) {
+ !minQtVersion(4, 7, 1) {
+ warning()
+ warning("Debugging QML requires the qmljsdebugger library that ships with Qt Creator.")
+ warning("This library requires Qt 4.7.1 or newer.")
+ warning()
+
+ error("Qt version $$QT_VERSION too old for QmlJS Debugging. Aborting.")
+ }
+ isEmpty(QMLJSDEBUGGER_PATH) {
+ warning()
+ warning("Debugging QML requires the qmljsdebugger library that ships with Qt Creator.")
+ warning("Please specify its location on the qmake command line, eg")
+ warning(" qmake -r QMLJSDEBUGGER_PATH=$CREATORDIR/share/qtcreator/qmljsdebugger")
+ warning()
+
+ error("QMLJSDEBUGGER defined, but no QMLJSDEBUGGER_PATH set on command line. Aborting.")
+ DEFINES -= QMLJSDEBUGGER
+ } else {
+ include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri)
+ }
+ } else {
+ DEFINES -= QMLJSDEBUGGER
+ }
+}
+# This file should not be edited.
+# Future versions of Qt Creator might offer updated versions of this file.
+
+defineTest(qtcAddDeployment) {
+for(deploymentfolder, DEPLOYMENTFOLDERS) {
+ item = item$${deploymentfolder}
+ itemsources = $${item}.sources
+ $$itemsources = $$eval($${deploymentfolder}.source)
+ itempath = $${item}.path
+ $$itempath= $$eval($${deploymentfolder}.target)
+ export($$itemsources)
+ export($$itempath)
+ DEPLOYMENT += $$item
+}
+
+MAINPROFILEPWD = $$PWD
+
+symbian {
+ ICON = $${TARGET}.svg
+ TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
+ contains(DEFINES, ORIENTATIONLOCK):LIBS += -lavkon -leikcore -leiksrv -lcone
+ contains(DEFINES, NETWORKACCESS):TARGET.CAPABILITY += NetworkServices
+} else:win32 {
+ !isEqual(PWD,$$OUT_PWD) {
+ copyCommand = @echo Copying application data...
+ for(deploymentfolder, DEPLOYMENTFOLDERS) {
+ source = $$eval($${deploymentfolder}.source)
+ pathSegments = $$split(source, /)
+ sourceAndTarget = $$MAINPROFILEPWD/$$source $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(pathSegments)
+ copyCommand += && $(COPY_DIR) $$replace(sourceAndTarget, /, \\)
+ }
+ copydeploymentfolders.commands = $$copyCommand
+ first.depends = $(first) copydeploymentfolders
+ export(first.depends)
+ export(copydeploymentfolders.commands)
+ QMAKE_EXTRA_TARGETS += first copydeploymentfolders
+ }
+} else:unix {
+ maemo5 {
+ installPrefix = /opt/usr
+ desktopfile.path = /usr/share/applications/hildon
+ } else {
+ installPrefix = /usr/local
+ desktopfile.path = /usr/share/applications
+ !isEqual(PWD,$$OUT_PWD) {
+ copyCommand = @echo Copying application data...
+ for(deploymentfolder, DEPLOYMENTFOLDERS) {
+ macx {
+ target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target)
+ } else {
+ target = $$OUT_PWD/$$eval($${deploymentfolder}.target)
+ }
+ copyCommand += && $(MKDIR) $$target
+ copyCommand += && $(COPY_DIR) $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) $$target
+ }
+ copydeploymentfolders.commands = $$copyCommand
+ first.depends = $(first) copydeploymentfolders
+ export(first.depends)
+ export(copydeploymentfolders.commands)
+ QMAKE_EXTRA_TARGETS += first copydeploymentfolders
+ }
+ }
+ for(deploymentfolder, DEPLOYMENTFOLDERS) {
+ item = item$${deploymentfolder}
+ itemfiles = $${item}.files
+ $$itemfiles = $$eval($${deploymentfolder}.source)
+ itempath = $${item}.path
+ $$itempath = $${installPrefix}/share/$${TARGET}/$$eval($${deploymentfolder}.target)
+ export($$itemfiles)
+ export($$itempath)
+ INSTALLS += $$item
+ }
+ icon.files = $${TARGET}.png
+ icon.path = /usr/share/icons/hicolor/64x64/apps
+ desktopfile.files = $${TARGET}.desktop
+ target.path = $${installPrefix}/bin
+ export(icon.files)
+ export(icon.path)
+ export(desktopfile.files)
+ export(desktopfile.path)
+ export(target.path)
+ INSTALLS += desktopfile icon target
+}
+
+export (ICON)
+export (INSTALLS)
+export (DEPLOYMENT)
+export (TARGET.EPOCHEAPSIZE)
+export (TARGET.CAPABILITY)
+export (LIBS)
+export (QMAKE_EXTRA_TARGETS)
+}
diff --git a/tests/manual/declarative/qmlshadersplugin/qmlshadersplugin.pro b/tests/manual/declarative/qmlshadersplugin/qmlshadersplugin.pro
new file mode 100644
index 0000000000..98101fb641
--- /dev/null
+++ b/tests/manual/declarative/qmlshadersplugin/qmlshadersplugin.pro
@@ -0,0 +1,29 @@
+QT += declarative opengl
+
+# Add more folders to ship with the application, here
+folder_01.source = qml/qmlshadersplugintest
+folder_01.target = qml
+DEPLOYMENTFOLDERS = folder_01
+
+# Additional import path used to resolve Qml modules in Creator's code model
+QML_IMPORT_PATH =
+
+# Avoid auto screen rotation
+#DEFINES += ORIENTATIONLOCK
+
+# Needs to be defined for Symbian
+#DEFINES += NETWORKACCESS
+
+symbian:TARGET.UID3 = 0xE40472A7
+
+# Define QMLJSDEBUGGER to enable basic debugging (setting breakpoints etc)
+# Define QMLOBSERVER for advanced features (requires experimental QmlInspector plugin!)
+#DEFINES += QMLJSDEBUGGER
+#DEFINES += QMLOBSERVER
+
+# The .cpp file which was generated for your project. Feel free to hack it.
+SOURCES += main.cpp
+
+# Please do not modify the following two lines. Required for deployment.
+include(qmlapplicationviewer/qmlapplicationviewer.pri)
+qtcAddDeployment()