PySide6.QtQuick.QSGGeometry¶
- class QSGGeometry¶
The
QSGGeometryclass provides low-level storage for graphics primitives in the Qt Quick Scene Graph . More_…Synopsis¶
Methods¶
def
__init__()def
allocate()def
attributeCount()def
attributes()def
drawingMode()def
indexCount()def
indexData()def
indexType()def
lineWidth()def
setDrawingMode()def
setLineWidth()def
sizeOfIndex()def
sizeOfVertex()def
vertexCount()def
vertexData()
Static functions¶
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
QSGGeometryclass 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 withsetDrawingMode().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
AttributeSetis used to describe how the vertex data is built up. The attribute set can only be specified on construction. TheQSGGeometryclass provides a few convenience attributes and attribute sets by default. ThedefaultAttributes_Point2D()function returns an attribute set to be used in normal solid color rectangles, while thedefaultAttributes_TexturedPoint2Dfunction returns attributes to be used for textured 2D geometry. The vertex data is internally stored as avoid *and is accessible with thevertexData()function. Convenience accessors for the common attribute sets are available withvertexDataAsPoint2D()andvertexDataAsTexturedPoint2D(). Vertex data is allocated by passing a vertex count to the constructor or by callingallocate()later.The
QSGGeometrycan 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
QSGGeometryis 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, theQSGGeometrysupports hinting to the renderer that a buffer should be uploaded using thesetVertexDataPattern()andsetIndexDataPattern()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
QSGGeometryNodeScene Graph - Custom Geometry- class AttributeType¶
This enum identifies several attribute types.
Constant
Description
QSGGeometry.AttributeType.UnknownAttribute
Don’t care
QSGGeometry.AttributeType.PositionAttribute
Position
QSGGeometry.AttributeType.ColorAttribute
Color
QSGGeometry.AttributeType.TexCoordAttribute
Texture coordinate
QSGGeometry.AttributeType.TexCoord1Attribute
Texture coordinate 1
QSGGeometry.AttributeType.TexCoord2Attribute
Texture coordinate 2
- class DataPattern¶
The DataPattern enum is used to specify the use pattern for the vertex and index data in a geometry object.
Constant
Description
QSGGeometry.DataPattern.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.DataPattern.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.DataPattern.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.DataPattern.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.
- class DrawingMode¶
(inherits
enum.IntEnum) Specifies the drawing mode, also called primitive topology.Note
Starting with Qt 6 the scene graph only exposes topologies that are supported across all the supported 3D graphics APIs. As a result, the values
DrawLineLoopandDrawTriangleFanare no longer supported at run time in Qt 6, even though the enum values themselves are still present.Constant
Description
QSGGeometry.DrawingMode.DrawPoints
QSGGeometry.DrawingMode.DrawLines
QSGGeometry.DrawingMode.DrawLineStrip
QSGGeometry.DrawingMode.DrawTriangles
QSGGeometry.DrawingMode.DrawTriangleStrip
- class Type¶
Specifies the component type in the vertex data.
Constant
Description
QSGGeometry.Type.ByteType
QSGGeometry.Type.UnsignedByteType
QSGGeometry.Type.ShortType
QSGGeometry.Type.UnsignedShortType
QSGGeometry.Type.IntType
QSGGeometry.Type.UnsignedIntType
QSGGeometry.Type.FloatType
QSGGeometry.Type.Bytes2Type
Added in Qt 5.14.
QSGGeometry.Type.Bytes3Type
Added in Qt 5.14.
QSGGeometry.Type.Bytes4Type
Added in Qt 5.14.
QSGGeometry.Type.DoubleType
Added in Qt 5.14.
- __init__(attribs, vertexCount[, indexCount=0[, indexType=QSGGeometry.Type.UnsignedShortType]])¶
- Parameters:
attribs –
AttributeSetvertexCount – int
indexCount – int
indexType – int
Constructs a geometry object based on
attributes.The object allocate space for
vertexCountvertices based on the accumulated size inattributesand forindexCount.The
indexTypecan beUnsignedShortTypeorUnsignedIntType. 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
DrawTriangleStripas the drawing mode.Note
attributesand theAttributeobjects referenced by it must stay valid for the entire lifetime of theQSGGeometry.QSGGeometrystores a reference toattributesand does not delete theAttributeobjects.- allocate(vertexCount[, indexCount=0])¶
- Parameters:
vertexCount – int
indexCount – int
Resizes the vertex and index data of this geometry object to fit
vertexCountvertices andindexCountindices.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.- attributeCount()¶
- Return type:
int
Returns the number of attributes in the attrbute set used by this geometry.
Returns an array with the attributes of this geometry. The size of the array is given with
attributeCount().- static defaultAttributes_ColoredPoint2D()¶
- Return type:
Convenience function which returns attributes to be used for per vertex colored 2D drawing.
- static defaultAttributes_Point2D()¶
- Return type:
Convenience function which returns attributes to be used for 2D solid color drawing.
- static defaultAttributes_TexturedPoint2D()¶
- Return type:
Convenience function which returns attributes to be used for textured 2D drawing.
- drawingMode()¶
- Return type:
int
Returns the drawing mode of this geometry.
The default value is
DrawTriangleStrip.See also
- indexCount()¶
- Return type:
int
Returns the number of indices in this geometry object.
- indexData()¶
- Return type:
void
Returns a pointer to the raw index data of this geometry object.
See also
- indexDataAsUInt()¶
- Return type:
uint
Convenience function to access the index data as an immutable array of 32-bit unsigned integers.
- indexDataAsUShort()¶
- Return type:
quint16
Convenience function to access the index data as an immutable array of 16-bit unsigned integers.
- indexDataPattern()¶
- Return type:
Returns the usage pattern for indices in this geometry. The default pattern is
AlwaysUploadPattern.See also
- indexType()¶
- Return type:
int
Returns the primitive type used for indices in this geometry object.
- 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
drawingModeisDrawLinesorDrawLineStrip. When supported, it also applies to point size when thedrawingModeisDrawPoints.The default value is
1.0Note
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.
- 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).
- 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).
- setDrawingMode(mode)¶
- Parameters:
mode – int
Sets the
modeto be used for drawing this geometry.The default value is
DrawTriangleStrip.See also
- 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 callmarkIndexDataDirty()after changing the index data, in addition to callingmarkDirty()withDirtyGeometry.See also
- 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 thedrawingModeisDrawLinesorDrawLineStrip. When supported, it also applies to point size when thedrawingModeisDrawPoints.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.
- setVertexDataAsPoint2D(points)¶
- Parameters:
points – .list of QSGGeometry.Point2D
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().
- 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 callmarkVertexDataDirty()after changing the vertex data, in addition to callingmarkDirty()withDirtyGeometry.See also
- sizeOfIndex()¶
- Return type:
int
Returns the byte size of the index type.
This value is either
2when the index type isUnsignedShortType, or4when the index type isUnsignedIntType.- sizeOfVertex()¶
- Return type:
int
Returns the size in bytes of one vertex.
This value comes from the attributes.
- static updateColoredRectGeometry(g, rect)¶
- Parameters:
g –
QSGGeometryrect –
QRectF
Updates the geometry
gwith the coordinates inrect.The function assumes the geometry object contains a single triangle strip of
ColoredPoint2Dvertices- static updateRectGeometry(g, rect)¶
- Parameters:
g –
QSGGeometryrect –
QRectF
Updates the geometry
gwith the coordinates inrect.The function assumes the geometry object contains a single triangle strip of
Point2Dvertices- static updateTexturedRectGeometry(g, rect, sourceRect)¶
- Parameters:
g –
QSGGeometryrect –
QRectFsourceRect –
QRectF
Updates the geometry
gwith the coordinates inrectand texture coordinates fromtextureRect.textureRectshould be in normalized coordinates.gis assumed to be a triangle strip of four vertices of typeTexturedPoint2D.- vertexCount()¶
- Return type:
int
Returns the number of vertices in this geometry object.
- vertexData()¶
- Return type:
void
Returns a pointer to the raw vertex data of this geometry object.
- vertexDataAsColoredPoint2D()¶
- Return type:
Convenience function to access the vertex data as an immutable array of
ColoredPoint2D.- vertexDataAsPoint2D()¶
- Return type:
PyObject*
Convenience function to access the vertex data as an immutable array of
Point2D.- vertexDataAsTexturedPoint2D()¶
- Return type:
Convenience function to access the vertex data as an immutable array of
TexturedPoint2D.- vertexDataPattern()¶
- Return type:
Returns the usage pattern for vertices in this geometry. The default pattern is
AlwaysUploadPattern.See also
- class TexturedPoint2D¶
Synopsis¶
Methods¶
def
set()
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¶
- PySide6.QtQuick.QSGGeometry.TexturedPoint2D.x¶
- PySide6.QtQuick.QSGGeometry.TexturedPoint2D.y¶
- PySide6.QtQuick.QSGGeometry.TexturedPoint2D.tx¶
- PySide6.QtQuick.QSGGeometry.TexturedPoint2D.ty¶
- set(nx, ny, ntx, nty)¶
- Parameters:
nx – float
ny – float
ntx – float
nty – float
Sets the position of the vertex to
xandyand the texture coordinate totxandty.
- class Point2D¶
Synopsis¶
Methods¶
def
set()
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¶
- PySide6.QtQuick.QSGGeometry.Point2D.x¶
- PySide6.QtQuick.QSGGeometry.Point2D.y¶
- set(nx, ny)¶
- Parameters:
nx – float
ny – float
Sets the x and y values of this point to
xandy.
- class ColoredPoint2D¶
Synopsis¶
Methods¶
def
set()
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¶
- PySide6.QtQuick.QSGGeometry.ColoredPoint2D.x¶
- PySide6.QtQuick.QSGGeometry.ColoredPoint2D.y¶
- PySide6.QtQuick.QSGGeometry.ColoredPoint2D.r¶
- PySide6.QtQuick.QSGGeometry.ColoredPoint2D.g¶
- PySide6.QtQuick.QSGGeometry.ColoredPoint2D.b¶
- PySide6.QtQuick.QSGGeometry.ColoredPoint2D.a¶
- set(nx, ny, nr, ng, nb, na)¶
- Parameters:
nx – float
ny – float
nr – int
ng – int
nb – int
na – int
Sets the position of the vertex to
xandyand the color tored,green,blue, andalpha.
- class Attribute¶
Synopsis¶
Static functions¶
def
create()
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¶
- PySide6.QtQuick.QSGGeometry.Attribute.position¶
- PySide6.QtQuick.QSGGeometry.Attribute.tupleSize¶
- PySide6.QtQuick.QSGGeometry.Attribute.type¶
- PySide6.QtQuick.QSGGeometry.Attribute.isVertexCoordinate¶
- PySide6.QtQuick.QSGGeometry.Attribute.attributeType¶
- PySide6.QtQuick.QSGGeometry.Attribute.reserved¶
- static create(pos, tupleSize, primitiveType[, isPosition=false])¶
- Parameters:
pos – int
tupleSize – int
primitiveType – int
isPosition – bool
- Return type:
Creates a new
Attributefor attribute registerposwithtupleSize. TheprimitiveTypecan be any of the supported types fromType, such asFloatTypeorUnsignedByteType.If the attribute describes the position for the vertex, the
isPositionhint should be set totrue. The scene graph renderer may use this information to perform optimizations.Use the create function to construct the attribute, rather than an initialization list, to ensure that all fields are initialized.
- static createWithAttributeType(pos, tupleSize, primitiveType, attributeType)¶
- Parameters:
pos – int
tupleSize – int
primitiveType – int
attributeType –
AttributeType
- Return type:
Creates a new
Attributefor attribute registerposwithtupleSize. TheprimitiveTypecan be any of the supported types fromType, such asFloatTypeorUnsignedByteType.attributeTypedescribes the intended use of the attribute.Use the create function to construct the attribute, rather than an initialization list, to ensure that all fields are initialized.
- class AttributeSet¶
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¶
- PySide6.QtQuick.QSGGeometry.AttributeSet.count¶
- PySide6.QtQuick.QSGGeometry.AttributeSet.stride¶
- PySide6.QtQuick.QSGGeometry.AttributeSet.attributes¶