summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-08-17 09:07:20 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-08-17 09:07:21 +0200
commitebd195c59fe50c49dd28f27828afa802384d7011 (patch)
treeb19869be7f7458aa2569ff2afe2f38a48ee711f1
parentdb836a410555108adff3bd594cf75f4174069f0c (diff)
parentccfe440c34479377363679fc890f10b44ee57769 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
-rw-r--r--examples/qt3d/exampleresources/assets/gltf/wine/LICENSE.md33
-rw-r--r--examples/qt3d/exampleresources/assets/gltf/wine/qt_attribution.json15
-rw-r--r--src/extras/defaults/qforwardrenderer.cpp4
-rw-r--r--src/plugins/sceneparsers/sceneparsers.pro3
-rw-r--r--src/quick3d/quick3dscene2d/items/scene2d.cpp2
-rw-r--r--src/render/backend/resourceaccessor.cpp16
-rw-r--r--src/render/backend/resourceaccessor_p.h3
-rw-r--r--src/render/jobs/job_common_p.h3
-rw-r--r--src/render/jobs/loadscenejob.cpp2
-rw-r--r--src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp6
-rw-r--r--src/render/renderers/opengl/graphicshelpers/submissioncontext_p.h1
-rw-r--r--src/render/renderers/opengl/jobs/renderviewjobutils_p.h2
-rw-r--r--src/render/renderers/opengl/renderer/renderer.cpp41
-rw-r--r--src/render/renderers/opengl/renderer/renderer_p.h5
-rw-r--r--src/render/renderers/opengl/textures/gltexture.cpp162
-rw-r--r--src/render/renderers/opengl/textures/gltexture_p.h11
-rw-r--r--src/render/texture/texture.cpp90
-rw-r--r--src/render/texture/texture_p.h6
-rw-r--r--tests/auto/render/texture/tst_texture.cpp186
-rw-r--r--tests/manual/manual.pro3
-rw-r--r--tests/manual/texture_property_updates/image.jpgbin0 -> 6173 bytes
-rw-r--r--tests/manual/texture_property_updates/image2.jpgbin0 -> 3983 bytes
-rw-r--r--tests/manual/texture_property_updates/main.cpp102
-rw-r--r--tests/manual/texture_property_updates/main.qml187
-rw-r--r--tests/manual/texture_property_updates/texture_property_updates.pro10
-rw-r--r--tests/manual/texture_property_updates/texture_property_updates.qrc7
-rw-r--r--tools/tools.pro3
27 files changed, 754 insertions, 149 deletions
diff --git a/examples/qt3d/exampleresources/assets/gltf/wine/LICENSE.md b/examples/qt3d/exampleresources/assets/gltf/wine/LICENSE.md
new file mode 100644
index 000000000..25e13f1d6
--- /dev/null
+++ b/examples/qt3d/exampleresources/assets/gltf/wine/LICENSE.md
@@ -0,0 +1,33 @@
+This license is for the example glTF code, not the [specification](specification/README.md) and [schema](specification).
+
+Original work Copyright (c) 2012, Motorola Mobility, Inc.
+All Rights Reserved.
+BSD License.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name of Motorola Mobility nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+Additional contributions copyright their respective contributors (also BSD License):
+ * Fabrice Robinet
+ * Analytical Graphics, Inc.
diff --git a/examples/qt3d/exampleresources/assets/gltf/wine/qt_attribution.json b/examples/qt3d/exampleresources/assets/gltf/wine/qt_attribution.json
new file mode 100644
index 000000000..c79a6fa5a
--- /dev/null
+++ b/examples/qt3d/exampleresources/assets/gltf/wine/qt_attribution.json
@@ -0,0 +1,15 @@
+{
+ "Id": "gltf-wine",
+ "Name": "glTF sample model \"wine\"",
+ "QDocModule": "qt3d",
+ "QtUsage": "Used in the Qt 3D autotests.",
+
+ "QtParts": [ "tests" ] ,
+ "Description": "Example from the official KhronosGroup/glTF repository",
+ "Homepage": "https://github.com/KhronosGroup/glTF",
+ "Version": "v0.8",
+ "LicenseId": "BSD-3-Clause",
+ "License": "BSD 3-Clause \"New\" or \"Revised\" License",
+ "LicenseFile": "LICENSE.md",
+ "Copyright": "Copyright (c) 2012, Motorola Mobility, Inc."
+}
diff --git a/src/extras/defaults/qforwardrenderer.cpp b/src/extras/defaults/qforwardrenderer.cpp
index b02077298..7548c45c6 100644
--- a/src/extras/defaults/qforwardrenderer.cpp
+++ b/src/extras/defaults/qforwardrenderer.cpp
@@ -293,7 +293,7 @@ QSize QForwardRenderer::externalRenderTargetSize() const
}
/*!
- \qmlproperty color ForwardRenderer::frustumCulling
+ \qmlproperty bool ForwardRenderer::frustumCulling
Indicates if the renderer applies frustum culling to the scene.
*/
@@ -309,7 +309,7 @@ bool QForwardRenderer::isFrustumCullingEnabled() const
}
/*!
- \qmlproperty color ForwardRenderer::gamma
+ \qmlproperty real ForwardRenderer::gamma
Holds the gamma value the renderer applies to the scene.
*/
diff --git a/src/plugins/sceneparsers/sceneparsers.pro b/src/plugins/sceneparsers/sceneparsers.pro
index cb274b472..e4b421606 100644
--- a/src/plugins/sceneparsers/sceneparsers.pro
+++ b/src/plugins/sceneparsers/sceneparsers.pro
@@ -2,8 +2,9 @@ TEMPLATE = subdirs
# QNX is not supported, and Linux GCC 4.9 on ARM chokes on the assimp
# sources (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66964).
QT_FOR_CONFIG += 3dcore-private
-qtConfig(assimp):if(qtConfig(system-assimp)|!cross_compile): \
+qtConfig(assimp):if(qtConfig(system-assimp)|android-clang|!cross_compile): {
SUBDIRS += assimp
+}
SUBDIRS += gltf
qtConfig(temporaryfile):qtConfig(regularexpression) {
diff --git a/src/quick3d/quick3dscene2d/items/scene2d.cpp b/src/quick3d/quick3dscene2d/items/scene2d.cpp
index c29f741ae..b5c25431f 100644
--- a/src/quick3d/quick3dscene2d/items/scene2d.cpp
+++ b/src/quick3d/quick3dscene2d/items/scene2d.cpp
@@ -336,7 +336,7 @@ void Scene2D::render()
if (resourceAccessor()->accessResource(RenderBackendResourceAccessor::OutputAttachment,
m_outputId, (void**)&attachmentData, nullptr)) {
- if (!resourceAccessor()->accessResource(RenderBackendResourceAccessor::OGLTexture,
+ if (!resourceAccessor()->accessResource(RenderBackendResourceAccessor::OGLTextureWrite,
attachmentData->m_textureUuid,
(void**)&texture, &textureLock)) {
// Need to call sync even if the texture is not in use
diff --git a/src/render/backend/resourceaccessor.cpp b/src/render/backend/resourceaccessor.cpp
index 8ca11e7a7..c6496976a 100644
--- a/src/render/backend/resourceaccessor.cpp
+++ b/src/render/backend/resourceaccessor.cpp
@@ -73,7 +73,10 @@ bool ResourceAccessor::accessResource(ResourceType type, Qt3DCore::QNodeId nodeI
{
switch (type) {
- case RenderBackendResourceAccessor::OGLTexture: {
+ case RenderBackendResourceAccessor::OGLTextureWrite:
+ Q_FALLTHROUGH();
+ case RenderBackendResourceAccessor::OGLTextureRead:
+ {
Texture *tex = m_textureManager->lookupResource(nodeId);
if (!tex)
return false;
@@ -85,10 +88,15 @@ bool ResourceAccessor::accessResource(ResourceType type, Qt3DCore::QNodeId nodeI
if (glTex->isDirty())
return false;
- glTex->setExternalRenderingEnabled(true);
+ if (type == RenderBackendResourceAccessor::OGLTextureWrite)
+ glTex->setExternalRenderingEnabled(true);
+
QOpenGLTexture **glTextureHandle = reinterpret_cast<QOpenGLTexture **>(handle);
- *glTextureHandle = glTex->getOrCreateGLTexture();
- *lock = glTex->externalRenderingLock();
+ *glTextureHandle = glTex->getGLTexture();
+
+ if (type == RenderBackendResourceAccessor::OGLTextureWrite)
+ *lock = glTex->externalRenderingLock();
+
return true;
}
diff --git a/src/render/backend/resourceaccessor_p.h b/src/render/backend/resourceaccessor_p.h
index 10e4abaa9..627efcb0d 100644
--- a/src/render/backend/resourceaccessor_p.h
+++ b/src/render/backend/resourceaccessor_p.h
@@ -73,7 +73,8 @@ class RenderBackendResourceAccessor
{
public:
enum ResourceType {
- OGLTexture,
+ OGLTextureWrite,
+ OGLTextureRead,
OutputAttachment,
EntityHandle,
};
diff --git a/src/render/jobs/job_common_p.h b/src/render/jobs/job_common_p.h
index 03e2cc90e..2ae7d81ff 100644
--- a/src/render/jobs/job_common_p.h
+++ b/src/render/jobs/job_common_p.h
@@ -106,7 +106,8 @@ namespace JobTypes {
ProximityFiltering,
SyncFilterEntityByLayer,
SyncMaterialGatherer,
- UpdateLayerEntity
+ UpdateLayerEntity,
+ SendTextureChangesToFrontend
};
} // JobTypes
diff --git a/src/render/jobs/loadscenejob.cpp b/src/render/jobs/loadscenejob.cpp
index f767fe720..9885d3225 100644
--- a/src/render/jobs/loadscenejob.cpp
+++ b/src/render/jobs/loadscenejob.cpp
@@ -183,7 +183,7 @@ Qt3DCore::QEntity *LoadSceneJob::tryLoadScene(Scene *scene,
}
if (!foundSuitableLoggerPlugin)
- qCWarning(SceneLoaders) << Q_FUNC_INFO << "Found not suitable importer plugin for" << m_source;
+ qCWarning(SceneLoaders) << Q_FUNC_INFO << "Found no suitable importer plugin for" << m_source;
return sceneSubTree;
}
diff --git a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
index cdc895f4d..7bb0713ee 100644
--- a/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
+++ b/src/render/renderers/opengl/graphicshelpers/submissioncontext.cpp
@@ -378,7 +378,6 @@ unsigned int nextFreeContextId()
SubmissionContext::SubmissionContext()
: GraphicsContext()
- , m_initialized(false)
, m_ownCurrent(true)
, m_id(nextFreeContextId())
, m_surface(nullptr)
@@ -473,9 +472,8 @@ bool SubmissionContext::beginDrawing(QSurface *surface)
}
#endif
- if (!m_initialized) {
+ if (!isInitialized())
initialize();
- }
// need to reset these values every frame, may get overwritten elsewhere
m_gl->functions()->glClearColor(m_currClearColorValue.redF(), m_currClearColorValue.greenF(), m_currClearColorValue.blueF(), m_currClearColorValue.alphaF());
@@ -863,7 +861,7 @@ void SubmissionContext::bindFrameBufferAttachmentHelper(GLuint fboId, const Atta
for (const Attachment &attachment : attachments_) {
GLTexture *rTex = glTextureManager->lookupResource(attachment.m_textureUuid);
if (!m_glHelper->frameBufferNeedsRenderBuffer(attachment)) {
- QOpenGLTexture *glTex = rTex ? rTex->getOrCreateGLTexture() : nullptr;
+ QOpenGLTexture *glTex = rTex ? rTex->getGLTexture() : nullptr;
if (glTex != nullptr) {
// The texture can not be rendered simultaniously by another renderer
Q_ASSERT(!rTex->isExternalRenderingEnabled());
diff --git a/src/render/renderers/opengl/graphicshelpers/submissioncontext_p.h b/src/render/renderers/opengl/graphicshelpers/submissioncontext_p.h
index 2881812e5..d502a8b27 100644
--- a/src/render/renderers/opengl/graphicshelpers/submissioncontext_p.h
+++ b/src/render/renderers/opengl/graphicshelpers/submissioncontext_p.h
@@ -185,7 +185,6 @@ private:
QByteArray downloadDataFromGLBuffer(Buffer *buffer, GLBuffer *b);
bool bindGLBuffer(GLBuffer *buffer, GLBuffer::Type type);
- bool m_initialized;
bool m_ownCurrent;
const unsigned int m_id;
QSurface *m_surface;
diff --git a/src/render/renderers/opengl/jobs/renderviewjobutils_p.h b/src/render/renderers/opengl/jobs/renderviewjobutils_p.h
index 3986f837d..90c4a53cc 100644
--- a/src/render/renderers/opengl/jobs/renderviewjobutils_p.h
+++ b/src/render/renderers/opengl/jobs/renderviewjobutils_p.h
@@ -104,7 +104,7 @@ Q_AUTOTEST_EXPORT RenderPassList findRenderPassesForTechnique(NodeManagers *mana
// Extracts the type T from a QVariant v without using QVariant::value which is slow
// Note: Assumes you are 100% sure about the type you requested
template<typename T>
-Q_AUTOTEST_EXPORT inline T variant_value(const QVariant &v)
+inline T variant_value(const QVariant &v)
{
return *reinterpret_cast<const T *>(v.data());
}
diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp
index a970a0479..7319fd0e5 100644
--- a/src/render/renderers/opengl/renderer/renderer.cpp
+++ b/src/render/renderers/opengl/renderer/renderer.cpp
@@ -194,6 +194,7 @@ Renderer::Renderer(QRenderAspect::RenderType type)
, m_bufferGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForDirtyBuffers(); }, JobTypes::DirtyBufferGathering))
, m_vaoGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForAbandonedVaos(); }, JobTypes::DirtyVaoGathering))
, m_textureGathererJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { lookForDirtyTextures(); }, JobTypes::DirtyTextureGathering))
+ , m_sendTextureChangesToFrontendJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { sendTextureChangesToFrontend(); }, JobTypes::SendTextureChangesToFrontend))
, m_introspectShaderJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([this] { reloadDirtyShaders(); }, JobTypes::DirtyShaderGathering))
, m_syncTextureLoadingJob(Render::GenericLambdaJobPtr<std::function<void ()>>::create([] {}, JobTypes::SyncTextureLoading))
, m_ownedContext(false)
@@ -1170,6 +1171,28 @@ void Renderer::reloadDirtyShaders()
}
}
+// Executed in a job
+void Renderer::sendTextureChangesToFrontend()
+{
+ const QVector<QPair<TextureProperties, Qt3DCore::QNodeIdVector>> updateTextureProperties = std::move(m_updatedTextureProperties);
+ for (const auto &pair : updateTextureProperties) {
+ // Prepare change notification
+
+ const Qt3DCore::QNodeIdVector targetIds = pair.second;
+ for (const Qt3DCore::QNodeId targetId: targetIds) {
+ // Lookup texture
+ Texture *t = m_nodesManager->textureManager()->lookupResource(targetId);
+
+ // Texture might have been deleted between previous and current frame
+ if (t == nullptr)
+ continue;
+
+ // Send change and update backend
+ t->updatePropertiesAndNotify(pair.first);
+ }
+ }
+}
+
// Render Thread (or QtQuick RenderThread when using Scene3D)
// Scene3D: When using Scene3D rendering, we can't assume that when
// updateGLResources is called, the resource handles points to still existing
@@ -1230,7 +1253,7 @@ void Renderer::updateGLResources()
if (texture == nullptr)
continue;
- // Update texture properties
+ // Create or Update GLTexture
updateTexture(texture);
}
// We want to upload textures data at this point as the SubmissionThread and
@@ -1240,8 +1263,17 @@ void Renderer::updateGLResources()
GLTextureManager *glTextureManager = m_nodesManager->glTextureManager();
const QVector<GLTexture *> glTextures = glTextureManager->activeResources();
// Upload texture data
- for (GLTexture *glTexture : glTextures)
- glTexture->getOrCreateGLTexture();
+ for (GLTexture *glTexture : glTextures) {
+ const GLTexture::TextureUpdateInfo info = glTexture->createOrUpdateGLTexture();
+
+ // GLTexture creation provides us width/height/format ... information
+ // for textures which had not initially specified these information (TargetAutomatic...)
+ // Gather these information and store them to be distributed by a change next frame
+ const QNodeIdVector referenceTextureIds = glTextureManager->referencedTextureIds(glTexture);
+ // Store properties and referenceTextureIds
+ if (info.wasUpdated)
+ m_updatedTextureProperties.push_back({info.properties, referenceTextureIds});
+ }
}
}
// When Textures are cleaned up, their id is saved so that they can be
@@ -1664,6 +1696,9 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
renderBinJobs.push_back(m_sendRenderCaptureJob);
}
+ // Do we need to notify any texture about property changes?
+ if (m_updatedTextureProperties.size() > 0)
+ renderBinJobs.push_back(m_sendTextureChangesToFrontendJob);
renderBinJobs.push_back(m_sendBufferCaptureJob);
renderBinJobs.append(bufferJobs);
diff --git a/src/render/renderers/opengl/renderer/renderer_p.h b/src/render/renderers/opengl/renderer/renderer_p.h
index b501fe6a0..23708e3e8 100644
--- a/src/render/renderers/opengl/renderer/renderer_p.h
+++ b/src/render/renderers/opengl/renderer/renderer_p.h
@@ -79,6 +79,7 @@
#include <Qt3DRender/private/updateskinningpalettejob_p.h>
#include <Qt3DRender/private/updateentitylayersjob_p.h>
#include <Qt3DRender/private/renderercache_p.h>
+#include <Qt3DRender/private/texture_p.h>
#include <QHash>
#include <QMatrix4x4>
@@ -216,6 +217,7 @@ public:
inline IntrospectShadersJobPtr introspectShadersJob() const { return m_introspectShaderJob; }
inline Qt3DCore::QAspectJobPtr bufferGathererJob() const { return m_bufferGathererJob; }
inline Qt3DCore::QAspectJobPtr textureGathererJob() const { return m_textureGathererJob; }
+ inline Qt3DCore::QAspectJobPtr sendTextureChangesToFrontendJob() const { return m_sendTextureChangesToFrontendJob; }
inline UpdateEntityLayersJobPtr updateEntityLayersJob() const { return m_updateEntityLayersJob; }
Qt3DCore::QAbstractFrameAdvanceService *frameAdvanceService() const override;
@@ -370,6 +372,7 @@ private:
GenericLambdaJobPtr<std::function<void ()>> m_bufferGathererJob;
GenericLambdaJobPtr<std::function<void ()>> m_vaoGathererJob;
GenericLambdaJobPtr<std::function<void ()>> m_textureGathererJob;
+ GenericLambdaJobPtr<std::function<void ()>> m_sendTextureChangesToFrontendJob;
IntrospectShadersJobPtr m_introspectShaderJob;
SynchronizerJobPtr m_syncTextureLoadingJob;
@@ -379,6 +382,7 @@ private:
void lookForDownloadableBuffers();
void lookForDirtyTextures();
void reloadDirtyShaders();
+ void sendTextureChangesToFrontend();
QMutex m_abandonedVaosMutex;
QVector<HVao> m_abandonedVaos;
@@ -387,6 +391,7 @@ private:
QVector<HBuffer> m_downloadableBuffers;
QVector<HShader> m_dirtyShaders;
QVector<HTexture> m_dirtyTextures;
+ QVector<QPair<TextureProperties, Qt3DCore::QNodeIdVector>> m_updatedTextureProperties;
bool m_ownedContext;
diff --git a/src/render/renderers/opengl/textures/gltexture.cpp b/src/render/renderers/opengl/textures/gltexture.cpp
index 3d8664e78..b61d06a80 100644
--- a/src/render/renderers/opengl/textures/gltexture.cpp
+++ b/src/render/renderers/opengl/textures/gltexture.cpp
@@ -105,107 +105,133 @@ void GLTexture::destroyGLTexture()
destroyResources();
}
-QOpenGLTexture* GLTexture::getOrCreateGLTexture()
+bool GLTexture::loadTextureDataFromGenerator()
+{
+ m_textureData = m_textureDataManager->getData(m_dataFunctor);
+ // if there is a texture generator, most properties will be defined by it
+ if (m_textureData) {
+ if (m_properties.target != QAbstractTexture::TargetAutomatic)
+ qWarning() << "[Qt3DRender::GLTexture] When a texture provides a generator, it's target is expected to be TargetAutomatic";
+
+ m_actualTarget = m_textureData->target();
+ m_properties.width = m_textureData->width();
+ m_properties.height = m_textureData->height();
+ m_properties.depth = m_textureData->depth();
+ m_properties.layers = m_textureData->layers();
+ m_properties.format = m_textureData->format();
+
+ const QVector<QTextureImageDataPtr> imageData = m_textureData->imageData();
+
+ if (imageData.size() > 0) {
+ // Set the mips level based on the first image if autoMipMapGeneration is disabled
+ if (!m_properties.generateMipMaps)
+ m_properties.mipLevels = imageData.first()->mipLevels();
+ }
+ }
+ return !m_textureData.isNull();
+}
+
+void GLTexture::loadTextureDataFromImages()
+{
+ int maxMipLevel = 0;
+ for (const Image &img : qAsConst(m_images)) {
+ const QTextureImageDataPtr imgData = m_textureImageDataManager->getData(img.generator);
+ // imgData may be null in the following cases:
+ // - Texture is created with TextureImages which have yet to be
+ // loaded (skybox where you don't yet know the path, source set by
+ // a property binding, queued connection ...)
+ // - TextureImage whose generator failed to return a valid data
+ // (invalid url, error opening file...)
+ if (imgData.isNull())
+ continue;
+
+ m_imageData.push_back(imgData);
+ maxMipLevel = qMax(maxMipLevel, img.mipLevel);
+
+ // If the texture doesn't have a texture generator, we will
+ // derive some properties from the first TextureImage (layer=0, miplvl=0, face=0)
+ if (!m_textureData && img.layer == 0 && img.mipLevel == 0 && img.face == QAbstractTexture::CubeMapPositiveX) {
+ if (imgData->width() != -1 && imgData->height() != -1 && imgData->depth() != -1) {
+ m_properties.width = imgData->width();
+ m_properties.height = imgData->height();
+ m_properties.depth = imgData->depth();
+ }
+ // Set the format of the texture if the texture format is set to Automatic
+ if (m_properties.format == QAbstractTexture::Automatic) {
+ m_properties.format = static_cast<QAbstractTexture::TextureFormat>(imgData->format());
+ }
+ setDirtyFlag(Properties, true);
+ }
+ }
+
+ // make sure the number of mip levels is set when there is no texture data generator
+ if (!m_dataFunctor) {
+ m_properties.mipLevels = maxMipLevel + 1;
+ setDirtyFlag(Properties, true);
+ }
+}
+
+GLTexture::TextureUpdateInfo GLTexture::createOrUpdateGLTexture()
{
QMutexLocker locker(&m_textureMutex);
bool needUpload = false;
+ TextureUpdateInfo textureInfo;
+
+ m_properties.status = QAbstractTexture::Error;
// on the first invocation in the render thread, make sure to
// evaluate the texture data generator output
// (this might change some property values)
if (m_dataFunctor && !m_textureData) {
- m_textureData = m_textureDataManager->getData(m_dataFunctor);
-
- // if there is a texture generator, most properties will be defined by it
- if (m_textureData) {
- if (m_properties.target != QAbstractTexture::TargetAutomatic)
- qWarning() << "[Qt3DRender::GLTexture] When a texture provides a generator, it's target is expected to be TargetAutomatic";
-
- m_actualTarget = m_textureData->target();
- m_properties.width = m_textureData->width();
- m_properties.height = m_textureData->height();
- m_properties.depth = m_textureData->depth();
- m_properties.layers = m_textureData->layers();
- m_properties.format = m_textureData->format();
-
- const QVector<QTextureImageDataPtr> imageData = m_textureData->imageData();
-
- if (imageData.size() > 0) {
- // Set the mips level based on the first image if autoMipMapGeneration is disabled
- if (!m_properties.generateMipMaps)
- m_properties.mipLevels = imageData.first()->mipLevels();
- }
-
+ const bool successfullyLoadedTextureData = loadTextureDataFromGenerator();
+ if (successfullyLoadedTextureData) {
setDirtyFlag(Properties, true);
needUpload = true;
} else {
qWarning() << "[Qt3DRender::GLTexture] No QTextureData generated from Texture Generator yet. Texture will be invalid for this frame";
- return nullptr;
+ textureInfo.properties.status = QAbstractTexture::Loading;
+ return textureInfo;
}
}
// additional texture images may be defined through image data generators
if (testDirtyFlag(TextureData)) {
m_imageData.clear();
+ loadTextureDataFromImages();
needUpload = true;
-
- int maxMipLevel = 0;
- for (const Image &img : qAsConst(m_images)) {
- const QTextureImageDataPtr imgData = m_textureImageDataManager->getData(img.generator);
- // imgData may be null in the following cases:
- // - Texture is created with TextureImages which have yet to be
- // loaded (skybox where you don't yet know the path, source set by
- // a property binding, queued connection ...)
- // - TextureImage whose generator failed to return a valid data
- // (invalid url, error opening file...)
- if (imgData.isNull())
- continue;
-
- m_imageData.push_back(imgData);
- maxMipLevel = qMax(maxMipLevel, img.mipLevel);
-
- // If the texture doesn't have a texture generator, we will
- // derive some properties from the first TextureImage (layer=0, miplvl=0, face=0)
- if (!m_textureData && img.layer == 0 && img.mipLevel == 0 && img.face == QAbstractTexture::CubeMapPositiveX) {
- if (imgData->width() != -1 && imgData->height() != -1 && imgData->depth() != -1) {
- m_properties.width = imgData->width();
- m_properties.height = imgData->height();
- m_properties.depth = imgData->depth();
- }
- // Set the format of the texture if the texture format is set to Automatic
- if (m_properties.format == QAbstractTexture::Automatic) {
- m_properties.format = static_cast<QAbstractTexture::TextureFormat>(imgData->format());
- }
- setDirtyFlag(Properties, true);
- }
- }
-
- // make sure the number of mip levels is set when there is no texture data generator
- if (!m_dataFunctor) {
- m_properties.mipLevels = maxMipLevel + 1;
- setDirtyFlag(Properties, true);
- }
}
// don't try to create the texture if the format was not set
- if (m_properties.format == QAbstractTexture::Automatic)
- return nullptr;
+ if (m_properties.format == QAbstractTexture::Automatic) {
+ textureInfo.properties.status = QAbstractTexture::Error;
+ return textureInfo;
+ }
// if the properties changed, we need to re-allocate the texture
if (testDirtyFlag(Properties)) {
delete m_gl;
m_gl = nullptr;
+ textureInfo.wasUpdated = true;
}
+
if (!m_gl) {
m_gl = buildGLTexture();
- if (!m_gl)
- return nullptr;
+ if (!m_gl) {
+ textureInfo.properties.status = QAbstractTexture::Error;
+ return textureInfo;
+ }
+
m_gl->allocateStorage();
if (!m_gl->isStorageAllocated()) {
- return nullptr;
+ textureInfo.properties.status = QAbstractTexture::Error;
+ return textureInfo;
}
}
+ m_properties.status = QAbstractTexture::Ready;
+
+ textureInfo.properties = m_properties;
+ textureInfo.texture = m_gl;
// need to (re-)upload texture data?
if (needUpload) {
@@ -223,7 +249,7 @@ QOpenGLTexture* GLTexture::getOrCreateGLTexture()
setDirtyFlag(Properties, false);
setDirtyFlag(Parameters, false);
- return m_gl;
+ return textureInfo;
}
RenderBuffer *GLTexture::getOrCreateRenderBuffer()
@@ -442,7 +468,7 @@ void GLTexture::uploadGLTextureData()
}
// Upload all QTexImageData references by the TextureImages
- for (int i = 0; i < m_images.size(); i++) {
+ for (int i = 0; i < std::min(m_images.size(), m_imageData.size()); i++) {
const QTextureImageDataPtr &imgData = m_imageData.at(i);
// Here the bytes in the QTextureImageData contain data for a single
// layer, face or mip level, unlike the QTextureGenerator case where
diff --git a/src/render/renderers/opengl/textures/gltexture_p.h b/src/render/renderers/opengl/textures/gltexture_p.h
index 5f4a20d30..dd0e05e36 100644
--- a/src/render/renderers/opengl/textures/gltexture_p.h
+++ b/src/render/renderers/opengl/textures/gltexture_p.h
@@ -140,7 +140,14 @@ public:
* If the texture properties or parameters have changed, these changes
* will be applied to the resulting OpenGL texture.
*/
- QOpenGLTexture* getOrCreateGLTexture();
+ struct TextureUpdateInfo
+ {
+ QOpenGLTexture *texture = nullptr;
+ bool wasUpdated = false;
+ TextureProperties properties;
+ };
+
+ TextureUpdateInfo createOrUpdateGLTexture();
/**
* @brief
@@ -221,6 +228,8 @@ private:
}
QOpenGLTexture *buildGLTexture();
+ bool loadTextureDataFromGenerator();
+ void loadTextureDataFromImages();
void uploadGLTextureData();
void updateGLTextureParameters();
void destroyResources();
diff --git a/src/render/texture/texture.cpp b/src/render/texture/texture.cpp
index 440a08e26..749b85802 100644
--- a/src/render/texture/texture.cpp
+++ b/src/render/texture/texture.cpp
@@ -117,24 +117,8 @@ void Texture::cleanup()
m_textureImageIds.clear();
// set default values
- m_properties.width = 1;
- m_properties.height = 1;
- m_properties.depth = 1;
- m_properties.layers = 1;
- m_properties.mipLevels = 1;
- m_properties.samples = 1;
- m_properties.generateMipMaps = false;
- m_properties.format = QAbstractTexture::RGBA8_UNorm;
- m_properties.target = QAbstractTexture::Target2D;
-
- m_parameters.magnificationFilter = QAbstractTexture::Nearest;
- m_parameters.minificationFilter = QAbstractTexture::Nearest;
- m_parameters.wrapModeX = QTextureWrapMode::ClampToEdge;
- m_parameters.wrapModeY = QTextureWrapMode::ClampToEdge;
- m_parameters.wrapModeZ = QTextureWrapMode::ClampToEdge;
- m_parameters.maximumAnisotropy = 1.0f;
- m_parameters.comparisonFunction = QAbstractTexture::CompareLessEqual;
- m_parameters.comparisonMode = QAbstractTexture::CompareNone;
+ m_properties = {};
+ m_parameters = {};
m_dirty = NotDirty;
}
@@ -156,9 +140,6 @@ void Texture::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
} else if (propertyChange->propertyName() == QByteArrayLiteral("depth")) {
m_properties.depth = propertyChange->value().toInt();
dirty = DirtyProperties;
- } else if (propertyChange->propertyName() == QByteArrayLiteral("maximumLayers")) {
- m_properties.layers = propertyChange->value().toInt();
- dirty = DirtyProperties;
} else if (propertyChange->propertyName() == QByteArrayLiteral("format")) {
m_properties.format = static_cast<QAbstractTexture::TextureFormat>(propertyChange->value().toInt());
dirty = DirtyProperties;
@@ -229,80 +210,79 @@ void Texture::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
BackendNode::sceneChangeEvent(e);
}
-void Texture::notifyStatus(QAbstractTexture::Status status)
+// Called by sceneChangeEvent or TextureDownloadRequest (both in AspectThread context)
+void Texture::setDataGenerator(const QTextureGeneratorPtr &generator)
{
- auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
- change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
- change->setPropertyName("status");
- change->setValue(status);
- notifyObservers(change);
+ m_dataFunctor = generator;
+ addDirtyFlag(DirtyDataGenerator);
}
-void Texture::updateFromData(QTextureDataPtr data)
+// Called by sendTextureChangesToFrontendJob once GLTexture and sharing
+// has been performed
+void Texture::updatePropertiesAndNotify(const TextureProperties &properties)
{
- if (data->width() != m_properties.width) {
- m_properties.width = data->width();
+ // If we are Dirty, some property has changed and the properties we have
+ // received are potentially already outdated
+ if (m_dirty != NotDirty)
+ return;
+
+ // Note we don't update target has it is constant for frontend nodes
+
+ if (properties.width != m_properties.width) {
+ m_properties.width = properties.width;
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
change->setPropertyName("width");
- change->setValue(data->width());
+ change->setValue(properties.width);
notifyObservers(change);
}
- if (data->height() != m_properties.height) {
- m_properties.height = data->height();
+ if (properties.height != m_properties.height) {
+ m_properties.height = properties.height;
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
change->setPropertyName("height");
- change->setValue(data->height());
+ change->setValue(properties.height);
notifyObservers(change);
}
- if (data->depth() != m_properties.depth) {
- m_properties.depth = data->depth();
+ if (properties.depth != m_properties.depth) {
+ m_properties.depth = properties.depth;
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
change->setPropertyName("depth");
- change->setValue(data->depth());
+ change->setValue(properties.depth);
notifyObservers(change);
}
- if (data->layers() != m_properties.layers) {
- m_properties.layers = data->layers();
+ if (properties.layers != m_properties.layers) {
+ m_properties.layers = properties.layers;
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
change->setPropertyName("layers");
- change->setValue(data->layers());
+ change->setValue(properties.layers);
notifyObservers(change);
}
- if (data->format() != m_properties.format) {
- m_properties.format = data->format();
+ if (properties.format != m_properties.format) {
+ m_properties.format = properties.format;
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
change->setPropertyName("format");
- change->setValue(data->format());
+ change->setValue(properties.format);
notifyObservers(change);
}
- if (data->target() != m_properties.target) {
- // TODO frontend property is actually constant
- m_properties.target = data->target();
+ if (properties.status != m_properties.status) {
+ m_properties.status = properties.status;
auto change = Qt3DCore::QPropertyUpdatedChangePtr::create(peerId());
change->setDeliveryFlags(Qt3DCore::QSceneChange::Nodes);
- change->setPropertyName("target");
- change->setValue(data->target());
+ change->setPropertyName("status");
+ change->setValue(properties.status);
notifyObservers(change);
}
}
-// Called by sceneChangeEvent or TextureDownloadRequest (both in AspectThread context)
-void Texture::setDataGenerator(const QTextureGeneratorPtr &generator)
-{
- m_dataFunctor = generator;
- addDirtyFlag(DirtyDataGenerator);
-}
-
bool Texture::isValid(TextureImageManager *manager) const
{
for (const QNodeId id : m_textureImageIds) {
diff --git a/src/render/texture/texture_p.h b/src/render/texture/texture_p.h
index b9ef0385f..9e385cefe 100644
--- a/src/render/texture/texture_p.h
+++ b/src/render/texture/texture_p.h
@@ -86,12 +86,13 @@ struct TextureProperties
QAbstractTexture::Target target = QAbstractTexture::Target2D;
QAbstractTexture::TextureFormat format = QAbstractTexture::RGBA8_UNorm;
bool generateMipMaps = false;
+ QAbstractTexture::Status status = QAbstractTexture::None;
bool operator==(const TextureProperties &o) const {
return (width == o.width) && (height == o.height) && (depth == o.depth)
&& (layers == o.layers) && (mipLevels == o.mipLevels) && (target == o.target)
&& (format == o.format) && (generateMipMaps == o.generateMipMaps)
- && (samples == o.samples);
+ && (samples == o.samples) && (status == o.status);
}
inline bool operator!=(const TextureProperties &o) const { return !(*this == o); }
};
@@ -155,9 +156,8 @@ public:
inline const Qt3DCore::QNodeIdVector textureImageIds() const { return m_textureImageIds; }
inline const QTextureGeneratorPtr& dataGenerator() const { return m_dataFunctor; }
- void notifyStatus(QAbstractTexture::Status status);
- void updateFromData(QTextureDataPtr data);
void setDataGenerator(const QTextureGeneratorPtr &generator);
+ void updatePropertiesAndNotify(const TextureProperties &propreties);
bool isValid(TextureImageManager *manager) const;
private:
void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
diff --git a/tests/auto/render/texture/tst_texture.cpp b/tests/auto/render/texture/tst_texture.cpp
index 2e94cda24..9876518e2 100644
--- a/tests/auto/render/texture/tst_texture.cpp
+++ b/tests/auto/render/texture/tst_texture.cpp
@@ -47,6 +47,22 @@ public:
}
};
+class FakeGenerator : public Qt3DRender::QTextureGenerator
+{
+public:
+ QT3D_FUNCTOR(FakeGenerator)
+
+ Qt3DRender::QTextureDataPtr operator ()() override
+ {
+ return {};
+ }
+
+ bool operator ==(const QTextureGenerator &) const override
+ {
+ return true;
+ }
+};
+
class tst_RenderTexture : public Qt3DCore::QBackendNodeTester
{
Q_OBJECT
@@ -242,6 +258,7 @@ void tst_RenderTexture::checkPropertyChanges()
TestRenderer renderer;
Qt3DRender::Render::Texture backend;
backend.setRenderer(&renderer);
+ backend.unsetDirty();
// WHEN
Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
@@ -252,7 +269,9 @@ void tst_RenderTexture::checkPropertyChanges()
// THEN
QCOMPARE(backend.properties().width, 256);
QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
// WHEN
updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
@@ -263,7 +282,9 @@ void tst_RenderTexture::checkPropertyChanges()
// THEN
QCOMPARE(backend.properties().height, 128);
QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
// WHEN
updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
@@ -274,7 +295,152 @@ void tst_RenderTexture::checkPropertyChanges()
// THEN
QCOMPARE(backend.properties().depth, 16);
QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QAbstractTexture::RGB16F));
+ updateChange->setPropertyName("format");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.properties().format, Qt3DRender::QAbstractTexture::RGB16F);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QAbstractTexture::Target1DArray));
+ updateChange->setPropertyName("target");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.properties().target, Qt3DRender::QAbstractTexture::Target1DArray);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(true);
+ updateChange->setPropertyName("mipmaps");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.properties().generateMipMaps, true);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QAbstractTexture::LinearMipMapLinear));
+ updateChange->setPropertyName("minificationFilter");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().minificationFilter, Qt3DRender::QAbstractTexture::LinearMipMapLinear);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QAbstractTexture::Linear));
+ updateChange->setPropertyName("magnificationFilter");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().magnificationFilter, Qt3DRender::QAbstractTexture::Linear);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QTextureWrapMode::Repeat));
+ updateChange->setPropertyName("wrapModeX");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().wrapModeX, Qt3DRender::QTextureWrapMode::Repeat);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QTextureWrapMode::Repeat));
+ updateChange->setPropertyName("wrapModeY");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().wrapModeY, Qt3DRender::QTextureWrapMode::Repeat);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QTextureWrapMode::Repeat));
+ updateChange->setPropertyName("wrapModeZ");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().wrapModeZ, Qt3DRender::QTextureWrapMode::Repeat);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(16.0f);
+ updateChange->setPropertyName("maximumAnisotropy");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().maximumAnisotropy, 16.0f);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QAbstractTexture::CompareEqual));
+ updateChange->setPropertyName("comparisonFunction");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().comparisonFunction, Qt3DRender::QAbstractTexture::CompareEqual);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ updateChange->setValue(QVariant::fromValue(Qt3DRender::QAbstractTexture::CompareRefToTexture));
+ updateChange->setPropertyName("comparisonMode");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.parameters().comparisonMode, Qt3DRender::QAbstractTexture::CompareRefToTexture);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyParameters);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
// WHEN
updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
@@ -285,7 +451,9 @@ void tst_RenderTexture::checkPropertyChanges()
// THEN
QCOMPARE(backend.properties().layers, 32);
QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
// WHEN
updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
@@ -296,7 +464,23 @@ void tst_RenderTexture::checkPropertyChanges()
// THEN
QCOMPARE(backend.properties().samples, 64);
QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyProperties);
+ renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
+
+ // WHEN
+ updateChange = QSharedPointer<Qt3DCore::QPropertyUpdatedChange>::create(Qt3DCore::QNodeId());
+ Qt3DRender::QTextureGeneratorPtr gen = QSharedPointer<FakeGenerator>::create();
+ updateChange->setValue(QVariant::fromValue(gen));
+ updateChange->setPropertyName("generator");
+ backend.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backend.dataGenerator(), gen);
+ QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyDataGenerator);
renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
// WHEN
Qt3DRender::QTextureImage img;
@@ -308,7 +492,9 @@ void tst_RenderTexture::checkPropertyChanges()
QCOMPARE(backend.textureImageIds().size(), 1);
QCOMPARE(backend.textureImageIds().first(), img.id());
QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::TexturesDirty);
+ QVERIFY(backend.dirtyFlags() == Qt3DRender::Render::Texture::DirtyImageGenerators);
renderer.clearDirtyBits(Qt3DRender::Render::AbstractRenderer::AllDirty);
+ backend.unsetDirty();
}
void tst_RenderTexture::checkTextureImageBookeeping()
diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro
index f5f60f6cb..643d03e6e 100644
--- a/tests/manual/manual.pro
+++ b/tests/manual/manual.pro
@@ -58,7 +58,8 @@ SUBDIRS += \
rendercapture-qml-fbo \
blitframebuffer-qml \
raycasting-qml \
- shared_texture_image
+ shared_texture_image \
+ texture_property_updates
qtHaveModule(widgets): {
SUBDIRS += \
diff --git a/tests/manual/texture_property_updates/image.jpg b/tests/manual/texture_property_updates/image.jpg
new file mode 100644
index 000000000..495afa5ce
--- /dev/null
+++ b/tests/manual/texture_property_updates/image.jpg
Binary files differ
diff --git a/tests/manual/texture_property_updates/image2.jpg b/tests/manual/texture_property_updates/image2.jpg
new file mode 100644
index 000000000..37f6de3e5
--- /dev/null
+++ b/tests/manual/texture_property_updates/image2.jpg
Binary files differ
diff --git a/tests/manual/texture_property_updates/main.cpp b/tests/manual/texture_property_updates/main.cpp
new file mode 100644
index 000000000..e145b0a26
--- /dev/null
+++ b/tests/manual/texture_property_updates/main.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QQuickView>
+#include <QGuiApplication>
+#include <QQmlContext>
+#include <Qt3DRender/QAbstractTexture>
+
+template<typename Obj>
+QHash<int, QString> enumToNameMap(const char *enumName)
+{
+ const QMetaObject metaObj = Obj::staticMetaObject;
+ const int indexOfEnum = metaObj.indexOfEnumerator(enumName);
+ const QMetaEnum metaEnum = metaObj.enumerator(indexOfEnum);
+ const int keysCount = metaEnum.keyCount();
+
+ QHash<int, QString> v;
+ v.reserve(keysCount);
+ for (int i = 0; i < keysCount; ++i)
+ v[metaEnum.value(i)] = metaEnum.key(i);
+ return v;
+}
+
+
+class EnumNameMapper : public QObject
+{
+ Q_OBJECT
+
+public:
+ Q_INVOKABLE QString statusName(int v) const { return m_statusMap.value(v); }
+ Q_INVOKABLE QString formatName(int v) const { return m_formatMap.value(v); }
+ Q_INVOKABLE QString targetName(int v) const { return m_targetMap.value(v); }
+
+private:
+ const QHash<int, QString> m_statusMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Status");
+ const QHash<int, QString> m_formatMap = enumToNameMap<Qt3DRender::QAbstractTexture>("TextureFormat");
+ const QHash<int, QString> m_targetMap = enumToNameMap<Qt3DRender::QAbstractTexture>("Target");
+};
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+ QQuickView view;
+
+ QQmlContext *ctx =view.rootContext();
+ EnumNameMapper mapper;
+ ctx->setContextProperty(QStringLiteral("nameMapper"), &mapper);
+
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/texture_property_updates/main.qml b/tests/manual/texture_property_updates/main.qml
new file mode 100644
index 000000000..ebefdc725
--- /dev/null
+++ b/tests/manual/texture_property_updates/main.qml
@@ -0,0 +1,187 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.2 as QQ2
+import QtQuick.Scene3D 2.0
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Input 2.0
+import Qt3D.Extras 2.0
+
+QQ2.Item {
+ id: root
+ width: 1280
+ height: 720
+
+ property int i: 0
+ readonly property var sources: ["https://codereview.qt-project.org/gitweb?p=qt/qt3d.git;a=blob_plain;hb=refs/heads/dev;f=examples/qt3d/planets-qml/images/solarsystemscope/earthmap2k.jpg", "qrc:/image.jpg", "qrc:/image2.jpg", "qrc:/wrongpath.jpg"]
+ readonly property url textureSource: sources[i]
+
+ QQ2.Timer {
+ interval: 3000
+ repeat: true
+ running: true
+ onTriggered: i = (i + 1) % sources.length
+ }
+
+ Scene3D {
+ anchors.fill: parent
+ focus: true
+
+ aspects: ["input", "logic"]
+
+ Entity {
+ id: sceneRoot
+
+ readonly property var textureModel: [texture1, texture2, texture3, texture4]
+
+ readonly property Texture texture1: TextureLoader {
+ source: textureSource
+ }
+
+ readonly property Texture texture2: TextureLoader {
+ source: textureSource
+ }
+
+ readonly property Texture texture3: Texture2D {
+ textureImages: TextureImage {
+ source: textureSource
+ }
+ }
+
+ readonly property Texture texture4: Texture2D {
+ textureImages: TextureImage {
+ source: textureSource
+ }
+ }
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ aspectRatio: 16/9
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 20.0, -40.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ OrbitCameraController {
+ camera: camera
+ }
+
+ components: [
+ RenderSettings {
+ activeFrameGraph: ForwardRenderer {
+ clearColor: Qt.rgba(0, 0.5, 1, 1)
+ camera: camera
+ }
+ },
+ // Event Source will be set by the Qt3DQuickWindow
+ InputSettings { }
+ ]
+
+ CuboidMesh { id: mesh }
+
+ NodeInstantiator {
+ id: instantiator
+ model: sceneRoot.textureModel
+
+ Entity {
+ readonly property Transform transform: Transform {
+ readonly property real angle: model.index / instantiator.count * Math.PI * 2
+ translation: Qt.vector3d(Math.cos(angle) * 10, 0, Math.sin(angle) * 10)
+ scale: 10
+ }
+
+ readonly property DiffuseMapMaterial material: DiffuseMapMaterial {
+ diffuse: model.modelData
+ }
+ components: [ mesh, material, transform ]
+ }
+ }
+ }
+ }
+
+ QQ2.Text {
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ bottom: parent.bottom
+ }
+ font.pointSize: 20
+ text: "Source (" + (i + 1) + " of " + sources.length + "): " + textureSource
+ }
+
+ QQ2.ListView {
+ anchors {
+ left: parent.left
+ top: parent.top
+ bottom: parent.bottom
+ }
+ readonly property var targets: []
+ readonly property var status: []
+
+ spacing: 30
+ model: sceneRoot.textureModel
+ width: parent.width / 4
+ delegate: QQ2.Grid {
+ spacing: 10
+ columns: 2
+ QQ2.Text { text: "Target: " + nameMapper.targetName(model.modelData.target) }
+ QQ2.Text { text: "Format: " + nameMapper.formatName(model.modelData.format.toString()) }
+ QQ2.Text { text: "Width: " + model.modelData.width }
+ QQ2.Text { text: "Height: " + model.modelData.height }
+ QQ2.Text { text: "Depth: " + model.modelData.depth}
+ QQ2.Text { text: "Layers: " + model.modelData.layers}
+ QQ2.Text { text: "Status: " + nameMapper.statusName(model.modelData.status.toString()) }
+ }
+ }
+}
diff --git a/tests/manual/texture_property_updates/texture_property_updates.pro b/tests/manual/texture_property_updates/texture_property_updates.pro
new file mode 100644
index 000000000..33d72da68
--- /dev/null
+++ b/tests/manual/texture_property_updates/texture_property_updates.pro
@@ -0,0 +1,10 @@
+QT += 3dcore 3drender 3dinput 3dquick 3dlogic qml quick 3dquickextras
+
+SOURCES += \
+ main.cpp
+
+OTHER_FILES += \
+ main.qml
+
+RESOURCES += \
+ texture_property_updates.qrc
diff --git a/tests/manual/texture_property_updates/texture_property_updates.qrc b/tests/manual/texture_property_updates/texture_property_updates.qrc
new file mode 100644
index 000000000..eb086cd72
--- /dev/null
+++ b/tests/manual/texture_property_updates/texture_property_updates.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>image.jpg</file>
+ <file>image2.jpg</file>
+ </qresource>
+</RCC>
diff --git a/tools/tools.pro b/tools/tools.pro
index 64f2b9fc7..c2f692034 100644
--- a/tools/tools.pro
+++ b/tools/tools.pro
@@ -1,4 +1,5 @@
TEMPLATE = subdirs
QT_FOR_CONFIG += 3dcore-private
-qtConfig(assimp):qtConfig(commandlineparser): \
+qtConfig(assimp):qtConfig(commandlineparser):!cross_compile: {
SUBDIRS += qgltf
+}