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