summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2019-07-29 21:51:19 +0800
committerouchuan <ouchuanm@outlook.com>2019-08-05 17:04:23 +0800
commit2efe9d733c162f425c993c586f524e9d1de88f31 (patch)
tree4df3c40d281d7b19e0fc325def79fa31ac53ae8b
parentd0d05922ed34011eca3c975d5653c14628344a24 (diff)
downloadqt3d-2efe9d733c162f425c993c586f524e9d1de88f31.tar.gz
QImageTextureDataFunctor: return invalid data when url is invalid
Since QSkyboxEntity creating empty cube map first and using QTimer to delay loading real cube map, in render thread, GLTexture will use the generator function of empty cube map to generate a QTextureImageDataPtr at first, this will set the format of property of GLTexture to NoFormat, and terminate the creation of GLTexture. Although GLTexture read real real cube map next time, format will not be reset and the creation of GLTexture terminates. [ChangeLog][Qt3DRender][QImageTextureDataFunctor] return a invalid image data when url is invalid to ensure the property of GLTexture will not be set to NoFormat Fixes: QTBUG-74017 Change-Id: If48f727dba817a931d618b2b88c7ebd54c508c47 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/render/texture/qtextureimage.cpp4
-rw-r--r--tests/auto/render/gltexture/tst_gltexture.cpp38
2 files changed, 41 insertions, 1 deletions
diff --git a/src/render/texture/qtextureimage.cpp b/src/render/texture/qtextureimage.cpp
index 6bcdaba7d..b4e9ed46f 100644
--- a/src/render/texture/qtextureimage.cpp
+++ b/src/render/texture/qtextureimage.cpp
@@ -289,10 +289,12 @@ QImageTextureDataFunctor::QImageTextureDataFunctor(const QUrl &url, bool mirrore
QTextureImageDataPtr QImageTextureDataFunctor::operator ()()
{
+ if (!m_url.isValid())
+ return QTextureImageDataPtr();
+
// We assume that a texture image is going to contain a single image data
// For compressed dds or ktx textures a warning should be issued if
// there are layers or 3D textures
-
if (!Qt3DCore::QDownloadHelperService::isLocal(m_url))
qWarning() << "QTextureImage only supports local url";
diff --git a/tests/auto/render/gltexture/tst_gltexture.cpp b/tests/auto/render/gltexture/tst_gltexture.cpp
index 8a8701f8e..e971078d0 100644
--- a/tests/auto/render/gltexture/tst_gltexture.cpp
+++ b/tests/auto/render/gltexture/tst_gltexture.cpp
@@ -864,6 +864,44 @@ private Q_SLOTS:
// Cleanup
texture.destroy();
}
+
+ void checkPropertiesAfterLoadTextureDataFromImages()
+ {
+ // GIVEN
+ GLTexture texture;
+ TextureProperties props;
+ props.target = QAbstractTexture::TargetCubeMap;
+ props.format = QAbstractTexture::Automatic;
+ props.width = 1;
+ props.height = 1;
+ texture.setProperties(props);
+ QVector<GLTexture::Image> images;
+ // test a image texture data generator whose url is invalid
+ QImageTextureDataFunctorPtr gen = QImageTextureDataFunctorPtr::create(QUrl(), true);
+ images.push_back({gen, 0, 0, QAbstractTexture::CubeMapPositiveX});
+ texture.setImages(images);
+
+ // WHEN
+ texture.createOrUpdateGLTexture();
+
+ // THEN
+ QCOMPARE(texture.properties().format, QAbstractTexture::Automatic);
+
+ // WHEN
+ // test a image texture data generator whose url is valid
+ gen = QImageTextureDataFunctorPtr::create(QUrl("qrc:/image.jpg"), true);
+ images.clear();
+ images.push_back({gen, 0, 0, QAbstractTexture::CubeMapPositiveX});
+ texture.setImages(images);
+ texture.createOrUpdateGLTexture();
+
+ // THEN
+ QVERIFY(texture.properties().format != QAbstractTexture::Automatic);
+ QVERIFY(texture.properties().format != QAbstractTexture::NoFormat);
+
+ // Cleanup
+ texture.destroy();
+ }
};
QTEST_MAIN(tst_GLTexture);