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
73
74 QSGTextureProvider *fillTextureProvider() const
75 {
76 return m_textureProvider;
77 }
78
79 void setFillGradient(const QSGGradientCache::GradientDesc &fillGradient)
80 {
81 m_fillGradient = fillGradient;
82 markDirty(DirtyMaterial);
83 }
84
85 const QSGGradientCache::GradientDesc *fillGradient() const
86 {
87 return &m_fillGradient;
88 }
89
90 void setGradientType(QGradient::Type type)
91 {
92 m_gradientType = type;
93 markDirty(DirtyMaterial);
94 }
95
96 QGradient::Type gradientType() const
97 {
98 return m_gradientType;
99 }
100
101 void setFillTransform(const QSGTransform &transform)
102 {
103 m_fillTransform = transform;
104 markDirty(DirtyMaterial);
105 }
106
107 const QSGTransform *fillTransform() const
108 {
109 return &m_fillTransform;
110 }
111
112 float debug() const
113 {
114 return m_debug;
115 }
116
117 void setDebug(float newDebug)
118 {
119 m_debug = newDebug;
120 }
121
122 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
123 const std::array<QVector2D, 3> &n, // vertex normals
124 std::function<QVector3D(QVector2D)> uvForPoint
125 )
126 {
127 QVector3D uv1 = uvForPoint(v[0]);
128 QVector3D uv2 = uvForPoint(v[1]);
129 QVector3D uv3 = uvForPoint(v[2]);
130
131 QVector2D duvdx = QVector2D(uvForPoint(v[0] + QVector2D(1, 0))) - QVector2D(uv1);
132 QVector2D duvdy = QVector2D(uvForPoint(v[0] + QVector2D(0, 1))) - QVector2D(uv1);
133
134 m_uncookedIndexes.append(m_uncookedVertexes.size());
135 m_uncookedVertexes.append( { v[0].x(), v[0].y(),
136 uv1.x(), uv1.y(), uv1.z(),
137 duvdx.x(), duvdx.y(),
138 duvdy.x(), duvdy.y(),
139 n[0].x(), n[0].y()
140 });
141
142 m_uncookedIndexes.append(m_uncookedVertexes.size());
143 m_uncookedVertexes.append( { v[1].x(), v[1].y(),
144 uv2.x(), uv2.y(), uv2.z(),
145 duvdx.x(), duvdx.y(),
146 duvdy.x(), duvdy.y(),
147 n[1].x(), n[1].y()
148 });
149
150 m_uncookedIndexes.append(m_uncookedVertexes.size());
151 m_uncookedVertexes.append( { v[2].x(), v[2].y(),
152 uv3.x(), uv3.y(), uv3.z(),
153 duvdx.x(), duvdx.y(),
154 duvdy.x(), duvdy.y(),
155 n[2].x(), n[2].y()
156 });
157 }
158
159 void appendTriangle(const QVector2D &v1,
160 const QVector2D &v2,
161 const QVector2D &v3,
162 const QVector3D &uv1,
163 const QVector3D &uv2,
164 const QVector3D &uv3,
165 const QVector2D &n1,
166 const QVector2D &n2,
167 const QVector2D &n3,
168 const QVector2D &duvdx,
169 const QVector2D &duvdy)
170 {
171 m_uncookedIndexes.append(m_uncookedVertexes.size());
172 m_uncookedVertexes.append( { v1.x(), v1.y(),
173 uv1.x(), uv1.y(), uv1.z(),
174 duvdx.x(), duvdx.y(),
175 duvdy.x(), duvdy.y(),
176 n1.x(), n1.y()
177 });
178
179 m_uncookedIndexes.append(m_uncookedVertexes.size());
180 m_uncookedVertexes.append( { v2.x(), v2.y(),
181 uv2.x(), uv2.y(), uv2.z(),
182 duvdx.x(), duvdx.y(),
183 duvdy.x(), duvdy.y(),
184 n2.x(), n2.y()
185 });
186
187 m_uncookedIndexes.append(m_uncookedVertexes.size());
188 m_uncookedVertexes.append( { v3.x(), v3.y(),
189 uv3.x(), uv3.y(), uv3.z(),
190 duvdx.x(), duvdx.y(),
191 duvdy.x(), duvdy.y(),
192 n3.x(), n3.y()
193 });
194 }
195
196 void appendTriangle(const QVector2D &v1,
197 const QVector2D &v2,
198 const QVector2D &v3,
199 std::function<QVector3D(QVector2D)> uvForPoint)
200 {
201 appendTriangle({v1, v2, v3}, {}, uvForPoint);
202 }
203
204 QList<quint32> uncookedIndexes() const
205 {
206 return m_uncookedIndexes;
207 }
208
209 void cookGeometry() override;
210
211 void reserve(qsizetype size)
212 {
213 m_uncookedIndexes.reserve(size);
214 m_uncookedVertexes.reserve(size);
215 }
216
217 void preprocess() override
218 {
219 if (m_textureProvider != nullptr) {
220 if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(m_textureProvider->texture()))
221 texture->updateTexture();
222 }
223 }
224
225 QVector2D boundsSize() const
226 {
227 return m_boundsSize;
228 }
229
230 void setBoundsSize(const QVector2D &boundsSize)
231 {
232 m_boundsSize = boundsSize;
233 }
234
235 bool useStandardDerivatives() const
236 {
237 return m_useStandardDerivatives;
238 }
239
240 void setUseStandardDerivatives(bool useStandardDerivatives) override
241 {
242 m_useStandardDerivatives = useStandardDerivatives;
243 }
244
245private Q_SLOTS:
246 void handleTextureChanged()
247 {
248 markDirty(DirtyMaterial);
249 }
250
251 void handleTextureProviderDestroyed()
252 {
253 m_textureProvider = nullptr;
254 markDirty(DirtyMaterial);
255 }
256
257private:
258 struct CurveNodeVertex
259 {
260 float x, y, u, v, w;
261 float dudx, dvdx, dudy, dvdy; // Size of pixel in curve space (must be same for all vertices in triangle)
262 float nx, ny; // normal vector describing the direction to shift the vertex for AA
263 };
264
265 void updateMaterial();
266 static const QSGGeometry::AttributeSet &attributes();
267
268 QScopedPointer<QSGMaterial> m_material;
269
270 QList<CurveNodeVertex> m_uncookedVertexes;
271 QList<quint32> m_uncookedIndexes;
272
273 QSGGradientCache::GradientDesc m_fillGradient;
274 QSGTextureProvider *m_textureProvider = nullptr;
275 QVector2D m_boundsSize;
276 QSGTransform m_fillTransform;
277 QColor m_color = Qt::white;
278 QGradient::Type m_gradientType = QGradient::NoGradient;
279 float m_debug = 0.0f;
280 bool m_useStandardDerivatives = false;
281};
282
283QT_END_NAMESPACE
284
285#endif // QSGCURVEFILLNODE_P_H
Combined button and popup list for selecting options.