Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Graph}. More...
#include <qsggeometry.h>
Classes | |
class | Attribute |
The QSGGeometry::Attribute describes a single vertex attribute in a QSGGeometry. More... | |
class | AttributeSet |
The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry are built up. More... | |
class | ColoredPoint2D |
The QSGGeometry::ColoredPoint2D struct is a convenience struct for accessing 2D Points with a color. More... | |
class | Point2D |
The QSGGeometry::Point2D struct is a convenience struct for accessing 2D Points. More... | |
class | TexturedPoint2D |
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture coordinates. More... | |
Public Types | |
enum | AttributeType { UnknownAttribute , PositionAttribute , ColorAttribute , TexCoordAttribute , TexCoord1Attribute , TexCoord2Attribute } |
This enum identifies several attribute types. More... | |
enum | DataPattern { AlwaysUploadPattern = 0 , StreamPattern = 1 , DynamicPattern = 2 , StaticPattern = 3 } |
The DataPattern enum is used to specify the use pattern for the vertex and index data in a geometry object. More... | |
enum | DrawingMode { DrawPoints = 0x0000 , DrawLines = 0x0001 , DrawLineLoop = 0x0002 , DrawLineStrip = 0x0003 , DrawTriangles = 0x0004 , DrawTriangleStrip = 0x0005 , DrawTriangleFan = 0x0006 } |
Specifies the drawing mode, also called primitive topology. More... | |
enum | Type { ByteType = 0x1400 , UnsignedByteType = 0x1401 , ShortType = 0x1402 , UnsignedShortType = 0x1403 , IntType = 0x1404 , UnsignedIntType = 0x1405 , FloatType = 0x1406 , Bytes2Type = 0x1407 , Bytes3Type = 0x1408 , Bytes4Type = 0x1409 , DoubleType = 0x140A } |
Specifies the component type in the vertex data. More... | |
Public Member Functions | |
QSGGeometry (const QSGGeometry::AttributeSet &attribs, int vertexCount, int indexCount=0, int indexType=UnsignedShortType) | |
Constructs a geometry object based on attributes. | |
virtual | ~QSGGeometry () |
Destroys the geometry object and the vertex and index data it has allocated. | |
void | setDrawingMode (unsigned int mode) |
Sets the mode to be used for drawing this geometry. | |
unsigned int | drawingMode () const |
Returns the drawing mode of this geometry. | |
void | allocate (int vertexCount, int indexCount=0) |
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount indices. | |
int | vertexCount () const |
Returns the number of vertices in this geometry object. | |
void * | vertexData () |
Returns a pointer to the raw vertex data of this geometry object. | |
Point2D * | vertexDataAsPoint2D () |
Convenience function to access the vertex data as a mutable array of QSGGeometry::Point2D. | |
TexturedPoint2D * | vertexDataAsTexturedPoint2D () |
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D. | |
ColoredPoint2D * | vertexDataAsColoredPoint2D () |
Convenience function to access the vertex data as a mutable array of QSGGeometry::ColoredPoint2D. | |
const void * | vertexData () const |
Returns a pointer to the raw vertex data of this geometry object. | |
const Point2D * | vertexDataAsPoint2D () const |
Convenience function to access the vertex data as an immutable array of QSGGeometry::Point2D. | |
const TexturedPoint2D * | vertexDataAsTexturedPoint2D () const |
Convenience function to access the vertex data as an immutable array of QSGGeometry::TexturedPoint2D. | |
const ColoredPoint2D * | vertexDataAsColoredPoint2D () const |
Convenience function to access the vertex data as an immutable array of QSGGeometry::ColoredPoint2D. | |
int | indexType () const |
Returns the primitive type used for indices in this geometry object. | |
int | indexCount () const |
Returns the number of indices in this geometry object. | |
void * | indexData () |
Returns a pointer to the raw index data of this geometry object. | |
uint * | indexDataAsUInt () |
Convenience function to access the index data as a mutable array of 32-bit unsigned integers. | |
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. | |
const void * | indexData () const |
Returns a pointer to the raw index data of this geometry object. | |
const uint * | indexDataAsUInt () const |
Convenience function to access the index data as an immutable array of 32-bit unsigned integers. | |
const quint16 * | indexDataAsUShort () const |
Convenience function to access the index data as an immutable array of 16-bit unsigned integers. | |
int | attributeCount () const |
Returns the number of attributes in the attrbute set used by this geometry. | |
const Attribute * | attributes () const |
Returns an array with the attributes of this geometry. | |
int | sizeOfVertex () const |
Returns the size in bytes of one vertex. | |
void | setIndexDataPattern (DataPattern p) |
Sets the usage pattern for indices to p. | |
DataPattern | indexDataPattern () const |
Returns the usage pattern for indices in this geometry. | |
void | setVertexDataPattern (DataPattern p) |
Sets the usage pattern for vertices to p. | |
DataPattern | vertexDataPattern () const |
Returns the usage pattern for vertices in this geometry. | |
void | markIndexDataDirty () |
Mark that the vertices in this geometry has changed and must be uploaded again. | |
void | markVertexDataDirty () |
Mark that the vertices in this geometry has changed and must be uploaded again. | |
float | lineWidth () const |
Gets the current line or point width or to be used for this geometry. | |
void | setLineWidth (float w) |
Sets the line or point width to be used for this geometry to width. | |
Static Public Member Functions | |
static const AttributeSet & | defaultAttributes_Point2D () |
Convenience function which returns attributes to be used for 2D solid color drawing. | |
static const AttributeSet & | defaultAttributes_TexturedPoint2D () |
Convenience function which returns attributes to be used for textured 2D drawing. | |
static const AttributeSet & | defaultAttributes_ColoredPoint2D () |
Convenience function which returns attributes to be used for per vertex colored 2D drawing. | |
static void | updateRectGeometry (QSGGeometry *g, const QRectF &rect) |
Updates the geometry g with the coordinates in rect. | |
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 | updateColoredRectGeometry (QSGGeometry *g, const QRectF &rect) |
Updates the geometry g with the coordinates in rect. | |
Friends | |
class | QSGGeometryData |
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Graph}.
\inmodule QtQuick
The QSGGeometry class stores the geometry of the primitives rendered with the scene graph. It contains vertex data and optionally index data. The mode used to draw the geometry, also called primitive topology, is specified with setDrawingMode().
Vertices can be as simple as points defined by x and y values or can be more complex where each vertex contains a normal, texture coordinates and a 3D position. The QSGGeometry::AttributeSet is used to describe how the vertex data is built up. The attribute set can only be specified on construction. The QSGGeometry class provides a few convenience attributes and attribute sets by default. The defaultAttributes_Point2D() function returns an attribute set to be used in normal solid color rectangles, while the defaultAttributes_TexturedPoint2D function returns attributes to be used for textured 2D geometry. The vertex data is internally stored as a {void
*} and is accessible with the vertexData() function. Convenience accessors for the common attribute sets are available with vertexDataAsPoint2D() and vertexDataAsTexturedPoint2D(). Vertex data is allocated by passing a vertex count to the constructor or by calling allocate() later.
The QSGGeometry can optionally contain indices of either unsigned 32-bit, unsigned 16-bit, or unsigned 8-bit integers. The index type must be specified during construction and cannot be changed.
Below is a snippet illustrating how a geometry composed of position and color vertices can be built.
The QSGGeometry is a software buffer and client-side in terms of accelerated rendering, as the buffers used in 2D graphics typically consist of many small buffers that change every frame and do not benefit from being uploaded to graphics memory. However, the QSGGeometry supports hinting to the renderer that a buffer should be uploaded using the setVertexDataPattern() and setIndexDataPattern() functions. Whether this hint is respected or not is implementation specific.
Definition at line 14 of file qsggeometry.h.
This enum identifies several attribute types.
\value UnknownAttribute Don't care \value PositionAttribute Position \value ColorAttribute Color \value TexCoordAttribute Texture coordinate \value TexCoord1Attribute Texture coordinate 1 \value TexCoord2Attribute Texture coordinate 2
Enumerator | |
---|---|
UnknownAttribute | |
PositionAttribute | |
ColorAttribute | |
TexCoordAttribute | |
TexCoord1Attribute | |
TexCoord2Attribute |
Definition at line 17 of file qsggeometry.h.
The DataPattern enum is used to specify the use pattern for the vertex and index data in a geometry object.
\value AlwaysUploadPattern The data is always uploaded. This means that the user does not need to explicitly mark index and vertex data as dirty after changing it. This is the default.
\value DynamicPattern The data is modified repeatedly and drawn many times. This is a hint that may provide better performance. When set the user must make sure to mark the data as dirty after changing it.
\value StaticPattern The data is modified once and drawn many times. This is a hint that may provide better performance. When set the user must make sure to mark the data as dirty after changing it.
\value StreamPattern The data is modified for almost every time it is drawn. This is a hint that may provide better performance. When set, the user must make sure to mark the data as dirty after changing it.
Enumerator | |
---|---|
AlwaysUploadPattern | |
StreamPattern | |
DynamicPattern | |
StaticPattern |
Definition at line 26 of file qsggeometry.h.
Specifies the drawing mode, also called primitive topology.
DrawLineLoop
and DrawTriangleFan
are no longer supported at run time in Qt 6, even though the enum values themselves are still present.\value DrawPoints \value DrawLines \omitvalue DrawLineLoop \value DrawLineStrip \value DrawTriangles \value DrawTriangleStrip \omitvalue DrawTriangleFan
Enumerator | |
---|---|
DrawPoints | |
DrawLines | |
DrawLineLoop | |
DrawLineStrip | |
DrawTriangles | |
DrawTriangleStrip | |
DrawTriangleFan |
Definition at line 33 of file qsggeometry.h.
enum QSGGeometry::Type |
Specifies the component type in the vertex data.
\value ByteType \value UnsignedByteType \value ShortType \value UnsignedShortType \value IntType \value UnsignedIntType \value FloatType \value Bytes2Type Added in Qt 5.14. \value Bytes3Type Added in Qt 5.14. \value Bytes4Type Added in Qt 5.14. \value DoubleType Added in Qt 5.14.
Enumerator | |
---|---|
ByteType | |
UnsignedByteType | |
ShortType | |
UnsignedShortType | |
IntType | |
UnsignedIntType | |
FloatType | |
Bytes2Type | |
Bytes3Type | |
Bytes4Type | |
DoubleType |
Definition at line 43 of file qsggeometry.h.
QSGGeometry::QSGGeometry | ( | const QSGGeometry::AttributeSet & | attributes, |
int | vertexCount, | ||
int | indexCount = 0, | ||
int | indexType = UnsignedShortType ) |
Constructs a geometry object based on attributes.
The object allocate space for vertexCount vertices based on the accumulated size in attributes and for indexCount.
The indexType can be UnsignedShortType or UnsignedIntType
. Support for the latter depends on the graphics API implementation used at run time, and may not always be available.
Geometry objects are constructed by default with DrawTriangleStrip as the drawing mode.
Definition at line 379 of file qsggeometry.cpp.
|
virtual |
Destroys the geometry object and the vertex and index data it has allocated.
Definition at line 431 of file qsggeometry.cpp.
void QSGGeometry::allocate | ( | int | vertexCount, |
int | indexCount = 0 ) |
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount indices.
Vertex and index data will be invalidated after this call and the caller must mark the associated geometry node as dirty, by calling node->markDirty(QSGNode::DirtyGeometry) to ensure that the renderer has a chance to update internal buffers.
Definition at line 610 of file qsggeometry.cpp.
|
inline |
Returns the number of attributes in the attrbute set used by this geometry.
Definition at line 146 of file qsggeometry.h.
|
inline |
Returns an array with the attributes of this geometry.
The size of the array is given with attributeCount().
Definition at line 147 of file qsggeometry.h.
|
static |
Convenience function which returns attributes to be used for per vertex colored 2D drawing.
Definition at line 64 of file qsggeometry.cpp.
|
static |
Convenience function which returns attributes to be used for 2D solid color drawing.
Definition at line 37 of file qsggeometry.cpp.
|
static |
Convenience function which returns attributes to be used for textured 2D drawing.
Definition at line 50 of file qsggeometry.cpp.
|
inline |
Returns the drawing mode of this geometry.
The default value is DrawTriangleStrip.
Definition at line 116 of file qsggeometry.h.
|
inline |
Returns the number of indices in this geometry object.
Definition at line 134 of file qsggeometry.h.
void * QSGGeometry::indexData | ( | ) |
Returns a pointer to the raw index data of this geometry object.
Definition at line 475 of file qsggeometry.cpp.
const void * QSGGeometry::indexData | ( | ) | const |
Returns a pointer to the raw index data of this geometry object.
Definition at line 487 of file qsggeometry.cpp.
|
inline |
Convenience function to access the index data as a mutable array of 32-bit unsigned integers.
Definition at line 192 of file qsggeometry.h.
|
inline |
Convenience function to access the index data as an immutable array of 32-bit unsigned integers.
Definition at line 204 of file qsggeometry.h.
|
inline |
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
Definition at line 198 of file qsggeometry.h.
|
inline |
Convenience function to access the index data as an immutable array of 16-bit unsigned integers.
Definition at line 210 of file qsggeometry.h.
|
inline |
Returns the usage pattern for indices in this geometry.
The default pattern is AlwaysUploadPattern.
Definition at line 155 of file qsggeometry.h.
|
inline |
Returns the primitive type used for indices in this geometry object.
Definition at line 132 of file qsggeometry.h.
float QSGGeometry::lineWidth | ( | ) | const |
Gets the current line or point width or to be used for this geometry.
This property only applies to line width when the drawingMode is DrawLines or DrawLineStrip. When supported, it also applies to point size when the drawingMode is DrawPoints.
The default value is 1.0
1.0
is always supported.Definition at line 560 of file qsggeometry.cpp.
void QSGGeometry::markIndexDataDirty | ( | ) |
Mark that the vertices in this geometry has changed and must be uploaded again.
This function only has an effect when the usage pattern for vertices is StaticData and the renderer that renders this geometry uploads the geometry into Vertex Buffer Objects (VBOs).
Definition at line 822 of file qsggeometry.cpp.
void QSGGeometry::markVertexDataDirty | ( | ) |
Mark that the vertices in this geometry has changed and must be uploaded again.
This function only has an effect when the usage pattern for vertices is StaticData and the renderer that renders this geometry uploads the geometry into Vertex Buffer Objects (VBOs).
Definition at line 837 of file qsggeometry.cpp.
void QSGGeometry::setDrawingMode | ( | unsigned int | mode | ) |
Sets the mode to be used for drawing this geometry.
The default value is QSGGeometry::DrawTriangleStrip.
Definition at line 538 of file qsggeometry.cpp.
void QSGGeometry::setIndexDataPattern | ( | DataPattern | p | ) |
Sets the usage pattern for indices to p.
The default is AlwaysUploadPattern. When set to anything other than the default, the user must call markIndexDataDirty() after changing the index data, in addition to calling QSGNode::markDirty() with QSGNode::DirtyGeometry.
Definition at line 782 of file qsggeometry.cpp.
void QSGGeometry::setLineWidth | ( | float | width | ) |
Sets the line or point width to be used for this geometry to width.
This property only applies to line width when the drawingMode is DrawLines or DrawLineStrip. When supported, it also applies to point size when the drawingMode is DrawPoints.
1.0
is always supported.Definition at line 580 of file qsggeometry.cpp.
void QSGGeometry::setVertexDataPattern | ( | DataPattern | p | ) |
Sets the usage pattern for vertices to p.
The default is AlwaysUploadPattern. When set to anything other than the default, the user must call markVertexDataDirty() after changing the vertex data, in addition to calling QSGNode::markDirty() with QSGNode::DirtyGeometry.
Definition at line 806 of file qsggeometry.cpp.
|
inline |
Returns the byte size of the index type.
This value is either 2
when the index type is UnsignedShortType, or 4
when the index type is UnsignedIntType.
Definition at line 288 of file qsggeometry.h.
|
inline |
Returns the size in bytes of one vertex.
This value comes from the attributes.
Definition at line 148 of file qsggeometry.h.
|
static |
Updates the geometry g with the coordinates in rect.
The function assumes the geometry object contains a single triangle strip of QSGGeometry::ColoredPoint2D vertices
Definition at line 709 of file qsggeometry.cpp.
|
static |
Updates the geometry g with the coordinates in rect.
The function assumes the geometry object contains a single triangle strip of QSGGeometry::Point2D vertices
Definition at line 654 of file qsggeometry.cpp.
|
static |
Updates the geometry g with the coordinates in rect and texture coordinates from textureRect.
textureRect should be in normalized coordinates.
g is assumed to be a triangle strip of four vertices of type QSGGeometry::TexturedPoint2D.
Definition at line 679 of file qsggeometry.cpp.
|
inline |
Returns the number of vertices in this geometry object.
Definition at line 120 of file qsggeometry.h.
|
inline |
Returns a pointer to the raw vertex data of this geometry object.
Definition at line 122 of file qsggeometry.h.
|
inline |
Returns a pointer to the raw vertex data of this geometry object.
Definition at line 127 of file qsggeometry.h.
|
inline |
Convenience function to access the vertex data as a mutable array of QSGGeometry::ColoredPoint2D.
Definition at line 239 of file qsggeometry.h.
|
inline |
Convenience function to access the vertex data as an immutable array of QSGGeometry::ColoredPoint2D.
Definition at line 275 of file qsggeometry.h.
|
inline |
Convenience function to access the vertex data as a mutable array of QSGGeometry::Point2D.
Definition at line 216 of file qsggeometry.h.
|
inline |
Convenience function to access the vertex data as an immutable array of QSGGeometry::Point2D.
Definition at line 252 of file qsggeometry.h.
|
inline |
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D.
Definition at line 226 of file qsggeometry.h.
|
inline |
Convenience function to access the vertex data as an immutable array of QSGGeometry::TexturedPoint2D.
Definition at line 262 of file qsggeometry.h.
|
inline |
Returns the usage pattern for vertices in this geometry.
The default pattern is AlwaysUploadPattern.
Definition at line 158 of file qsggeometry.h.
|
friend |
Definition at line 168 of file qsggeometry.h.