summaryrefslogtreecommitdiffstats
path: root/src/plugins/renderers/opengl/renderer/renderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/renderers/opengl/renderer/renderer.cpp')
-rw-r--r--src/plugins/renderers/opengl/renderer/renderer.cpp114
1 files changed, 67 insertions, 47 deletions
diff --git a/src/plugins/renderers/opengl/renderer/renderer.cpp b/src/plugins/renderers/opengl/renderer/renderer.cpp
index 394e08fd6..24326a546 100644
--- a/src/plugins/renderers/opengl/renderer/renderer.cpp
+++ b/src/plugins/renderers/opengl/renderer/renderer.cpp
@@ -1,13 +1,12 @@
/****************************************************************************
**
** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Copyright (C) 2021 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:COMM$
-**
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
@@ -16,25 +15,26 @@
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
-** $QT_END_LICENSE$
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
+** $QT_END_LICENSE$
**
****************************************************************************/
@@ -594,38 +594,50 @@ void Renderer::releaseGraphicsResources()
QOpenGLContext *context = m_submissionContext->openGLContext();
Q_ASSERT(context);
- if (context->thread() == QThread::currentThread() && context->makeCurrent(offscreenSurface)) {
+ if (context->thread() == QThread::currentThread()) {
+ QSurface *lastContextSurface = context->surface();
- // Clean up the graphics context and any resources
- const std::vector<HGLTexture> &activeTexturesHandles = m_glResourceManagers->glTextureManager()->activeHandles();
- for (const HGLTexture &textureHandle : activeTexturesHandles) {
- GLTexture *tex = m_glResourceManagers->glTextureManager()->data(textureHandle);
- tex->destroy();
- }
+ if (context->makeCurrent(offscreenSurface)) {
+ // Clean up the graphics context and any resources
+ const std::vector<HGLTexture> &activeTexturesHandles = m_glResourceManagers->glTextureManager()->activeHandles();
+ for (const HGLTexture &textureHandle : activeTexturesHandles) {
+ GLTexture *tex = m_glResourceManagers->glTextureManager()->data(textureHandle);
+ tex->destroy();
+ }
- // Do the same thing with buffers
- const std::vector<HGLBuffer> &activeBuffers = m_glResourceManagers->glBufferManager()->activeHandles();
- for (const HGLBuffer &bufferHandle : activeBuffers) {
- GLBuffer *buffer = m_glResourceManagers->glBufferManager()->data(bufferHandle);
- buffer->destroy(m_submissionContext.data());
- }
+ // Do the same thing with buffers
+ const std::vector<HGLBuffer> &activeBuffers = m_glResourceManagers->glBufferManager()->activeHandles();
+ for (const HGLBuffer &bufferHandle : activeBuffers) {
+ GLBuffer *buffer = m_glResourceManagers->glBufferManager()->data(bufferHandle);
+ buffer->destroy(m_submissionContext.data());
+ }
- // Do the same thing with shaders
- const QVector<GLShader *> shaders = m_glResourceManagers->glShaderManager()->takeActiveResources();
- qDeleteAll(shaders);
+ // Do the same thing with shaders
+ const QVector<GLShader *> shaders = m_glResourceManagers->glShaderManager()->takeActiveResources();
+ qDeleteAll(shaders);
- // Do the same thing with VAOs
- const std::vector<HVao> &activeVaos = m_glResourceManagers->vaoManager()->activeHandles();
- for (const HVao &vaoHandle : activeVaos) {
- OpenGLVertexArrayObject *vao = m_glResourceManagers->vaoManager()->data(vaoHandle);
- vao->destroy();
- }
+ // Do the same thing with VAOs
+ const std::vector<HVao> &activeVaos = m_glResourceManagers->vaoManager()->activeHandles();
+ for (const HVao &vaoHandle : activeVaos) {
+ OpenGLVertexArrayObject *vao = m_glResourceManagers->vaoManager()->data(vaoHandle);
+ vao->destroy();
+ }
- m_submissionContext->releaseRenderTargets();
+ m_submissionContext->releaseRenderTargets();
- m_frameProfiler.reset();
- if (m_ownedContext)
- context->doneCurrent();
+ m_frameProfiler.reset();
+ if (m_ownedContext) {
+ context->doneCurrent();
+ } else {
+ // Leave the context in the state we found it in by restoring
+ // its last used surface. This satisfies expectations when used
+ // with QQuickWidgets that surface on current context after
+ // QQuickRenderControl cleanup is the same as prior to the
+ // cleanup. Arguably this could also be checked for in
+ // QQuickWidgetPrivate::invalidateRenderControl.
+ context->makeCurrent(lastContextSurface);
+ }
+ }
} else {
qWarning() << "Failed to make context current: OpenGL resources will not be destroyed";
}
@@ -1168,6 +1180,9 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager)
const std::vector<HShader> &activeShaders = m_nodesManager->shaderManager()->activeHandles();
for (const HShader &handle :activeShaders) {
Shader *s = m_nodesManager->shaderManager()->data(handle);
+ if (!s)
+ continue;
+
if (s->requiresFrontendSync()) {
QShaderProgram *frontend = static_cast<decltype(frontend)>(manager->lookupNode(s->peerId()));
// Could happen as a backend shader might live beyong the frontend
@@ -1872,6 +1887,7 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
// Remove previous dependencies
m_cleanupJob->removeDependency(QWeakPointer<QAspectJob>());
+ const bool dirtyParametersForCurrentFrame = m_dirtyBits.marked & AbstractRenderer::ParameterDirty;
const BackendNodeDirtySet dirtyBitsForFrame = m_dirtyBits.marked | m_dirtyBits.remaining;
m_dirtyBits.marked = {};
m_dirtyBits.remaining = {};
@@ -1939,7 +1955,7 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
m_updatedDisableSubtreeEnablers.push_back(node->peerId());
}
- int idealThreadCount = QThreadPooler::maxThreadCount();
+ int idealThreadCount = Qt3DCore::QAspectJobManager::idealThreadCount();
const int fgBranchCount = m_frameGraphLeaves.size();
if (fgBranchCount > 1) {
@@ -1995,6 +2011,10 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
m_dirtyBits.remaining = dirtyBitsForFrame & notCleared;
+ // Dirty Parameters might need 2 frames to react if the parameter references a texture
+ if (dirtyParametersForCurrentFrame)
+ m_dirtyBits.remaining |= AbstractRenderer::ParameterDirty;
+
return renderBinJobs;
}