Make example work on Windows
authorGunnar Sletta <gunnar.sletta@digia.com>
Mon, 7 Oct 2013 09:03:05 +0000 (11:03 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 22 Oct 2013 08:00:04 +0000 (10:00 +0200)
Change-Id: I75a035939a390de8cdae03c11599efa0b7ed68df
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
examples/quick/scenegraph/textureinthread/threadrenderer.cpp
examples/quick/scenegraph/textureinthread/threadrenderer.h

index 7de1d29..072b4b9 100644 (file)
@@ -79,6 +79,7 @@ public:
         m_context = new QOpenGLContext();
         m_context->setShareContext(context);
         m_context->setFormat(context->format());
+        m_context->create();
         m_context->moveToThread(this);
 
         // We need a non-visible surface to make current in the other thread
@@ -93,9 +94,6 @@ public:
 public slots:
     void renderNext()
     {
-        if (!m_context->isValid())
-            m_context->create();
-
         m_context->makeCurrent(m_fakeSurface);
 
         if (!m_renderFbo) {
@@ -234,30 +232,22 @@ 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 *)
 {
+    TextureNode *node = static_cast<TextureNode *>(oldNode);
+
     if (!m_renderThread) {
-        polish();
-        update();
-        return 0;
+        QOpenGLContext *current = window()->openglContext();
+        current->doneCurrent();
+        m_renderThread = new RenderThread(QSize(512, 512), current);
+        current->makeCurrent(window());
+        m_renderThread->moveToThread(m_renderThread);
+        m_renderThread->start();
+        connect(window(), SIGNAL(sceneGraphInvalidated()), m_renderThread, SLOT(shutDown()), Qt::QueuedConnection);
     }
 
-    TextureNode *node = static_cast<TextureNode *>(oldNode);
-
     if (!node) {
         node = new TextureNode(window());
 
index 8c68e27..7f720cb 100644 (file)
@@ -54,9 +54,6 @@ public:
 
     static QList<QThread *> threads;
 
-public slots:
-    void updatePolish();
-
 protected:
     QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);