1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2019 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QSGTEXTURE_H |
41 | #define QSGTEXTURE_H |
42 | |
43 | #include <QtQuick/qtquickglobal.h> |
44 | #include <QtCore/QObject> |
45 | #include <QtGui/QImage> |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | class QSGTexturePrivate; |
50 | class QRhi; |
51 | class QRhiTexture; |
52 | class QRhiResourceUpdateBatch; |
53 | |
54 | class Q_QUICK_EXPORT QSGTexture : public QObject |
55 | { |
56 | Q_OBJECT |
57 | Q_DECLARE_PRIVATE(QSGTexture) |
58 | |
59 | public: |
60 | QSGTexture(); |
61 | ~QSGTexture() override; |
62 | |
63 | enum WrapMode { |
64 | Repeat, |
65 | ClampToEdge, |
66 | MirroredRepeat |
67 | }; |
68 | |
69 | enum Filtering { |
70 | None, |
71 | Nearest, |
72 | Linear |
73 | }; |
74 | |
75 | enum AnisotropyLevel { |
76 | AnisotropyNone, |
77 | Anisotropy2x, |
78 | Anisotropy4x, |
79 | Anisotropy8x, |
80 | Anisotropy16x |
81 | }; |
82 | |
83 | struct NativeTexture { |
84 | const void *object; |
85 | int layout; |
86 | }; |
87 | |
88 | virtual int textureId() const = 0; // ### Qt 6: remove |
89 | NativeTexture nativeTexture() const; |
90 | virtual QSize textureSize() const = 0; |
91 | virtual bool hasAlphaChannel() const = 0; |
92 | virtual bool hasMipmaps() const = 0; |
93 | |
94 | virtual QRectF normalizedTextureSubRect() const; |
95 | |
96 | virtual bool isAtlasTexture() const; |
97 | |
98 | virtual QSGTexture *removedFromAtlas() const; |
99 | |
100 | virtual void bind() = 0; |
101 | void updateBindOptions(bool force = false); |
102 | |
103 | void setMipmapFiltering(Filtering filter); |
104 | QSGTexture::Filtering mipmapFiltering() const; |
105 | |
106 | void setFiltering(Filtering filter); |
107 | QSGTexture::Filtering filtering() const; |
108 | |
109 | void setAnisotropyLevel(AnisotropyLevel level); |
110 | QSGTexture::AnisotropyLevel anisotropyLevel() const; |
111 | |
112 | void setHorizontalWrapMode(WrapMode hwrap); |
113 | QSGTexture::WrapMode horizontalWrapMode() const; |
114 | |
115 | void setVerticalWrapMode(WrapMode vwrap); |
116 | QSGTexture::WrapMode verticalWrapMode() const; |
117 | |
118 | inline QRectF convertToNormalizedSourceRect(const QRectF &rect) const; |
119 | |
120 | // ### Qt 6: make these virtual |
121 | int comparisonKey() const; |
122 | void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates); |
123 | |
124 | // ### Qt 6: make this an argument for removedFromAtlas() |
125 | void setWorkResourceUpdateBatch(QRhiResourceUpdateBatch *resourceUpdates); |
126 | |
127 | protected: |
128 | QSGTexture(QSGTexturePrivate &dd); |
129 | }; |
130 | |
131 | QRectF QSGTexture::convertToNormalizedSourceRect(const QRectF &rect) const |
132 | { |
133 | QSize s = textureSize(); |
134 | QRectF r = normalizedTextureSubRect(); |
135 | |
136 | qreal sx = r.width() / s.width(); |
137 | qreal sy = r.height() / s.height(); |
138 | |
139 | return QRectF(r.x() + rect.x() * sx, |
140 | r.y() + rect.y() * sy, |
141 | rect.width() * sx, |
142 | rect.height() * sy); |
143 | } |
144 | |
145 | class Q_QUICK_EXPORT QSGDynamicTexture : public QSGTexture |
146 | { |
147 | Q_OBJECT |
148 | |
149 | public: |
150 | QSGDynamicTexture() = default; |
151 | virtual bool updateTexture() = 0; |
152 | |
153 | protected: |
154 | QSGDynamicTexture(QSGTexturePrivate &dd); |
155 | }; |
156 | |
157 | QT_END_NAMESPACE |
158 | |
159 | #endif |
160 | |