diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-01-16 17:01:26 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2018-01-17 19:33:02 +0000 |
commit | 5b85e57ff54e6c6a108af5dbe668bc4661fe2f8b (patch) | |
tree | 85166dd1909dd2bf4cbe9c8cd2ef190c7ecd6693 | |
parent | 43c06d91f08c561b81575924d22db04efe10ba9b (diff) |
Load textures via QTextureLoader
...in order to get valid property values for width, height, etc.
However, this is still not perfect due to not updating these values when
a file has already been loaded by another QTexture. See QTBUG-65775.
And fix a missing QTexture registration.
Change-Id: I5ba7df2777b81beeb8f510a1c610f34dbfba3013
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r-- | src/runtime/profileui/q3dsprofileui.cpp | 39 | ||||
-rw-r--r-- | src/runtime/q3dsprofiler_p.h | 1 | ||||
-rw-r--r-- | src/runtime/q3dsscenemanager.cpp | 23 | ||||
-rw-r--r-- | src/runtime/q3dsscenemanager.h | 5 |
4 files changed, 31 insertions, 37 deletions
diff --git a/src/runtime/profileui/q3dsprofileui.cpp b/src/runtime/profileui/q3dsprofileui.cpp index c6b0170..3d9257e 100644 --- a/src/runtime/profileui/q3dsprofileui.cpp +++ b/src/runtime/profileui/q3dsprofileui.cpp @@ -196,13 +196,12 @@ void Q3DSProfileView::frame() auto tex2d = objs->values(Q3DSProfiler::Texture2DObject); ImGui::Text("2D textures: %d", tex2d.count()); if (ImGui::TreeNodeEx("2D texture details", tex2d.isEmpty() ? 0 : ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::Columns(6, "tex2dcols"); + ImGui::Columns(5, "tex2dcols"); ImGui::Separator(); ImGui::Text("Index"); ImGui::SetColumnWidth(-1, 50); ImGui::NextColumn(); ImGui::Text("Description"); ImGui::NextColumn(); ImGui::Text("Size (pixels)"); ImGui::NextColumn(); ImGui::Text("Format"); ImGui::NextColumn(); - ImGui::Text("Source"); ImGui::NextColumn(); ImGui::Text("Samples"); ImGui::NextColumn(); ImGui::Separator(); int idx = 0; @@ -214,35 +213,27 @@ void Q3DSProfileView::frame() ImGui::Text("%s", info.constData()); ImGui::NextColumn(); if (auto t = qobject_cast<Qt3DRender::QAbstractTexture *>(objd.obj)) { + bool useTexture = true; const QVector<Qt3DRender::QAbstractTextureImage *> textureImages = t->textureImages(); - if (textureImages.isEmpty()) { + if (!textureImages.isEmpty()) { + // handle Text textures specially since the data may be dummy on the texture itself + if (auto ti = qobject_cast<Qt3DRender::QPaintedTextureImage *>(textureImages[0])) { + ImGui::Text("%dx%d", ti->width(), ti->height()); + ImGui::NextColumn(); + ImGui::Text("0x8058"); + ImGui::NextColumn(); + ImGui::Text("1"); + ImGui::NextColumn(); + useTexture = false; + } + } + if (useTexture) { ImGui::Text("%dx%d", t->width(), t->height()); ImGui::NextColumn(); ImGui::Text("0x%x", t->format()); ImGui::NextColumn(); - ImGui::NextColumn(); ImGui::Text("%d", t->samples()); ImGui::NextColumn(); - } else { - if (auto ti = qobject_cast<Qt3DRender::QTextureImage *>(textureImages[0])) { - ImGui::NextColumn(); - ImGui::NextColumn(); - const QByteArray src = ti->source().toLocalFile().toUtf8(); - ImGui::TextWrapped("%s", src.constData()); - ImGui::NextColumn(); - ImGui::NextColumn(); - } else if (auto ti = qobject_cast<Qt3DRender::QPaintedTextureImage *>(textureImages[0])) { - ImGui::Text("%dx%d", ti->width(), ti->height()); - ImGui::NextColumn(); - ImGui::NextColumn(); - ImGui::NextColumn(); - ImGui::NextColumn(); - } else { - ImGui::NextColumn(); - ImGui::NextColumn(); - ImGui::NextColumn(); - ImGui::NextColumn(); - } } } else { ImGui::NextColumn(); diff --git a/src/runtime/q3dsprofiler_p.h b/src/runtime/q3dsprofiler_p.h index 3a14b6c..718f972 100644 --- a/src/runtime/q3dsprofiler_p.h +++ b/src/runtime/q3dsprofiler_p.h @@ -69,6 +69,7 @@ public: UnknownObject, RenderTargetObject, Texture2DObject, + TextureLoaderObject = Texture2DObject, // no difference in practice, will only cast to QAbstractTexture anyways TextureCubeObject }; void trackNewObject(QObject *obj, ObjectType type, const char *info, ...); diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp index 96c1141..15b08df 100644 --- a/src/runtime/q3dsscenemanager.cpp +++ b/src/runtime/q3dsscenemanager.cpp @@ -3863,11 +3863,11 @@ void Q3DSSceneManager::prepareTextureParameters(Q3DSTextureParameters &texturePa textureParameters.rotations = new Qt3DRender::QParameter; textureParameters.rotations->setName(name + QLatin1String("_rotations")); - textureParameters.texture = new Qt3DRender::QTexture2D(m_rootEntity); - m_profiler->trackNewObject(textureParameters.texture, Q3DSProfiler::Texture2DObject, + // Prefer QTextureLoader since this is simpler and leads to updated width, + // height, etc. values on the texture. + textureParameters.texture = new Qt3DRender::QTextureLoader(m_rootEntity); + m_profiler->trackNewObject(textureParameters.texture, Q3DSProfiler::TextureLoaderObject, "Texture for image %s", image3DS->id().constData()); - textureParameters.textureImage = new Qt3DRender::QTextureImage; - textureParameters.texture->addTextureImage(textureParameters.textureImage); } void Q3DSSceneManager::updateTextureParameters(Q3DSTextureParameters &textureParameters, Q3DSImage *image) @@ -3884,7 +3884,7 @@ void Q3DSSceneManager::updateTextureParameters(Q3DSTextureParameters &texturePar } } } else if (!image->sourcePath().isEmpty()) { - textureParameters.textureImage->setSource(QUrl::fromLocalFile(image->sourcePath())); + textureParameters.texture->setSource(QUrl::fromLocalFile(image->sourcePath())); textureParameters.sampler->setValue(QVariant::fromValue(textureParameters.texture)); } else { textureParameters.sampler->setValue(QVariant::fromValue(dummyTexture())); @@ -4191,14 +4191,15 @@ static inline void forAllCustomProperties(Q3DSEffectInstance *eff3DS, CustomProp Qt3DRender::QAbstractTexture *Q3DSSceneManager::createCustomPropertyTexture(const Q3DSCustomPropertyParameter &p) { const QString source = p.inputValue.toString(); - Qt3DRender::QTexture2D *texture = new Qt3DRender::QTexture2D(m_rootEntity); - m_profiler->trackNewObject(texture, Q3DSProfiler::Texture2DObject, + // Using QTextureLoader has the benefit of getting updated width and height + // values from the texture later on which is pretty important for some + // effect uniforms for instance. + Qt3DRender::QTextureLoader *texture = new Qt3DRender::QTextureLoader(m_rootEntity); + m_profiler->trackNewObject(texture, Q3DSProfiler::TextureLoaderObject, "Custom property texture %s", qPrintable(source)); if (!source.isEmpty()) { qCDebug(lcScene, "Creating custom property texture %s", qPrintable(source)); - Qt3DRender::QTextureImage *textureImage = new Qt3DRender::QTextureImage; - textureImage->setSource(QUrl::fromLocalFile(source)); - texture->addTextureImage(textureImage); + texture->setSource(QUrl::fromLocalFile(source)); } switch (p.meta.magFilterType) { @@ -4535,6 +4536,8 @@ void Q3DSSceneManager::setupEffectTextureBuffer(Q3DSEffectAttached::TextureBuffe Q3DSLayerNode *layer3DS) { Qt3DRender::QAbstractTexture *texture = new Qt3DRender::QTexture2D(m_rootEntity); + m_profiler->trackNewObject(texture, Q3DSProfiler::Texture2DObject, + "Effect buffer %s", qPrintable(bufDesc.name())); tb->texture = texture; switch (bufDesc.filter()) { diff --git a/src/runtime/q3dsscenemanager.h b/src/runtime/q3dsscenemanager.h index 30f37dd..a52786f 100644 --- a/src/runtime/q3dsscenemanager.h +++ b/src/runtime/q3dsscenemanager.h @@ -71,7 +71,7 @@ class QRenderPass; class QShaderProgram; class QBuffer; class QTexture2D; -class QTextureImage; +class QTextureLoader; class QPaintedTextureImage; class QLayerFilter; class QRenderTargetSelector; @@ -343,8 +343,7 @@ struct Q3DSTextureParameters QVector<Qt3DRender::QParameter *> parameters() const { return { sampler, offsets, rotations }; } - Qt3DRender::QTexture2D *texture = nullptr; - Qt3DRender::QTextureImage *textureImage = nullptr; + Qt3DRender::QTextureLoader *texture = nullptr; QString subPresId; }; |