Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickshapegenericrenderer_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QQUICKSHAPEGENERICRENDERER_P_H
5#define QQUICKSHAPEGENERICRENDERER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickShapes/private/qquickshapesglobal_p.h>
19#include <QtQuickShapes/private/qquickshape_p_p.h>
20#include <qsgnode.h>
21#include <qsggeometry.h>
22#include <qsgmaterial.h>
24#include <qsgtexture.h>
25#include <QtCore/qrunnable.h>
26
28
33
35{
36public:
37 enum Dirty {
40 DirtyColor = 0x04,
42 DirtyList = 0x10 // only for accDirty
43 };
44
46 : m_item(item),
48 m_rootNode(nullptr),
49 m_accDirty(0),
50 m_asyncCallback(nullptr),
51 m_asyncCallbackData(nullptr)
52 { }
54
55 void beginSync(int totalCount, bool *countChanged) override;
56 void setPath(int index, const QQuickPath *path) override;
57 void setStrokeColor(int index, const QColor &color) override;
58 void setStrokeWidth(int index, qreal w) override;
59 void setFillColor(int index, const QColor &color) override;
60 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
61 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
62 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
64 qreal dashOffset, const QVector<qreal> &dashPattern) override;
65 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
66 void setTriangulationScale(qreal scale) override;
67 void endSync(bool async) override;
68 void setAsyncCallback(void (*)(void *), void *) override;
69 Flags flags() const override { return SupportsAsync; }
70
71 void updateNode() override;
72
74
75 struct Color4ub { unsigned char r, g, b, a; };
78
79 static void triangulateFill(const QPainterPath &path,
80 const Color4ub &fillColor,
81 VertexContainerType *fillVertices,
82 IndexContainerType *fillIndices,
83 QSGGeometry::Type *indexType,
84 bool supportsElementIndexUint,
85 qreal triangulationScale);
86 static void triangulateStroke(const QPainterPath &path,
87 const QPen &pen,
88 const Color4ub &strokeColor,
89 VertexContainerType *strokeVertices,
90 const QSize &clipSize,
91 qreal triangulationScale);
92
93private:
94 void maybeUpdateAsyncItem();
95
96 struct ShapePathData {
97 float strokeWidth;
98 QPen pen;
99 Color4ub strokeColor;
100 Color4ub fillColor;
101 Qt::FillRule fillRule;
103 FillGradientType fillGradientActive;
104 GradientDesc fillGradient;
105 VertexContainerType fillVertices;
106 IndexContainerType fillIndices;
107 QSGGeometry::Type indexType;
108 VertexContainerType strokeVertices;
109 int syncDirty;
110 int effectiveDirty = 0;
111 QQuickShapeFillRunnable *pendingFill = nullptr;
112 QQuickShapeStrokeRunnable *pendingStroke = nullptr;
113 };
114
115 void updateShadowDataInNode(ShapePathData *d, QQuickShapeGenericStrokeFillNode *n);
116 void updateFillNode(ShapePathData *d, QQuickShapeGenericNode *node);
117 void updateStrokeNode(ShapePathData *d, QQuickShapeGenericNode *node);
118
119 QQuickItem *m_item;
121 QQuickShapeGenericNode *m_rootNode;
123 int m_accDirty;
124 void (*m_asyncCallback)(void *);
125 void *m_asyncCallbackData;
126 float m_triangulationScale = 1.0;
127};
128
130{
132
133public:
134 void run() override;
135
136 bool orphaned = false;
137
138 // input
143
144 // output
148
151};
152
154{
156
157public:
158 void run() override;
159
160 bool orphaned = false;
161
162 // input
168
169 // output
171
174};
175
177{
178public:
180
181 enum Material {
186 };
187
189
190 // shadow data for custom materials
192
193private:
195
197};
198
200{
201public:
205};
206
208{
209public:
214};
215
217{
218public:
220
222 QSGMaterial *oldMaterial) override;
224 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
225
226private:
227 QVector2D m_gradA;
228 QVector2D m_gradB;
229};
230
232{
233public:
235 : m_node(node)
236 {
237 // Passing RequiresFullMatrix is essential in order to prevent the
238 // batch renderer from baking in simple, translate-only transforms into
239 // the vertex data. The shader will rely on the fact that
240 // vertexCoord.xy is the Shape-space coordinate and so no modifications
241 // are welcome.
243 }
244
245 QSGMaterialType *type() const override;
246 int compare(const QSGMaterial *other) const override;
248
249 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
250
251private:
253};
254
256{
257public:
259
261 QSGMaterial *oldMaterial) override;
263 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
264
265private:
266 QVector2D m_focalPoint;
267 QVector2D m_focalToCenter;
268 float m_centerRadius;
269 float m_focalRadius;
270};
271
273{
274public:
276 : m_node(node)
277 {
279 }
280
281 QSGMaterialType *type() const override;
282 int compare(const QSGMaterial *other) const override;
284
285 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
286
287private:
289};
290
292{
293public:
295
297 QSGMaterial *oldMaterial) override;
299 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
300
301private:
302 QVector2D m_centerPoint;
303 float m_angle;
304};
305
307{
308public:
310 : m_node(node)
311 {
313 }
314
315 QSGMaterialType *type() const override;
316 int compare(const QSGMaterial *other) const override;
318
319 QQuickShapeGenericStrokeFillNode *node() const { return m_node; }
320
321private:
323};
324
326
327#endif // QQUICKSHAPEGENERICRENDERER_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
Definition qlist.h:74
\inmodule QtCore
Definition qobject.h:90
\inmodule QtGui
\inmodule QtGui
Definition qpen.h:25
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeConicalGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeGenericRenderer::Color4ub fillColor
QQuickShapeGenericRenderer::VertexContainerType fillVertices
QQuickShapeGenericRenderer::IndexContainerType fillIndices
void done(QQuickShapeFillRunnable *self)
void run() override
Implement this pure virtual function in your subclass.
static QSGMaterial * createLinearGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
static QSGMaterial * createConicalGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
static QSGMaterial * createVertexColor(QQuickWindow *window)
static QSGMaterial * createRadialGradient(QQuickWindow *window, QQuickShapeGenericStrokeFillNode *node)
QQuickShapeGenericStrokeFillNode * m_fillNode
QQuickShapeGenericStrokeFillNode * m_strokeNode
void setAsyncCallback(void(*)(void *), void *) override
void setTriangulationScale(qreal scale) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
static void triangulateFill(const QPainterPath &path, const Color4ub &fillColor, VertexContainerType *fillVertices, IndexContainerType *fillIndices, QSGGeometry::Type *indexType, bool supportsElementIndexUint, qreal triangulationScale)
void setStrokeColor(int index, const QColor &color) override
void setFillRule(int index, QQuickShapePath::FillRule fillRule) override
void setFillColor(int index, const QColor &color) override
QVector< QSGGeometry::ColoredPoint2D > VertexContainerType
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setStrokeWidth(int index, qreal w) override
void setRootNode(QQuickShapeGenericNode *node)
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
static void triangulateStroke(const QPainterPath &path, const QPen &pen, const Color4ub &strokeColor, VertexContainerType *strokeVertices, const QSize &clipSize, qreal triangulationScale)
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern) override
void setPath(int index, const QQuickPath *path) override
QQuickAbstractPathRenderer::GradientDesc m_fillGradient
void activateMaterial(QQuickWindow *window, Material m)
QQuickShapeLinearGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeGenericStrokeFillNode * node() const
QQuickShapeRadialGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
QQuickShapeGenericRenderer::Color4ub strokeColor
QQuickShapeGenericRenderer::VertexContainerType strokeVertices
void done(QQuickShapeStrokeRunnable *self)
void run() override
Implement this pure virtual function in your subclass.
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore
Definition qrunnable.h:18
The QSGGeometryNode class is used for all rendered content in the scene graph.
Definition qsgnode.h:191
Type
Specifies the component type in the vertex data.
Definition qsggeometry.h:43
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterialShader class represents a graphics API independent shader program.
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
An interface providing access to some of the graphics API specific internals of the scenegraph.
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
GraphicsApi
\value Unknown An unknown graphics API is in use \value Software The Qt Quick 2D Renderer is in use \...
\inmodule QtQuick
Definition qsgtexture.h:20
\inmodule QtCore
\inmodule QtCore
Definition qsize.h:25
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
Flags
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLuint index
[2]
GLenum GLuint texture
GLfloat n
GLsizei const GLchar *const * path
GLenum GLenum GLenum GLenum GLenum scale
#define Q_OBJECT
#define Q_SIGNALS
double qreal
Definition qtypes.h:92
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QGraphicsItem * item
aWidget window() -> setWindowTitle("New Window Title")
[2]
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.