diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2018-09-18 09:52:05 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-09-18 08:58:51 +0000 |
commit | efb662522ab15b09f1d85f58c1077f4fdfc6d50d (patch) | |
tree | dff2a9e6d06fac52ab8ef5e2dec4fad61365e2db | |
parent | 54b95edfc69d3f336dcd9f61fb47a00f79f2929b (diff) |
Fix environment map finding for custom materials
Task-number: QT3DS-2349
Change-Id: I607aafe086fb0349d3a44326594b5bbf68055645
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/Runtime/Source/Qt3DSRuntimeRender/ResourceManager/Qt3DSRenderBufferManager.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/ResourceManager/Qt3DSRenderBufferManager.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/ResourceManager/Qt3DSRenderBufferManager.cpp index 2e25ff0d..fe49a91f 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/ResourceManager/Qt3DSRenderBufferManager.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/ResourceManager/Qt3DSRenderBufferManager.cpp @@ -49,6 +49,7 @@ #include "foundation/Qt3DSPerfTimer.h" #include "foundation/Qt3DSMutex.h" #include "Qt3DSRenderPrefilterTexture.h" +#include <QtCore/qdir.h> using namespace qt3ds::render; @@ -344,14 +345,36 @@ struct SBufferManager : public IBufferManager // in sub-presentations. Note: Runtime 1 is going to be removed in Qt 3D Studio 2.x, // so this should be ok. if (!theLoadedImage) { - QString searchPath = QStringLiteral("."); - searchPath.append(inImagePath.c_str()); - int loops = 0; - while (!theLoadedImage && ++loops <= 3) { - theLoadedImage = SLoadedTexture::Load( - searchPath.toUtf8(), m_Context->GetFoundation(), - *m_InputStreamFactory, true, m_Context->GetRenderContextType()); - searchPath.prepend(QStringLiteral("../")); + if (QDir(inImagePath.c_str()).isRelative()) { + QString searchPath = QLatin1String("."); + searchPath.append(inImagePath.c_str()); + int loops = 0; + while (!theLoadedImage && ++loops <= 3) { + theLoadedImage = SLoadedTexture::Load( + searchPath.toUtf8(), m_Context->GetFoundation(), + *m_InputStreamFactory, true, + m_Context->GetRenderContextType()); + searchPath.prepend(QLatin1String("../")); + } + } else { + // Some textures, for example environment maps for custom materials, + // have absolute path at this point. It point to the wrong place with + // the new project structure, so we need to split it up and construct + // the new absolute path here. + QString wholePath = inImagePath.c_str(); + QStringList splitPath = wholePath.split(QLatin1String("../")); + QString searchPath = splitPath.at(0) + splitPath.at(1); + int loops = 0; + while (!theLoadedImage && ++loops <= 3) { + theLoadedImage = SLoadedTexture::Load( + searchPath.toUtf8(), m_Context->GetFoundation(), + *m_InputStreamFactory, true, + m_Context->GetRenderContextType()); + searchPath = splitPath.at(0); + for (int i = 0; i < loops; i++) + searchPath.append(QLatin1String("../")); + searchPath.append(splitPath.at(1)); + } } } } |