Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgcurvefillnode_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 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// Qt-Security score:significant reason:default
4
5#ifndef QSGCURVEFILLNODE_P_H
6#define QSGCURVEFILLNODE_P_H
7
8#include <QtGui/qbrush.h>
9
10#include <QtQuick/qtquickexports.h>
11#include <QtQuick/private/qsggradientcache_p.h>
12#include <QtQuick/private/qsgtransform_p.h>
13#include <QtQuick/qsgnode.h>
14#include <QtQuick/qsgtextureprovider.h>
15
17
18//
19// W A R N I N G
20// -------------
21//
22// This file is not part of the Qt API. It exists for the convenience
23// of a number of Qt sources files. This header file may change from
24// version to version without notice, or even be removed.
25//
26// We mean it.
27//
28
30
31class QSGTextureProvider;
32
33class Q_QUICK_EXPORT QSGCurveFillNode : public QObject, public QSGCurveAbstractNode
34{
35 Q_OBJECT
36public:
37 QSGCurveFillNode();
38
39 void setColor(QColor col) override
40 {
41 m_color = col;
42 markDirty(DirtyMaterial);
43 }
44
45 QColor color() const
46 {
47 return m_color;
48 }
49
50 void setFillTextureProvider(QSGTextureProvider *provider)
51 {
52 if (provider == m_textureProvider)
53 return;
54
55 if (m_textureProvider != nullptr) {
56 disconnect(m_textureProvider, &QSGTextureProvider::textureChanged,
57 this, &QSGCurveFillNode::handleTextureChanged);
58 disconnect(m_textureProvider, &QSGTextureProvider::destroyed,
59 this, &QSGCurveFillNode::handleTextureProviderDestroyed);
60 }
61
62 m_textureProvider = provider;
63 markDirty(DirtyMaterial);
64
65 if (m_textureProvider != nullptr) {
66 connect(m_textureProvider, &QSGTextureProvider::textureChanged,
67 this, &QSGCurveFillNode::handleTextureChanged);
68 connect(m_textureProvider, &QSGTextureProvider::destroyed,
69 this, &QSGCurveFillNode::handleTextureProviderDestroyed);
70 }
71
72 updateMaterialFlags();
73 }
74
75
76 QSGTextureProvider *fillTextureProvider() const
77 {
78 return m_textureProvider;
79 }
80
81 void setFillGradient(const QSGGradientCache::GradientDesc &fillGradient)
82 {
83 m_fillGradient = fillGradient;
84 markDirty(DirtyMaterial);
85 }
86
87 const QSGGradientCache::GradientDesc *fillGradient() const
88 {
89 return &m_fillGradient;
90 }
91
92 void setGradientType(QGradient::Type type)
93 {
94 m_gradientType = type;
95 markDirty(DirtyMaterial);
96
97 updateMaterialFlags();
98 }
99
100 QGradient::Type gradientType() const
101 {
102 return m_gradientType;
103 }
104
105 void setFillTransform(const QSGTransform &transform)
106 {
107 m_fillTransform = transform;
108 markDirty(DirtyMaterial);
109 }
110
111 const QSGTransform *fillTransform() const
112 {
113 return &m_fillTransform;
114 }
115
116 float debug() const
117 {
118 return m_debug;
119 }
120
121 void setDebug(float newDebug)
122 {
123 m_debug = newDebug;
124 }
125
126 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
127 const std::array<QVector2D, 3> &n, // vertex normals
128 std::function<QVector3D(QVector2D)> uvForPoint
129 )
130 {
131 QVector3D uv1 = uvForPoint(v[0]);
132 QVector3D uv2 = uvForPoint(v[1]);
133 QVector3D uv3 = uvForPoint(v[2]);
134
135 QVector2D duvdx = QVector2D(uvForPoint(v[0] + QVector2D(1, 0))) - QVector2D(uv1);
136 QVector2D duvdy = QVector2D(uvForPoint(v[0] + QVector2D(0, 1))) - QVector2D(uv1);
137
138 m_uncookedIndexes.append(m_uncookedVertexes.size());
139 m_uncookedVertexes.append( { v[0].x(), v[0].y(),
140 uv1.x(), uv1.y(), uv1.z(),
141 duvdx.x(), duvdx.y(),
142 duvdy.x(), duvdy.y(),
143 n[0].x(), n[0].y()
144 });
145
146 m_uncookedIndexes.append(m_uncookedVertexes.size());
147 m_uncookedVertexes.append( { v[1].x(), v[1].y(),
148 uv2.x(), uv2.y(), uv2.z(),
149 duvdx.x(), duvdx.y(),
150 duvdy.x(), duvdy.y(),
151 n[1].x(), n[1].y()
152 });
153
154 m_uncookedIndexes.append(m_uncookedVertexes.size());
155 m_uncookedVertexes.append( { v[2].x(), v[2].y(),
156 uv3.x(), uv3.y(), uv3.z(),
157 duvdx.x(), duvdx.y(),
158 duvdy.x(), duvdy.y(),
159 n[2].x(), n[2].y()
160 });
161 }
162
163 void appendTriangle(const QVector2D &v1,
164 const QVector2D &v2,
165 const QVector2D &v3,
166 const QVector3D &uv1,
167 const QVector3D &uv2,
168 const QVector3D &uv3,
169 const QVector2D &n1,
170 const QVector2D &n2,
171 const QVector2D &n3,
172 const QVector2D &duvdx,
173 const QVector2D &duvdy)
174 {
175 m_uncookedIndexes.append(m_uncookedVertexes.size());
176 m_uncookedVertexes.append( { v1.x(), v1.y(),
177 uv1.x(), uv1.y(), uv1.z(),
178 duvdx.x(), duvdx.y(),
179 duvdy.x(), duvdy.y(),
180 n1.x(), n1.y()
181 });
182
183 m_uncookedIndexes.append(m_uncookedVertexes.size());
184 m_uncookedVertexes.append( { v2.x(), v2.y(),
185 uv2.x(), uv2.y(), uv2.z(),
186 duvdx.x(), duvdx.y(),
187 duvdy.x(), duvdy.y(),
188 n2.x(), n2.y()
189 });
190
191 m_uncookedIndexes.append(m_uncookedVertexes.size());
192 m_uncookedVertexes.append( { v3.x(), v3.y(),
193 uv3.x(), uv3.y(), uv3.z(),
194 duvdx.x(), duvdx.y(),
195 duvdy.x(), duvdy.y(),
196 n3.x(), n3.y()
197 });
198 }
199
200 void appendTriangle(const QVector2D &v1,
201 const QVector2D &v2,
202 const QVector2D &v3,
203 std::function<QVector3D(QVector2D)> uvForPoint)
204 {
205 appendTriangle({v1, v2, v3}, {}, uvForPoint);
206 }
207
208 QList<quint32> uncookedIndexes() const
209 {
210 return m_uncookedIndexes;
211 }
212
213 void cookGeometry() override;
214
215 void reserve(qsizetype size)
216 {
217 m_uncookedIndexes.reserve(size);
218 m_uncookedVertexes.reserve(size);
219 }
220
221 void preprocess() override
222 {
223 if (m_textureProvider != nullptr) {
224 if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(m_textureProvider->texture()))
225 texture->updateTexture();
226 }
227 }
228
229 QVector2D boundsSize() const
230 {
231 return m_boundsSize;
232 }
233
234 void setBoundsSize(const QVector2D &boundsSize)
235 {
236 m_boundsSize = boundsSize;
237 }
238
239 bool useStandardDerivatives() const
240 {
241 return m_useStandardDerivatives;
242 }
243
244 void setUseStandardDerivatives(bool useStandardDerivatives) override
245 {
246 m_useStandardDerivatives = useStandardDerivatives;
247 }
248
249private Q_SLOTS:
250 void handleTextureChanged()
251 {
252 markDirty(DirtyMaterial);
253 }
254
255 void handleTextureProviderDestroyed()
256 {
257 m_textureProvider = nullptr;
258 markDirty(DirtyMaterial);
259 }
260
261private:
262 struct CurveNodeVertex
263 {
264 float x, y, u, v, w;
265 float dudx, dvdx, dudy, dvdy; // Size of pixel in curve space (must be same for all vertices in triangle)
266 float nx, ny; // normal vector describing the direction to shift the vertex for AA
267 };
268
269 void updateMaterialFlags();
270 void updateMaterial();
271 static const QSGGeometry::AttributeSet &attributes();
272
273 QScopedPointer<QSGMaterial> m_material;
274
275 QList<CurveNodeVertex> m_uncookedVertexes;
276 QList<quint32> m_uncookedIndexes;
277
278 QSGGradientCache::GradientDesc m_fillGradient;
279 QSGTextureProvider *m_textureProvider = nullptr;
280 QVector2D m_boundsSize;
281 QSGTransform m_fillTransform;
282 QColor m_color = Qt::white;
283 QGradient::Type m_gradientType = QGradient::NoGradient;
284 float m_debug = 0.0f;
285 bool m_useStandardDerivatives = false;
286};
287
288QT_END_NAMESPACE
289
290#endif // QSGCURVEFILLNODE_P_H
Combined button and popup list for selecting options.