/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmAddTestCommand.h" #include #include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmStringAlgorithms.h" #include "cmTest.h" #include "cmTestGenerator.h" static bool cmAddTestCommandHandleNameMode( std::vector const& args, cmExecutionStatus& status); bool cmAddTestCommand(std::vector const& args, cmExecutionStatus& status) { if (!args.empty() && args[0] == "NAME") { return cmAddTestCommandHandleNameMode(args, status); } // First argument is the name of the test Second argument is the name of // the executable to run (a target or external program) Remaining arguments // are the arguments to pass to the executable if (args.size() < 2) { status.SetError("called with incorrect number of arguments"); return false; } cmMakefile& mf = status.GetMakefile(); // Collect the command with arguments. std::vector command(args.begin() + 1, args.end()); // Create the test but add a generator only the first time it is // seen. This preserves behavior from before test generators. cmTest* test = mf.GetTest(args[0]); if (test) { // If the test was already added by a new-style signature do not // allow it to be duplicated. if (!test->GetOldStyle()) { status.SetError(cmStrCat(" given test name \"", args[0], "\" which already exists in this directory.")); return false; } } else { test = mf.CreateTest(args[0]); test->SetOldStyle(true); mf.AddTestGenerator(cm::make_unique(test)); } test->SetCommand(command); return true; } bool cmAddTestCommandHandleNameMode(std::vector const& args, cmExecutionStatus& status) { std::string name; std::vector configurations; std::string working_directory; std::vector command; bool command_expand_lists = false; // Read the arguments. enum Doing { DoingName, DoingCommand, DoingConfigs, DoingWorkingDirectory, DoingNone }; Doing doing = DoingName; for (unsigned int i = 1; i < args.size(); ++i) { if (args[i] == "COMMAND") { if (!command.empty()) { status.SetError(" may be given at most one COMMAND."); return false; } doing = DoingCommand; } else if (args[i] == "CONFIGURATIONS") { if (!configurations.empty()) { status.SetError(" may be given at most one set of CONFIGURATIONS."); return false; } doing = DoingConfigs; } else if (args[i] == "WORKING_DIRECTORY") { if (!working_directory.empty()) { status.SetError(" may be given at most one WORKING_DIRECTORY."); return false; } doing = DoingWorkingDirectory; } else if (args[i] == "COMMAND_EXPAND_LISTS") { if (command_expand_lists) { status.SetError(" may be given at most one COMMAND_EXPAND_LISTS."); return false; } command_expand_lists = true; doing = DoingNone; } else if (doing == DoingName) { name = args[i]; doing = DoingNone; } else if (doing == DoingCommand) { command.push_back(args[i]); } else if (doing == DoingConfigs) { configurations.push_back(args[i]); } else if (doing == DoingWorkingDirectory) { working_directory = args[i]; doing = DoingNone; } else { status.SetError(cmStrCat(" given unknown argument:\n ", args[i], "\n")); return false; } } // Require a test name. if (name.empty()) { status.SetError(" must be given non-empty NAME."); return false; } // Require a command. if (command.empty()) { status.SetError(" must be given non-empty COMMAND."); return false; } cmMakefile& mf = status.GetMakefile(); // Require a unique test name within the directory. if (mf.GetTest(name)) { status.SetError(cmStrCat(" given test NAME \"", name, "\" which already exists in this directory.")); return false; } // Add the test. cmTest* test = mf.CreateTest(name); test->SetOldStyle(false); test->SetCommand(command); if (!working_directory.empty()) { test->SetProperty("WORKING_DIRECTORY", working_directory); } test->SetCommandExpandLists(command_expand_lists); mf.AddTestGenerator(cm::make_unique(test, configurations)); return true; } n results should have all configurations every time + //QCOMPARE(thread.preScanConfigs, preScanConfigs); +#endif +} QTEST_MAIN(tst_QNetworkConfigurationManager) #include "tst_qnetworkconfigurationmanager.moc" diff --git a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index 954b369..c56fedb 100644 --- a/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -41,14 +41,17 @@ #include +#include #include #include #include +#include class tst_QNetworkProxyFactory : public QObject { Q_OBJECT private slots: + void systemProxyForQueryCalledFromThread(); void systemProxyForQuery() const; private: @@ -96,5 +99,31 @@ void tst_QNetworkProxyFactory::systemProxyForQuery() const QFAIL("One or more system proxy lookup failures occurred."); } +class QSPFQThread : public QThread +{ +protected: + virtual void run() + { + proxies = QNetworkProxyFactory::systemProxyForQuery(query); + } +public: + QNetworkProxyQuery query; + QList proxies; +}; + +//regression test for QTBUG-18799 +void tst_QNetworkProxyFactory::systemProxyForQueryCalledFromThread() +{ + QUrl url(QLatin1String("http://qt.nokia.com")); + QNetworkProxyQuery query(url); + QSPFQThread thread; + thread.query = query; + connect(&thread, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + thread.start(); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(thread.isFinished()); + QCOMPARE(thread.proxies, QNetworkProxyFactory::systemProxyForQuery(query)); +} + QTEST_MAIN(tst_QNetworkProxyFactory) #include "tst_qnetworkproxyfactory.moc" -- cgit v0.12 From 5f879c55e531165cc2569b03c3796d0f33d0a0b7 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 1 Jun 2011 16:35:43 +0100 Subject: bearer: run the bearer engines in their own worker thread The original architecture of the QtNetwork bearer support hosted the engines in the application's main thread, but this causes some problems. If the QNetworkConfigurationManager is constructed in a worker thread, then it is populated asynchronously without any notification when it is done (the app gets incomplete or missing results) Fixing that by restoring the earlier behaviour of using blocking queued connections to wait for the lists to be populated caused a regression, as some applications deadlock because the main thread is waiting on the worker thread at this time. By introducing a dedicated worker thread for the bearer engines, QNetworkConfigurationManager can be safely constructed in any thread while using blocking queued connections internally. Task-number: QTBUG-18795 Reviewed-by: mread --- src/network/bearer/qnetworkconfigmanager.cpp | 4 +-- src/network/bearer/qnetworkconfigmanager_p.cpp | 36 ++++++++++++++++---------- src/network/bearer/qnetworkconfigmanager_p.h | 3 +++ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 65a15d7..d2c7317 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC_INIT(TYPE, NAME); \ static void NAME##_cleanup() \ { \ - delete this_##NAME.pointer; \ + this_##NAME.pointer->cleanup(); \ this_##NAME.pointer = 0; \ } \ static TYPE *NAME() \ @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE delete x; \ else { \ qAddPostRoutine(NAME##_cleanup); \ - this_##NAME.pointer->updateConfigurations(); \ + this_##NAME.pointer->initialize(); \ } \ } \ return this_##NAME.pointer; \ diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 2391a34..17e47bd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -66,11 +66,31 @@ QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate() qRegisterMetaType("QNetworkConfigurationPrivatePointer"); } +void QNetworkConfigurationManagerPrivate::initialize() +{ + //Two stage construction, because we only want to do this heavyweight work for the winner of the Q_GLOBAL_STATIC race. + bearerThread = new QThread(); + bearerThread->moveToThread(QCoreApplicationPrivate::mainThread()); // because cleanup() is called in main thread context. + moveToThread(bearerThread); + bearerThread->start(); + updateConfigurations(); +} + QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() { QMutexLocker locker(&mutex); qDeleteAll(sessionEngines); + if (bearerThread) + bearerThread->quit(); +} + +void QNetworkConfigurationManagerPrivate::cleanup() +{ + QThread* thread = bearerThread; + deleteLater(); + if(thread->wait(5000)) + delete thread; } QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() @@ -356,13 +376,6 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (sender()) return; - if (thread() != QCoreApplicationPrivate::mainThread()) { - if (thread() != QThread::currentThread()) - return; - - moveToThread(QCoreApplicationPrivate::mainThread()); - } - updating = false; #ifndef QT_NO_LIBRARY @@ -382,7 +395,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() else sessionEngines.append(engine); - engine->moveToThread(QCoreApplicationPrivate::mainThread()); + engine->moveToThread(bearerThread); connect(engine, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); @@ -424,14 +437,9 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (firstUpdate) { firstUpdate = false; QList enginesToInitialize = sessionEngines; //shallow copy the list in case it is modified when we unlock mutex - Qt::ConnectionType connectionType; - if (QCoreApplicationPrivate::mainThread() == QThread::currentThread()) - connectionType = Qt::DirectConnection; - else - connectionType = Qt::BlockingQueuedConnection; locker.unlock(); foreach (QBearerEngine* engine, enginesToInitialize) { - QMetaObject::invokeMethod(engine, "initialize", connectionType); + QMetaObject::invokeMethod(engine, "initialize", Qt::BlockingQueuedConnection); } } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 1679c3b..b3c83bc 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -91,6 +91,8 @@ public: void enablePolling(); void disablePolling(); + void initialize(); + void cleanup(); public slots: void updateConfigurations(); @@ -105,6 +107,7 @@ Q_SIGNALS: private: QTimer *pollTimer; + QThread *bearerThread; QMutex mutex; -- cgit v0.12 From 3359984cd1f8e568feb42969830b3fb6a13f5718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Niemel=C3=A4?= Date: Mon, 13 Jun 2011 15:49:35 +0300 Subject: Qmlshadersplugin API documentation enhancements. Added a link from qml element index, removed some unnecessary doc markings, added missing example image and some other minor fixes. Reviewed-by: Kim Gronholm --- doc/src/declarative/elements.qdoc | 13 +++ doc/src/declarative/pics/shaderexample.png | Bin 0 -> 3941 bytes src/imports/shaders/scenegraph/qsggeometry.cpp | 116 ------------------------- src/imports/shaders/shadereffectitem.cpp | 6 +- src/imports/shaders/shadereffectsource.cpp | 10 +-- 5 files changed, 21 insertions(+), 124 deletions(-) create mode 100644 doc/src/declarative/pics/shaderexample.png diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index a861a66..6b7a5fc 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -175,6 +175,8 @@ Elements that animate properties based on data types \o \l {ParticleMotionLinear} - Adds linear motion behavior to \l {Particles} \o \l {ParticleMotionGravity} - Adds gravitational motion to \l {Particles} \o \l {ParticleMotionWander} - Adds varied motions to \l {Particles} +\o \l {ShaderEffectItem} - Enables the use of OpenGL Shading Language together with QML +\o \l {ShaderEffectSource} - Encapsulates QML item tree as a source item for \l {ShaderEffectItem} \endlist \section1 Add-On Elements @@ -321,3 +323,14 @@ should first be obtained and installed. \generatelist{related} */ + +/*! + \group qml-shader-elements + \title QML Shader Elements + \ingroup qml-groups + + \brief Elements for using OpenGL shading language code together with the QML code. + + \generatelist{related} + +*/ diff --git a/doc/src/declarative/pics/shaderexample.png b/doc/src/declarative/pics/shaderexample.png new file mode 100644 index 0000000..dbc7291 Binary files /dev/null and b/doc/src/declarative/pics/shaderexample.png differ diff --git a/src/imports/shaders/scenegraph/qsggeometry.cpp b/src/imports/shaders/scenegraph/qsggeometry.cpp index 05c111a..08ac10e 100644 --- a/src/imports/shaders/scenegraph/qsggeometry.cpp +++ b/src/imports/shaders/scenegraph/qsggeometry.cpp @@ -44,11 +44,6 @@ 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[] = { @@ -58,9 +53,6 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D() return attrs; } -/*! - Convenience function which returns attributes to be used for textured 2D drawing. - */ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D() { @@ -72,9 +64,6 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D( return attrs; } -/*! - Convenience function which returns attributes to be used for per vertex colored 2D drawing. - */ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D() { @@ -87,29 +76,6 @@ const QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D() } -/*! - \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, @@ -138,41 +104,6 @@ QSGGeometry::~QSGGeometry() 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 @@ -180,11 +111,6 @@ void *QSGGeometry::indexData() : ((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 @@ -192,38 +118,11 @@ const void *QSGGeometry::indexData() const : ((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) @@ -252,12 +151,6 @@ void QSGGeometry::allocate(int vertexCount, int indexCount) } -/*! - 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(); @@ -274,15 +167,6 @@ void QSGGeometry::updateRectGeometry(QSGGeometry *g, const QRectF &rect) 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(); diff --git a/src/imports/shaders/shadereffectitem.cpp b/src/imports/shaders/shadereffectitem.cpp index 5bb906c..48c842a 100644 --- a/src/imports/shaders/shadereffectitem.cpp +++ b/src/imports/shaders/shadereffectitem.cpp @@ -72,7 +72,7 @@ static const char qt_emptyAttributeName[] = ""; /*! \qmlclass ShaderEffectItem ShaderEffectItem - \ingroup qmlshadersplugin + \ingroup qml-shader-elements \brief The ShaderEffectItem object alters the output of given item with OpenGL shaders. \inherits Item @@ -84,7 +84,7 @@ static const char qt_emptyAttributeName[] = ""; 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). + Qt OpenGL graphicssystem or is using OpenGL by setting QGLWidget as the viewport to QDeclarativeView (depending on which one is the recommened way in the targeted platform). 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, @@ -195,7 +195,7 @@ Rectangle { } } \endqml - \image Example1.png + \image shaderexample.png */ diff --git a/src/imports/shaders/shadereffectsource.cpp b/src/imports/shaders/shadereffectsource.cpp index dec3bb0..e6dbc73 100644 --- a/src/imports/shaders/shadereffectsource.cpp +++ b/src/imports/shaders/shadereffectsource.cpp @@ -48,7 +48,7 @@ /*! \qmlclass ShaderEffectSource ShaderEffectSource - \ingroup qmlshadersplugin + \ingroup qml-shader-elements \brief The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem. ShaderEffectSource is available in the \bold{Qt.labs.shaders 1.0} module. @@ -273,10 +273,10 @@ void ShaderEffectSource::setHideSource(bool hide) 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. + \o ShaderEffectSource.ClampToEdge - Causes texturecoordinates to be clamped to the range [ 1/2*N , 1 - 1/2*N ], where N is the texture width. + \o ShaderEffectSource.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 ShaderEffectSource.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 ShaderEffectSource.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. -- cgit v0.12 From 3199ee59ad931b88a26657fc5c66d94c4fff606f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Niemel=C3=A4?= Date: Mon, 13 Jun 2011 15:57:49 +0300 Subject: Qmlshadersplugin examples added. Example application for OpenGL shading language and QML. Added also a link from qml examples main documents labs section. Reviewed-by: Kim Gronholm --- doc/src/declarative/examples.qdoc | 23 +-- doc/src/examples/qml-examples.qdoc | 10 ++ doc/src/images/qml-shadereffects-example.png | Bin 0 -> 271264 bytes examples/declarative/declarative.pro | 3 + examples/declarative/shadereffects/main.cpp | 76 +++++++++ examples/declarative/shadereffects/qml/Curtain.qml | 106 +++++++++++++ .../shadereffects/qml/CurtainEffect.qml | 97 ++++++++++++ .../declarative/shadereffects/qml/DropShadow.qml | 117 ++++++++++++++ .../shadereffects/qml/DropShadowEffect.qml | 174 +++++++++++++++++++++ .../declarative/shadereffects/qml/Grayscale.qml | 77 +++++++++ .../shadereffects/qml/GrayscaleEffect.qml | 62 ++++++++ .../declarative/shadereffects/qml/ImageMask.qml | 143 +++++++++++++++++ .../shadereffects/qml/ImageMaskEffect.qml | 60 +++++++ .../declarative/shadereffects/qml/RadialWave.qml | 85 ++++++++++ .../shadereffects/qml/RadialWaveEffect.qml | 81 ++++++++++ examples/declarative/shadereffects/qml/Water.qml | 60 +++++++ .../declarative/shadereffects/qml/WaterEffect.qml | 126 +++++++++++++++ .../shadereffects/qml/images/Curtain.jpg | Bin 0 -> 16112 bytes .../shadereffects/qml/images/DropShadow.jpg | Bin 0 -> 12975 bytes .../shadereffects/qml/images/Grayscale.jpg | Bin 0 -> 19048 bytes .../shadereffects/qml/images/ImageMask.jpg | Bin 0 -> 18751 bytes .../shadereffects/qml/images/RadialWave.jpg | Bin 0 -> 41406 bytes .../declarative/shadereffects/qml/images/Water.jpg | Bin 0 -> 17751 bytes .../declarative/shadereffects/qml/images/back.png | Bin 0 -> 370 bytes .../declarative/shadereffects/qml/images/bg.jpg | Bin 0 -> 10189 bytes .../shadereffects/qml/images/desaturate.jpg | Bin 0 -> 203942 bytes .../shadereffects/qml/images/drop_shadow.png | Bin 0 -> 219220 bytes .../shadereffects/qml/images/fabric.jpg | Bin 0 -> 163431 bytes .../shadereffects/qml/images/flower.png | Bin 0 -> 219220 bytes .../shadereffects/qml/images/image1.jpg | Bin 0 -> 115770 bytes .../shadereffects/qml/images/image2.jpg | Bin 0 -> 45837 bytes .../shadereffects/qml/images/qt-logo.png | Bin 0 -> 22746 bytes .../shadereffects/qml/images/shader_effects.jpg | Bin 0 -> 4906 bytes .../declarative/shadereffects/qml/images/sky.jpg | Bin 0 -> 36734 bytes .../shadereffects/qml/images/toolbar.png | Bin 0 -> 342 bytes .../declarative/shadereffects/qml/images/wave.jpg | Bin 0 -> 176681 bytes examples/declarative/shadereffects/qml/main.qml | 160 +++++++++++++++++++ .../declarative/shadereffects/shadereffects.pro | 21 +++ 38 files changed, 1470 insertions(+), 11 deletions(-) create mode 100644 doc/src/images/qml-shadereffects-example.png create mode 100755 examples/declarative/shadereffects/main.cpp create mode 100755 examples/declarative/shadereffects/qml/Curtain.qml create mode 100755 examples/declarative/shadereffects/qml/CurtainEffect.qml create mode 100755 examples/declarative/shadereffects/qml/DropShadow.qml create mode 100755 examples/declarative/shadereffects/qml/DropShadowEffect.qml create mode 100755 examples/declarative/shadereffects/qml/Grayscale.qml create mode 100755 examples/declarative/shadereffects/qml/GrayscaleEffect.qml create mode 100755 examples/declarative/shadereffects/qml/ImageMask.qml create mode 100755 examples/declarative/shadereffects/qml/ImageMaskEffect.qml create mode 100755 examples/declarative/shadereffects/qml/RadialWave.qml create mode 100755 examples/declarative/shadereffects/qml/RadialWaveEffect.qml create mode 100755 examples/declarative/shadereffects/qml/Water.qml create mode 100755 examples/declarative/shadereffects/qml/WaterEffect.qml create mode 100755 examples/declarative/shadereffects/qml/images/Curtain.jpg create mode 100755 examples/declarative/shadereffects/qml/images/DropShadow.jpg create mode 100755 examples/declarative/shadereffects/qml/images/Grayscale.jpg create mode 100755 examples/declarative/shadereffects/qml/images/ImageMask.jpg create mode 100755 examples/declarative/shadereffects/qml/images/RadialWave.jpg create mode 100755 examples/declarative/shadereffects/qml/images/Water.jpg create mode 100755 examples/declarative/shadereffects/qml/images/back.png create mode 100755 examples/declarative/shadereffects/qml/images/bg.jpg create mode 100755 examples/declarative/shadereffects/qml/images/desaturate.jpg create mode 100755 examples/declarative/shadereffects/qml/images/drop_shadow.png create mode 100755 examples/declarative/shadereffects/qml/images/fabric.jpg create mode 100755 examples/declarative/shadereffects/qml/images/flower.png create mode 100755 examples/declarative/shadereffects/qml/images/image1.jpg create mode 100755 examples/declarative/shadereffects/qml/images/image2.jpg create mode 100755 examples/declarative/shadereffects/qml/images/qt-logo.png create mode 100755 examples/declarative/shadereffects/qml/images/shader_effects.jpg create mode 100755 examples/declarative/shadereffects/qml/images/sky.jpg create mode 100755 examples/declarative/shadereffects/qml/images/toolbar.png create mode 100755 examples/declarative/shadereffects/qml/images/wave.jpg create mode 100755 examples/declarative/shadereffects/qml/main.qml create mode 100755 examples/declarative/shadereffects/shadereffects.pro diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index 0e325e2..1003b22 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -33,7 +33,7 @@ Qt includes a set of examples and demos that show how to use various aspects -of QML. The examples are small demonstrations of particular QML components, +of QML. The examples are small demonstrations of particular QML components, while the demos contain more complete and functional applications. To run the examples and demos, open them in Qt Creator or use the included @@ -60,43 +60,43 @@ can be used to produce sophisticated interfaces and applications: \table \row -\o +\o \l{demos/declarative/calculator}{Calculator} \image qml-calculator-example-small.png -\o +\o \l{demos/declarative/flickr}{Flickr Mobile} \image qml-flickr-demo-small.png -\o +\o \l{demos/declarative/minehunt}{Minehunt} \image qml-minehunt-demo-small.png \row -\o +\o \l{demos/declarative/photoviewer}{Photo Viewer} \image qml-photoviewer-demo-small.png -\o +\o \l{demos/declarative/rssnews}{RSS News Reader} \image qml-rssnews-demo-small.png -\o +\o \l{demos/declarative/samegame}{Same Game} \image qml-samegame-demo-small.png \row -\o +\o \l{demos/declarative/snake}{Snake} \image qml-snake-demo-small.png -\o +\o \l{demos/declarative/twitter}{Twitter} \image qml-twitter-demo-small.png -\o +\o \l{demos/declarative/webbrowser}{Web Browser} \image qml-webbrowser-demo-small.png @@ -109,7 +109,7 @@ The demos can be found in Qt's \c demos/declarative directory. The QML examples are small, simple applications that show how to use a particular QML component or feature. If you are new -to QML, you may also find the \l{QML Tutorial}{Hello World} and +to QML, you may also find the \l{QML Tutorial}{Hello World} and \l {QML Advanced Tutorial}{Same Game} tutorials useful. The examples can be found in Qt's \c examples/declarative directory. @@ -234,6 +234,7 @@ The examples can be found in Qt's \c examples/declarative directory. \list \o \l{src/imports/folderlistmodel}{Folder List Model} - a C++ model plugin +\o \l{declarative/shadereffects}{Shader Effects} \endlist */ diff --git a/doc/src/examples/qml-examples.qdoc b/doc/src/examples/qml-examples.qdoc index 00eeb43..a910266 100644 --- a/doc/src/examples/qml-examples.qdoc +++ b/doc/src/examples/qml-examples.qdoc @@ -714,3 +714,13 @@ \image qml-xmlhttprequest-example.png */ + +/*! + \title Labs: Shader Effects + \example declarative/shadereffects + + This example shows how to create visual effects by using OpenGL shading language together with QML using \l ShaderEffectItem and \l ShaderEffectSource APIs. + + \image qml-shadereffects-example.png +*/ + diff --git a/doc/src/images/qml-shadereffects-example.png b/doc/src/images/qml-shadereffects-example.png new file mode 100644 index 0000000..9649fe1 Binary files /dev/null and b/doc/src/images/qml-shadereffects-example.png differ diff --git a/examples/declarative/declarative.pro b/examples/declarative/declarative.pro index e3d922c..f10e7a4 100644 --- a/examples/declarative/declarative.pro +++ b/examples/declarative/declarative.pro @@ -6,6 +6,9 @@ SUBDIRS = \ modelviews \ tutorials +# OpenGL shader examples requires opengl and they contain some C++ and need to be built +contains(QT_CONFIG, opengl): SUBDIRS += shadereffects + # plugins uses a 'Time' class that conflicts with symbian e32std.h also defining a class of the same name symbian:SUBDIRS -= plugins diff --git a/examples/declarative/shadereffects/main.cpp b/examples/declarative/shadereffects/main.cpp new file mode 100755 index 0000000..62bf505 --- /dev/null +++ b/examples/declarative/shadereffects/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 examples 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 +#include +#include +#include + +int main(int argc, char *argv[]) +{ +// Depending on which is the recommended way for the platform, either use +// opengl graphics system or paint into QGLWidget. +#ifdef SHADEREFFECTS_USE_OPENGL_GRAPHICSSYSTEM + QApplication::setGraphicsSystem("opengl"); +#endif + + QApplication app(argc, argv); + QDeclarativeView view; + +#ifndef SHADEREFFECTS_USE_OPENGL_GRAPHICSSYSTEM + QGLFormat format = QGLFormat::defaultFormat(); + format.setSampleBuffers(false); + format.setSwapInterval(1); + QGLWidget* glWidget = new QGLWidget(format); + glWidget->setAutoFillBackground(false); + view.setViewport(glWidget); +#endif + + view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + view.setAttribute(Qt::WA_OpaquePaintEvent); + view.setAttribute(Qt::WA_NoSystemBackground); + view.setSource(QUrl::fromLocalFile(QLatin1String("qml/main.qml"))); + QObject::connect(view.engine(), SIGNAL(quit()), &view, SLOT(close())); + + view.show(); + + return app.exec(); +} diff --git a/examples/declarative/shadereffects/qml/Curtain.qml b/examples/declarative/shadereffects/qml/Curtain.qml new file mode 100755 index 0000000..8697951 --- /dev/null +++ b/examples/declarative/shadereffects/qml/Curtain.qml @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 examples 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 + +Item { + id: main + anchors.fill: parent + + Rectangle{ + id: bg + anchors.fill: parent + color: "black" + } + + Image { + source: "images/qt-logo.png" + anchors.centerIn: parent + } + + Image { + id: fabric + anchors.fill: parent + source: "images/fabric.jpg" + fillMode: Image.Tile + } + + CurtainEffect { + id: curtain + anchors.fill: fabric + bottomWidth: topWidth + source: ShaderEffectSource { sourceItem: fabric; hideSource: true } + + Behavior on bottomWidth { + SpringAnimation { easing.type: Easing.OutElastic; velocity: 250; mass: 1.5; spring: 0.5; damping: 0.05} + } + + SequentialAnimation on topWidth { + id: topWidthAnim + loops: Animation.Infinite + + NumberAnimation { to: 360; duration: 1000 } + PauseAnimation { duration: 2000 } + NumberAnimation { to: 180; duration: 1000 } + PauseAnimation { duration: 2000 } + } + } + + MouseArea { + anchors.fill: parent + + onPressed: { + topWidthAnim.stop() + curtain.topWidth = mouseX; + } + + onReleased: { + topWidthAnim.restart() + } + + onPositionChanged: { + if (pressed) { + curtain.topWidth = mouseX; + } + } + } +} diff --git a/examples/declarative/shadereffects/qml/CurtainEffect.qml b/examples/declarative/shadereffects/qml/CurtainEffect.qml new file mode 100755 index 0000000..7834a1a --- /dev/null +++ b/examples/declarative/shadereffects/qml/CurtainEffect.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 examples 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 + +ShaderEffectItem { + anchors.fill: parent + property variant source + meshResolution: Qt.size(50, 50) + + property real topWidth: width / 2 + property real bottomWidth: width / 2 + property real originalWidth: width + property real originalHeight: height + property real amplitude: 0.1 + + vertexShader: " + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + uniform highp mat4 qt_ModelViewProjectionMatrix; + varying highp vec2 qt_TexCoord0; + varying lowp float shade; + + uniform highp float topWidth; + uniform highp float bottomWidth; + uniform highp float originalWidth; + uniform highp float originalHeight; + uniform highp float amplitude; + + void main() { + qt_TexCoord0 = qt_MultiTexCoord0; + + highp vec4 shift = vec4(0, 0, 0, 0); + shift.x = qt_Vertex.x * ((originalWidth - topWidth) + (topWidth - bottomWidth) * (qt_Vertex.y / originalHeight)) / originalWidth; + + shade = sin(21.9911486 * qt_Vertex.x / originalWidth); + shift.y = amplitude * (originalWidth - topWidth + (topWidth - bottomWidth) * (qt_Vertex.y / originalHeight)) * shade; + + gl_Position = qt_ModelViewProjectionMatrix * (qt_Vertex - shift); + + shade = 0.2 * (2.0 - shade ) * (1.0 - (bottomWidth + (topWidth - bottomWidth) * (1.0 - qt_Vertex.y / originalHeight)) / originalWidth); + } + " + + fragmentShader: " + uniform sampler2D source; + varying highp vec2 qt_TexCoord0; + varying lowp float shade; + void main() { + highp vec4 color = texture2D(source, qt_TexCoord0); + color.rgb *= 1.0 - shade; + gl_FragColor = color; + } + " +} + + + diff --git a/examples/declarative/shadereffects/qml/DropShadow.qml b/examples/declarative/shadereffects/qml/DropShadow.qml new file mode 100755 index 0000000..054f193 --- /dev/null +++ b/examples/declarative/shadereffects/qml/DropShadow.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** 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 examples 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 + +Item { + id: main + anchors.fill: parent + + Image { + id: background + anchors.fill: parent + source: "images/bg.jpg" + } + + DropShadowEffect { + id: layer + + property real distance: 0.0 + + width: photo.width + height: photo.height + sourceItem: photo + color: "black" + blur: distance / 10.0 + opacity: 1 - distance / 50.0 + + Binding { + target: layer + property: "x" + value: -0.4 * layer.distance + when: !dragArea.pressed + } + Binding { + target: layer + property: "y" + value: 0.9 * layer.distance + when: !dragArea.pressed + } + + SequentialAnimation on distance { + id: animation + running: true + loops: Animation.Infinite + + NumberAnimation { to: 30; duration: 2000 } + PauseAnimation { duration: 500 } + NumberAnimation { to: 0; duration: 2000 } + PauseAnimation { duration: 500 } + } + } + + Image { + id: photo + anchors.fill: parent + source: "images/drop_shadow.png" + smooth: true + } + + MouseArea { + id: dragArea + anchors.fill: parent + + property int startX + property int startY + + onPressed: { + startX = mouseX + startY = mouseY + } + + onPositionChanged: { + layer.x += mouseX - startX + layer.y += mouseY - startY + startX = mouseX + startY = mouseY + } + } +} diff --git a/examples/declarative/shadereffects/qml/DropShadowEffect.qml b/examples/declarative/shadereffects/qml/DropShadowEffect.qml new file mode 100755 index 0000000..b9903a3 --- /dev/null +++ b/examples/declarative/shadereffects/qml/DropShadowEffect.qml @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** 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 examples 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 + +Item { + id: main + property real blur: 0.0 + property alias color: shadowEffectWithHBlur.color + property alias sourceItem: source.sourceItem + + ShaderEffectSource { + id: source + smooth: true + hideSource: false + } + + ShaderEffectItem { + id: shadowEffectWithHBlur + anchors.fill: parent + + property color color: "grey" + property variant sourceTexture: source; + property real xStep: main.blur / main.width + + vertexShader:" + uniform highp mat4 qt_ModelViewProjectionMatrix; + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + uniform highp float xStep; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord4; + varying highp vec2 qt_TexCoord5; + varying highp vec2 qt_TexCoord6; + + void main(void) + { + highp vec2 shift = vec2(xStep, 0.); + qt_TexCoord0 = qt_MultiTexCoord0 - 2.5 * shift; + qt_TexCoord1 = qt_MultiTexCoord0 - 1.5 * shift; + qt_TexCoord2 = qt_MultiTexCoord0 - 0.5 * shift; + qt_TexCoord4 = qt_MultiTexCoord0 + 0.5 * shift; + qt_TexCoord5 = qt_MultiTexCoord0 + 1.5 * shift; + qt_TexCoord6 = qt_MultiTexCoord0 + 2.5 * shift; + gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex; + } + " + + fragmentShader:" + uniform highp vec4 color; + uniform lowp sampler2D sourceTexture; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord4; + varying highp vec2 qt_TexCoord5; + varying highp vec2 qt_TexCoord6; + + void main() { + highp vec4 sourceColor = (texture2D(sourceTexture, qt_TexCoord0) * 0.1 + + texture2D(sourceTexture, qt_TexCoord1) * 0.15 + + texture2D(sourceTexture, qt_TexCoord2) * 0.25 + + texture2D(sourceTexture, qt_TexCoord4) * 0.25 + + texture2D(sourceTexture, qt_TexCoord5) * 0.15 + + texture2D(sourceTexture, qt_TexCoord6) * 0.1); + gl_FragColor = mix(vec4(0), color, sourceColor.a); + } + " + } + + ShaderEffectSource { + id: hBlurredShadow + smooth: true + sourceItem: shadowEffectWithHBlur + hideSource: true + } + + ShaderEffectItem { + id: finalEffect + anchors.fill: parent + + property color color: "grey" + property variant sourceTexture: hBlurredShadow; + property real yStep: main.blur / main.height + + vertexShader:" + uniform highp mat4 qt_ModelViewProjectionMatrix; + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + uniform highp float yStep; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord4; + varying highp vec2 qt_TexCoord5; + varying highp vec2 qt_TexCoord6; + + void main(void) + { + highp vec2 shift = vec2(0., yStep); + qt_TexCoord0 = qt_MultiTexCoord0 - 2.5 * shift; + qt_TexCoord1 = qt_MultiTexCoord0 - 1.5 * shift; + qt_TexCoord2 = qt_MultiTexCoord0 - 0.5 * shift; + qt_TexCoord4 = qt_MultiTexCoord0 + 0.5 * shift; + qt_TexCoord5 = qt_MultiTexCoord0 + 1.5 * shift; + qt_TexCoord6 = qt_MultiTexCoord0 + 2.5 * shift; + gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex; + } + " + + fragmentShader:" + uniform highp vec4 color; + uniform lowp sampler2D sourceTexture; + uniform highp float qt_Opacity; + varying highp vec2 qt_TexCoord0; + varying highp vec2 qt_TexCoord1; + varying highp vec2 qt_TexCoord2; + varying highp vec2 qt_TexCoord4; + varying highp vec2 qt_TexCoord5; + varying highp vec2 qt_TexCoord6; + + void main() { + highp vec4 sourceColor = (texture2D(sourceTexture, qt_TexCoord0) * 0.1 + + texture2D(sourceTexture, qt_TexCoord1) * 0.15 + + texture2D(sourceTexture, qt_TexCoord2) * 0.25 + + texture2D(sourceTexture, qt_TexCoord4) * 0.25 + + texture2D(sourceTexture, qt_TexCoord5) * 0.15 + + texture2D(sourceTexture, qt_TexCoord6) * 0.1); + gl_FragColor = sourceColor * qt_Opacity; + } + " + } +} diff --git a/examples/declarative/shadereffects/qml/Grayscale.qml b/examples/declarative/shadereffects/qml/Grayscale.qml new file mode 100755 index 0000000..d819a5d --- /dev/null +++ b/examples/declarative/shadereffects/qml/Grayscale.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 examples 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 + +Item { + id: main + anchors.fill: parent + + GrayscaleEffect { + id: layer + anchors.fill: parent + + source: ShaderEffectSource { + sourceItem: Image { source: "images/desaturate.jpg" } + live: false + hideSource: true + } + + SequentialAnimation on ratio { + id: ratioAnimation + running: true + loops: Animation.Infinite + NumberAnimation { + easing.type: Easing.Linear + to: 0.0 + duration: 1500 + } + PauseAnimation { duration: 1000 } + NumberAnimation { + easing.type: Easing.Linear + to: 1.0 + duration: 1500 + } + PauseAnimation { duration: 1000 } + } + } +} diff --git a/examples/declarative/shadereffects/qml/GrayscaleEffect.qml b/examples/declarative/shadereffects/qml/GrayscaleEffect.qml new file mode 100755 index 0000000..34505ff --- /dev/null +++ b/examples/declarative/shadereffects/qml/GrayscaleEffect.qml @@ -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 examples 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 + +ShaderEffectItem { + id: effect + property real ratio: 1.0 + property variant source: 0 + + fragmentShader: + " + varying highp vec2 qt_TexCoord0; + uniform sampler2D source; + uniform highp float ratio; + void main(void) + { + lowp vec4 textureColor = texture2D(source, qt_TexCoord0.st); + lowp float gray = dot(textureColor, vec4(0.299, 0.587, 0.114, 0.0)); + gl_FragColor = vec4(gray * ratio + textureColor.r * (1.0 - ratio), gray * ratio + textureColor.g * (1.0 - ratio), gray * ratio + textureColor.b * (1.0 - ratio), textureColor.a); + } + " +} diff --git a/examples/declarative/shadereffects/qml/ImageMask.qml b/examples/declarative/shadereffects/qml/ImageMask.qml new file mode 100755 index 0000000..ea9fa0a --- /dev/null +++ b/examples/declarative/shadereffects/qml/ImageMask.qml @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** 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 examples 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 + +Item { + anchors.fill: parent + + Image { + id: bg + anchors.fill: parent + source: "images/image2.jpg" + } + + Item { + id: mask + anchors.fill: parent + + Text { + text: "Mask text" + font.pixelSize: 50 + font.bold: true + anchors.horizontalCenter: parent.horizontalCenter + + NumberAnimation on rotation { + running: true + loops: Animation.Infinite + from: 0 + to: 360 + duration: 3000 + } + + SequentialAnimation on y { + running: true + loops: Animation.Infinite + NumberAnimation { + to: main.height + duration: 3000 + } + NumberAnimation { + to: 0 + duration: 3000 + } + } + } + + Rectangle { + id: opaqueBox + width: 60 + height: parent.height + SequentialAnimation on x { + running: true + loops: Animation.Infinite + NumberAnimation { + to: main.width + duration: 2000 + easing.type: Easing.InOutCubic + } + NumberAnimation { + to: 0 + duration: 2000 + easing.type: Easing.InOutCubic + } + } + } + + Rectangle { + width: 100 + opacity: 0.5 + height: parent.height + SequentialAnimation on x { + PauseAnimation { duration: 100 } + + SequentialAnimation { + loops: Animation.Infinite + NumberAnimation { + to: main.width + duration: 2000 + easing.type: Easing.InOutCubic + } + NumberAnimation { + to: 0 + duration: 2000 + easing.type: Easing.InOutCubic + } + } + } + } + } + + ImageMaskEffect { + anchors.fill: parent + image: ShaderEffectSource { + sourceItem: Image { source: "images/image1.jpg" } + live: false + hideSource: true + } + mask: ShaderEffectSource { + sourceItem: mask + live: true + hideSource: true + } + } +} diff --git a/examples/declarative/shadereffects/qml/ImageMaskEffect.qml b/examples/declarative/shadereffects/qml/ImageMaskEffect.qml new file mode 100755 index 0000000..2dc0e75 --- /dev/null +++ b/examples/declarative/shadereffects/qml/ImageMaskEffect.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 examples 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 +i