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.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"
5#include "qsggeometry_p.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
21{
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
38{
39 static Attribute data[] = {
41 };
42 static AttributeSet attrs = { 1, sizeof(float) * 2, data };
43 return attrs;
44}
45
59
73
74
380 int vertexCount,
381 int indexCount,
382 int indexType)
383 : m_drawing_mode(DrawTriangleStrip)
384 , m_vertex_count(0)
385 , m_index_count(0)
386 , m_index_type(indexType)
387 , m_attributes(attributes)
388 , m_data(nullptr)
389 , m_index_data_offset(-1)
390 , m_server_data(nullptr)
391 , m_owns_data(false)
392 , m_index_usage_pattern(AlwaysUploadPattern)
393 , m_vertex_usage_pattern(AlwaysUploadPattern)
394 , m_line_width(1.0)
395{
396 Q_UNUSED(m_reserved_bits);
397 Q_ASSERT(m_attributes.count > 0);
398 Q_ASSERT(m_attributes.stride > 0);
402 qFatal("QSGGeometry: Unsupported index type, %x.\n", indexType);
403 }
404
405 // Because allocate reads m_vertex_count, m_index_count and m_owns_data, these
406 // need to be set before calling allocate...
408}
409
432{
433 if (m_owns_data)
434 free(m_data);
435
436 if (m_server_data)
437 delete m_server_data;
438}
439
476{
477 return m_index_data_offset < 0
478 ? nullptr
479 : ((char *) m_data + m_index_data_offset);
480}
481
487const void *QSGGeometry::indexData() const
488{
489 return m_index_data_offset < 0
490 ? nullptr
491 : ((char *) m_data + m_index_data_offset);
492}
493
539{
540 m_drawing_mode = mode;
541}
542
561{
562 return m_line_width;
563}
564
581{
582 m_line_width = width;
583}
584
610void QSGGeometry::allocate(int vertexCount, int indexCount)
611{
612 if (vertexCount == m_vertex_count && indexCount == m_index_count)
613 return;
614
615 m_vertex_count = vertexCount;
616 m_index_count = indexCount;
617
618 bool canUsePrealloc = m_index_count <= 0;
619 int vertexByteSize = m_attributes.stride * m_vertex_count;
620
621 if (m_owns_data)
622 free(m_data);
623
624 if (canUsePrealloc && vertexByteSize <= (int) sizeof(m_prealloc)) {
625 m_data = (void *) &m_prealloc[0];
626 m_index_data_offset = -1;
627 m_owns_data = false;
628 } else {
629 Q_ASSERT(m_index_type == UnsignedIntType || m_index_type == UnsignedShortType);
630 int indexByteSize = indexCount * (m_index_type == UnsignedShortType ? sizeof(quint16) : sizeof(quint32));
631 m_data = (void *) malloc(vertexByteSize + indexByteSize);
632 Q_CHECK_PTR(m_data);
633 m_index_data_offset = vertexByteSize;
634 m_owns_data = true;
635 }
636
637 // If we have associated vbo data we could potentially crash later if
638 // the old buffers are used with the new vertex and index count, so we force
639 // an update in the renderer in that case. This is really the users responsibility
640 // but it is cheap for us to enforce this, so why not...
641 if (m_server_data) {
644 }
645
646}
647
655{
656 Point2D *v = g->vertexDataAsPoint2D();
657 v[0].x = rect.left();
658 v[0].y = rect.top();
659
660 v[1].x = rect.left();
661 v[1].y = rect.bottom();
662
663 v[2].x = rect.right();
664 v[2].y = rect.top();
665
666 v[3].x = rect.right();
667 v[3].y = rect.bottom();
668}
669
680{
681 TexturedPoint2D *v = g->vertexDataAsTexturedPoint2D();
682 v[0].x = rect.left();
683 v[0].y = rect.top();
684 v[0].tx = textureRect.left();
685 v[0].ty = textureRect.top();
686
687 v[1].x = rect.left();
688 v[1].y = rect.bottom();
689 v[1].tx = textureRect.left();
690 v[1].ty = textureRect.bottom();
691
692 v[2].x = rect.right();
693 v[2].y = rect.top();
694 v[2].tx = textureRect.right();
695 v[2].ty = textureRect.top();
696
697 v[3].x = rect.right();
698 v[3].y = rect.bottom();
699 v[3].tx = textureRect.right();
700 v[3].ty = textureRect.bottom();
701}
702
710{
711 ColoredPoint2D *v = g->vertexDataAsColoredPoint2D();
712 v[0].x = rect.left();
713 v[0].y = rect.top();
714
715 v[1].x = rect.left();
716 v[1].y = rect.bottom();
717
718 v[2].x = rect.right();
719 v[2].y = rect.top();
720
721 v[3].x = rect.right();
722 v[3].y = rect.bottom();
723}
724
783{
784 m_index_usage_pattern = p;
785}
786
787
788
789
807{
808 m_vertex_usage_pattern = p;
809}
810
811
812
813
823{
824 m_dirty_index_data = true;
825}
826
827
828
838{
839 m_dirty_vertex_data = true;
840}
841
842
\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
virtual ~QSGGeometry()
Destroys the geometry object and the vertex and index data it has allocated.
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
@ AlwaysUploadPattern
Definition qsggeometry.h:27
static const AttributeSet & defaultAttributes_Point2D()
Convenience function which returns attributes to be used for 2D solid color drawing.
static const AttributeSet & defaultAttributes_ColoredPoint2D()
Convenience function which returns attributes to be used for per vertex colored 2D drawing.
void setDrawingMode(unsigned int mode)
Sets the mode to be used for drawing this geometry.
static const AttributeSet & defaultAttributes_TexturedPoint2D()
Convenience function which returns attributes to be used for textured 2D drawing.
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
Updates the geometry g with the coordinates in rect and texture coordinates from textureRect.
static void updateRectGeometry(QSGGeometry *g, const QRectF &rect)
Updates the geometry g with the coordinates in rect.
AttributeType
This enum identifies several attribute types.
Definition qsggeometry.h:17
void markVertexDataDirty()
Mark that the vertices in this geometry has changed and must be uploaded again.
const Attribute * attributes() const
Returns an array with the attributes of this geometry.
void * indexData()
Returns a pointer to the raw index data of this geometry object.
int indexType() const
Returns the primitive type used for indices in this geometry object.
void allocate(int vertexCount, int indexCount=0)
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount ...
void setVertexDataPattern(DataPattern p)
Sets the usage pattern for vertices to p.
void setIndexDataPattern(DataPattern p)
Sets the usage pattern for indices to p.
int indexCount() const
Returns the number of indices in this geometry object.
void setLineWidth(float w)
Sets the line or point width to be used for this geometry to width.
void markIndexDataDirty()
Mark that the vertices in this geometry has changed and must be uploaded again.
QSGGeometry(const QSGGeometry::AttributeSet &attribs, int vertexCount, int indexCount=0, int indexType=UnsignedShortType)
Constructs a geometry object based on attributes.
static void updateColoredRectGeometry(QSGGeometry *g, const QRectF &rect)
Updates the geometry g with the coordinates in rect.
float lineWidth() const
Gets the current line or point width or to be used for this geometry.
int vertexCount() const
Returns the number of vertices in this geometry object.
rect
[4]
Combined button and popup list for selecting options.
static struct AttrInfo attrs[]
#define qFatal
Definition qlogging.h:168
GLsizei const GLfloat * v
[13]
GLenum mode
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei width
GLboolean GLboolean g
GLfloat GLfloat p
[1]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:50
unsigned short quint16
Definition qtypes.h:48
Q_CHECK_PTR(a=new int[80])
QObject::connect nullptr
The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry are built up.
Definition qsggeometry.h:73
The QSGGeometry::Attribute describes a single vertex attribute in a QSGGeometry.
Definition qsggeometry.h:58
static Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition=false)
Creates a new QSGGeometry::Attribute for attribute register pos with tupleSize.
static Attribute createWithAttributeType(int pos, int tupleSize, int primitiveType, AttributeType attributeType)
Creates a new QSGGeometry::Attribute for attribute register pos with tupleSize.
The QSGGeometry::ColoredPoint2D struct is a convenience struct for accessing 2D Points with a color.
Definition qsggeometry.h:92
The QSGGeometry::Point2D struct is a convenience struct for accessing 2D Points.
Definition qsggeometry.h:79
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture ...
Definition qsggeometry.h:85