diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-03-09 15:28:11 +0000 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2020-04-23 14:18:22 +0100 |
commit | 9a2ab2f1c0dc7ffe83f3e22aa97951de216b4ef7 (patch) | |
tree | b89fbf07593668f11544a2e937500fc3802489bf /src/core/jobs | |
parent | 60f42119fe5c341880f4576e0c9ad8d99ee277d5 (diff) |
Add ability to override bounding data and trigger calculation
With this, can set min and max extents of a geometry renderer which
will avoid calculating it from the real geometry.
Can also trigger the computation from user code (via public API) if
user doesn't want to wait for next frame to get the data.
Change-Id: I821bfb7c9d710a77a2b87ec607b4ed35a0c7f236
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/jobs')
-rw-r--r-- | src/core/jobs/calcboundingvolumejob.cpp | 73 | ||||
-rw-r--r-- | src/core/jobs/calcboundingvolumejob_p.h | 22 |
2 files changed, 46 insertions, 49 deletions
diff --git a/src/core/jobs/calcboundingvolumejob.cpp b/src/core/jobs/calcboundingvolumejob.cpp index 37ee92e84..0b817490c 100644 --- a/src/core/jobs/calcboundingvolumejob.cpp +++ b/src/core/jobs/calcboundingvolumejob.cpp @@ -145,19 +145,6 @@ BoundingVolumeComputeData findBoundingVolumeComputeData(QGeometryView *node) return { nullptr, nullptr, positionAttribute, indexAttribute, drawVertexCount }; } -BoundingVolumeComputeResult calculateLocalBoundingVolume(const BoundingVolumeComputeData &data) { - BoundingVolumeCalculator calculator; - if (calculator.apply(data.positionAttribute, data.indexAttribute, data.vertexCount, - data.provider->view()->primitiveRestartEnabled(), - data.provider->view()->restartIndexValue())) - return { - data.entity, data.provider, data.positionAttribute, data.indexAttribute, - calculator.min(), calculator.max(), - calculator.center(), calculator.radius() - }; - return {}; -} - bool isTreeEnabled(QEntity *entity) { if (!entity->isEnabled()) return false; @@ -178,7 +165,7 @@ struct UpdateBoundFunctor typedef QVector<BoundingVolumeComputeResult> result_type; result_type operator ()(const BoundingVolumeComputeData &data) { - return { calculateLocalBoundingVolume(data) }; + return { data.compute() }; } }; @@ -192,25 +179,26 @@ struct ReduceUpdateBoundFunctor } // anonymous -//class CalculateBoundingVolumeJobPrivate : public Qt3DCore::QAspectJobPrivate -//{ -//public: -// CalculateBoundingVolumeJobPrivate() { } -// ~CalculateBoundingVolumeJobPrivate() override { } - -// void postFrame(Qt3DCore::QAspectManager *manager) override -// { -// Q_UNUSED(manager) -//// for (Geometry *backend : qAsConst(m_updatedGeometries)) { -//// Qt3DCore::QGeometry *node = qobject_cast<Qt3DCore::QGeometry *>(manager->lookupNode(backend->peerId())); -//// if (!node) -//// continue; -//// Qt3DCore::QGeometryPrivate *dNode = static_cast<Qt3DCore::QGeometryPrivate *>(Qt3DCore::QNodePrivate::get(node)); -//// dNode->setExtent(backend->min(), backend->max()); -//// } -// } - -//}; + +BoundingVolumeComputeData BoundingVolumeComputeData::fromView(QGeometryView *view) +{ + return findBoundingVolumeComputeData(view); +} + +BoundingVolumeComputeResult BoundingVolumeComputeData::compute() const +{ + BoundingVolumeCalculator calculator; + if (calculator.apply(positionAttribute, indexAttribute, vertexCount, + provider->view()->primitiveRestartEnabled(), + provider->view()->restartIndexValue())) + return { + entity, provider, positionAttribute, indexAttribute, + calculator.min(), calculator.max(), + calculator.center(), calculator.radius() + }; + return {}; +} + CalculateBoundingVolumeJob::CalculateBoundingVolumeJob() : Qt3DCore::QAspectJob() @@ -237,17 +225,22 @@ void CalculateBoundingVolumeJob::run() // or THE primary provider bool foundBV = false; for (auto bv: bvProviders) { - if (!bv->view()) - continue; auto dbv = QBoundingVolumePrivate::get(bv); if (foundBV && !dbv->m_primaryProvider) continue; - auto bvdata = findBoundingVolumeComputeData(bv->view()); - if (!bvdata.valid()) + BoundingVolumeComputeData bvdata; + if (!dbv->m_explicitPointsValid && bv->view()) { + bvdata = findBoundingVolumeComputeData(bv->view()); + if (!bvdata.valid()) + continue; + bvdata.entity = entity; + bvdata.provider = bv; + } else { + // bounds are explicitly set, don't bother computing + // or no view, can't compute continue; - bvdata.entity = entity; - bvdata.provider = bv; + } bool dirty = QEntityPrivate::get(entity)->m_dirty; dirty |= QGeometryViewPrivate::get(bv->view())->m_dirty; @@ -279,7 +272,7 @@ void CalculateBoundingVolumeJob::run() #endif { for (auto it = dirtyEntities.begin(); it != dirtyEntities.end(); ++it) { - auto res = calculateLocalBoundingVolume(it.value()); + auto res = it.value().compute(); if (res.valid()) m_results.push_back(res); // How do we push it to the backends???? } diff --git a/src/core/jobs/calcboundingvolumejob_p.h b/src/core/jobs/calcboundingvolumejob_p.h index 498fe766f..f61dd72cf 100644 --- a/src/core/jobs/calcboundingvolumejob_p.h +++ b/src/core/jobs/calcboundingvolumejob_p.h @@ -65,28 +65,32 @@ class CalculateBoundingVolumeJobPrivate; class QEntity; class QAttribute; class QBoundingVolume; +class QGeometryView; -struct BoundingVolumeComputeData { +struct Q_3DCORE_PRIVATE_EXPORT BoundingVolumeComputeResult { QEntity *entity = nullptr; QBoundingVolume *provider = nullptr; QAttribute *positionAttribute = nullptr; QAttribute *indexAttribute = nullptr; - int vertexCount = 0; + QVector3D m_min; + QVector3D m_max; + QVector3D m_center; + float m_radius = -1.f; - bool valid() const { return positionAttribute != nullptr; } + bool valid() const { return m_radius >= 0.f; } }; -struct BoundingVolumeComputeResult { +struct Q_3DCORE_PRIVATE_EXPORT BoundingVolumeComputeData { QEntity *entity = nullptr; QBoundingVolume *provider = nullptr; QAttribute *positionAttribute = nullptr; QAttribute *indexAttribute = nullptr; - QVector3D m_min; - QVector3D m_max; - QVector3D m_center; - float m_radius = -1.f; + int vertexCount = 0; - bool valid() const { return m_radius >= 0.f; } + static BoundingVolumeComputeData fromView(QGeometryView *view); + + bool valid() const { return positionAttribute != nullptr; } + BoundingVolumeComputeResult compute() const; }; class Q_3DCORE_PRIVATE_EXPORT CalculateBoundingVolumeJob : public Qt3DCore::QAspectJob |