aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgrenderloop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/qsgrenderloop.cpp')
-rw-r--r--src/quick/scenegraph/qsgrenderloop.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/quick/scenegraph/qsgrenderloop.cpp b/src/quick/scenegraph/qsgrenderloop.cpp
index ac4c315ccb..443afb00ac 100644
--- a/src/quick/scenegraph/qsgrenderloop.cpp
+++ b/src/quick/scenegraph/qsgrenderloop.cpp
@@ -371,7 +371,7 @@ void QSGGuiThreadRenderLoop::windowDestroyed(QQuickWindow *window)
d->cleanupNodesOnShutdown();
#if QT_CONFIG(quick_shadereffect)
- QSGRhiShaderEffectNode::cleanupMaterialTypeCache();
+ QSGRhiShaderEffectNode::cleanupMaterialTypeCache(window);
#endif
if (m_windows.size() == 0) {
@@ -442,7 +442,7 @@ bool QSGGuiThreadRenderLoop::ensureRhi(QQuickWindow *window, WindowData &data)
{
QQuickWindowPrivate *cd = QQuickWindowPrivate::get(window);
QSGRhiSupport *rhiSupport = QSGRhiSupport::instance();
- bool current = false;
+ bool ok = rhi != nullptr;
if (!rhi) {
// This block below handles both the initial QRhi initialization and
@@ -463,7 +463,9 @@ bool QSGGuiThreadRenderLoop::ensureRhi(QQuickWindow *window, WindowData &data)
data.rhiDeviceLost = false;
- current = true;
+ ok = true;
+ // We need to guarantee that sceneGraphInitialized is
+ // emitted with a context current, if running with OpenGL.
rhi->makeThreadLocalNativeContextCurrent();
// The sample count cannot vary between windows as we use the same
@@ -483,16 +485,8 @@ bool QSGGuiThreadRenderLoop::ensureRhi(QQuickWindow *window, WindowData &data)
data.rhiDoomed = true;
handleContextCreationFailure(window);
}
- // otherwise no error, will retry on a subsequent rendering attempt
+ // otherwise no error, just return false so that we will retry on a subsequent rendering attempt
}
- } else {
- current = true;
- // With the rhi making the (OpenGL) context current serves only one
- // purpose: to enable external OpenGL rendering connected to one of
- // the QQuickWindow signals (beforeSynchronizing, beforeRendering,
- // etc.) to function like it did on the direct OpenGL path. For our
- // own rendering this call would not be necessary.
- rhi->makeThreadLocalNativeContextCurrent();
}
if (rhi && !cd->swapchain) {
@@ -541,7 +535,7 @@ bool QSGGuiThreadRenderLoop::ensureRhi(QQuickWindow *window, WindowData &data)
window->installEventFilter(this);
}
- return current;
+ return ok;
}
void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
@@ -655,6 +649,12 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
}
}
+ // Enable external OpenGL rendering connected to one of the
+ // QQuickWindow signals (beforeSynchronizing, beforeRendering,
+ // etc.) to function like it did on the direct OpenGL path,
+ // i.e. ensure there is a context current, just in case.
+ rhi->makeThreadLocalNativeContextCurrent();
+
cd->syncSceneGraph();
if (lastDirtyWindow)
rc->endSync();
@@ -765,6 +765,7 @@ QImage QSGGuiThreadRenderLoop::grab(QQuickWindow *window)
// renderWindow() so one cannot get to grab() without having done at least
// one on-screen frame.
cd->rhi->beginFrame(cd->swapchain);
+ rhi->makeThreadLocalNativeContextCurrent(); // for custom GL rendering before/during/after sync
cd->syncSceneGraph();
cd->renderSceneGraph(window->size());
QImage image = QSGRhiSupport::instance()->grabAndBlockInCurrentFrame(rhi, cd->swapchain->currentFrameCommandBuffer());