diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-08-31 15:36:15 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-09-03 11:04:52 +0000 |
commit | 9d0ebf6f40c3ff589cde420f4e6ca6f5a18cb55f (patch) | |
tree | 1b2fc0ea16feeaf3e34b06cafb921b1deddc8c91 | |
parent | de2dbd12457f32fb6f4f78eb0a758366a607463b (diff) |
Add the option of deferring loading uip subpresentations
It is the default, actually.
To get back to the old system and load all (uip) subpresentations
during the initial load phase, pass PreLoadSubPresentations to
Q3DSEngine.
Note that this does not affect QML subpresentations atm.
It also not available for subpresentations that are used as texture maps.
The unused Q3DSEngine::autoStart setting is removed since that
would be hard to support now.
Task-number: QT3DS-2155
Change-Id: I35f3f463b3fea4b5557743d724ffb863a9526b88
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r-- | src/runtime/q3dsengine.cpp | 47 | ||||
-rw-r--r-- | src/runtime/q3dsengine_p.h | 7 | ||||
-rw-r--r-- | src/runtime/q3dsscenemanager.cpp | 50 | ||||
-rw-r--r-- | src/runtime/q3dsscenemanager_p.h | 2 |
4 files changed, 71 insertions, 35 deletions
diff --git a/src/runtime/q3dsengine.cpp b/src/runtime/q3dsengine.cpp index cada5a8..4249bf7 100644 --- a/src/runtime/q3dsengine.cpp +++ b/src/runtime/q3dsengine.cpp @@ -660,8 +660,10 @@ bool Q3DSEngine::loadPresentations() return false; } - for (int i = 1; i < m_uipPresentations.count(); ++i) - loadSubUipPresentation(&m_uipPresentations[i]); + if (m_flags.testFlag(PreLoadSubPresentations)) { + for (int i = 1; i < m_uipPresentations.count(); ++i) + loadSubUipPresentation(&m_uipPresentations[i]); + } for (QmlPresentation &qmlDocument : m_qmlPresentations) loadSubQmlPresentation(&qmlDocument); @@ -676,7 +678,7 @@ void Q3DSEngine::finalizePresentations() Q3DSSceneManager *mainPresSceneMgr = m_uipPresentations[0].sceneManager; QVector<Q3DSSubPresentation> subPresentations; for (const UipPresentation &pres : m_uipPresentations) { - if (!pres.subPres.id.isEmpty() && pres.subPres.colorTex) + if (!pres.subPres.id.isEmpty()) // do not check for something like pres.subPres.colorTex - with deferred loading it's not there yet subPresentations.append(pres.subPres); } for (const QmlPresentation &pres : m_qmlPresentations) { @@ -698,8 +700,8 @@ void Q3DSEngine::finalizePresentations() m_uipPresentations[0].q3dscene.renderSettings->setRenderPolicy(m_onDemandRendering ? Qt3DRender::QRenderSettings::OnDemand : Qt3DRender::QRenderSettings::Always); - if (m_autoStart) { - for (const UipPresentation &pres : m_uipPresentations) + for (const UipPresentation &pres : m_uipPresentations) { + if (pres.sceneManager) pres.sceneManager->prepareAnimators(); } @@ -800,11 +802,23 @@ bool Q3DSEngine::buildUipPresentationScene(UipPresentation *pres) return true; } +Q3DSSubPresentation Q3DSEngine::loadSubUipPresentation(const QString &subPresId) +{ + Q3DSSubPresentation sp; + for (int i = 0; i < m_uipPresentations.count(); ++i) { + if (m_uipPresentations[i].subPres.id == subPresId) { + if (loadSubUipPresentation(&m_uipPresentations[i])) + sp = m_uipPresentations[i].subPres; + break; + } + } + return sp; +} + bool Q3DSEngine::loadSubUipPresentation(UipPresentation *pres) { Q_ASSERT(pres); Q_ASSERT(pres->uipDocument); - // Parse. if (!parseUipDocument(pres)) { Q3DSUtils::showMessage(QObject::tr("Failed to parse subpresentation")); return false; @@ -1286,11 +1300,6 @@ void Q3DSEngine::resize(const QSize &size, qreal dpr, bool forceSynchronous) } } -void Q3DSEngine::setAutoStart(bool autoStart) -{ - m_autoStart = autoStart; -} - bool Q3DSEngine::isProfileUiVisible() const { Q3DSSceneManager *sm = !m_uipPresentations.isEmpty() ? m_uipPresentations[0].sceneManager : nullptr; @@ -1648,13 +1657,15 @@ void Q3DSEngine::loadBehaviors() for (int i = 0, ie = presentationCount(); i != ie; ++i) { BehavInstDesc desc; desc.presentation = presentation(i); - Q3DSUipPresentation::forAllObjectsOfType(desc.presentation->scene(), - Q3DSGraphObject::Behavior, - [&behaviorInstances, &desc](Q3DSGraphObject *obj) - { - desc.behaviorInstance = static_cast<Q3DSBehaviorInstance *>(obj); - behaviorInstances.append(desc); - }); + if (desc.presentation) { + Q3DSUipPresentation::forAllObjectsOfType(desc.presentation->scene(), + Q3DSGraphObject::Behavior, + [&behaviorInstances, &desc](Q3DSGraphObject *obj) + { + desc.behaviorInstance = static_cast<Q3DSBehaviorInstance *>(obj); + behaviorInstances.append(desc); + }); + } } qCDebug(lcUip, "Found %d behavior instances in total", behaviorInstances.count()); diff --git a/src/runtime/q3dsengine_p.h b/src/runtime/q3dsengine_p.h index cfad22a..3c56a7e 100644 --- a/src/runtime/q3dsengine_p.h +++ b/src/runtime/q3dsengine_p.h @@ -100,7 +100,8 @@ public: enum Flag { Force4xMSAA = 0x01, EnableProfiling = 0x02, - WithoutRenderAspect = 0x04 + WithoutRenderAspect = 0x04, + PreLoadSubPresentations = 0x08 }; Q_DECLARE_FLAGS(Flags, Flag) @@ -160,7 +161,6 @@ public: bool start(); void resize(const QSize &size, qreal dpr = qreal(1.0), bool forceSynchronous = false); - void setAutoStart(bool autoStart); void setDataInputValue(const QString &name, const QVariant &value); void fireEvent(Q3DSGraphObject *target, Q3DSUipPresentation *presentation, const QString &event); @@ -212,6 +212,8 @@ public: void reportQuickRenderLoopStats(float deltaMs, bool isThreaded); Q3DSRenderLoopStats renderLoopStats(); + Q3DSSubPresentation loadSubUipPresentation(const QString &subPresId); + public Q_SLOTS: void requestGrab(); @@ -293,7 +295,6 @@ private: QHash<Qt3DRender::QRenderCaptureReply*, QMetaObject::Connection> m_captureConnections; QObject m_profileUiEventSource; - bool m_autoStart = true; float m_profileUiScale = 1.0f; bool m_autoToggleProfileUi = true; diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp index b277552..a5e5613 100644 --- a/src/runtime/q3dsscenemanager.cpp +++ b/src/runtime/q3dsscenemanager.cpp @@ -896,12 +896,11 @@ void Q3DSSceneManager::finalizeMainScene(const QVector<Q3DSSubPresentation> &sub m_subPresentations = subPresentations; - updateSubPresentationHosts(); + updateSubPresentationHosts(true); for (const Q3DSSubPresentation &subPres : m_subPresentations) { - if (!subPres.sceneManager) - continue; - m_profiler->registerSubPresentationProfiler(subPres.sceneManager->m_profiler); + if (subPres.sceneManager) + m_profiler->registerSubPresentationProfiler(subPres.sceneManager->m_profiler); } #if QT_CONFIG(q3ds_profileui) @@ -910,19 +909,44 @@ void Q3DSSceneManager::finalizeMainScene(const QVector<Q3DSSubPresentation> &sub #endif } -void Q3DSSceneManager::updateSubPresentationHosts() +void Q3DSSceneManager::updateSubPresentationHosts(bool inFinalizeMainScene) { for (Q3DSLayerNode *layer3DS : m_pendingSubPresLayers) { const QString subPresId = layer3DS->sourcePath(); Q_ASSERT(!subPresId.isEmpty()); - auto it = std::find_if(m_subPresentations.cbegin(), m_subPresentations.cend(), + auto it = std::find_if(m_subPresentations.begin(), m_subPresentations.end(), [subPresId](const Q3DSSubPresentation &sp) { return sp.id == subPresId; }); - if (it != m_subPresentations.cend()) { - qCDebug(lcScene, "Directing subpresentation %s to layer %s", qPrintable(it->id), layer3DS->id().constData()); - Q3DSLayerAttached *layerData = static_cast<Q3DSLayerAttached *>(layer3DS->attached()); - layerData->layerTexture = it->colorTex; - layerData->compositorSourceParam->setValue(QVariant::fromValue(layerData->layerTexture)); - layerData->updateSubPresentationSize(); + if (it != m_subPresentations.end()) { + if (!it->colorTex) { + Q3DSSubPresentation sp = m_engine->loadSubUipPresentation(it->id); + if (sp.colorTex && sp.sceneManager) { + it->id = sp.id; + it->sceneManager = sp.sceneManager; + it->colorTex = sp.colorTex; + it->depthOrDepthStencilTex = sp.depthOrDepthStencilTex; + it->stencilTex = sp.stencilTex; + + if (!inFinalizeMainScene) { + sp.sceneManager->prepareAnimators(); + m_profiler->registerSubPresentationProfiler(sp.sceneManager->m_profiler); + Q3DSUipPresentation::forAllObjectsOfType(sp.sceneManager->m_presentation->scene(), + Q3DSGraphObject::Behavior, + [this, &sp](Q3DSGraphObject *obj) + { + Q3DSBehaviorInstance *behaviorInstance = static_cast<Q3DSBehaviorInstance *>(obj); + if (behaviorInstance->eyeballEnabled()) + m_engine->loadBehaviorInstance(behaviorInstance, sp.sceneManager->m_presentation); + }); + } + } + } + if (it->colorTex) { + qCDebug(lcScene, "Directing subpresentation %s to layer %s", qPrintable(it->id), layer3DS->id().constData()); + Q3DSLayerAttached *layerData = static_cast<Q3DSLayerAttached *>(layer3DS->attached()); + layerData->layerTexture = it->colorTex; + layerData->compositorSourceParam->setValue(QVariant::fromValue(layerData->layerTexture)); + layerData->updateSubPresentationSize(); + } } else { qCDebug(lcScene, "Subpresentation %s for layer %s not found", qPrintable(subPresId), layer3DS->id().constData()); @@ -1352,7 +1376,7 @@ void Q3DSSceneManager::buildSubPresentationLayer(Q3DSLayerNode *layer3DS, const const QSize layerPixelSize = safeLayerPixelSize(data); auto it = std::find_if(m_subPresentations.cbegin(), m_subPresentations.cend(), [layer3DS](const Q3DSSubPresentation &sp) { return sp.id == layer3DS->sourcePath(); }); - if (it != m_subPresentations.cend()) { + if (it != m_subPresentations.cend() && it->colorTex) { qCDebug(lcScene, "Resizing subpresentation %s for layer %s to %dx%d", qPrintable(layer3DS->sourcePath()), layer3DS->id().constData(), sz.width(), sz.height()); // Resize the offscreen subpresentation buffers diff --git a/src/runtime/q3dsscenemanager_p.h b/src/runtime/q3dsscenemanager_p.h index 7652866..47afea9 100644 --- a/src/runtime/q3dsscenemanager_p.h +++ b/src/runtime/q3dsscenemanager_p.h @@ -774,7 +774,7 @@ public: private: Q_DISABLE_COPY(Q3DSSceneManager) - void updateSubPresentationHosts(); + void updateSubPresentationHosts(bool inFinalizeMainScene = false); void initSubTree(Q3DSGraphObject *subTreeRoot); void buildLayer(Q3DSLayerNode *layer3DS, Qt3DRender::QFrameGraphNode *parent, const QSize &parentSize); void buildSubPresentationLayer(Q3DSLayerNode *layer3DS, const QSize &parentSize); |