summaryrefslogtreecommitdiffstats
path: root/src/render/jobs/raycastingjob.cpp
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-04-03 21:20:53 +0100
committerMike Krus <mike.krus@kdab.com>2019-05-25 09:28:45 +0100
commitf6b813d900550703831798329a274113caee91c6 (patch)
tree2139254e22fab48f87617c01f6f8e18bed5659cc /src/render/jobs/raycastingjob.cpp
parent7dcfd013e60787827fa5e31a408de04d1ed6ec0d (diff)
Use entity visitor to traverse scene graph
Also avoid doing traversal at all if there's no LOD components Change-Id: I27f21f12b89bb05d8c4aecda16478261ae312c5a Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/jobs/raycastingjob.cpp')
-rw-r--r--src/render/jobs/raycastingjob.cpp44
1 files changed, 13 insertions, 31 deletions
diff --git a/src/render/jobs/raycastingjob.cpp b/src/render/jobs/raycastingjob.cpp
index 887f203bf..f3571c210 100644
--- a/src/render/jobs/raycastingjob.cpp
+++ b/src/render/jobs/raycastingjob.cpp
@@ -50,6 +50,7 @@
#include <Qt3DRender/private/renderer_p.h>
#include <Qt3DRender/private/rendersettings_p.h>
#include <Qt3DRender/private/trianglesvisitor_p.h>
+#include <Qt3DRender/private/entityvisitor_p.h>
QT_BEGIN_NAMESPACE
@@ -59,43 +60,23 @@ using namespace Render;
namespace {
-class EntityCasterGatherer
+class EntityCasterGatherer : public EntityVisitor
{
public:
using EntityCasterList = QVector<QPair<Entity *, RayCaster*>>;
+ EntityCasterList m_result;
- explicit EntityCasterGatherer(Entity *root) : m_root(root), m_needsRefresh(true) { }
+ explicit EntityCasterGatherer(NodeManagers *manager) : EntityVisitor(manager) { setPruneDisabled(true); }
- EntityCasterList result() const {
- if (m_needsRefresh) {
- m_result.clear();
- m_result = gatherEntities(m_root, std::move(m_result));
- m_needsRefresh = false;
+ Operation visit(Entity *entity) override {
+ QVector<RayCaster *> components = entity->renderComponents<RayCaster>();
+ for (const auto c: qAsConst(components)) {
+ if (c->isEnabled())
+ m_result.push_back(qMakePair(entity, c));
}
- return m_result;
- }
-
-private:
- EntityCasterList gatherEntities(Entity *entity, EntityCasterList entities) const
- {
- if (entity != nullptr && entity->isEnabled()) {
- QVector<RayCaster *> components = entity->renderComponents<RayCaster>();
- for (const auto c: qAsConst(components)) {
- if (c->isEnabled())
- entities.push_back(qMakePair(entity, c));
- }
- // Traverse children
- const auto children = entity->children();
- for (Entity *child : children)
- entities = gatherEntities(child, std::move(entities));
- }
- return entities;
+ return Continue;
}
-
- Entity *m_root;
- mutable EntityCasterList m_result;
- mutable bool m_needsRefresh;
};
} // anonymous
@@ -145,8 +126,9 @@ bool RayCastingJob::runHelper()
m_renderSettings->faceOrientationPickingMode() != QPickingSettings::FrontFace;
const float pickWorldSpaceTolerance = m_renderSettings->pickWorldSpaceTolerance();
- EntityCasterGatherer gatherer(m_node);
- const EntityCasterGatherer::EntityCasterList &entities = gatherer.result();
+ EntityCasterGatherer gatherer(m_manager);
+ gatherer.apply(m_node);
+ const EntityCasterGatherer::EntityCasterList &entities = gatherer.m_result;
PickingUtils::ViewportCameraAreaGatherer vcaGatherer;
const QVector<PickingUtils::ViewportCameraAreaDetails> vcaDetails = vcaGatherer.gather(m_frameGraphRoot);