diff options
Diffstat (limited to 'src/render/renderers')
11 files changed, 40 insertions, 577 deletions
diff --git a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp index bedc7f61c..4b4199820 100644 --- a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp +++ b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp @@ -1572,7 +1572,8 @@ void SubmissionContext::blitFramebuffer(Qt3DCore::QNodeId inputRenderTargetId, const GLenum mode = interpolationMethod ? GL_NEAREST : GL_LINEAR; m_glHelper->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, - GL_COLOR_BUFFER_BIT, mode); + GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT, + mode); // Reset draw buffer bindFramebuffer(lastDrawFboId, GraphicsHelperInterface::FBOReadAndDraw); diff --git a/src/render/renderers/opengl/jobs/renderviewjobutils.cpp b/src/render/renderers/opengl/jobs/renderviewjobutils.cpp index c70f82dea..fee1cc4b5 100644 --- a/src/render/renderers/opengl/jobs/renderviewjobutils.cpp +++ b/src/render/renderers/opengl/jobs/renderviewjobutils.cpp @@ -512,27 +512,24 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper(ShaderData * // If the property needs to be transformed, we transform it here as // the shaderdata cannot hold transformed properties for multiple // thread contexts at once - if (currentShaderData->propertyTransformType(qmlPropertyName) != ShaderData::NoTransform) - activeUniformNamesToValue.insert(StringToInt::lookupId(varName), - currentShaderData->getTransformedProperty(qmlPropertyName, viewMatrix)); - else - activeUniformNamesToValue.insert(StringToInt::lookupId(varName), value); + activeUniformNamesToValue.insert(StringToInt::lookupId(varName), + currentShaderData->getTransformedProperty(qmlPropertyName.toLatin1(), viewMatrix)); } } } void UniformBlockValueBuilder::buildActiveUniformNameValueMapStructHelper(ShaderData *rShaderData, const QString &blockName, const QString &qmlPropertyName) { - const QHash<QString, QVariant> &properties = rShaderData->properties(); - QHash<QString, QVariant>::const_iterator it = properties.begin(); - const QHash<QString, QVariant>::const_iterator end = properties.end(); + const QHash<QString, ShaderData::PropertyValue> &properties = rShaderData->properties(); + auto it = properties.begin(); + const auto end = properties.end(); while (it != end) { const auto prefix = qmlPropertyName.isEmpty() ? QLatin1String("") : QLatin1String("."); buildActiveUniformNameValueMapHelper(rShaderData, blockName + prefix + qmlPropertyName, it.key(), - it.value()); + it.value().value); ++it; } } diff --git a/src/render/renderers/opengl/renderer/commandthread.cpp b/src/render/renderers/opengl/renderer/commandthread.cpp deleted file mode 100644 index a518d3b68..000000000 --- a/src/render/renderers/opengl/renderer/commandthread.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $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 -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** 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$ -** -****************************************************************************/ - -#include "commandthread_p.h" -#include <Qt3DRender/private/glcommands_p.h> -#include <Qt3DRender/private/offscreensurfacehelper_p.h> -#include <Qt3DRender/private/graphicscontext_p.h> -#include <Qt3DRender/private/shadercache_p.h> -#include <QOpenGLContext> -#include <QOffscreenSurface> -#include <QDebug> - -QT_BEGIN_NAMESPACE - -namespace Qt3DRender { - -namespace Render { - -CommandThread::CommandThread(Renderer *renderer) - : QThread() - , m_renderer(renderer) - , m_waitForStartSemaphore(0) - , m_initializedSemaphore(0) - , m_commandRequestedSemaphore(0) - , m_commandExecutionSemaphore(0) - , m_mainContext(nullptr) - , m_shaderCache(nullptr) - , m_offsreenSurfaceHelper(nullptr) - , m_currentCommand(nullptr) - , m_running(0) -{ -} - -CommandThread::~CommandThread() -{ - Q_ASSERT(!isRunning()); -} - -void CommandThread::setShaderCache(ShaderCache *shaderCache) -{ - m_shaderCache = shaderCache; -} - -// Called by RenderThread or MainThread (Scene3d) -void CommandThread::initialize(QOpenGLContext *mainContext, OffscreenSurfaceHelper *offsreenSurfaceHelper) -{ - // Start the thread - start(); - - // Wait for thread to be started - m_waitForStartSemaphore.acquire(); - - m_mainContext = mainContext; - m_offsreenSurfaceHelper = offsreenSurfaceHelper; - Q_ASSERT(m_mainContext && offsreenSurfaceHelper); - - // Initialize shared context and resources for the thread. This must be - // done here since some platforms do not allow context sharing to be set up - // with contexts created on different threads. (Windows with WGL, in - // particular; resource sharing works fine later on, what matters is the - // thread the wglShareLists call is made on) - m_localContext.reset(new QOpenGLContext()); - m_localContext->setFormat(m_mainContext->format()); - m_localContext->setShareContext(m_mainContext); - if (!m_localContext->create()) - qWarning("CommandThread: Failed to create local context"); - m_localContext->moveToThread(this); - - m_running.fetchAndStoreOrdered(1); - - // Allow thread to proceed - m_initializedSemaphore.release(); -} - -// Called by RenderThread or MainThread (Scene3D) -void CommandThread::shutdown() -{ - m_running.fetchAndStoreOrdered(0); - - // Unblock thread - m_commandRequestedSemaphore.release(1); - - // Wait for thread to exit - wait(); - - // Reset semaphores (in case we ever want to restart) - m_waitForStartSemaphore.acquire(m_waitForStartSemaphore.available()); - m_initializedSemaphore.acquire(m_initializedSemaphore.available()); - m_commandRequestedSemaphore.acquire(m_commandRequestedSemaphore.available()); - m_commandExecutionSemaphore.acquire(m_commandExecutionSemaphore.available()); - m_localContext.reset(); -} - -// Any thread can call this, this is a blocking command -void CommandThread::executeCommand(GLCommand *command) -{ - if (!isRunning()) - return; - - // We lock to prevent any other call to executeCommand to be executed - // before we have received the result of our command - m_blockingCallerMutex.lock(); - - // Store command to be executed - m_currentCommand = command; - - // Allow thread to proceed and execute command - m_commandRequestedSemaphore.release(); - - // Wait for thread to be done - m_commandExecutionSemaphore.acquire(); - - // Reset command - m_currentCommand = nullptr; - - // Unlock blocking semaphore so that other calls to executeCommand - // can proceed - m_blockingCallerMutex.unlock(); -} - -void CommandThread::run() -{ - // Allow initialize to proceed - m_waitForStartSemaphore.release(); - - // Wait for initialize to be completed - m_initializedSemaphore.acquire(); - - Q_ASSERT(m_mainContext && m_shaderCache); - - // Initialize GraphicsContext - m_graphicsContext.reset(new GraphicsContext()); - m_graphicsContext->setShaderCache(m_shaderCache); - m_graphicsContext->setOpenGLContext(m_localContext.data()); - - bool initialized = false; - while (true) { - - // Wait for command - m_commandRequestedSemaphore.acquire(); - - // Are we still running? - if (!m_running.loadRelaxed()) { - m_graphicsContext->doneCurrent(); - // to prevent executeCommand being locked - m_commandExecutionSemaphore.release(); - break; - } - - if (Q_UNLIKELY(!initialized)) { - QOffscreenSurface *offscreenSurface = m_offsreenSurfaceHelper->offscreenSurface(); - Q_ASSERT(offscreenSurface); - m_graphicsContext->makeCurrent(offscreenSurface); - initialized = true; - } - - m_currentCommand->execute(m_renderer, m_graphicsContext.data()); - - // Allow caller to proceed as we are done with the command - m_commandExecutionSemaphore.release(); - } -} - -} // Render - -} // Qt3DRender - -QT_END_NAMESPACE diff --git a/src/render/renderers/opengl/renderer/commandthread_p.h b/src/render/renderers/opengl/renderer/commandthread_p.h deleted file mode 100644 index 0508675c4..000000000 --- a/src/render/renderers/opengl/renderer/commandthread_p.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $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 -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** 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$ -** -****************************************************************************/ - -#ifndef QT3DRENDER_RENDER_COMMANDTHREAD_P_H -#define QT3DRENDER_RENDER_COMMANDTHREAD_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/QThread> -#include <QtCore/QSemaphore> -#include <QtCore/QMutex> - -QT_BEGIN_NAMESPACE - -class QOpenGLContext; - -namespace Qt3DRender { - -namespace Render { - -class Renderer; -class GLCommand; -class OffscreenSurfaceHelper; -class GraphicsContext; -class ShaderCache; - -class CommandThread : public QThread -{ - Q_OBJECT -public: - explicit CommandThread(Renderer *renderer); - ~CommandThread(); - - Render::Renderer* renderer() const { return m_renderer; } - - void setShaderCache(ShaderCache *shaderCache); - ShaderCache *shaderCache() const { return m_shaderCache; } - - void initialize(QOpenGLContext *mainContext, OffscreenSurfaceHelper *offsreenSurfaceHelper); - void shutdown(); - - void executeCommand(GLCommand *command); - -private: - void run() override; - void executeCommandInternal(Qt3DRender::Render::GLCommand *command); - -private: - Renderer* m_renderer; - QSemaphore m_waitForStartSemaphore; - QSemaphore m_initializedSemaphore; - QSemaphore m_commandRequestedSemaphore; - QSemaphore m_commandExecutionSemaphore; - QMutex m_blockingCallerMutex; - QOpenGLContext *m_mainContext; - ShaderCache *m_shaderCache; - OffscreenSurfaceHelper *m_offsreenSurfaceHelper; - QScopedPointer<QOpenGLContext> m_localContext; - QScopedPointer<GraphicsContext> m_graphicsContext; - GLCommand *m_currentCommand; - QAtomicInt m_running; -}; - -} // Render - -} // Qt3DRender - -QT_END_NAMESPACE - -#endif // QT3DRENDER_RENDER_COMMANDTHREAD_P_H diff --git a/src/render/renderers/opengl/renderer/glcommands.cpp b/src/render/renderers/opengl/renderer/glcommands.cpp deleted file mode 100644 index fd7ee9fe8..000000000 --- a/src/render/renderers/opengl/renderer/glcommands.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $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 -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** 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$ -** -****************************************************************************/ - -#include "glcommands_p.h" -#include <Qt3DRender/private/renderer_p.h> -#include <Qt3DRender/private/graphicscontext_p.h> -#include <Qt3DRender/private/nodemanagers_p.h> - -QT_BEGIN_NAMESPACE - -namespace Qt3DRender { - -namespace Render { - -LoadShaderCommand::LoadShaderCommand(Shader *shader) - : m_shader(shader) -{ - Q_ASSERT(m_shader); -} - -void LoadShaderCommand::execute(Renderer *renderer, GraphicsContext *ctx) -{ - NodeManagers *nodeManagers = renderer->nodeManagers(); - ctx->loadShader(m_shader, nodeManagers->shaderManager()); -} - -} // Render - -} // Qt3DRender - -QT_END_NAMESPACE diff --git a/src/render/renderers/opengl/renderer/glcommands_p.h b/src/render/renderers/opengl/renderer/glcommands_p.h deleted file mode 100644 index 5ed360759..000000000 --- a/src/render/renderers/opengl/renderer/glcommands_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $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 -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** 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$ -** -****************************************************************************/ - -#ifndef QT3DRENDER_RENDER_GLCOMMANDS_P_H -#define QT3DRENDER_RENDER_GLCOMMANDS_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <Qt3DRender/qt3drender_global.h> - -QT_BEGIN_NAMESPACE - - -namespace Qt3DRender { - -namespace Render { - -class GraphicsContext; -class Renderer; -class Shader; - -class GLCommand -{ -public: - virtual void execute(Renderer *renderer, GraphicsContext *ctx) = 0; -}; - -class Q_AUTOTEST_EXPORT LoadShaderCommand : public GLCommand -{ -public: - explicit LoadShaderCommand(Shader *shader); - Shader *shader() const { return m_shader; } - void execute(Renderer *renderer, GraphicsContext *ctx) Q_DECL_OVERRIDE; - -private: - Shader *m_shader = nullptr; -}; -} // Render - -} // Qt3DRender - -QT_END_NAMESPACE - -#endif // QT3DRENDER_RENDER_GLCOMMANDS_P_H diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp index 45f13c424..42af03d11 100644 --- a/src/render/renderers/opengl/renderer/renderer.cpp +++ b/src/render/renderers/opengl/renderer/renderer.cpp @@ -89,14 +89,13 @@ #include <Qt3DRender/private/buffercapture_p.h> #include <Qt3DRender/private/offscreensurfacehelper_p.h> #include <Qt3DRender/private/renderviewbuilder_p.h> -#include <Qt3DRender/private/commandthread_p.h> -#include <Qt3DRender/private/glcommands_p.h> #include <Qt3DRender/private/setfence_p.h> #include <Qt3DRender/private/subtreeenabler_p.h> #include <Qt3DRender/qcameralens.h> #include <Qt3DCore/private/qeventfilterservice_p.h> #include <Qt3DCore/private/qabstractaspectjobmanager_p.h> +#include <Qt3DCore/private/qaspectmanager_p.h> #if QT_CONFIG(qt3d_profile_jobs) #include <Qt3DCore/private/aspectcommanddebugger_p.h> @@ -165,7 +164,6 @@ Renderer::Renderer(QRenderAspect::RenderType type) , m_submissionContext(nullptr) , m_renderQueue(new RenderQueue()) , m_renderThread(type == QRenderAspect::Threaded ? new RenderThread(this) : nullptr) - , m_commandThread(new CommandThread(this)) , m_vsyncFrameAdvanceService(new VSyncFrameAdvanceService(m_renderThread != nullptr)) , m_waitForInitializationToBeCompleted(0) , m_hasBeenInitializedMutex() @@ -196,7 +194,9 @@ Renderer::Renderer(QRenderAspect::RenderType type) , m_bufferGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForDirtyBuffers(); }, JobTypes::DirtyBufferGathering)) , m_vaoGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForAbandonedVaos(); }, JobTypes::DirtyVaoGathering)) , m_textureGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForDirtyTextures(); }, JobTypes::DirtyTextureGathering)) - , m_sendTextureChangesToFrontendJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { sendTextureChangesToFrontend(); }, JobTypes::SendTextureChangesToFrontend)) + , m_sendTextureChangesToFrontendJob(decltype(m_sendTextureChangesToFrontendJob)::create([] {}, + [this] (Qt3DCore::QAspectManager *m) { sendTextureChangesToFrontend(m); }, + JobTypes::SendTextureChangesToFrontend)) , m_sendSetFenceHandlesToFrontendJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { sendSetFenceHandlesToFrontend(); }, JobTypes::SendSetFenceHandlesToFrontend)) , m_sendDisablesToFrontendJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { sendDisablesToFrontend(); }, JobTypes::SendDisablesToFrontend)) , m_introspectShaderJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { reloadDirtyShaders(); }, JobTypes::DirtyShaderGathering)) @@ -331,18 +331,11 @@ QOpenGLContext *Renderer::shareContext() const : nullptr); } -// Executed in the command thread +// Executed in the reloadDirtyShader job void Renderer::loadShader(Shader *shader, HShader shaderHandle) { -#ifdef SHADER_LOADING_IN_COMMAND_THREAD - Q_UNUSED(shaderHandle); - Profiling::GLTimeRecorder recorder(Profiling::ShaderUpload); - LoadShaderCommand cmd(shader); - m_commandThread->executeCommand(&cmd); -#else Q_UNUSED(shader); m_dirtyShaders.push_back(shaderHandle); -#endif } void Renderer::setOpenGLContext(QOpenGLContext *context) @@ -403,7 +396,6 @@ void Renderer::initialize() // Set shader cache on submission context and command thread m_submissionContext->setShaderCache(m_shaderCache); - m_commandThread->setShaderCache(m_shaderCache); // Note: we don't have a surface at this point // The context will be made current later on (at render time) @@ -416,13 +408,6 @@ void Renderer::initialize() // (MS Windows), an offscreen surface is just a hidden QWindow. m_format = ctx->format(); QMetaObject::invokeMethod(m_offscreenHelper, "createOffscreenSurface"); - - // Initialize command thread (uses the offscreen surface to make its own ctx current) - m_commandThread->initialize(ctx, m_offscreenHelper); - // Note: the offscreen surface is also used at shutdown time to release resources - // of the submission gl context (when the window is already gone). - // By that time (in releaseGraphicResources), the commandThread has been destroyed - // and the offscreenSurface can be reused } // Awake setScenegraphRoot in case it was waiting @@ -454,8 +439,6 @@ void Renderer::shutdown() m_renderQueue->reset(); lockRenderQueue.unlock(); - m_commandThread->shutdown(); - if (!m_renderThread) { releaseGraphicsResources(); } else { @@ -1167,24 +1150,39 @@ void Renderer::reloadDirtyShaders() } } -// Executed in a job -void Renderer::sendTextureChangesToFrontend() +// Executed in a job (as postFrame) +void Renderer::sendTextureChangesToFrontend(Qt3DCore::QAspectManager *manager) { const QVector<QPair<Texture::TextureUpdateInfo, Qt3DCore::QNodeIdVector>> updateTextureProperties = std::move(m_updatedTextureProperties); for (const auto &pair : updateTextureProperties) { - // Prepare change notification - const Qt3DCore::QNodeIdVector targetIds = pair.second; for (const Qt3DCore::QNodeId targetId: targetIds) { + // Lookup texture Texture *t = m_nodesManager->textureManager()->lookupResource(targetId); + // If backend texture is Dirty, some property has changed and the properties we are + // about to send are already outdate + if (t == nullptr || t->dirtyFlags() != Texture::NotDirty) + continue; - // Texture might have been deleted between previous and current frame - if (t == nullptr) + QAbstractTexture *texture = static_cast<QAbstractTexture *>(manager->lookupNode(targetId)); + if (!texture) continue; + const TextureProperties &properties = pair.first.properties; + + const bool blocked = texture->blockNotifications(true); + texture->setWidth(properties.width); + texture->setHeight(properties.height); + texture->setDepth(properties.depth); + texture->setLayers(properties.layers); + texture->setFormat(properties.format); + texture->blockNotifications(blocked); + + QAbstractTexturePrivate *dTexture = static_cast<QAbstractTexturePrivate *>(QNodePrivate::get(texture)); - // Send change and update backend - t->updatePropertiesAndNotify(pair.first); + dTexture->setStatus(properties.status); + dTexture->setHandleType(pair.first.handleType); + dTexture->setHandle(pair.first.handle); } } } @@ -1807,11 +1805,12 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() const bool frameGraphDirty = dirtyBitsForFrame & AbstractRenderer::FrameGraphDirty; const bool layersDirty = dirtyBitsForFrame & AbstractRenderer::LayersDirty; const bool layersCacheNeedsToBeRebuilt = layersDirty || entitiesEnabledDirty || frameGraphDirty; + const bool shadersDirty = dirtyBitsForFrame & AbstractRenderer::ShadersDirty; const bool materialDirty = dirtyBitsForFrame & AbstractRenderer::MaterialDirty; const bool lightsDirty = dirtyBitsForFrame & AbstractRenderer::LightsDirty; const bool computeableDirty = dirtyBitsForFrame & AbstractRenderer::ComputeDirty; const bool renderableDirty = dirtyBitsForFrame & AbstractRenderer::GeometryDirty; - const bool materialCacheNeedsToBeRebuilt = materialDirty || frameGraphDirty; + const bool materialCacheNeedsToBeRebuilt = shadersDirty || materialDirty || frameGraphDirty; // Rebuild Entity Layers list if layers are dirty if (layersDirty) diff --git a/src/render/renderers/opengl/renderer/renderer.pri b/src/render/renderers/opengl/renderer/renderer.pri index 34f6064bd..849bac702 100644 --- a/src/render/renderers/opengl/renderer/renderer.pri +++ b/src/render/renderers/opengl/renderer/renderer.pri @@ -1,8 +1,6 @@ INCLUDEPATH += $$PWD SOURCES += \ - $$PWD/commandthread.cpp \ - $$PWD/glcommands.cpp \ $$PWD/openglvertexarrayobject.cpp \ $$PWD/rendercommand.cpp \ $$PWD/renderer.cpp \ @@ -12,8 +10,6 @@ SOURCES += \ $$PWD/shaderparameterpack.cpp HEADERS += \ - $$PWD/commandthread_p.h \ - $$PWD/glcommands_p.h \ $$PWD/openglvertexarrayobject_p.h \ $$PWD/renderercache_p.h \ $$PWD/rendercommand_p.h \ diff --git a/src/render/renderers/opengl/renderer/renderer_p.h b/src/render/renderers/opengl/renderer/renderer_p.h index c7b4f8805..41a071290 100644 --- a/src/render/renderers/opengl/renderer/renderer_p.h +++ b/src/render/renderers/opengl/renderer/renderer_p.h @@ -144,7 +144,6 @@ class RenderView; class Effect; class RenderPass; class RenderThread; -class CommandThread; class RenderStateSet; class VSyncFrameAdvanceService; class PickEventFilter; @@ -320,7 +319,6 @@ private: RenderQueue *m_renderQueue; QScopedPointer<RenderThread> m_renderThread; - QScopedPointer<CommandThread> m_commandThread; QScopedPointer<VSyncFrameAdvanceService> m_vsyncFrameAdvanceService; QSemaphore m_submitRenderViewsSemaphore; @@ -379,7 +377,7 @@ private: GenericLambdaJobPtr<std::function<void ()>> m_bufferGathererJob; GenericLambdaJobPtr<std::function<void ()>> m_vaoGathererJob; GenericLambdaJobPtr<std::function<void ()>> m_textureGathererJob; - GenericLambdaJobPtr<std::function<void ()>> m_sendTextureChangesToFrontendJob; + GenericLambdaJobAndPostFramePtr<std::function<void ()>, std::function<void (Qt3DCore::QAspectManager *)>> m_sendTextureChangesToFrontendJob; GenericLambdaJobPtr<std::function<void ()>> m_sendSetFenceHandlesToFrontendJob; GenericLambdaJobPtr<std::function<void ()>> m_sendDisablesToFrontendJob; IntrospectShadersJobPtr m_introspectShaderJob; @@ -391,7 +389,7 @@ private: void lookForDownloadableBuffers(); void lookForDirtyTextures(); void reloadDirtyShaders(); - void sendTextureChangesToFrontend(); + void sendTextureChangesToFrontend(Qt3DCore::QAspectManager *manager); void sendSetFenceHandlesToFrontend(); void sendDisablesToFrontend(); diff --git a/src/render/renderers/opengl/renderer/renderview.cpp b/src/render/renderers/opengl/renderer/renderview.cpp index 420b32325..8fbe8e188 100644 --- a/src/render/renderers/opengl/renderer/renderview.cpp +++ b/src/render/renderers/opengl/renderer/renderview.cpp @@ -849,56 +849,6 @@ void RenderView::setUniformBlockValue(ShaderParameterPack &uniformPack, uniformPack.setUniformBuffer(std::move(uniformBlockUBO)); // Buffer update to GL buffer will be done at render time } - - - //ShaderData *shaderData = nullptr; - // if ((shaderData = m_manager->shaderDataManager()->lookupResource(value.value<Qt3DCore::QNodeId>())) != nullptr) { - // UBO are indexed by <ShaderId, ShaderDataId> so that a same QShaderData can be used among different shaders - // while still making sure that if they have a different layout everything will still work - // If two shaders define the same block with the exact same layout, in that case the UBO could be shared - // but how do we know that ? We'll need to compare ShaderUniformBlocks - - // Note: we assume that if a buffer is shared across multiple shaders - // then it implies that they share the same layout - - // Temporarly disabled - - // BufferShaderKey uboKey(shaderData->peerId(), - // shader->peerId()); - - // BlockToUBO uniformBlockUBO; - // uniformBlockUBO.m_blockIndex = block.m_index; - // uniformBlockUBO.m_shaderDataID = shaderData->peerId(); - // bool uboNeedsUpdate = false; - - // // build UBO at uboId if not created before - // if (!m_manager->glBufferManager()->contains(uboKey)) { - // m_manager->glBufferManager()->getOrCreateResource(uboKey); - // uboNeedsUpdate = true; - // } - - // // If shaderData has been updated (property has changed or one of the nested properties has changed) - // // foreach property defined in the QShaderData, we try to fill the value of the corresponding active uniform(s) - // // for all the updated properties (all the properties if the UBO was just created) - // if (shaderData->updateViewTransform(*m_data->m_viewMatrix) || uboNeedsUpdate) { - // // Clear previous values remaining in the hash - // m_data->m_uniformBlockBuilder.activeUniformNamesToValue.clear(); - // // Update only update properties if uboNeedsUpdate is true, otherwise update the whole block - // m_data->m_uniformBlockBuilder.updatedPropertiesOnly = uboNeedsUpdate; - // // Retrieve names and description of each active uniforms in the uniform block - // m_data->m_uniformBlockBuilder.uniforms = shader->activeUniformsForUniformBlock(block.m_index); - // // Builds the name-value map for the block - // m_data->m_uniformBlockBuilder.buildActiveUniformNameValueMapStructHelper(shaderData, block.m_name); - // if (!uboNeedsUpdate) - // shaderData->markDirty(); - // // copy the name-value map into the BlockToUBO - // uniformBlockUBO.m_updatedProperties = m_data->m_uniformBlockBuilder.activeUniformNamesToValue; - // uboNeedsUpdate = true; - // } - - // uniformBlockUBO.m_needsUpdate = uboNeedsUpdate; - // uniformPack.setUniformBuffer(std::move(uniformBlockUBO)); - // } } } diff --git a/src/render/renderers/opengl/textures/gltexture.cpp b/src/render/renderers/opengl/textures/gltexture.cpp index 11d2c2be9..1b5a972ec 100644 --- a/src/render/renderers/opengl/textures/gltexture.cpp +++ b/src/render/renderers/opengl/textures/gltexture.cpp @@ -54,9 +54,6 @@ #include <Qt3DRender/private/qabstracttexture_p.h> #include <Qt3DRender/private/renderbuffer_p.h> #include <Qt3DRender/private/qtextureimagedata_p.h> -#include <Qt3DCore/qpropertyupdatedchange.h> -#include <Qt3DCore/qpropertynodeaddedchange.h> -#include <Qt3DCore/qpropertynoderemovedchange.h> #if !defined(QT_OPENGL_ES_2) #include <QOpenGLFunctions_3_1> |