summaryrefslogtreecommitdiffstats
path: root/src/render/jobs/updatemeshtrianglelistjob.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-08-02 14:57:17 +0200
committerPaul Lemire <paul.lemire@kdab.com>2016-10-13 06:10:27 +0000
commitbb43c895d1dbf44d381ba70f5684f40a0984c1c4 (patch)
tree59e6d4d77a7cdcbdf28310474f23e5029b1f8254 /src/render/jobs/updatemeshtrianglelistjob.cpp
parentcfd030f4b8e3daa9af346c4b3bbb3f7f887aa887 (diff)
Add MeshTriangleListUpdateJob
Change-Id: I5c94db7de2726f9088861f0f6522800ac893dc82 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/jobs/updatemeshtrianglelistjob.cpp')
-rw-r--r--src/render/jobs/updatemeshtrianglelistjob.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/render/jobs/updatemeshtrianglelistjob.cpp b/src/render/jobs/updatemeshtrianglelistjob.cpp
new file mode 100644
index 000000000..f796a7297
--- /dev/null
+++ b/src/render/jobs/updatemeshtrianglelistjob.cpp
@@ -0,0 +1,120 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 "updatemeshtrianglelistjob_p.h"
+#include <Qt3DRender/private/job_common_p.h>
+#include <Qt3DRender/private/nodemanagers_p.h>
+#include <Qt3DRender/private/light_p.h>
+#include <Qt3DRender/private/sphere_p.h>
+#include <Qt3DRender/private/attribute_p.h>
+#include <Qt3DRender/private/geometryrenderer_p.h>
+#include <Qt3DRender/private/geometry_p.h>
+#include <Qt3DRender/private/attribute_p.h>
+#include <Qt3DRender/private/buffer_p.h>
+#include <Qt3DRender/private/managers_p.h>
+#include <Qt3DRender/private/buffermanager_p.h>
+#include <Qt3DRender/private/geometryrenderermanager_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+UpdateMeshTriangleListJob::UpdateMeshTriangleListJob()
+ : m_manager(nullptr)
+{
+ SET_JOB_RUN_STAT_TYPE(this, JobTypes::UpdateMeshTriangleList, 0);
+}
+
+UpdateMeshTriangleListJob::~UpdateMeshTriangleListJob()
+{
+}
+
+void UpdateMeshTriangleListJob::setManagers(NodeManagers *manager)
+{
+ m_manager = manager;
+}
+
+void UpdateMeshTriangleListJob::run()
+{
+ EntityManager *manager = m_manager->renderNodesManager();
+ const QVector<HEntity> handles = manager->activeHandles();
+
+ for (const HEntity handle : handles) {
+ Entity *node = manager->data(handle);
+
+ // Look if for the GeometryRender/Geometry the attributes and or buffers are dirty
+ // in which case we need to recompute the triangle list
+ const GeometryRenderer *geomRenderer = node->renderComponent<GeometryRenderer>();
+ if (geomRenderer != nullptr) {
+ const Geometry *geom = m_manager->lookupResource<Geometry, GeometryManager>(geomRenderer->geometryId());
+ if (geom != nullptr) {
+ const Qt3DCore::QNodeId geomRendererId = geomRenderer->peerId();
+ if (!m_manager->geometryRendererManager()->isGeometryRendererScheduledForTriangleDataRefresh(geomRendererId)) {
+ // Check if the attributes or buffers are dirty
+ bool dirty = geomRenderer->isDirty();
+ Attribute *attr = nullptr;
+ const auto attrIds = geom->attributes();
+ for (const Qt3DCore::QNodeId attrId : attrIds) {
+ attr = m_manager->attributeManager()->lookupResource(attrId);
+ if (attr != nullptr) {
+ dirty |= attr->isDirty();
+ if (!dirty) {
+ const Buffer *buffer = m_manager->bufferManager()->lookupResource(attr->bufferId());
+ if (buffer != nullptr)
+ dirty = buffer->isDirty();
+ }
+ if (dirty)
+ break;
+ }
+ }
+ if (dirty)
+ m_manager->geometryRendererManager()->requestTriangleDataRefreshForGeometryRenderer(geomRendererId);
+ }
+ }
+ }
+ }
+}
+
+} // Render
+
+} // Qt3DRender
+
+QT_END_NAMESPACE