summaryrefslogtreecommitdiffstats
path: root/src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp')
-rw-r--r--src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp74
1 files changed, 11 insertions, 63 deletions
diff --git a/src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp b/src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp
index 8046a10..634e3c0 100644
--- a/src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp
+++ b/src/runtimerender/resourcemanager/Qt3DSRenderLoadedTexture.cpp
@@ -908,78 +908,26 @@ void SLoadedTexture::ReleaseDecompressedTexture(STextureData inImage)
m_Allocator.deallocate(inImage.data);
}
-// Locate existing file by adding a supported suffix to localFile.
-// If localFile already contains suffix or exiting file isn't found
-// returns localFile unchanged.
-static QString existingImageFileForPath(const QString &localFile, bool preferKTX)
-{
- // Do nothing if given filepath exists or already has a suffix
- QFileInfo fi(localFile);
- if (!fi.suffix().isEmpty() || fi.exists())
- return localFile;
-
- // Lists of supported image formats in preferred-first order.
- const QStringList compressedFormats {"ktx", "astc", "dds"};
- const QStringList nonCompressedFormats {"hdr", "png", "jpg", "jpeg", "gif"};
-
- // Depending on preferKTX, check compressed formats before or after non-compressed ones.
- QStringList supportedFormats = preferKTX ? compressedFormats + nonCompressedFormats
- : nonCompressedFormats + compressedFormats;
-
- // Check first if file exists from resources as that
- // is common and optimal for integrity case.
- for (const QString &suffix : supportedFormats) {
- QString tryFile = ":/" + localFile + "." + suffix;
- if (QFileInfo::exists(tryFile))
- return tryFile;
- }
- // If not found, check still file path as-is
- for (const QString &suffix : supportedFormats) {
- QString tryFile = localFile + "." + suffix;
- if (QFileInfo::exists(tryFile))
- return tryFile;
- }
-
- return localFile;
-}
-
-SLoadedTexture *SLoadedTexture::Load(const QString &inPath, NVFoundationBase &inFoundation,
+SLoadedTexture *SLoadedTexture::Load(const QString &path, NVFoundationBase &inFoundation,
IInputStreamFactory &inFactory, bool inFlipY,
bool inFlipCompressed,
- NVRenderContextType renderContextType, bool preferKTX,
+ NVRenderContextType renderContextType,
IBufferManager *bufferManager)
{
- if (inPath.isEmpty())
+ if (path.isEmpty())
return nullptr;
- if (QUrl(inPath).scheme() == QLatin1String("image"))
- return LoadQImage(inPath, inFlipY, inFoundation, renderContextType, bufferManager);
+ if (QUrl(path).scheme() == QLatin1String("image"))
+ return LoadQImage(path, inFlipY, inFoundation, renderContextType, bufferManager);
- // If inPath doesn't have suffix, try to find most optimal existing one
- QString path = existingImageFileForPath(inPath, preferKTX);
+ SLoadedTexture *theLoadedImage = nullptr;
+ NVScopedRefCounted<IRefCountedInputStream> theStream(inFactory.GetStreamForFile(path, true));
- // If preferKTX is true, always check KTX path first
- QString ktxSource = path;
- if (preferKTX) {
- ktxSource = ktxSource.left(ktxSource.lastIndexOf(QLatin1Char('.')));
- ktxSource.append(QLatin1String(".ktx"));
- }
+ if (!theStream.mPtr)
+ return nullptr;
- SLoadedTexture *theLoadedImage = nullptr;
- // We will get invalid error logs of files not found if we don't force quiet mode
- // If the file is actually missing, it will be logged later (loaded image is null)
- NVScopedRefCounted<IRefCountedInputStream> theStream(
- inFactory.GetStreamForFile(preferKTX ? ktxSource : path, true));
- if (!theStream.mPtr) {
- if (preferKTX)
- theStream = inFactory.GetStreamForFile(path, true);
- else
- return nullptr;
- } else {
- path = ktxSource;
- }
QString fileName;
- inFactory.GetPathForFile(path, fileName, true);
+ inFactory.GetPathForStream(theStream.mPtr, fileName);
if (theStream.mPtr && path.size() > 3) {
if (path.endsWith(QLatin1String("png"), Qt::CaseInsensitive)
|| path.endsWith(QLatin1String("jpg"), Qt::CaseInsensitive)
@@ -1006,7 +954,7 @@ SLoadedTexture *SLoadedTexture::Load(const QString &inPath, NVFoundationBase &in
inFlipCompressed);
theLoadedImage = LoadASTC(fileName, inFlipY, inFoundation, renderContextType);
} else {
- qCWarning(INTERNAL_ERROR, "Unrecognized image extension: %s", qPrintable(inPath));
+ qCWarning(INTERNAL_ERROR, "Unrecognized image extension: %s", qPrintable(path));
}
}