1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5#ifndef QSSG_RENDER_LOADED_TEXTURE_H
6#define QSSG_RENDER_LOADED_TEXTURE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
20#include <QtQuick3DRuntimeRender/private/qtquick3druntimerenderglobal_p.h>
21
22#include <QtGui/QImage>
23
24#include <private/qtexturefiledata_p.h>
25
26QT_BEGIN_NAMESPACE
27class QSSGRenderTextureData;
28
29struct QSSGTextureData
30{
31 void *data = nullptr;
32 quint32 dataSizeInBytes = 0;
33 QSSGRenderTextureFormat format = QSSGRenderTextureFormat::Unknown;
34};
35
36struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGInputUtil
37{
38public:
39 enum FileType { UnknownFile, ImageFile, TextureFile, HdrFile };
40 static QSharedPointer<QIODevice> getStreamForFile(const QString &inPath,
41 bool inQuiet = false,
42 QString *outPath = nullptr);
43 static QSharedPointer<QIODevice> getStreamForTextureFile(const QString &inPath,
44 bool inQuiet = false,
45 QString *outPath = nullptr,
46 FileType *outFileType = nullptr);
47};
48
49
50// Utility class used for loading image data from disk.
51struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGLoadedTexture
52{
53public:
54 qint32 width = 0;
55 qint32 height = 0;
56 qint32 depth = 0;
57 qint32 components = 0;
58 void *data = nullptr;
59 bool ownsData = true;
60 QTextureFileData textureFileData;
61 QImage image;
62 quint32 dataSizeInBytes = 0;
63 QSSGRenderTextureFormat format = QSSGRenderTextureFormat::RGBA8;
64 // #TODO: There should be more ways to influence this (hints on the texture)
65 bool isSRGB = false;
66
67 ~QSSGLoadedTexture();
68 void setFormatFromComponents()
69 {
70 switch (components) {
71 case 1: // undefined, but in this context probably luminance
72 format = QSSGRenderTextureFormat::R8;
73 break;
74 case 2:
75 format = QSSGRenderTextureFormat::RG8;
76 break;
77 case 3:
78 format = QSSGRenderTextureFormat::RGB8;
79 break;
80
81 default:
82 // fallthrough intentional
83 case 4:
84 format = QSSGRenderTextureFormat::RGBA8;
85 break;
86 }
87 }
88
89 // Returns true if this image has a pixel less than 255.
90 bool scanForTransparency() const;
91
92 static QSSGLoadedTexture *load(const QString &inPath,
93 const QSSGRenderTextureFormat &inFormat,
94 bool inFlipY = true);
95 static QSSGLoadedTexture *loadQImage(const QString &inPath, qint32 flipVertical);
96 static QSSGLoadedTexture *loadCompressedImage(const QString &inPath);
97 static QSSGLoadedTexture *loadHdrImage(const QSharedPointer<QIODevice> &source, const QSSGRenderTextureFormat &inFormat);
98 static QSSGLoadedTexture *loadTextureData(QSSGRenderTextureData *textureData);
99};
100QT_END_NAMESPACE
101
102#endif
103

source code of qtquick3d/src/runtimerender/resourcemanager/qssgrenderloadedtexture_p.h