QSGGeometry#
The QSGGeometry
class provides low-level storage for graphics primitives in the Qt Quick Scene Graph . More…
Synopsis#
Functions#
def
allocate
(vertexCount[, indexCount=0])def
attributeCount
()def
attributes
()def
drawingMode
()def
indexCount
()def
indexData
()def
indexDataAsUInt
()def
indexDataAsUShort
()def
indexDataPattern
()def
indexType
()def
lineWidth
()def
markIndexDataDirty
()def
markVertexDataDirty
()def
setDrawingMode
(mode)def
setIndexDataPattern
(p)def
setLineWidth
(w)def
setVertexDataAsPoint2D
(points)def
setVertexDataPattern
(p)def
sizeOfIndex
()def
sizeOfVertex
()def
vertexCount
()def
vertexData
()def
vertexDataAsColoredPoint2D
()def
vertexDataAsPoint2D
()def
vertexDataAsTexturedPoint2D
()def
vertexDataPattern
()
Static functions#
def
defaultAttributes_Point2D
()def
updateColoredRectGeometry
(g, rect)def
updateRectGeometry
(g, rect)def
updateTexturedRectGeometry
(g, rect, sourceRect)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
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 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.
struct MyPoint2D { float x; float y; float r; float g; float b; float a; void set(float x_, float y_, float r_, float g_, float b_, float a_) { x = x_; y = y_; r = r_; g = g_; b = b_; a = a_; } }; QSGGeometry::Attribute MyPoint2D_Attributes[] = { QSGGeometry::Attribute::create(0, 2, FloatType, true), QSGGeometry::Attribute::create(1, 4, FloatType, false) }; QSGGeometry::AttributeSet MyPoint2D_AttributeSet = { 2, sizeof(MyPoint2D), MyPoint2D_Attributes }; ... geometry = new QSGGeometry(MyPoint2D_AttributeSet, 2); geometry->setDrawingMode(DrawLines); MyPoint2D *vertices = static_cast<MyPoint2D *>(geometry->vertexData()); vertices[0].set(0, 0, 1, 0, 0, 1); vertices[1].set(width(), height(), 0, 0, 1, 1);
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.
Note
All classes with QSG prefix should be used solely on the scene graph’s rendering thread. See Scene Graph and Rendering for more information.
See also
QSGGeometryNode
Scene Graph - Custom Geometry
- class PySide6.QtQuick.QSGGeometry(attribs, vertexCount[, indexCount=0[, indexType=QSGGeometry.Type.UnsignedShortType]])#
- Parameters:
indexCount – int
indexType – int
vertexCount – int
attribs –
PySide6.QtQuick.QSGGeometry.AttributeSet
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.
Note
attributes
and the Attribute
objects referenced by it must stay valid for the entire lifetime of the QSGGeometry
. QSGGeometry
stores a reference to attributes
and does not delete the Attribute
objects.
- PySide6.QtQuick.QSGGeometry.AttributeType#
This enum identifies several attribute types.
Constant
Description
QSGGeometry.UnknownAttribute
Don’t care
QSGGeometry.PositionAttribute
Position
QSGGeometry.ColorAttribute
Color
QSGGeometry.TexCoordAttribute
Texture coordinate
QSGGeometry.TexCoord1Attribute
Texture coordinate 1
QSGGeometry.TexCoord2Attribute
Texture coordinate 2
- PySide6.QtQuick.QSGGeometry.DataPattern#
The DataPattern enum is used to specify the use pattern for the vertex and index data in a geometry object.
Constant
Description
QSGGeometry.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.
QSGGeometry.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.
QSGGeometry.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.
QSGGeometry.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.
- PySide6.QtQuick.QSGGeometry.DrawingMode#
(inherits enum.IntEnum
) Specifies the drawing mode, also called primitive topology.
Constant
Description
QSGGeometry.DrawPoints
QSGGeometry.DrawLines
QSGGeometry.DrawLineLoop
QSGGeometry.DrawLineStrip
QSGGeometry.DrawTriangles
QSGGeometry.DrawTriangleStrip
QSGGeometry.DrawTriangleFan
- PySide6.QtQuick.QSGGeometry.Type#
Specifies the component type in the vertex data.
Constant
Description
QSGGeometry.ByteType
QSGGeometry.UnsignedByteType
QSGGeometry.ShortType
QSGGeometry.UnsignedShortType
QSGGeometry.IntType
QSGGeometry.UnsignedIntType
QSGGeometry.FloatType
QSGGeometry.Bytes2Type
Added in Qt 5.14.
QSGGeometry.Bytes3Type
Added in Qt 5.14.
QSGGeometry.Bytes4Type
Added in Qt 5.14.
QSGGeometry.DoubleType
Added in Qt 5.14.
- PySide6.QtQuick.QSGGeometry.allocate(vertexCount[, indexCount=0])#
- Parameters:
vertexCount – int
indexCount – int
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( DirtyGeometry
) to ensure that the renderer has a chance to update internal buffers.
- PySide6.QtQuick.QSGGeometry.attributeCount()#
- Return type:
int
Returns the number of attributes in the attrbute set used by this geometry.
- PySide6.QtQuick.QSGGeometry.attributes()#
- Return type:
Returns an array with the attributes of this geometry. The size of the array is given with attributeCount()
.
- static PySide6.QtQuick.QSGGeometry.defaultAttributes_ColoredPoint2D()#
- Return type:
Convenience function which returns attributes to be used for per vertex colored 2D drawing.
- static PySide6.QtQuick.QSGGeometry.defaultAttributes_Point2D()#
- Return type:
Convenience function which returns attributes to be used for 2D solid color drawing.
- static PySide6.QtQuick.QSGGeometry.defaultAttributes_TexturedPoint2D()#
- Return type:
Convenience function which returns attributes to be used for textured 2D drawing.
- PySide6.QtQuick.QSGGeometry.drawingMode()#
- Return type:
int
Returns the drawing mode of this geometry.
The default value is DrawTriangleStrip
.
See also
- PySide6.QtQuick.QSGGeometry.indexCount()#
- Return type:
int
Returns the number of indices in this geometry object.
- PySide6.QtQuick.QSGGeometry.indexData()#
- Return type:
void
Returns a pointer to the raw index data of this geometry object.
See also
- PySide6.QtQuick.QSGGeometry.indexDataAsUInt()#
- Return type:
uint
Convenience function to access the index data as an immutable array of 32-bit unsigned integers.
- PySide6.QtQuick.QSGGeometry.indexDataAsUShort()#
- Return type:
quint16
Convenience function to access the index data as an immutable array of 16-bit unsigned integers.
- PySide6.QtQuick.QSGGeometry.indexDataPattern()#
- Return type:
Returns the usage pattern for indices in this geometry. The default pattern is AlwaysUploadPattern
.
See also
- PySide6.QtQuick.QSGGeometry.indexType()#
- Return type:
int
Returns the primitive type used for indices in this geometry object.
- PySide6.QtQuick.QSGGeometry.lineWidth()#
- Return type:
float
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
, DarwLineStrip, or DrawLineLoop
. When supported, it also applies to point size when the drawingMode
is DrawPoints
.
The default value is 1.0
Note
Support for point and line drawing may be limited at run time, depending on the platform and graphics API. For example, some APIs do not support point sprites and so setting a size other than 1 is not possible.
- PySide6.QtQuick.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).
- PySide6.QtQuick.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).
- PySide6.QtQuick.QSGGeometry.setDrawingMode(mode)#
- Parameters:
mode – int
Sets the mode
to be used for drawing this geometry.
The default value is DrawTriangleStrip
.
See also
drawingMode()
DrawingMode
- PySide6.QtQuick.QSGGeometry.setIndexDataPattern(p)#
- Parameters:
p –
DataPattern
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 markDirty()
with DirtyGeometry
.
See also
- PySide6.QtQuick.QSGGeometry.setLineWidth(w)#
- Parameters:
w – float
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
, DrawLineStrip
, or DrawLineLoop
. When supported, it also applies to point size when the drawingMode
is DrawPoints
.
Note
Support for point and line drawing may be limited at run time, depending on the platform and graphics API. For example, some APIs do not support point sprites and so setting a size other than 1 is not possible.
- PySide6.QtQuick.QSGGeometry.setVertexDataAsPoint2D(points)#
- Parameters:
points –
Sets the vertex data from a list of QSGGeometry.Point2D. The list size must match the allocated number of vertexes as returned by QSGGeometry.vertexCount().
- PySide6.QtQuick.QSGGeometry.setVertexDataPattern(p)#
- Parameters:
p –
DataPattern
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 markDirty()
with DirtyGeometry
.
See also
- PySide6.QtQuick.QSGGeometry.sizeOfIndex()#
- Return type:
int
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
.
- PySide6.QtQuick.QSGGeometry.sizeOfVertex()#
- Return type:
int
Returns the size in bytes of one vertex.
This value comes from the attributes.
- static PySide6.QtQuick.QSGGeometry.updateColoredRectGeometry(g, rect)#
- Parameters:
rect –
PySide6.QtCore.QRectF
Updates the geometry g
with the coordinates in rect
.
The function assumes the geometry object contains a single triangle strip of ColoredPoint2D
vertices
- static PySide6.QtQuick.QSGGeometry.updateRectGeometry(g, rect)#
- Parameters:
rect –
PySide6.QtCore.QRectF
Updates the geometry g
with the coordinates in rect
.
The function assumes the geometry object contains a single triangle strip of Point2D
vertices
- static PySide6.QtQuick.QSGGeometry.updateTexturedRectGeometry(g, rect, sourceRect)#
- Parameters:
rect –
PySide6.QtCore.QRectF
sourceRect –
PySide6.QtCore.QRectF
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 TexturedPoint2D
.
- PySide6.QtQuick.QSGGeometry.vertexCount()#
- Return type:
int
Returns the number of vertices in this geometry object.
- PySide6.QtQuick.QSGGeometry.vertexData()#
- Return type:
void
Returns a pointer to the raw vertex data of this geometry object.
- PySide6.QtQuick.QSGGeometry.vertexDataAsColoredPoint2D()#
- Return type:
Convenience function to access the vertex data as an immutable array of ColoredPoint2D
.
- PySide6.QtQuick.QSGGeometry.vertexDataAsPoint2D()#
- Return type:
PyObject*
Convenience function to access the vertex data as an immutable array of Point2D
.
- PySide6.QtQuick.QSGGeometry.vertexDataAsTexturedPoint2D()#
- Return type:
Convenience function to access the vertex data as an immutable array of TexturedPoint2D
.
- PySide6.QtQuick.QSGGeometry.vertexDataPattern()#
- Return type:
Returns the usage pattern for vertices in this geometry. The default pattern is AlwaysUploadPattern
.
See also