diff --git a/src/runtimerender/qssgrenderer_p.h b/src/runtimerender/qssgrenderer_p.h index cbf5b7fbf71c8470150b2b9bc5846dca59ac9d35..07d34598b25a85cfd7372573d637298bd249e512 100644 --- a/src/runtimerender/qssgrenderer_p.h +++ b/src/runtimerender/qssgrenderer_p.h @@ -136,11 +136,9 @@ public: const QVector2D &inMouseCoords, bool inPickSiblings = true, bool inPickEverything = false) = 0; - virtual QSSGRenderPickResult syncPick(QSSGRenderLayer &inLayer, - const QVector2D &inViewportDimensions, - const QVector2D &inMouseCoords, - bool inPickSiblings = true, - bool inPickEverything = false) = 0; + virtual QSSGRenderPickResult syncPick(const QSSGRenderLayer &inLayer, + const QVector2D &inViewportDimensions, + const QVector2D &inMouseCoords) = 0; // Return the relative hit position, in UV space, of a mouse pick against this object. // We need the node in order to figure out which layer rendered this object. diff --git a/src/runtimerender/rendererimpl/qssgrendererimpl.cpp b/src/runtimerender/rendererimpl/qssgrendererimpl.cpp index 40ec6bbfea16924a8031da01b8e5c761ca21ff76..bee98d9c5e478db9cbe51ab91e7569615db46219 100644 --- a/src/runtimerender/rendererimpl/qssgrendererimpl.cpp +++ b/src/runtimerender/rendererimpl/qssgrendererimpl.cpp @@ -464,7 +464,7 @@ QSSGRenderPickResult QSSGRendererImpl::pick(QSSGRenderLayer &inLayer, return QSSGRenderPickResult(); } -QSSGRenderPickResult QSSGRendererImpl::syncPick(QSSGRenderLayer &inLayer, const QVector2D &inViewportDimensions, const QVector2D &inMouseCoords, bool inPickSiblings, bool inPickEverything) +QSSGRenderPickResult QSSGRendererImpl::syncPick(const QSSGRenderLayer &layer, const QVector2D &inViewportDimensions, const QVector2D &inMouseCoords) { using PickResultList = QVarLengthArray<QSSGRenderPickResult, 20>; // Lets assume most items are filtered out already static const auto processResults = [](PickResultList &pickResults) { @@ -478,17 +478,11 @@ QSSGRenderPickResult QSSGRendererImpl::syncPick(QSSGRenderLayer &inLayer, const }; PickResultList pickResults; - QSSGRenderLayer *layer = &inLayer; - while (layer != nullptr) { - if (layer->flags.testFlag(QSSGRenderLayer::Flag::Active)) { - pickResults.clear(); - getLayerHitObjectList(*layer, inViewportDimensions, inMouseCoords, inPickEverything, pickResults); - QSSGPickResultProcessResult retval = processResults(pickResults); - if (retval.m_wasPickConsumed) - return retval; - } - - layer = inPickSiblings ? getNextLayer(*layer) : nullptr; + if (layer.flags.testFlag(QSSGRenderLayer::Flag::Active)) { + getLayerHitObjectList(layer, inViewportDimensions, inMouseCoords, false, pickResults); + QSSGPickResultProcessResult retval = processResults(pickResults); + if (retval.m_wasPickConsumed) + return retval; } return QSSGPickResultProcessResult(); @@ -838,7 +832,7 @@ static void dfs(const QSSGRenderNode &node, RenderableList &renderables) dfs(*child, renderables); } -void QSSGRendererImpl::getLayerHitObjectList(QSSGRenderLayer &layer, +void QSSGRendererImpl::getLayerHitObjectList(const QSSGRenderLayer &layer, const QVector2D &inViewportDimensions, const QVector2D &inPresCoords, bool inPickEverything, @@ -877,15 +871,15 @@ void QSSGRendererImpl::intersectRayWithSubsetRenderable(const QSSGRef<QSSGBuffer if (node.type != QSSGRenderGraphObject::Type::Model) return; - const QSSGRenderModel *model = static_cast<const QSSGRenderModel *>(&node); + const QSSGRenderModel &model = static_cast<const QSSGRenderModel &>(node); // TODO: Technically we should have some guard here, as the meshes are usually loaded on a different thread, // so this isn't really nice (assumes all meshes are loaded before picking and none are removed, which currently should be the case). - auto mesh = bufferManager->getMesh(model->meshPath); + auto mesh = bufferManager->getMesh(model.meshPath); if (!mesh) return; - const auto &globalTransform = model->globalTransform; + const auto &globalTransform = model.globalTransform; const auto &subMeshes = mesh->subsets; QSSGBounds3 modelBounds = QSSGBounds3::empty(); for (const auto &subMesh : subMeshes) @@ -910,7 +904,7 @@ void QSSGRendererImpl::intersectRayWithSubsetRenderable(const QSSGRef<QSSGBuffer return; outIntersectionResultList.push_back( - QSSGRenderPickResult(*model, + QSSGRenderPickResult(model, intersectionResult.rayLengthSquared, intersectionResult.relXY, intersectionResult.scenePosition)); diff --git a/src/runtimerender/rendererimpl/qssgrendererimpl_p.h b/src/runtimerender/rendererimpl/qssgrendererimpl_p.h index 2f2d6cc107d6c3fe1e9c550d047729dbcf16720b..61d72cc84abafc4932f79d592282d85a001feafd 100644 --- a/src/runtimerender/rendererimpl/qssgrendererimpl_p.h +++ b/src/runtimerender/rendererimpl/qssgrendererimpl_p.h @@ -202,11 +202,9 @@ public: const QVector2D &inMouseCoords, bool inPickSiblings, bool inPickEverything) override; - QSSGRenderPickResult syncPick(QSSGRenderLayer &inLayer, + QSSGRenderPickResult syncPick(const QSSGRenderLayer &layer, const QVector2D &inViewportDimensions, - const QVector2D &inMouseCoords, - bool inPickSiblings, - bool inPickEverything) override; + const QVector2D &inMouseCoords) override; virtual QSSGOption<QVector2D> facePosition(QSSGRenderNode &inNode, QSSGBounds3 inBounds, @@ -334,7 +332,7 @@ protected: const QVector2D &inMouseCoords, bool inPickEverything, TPickResultArray &outIntersectionResult); - void getLayerHitObjectList(QSSGRenderLayer &layer, + void getLayerHitObjectList(const QSSGRenderLayer &layer, const QVector2D &inViewportDimensions, const QVector2D &inMouseCoords, bool inPickEverything,