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
47QT_BEGIN_NAMESPACE
48
49class QSGTexturePrivate;
50class QRhi;
51class QRhiTexture;
52class QRhiResourceUpdateBatch;
53
54class Q_QUICK_EXPORT QSGTexture : public QObject
55{
56 Q_OBJECT
57 Q_DECLARE_PRIVATE(QSGTexture)
58
59public:
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 virtual int textureId() const = 0; // ### Qt 6: remove
84 virtual QSize textureSize() const = 0;
85 virtual bool hasAlphaChannel() const = 0;
86 virtual bool hasMipmaps() const = 0;
87
88 virtual QRectF normalizedTextureSubRect() const;
89
90 virtual bool isAtlasTexture() const;
91
92 virtual QSGTexture *removedFromAtlas() const;
93
94 virtual void bind() = 0;
95 void updateBindOptions(bool force = false);
96
97 void setMipmapFiltering(Filtering filter);
98 QSGTexture::Filtering mipmapFiltering() const;
99
100 void setFiltering(Filtering filter);
101 QSGTexture::Filtering filtering() const;
102
103 void setAnisotropyLevel(AnisotropyLevel level);
104 QSGTexture::AnisotropyLevel anisotropyLevel() const;
105
106 void setHorizontalWrapMode(WrapMode hwrap);
107 QSGTexture::WrapMode horizontalWrapMode() const;
108
109 void setVerticalWrapMode(WrapMode vwrap);
110 QSGTexture::WrapMode verticalWrapMode() const;
111
112 inline QRectF convertToNormalizedSourceRect(const QRectF &rect) const;
113
114 // ### Qt 6: make these virtual
115 int comparisonKey() const;
116 QRhiTexture *rhiTexture() const;
117 void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates);
118
119 // ### Qt 6: make this an argument for removedFromAtlas()
120 void setWorkResourceUpdateBatch(QRhiResourceUpdateBatch *resourceUpdates);
121
122protected:
123 QSGTexture(QSGTexturePrivate &dd);
124};
125
126QRectF QSGTexture::convertToNormalizedSourceRect(const QRectF &rect) const
127{
128 QSize s = textureSize();
129 QRectF r = normalizedTextureSubRect();
130
131 qreal sx = r.width() / s.width();
132 qreal sy = r.height() / s.height();
133
134 return QRectF(r.x() + rect.x() * sx,
135 r.y() + rect.y() * sy,
136 rect.width() * sx,
137 rect.height() * sy);
138}
139
140class Q_QUICK_EXPORT QSGDynamicTexture : public QSGTexture
141{
142 Q_OBJECT
143
144public:
145 virtual bool updateTexture() = 0;
146
147protected:
148 QSGDynamicTexture(QSGTexturePrivate &dd);
149};
150
151QT_END_NAMESPACE
152
153#endif
154