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
qsggeometry.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 QSGGEOMETRY_H
5#define QSGGEOMETRY_H
6
7#include <QtQuick/qtquickglobal.h>
8#include <QtCore/QRectF>
9
11
12class QSGGeometryData;
13
14class Q_QUICK_EXPORT QSGGeometry
15{
16public:
25
27 AlwaysUploadPattern = 0,
28 StreamPattern = 1,
29 DynamicPattern = 2,
30 StaticPattern = 3
31 };
32
34 DrawPoints = 0x0000,
35 DrawLines = 0x0001,
36 DrawLineLoop = 0x0002,
37 DrawLineStrip = 0x0003,
38 DrawTriangles = 0x0004,
39 DrawTriangleStrip = 0x0005,
40 DrawTriangleFan = 0x0006
41 };
42
43 enum Type {
44 ByteType = 0x1400,
45 UnsignedByteType = 0x1401,
46 ShortType = 0x1402,
47 UnsignedShortType = 0x1403,
48 IntType = 0x1404,
49 UnsignedIntType = 0x1405,
50 FloatType = 0x1406,
51 Bytes2Type = 0x1407,
52 Bytes3Type = 0x1408,
53 Bytes4Type = 0x1409,
54 DoubleType = 0x140A
55 };
56
57 struct Q_QUICK_EXPORT Attribute
58 {
61 int type;
62
64
66
68
69 static Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition = false);
70 static Attribute createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType);
71 };
72
73 struct AttributeSet {
74 int count;
75 int stride;
77 };
78
79 struct Point2D {
80 float x, y;
81 void set(float nx, float ny) {
82 x = nx; y = ny;
83 }
84 };
86 float x, y;
87 float tx, ty;
88 void set(float nx, float ny, float ntx, float nty) {
89 x = nx; y = ny; tx = ntx; ty = nty;
90 }
91 };
93 float x, y;
94 unsigned char r, g, b, a;
95 void set(float nx, float ny, uchar nr, uchar ng, uchar nb, uchar na) {
96 x = nx; y = ny;
97 r = nr;
98 g = ng;
99 b = nb;
100 a = na;
101 }
102 };
103
104 static const AttributeSet &defaultAttributes_Point2D();
105 static const AttributeSet &defaultAttributes_TexturedPoint2D();
106 static const AttributeSet &defaultAttributes_ColoredPoint2D();
107
109 int vertexCount,
110 int indexCount = 0,
111 int indexType = UnsignedShortType);
112 virtual ~QSGGeometry();
113
114 // must use unsigned int to be compatible with the old GLenum to keep BC
115 void setDrawingMode(unsigned int mode);
116 inline unsigned int drawingMode() const { return m_drawing_mode; }
117
118 void allocate(int vertexCount, int indexCount = 0);
119
120 int vertexCount() const { return m_vertex_count; }
121
122 void *vertexData() { return m_data; }
123 inline Point2D *vertexDataAsPoint2D();
124 inline TexturedPoint2D *vertexDataAsTexturedPoint2D();
125 inline ColoredPoint2D *vertexDataAsColoredPoint2D();
126
127 inline const void *vertexData() const { return m_data; }
128 inline const Point2D *vertexDataAsPoint2D() const;
129 inline const TexturedPoint2D *vertexDataAsTexturedPoint2D() const;
130 inline const ColoredPoint2D *vertexDataAsColoredPoint2D() const;
131
132 inline int indexType() const { return m_index_type; }
133
134 int indexCount() const { return m_index_count; }
135
136 void *indexData();
137 inline uint *indexDataAsUInt();
138 inline quint16 *indexDataAsUShort();
139
140 inline int sizeOfIndex() const;
141
142 const void *indexData() const;
143 inline const uint *indexDataAsUInt() const;
144 inline const quint16 *indexDataAsUShort() const;
145
146 inline int attributeCount() const { return m_attributes.count; }
147 inline const Attribute *attributes() const { return m_attributes.attributes; }
148 inline int sizeOfVertex() const { return m_attributes.stride; }
149
150 static void updateRectGeometry(QSGGeometry *g, const QRectF &rect);
151 static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect);
152 static void updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect);
153
154 void setIndexDataPattern(DataPattern p);
155 DataPattern indexDataPattern() const { return DataPattern(m_index_usage_pattern); }
156
157 void setVertexDataPattern(DataPattern p);
158 DataPattern vertexDataPattern() const { return DataPattern(m_vertex_usage_pattern); }
159
160 void markIndexDataDirty();
161 void markVertexDataDirty();
162
163 float lineWidth() const;
164 void setLineWidth(float w);
165
166private:
167 Q_DISABLE_COPY_MOVE(QSGGeometry)
168 friend class QSGGeometryData;
169
170 int m_drawing_mode;
171 int m_vertex_count;
172 int m_index_count;
173 int m_index_type;
174 const AttributeSet &m_attributes;
175 void *m_data;
176 int m_index_data_offset;
177
178 QSGGeometryData *m_server_data;
179
180 uint m_owns_data : 1;
181 uint m_index_usage_pattern : 2;
182 uint m_vertex_usage_pattern : 2;
183 uint m_dirty_index_data : 1;
184 uint m_dirty_vertex_data : 1;
185 uint m_reserved_bits : 25;
186
187 float m_prealloc[16];
188
189 float m_line_width;
190};
191
192inline uint *QSGGeometry::indexDataAsUInt()
193{
194 Q_ASSERT(m_index_type == UnsignedIntType);
195 return static_cast<uint *>(indexData());
196}
197
199{
200 Q_ASSERT(m_index_type == UnsignedShortType);
201 return static_cast<quint16 *>(indexData());
202}
203
205{
206 Q_ASSERT(m_index_type == UnsignedIntType);
207 return static_cast<const uint *>(indexData());
208}
209
211{
212 Q_ASSERT(m_index_type == UnsignedShortType);
213 return static_cast<const quint16 *>(indexData());
214}
215
217{
218 Q_ASSERT(m_attributes.count == 1);
219 Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
220 Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
221 Q_ASSERT(m_attributes.attributes[0].type == FloatType);
222 Q_ASSERT(m_attributes.attributes[0].position == 0);
223 return static_cast<Point2D *>(m_data);
224}
225
227{
228 Q_ASSERT(m_attributes.count == 2);
229 Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
230 Q_ASSERT(m_attributes.attributes[0].position == 0);
231 Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
232 Q_ASSERT(m_attributes.attributes[0].type == FloatType);
233 Q_ASSERT(m_attributes.attributes[1].position == 1);
234 Q_ASSERT(m_attributes.attributes[1].tupleSize == 2);
235 Q_ASSERT(m_attributes.attributes[1].type == FloatType);
236 return static_cast<TexturedPoint2D *>(m_data);
237}
238
240{
241 Q_ASSERT(m_attributes.count == 2);
242 Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
243 Q_ASSERT(m_attributes.attributes[0].position == 0);
244 Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
245 Q_ASSERT(m_attributes.attributes[0].type == FloatType);
246 Q_ASSERT(m_attributes.attributes[1].position == 1);
247 Q_ASSERT(m_attributes.attributes[1].tupleSize == 4);
248 Q_ASSERT(m_attributes.attributes[1].type == UnsignedByteType);
249 return static_cast<ColoredPoint2D *>(m_data);
250}
251
253{
254 Q_ASSERT(m_attributes.count == 1);
255 Q_ASSERT(m_attributes.stride == 2 * sizeof(float));
256 Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
257 Q_ASSERT(m_attributes.attributes[0].type == FloatType);
258 Q_ASSERT(m_attributes.attributes[0].position == 0);
259 return static_cast<const Point2D *>(m_data);
260}
261
263{
264 Q_ASSERT(m_attributes.count == 2);
265 Q_ASSERT(m_attributes.stride == 4 * sizeof(float));
266 Q_ASSERT(m_attributes.attributes[0].position == 0);
267 Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
268 Q_ASSERT(m_attributes.attributes[0].type == FloatType);
269 Q_ASSERT(m_attributes.attributes[1].position == 1);
270 Q_ASSERT(m_attributes.attributes[1].tupleSize == 2);
271 Q_ASSERT(m_attributes.attributes[1].type == FloatType);
272 return static_cast<const TexturedPoint2D *>(m_data);
273}
274
276{
277 Q_ASSERT(m_attributes.count == 2);
278 Q_ASSERT(m_attributes.stride == 2 * sizeof(float) + 4 * sizeof(char));
279 Q_ASSERT(m_attributes.attributes[0].position == 0);
280 Q_ASSERT(m_attributes.attributes[0].tupleSize == 2);
281 Q_ASSERT(m_attributes.attributes[0].type == FloatType);
282 Q_ASSERT(m_attributes.attributes[1].position == 1);
283 Q_ASSERT(m_attributes.attributes[1].tupleSize == 4);
284 Q_ASSERT(m_attributes.attributes[1].type == UnsignedByteType);
285 return static_cast<const ColoredPoint2D *>(m_data);
286}
287
289{
290 if (m_index_type == UnsignedShortType) return 2;
291 else if (m_index_type == UnsignedByteType) return 1;
292 else if (m_index_type == UnsignedIntType) return 4;
293 return 0;
294}
295
297
298#endif // QSGGEOMETRY_H
NSData * m_data
\inmodule QtCore\reentrant
Definition qrect.h:484
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
DataPattern
The DataPattern enum is used to specify the use pattern for the vertex and index data in a geometry o...
Definition qsggeometry.h:26
uint * indexDataAsUInt()
Convenience function to access the index data as a mutable array of 32-bit unsigned integers.
unsigned int drawingMode() const
Returns the drawing mode of this geometry.
DrawingMode
Specifies the drawing mode, also called primitive topology.
Definition qsggeometry.h:33
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D.
DataPattern vertexDataPattern() const
Returns the usage pattern for vertices in this geometry.
DataPattern indexDataPattern() const
Returns the usage pattern for indices in this geometry.
AttributeType
This enum identifies several attribute types.
Definition qsggeometry.h:17
const Attribute * attributes() const
Returns an array with the attributes of this geometry.
int attributeCount() const
Returns the number of attributes in the attrbute set used by this geometry.
const void * vertexData() const
Returns a pointer to the raw vertex data of this geometry object.
ColoredPoint2D * vertexDataAsColoredPoint2D()
Convenience function to access the vertex data as a mutable array of QSGGeometry::ColoredPoint2D.
int indexType() const
Returns the primitive type used for indices in this geometry object.
int sizeOfVertex() const
Returns the size in bytes of one vertex.
void * vertexData()
Returns a pointer to the raw vertex data of this geometry object.
int indexCount() const
Returns the number of indices in this geometry object.
Point2D * vertexDataAsPoint2D()
Convenience function to access the vertex data as a mutable array of QSGGeometry::Point2D.
quint16 * indexDataAsUShort()
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
int sizeOfIndex() const
Returns the byte size of the index type.
int vertexCount() const
Returns the number of vertices in this geometry object.
rect
[4]
Combined button and popup list for selecting options.
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLboolean GLboolean g
GLint y
GLbyte nx
GLfixed ny
GLfloat GLfloat p
[1]
GLbyte ty
const GLint * attribs
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
unsigned char uchar
Definition qtypes.h:32
unsigned short quint16
Definition qtypes.h:48
unsigned int uint
Definition qtypes.h:34
label setLineWidth(2)
view create()
The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry are built up.
Definition qsggeometry.h:73
const Attribute * attributes
Definition qsggeometry.h:76
The QSGGeometry::Attribute describes a single vertex attribute in a QSGGeometry.
Definition qsggeometry.h:58
AttributeType attributeType
Definition qsggeometry.h:65
The QSGGeometry::ColoredPoint2D struct is a convenience struct for accessing 2D Points with a color.
Definition qsggeometry.h:92
void set(float nx, float ny, uchar nr, uchar ng, uchar nb, uchar na)
Sets the position of the vertex to x and y and the color to red, green, blue, and alpha.
Definition qsggeometry.h:95
The QSGGeometry::Point2D struct is a convenience struct for accessing 2D Points.
Definition qsggeometry.h:79
void set(float nx, float ny)
Sets the x and y values of this point to x and y.
Definition qsggeometry.h:81
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture ...
Definition qsggeometry.h:85
void set(float nx, float ny, float ntx, float nty)
Sets the position of the vertex to x and y and the texture coordinate to tx and ty.
Definition qsggeometry.h:88
Definition moc.h:23