diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2018-10-26 13:42:57 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-11-01 05:09:52 +0000 |
commit | 3981b2ce1439eff2f87064296f5a91b4a271515d (patch) | |
tree | 85e49e95a6681ae0f00d73615436179cf7052f26 | |
parent | c9f9043a0081c1fab1b94858fda16099fc7d6b48 (diff) |
Try loading a ktx image instead of the given one if option is set
If "Use ktx textures if available" option is set for the presentation
from presentation settings dialog, try loading the given image file with ktx
extension first.
Task-number: QT3DS-2505
Change-Id: Ib1876fb810287beb943d8138b8fb2755853e6f3e
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r-- | src/runtime/q3dsimagemanager.cpp | 30 | ||||
-rw-r--r-- | src/runtime/q3dsimagemanager_p.h | 2 | ||||
-rw-r--r-- | src/runtime/q3dsscenemanager.cpp | 18 | ||||
-rw-r--r-- | src/runtime/q3dsuipparser.cpp | 4 | ||||
-rw-r--r-- | src/runtime/q3dsuippresentation.cpp | 10 | ||||
-rw-r--r-- | src/runtime/q3dsuippresentation_p.h | 3 |
6 files changed, 54 insertions, 13 deletions
diff --git a/src/runtime/q3dsimagemanager.cpp b/src/runtime/q3dsimagemanager.cpp index 1ac9c74..facfcd5 100644 --- a/src/runtime/q3dsimagemanager.cpp +++ b/src/runtime/q3dsimagemanager.cpp @@ -244,7 +244,8 @@ QVector<Qt3DRender::QTextureImageDataPtr> Q3DSImageManager::load(const QUrl &sou return result; } -void Q3DSImageManager::setSource(Qt3DRender::QAbstractTexture *tex, const QUrl &source) +void Q3DSImageManager::setSource(Qt3DRender::QAbstractTexture *tex, const QUrl &source, + bool preferKtx) { TextureInfo info; auto it = m_metadata.find(tex); @@ -254,12 +255,29 @@ void Q3DSImageManager::setSource(Qt3DRender::QAbstractTexture *tex, const QUrl & info = *it; } - info.source = source; + QVector<Qt3DRender::QTextureImageDataPtr> imageData; - // yes, it's all synchronous and this is intentional. The generator - // (invoked from some Qt3D job thread later on) will just return the already - // loaded data. - QVector<Qt3DRender::QTextureImageDataPtr> imageData = load(source, info.flags, &info.wasCached); + if (!preferKtx) { + info.source = source; + + // yes, it's all synchronous and this is intentional. The generator + // (invoked from some Qt3D job thread later on) will just return the already + // loaded data. + imageData = load(source, info.flags, &info.wasCached); + } else { + QString ktxSource = source.toLocalFile(); + ktxSource = ktxSource.left(ktxSource.lastIndexOf(QLatin1Char('.'))); + ktxSource.append(QLatin1String(".ktx")); + info.source = QUrl::fromLocalFile(ktxSource); + imageData = load(info.source, info.flags, &info.wasCached); + // If ktx is not found, load with the original extension + if (imageData.isEmpty()) { + qCWarning(lcPerf, "You have specified \"Use ktx texture if available\" option, " + "but did not provide a ktx texture: %s", qPrintable(ktxSource)); + info.source = source; + load(source, info.flags, &info.wasCached); + } + } for (Qt3DRender::QAbstractTextureImage *oldImage : tex->textureImages()) { tex->removeTextureImage(oldImage); diff --git a/src/runtime/q3dsimagemanager_p.h b/src/runtime/q3dsimagemanager_p.h index fff9ab0..707cb42 100644 --- a/src/runtime/q3dsimagemanager_p.h +++ b/src/runtime/q3dsimagemanager_p.h @@ -72,7 +72,7 @@ public: const QByteArray &id, Q3DSProfiler *profiler = nullptr, const char *profName = nullptr, ...); - void setSource(Qt3DRender::QAbstractTexture *tex, const QUrl &source); + void setSource(Qt3DRender::QAbstractTexture *tex, const QUrl &source, bool preferKtx); void setSource(Qt3DRender::QAbstractTexture *tex, const QImage &image); QSize size(Qt3DRender::QAbstractTexture *tex) const; diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp index 984b899..cf2f2e7 100644 --- a/src/runtime/q3dsscenemanager.cpp +++ b/src/runtime/q3dsscenemanager.cpp @@ -2118,7 +2118,8 @@ void Q3DSSceneManager::setLayerProperties(Q3DSLayerNode *layer3DS) // also sets min/mag and generates mipmaps Q3DSImageManager::instance().setSource(data->iblProbeData.lightProbeTexture, - QUrl::fromLocalFile(layer3DS->lightProbe()->sourcePath())); + QUrl::fromLocalFile(layer3DS->lightProbe()->sourcePath()), + m_presentation->preferKtx()); data->iblProbeData.lightProbeSampler->setValue(QVariant::fromValue(data->iblProbeData.lightProbeTexture)); // Image probes force repeat for horizontal repeat @@ -2170,7 +2171,8 @@ void Q3DSSceneManager::setLayerProperties(Q3DSLayerNode *layer3DS) // also sets min/mag and generates mipmaps Q3DSImageManager::instance().setSource(data->iblProbeData.lightProbe2Texture, - QUrl::fromLocalFile(layer3DS->lightProbe2()->sourcePath())); + QUrl::fromLocalFile(layer3DS->lightProbe2()->sourcePath()), + m_presentation->preferKtx()); data->iblProbeData.lightProbe2Sampler->setValue(QVariant::fromValue(data->iblProbeData.lightProbe2Texture)); data->iblProbeData.lightProbe2Texture->setWrapMode(wrapMode); @@ -5457,7 +5459,8 @@ void Q3DSSceneManager::updateTextureParameters(Q3DSTextureParameters &texturePar } } } else if (!image->sourcePath().isEmpty()) { - Q3DSImageManager::instance().setSource(textureParameters.texture, QUrl::fromLocalFile(image->sourcePath())); + Q3DSImageManager::instance().setSource(textureParameters.texture, QUrl::fromLocalFile(image->sourcePath()), + m_presentation->preferKtx()); textureParameters.sampler->setValue(QVariant::fromValue(textureParameters.texture)); } else if (!image->customImage().isNull()) { Q3DSImageManager::instance().setSource(textureParameters.texture, image->customImage()); @@ -5915,7 +5918,8 @@ void Q3DSSceneManager::updateDefaultMaterial(Q3DSDefaultMaterial *m, Q3DSReferen setImageTextureFromSubPresentation(data->lightProbeSampler, iblOverride); } else { Q3DSImageManager::instance().setSource(data->lightProbeOverrideTexture, - QUrl::fromLocalFile(iblOverride->sourcePath())); + QUrl::fromLocalFile(iblOverride->sourcePath()), + m_presentation->preferKtx()); data->lightProbeSampler->setValue(QVariant::fromValue(data->lightProbeOverrideTexture)); } @@ -5984,7 +5988,8 @@ Qt3DRender::QAbstractTexture *Q3DSSceneManager::createCustomPropertyTexture(cons texture = Q3DSImageManager::instance().newTextureForImage(m_rootEntity, 0, id, m_profiler, "Custom property texture %s", qPrintable(source)); qCDebug(lcScene, "Creating custom property texture %s", qPrintable(source)); - Q3DSImageManager::instance().setSource(texture, QUrl::fromLocalFile(source)); + Q3DSImageManager::instance().setSource(texture, QUrl::fromLocalFile(source), + m_presentation->preferKtx()); } // now override the defaults set in setSource() with whatever the metadata specifies @@ -6228,7 +6233,8 @@ void Q3DSSceneManager::updateCustomMaterial(Q3DSCustomMaterialInstance *m, Q3DSR if (iblOverride) { // also sets min/mag and generates mipmaps Q3DSImageManager::instance().setSource(data->lightProbeOverrideTexture, - QUrl::fromLocalFile(iblOverride->sourcePath())); + QUrl::fromLocalFile(iblOverride->sourcePath()), + m_presentation->preferKtx()); data->lightProbeSampler->setValue(QVariant::fromValue(data->lightProbeOverrideTexture)); Qt3DRender::QTextureWrapMode wrapMode; diff --git a/src/runtime/q3dsuipparser.cpp b/src/runtime/q3dsuipparser.cpp index 0528ef8..e087641 100644 --- a/src/runtime/q3dsuipparser.cpp +++ b/src/runtime/q3dsuipparser.cpp @@ -210,6 +210,10 @@ void Q3DSUipParser::parseProjectSettings() bool v; if (Q3DS::convertToBool(attr.value(), &v, "maintainAspect value", r)) m_presentation->setMaintainAspectRatio(v); + } else if (attr.name() == QStringLiteral("preferKtx")) { + bool v; + if (Q3DS::convertToBool(attr.value(), &v, "preferKtx value", r)) + m_presentation->setPreferKtx(v); } } r->skipCurrentElement(); diff --git a/src/runtime/q3dsuippresentation.cpp b/src/runtime/q3dsuippresentation.cpp index e8577b4..b2fb022 100644 --- a/src/runtime/q3dsuippresentation.cpp +++ b/src/runtime/q3dsuippresentation.cpp @@ -3633,6 +3633,11 @@ bool Q3DSUipPresentation::maintainAspectRatio() const return d->maintainAspectRatio; } +bool Q3DSUipPresentation::preferKtx() const +{ + return d->preferKtx; +} + void Q3DSUipPresentation::setAuthor(const QString &author) { d->author = author; @@ -3663,6 +3668,11 @@ void Q3DSUipPresentation::setMaintainAspectRatio(bool maintain) d->maintainAspectRatio = maintain; } +void Q3DSUipPresentation::setPreferKtx(bool prefer) +{ + d->preferKtx = prefer; +} + Q3DSScene *Q3DSUipPresentation::scene() const { return d->scene; diff --git a/src/runtime/q3dsuippresentation_p.h b/src/runtime/q3dsuippresentation_p.h index 7f86ba7..3a2381d 100644 --- a/src/runtime/q3dsuippresentation_p.h +++ b/src/runtime/q3dsuippresentation_p.h @@ -2046,6 +2046,7 @@ public: int presentationHeight() const; Rotation presentationRotation() const; bool maintainAspectRatio() const; + bool preferKtx() const; void setAuthor(const QString &author); void setCompany(const QString &company); @@ -2053,6 +2054,7 @@ public: void setPresentationHeight(int h); void setPresentationRotation(Rotation r); void setMaintainAspectRatio(bool maintain); + void setPreferKtx(bool prefer); Q3DSScene *scene() const; Q3DSSlide *masterSlide() const; @@ -2156,6 +2158,7 @@ struct Q3DSUipPresentationData int presentationHeight = 0; Q3DSUipPresentation::Rotation presentationRotation = Q3DSUipPresentation::NoRotation; bool maintainAspectRatio = false; + bool preferKtx = false; qint64 loadTime = 0; qint64 meshesLoadTime = 0; |