The QSGGeometry class provides low-level storage for graphics primitives in the Qt Quick 场景图形 . 更多...
头: | #include <QSGGeometry> |
qmake: | QT += quick |
class | Attribute |
class | AttributeSet |
class | ColoredPoint2D |
class | Point2D |
class | TexturedPoint2D |
enum | AttributeType { UnknownAttribute, PositionAttribute, ColorAttribute, TexCoordAttribute, TexCoord1Attribute, TexCoord2Attribute } |
enum | DataPattern { AlwaysUploadPattern, DynamicPattern, StaticPattern, StreamPattern } |
enum | DrawingMode { DrawPoints, DrawLines, DrawLineLoop, DrawLineStrip, ..., DrawTriangleFan } |
enum | Type { ByteType, UnsignedByteType, ShortType, UnsignedShortType, ..., FloatType } |
QSGGeometry (const QSGGeometry::AttributeSet & 属性 , int vertexCount , int indexCount = 0, int indexType = UnsignedShortType) | |
virtual | ~QSGGeometry () |
void | allocate (int vertexCount , int indexCount = 0) |
int | attributeCount () const |
const QSGGeometry::Attribute * | 属性 () const |
无符号 int | drawingMode () const |
int | indexCount () const |
void * | indexData () |
const void * | indexData () const |
uint * | indexDataAsUInt () |
const uint * | indexDataAsUInt () const |
quint16 * | indexDataAsUShort () |
const quint16 * | indexDataAsUShort () const |
QSGGeometry::DataPattern | indexDataPattern () const |
int | indexType () const |
float | lineWidth () const |
void | markIndexDataDirty () |
void | markVertexDataDirty () |
void | setDrawingMode (unsigned int mode ) |
void | setIndexDataPattern (QSGGeometry::DataPattern p ) |
void | setLineWidth (float width ) |
void | setVertexDataPattern (QSGGeometry::DataPattern p ) |
int | sizeOfIndex () const |
int | sizeOfVertex () const |
int | vertexCount () const |
void * | vertexData () |
const void * | vertexData () const |
QSGGeometry::ColoredPoint2D * | vertexDataAsColoredPoint2D () |
const QSGGeometry::ColoredPoint2D * | vertexDataAsColoredPoint2D () const |
QSGGeometry::Point2D * | vertexDataAsPoint2D () |
const QSGGeometry::Point2D * | vertexDataAsPoint2D () const |
QSGGeometry::TexturedPoint2D * | vertexDataAsTexturedPoint2D () |
const QSGGeometry::TexturedPoint2D * | vertexDataAsTexturedPoint2D () const |
QSGGeometry::DataPattern | vertexDataPattern () const |
const QSGGeometry::AttributeSet & | defaultAttributes_ColoredPoint2D () |
const QSGGeometry::AttributeSet & | defaultAttributes_Point2D () |
const QSGGeometry::AttributeSet & | defaultAttributes_TexturedPoint2D () |
void | updateColoredRectGeometry (QSGGeometry * g , const QRectF & rect ) |
void | updateRectGeometry (QSGGeometry * g , const QRectF & rect ) |
void | updateTexturedRectGeometry (QSGGeometry * g , const QRectF & rect , const QRectF & textureRect ) |
The QSGGeometry class provides low-level storage for graphics primitives in the Qt Quick 场景图形 .
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 is specified with
setDrawingMode
(), which maps directly to the graphics API's drawing mode, such as
GL_TRIANGLE_STRIP
,
GL_TRIANGLES
,或
GL_POINTS
in case of OpenGL.
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
() 和
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, GL_FLOAT, true), QSGGeometry::Attribute::create(1, 4, GL_FLOAT, false) }; QSGGeometry::AttributeSet MyPoint2D_AttributeSet = { 2, sizeof(MyPoint2D), MyPoint2D_Attributes }; ... geometry = new QSGGeometry(MyPoint2D_AttributeSet, 2); geometry->setDrawingMode(GL_LINES); 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 OpenGL 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 () 和 setIndexDataPattern () functions. Whether this hint is respected or not is implementation specific.
注意: 所有带有 QSG 前缀的类只应用于场景图形渲染线程。见 场景图形和渲染 了解更多信息。
另请参阅 QSGGeometryNode and 场景图形 - 自定义几何图形 .
This enum identifies several attribute types.
常量 | 值 | 描述 |
---|---|---|
QSGGeometry::UnknownAttribute
|
0
|
Don't care |
QSGGeometry::PositionAttribute
|
1
|
Position |
QSGGeometry::ColorAttribute
|
2
|
颜色 |
QSGGeometry::TexCoordAttribute
|
3
|
Texture coordinate |
QSGGeometry::TexCoord1Attribute
|
4
|
Texture coordinate 1 |
QSGGeometry::TexCoord2Attribute
|
5
|
Texture coordinate 2 |
The DataPattern enum is used to specify the use pattern for the vertex and index data in a geometry object.
常量 | 值 | 描述 |
---|---|---|
QSGGeometry::AlwaysUploadPattern
|
0
|
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
|
2
|
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
|
3
|
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
|
1
|
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. |
The values correspond to OpenGL enum values like
GL_POINTS
,
GL_LINES
,等。
QSGGeometry
provies its own type in order to be able to provide the same API with non-OpenGL backends as well.
常量 | 值 |
---|---|
QSGGeometry::DrawPoints
|
0x0000
|
QSGGeometry::DrawLines
|
0x0001
|
QSGGeometry::DrawLineLoop
|
0x0002
|
QSGGeometry::DrawLineStrip
|
0x0003
|
QSGGeometry::DrawTriangles
|
0x0004
|
QSGGeometry::DrawTriangleStrip
|
0x0005
|
QSGGeometry::DrawTriangleFan
|
0x0006
|
The values correspond to OpenGL type constants like
GL_BYTE
,
GL_UNSIGNED_BYTE
,等。
QSGGeometry
provies its own type in order to be able to provide the same API with non-OpenGL backends as well.
常量 | 值 |
---|---|
QSGGeometry::ByteType
|
0x1400
|
QSGGeometry::UnsignedByteType
|
0x1401
|
QSGGeometry::ShortType
|
0x1402
|
QSGGeometry::UnsignedShortType
|
0x1403
|
QSGGeometry::IntType
|
0x1404
|
QSGGeometry::UnsignedIntType
|
0x1405
|
QSGGeometry::FloatType
|
0x1406
|
Constructs a geometry object based on 属性 .
The object allocate space for vertexCount vertices based on the accumulated size in 属性 和对于 indexCount .
The
indexType
maps to the OpenGL index type and can be
GL_UNSIGNED_SHORT
and
GL_UNSIGNED_BYTE
. On OpenGL implementations that support it, such as desktop OpenGL,
GL_UNSIGNED_INT
can also be used.
Geometry objects are constructed with
GL_TRIANGLE_STRIP
as default drawing mode.
The attribute structure is assumed to be POD and the geometry object assumes this will not go away. There is no memory management involved.
[虚拟]
QSGGeometry::
~QSGGeometry
()
Destroys the geometry object and the vertex and index data it has allocated.
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.
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]
const
QSGGeometry::AttributeSet
&QSGGeometry::
defaultAttributes_ColoredPoint2D
()
Convenience function which returns attributes to be used for per vertex colored 2D drawing.
[static]
const
QSGGeometry::AttributeSet
&QSGGeometry::
defaultAttributes_Point2D
()
Convenience function which returns attributes to be used for 2D solid color drawing.
[static]
const
QSGGeometry::AttributeSet
&QSGGeometry::
defaultAttributes_TexturedPoint2D
()
Convenience function which returns attributes to be used for textured 2D drawing.
Returns the drawing mode of this geometry.
默认值为
GL_TRIANGLE_STRIP
.
另请参阅 setDrawingMode ().
Returns the number of indices in this geometry object.
Returns a pointer to the raw index data of this geometry object.
另请参阅 indexDataAsUShort () 和 indexDataAsUInt ().
Returns a pointer to the raw index data of this geometry object.
另请参阅 indexDataAsUShort () 和 indexDataAsUInt ().
Convenience function to access the index data as a mutable array of 32-bit unsigned integers.
Convenience function to access the index data as an immutable array of 32-bit unsigned integers.
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
Convenience function to access the index data as an immutable array of 16-bit unsigned integers.
Returns the usage pattern for indices in this geometry. The default pattern is AlwaysUploadPattern .
另请参阅 setIndexDataPattern ().
Returns the primitive type used for indices in this geometry object.
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 . For desktop OpenGL, it also applies to point size when the drawingMode is DrawPoints .
默认值为
1.0
注意: When not using OpenGL, support for point and line drawing may be limited. For example, some APIs do not support point sprites and so setting a size other than 1 is not possible. Some backends may be able implement support via geometry shaders, but this is not guaranteed to be always available.
另请参阅 setLineWidth () 和 drawingMode ().
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).
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).
设置 mode to be used for drawing this geometry.
默认值为 QSGGeometry::DrawTriangleStrip .
另请参阅 drawingMode () 和 DrawingMode .
Sets the usage pattern for indices to p .
默认为 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 () 采用 QSGNode::DirtyGeometry .
另请参阅 indexDataPattern ().
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 ,或 DrawLineLoop . For Desktop OpenGL, it also applies to point size when the drawingMode is DrawPoints .
注意: How line width and point size are treated is implementation dependent: The application should not rely on these, but rather create triangles or similar to draw areas. On OpenGL ES, line width support is limited and point size is unsupported.
另请参阅 lineWidth () 和 drawingMode ().
Sets the usage pattern for vertices to p .
默认为 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 () 采用 QSGNode::DirtyGeometry .
另请参阅 vertexDataPattern ().
Returns the byte size of the index type.
This value is either
1
when index type is
GL_UNSIGNED_BYTE
or
2
when index type is
GL_UNSIGNED_SHORT
. For Desktop OpenGL,
GL_UNSIGNED_INT
采用值
4
is also supported.
Returns the size in bytes of one vertex.
This value comes from the attributes.
[static]
void
QSGGeometry::
updateColoredRectGeometry
(
QSGGeometry
*
g
, const
QRectF
&
rect
)
Updates the geometry g with the coordinates in rect .
The function assumes the geometry object contains a single triangle strip of QSGGeometry::ColoredPoint2D vertices
[static]
void
QSGGeometry::
updateRectGeometry
(
QSGGeometry
*
g
, const
QRectF
&
rect
)
Updates the geometry g with the coordinates in rect .
The function assumes the geometry object contains a single triangle strip of QSGGeometry::Point2D vertices
[static]
void
QSGGeometry::
updateTexturedRectGeometry
(
QSGGeometry
*
g
, const
QRectF
&
rect
, const
QRectF
&
textureRect
)
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 .
Returns the number of vertices in this geometry object.
Returns a pointer to the raw vertex data of this geometry object.
另请参阅 vertexDataAsPoint2D () 和 vertexDataAsTexturedPoint2D ().
Returns a pointer to the raw vertex data of this geometry object.
另请参阅 vertexDataAsPoint2D () 和 vertexDataAsTexturedPoint2D ().
Convenience function to access the vertex data as a mutable array of QSGGeometry::ColoredPoint2D .
Convenience function to access the vertex data as an immutable array of QSGGeometry::ColoredPoint2D .
Convenience function to access the vertex data as a mutable array of QSGGeometry::Point2D .
Convenience function to access the vertex data as an immutable array of QSGGeometry::Point2D .
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D .
Convenience function to access the vertex data as an immutable array of QSGGeometry::TexturedPoint2D .
Returns the usage pattern for vertices in this geometry. The default pattern is AlwaysUploadPattern .
另请参阅 setVertexDataPattern ().