Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsggeometry.cpp
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
// Qt-Security score:significant reason:default
4
5
#
include
"qsggeometry.h"
6
#
include
"qsggeometry_p.h"
7
8
#
ifdef
Q_OS_QNX
9
#
include
<
malloc
.
h
>
10
#
endif
11
12
QT_BEGIN_NAMESPACE
13
14
15
QSGGeometry::Attribute QSGGeometry::Attribute::create(
int
attributeIndex,
int
tupleSize,
int
primitiveType,
bool
isPrimitive)
16
{
17
Attribute a = { attributeIndex, tupleSize, primitiveType, isPrimitive, UnknownAttribute, 0 };
18
return
a;
19
}
20
21
QSGGeometry::Attribute QSGGeometry::Attribute::createWithAttributeType(
int
pos,
int
tupleSize,
int
primitiveType, AttributeType attributeType)
22
{
23
Attribute a;
24
a.position = pos;
25
a.tupleSize = tupleSize;
26
a.type = primitiveType;
27
a.isVertexCoordinate = attributeType == PositionAttribute;
28
a.attributeType = attributeType;
29
a.reserved = 0;
30
return
a;
31
}
32
33
/*!
34
Convenience function which returns attributes to be used for 2D solid
35
color drawing.
36
*/
37
38
const
QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_Point2D()
39
{
40
static
Attribute data[] = {
41
Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute)
42
};
43
static
AttributeSet attrs = { 1,
sizeof
(
float
) * 2, data };
44
return
attrs;
45
}
46
47
/*!
48
Convenience function which returns attributes to be used for textured 2D drawing.
49
*/
50
51
const
QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_TexturedPoint2D()
52
{
53
static
Attribute data[] = {
54
Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute),
55
Attribute::createWithAttributeType(1, 2, FloatType, TexCoordAttribute)
56
};
57
static
AttributeSet attrs = { 2,
sizeof
(
float
) * 4, data };
58
return
attrs;
59
}
60
61
/*!
62
Convenience function which returns attributes to be used for per vertex colored 2D drawing.
63
*/
64
65
const
QSGGeometry::AttributeSet &QSGGeometry::defaultAttributes_ColoredPoint2D()
66
{
67
static
Attribute data[] = {
68
Attribute::createWithAttributeType(0, 2, FloatType, PositionAttribute),
69
Attribute::createWithAttributeType(1, 4, UnsignedByteType, ColorAttribute)
70
};
71
static
AttributeSet attrs = { 2, 2 *
sizeof
(
float
) + 4 *
sizeof
(
char
), data };
72
return
attrs;
73
}
74
75
76
/*!
77
\class QSGGeometry::Attribute
78
\brief The QSGGeometry::Attribute describes a single vertex attribute in a QSGGeometry.
79
\inmodule QtQuick
80
81
The QSGGeometry::Attribute struct describes the attribute register position,
82
the size of the attribute tuple and the attribute type.
83
84
It also contains a hint to the renderer if this attribute is the attribute
85
describing the position. The scene graph renderer may use this information
86
to perform optimizations.
87
88
It contains a number of bits which are reserved for future use.
89
90
\sa QSGGeometry
91
*/
92
93
/*!
94
\fn QSGGeometry::Attribute QSGGeometry::Attribute::create(int pos, int tupleSize, int primitiveType, bool isPosition)
95
96
Creates a new QSGGeometry::Attribute for attribute register \a pos with \a
97
tupleSize. The \a primitiveType can be any of the supported types from
98
QSGGeometry::Type, such as QSGGeometry::FloatType or
99
QSGGeometry::UnsignedByteType.
100
101
If the attribute describes the position for the vertex, the \a isPosition
102
hint should be set to \c true. The scene graph renderer may use this
103
information to perform optimizations.
104
105
Use the create function to construct the attribute, rather than an
106
initialization list, to ensure that all fields are initialized.
107
*/
108
109
/*!
110
\fn QSGGeometry::Attribute QSGGeometry::Attribute::createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType)
111
112
Creates a new QSGGeometry::Attribute for attribute register \a pos with \a
113
tupleSize. The \a primitiveType can be any of the supported types from
114
QSGGeometry::Type, such as QSGGeometry::FloatType or
115
QSGGeometry::UnsignedByteType.
116
117
\a attributeType describes the intended use of the attribute.
118
119
Use the create function to construct the attribute, rather than an
120
initialization list, to ensure that all fields are initialized.
121
*/
122
123
124
/*!
125
\class QSGGeometry::AttributeSet
126
\brief The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry
127
are built up.
128
\inmodule QtQuick
129
130
\sa QSGGeometry
131
*/
132
133
134
/*!
135
\class QSGGeometry::Point2D
136
\brief The QSGGeometry::Point2D struct is a convenience struct for accessing
137
2D Points.
138
139
\inmodule QtQuick
140
*/
141
142
143
/*!
144
\fn void QSGGeometry::Point2D::set(float x, float y)
145
146
Sets the x and y values of this point to \a x and \a y.
147
*/
148
149
150
/*!
151
\class QSGGeometry::ColoredPoint2D
152
\brief The QSGGeometry::ColoredPoint2D struct is a convenience struct for accessing
153
2D Points with a color.
154
155
\inmodule QtQuick
156
*/
157
158
159
/*!
160
\fn void QSGGeometry::ColoredPoint2D::set(float x, float y, uchar red, uchar green, uchar blue, uchar alpha)
161
162
Sets the position of the vertex to \a x and \a y and the color to \a red, \a
163
green, \a blue, and \a alpha.
164
*/
165
166
167
/*!
168
\class QSGGeometry::TexturedPoint2D
169
\brief The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing
170
2D Points with texture coordinates.
171
172
\inmodule QtQuick
173
*/
174
175
176
/*!
177
\fn void QSGGeometry::TexturedPoint2D::set(float x, float y, float tx, float ty)
178
179
Sets the position of the vertex to \a x and \a y and the texture coordinate
180
to \a tx and \a ty.
181
*/
182
183
184
185
/*!
186
\class QSGGeometry
187
188
\brief The QSGGeometry class provides low-level
189
storage for graphics primitives in the \l{Qt Quick Scene Graph}.
190
191
\inmodule QtQuick
192
193
The QSGGeometry class stores the geometry of the primitives rendered
194
with the scene graph. It contains vertex data and optionally index
195
data. The mode used to draw the geometry, also called primitive
196
topology, is specified with setDrawingMode().
197
198
Vertices can be as simple as points defined by x and y values or
199
can be more complex where each vertex contains a normal, texture
200
coordinates and a 3D position. The QSGGeometry::AttributeSet is
201
used to describe how the vertex data is built up. The attribute
202
set can only be specified on construction. The QSGGeometry class
203
provides a few convenience attributes and attribute sets by
204
default. The defaultAttributes_Point2D() function returns an
205
attribute set to be used in normal solid color rectangles, while
206
the defaultAttributes_TexturedPoint2D function returns attributes
207
to be used for textured 2D geometry. The vertex data is internally
208
stored as a \c {void *} and is accessible with the vertexData()
209
function. Convenience accessors for the common attribute sets are
210
available with vertexDataAsPoint2D() and
211
vertexDataAsTexturedPoint2D(). Vertex data is allocated by passing
212
a vertex count to the constructor or by calling allocate() later.
213
214
The number of vertices and indices can be changed after construction
215
by using the allocate() method to resize the data buffer. However,
216
allocate() requires updating all vertex and index data each time
217
called. Since Qt 6.10, setVertexCount() and setIndexCount() allow
218
adjusting the number of vertices or indices without reallocating the
219
data buffer and only require updating new vertices or indices. In
220
either case, the caller must mark the geometry node as dirty, by calling
221
\c{node->markDirty(QSGNode::DirtyGeometry)}, to ensure that the renderer
222
has a chance to update internal buffers.
223
224
The QSGGeometry can optionally contain indices of either unsigned
225
32-bit, unsigned 16-bit, or unsigned 8-bit integers. The index type
226
must be specified during construction and cannot be changed.
227
228
Below is a snippet illustrating how a geometry composed of
229
position and color vertices can be built.
230
231
\code
232
struct MyPoint2D {
233
float x;
234
float y;
235
float r;
236
float g;
237
float b;
238
float a;
239
240
void set(float x_, float y_, float r_, float g_, float b_, float a_) {
241
x = x_;
242
y = y_;
243
r = r_;
244
g = g_;
245
b = b_;
246
a = a_;
247
}
248
};
249
250
QSGGeometry::Attribute MyPoint2D_Attributes[] = {
251
QSGGeometry::Attribute::create(0, 2, FloatType, true),
252
QSGGeometry::Attribute::create(1, 4, FloatType, false)
253
};
254
255
QSGGeometry::AttributeSet MyPoint2D_AttributeSet = {
256
2,
257
sizeof(MyPoint2D),
258
MyPoint2D_Attributes
259
};
260
261
...
262
263
geometry = new QSGGeometry(MyPoint2D_AttributeSet, 2);
264
geometry->setDrawingMode(DrawLines);
265
266
MyPoint2D *vertices = static_cast<MyPoint2D *>(geometry->vertexData());
267
vertices[0].set(0, 0, 1, 0, 0, 1);
268
vertices[1].set(width(), height(), 0, 0, 1, 1);
269
\endcode
270
271
The QSGGeometry is a software buffer and client-side in terms of
272
accelerated rendering, as the buffers used in 2D graphics typically consist of
273
many small buffers that change every frame and do not benefit from
274
being uploaded to graphics memory. However, the QSGGeometry
275
supports hinting to the renderer that a buffer should be
276
uploaded using the setVertexDataPattern() and
277
setIndexDataPattern() functions. Whether this hint is respected or
278
not is implementation specific.
279
280
\sa QSGGeometryNode, {Scene Graph - Custom Geometry}
281
282
\note All classes with QSG prefix should be used solely on the scene graph's
283
rendering thread. See \l {Scene Graph and Rendering} for more information.
284
285
*/
286
287
/*!
288
\fn int QSGGeometry::attributeCount() const
289
290
Returns the number of attributes in the attrbute set used by this geometry.
291
*/
292
293
/*!
294
\fn QSGGeometry::Attribute *QSGGeometry::attributes() const
295
296
Returns an array with the attributes of this geometry. The size of the array
297
is given with attributeCount().
298
*/
299
300
/*!
301
\fn uint *QSGGeometry::indexDataAsUInt()
302
303
Convenience function to access the index data as a mutable array of
304
32-bit unsigned integers.
305
*/
306
307
/*!
308
\fn const uint *QSGGeometry::indexDataAsUInt() const
309
310
Convenience function to access the index data as an immutable array of
311
32-bit unsigned integers.
312
*/
313
314
/*!
315
\fn quint16 *QSGGeometry::indexDataAsUShort()
316
317
Convenience function to access the index data as a mutable array of
318
16-bit unsigned integers.
319
*/
320
321
/*!
322
\fn const quint16 *QSGGeometry::indexDataAsUShort() const
323
324
Convenience function to access the index data as an immutable array of
325
16-bit unsigned integers.
326
*/
327
328
/*!
329
\fn const QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D() const
330
331
Convenience function to access the vertex data as an immutable
332
array of QSGGeometry::ColoredPoint2D.
333
*/
334
335
/*!
336
\fn QSGGeometry::ColoredPoint2D *QSGGeometry::vertexDataAsColoredPoint2D()
337
338
Convenience function to access the vertex data as a mutable
339
array of QSGGeometry::ColoredPoint2D.
340
*/
341
342
/*!
343
\fn const QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D() const
344
345
Convenience function to access the vertex data as an immutable
346
array of QSGGeometry::TexturedPoint2D.
347
*/
348
349
/*!
350
\fn QSGGeometry::TexturedPoint2D *QSGGeometry::vertexDataAsTexturedPoint2D()
351
352
Convenience function to access the vertex data as a mutable
353
array of QSGGeometry::TexturedPoint2D.
354
*/
355
356
/*!
357
\fn const QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D() const
358
359
Convenience function to access the vertex data as an immutable
360
array of QSGGeometry::Point2D.
361
*/
362
363
/*!
364
\fn QSGGeometry::Point2D *QSGGeometry::vertexDataAsPoint2D()
365
366
Convenience function to access the vertex data as a mutable
367
array of QSGGeometry::Point2D.
368
*/
369
370
371
/*!
372
Constructs a geometry object based on \a attributes.
373
374
The object allocate space for \a vertexCount vertices based on the
375
accumulated size in \a attributes and for \a indexCount.
376
377
The \a indexType can be UnsignedShortType or \c
378
UnsignedIntType. Support for the latter depends on the graphics API
379
implementation used at run time, and may not always be available.
380
381
Geometry objects are constructed by default with DrawTriangleStrip as
382
the drawing mode.
383
384
\note \a attributes and the \l Attribute objects referenced by it must
385
stay valid for the entire lifetime of the QSGGeometry.
386
QSGGeometry stores a reference to \a attributes and does not delete
387
the \l Attribute objects.
388
*/
389
390
QSGGeometry::QSGGeometry(
const
QSGGeometry::AttributeSet &attributes,
391
int
vertexCount,
392
int
indexCount,
393
int
indexType)
394
: m_drawing_mode(DrawTriangleStrip)
395
, m_vertex_count(0)
396
, m_index_count(0)
397
, m_index_type(indexType)
398
, m_attributes(attributes)
399
, m_data(
nullptr
)
400
, m_index_data_offset(-1)
401
, m_server_data(
nullptr
)
402
, m_owns_data(
false
)
403
, m_index_usage_pattern(AlwaysUploadPattern)
404
, m_vertex_usage_pattern(AlwaysUploadPattern)
405
, m_line_width(1.0)
406
{
407
Q_UNUSED(m_reserved_bits);
408
Q_ASSERT(m_attributes.count > 0);
409
Q_ASSERT(m_attributes.stride > 0);
410
if
(indexType != UnsignedByteType
411
&& indexType != UnsignedShortType
412
&& indexType != UnsignedIntType) {
413
qFatal(
"QSGGeometry: Unsupported index type, %x.\n"
, indexType);
414
}
415
416
// Because allocate reads m_vertex_count, m_index_count and m_owns_data, these
417
// need to be set before calling allocate...
418
allocate(vertexCount, indexCount);
419
}
420
421
/*!
422
\fn int QSGGeometry::sizeOfVertex() const
423
424
Returns the size in bytes of one vertex.
425
426
This value comes from the attributes.
427
*/
428
429
/*!
430
\fn int QSGGeometry::sizeOfIndex() const
431
432
Returns the byte size of the index type.
433
434
This value is either \c 2 when the index type is UnsignedShortType, or
435
\c 4 when the index type is UnsignedIntType.
436
*/
437
438
/*!
439
Destroys the geometry object and the vertex and index data it has allocated.
440
*/
441
442
QSGGeometry::~QSGGeometry()
443
{
444
if
(m_owns_data)
445
free(m_data);
446
447
if
(m_server_data)
448
delete
m_server_data;
449
}
450
451
/*!
452
\fn int QSGGeometry::vertexCount() const
453
454
Returns the number of vertices that can be rendered, or if indices are used,
455
it returns the number of vertices that can be accessed through indices.
456
457
\sa setVertexCount()
458
*/
459
460
/*!
461
Sets the number of vertices to be rendered.
462
463
The \a count is not validated and it is the users responsibility to ensure
464
that only values between zero and the number of allocated vertices are
465
specified.
466
467
Vertex data is not invalidated after this call, but the caller must mark
468
the geometry node as dirty, by calling \c{node->markDirty(QSGNode::DirtyGeometry)},
469
to ensure that the renderer has a chance to update internal buffers.
470
471
\since 6.10
472
473
\sa vertexCount()
474
*/
475
void
QSGGeometry::setVertexCount(
int
count)
476
{
477
m_vertex_count = count;
478
}
479
480
481
/*!
482
\fn int QSGGeometry::indexCount() const
483
484
Returns the number of indices that are processed when the geometry object
485
is rendered.
486
487
\sa setIndexCount()
488
*/
489
490
/*!
491
Sets the number of indices to be processed each time the geometry object is
492
rendered.
493
494
The \a count is not validated and it is the users responsibility to ensure
495
that only values between zero and the number of allocated indices are
496
specified.
497
498
Vertex and index data is not invalidated after this call, but the caller must
499
mark the geometry node as dirty, by calling \c{node->markDirty(QSGNode::DirtyGeometry)},
500
to ensure that the renderer has a chance to update internal buffers.
501
502
\since 6.10
503
504
\sa indexCount()
505
*/
506
void
QSGGeometry::setIndexCount(
int
count)
507
{
508
m_index_count = count;
509
}
510
511
512
/*!
513
\fn void *QSGGeometry::vertexData()
514
515
Returns a pointer to the raw vertex data of this geometry object.
516
517
\sa vertexDataAsPoint2D(), vertexDataAsTexturedPoint2D()
518
*/
519
520
/*!
521
\fn const void *QSGGeometry::vertexData() const
522
523
Returns a pointer to the raw vertex data of this geometry object.
524
525
\sa vertexDataAsPoint2D(), vertexDataAsTexturedPoint2D()
526
*/
527
528
/*!
529
Returns a pointer to the raw index data of this geometry object.
530
531
\sa indexDataAsUShort(), indexDataAsUInt()
532
*/
533
void
*QSGGeometry::indexData()
534
{
535
return
m_index_data_offset < 0
536
?
nullptr
537
: ((
char
*) m_data + m_index_data_offset);
538
}
539
540
/*!
541
Returns a pointer to the raw index data of this geometry object.
542
543
\sa indexDataAsUShort(), indexDataAsUInt()
544
*/
545
const
void
*QSGGeometry::indexData()
const
546
{
547
return
m_index_data_offset < 0
548
?
nullptr
549
: ((
char
*) m_data + m_index_data_offset);
550
}
551
552
/*!
553
\enum QSGGeometry::DrawingMode
554
555
Specifies the drawing mode, also called primitive topology.
556
557
\note Starting with Qt 6 the scene graph only exposes topologies that are
558
supported across all the supported 3D graphics APIs. As a result, the
559
values \c DrawLineLoop and \c DrawTriangleFan are no longer supported at
560
run time in Qt 6, even though the enum values themselves are still present.
561
562
\value DrawPoints
563
\value DrawLines
564
\omitvalue DrawLineLoop
565
\value DrawLineStrip
566
\value DrawTriangles
567
\value DrawTriangleStrip
568
\omitvalue DrawTriangleFan
569
*/
570
571
/*!
572
\enum QSGGeometry::Type
573
574
Specifies the component type in the vertex data.
575
576
\value ByteType
577
\value UnsignedByteType
578
\value ShortType
579
\value UnsignedShortType
580
\value IntType
581
\value UnsignedIntType
582
\value FloatType
583
\value Bytes2Type Added in Qt 5.14.
584
\value Bytes3Type Added in Qt 5.14.
585
\value Bytes4Type Added in Qt 5.14.
586
\value DoubleType Added in Qt 5.14.
587
*/
588
589
/*!
590
Sets the \a mode to be used for drawing this geometry.
591
592
The default value is QSGGeometry::DrawTriangleStrip.
593
594
\sa DrawingMode
595
*/
596
void
QSGGeometry::setDrawingMode(
unsigned
int
mode)
597
{
598
m_drawing_mode = mode;
599
}
600
601
/*!
602
Gets the current line or point width or to be used for this geometry. This
603
property only applies to line width when the drawingMode is DrawLines or
604
DrawLineStrip. When supported, it also applies to point size when the
605
drawingMode is DrawPoints.
606
607
The default value is \c 1.0
608
609
\note Support for point and line drawing may be limited at run time,
610
depending on the platform and graphics API. For example, some APIs do
611
not support point sprites and so setting a size other than 1 is not
612
possible.
613
614
\note The width of \c 1.0 is always supported.
615
616
\sa setLineWidth(), drawingMode()
617
*/
618
float
QSGGeometry::lineWidth()
const
619
{
620
return
m_line_width;
621
}
622
623
/*!
624
Sets the line or point width to be used for this geometry to \a width. This
625
property only applies to line width when the drawingMode is DrawLines or
626
DrawLineStrip. When supported, it also applies to point size when the
627
drawingMode is DrawPoints.
628
629
\note Support for point and line drawing may be limited at run time,
630
depending on the platform and graphics API. For example, some APIs do
631
not support point sprites and so setting a size other than 1 is not
632
possible.
633
634
\note The width of \c 1.0 is always supported.
635
636
\sa lineWidth(), drawingMode()
637
*/
638
void
QSGGeometry::setLineWidth(
float
width)
639
{
640
m_line_width = width;
641
}
642
643
/*!
644
\fn int QSGGeometry::drawingMode() const
645
646
Returns the drawing mode of this geometry.
647
648
The default value is DrawTriangleStrip.
649
*/
650
651
/*!
652
\fn int QSGGeometry::indexType() const
653
654
Returns the primitive type used for indices in this
655
geometry object.
656
*/
657
658
659
/*!
660
Resizes the vertex and index data of this geometry object to fit \a vertexCount
661
vertices and \a indexCount indices and sets the number of vertices and
662
indices accordingly.
663
664
Use setVertexCount() or setIndexCount() to change the number of vertices
665
or indices without calling allocate() again.
666
667
Vertex and index data will be invalidated after this call and the caller must
668
mark the associated geometry node as dirty, by calling
669
\c{node->markDirty(QSGNode::DirtyGeometry)}, to ensure that the renderer has
670
a chance to update internal buffers.
671
672
\sa setVertexCount(), setIndexCount()
673
*/
674
void
QSGGeometry::allocate(
int
vertexCount,
int
indexCount)
675
{
676
if
(vertexCount == m_vertex_count && indexCount == m_index_count)
677
return
;
678
679
m_vertex_count = vertexCount;
680
m_index_count = indexCount;
681
682
bool
canUsePrealloc = m_index_count <= 0;
683
int
vertexByteSize = m_attributes.stride * m_vertex_count;
684
685
if
(m_owns_data)
686
free(m_data);
687
688
if
(canUsePrealloc && vertexByteSize <= (
int
)
sizeof
(m_prealloc)) {
689
// The preallocated buffer is suitable for simple geometry objects like
690
// rectangles and avoids a malloc/free but does not support index data.
691
m_data = (
void
*) &m_prealloc[0];
692
m_index_data_offset = -1;
693
m_owns_data =
false
;
694
}
else
{
695
Q_ASSERT(m_index_type == UnsignedIntType || m_index_type == UnsignedShortType);
696
int
indexByteSize = indexCount * (m_index_type == UnsignedShortType ?
sizeof
(quint16) :
sizeof
(quint32));
697
m_data = (
void
*) malloc(vertexByteSize + indexByteSize);
698
Q_CHECK_PTR(m_data);
699
m_index_data_offset = vertexByteSize;
700
m_owns_data =
true
;
701
}
702
703
// If we have associated vbo data we could potentially crash later if
704
// the old buffers are used with the new vertex and index count, so we force
705
// an update in the renderer in that case. This is really the users responsibility
706
// but it is cheap for us to enforce this, so why not...
707
if
(m_server_data) {
708
markIndexDataDirty();
709
markVertexDataDirty();
710
}
711
}
712
713
/*!
714
Updates the geometry \a g with the coordinates in \a rect.
715
716
The function assumes the geometry object contains a single triangle strip
717
of QSGGeometry::Point2D vertices
718
*/
719
void
QSGGeometry::updateRectGeometry(QSGGeometry *g,
const
QRectF &rect)
720
{
721
Point2D *v = g->vertexDataAsPoint2D();
722
v[0].x = rect.left();
723
v[0].y = rect.top();
724
725
v[1].x = rect.left();
726
v[1].y = rect.bottom();
727
728
v[2].x = rect.right();
729
v[2].y = rect.top();
730
731
v[3].x = rect.right();
732
v[3].y = rect.bottom();
733
}
734
735
/*!
736
Updates the geometry \a g with the coordinates in \a rect and texture
737
coordinates from \a textureRect.
738
739
\a textureRect should be in normalized coordinates.
740
741
\a g is assumed to be a triangle strip of four vertices of type
742
QSGGeometry::TexturedPoint2D.
743
*/
744
void
QSGGeometry::updateTexturedRectGeometry(QSGGeometry *g,
const
QRectF &rect,
const
QRectF &textureRect)
745
{
746
TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
747
v[0].x = rect.left();
748
v[0].y = rect.top();
749
v[0].tx = textureRect.left();
750
v[0].ty = textureRect.top();
751
752
v[1].x = rect.left();
753
v[1].y = rect.bottom();
754
v[1].tx = textureRect.left();
755
v[1].ty = textureRect.bottom();
756
757
v[2].x = rect.right();
758
v[2].y = rect.top();
759
v[2].tx = textureRect.right();
760
v[2].ty = textureRect.top();
761
762
v[3].x = rect.right();
763
v[3].y = rect.bottom();
764
v[3].tx = textureRect.right();
765
v[3].ty = textureRect.bottom();
766
}
767
768
/*!
769
Updates the geometry \a g with the coordinates in \a rect.
770
771
The function assumes the geometry object contains a single triangle strip
772
of QSGGeometry::ColoredPoint2D vertices
773
*/
774
void
QSGGeometry::updateColoredRectGeometry(QSGGeometry *g,
const
QRectF &rect)
775
{
776
ColoredPoint2D *v = g->vertexDataAsColoredPoint2D();
777
v[0].x = rect.left();
778
v[0].y = rect.top();
779
780
v[1].x = rect.left();
781
v[1].y = rect.bottom();
782
783
v[2].x = rect.right();
784
v[2].y = rect.top();
785
786
v[3].x = rect.right();
787
v[3].y = rect.bottom();
788
}
789
790
/*!
791
\enum QSGGeometry::AttributeType
792
793
This enum identifies several attribute types.
794
795
\value UnknownAttribute Don't care
796
\value PositionAttribute Position
797
\value ColorAttribute Color
798
\value TexCoordAttribute Texture coordinate
799
\value TexCoord1Attribute Texture coordinate 1
800
\value TexCoord2Attribute Texture coordinate 2
801
802
*/
803
804
/*!
805
\enum QSGGeometry::DataPattern
806
807
The DataPattern enum is used to specify the use pattern for the
808
vertex and index data in a geometry object.
809
810
\value AlwaysUploadPattern The data is always uploaded. This means
811
that the user does not need to explicitly mark index and vertex
812
data as dirty after changing it. This is the default.
813
814
\value DynamicPattern The data is modified repeatedly and drawn
815
many times. This is a hint that may provide better
816
performance. When set the user must make sure to mark the data as
817
dirty after changing it.
818
819
\value StaticPattern The data is modified once and drawn many
820
times. This is a hint that may provide better performance. When
821
set the user must make sure to mark the data as dirty after
822
changing it.
823
824
\value StreamPattern The data is modified for almost every time it
825
is drawn. This is a hint that may provide better performance. When
826
set, the user must make sure to mark the data as dirty after
827
changing it.
828
*/
829
830
831
/*!
832
\fn QSGGeometry::DataPattern QSGGeometry::indexDataPattern() const
833
834
Returns the usage pattern for indices in this geometry. The default
835
pattern is AlwaysUploadPattern.
836
*/
837
838
/*!
839
Sets the usage pattern for indices to \a p.
840
841
The default is AlwaysUploadPattern. When set to anything other than
842
the default, the user must call markIndexDataDirty() after changing
843
the index data, in addition to calling QSGNode::markDirty() with
844
QSGNode::DirtyGeometry.
845
*/
846
847
void
QSGGeometry::setIndexDataPattern(DataPattern p)
848
{
849
m_index_usage_pattern = p;
850
}
851
852
853
854
855
/*!
856
\fn QSGGeometry::DataPattern QSGGeometry::vertexDataPattern() const
857
858
Returns the usage pattern for vertices in this geometry. The default
859
pattern is AlwaysUploadPattern.
860
*/
861
862
/*!
863
Sets the usage pattern for vertices to \a p.
864
865
The default is AlwaysUploadPattern. When set to anything other than
866
the default, the user must call markVertexDataDirty() after changing
867
the vertex data, in addition to calling QSGNode::markDirty() with
868
QSGNode::DirtyGeometry.
869
*/
870
871
void
QSGGeometry::setVertexDataPattern(DataPattern p)
872
{
873
m_vertex_usage_pattern = p;
874
}
875
876
877
878
879
/*!
880
Mark that the vertices in this geometry has changed and must be uploaded
881
again.
882
883
This function only has an effect when the usage pattern for vertices is
884
StaticData and the renderer that renders this geometry uploads the geometry
885
into Vertex Buffer Objects (VBOs).
886
*/
887
void
QSGGeometry::markIndexDataDirty()
888
{
889
m_dirty_index_data =
true
;
890
}
891
892
893
894
/*!
895
Mark that the vertices in this geometry has changed and must be uploaded
896
again.
897
898
This function only has an effect when the usage pattern for vertices is
899
StaticData and the renderer that renders this geometry uploads the geometry
900
into Vertex Buffer Objects (VBOs).
901
*/
902
void
QSGGeometry::markVertexDataDirty()
903
{
904
m_dirty_vertex_data =
true
;
905
}
906
907
908
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quick
scenegraph
coreapi
qsggeometry.cpp
Generated on
for Qt by
1.18.0