Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QSGCURVEFILLNODE_P_H
5#define QSGCURVEFILLNODE_P_H
6
7#include <QtGui/qbrush.h>
8
9#include <QtQuick/qtquickexports.h>
10#include <QtQuick/private/qsggradientcache_p.h>
11#include <QtQuick/private/qsgtransform_p.h>
12#include <QtQuick/qsgnode.h>
13
15
16//
17// W A R N I N G
18// -------------
19//
20// This file is not part of the Qt API. It exists for the convenience
21// of a number of Qt sources files. This header file may change from
22// version to version without notice, or even be removed.
23//
24// We mean it.
25//
26
28
29class Q_QUICK_EXPORT QSGCurveFillNode : public QSGCurveAbstractNode
30{
31public:
33
34 void setColor(QColor col) override
35 {
36 if (m_color == col)
37 return;
38 m_color = col;
39 updateMaterial();
40 }
41
42 QColor color() const
43 {
44 return m_color;
45 }
46
48 {
49 m_fillGradient = fillGradient;
50 }
51
53 {
54 return &m_fillGradient;
55 }
56
58 {
59 if (m_gradientType != type) {
60 m_gradientType = type;
61 updateMaterial();
62 }
63 }
64
66 {
67 return m_gradientType;
68 }
69
71 {
72 m_fillTransform = transform;
73 }
74
76 {
77 return &m_fillTransform;
78 }
79
80 float debug() const
81 {
82 return m_debug;
83 }
84
85 void setDebug(float newDebug)
86 {
87 m_debug = newDebug;
88 }
89
90 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
91 const std::array<QVector2D, 3> &n, // vertex normals
92 std::function<QVector3D(QVector2D)> uvForPoint
93 )
94 {
95 QVector3D uv1 = uvForPoint(v[0]);
96 QVector3D uv2 = uvForPoint(v[1]);
97 QVector3D uv3 = uvForPoint(v[2]);
98
99 QVector2D duvdx = QVector2D(uvForPoint(v[0] + QVector2D(1, 0))) - QVector2D(uv1);
100 QVector2D duvdy = QVector2D(uvForPoint(v[0] + QVector2D(0, 1))) - QVector2D(uv1);
101
102 m_uncookedIndexes.append(m_uncookedVertexes.size());
103 m_uncookedVertexes.append( { v[0].x(), v[0].y(),
104 uv1.x(), uv1.y(), uv1.z(),
105 duvdx.x(), duvdx.y(),
106 duvdy.x(), duvdy.y(),
107 n[0].x(), n[0].y()
108 });
109
110 m_uncookedIndexes.append(m_uncookedVertexes.size());
111 m_uncookedVertexes.append( { v[1].x(), v[1].y(),
112 uv2.x(), uv2.y(), uv2.z(),
113 duvdx.x(), duvdx.y(),
114 duvdy.x(), duvdy.y(),
115 n[1].x(), n[1].y()
116 });
117
118 m_uncookedIndexes.append(m_uncookedVertexes.size());
119 m_uncookedVertexes.append( { v[2].x(), v[2].y(),
120 uv3.x(), uv3.y(), uv3.z(),
121 duvdx.x(), duvdx.y(),
122 duvdy.x(), duvdy.y(),
123 n[2].x(), n[2].y()
124 });
125 }
126
128 const QVector2D &v2,
129 const QVector2D &v3,
130 const QVector3D &uv1,
131 const QVector3D &uv2,
132 const QVector3D &uv3,
133 const QVector2D &n1,
134 const QVector2D &n2,
135 const QVector2D &n3,
136 const QVector2D &duvdx,
137 const QVector2D &duvdy)
138 {
139 m_uncookedIndexes.append(m_uncookedVertexes.size());
140 m_uncookedVertexes.append( { v1.x(), v1.y(),
141 uv1.x(), uv1.y(), uv1.z(),
142 duvdx.x(), duvdx.y(),
143 duvdy.x(), duvdy.y(),
144 n1.x(), n1.y()
145 });
146
147 m_uncookedIndexes.append(m_uncookedVertexes.size());
148 m_uncookedVertexes.append( { v2.x(), v2.y(),
149 uv2.x(), uv2.y(), uv2.z(),
150 duvdx.x(), duvdx.y(),
151 duvdy.x(), duvdy.y(),
152 n2.x(), n2.y()
153 });
154
155 m_uncookedIndexes.append(m_uncookedVertexes.size());
156 m_uncookedVertexes.append( { v3.x(), v3.y(),
157 uv3.x(), uv3.y(), uv3.z(),
158 duvdx.x(), duvdx.y(),
159 duvdy.x(), duvdy.y(),
160 n3.x(), n3.y()
161 });
162 }
163
165 const QVector2D &v2,
166 const QVector2D &v3,
167 std::function<QVector3D(QVector2D)> uvForPoint)
168 {
169 appendTriangle({v1, v2, v3}, {}, uvForPoint);
170 }
171
172 QVector<quint32> uncookedIndexes() const
173 {
174 return m_uncookedIndexes;
175 }
176
177 void cookGeometry() override;
178
180 {
181 m_uncookedIndexes.reserve(size);
182 m_uncookedVertexes.reserve(size);
183 }
184
185private:
186 struct CurveNodeVertex
187 {
188 float x, y, u, v, w;
189 float dudx, dvdx, dudy, dvdy; // Size of pixel in curve space (must be same for all vertices in triangle)
190 float nx, ny; // normal vector describing the direction to shift the vertex for AA
191 };
192
193 void updateMaterial();
194 static const QSGGeometry::AttributeSet &attributes();
195
196 QColor m_color = Qt::white;
197 float m_debug = 0.0f;
198 QSGGradientCache::GradientDesc m_fillGradient;
199 QGradient::Type m_gradientType = QGradient::NoGradient;
200 QSGTransform m_fillTransform;
201
202 QScopedPointer<QSGMaterial> m_material;
203
204 QVector<CurveNodeVertex> m_uncookedVertexes;
205 QVector<quint32> m_uncookedIndexes;
206};
207
209
210#endif // QSGCURVEFILLNODE_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
Type
Specifies the type of gradient.
Definition qbrush.h:138
@ NoGradient
Definition qbrush.h:142
QGradient::Type gradientType() const
void appendTriangle(const QVector2D &v1, const QVector2D &v2, const QVector2D &v3, const QVector3D &uv1, const QVector3D &uv2, const QVector3D &uv3, const QVector2D &n1, const QVector2D &n2, const QVector2D &n3, const QVector2D &duvdx, const QVector2D &duvdy)
void setDebug(float newDebug)
const QSGGradientCache::GradientDesc * fillGradient() const
void setFillGradient(const QSGGradientCache::GradientDesc &fillGradient)
void reserve(qsizetype size)
const QSGTransform * fillTransform() const
void appendTriangle(const std::array< QVector2D, 3 > &v, const std::array< QVector2D, 3 > &n, std::function< QVector3D(QVector2D)> uvForPoint)
QColor color() const
void setFillTransform(const QSGTransform &transform)
QVector< quint32 > uncookedIndexes() const
void setColor(QColor col) override
void setGradientType(QGradient::Type type)
void appendTriangle(const QVector2D &v1, const QVector2D &v2, const QVector2D &v3, std::function< QVector3D(QVector2D)> uvForPoint)
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:502
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:501
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:671
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:670
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:672
Combined button and popup list for selecting options.
@ white
Definition qnamespace.h:31
GLint GLfloat GLfloat GLfloat v2
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum type
GLint GLfloat GLfloat v1
GLint GLfloat GLfloat GLfloat GLfloat v3
GLfloat n
GLint y
GLuint GLenum GLenum transform
GLbyte nx
GLfixed ny
#define v1
ptrdiff_t qsizetype
Definition qtypes.h:165
The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry are built up.
Definition qsggeometry.h:73