summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2016-01-20 14:59:37 +0100
committerTobias Koenig <tobias.koenig@kdab.com>2016-01-20 14:34:29 +0000
commit5d921dda57bff431487e6f1d64ef5111d464655d (patch)
treee312220e9ddec92315de30b9dbc3570ea216c879 /src
parent30152f710ab459c203d3b59d2d0c364af365f92f (diff)
Port FrameGraphManager away from QResourceManager
Change-Id: I7399008adb0f612c78738f58f168fa38cf6ae845 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/render/backend/managers.cpp73
-rw-r--r--src/render/backend/managers_p.h16
-rw-r--r--src/render/backend/render-backend.pri1
-rw-r--r--src/render/backend/renderer.cpp5
-rw-r--r--src/render/framegraph/framegraphnode.cpp63
-rw-r--r--src/render/framegraph/framegraphnode_p.h37
-rw-r--r--src/render/framegraph/framegraphvisitor.cpp2
-rw-r--r--src/render/jobs/pickboundingvolumejob.cpp2
8 files changed, 128 insertions, 71 deletions
diff --git a/src/render/backend/managers.cpp b/src/render/backend/managers.cpp
new file mode 100644
index 000000000..e59db7402
--- /dev/null
+++ b/src/render/backend/managers.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "managers_p.h"
+
+#include <Qt3DRender/private/framegraphnode_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+namespace Render {
+
+bool FrameGraphManager::containsNode(const Qt3DCore::QNodeId &id) const
+{
+ return m_nodes.contains(id);
+}
+
+void FrameGraphManager::appendNode(FrameGraphNode *node)
+{
+ m_nodes.insert(node->peerUuid(), node);
+}
+
+FrameGraphNode* FrameGraphManager::lookupNode(const Qt3DCore::QNodeId &id) const
+{
+ const QHash<Qt3DCore::QNodeId, FrameGraphNode*>::const_iterator it = m_nodes.find(id);
+ if (it == m_nodes.end())
+ return Q_NULLPTR;
+ else
+ return *it;
+}
+
+void FrameGraphManager::releaseNode(const Qt3DCore::QNodeId &id)
+{
+ delete m_nodes.take(id);
+}
+
+} // namespace Render
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/backend/managers_p.h b/src/render/backend/managers_p.h
index e3b9cb9d7..a1f228339 100644
--- a/src/render/backend/managers_p.h
+++ b/src/render/backend/managers_p.h
@@ -135,14 +135,20 @@ public:
EntityManager() {}
};
-class FrameGraphManager : public Qt3DCore::QResourceManager<
- FrameGraphNode *,
- Qt3DCore::QNodeId,
- 8,
- Qt3DCore::ArrayAllocatingPolicy>
+class FrameGraphNode;
+
+class Q_AUTOTEST_EXPORT FrameGraphManager
{
public:
FrameGraphManager() {}
+
+ bool containsNode(const Qt3DCore::QNodeId &id) const;
+ void appendNode(FrameGraphNode *node);
+ FrameGraphNode* lookupNode(const Qt3DCore::QNodeId &id) const;
+ void releaseNode(const Qt3DCore::QNodeId &id);
+
+private:
+ QHash<Qt3DCore::QNodeId, FrameGraphNode*> m_nodes;
};
class LayerManager : public Qt3DCore::QResourceManager<
diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri
index b6c4a77a5..0b7efa5e7 100644
--- a/src/render/backend/render-backend.pri
+++ b/src/render/backend/render-backend.pri
@@ -43,6 +43,7 @@ SOURCES += \
$$PWD/rendertarget.cpp \
$$PWD/renderattachment.cpp \
$$PWD/attachmentpack.cpp \
+ $$PWD/managers.cpp \
$$PWD/platformsurfacefilter.cpp \
$$PWD/cameralens.cpp \
$$PWD/entity.cpp \
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index e6bf0cf86..c9a5b5b0f 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -413,10 +413,7 @@ void Renderer::setFrameGraphRoot(const Qt3DCore::QNodeId fgRootId)
Render::FrameGraphNode *Renderer::frameGraphRoot() const
{
- FrameGraphNode **fgRoot = m_nodesManager->lookupResource<FrameGraphNode*, FrameGraphManager>(m_frameGraphRootUuid);
- if (fgRoot != Q_NULLPTR)
- return *fgRoot;
- return Q_NULLPTR;
+ return m_nodesManager->frameGraphManager()->lookupNode(m_frameGraphRootUuid);
}
// QAspectThread context
diff --git a/src/render/framegraph/framegraphnode.cpp b/src/render/framegraph/framegraphnode.cpp
index 1c913b281..7d3c1d03a 100644
--- a/src/render/framegraph/framegraphnode.cpp
+++ b/src/render/framegraph/framegraphnode.cpp
@@ -74,75 +74,62 @@ FrameGraphManager *FrameGraphNode::manager() const
return m_manager;
}
-void FrameGraphNode::setHandle(HFrameGraphNode handle)
+void FrameGraphNode::setParentId(const Qt3DCore::QNodeId &parentId)
{
- m_handle = handle;
-}
-
-void FrameGraphNode::setParentHandle(HFrameGraphNode parentHandle)
-{
- if (m_parentHandle != parentHandle) {
- m_parentHandle = parentHandle;
- FrameGraphNode **parent = m_manager->data(m_parentHandle);
- if (parent != Q_NULLPTR && *parent != Q_NULLPTR && !(*parent)->m_childrenHandles.contains(m_handle))
- (*parent)->m_childrenHandles.append(m_handle);
+ if (m_parentId != parentId) {
+ m_parentId = parentId;
+ FrameGraphNode *parent = m_manager->lookupNode(m_parentId);
+ if (parent != Q_NULLPTR && !parent->m_childrenIds.contains(peerUuid()))
+ parent->m_childrenIds.append(peerUuid());
}
}
-void FrameGraphNode::appendChildHandle(HFrameGraphNode childHandle)
+void FrameGraphNode::appendChildId(const Qt3DCore::QNodeId &childId)
{
- if (!m_childrenHandles.contains(childHandle)) {
- FrameGraphNode **child = m_manager->data(childHandle);
+ if (!m_childrenIds.contains(childId)) {
+ FrameGraphNode *child = m_manager->lookupNode(childId);
if (child != Q_NULLPTR) {
- m_childrenHandles.append(childHandle);
- (*child)->m_parentHandle = m_handle;
+ m_childrenIds.append(childId);
+ child->m_parentId = peerUuid();
}
}
}
-void FrameGraphNode::removeChildHandle(HFrameGraphNode childHandle)
+void FrameGraphNode::removeChildId(const Qt3DCore::QNodeId &childId)
{
- if (m_childrenHandles.contains(childHandle)) {
- FrameGraphNode **child = m_manager->data(childHandle);
+ if (m_childrenIds.contains(childId)) {
+ FrameGraphNode *child = m_manager->lookupNode(childId);
if (child != Q_NULLPTR) {
- (*child)->m_parentHandle = HFrameGraphNode();
+ child->m_parentId = Qt3DCore::QNodeId();
}
- m_childrenHandles.removeAll(childHandle);
+ m_childrenIds.removeAll(childId);
}
}
-HFrameGraphNode FrameGraphNode::handle() const
+Qt3DCore::QNodeId FrameGraphNode::parentId() const
{
- return m_handle;
+ return m_parentId;
}
-HFrameGraphNode FrameGraphNode::parentHandle() const
+QList<Qt3DCore::QNodeId> FrameGraphNode::childrenIds() const
{
- return m_parentHandle;
-}
-
-QList<HFrameGraphNode> FrameGraphNode::childrenHandles() const
-{
- return m_childrenHandles;
+ return m_childrenIds;
}
FrameGraphNode *FrameGraphNode::parent() const
{
- FrameGraphNode **parent = m_manager->data(m_parentHandle);
- if (parent != Q_NULLPTR)
- return *parent;
- return Q_NULLPTR;
+ return m_manager->lookupNode(m_parentId);
}
QList<FrameGraphNode *> FrameGraphNode::children() const
{
QList<FrameGraphNode *> children;
- children.reserve(m_childrenHandles.size());
+ children.reserve(m_childrenIds.size());
- Q_FOREACH (HFrameGraphNode handle, m_childrenHandles) {
- FrameGraphNode **child = m_manager->data(handle);
+ Q_FOREACH (const Qt3DCore::QNodeId &id, m_childrenIds) {
+ FrameGraphNode *child = m_manager->lookupNode(id);
if (child != Q_NULLPTR)
- children << *child;
+ children << child;
}
return children;
}
diff --git a/src/render/framegraph/framegraphnode_p.h b/src/render/framegraph/framegraphnode_p.h
index 9c4998729..ebc96748c 100644
--- a/src/render/framegraph/framegraphnode_p.h
+++ b/src/render/framegraph/framegraphnode_p.h
@@ -62,6 +62,8 @@ namespace Qt3DRender {
namespace Render {
+class FrameGraphManager;
+
class Q_AUTOTEST_EXPORT FrameGraphNode : public Qt3DCore::QBackendNode
{
public:
@@ -94,14 +96,12 @@ public:
void setFrameGraphManager(FrameGraphManager *manager);
FrameGraphManager *manager() const;
- void setHandle(HFrameGraphNode handle);
- void setParentHandle(HFrameGraphNode parentHandle);
- void appendChildHandle(HFrameGraphNode childHandle);
- void removeChildHandle(HFrameGraphNode childHandle);
+ void setParentId(const Qt3DCore::QNodeId &parentId);
+ void appendChildId(const Qt3DCore::QNodeId &childHandle);
+ void removeChildId(const Qt3DCore::QNodeId &childHandle);
- HFrameGraphNode handle() const;
- HFrameGraphNode parentHandle() const;
- QList<HFrameGraphNode> childrenHandles() const;
+ Qt3DCore::QNodeId parentId() const;
+ QList<Qt3DCore::QNodeId> childrenIds() const;
FrameGraphNode *parent() const;
QList<FrameGraphNode *> children() const;
@@ -112,9 +112,8 @@ protected:
private:
FrameGraphNodeType m_nodeType;
bool m_enabled;
- HFrameGraphNode m_handle;
- HFrameGraphNode m_parentHandle;
- QList<HFrameGraphNode> m_childrenHandles;
+ Qt3DCore::QNodeId m_parentId;
+ QList<Qt3DCore::QNodeId> m_childrenIds;
FrameGraphManager *m_manager;
friend class FrameGraphVisitor;
@@ -136,15 +135,12 @@ public:
Qt3DCore::QBackendNode *get(const Qt3DCore::QNodeId &id) const Q_DECL_OVERRIDE
{
- FrameGraphNode **node = m_manager->lookupResource(id);
- if (node != Q_NULLPTR)
- return *node;
- return Q_NULLPTR;
+ return m_manager->lookupNode(id);
}
void destroy(const Qt3DCore::QNodeId &id) const Q_DECL_OVERRIDE
{
- m_manager->releaseResource(id);
+ m_manager->releaseNode(id);
}
protected:
@@ -152,21 +148,18 @@ protected:
{
Frontend *f = qobject_cast<Frontend *>(n);
if (f != Q_NULLPTR) {
- HFrameGraphNode handle = m_manager->lookupHandle(n->id());
- if (handle.isNull()) {
- handle = m_manager->getOrAcquireHandle(n->id());
+ if (!m_manager->containsNode(n->id())) {
Backend *backend = new Backend();
- *m_manager->data(handle) = backend;
backend->setFactory(factory);
backend->setFrameGraphManager(m_manager);
- backend->setHandle(handle);
backend->setPeer(f);
QFrameGraphNode *parentFGNode = static_cast<QFrameGraphNode *>(n)->parentFrameGraphNode();
if (parentFGNode)
- backend->setParentHandle(m_manager->lookupHandle(parentFGNode->id()));
+ backend->setParentId(parentFGNode->id());
+ m_manager->appendNode(backend);
return backend;
}
- return static_cast<Backend *>(*m_manager->data(handle));
+ return static_cast<Backend *>(m_manager->lookupNode(n->id()));
}
return Q_NULLPTR;
}
diff --git a/src/render/framegraph/framegraphvisitor.cpp b/src/render/framegraph/framegraphvisitor.cpp
index 60307469a..3aa682468 100644
--- a/src/render/framegraph/framegraphvisitor.cpp
+++ b/src/render/framegraph/framegraphvisitor.cpp
@@ -87,7 +87,7 @@ void FrameGraphVisitor::visit(Render::FrameGraphNode *node)
// Leaf node - create a RenderView ready to be populated
// TODO: Pass in only framegraph config that has changed from previous
// index RenderViewJob.
- if (node->childrenHandles().empty()) {
+ if (node->childrenIds().empty()) {
QAspectJobPtr job = m_renderer->createRenderViewJob(node, m_renderviewIndex++);
m_jobs->append(job);
}
diff --git a/src/render/jobs/pickboundingvolumejob.cpp b/src/render/jobs/pickboundingvolumejob.cpp
index 9f4af60ed..23c320b83 100644
--- a/src/render/jobs/pickboundingvolumejob.cpp
+++ b/src/render/jobs/pickboundingvolumejob.cpp
@@ -77,7 +77,7 @@ private:
{
Q_FOREACH (Render::FrameGraphNode *n, node->children())
visit(n);
- if (node->childrenHandles().empty())
+ if (node->childrenIds().empty())
m_leaves.push_back(node);
}