1 | // Copyright (C) 2020 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QSSGRENDERTEXTUREDATA_H |
5 | #define QSSGRENDERTEXTUREDATA_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h> |
19 | #include <QtQuick3DRuntimeRender/private/qssgrenderimagetexture_p.h> |
20 | #include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h> |
21 | #include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h> |
22 | #include <QtCore/qsize.h> |
23 | #include <QtCore/qbytearray.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderTextureData : public QSSGRenderGraphObject |
28 | { |
29 | public: |
30 | explicit QSSGRenderTextureData(); |
31 | virtual ~QSSGRenderTextureData(); |
32 | |
33 | const QByteArray &textureData() const; |
34 | void setTextureData(const QByteArray &data); |
35 | |
36 | QSize size() const { return m_size; } |
37 | void setSize(const QSize &size); |
38 | |
39 | int depth() const { return m_depth; } |
40 | void setDepth(int depth); |
41 | |
42 | QSSGRenderTextureFormat format() const { return m_format; } |
43 | void setFormat(QSSGRenderTextureFormat format); |
44 | |
45 | bool hasTransparency() const { return m_hasTransparency; } |
46 | void setHasTransparency(bool hasTransparency); |
47 | |
48 | // We use a version number to track changes in the texture data. |
49 | [[nodiscard]] quint32 version() const { return m_textureDataVersion; } |
50 | |
51 | QString debugObjectName; |
52 | |
53 | protected: |
54 | Q_DISABLE_COPY(QSSGRenderTextureData) |
55 | |
56 | // it's specially used for Type::Skin |
57 | explicit QSSGRenderTextureData(QSSGRenderGraphObject::Type inType); |
58 | |
59 | QByteArray m_textureData; |
60 | QSize m_size; |
61 | int m_depth = 0; |
62 | quint32 m_textureDataVersion = 0; |
63 | QSSGRenderTextureFormat m_format = QSSGRenderTextureFormat::Unknown; |
64 | bool m_hasTransparency = false; |
65 | }; |
66 | |
67 | // NOTE: We only hash the size, depth, format and hasTransparency here, not the actual data. |
68 | // This is because we want to be able to quickly check if a texture has changed, without needing |
69 | // to inspect the data content. If only the version changes we'll try to recycle the existing |
70 | // texture resource, if the size, depth, format or hasTransparency changes we'll need to create a |
71 | // new texture resource (See: QSSGBufferManager::loadTextureData). |
72 | inline size_t qHash(const QSSGRenderTextureData &data, size_t seed) noexcept |
73 | { |
74 | const auto format = data.format(); |
75 | return qHashMulti(seed, args: data.size(), args: data.depth(), args: format.format, args: data.hasTransparency()); |
76 | } |
77 | |
78 | QT_END_NAMESPACE |
79 | |
80 | #endif // QSSGRENDERTEXTUREDATA_H |
81 | |