aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-04-29 14:17:46 +0200
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2013-04-29 14:17:46 +0200
commit7224dd977163335d61ed4297341e6161bf1dbcf7 (patch)
tree1674bfdd872ba45908437c9cbc67ba98f5f3b534 /examples/quick
parentc704226b6815df4d989142729bae9fadd14f6f9d (diff)
parentf3973cbd077d2d92250958f8bda57fea30827f00 (diff)
Merge remote-tracking branch 'origin/stable' into dev
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/painteditem/textballoons/doc/src/textballoons.qdoc4
-rw-r--r--examples/quick/particles/system/doc/src/system.qdoc2
-rw-r--r--examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc32
-rw-r--r--examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc32
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.cpp11
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.h6
-rw-r--r--examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc26
-rw-r--r--examples/quick/scenegraph/textureinthread/main.cpp32
-rw-r--r--examples/quick/scenegraph/textureinthread/threadrenderer.cpp69
-rw-r--r--examples/quick/scenegraph/textureinthread/threadrenderer.h6
-rw-r--r--examples/quick/shadereffects/doc/src/shadereffects.qdoc2
-rw-r--r--examples/quick/views/doc/src/views.qdoc2
12 files changed, 141 insertions, 83 deletions
diff --git a/examples/quick/painteditem/textballoons/doc/src/textballoons.qdoc b/examples/quick/painteditem/textballoons/doc/src/textballoons.qdoc
index d4aabc01d8..9450c19259 100644
--- a/examples/quick/painteditem/textballoons/doc/src/textballoons.qdoc
+++ b/examples/quick/painteditem/textballoons/doc/src/textballoons.qdoc
@@ -43,12 +43,12 @@
The example consists of an item class, a plugin class and a QML file
to use this plugin. The \c TextBalloon class represents the individual
text balloons extending QQuickPaintedItem, the \c TextBalloonPlugin class
- represents the skeleton code for a QtQuick plugin and the
+ represents the skeleton code for a \l {Qt Quick} plugin and the
\c textballoons.qml file is used to load the plugin and display the text
balloons.
We will focus on the \c TextBalloon class first and continue with the
- \c textballoons.qml file. For an example on how to implement a QtQuick
+ \c textballoons.qml file. For an example on how to implement a \l {Qt Quick}
plugin please look at \l{declarative/tutorials/extending/chapter6-plugins}
{Writing an Extension Plugin}
diff --git a/examples/quick/particles/system/doc/src/system.qdoc b/examples/quick/particles/system/doc/src/system.qdoc
index 04dc1727d2..2bef4c6947 100644
--- a/examples/quick/particles/system/doc/src/system.qdoc
+++ b/examples/quick/particles/system/doc/src/system.qdoc
@@ -53,6 +53,6 @@
\snippet quick/particles/system/content/dynamicemitters.qml 0
Note that this effect, a flurry of flying rainbow spears, would be better served with TrailEmitter. It is only done with dynamic emitters in this example to show the concept more simply.
- Multiple Painters shows how to control paint ordering of individual particles. While the paint ordering of particles within one ImagePainter is not strictly defined, ImageParticle objects follow the normal Z-ordering rules for QtQuick items. This example allow you to paint the inside of the particles above the black borders using a pair of ImageParticles each painting different parts of the same logical particle.
+ Multiple Painters shows how to control paint ordering of individual particles. While the paint ordering of particles within one ImagePainter is not strictly defined, ImageParticle objects follow the normal Z-ordering rules for \l {Qt Quick} items. This example allow you to paint the inside of the particles above the black borders using a pair of ImageParticles each painting different parts of the same logical particle.
*/
diff --git a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
index d98407b6c1..e3cef52bf7 100644
--- a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
+++ b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
@@ -41,7 +41,7 @@
\section1 BezierCurve Declaration
- \snippet quick/scenegraph/customgeometry/beziercurve.h 1
+ \snippet scenegraph/customgeometry/beziercurve.h 1
The item declaration subclasses the QQuickItem class and adds five
properties. One for each of the four control points in the bezier
@@ -52,7 +52,7 @@
signals for each of them so changes will be picked up the QML
engine and used accordingly.
- \snippet quick/scenegraph/customgeometry/beziercurve.h 2
+ \snippet scenegraph/customgeometry/beziercurve.h 2
The synchronization point between the QML scene and the rendering
scene graph is the virtual function \l
@@ -67,7 +67,7 @@
\section1 BezierCurve Implementation
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 1
+ \snippet scenegraph/customgeometry/beziercurve.cpp 1
The BezierCurve constructor sets up default values for the
control points and the number of segments. The bezier curve
@@ -80,7 +80,7 @@
QQuickItem::updatePaintNode() when it is time for the QML scene to
be synchronized with the rendering scene graph.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 2
+ \snippet scenegraph/customgeometry/beziercurve.cpp 2
The BezierCurve class has no data members that need to be cleaned
up so the destructor does nothing. It is worth mentioning that the
@@ -89,7 +89,7 @@
QSGNode references in the QQuickItem class nor try to clean them
up explicitly.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 3
+ \snippet scenegraph/customgeometry/beziercurve.cpp 3
The setter function for the p1 property checks if the value is
unchanged and exits early if this is the case. Then it updates the
@@ -103,7 +103,7 @@
The other property setters are equivalent, and are omitted from
this example.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 4
+ \snippet scenegraph/customgeometry/beziercurve.cpp 4
The updatePaintNode() function is the primary integration point
for synchronizing the state of the QML scene with the rendering
@@ -113,7 +113,7 @@
our QSGGeometryNode which we will fill with geometry and a
material.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 5
+ \snippet scenegraph/customgeometry/beziercurve.cpp 5
We then create the geometry and add it to the node. The first
argument to the QSGGeometry constructor is a definition of the
@@ -135,7 +135,7 @@
geometry a member of a QSGGeometryNode subclass, in which case, we
would not have set the QSGGeometryNode::OwnsGeometry flag.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 6
+ \snippet scenegraph/customgeometry/beziercurve.cpp 6
The scene graph API provides a few commonly used used material
implementations. In this example we use the QSGFlatColorMaterial
@@ -143,7 +143,7 @@
color. Again we pass the ownership of the material to the node, so
it can be cleaned up by the scene graph.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 7
+ \snippet scenegraph/customgeometry/beziercurve.cpp 7
In the case where the QML item has changed and we only want to
modify the existing node's geometry, we cast the \c oldNode to a
@@ -151,7 +151,7 @@
segment count has changed, we call QSGGeometry::allocate() to make
sure it has the right number of vertices.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 8
+ \snippet scenegraph/customgeometry/beziercurve.cpp 8
To fill the geometry, we first extract the vertex array from
it. Since we are using one of the default attribute sets, we can
@@ -159,14 +159,14 @@
Then we go through each segment and calculate its position and
write that value to the vertex.
- \snippet quick/scenegraph/customgeometry/beziercurve.cpp 9
+ \snippet scenegraph/customgeometry/beziercurve.cpp 9
In the end of the function, we return the node so the scene graph
can render it.
\section1 Application Entry-Point
- \snippet quick/scenegraph/customgeometry/main.cpp 1
+ \snippet scenegraph/customgeometry/main.cpp 1
The application is a straightforward QML application, with a
QGuiApplication and a QQuickView that we pass a .qml file. To make
@@ -183,24 +183,24 @@
\section1 Using the Item
- \snippet quick/scenegraph/customgeometry/main.qml 1
+ \snippet scenegraph/customgeometry/main.qml 1
Our .qml file imports the \c {QtQuick 2.0} module to get the
standard types and also our own \c {CustomGeometry 1.0} module
which contains our newly created BezierCurve objects.
- \snippet quick/scenegraph/customgeometry/main.qml 2
+ \snippet scenegraph/customgeometry/main.qml 2
Then we create the our root item and an instance of the
BezierCurve which we anchor to fill the root.
- \snippet quick/scenegraph/customgeometry/main.qml 3
+ \snippet scenegraph/customgeometry/main.qml 3
To make the example a bit more interesting we add an animation to
change the two control points in the curve. The end points stay
unchanged.
- \snippet quick/scenegraph/customgeometry/main.qml 4
+ \snippet scenegraph/customgeometry/main.qml 4
Finally we overlay a short text outlining what the example shows.
diff --git a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
index 4bf5444d79..1f87412aa4 100644
--- a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
+++ b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
@@ -50,7 +50,7 @@
in the QML file and this value is used by the OpenGL shader
program that draws the squircles.
- \snippet quick/scenegraph/openglunderqml/squircle.h 1
+ \snippet scenegraph/openglunderqml/squircle.h 1
First of all, we need a QObject with a slot to connect the signals
to. We subclass QQuickItem in order to use the \l
@@ -73,13 +73,13 @@
Lets move on to the implementation.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 7
+ \snippet scenegraph/openglunderqml/squircle.cpp 7
The constructor of the \c Squircle class simply initializes the
values. The shader program will be initialized during rendering
later.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 8
+ \snippet scenegraph/openglunderqml/squircle.cpp 8
The property setter checks that the value has indeed changed
before updating its internal variable. It then calls \l
@@ -88,13 +88,13 @@
initialization, before the object has been entered into the scene
and before it has a window.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 1
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 2
+ \snippet scenegraph/openglunderqml/squircle.cpp 1
+ \snippet scenegraph/openglunderqml/squircle.cpp 2
For our paint function to be called, we need to connect to the
window's signals. When Squircle object is populated into the
- scene, the itemChange function is called with the change type \c
- ItemSceneChange. We connect \l QQuickWindow::beforeRendering() to
+ scene, the windowChanged signal is emitted. In our handler,
+ we connect \l QQuickWindow::beforeRendering() to
\c paint() to do the rendering, and \l
QQuickWindow::beforeSynchronizing() to \c sync() to copy the state
of the \c t property for the upcoming frame.
@@ -106,14 +106,14 @@
slots are invoked on the wrong thread with no OpenGL context
present.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 3
+ \snippet scenegraph/openglunderqml/squircle.cpp 3
The default behavior of the scene graph is to clear the
framebuffer before rendering. Since we render before the scene
graph, we need to turn this clearing off. This means that we need
to clear ourselves in the \c paint() function.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 4
+ \snippet scenegraph/openglunderqml/squircle.cpp 4
The first thing we do in the \c paint() function is to
initialize the shader program. By initializing the shader program
@@ -126,18 +126,18 @@
all rendering related operations must happen on the rendering
thread.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 5
+ \snippet scenegraph/openglunderqml/squircle.cpp 5
We use the shader program to draw the squircle. At the end of the
\c paint function we release the program and disable the
attributes we used so that the OpenGL context is in a "clean"
state for the scene graph to pick it up.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 6
+ \snippet scenegraph/openglunderqml/squircle.cpp 6
In the \c cleanup() function we delete the program.
- \snippet quick/scenegraph/openglunderqml/squircle.cpp 9
+ \snippet scenegraph/openglunderqml/squircle.cpp 9
We use the \c sync() function to copy the state of the
object in the GUI thread into the rendering thread.
@@ -146,20 +146,20 @@
thread is blocked, so it is safe to simply copy the value without
any additional protection.
- \snippet quick/scenegraph/openglunderqml/main.cpp 1
+ \snippet scenegraph/openglunderqml/main.cpp 1
The application's \c main() function instantiates a QQuickView and
launches the \c main.qml file. The only thing worth noting is that
we export the \c Squircle class to QML using the \l
qmlRegisterType() macro.
- \snippet quick/scenegraph/openglunderqml/main.qml 1
+ \snippet scenegraph/openglunderqml/main.qml 1
We import the Squircle QML type with the name we registered in the
\c main() function. We then instantiate it and create a running
- NumberAnimation on the its \c t property.
+ NumberAnimation on its \c t property.
- \snippet quick/scenegraph/openglunderqml/main.qml 2
+ \snippet scenegraph/openglunderqml/main.qml 2
Then we overlay a short descriptive text, so that it is clearly
visible that we are in fact rendering OpenGL under our Qt Quick
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.cpp b/examples/quick/scenegraph/openglunderqml/squircle.cpp
index 84509fb615..8ceb9c5f9e 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.cpp
+++ b/examples/quick/scenegraph/openglunderqml/squircle.cpp
@@ -51,6 +51,7 @@ Squircle::Squircle()
, m_t(0)
, m_thread_t(0)
{
+ connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
}
//! [7]
@@ -66,17 +67,11 @@ void Squircle::setT(qreal t)
}
//! [8]
-
//! [1]
-void Squircle::itemChange(ItemChange change, const ItemChangeData &)
+void Squircle::handleWindowChanged(QQuickWindow *win)
{
- // The ItemSceneChange event is sent when we are first attached to a window.
- if (change == ItemSceneChange) {
- QQuickWindow *win = window();
- if (!win)
- return;
+ if (win) {
//! [1]
-
// Connect the beforeRendering signal to our paint function.
// Since this call is executed on the rendering thread it must be
// a Qt::DirectConnection
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.h b/examples/quick/scenegraph/openglunderqml/squircle.h
index e292ca325f..449e02bbf1 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.h
+++ b/examples/quick/scenegraph/openglunderqml/squircle.h
@@ -61,14 +61,14 @@ public:
signals:
void tChanged();
-protected:
- void itemChange(ItemChange change, const ItemChangeData &);
-
public slots:
void paint();
void cleanup();
void sync();
+private slots:
+ void handleWindowChanged(QQuickWindow *win);
+
private:
QOpenGLShaderProgram *m_program;
diff --git a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
index 1529649798..5d83b9fa5f 100644
--- a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
+++ b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
@@ -47,7 +47,7 @@
material state is what we assign to each individual node, in this
case to give them different colors.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 1
+ \snippet scenegraph/simplematerial/simplematerial.cpp 1
The first thing we do when creating custom materials with the
simplified scheme is to create a state class. In this case the
@@ -55,7 +55,7 @@
compare function which the scene graph can use to reorder the node
rendering.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 2
+ \snippet scenegraph/simplematerial/simplematerial.cpp 2
Next we define the material shader, by subclassing a template
instantiation of \l QSGSimpleMaterialShader with our \c State.
@@ -74,21 +74,21 @@
classes. Using the same \c State class in multiple shaders will
will lead to undefined behavior.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 3
+ \snippet scenegraph/simplematerial/simplematerial.cpp 3
Next comes the declaration of the shader source code, where we
define a vertex and fragment shader. The simple material assumes
the presence of \c qt_Matrix in the vertex shader and \c
qt_Opacity in the fragment shader.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 4
+ \snippet scenegraph/simplematerial/simplematerial.cpp 4
We reimplement the \c attributes function to return the name of
the \c aVertex and \c aTexCoord attribute names. These attributes
will be mapped to attribute indices 0 and 1 in the node's
geometry.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 6
+ \snippet scenegraph/simplematerial/simplematerial.cpp 6
Uniforms can be accessed either by name or by index, where index
is faster than name, so we reimplement the \c resolveUniforms()
@@ -96,7 +96,7 @@
to worry about resolving \c qt_Opacity or \c qt_Matrix as these
are handled by the baseclass.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 5
+ \snippet scenegraph/simplematerial/simplematerial.cpp 5
The \c updateState() function is called once for every unique
state and we use it to update the shader program with the current
@@ -105,7 +105,7 @@
usecase, where all the colors are different, the updateState will
be called once for every node.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 7
+ \snippet scenegraph/simplematerial/simplematerial.cpp 7
The \c ColorNode class is supposed to draw something, so it needs
to be a subclass of \l QSGGeometryNode.
@@ -129,12 +129,12 @@
Finally, we tell the node to take ownership of the material, so we
do not have to explicitly memorymanage it.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 8
+ \snippet scenegraph/simplematerial/simplematerial.cpp 8
Since the Item is providing its own graphics to the scene graph,
we set the flag \l QQuickItem::ItemHasContents.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 9
+ \snippet scenegraph/simplematerial/simplematerial.cpp 9
Whenever the Item has changed graphically, the \l
QQuickItem::updatePaintNode() function is called.
@@ -157,23 +157,23 @@
state. Finally, we notify the scene graph that the node has
undergone changes to its geometry and material.
- \snippet quick/scenegraph/simplematerial/simplematerial.cpp 11
+ \snippet scenegraph/simplematerial/simplematerial.cpp 11
The \c main() function of the application adds the custom QML type
using \l qmlRegisterType() and opens up a \l QQuickView with our
QML file.
- \snippet quick/scenegraph/simplematerial/main.qml 1
+ \snippet scenegraph/simplematerial/main.qml 1
In the QML file, we import our custom type so we can instantiate
it.
- \snippet quick/scenegraph/simplematerial/main.qml 2
+ \snippet scenegraph/simplematerial/main.qml 2
Then we create a column of three instances of our custom item,
each with a different color.
- \snippet quick/scenegraph/simplematerial/main.qml 3
+ \snippet scenegraph/simplematerial/main.qml 3
And finally we overlay a short descriptive text.
diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp
index e415d254a1..3286055496 100644
--- a/examples/quick/scenegraph/textureinthread/main.cpp
+++ b/examples/quick/scenegraph/textureinthread/main.cpp
@@ -38,6 +38,8 @@
**
****************************************************************************/
+#include <QtCore/QThread>
+
#include <QGuiApplication>
#include <QtQuick/QQuickView>
@@ -49,11 +51,31 @@ int main(int argc, char **argv)
QGuiApplication app(argc, argv);
qmlRegisterType<ThreadRenderer>("SceneGraphRendering", 1, 0, "Renderer");
+ int execReturn = 0;
+
+ {
+ QQuickView view;
+
+ // Rendering in a thread introduces a slightly more complicated cleanup
+ // so we ensure that no cleanup of graphics resources happen until the
+ // application is shutting down.
+ view.setPersistentOpenGLContext(true);
+ view.setPersistentSceneGraph(true);
+
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:///scenegraph/textureinsgnode/main.qml"));
+ view.show();
+
+ execReturn = app.exec();
+ }
- QQuickView view;
- view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///scenegraph/textureinsgnode/main.qml"));
- view.show();
+ // As the render threads make use of our QGuiApplication object
+ // to clean up gracefully, wait for them to finish before
+ // QGuiApp is taken off the heap.
+ foreach (QThread *t, ThreadRenderer::threads) {
+ t->wait();
+ delete t;
+ }
- return app.exec();
+ return execReturn;
}
diff --git a/examples/quick/scenegraph/textureinthread/threadrenderer.cpp b/examples/quick/scenegraph/textureinthread/threadrenderer.cpp
index 90b6b49880..7de1d294ba 100644
--- a/examples/quick/scenegraph/textureinthread/threadrenderer.cpp
+++ b/examples/quick/scenegraph/textureinthread/threadrenderer.cpp
@@ -46,10 +46,13 @@
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFramebufferObject>
+#include <QtGui/QGuiApplication>
+#include <QtGui/QOffscreenSurface>
#include <QtQuick/QQuickWindow>
#include <qsgsimpletexturenode.h>
+QList<QThread *> ThreadRenderer::threads;
/*
* The render thread shares a context with the scene graph and will
@@ -60,37 +63,39 @@ class RenderThread : public QThread
{
Q_OBJECT
public:
- RenderThread(const QSize &size)
+ RenderThread(const QSize &size, QOpenGLContext *context)
: m_renderFbo(0)
, m_displayFbo(0)
, m_logoRenderer(0)
+ , m_fakeSurface(0)
, m_size(size)
{
- // Since we're using queued connections, we need affinity to the rendering thread.
- moveToThread(this);
+ ThreadRenderer::threads << this;
// Set up the QOpenGLContext to use for rendering in this thread. It is sharing
// memory space with the GL context of the scene graph. This constructor is called
// during updatePaintNode, so we are currently on the scene graph thread with the
// scene graph's OpenGL context current.
- QOpenGLContext *current = QOpenGLContext::currentContext();
m_context = new QOpenGLContext();
- m_context->setShareContext(current);
- m_context->setFormat(current->format());
- m_context->create();
+ m_context->setShareContext(context);
+ m_context->setFormat(context->format());
m_context->moveToThread(this);
- // We need a non-visible surface to make current...
- m_fakeSurface = new QWindow();
- m_fakeSurface->setGeometry(0, 0, 64, 64);
- m_fakeSurface->setSurfaceType(QWindow::OpenGLSurface);
- m_fakeSurface->setFormat(current->format());
+ // We need a non-visible surface to make current in the other thread
+ // and QWindows must be created and managed on the GUI thread.
+ m_fakeSurface = new QOffscreenSurface();
+ m_fakeSurface->setFormat(context->format());
m_fakeSurface->create();
}
+ void setSurface(QOffscreenSurface *surface) { m_fakeSurface = surface; }
+
public slots:
void renderNext()
{
+ if (!m_context->isValid())
+ m_context->create();
+
m_context->makeCurrent(m_fakeSurface);
if (!m_renderFbo) {
@@ -119,6 +124,23 @@ public slots:
emit textureReady(m_displayFbo->texture(), m_size);
}
+ void shutDown()
+ {
+ m_context->makeCurrent(m_fakeSurface);
+ delete m_renderFbo;
+ delete m_displayFbo;
+ delete m_logoRenderer;
+ m_context->doneCurrent();
+ delete m_context;
+
+ // schedule this to be deleted only after we're done cleaning up
+ m_fakeSurface->deleteLater();
+
+ // Stop event processing, move the thread to GUI and make sure it is deleted.
+ exit();
+ moveToThread(QGuiApplication::instance()->thread());
+ }
+
signals:
void textureReady(int id, const QSize &size);
@@ -128,7 +150,7 @@ private:
LogoRenderer *m_logoRenderer;
- QWindow *m_fakeSurface;
+ QOffscreenSurface *m_fakeSurface;
QOpenGLContext *m_context;
QSize m_size;
};
@@ -209,19 +231,35 @@ private:
ThreadRenderer::ThreadRenderer()
+ : m_renderThread(0)
{
setFlag(ItemHasContents, true);
+ polish();
}
+void ThreadRenderer::updatePolish()
+{
+ if (!window() || !window()->openglContext())
+ return;
+ m_renderThread = new RenderThread(QSize(512, 512), window()->openglContext());
+ m_renderThread->moveToThread(m_renderThread);
+ m_renderThread->start();
+ connect(window(), SIGNAL(sceneGraphInvalidated()), m_renderThread, SLOT(shutDown()), Qt::QueuedConnection);
+}
QSGNode *ThreadRenderer::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
+ if (!m_renderThread) {
+ polish();
+ update();
+ return 0;
+ }
+
TextureNode *node = static_cast<TextureNode *>(oldNode);
if (!node) {
node = new TextureNode(window());
- m_renderThread = new RenderThread(QSize(512, 512));
/* Set up connections to get the production of FBO textures in sync with vsync on the
* rendering thread.
@@ -242,9 +280,6 @@ QSGNode *ThreadRenderer::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
connect(window(), SIGNAL(beforeRendering()), node, SLOT(prepareNode()), Qt::DirectConnection);
connect(node, SIGNAL(textureInUse()), m_renderThread, SLOT(renderNext()), Qt::QueuedConnection);
- // Start the render thread and enter let it process events.
- m_renderThread->start();
-
// Get the production of FBO textures started..
QMetaObject::invokeMethod(m_renderThread, "renderNext", Qt::QueuedConnection);
}
diff --git a/examples/quick/scenegraph/textureinthread/threadrenderer.h b/examples/quick/scenegraph/textureinthread/threadrenderer.h
index f12e6404e5..8c68e27d92 100644
--- a/examples/quick/scenegraph/textureinthread/threadrenderer.h
+++ b/examples/quick/scenegraph/textureinthread/threadrenderer.h
@@ -52,9 +52,15 @@ class ThreadRenderer : public QQuickItem
public:
ThreadRenderer();
+ static QList<QThread *> threads;
+
+public slots:
+ void updatePolish();
+
protected:
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
+
private:
RenderThread *m_renderThread;
};
diff --git a/examples/quick/shadereffects/doc/src/shadereffects.qdoc b/examples/quick/shadereffects/doc/src/shadereffects.qdoc
index 5d1547a1fe..6f6311a5ae 100644
--- a/examples/quick/shadereffects/doc/src/shadereffects.qdoc
+++ b/examples/quick/shadereffects/doc/src/shadereffects.qdoc
@@ -32,7 +32,7 @@
\ingroup qtquickexamples
This example demonstrates a couple of visual effects that you can perform
- with shaders in QtQuick 2.0
+ with shaders in \l {Qt Quick}.
ShaderEffects typically operate on other types, using a ShaderEffectSource
\snippet quick/shadereffects/shadereffects.qml source
diff --git a/examples/quick/views/doc/src/views.qdoc b/examples/quick/views/doc/src/views.qdoc
index cc8112f4dd..21a2d2e5e0 100644
--- a/examples/quick/views/doc/src/views.qdoc
+++ b/examples/quick/views/doc/src/views.qdoc
@@ -32,7 +32,7 @@
\image qml-modelviews-example.png
\ingroup qtquickexamples
- This is a collection of small QML examples relating to model and view functionality. They demonstrate how to show data from a model using the QtQuick view types.
+ This is a collection of small QML examples relating to model and view functionality. They demonstrate how to show data from a model using the \l {Qt Quick} view types.
\section2 GridView and PathView demonstrate usage of these types to display views.
\snippet quick/views/gridview/gridview-example.qml 0