1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSGTEXTURE_H
5#define QSGTEXTURE_H
6
7#include <QtQuick/qtquickglobal.h>
8#include <QtCore/qobject.h>
9#include <QtGui/qimage.h>
10#include <QtQuick/qsgtexture_platform.h>
11
12QT_BEGIN_NAMESPACE
13
14class QSGTexturePrivate;
15class QRhi;
16class QRhiTexture;
17class QRhiResourceUpdateBatch;
18
19class Q_QUICK_EXPORT QSGTexture : public QObject
20{
21 Q_OBJECT
22 Q_DECLARE_PRIVATE(QSGTexture)
23
24public:
25 QSGTexture();
26 ~QSGTexture() override;
27
28 enum WrapMode {
29 Repeat,
30 ClampToEdge,
31 MirroredRepeat
32 };
33
34 enum Filtering {
35 None,
36 Nearest,
37 Linear
38 };
39
40 enum AnisotropyLevel {
41 AnisotropyNone,
42 Anisotropy2x,
43 Anisotropy4x,
44 Anisotropy8x,
45 Anisotropy16x
46 };
47
48 virtual qint64 comparisonKey() const = 0;
49 virtual QRhiTexture *rhiTexture() const;
50 virtual QSize textureSize() const = 0;
51 virtual bool hasAlphaChannel() const = 0;
52 virtual bool hasMipmaps() const = 0;
53
54 virtual QRectF normalizedTextureSubRect() const;
55
56 virtual bool isAtlasTexture() const;
57
58 virtual QSGTexture *removedFromAtlas(QRhiResourceUpdateBatch *resourceUpdates = nullptr) const;
59
60 virtual void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
61
62 void setMipmapFiltering(Filtering filter);
63 QSGTexture::Filtering mipmapFiltering() const;
64
65 void setFiltering(Filtering filter);
66 QSGTexture::Filtering filtering() const;
67
68 void setAnisotropyLevel(AnisotropyLevel level);
69 QSGTexture::AnisotropyLevel anisotropyLevel() const;
70
71 void setHorizontalWrapMode(WrapMode hwrap);
72 QSGTexture::WrapMode horizontalWrapMode() const;
73
74 void setVerticalWrapMode(WrapMode vwrap);
75 QSGTexture::WrapMode verticalWrapMode() const;
76
77 inline QRectF convertToNormalizedSourceRect(const QRectF &rect) const;
78
79 QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QSGTexture)
80
81protected:
82 QSGTexture(QSGTexturePrivate &dd);
83};
84
85QRectF QSGTexture::convertToNormalizedSourceRect(const QRectF &rect) const
86{
87 QSize s = textureSize();
88 QRectF r = normalizedTextureSubRect();
89
90 qreal sx = r.width() / s.width();
91 qreal sy = r.height() / s.height();
92
93 return QRectF(r.x() + rect.x() * sx,
94 r.y() + rect.y() * sy,
95 rect.width() * sx,
96 rect.height() * sy);
97}
98
99class Q_QUICK_EXPORT QSGDynamicTexture : public QSGTexture
100{
101 Q_OBJECT
102
103public:
104 QSGDynamicTexture() = default;
105 ~QSGDynamicTexture() override;
106
107 virtual bool updateTexture() = 0;
108
109protected:
110 QSGDynamicTexture(QSGTexturePrivate &dd);
111};
112
113QT_END_NAMESPACE
114
115#endif
116

source code of qtdeclarative/src/quick/scenegraph/coreapi/qsgtexture.h