PySide6.QtQuick.QSGGeometry¶
- class QSGGeometry¶
QSGGeometry类为 Qt Quick Scene Graph 中的图形原语提供低级存储。More_…概要¶
方法¶
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()
静态函数¶
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
QSGGeometry类存储了使用场景图渲染的图元的几何信息。它包含顶点数据以及可选的索引数据。用于绘制几何图形的模式,也称为图元拓扑,通过setDrawingMode()指定。顶点可以简单到由x和y值定义的点,也可以更复杂,每个顶点包含法线、纹理坐标和3D位置。
AttributeSet用于描述顶点数据的构建方式。属性集只能在构造时指定。QSGGeometry类默认提供了一些方便的属性和属性集。defaultAttributes_Point2D()函数返回用于普通纯色矩形的属性集,而defaultAttributes_TexturedPoint2D函数返回用于带纹理的2D几何体的属性。顶点数据在内部存储为void *,可以通过vertexData()函数访问。常见的属性集的便捷访问器可通过vertexDataAsPoint2D()和vertexDataAsTexturedPoint2D()获得。顶点数据通过将顶点计数传递给构造函数或稍后调用allocate()来分配。QSGGeometry可以选择性地包含无符号32位、无符号16位或无符号8位整数的索引。索引类型必须在构造时指定,并且不能更改。下面是一个片段,展示了如何构建由位置和颜色顶点组成的几何体。
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);
QSGGeometry是一个软件缓冲区和客户端加速渲染的一部分,因为2D图形中使用的缓冲区通常由许多每帧都会变化的小缓冲区组成,这些缓冲区不会从上传到图形内存中受益。然而,QSGGeometry支持通过setVertexDataPattern()和setIndexDataPattern()函数向渲染器提示应该上传缓冲区。是否遵循此提示取决于具体实现。- class AttributeType¶
此枚举标识了几种属性类型。
常量
描述
QSGGeometry.UnknownAttribute
不关心
QSGGeometry.PositionAttribute
位置
QSGGeometry.ColorAttribute
颜色
QSGGeometry.TexCoordAttribute
纹理坐标
QSGGeometry.TexCoord1Attribute
纹理坐标 1
QSGGeometry.TexCoord2Attribute
纹理坐标 2
- class DataPattern¶
DataPattern 枚举用于指定几何对象中顶点和索引数据的使用模式。
常量
描述
QSGGeometry.AlwaysUploadPattern
数据总是被上传。这意味着用户在更改后不需要显式地将索引和顶点数据标记为脏数据。这是默认设置。
QSGGeometry.DynamicPattern
数据被反复修改并多次绘制。这是一个提示,可能会提供更好的性能。设置后,用户必须确保在更改数据后将其标记为脏数据。
QSGGeometry.StaticPattern
数据被修改一次并绘制多次。这是一个可能提供更好性能的提示。设置后,用户必须确保在更改数据后将其标记为脏数据。
QSGGeometry.StreamPattern
数据在每次绘制时几乎都会被修改。这是一个提示,可能会提供更好的性能。当设置时,用户必须在更改数据后确保将其标记为脏数据。
- class DrawingMode¶
(继承自
enum.IntEnum) 指定绘图模式,也称为图元拓扑。注意
从 Qt 6 开始,场景图仅暴露所有支持的 3D 图形 API 都支持的拓扑结构。因此,在 Qt 6 运行时不再支持
DrawLineLoop和DrawTriangleFan这些值,尽管枚举值本身仍然存在。常量
描述
QSGGeometry.DrawPoints
QSGGeometry.DrawLines
QSGGeometry.DrawLineStrip
QSGGeometry.DrawTriangles
QSGGeometry.DrawTriangleStrip
- class Type¶
指定顶点数据中的组件类型。
常量
描述
QSGGeometry.ByteType
QSGGeometry.UnsignedByteType
QSGGeometry.ShortType
QSGGeometry.UnsignedShortType
QSGGeometry.IntType
QSGGeometry.UnsignedIntType
QSGGeometry.FloatType
QSGGeometry.Bytes2Type
在 Qt 5.14 中添加。
QSGGeometry.Bytes3Type
在 Qt 5.14 中添加。
QSGGeometry.Bytes4Type
在 Qt 5.14 中添加。
QSGGeometry.DoubleType
在 Qt 5.14 中添加。
- __init__(attribs, vertexCount[, indexCount=0[, indexType=QSGGeometry.Type.UnsignedShortType]])¶
- Parameters:
attribs –
AttributeSetvertexCount – int
indexCount – int
indexType – int
基于
attributes构建一个几何对象。该对象根据
attributes中累积的大小为vertexCount个顶点分配空间,并为indexCount分配空间。indexType可以是UnsignedShortType或UnsignedIntType。对后者的支持取决于运行时使用的图形 API 实现,可能并不总是可用。默认情况下,几何对象使用
DrawTriangleStrip作为绘制模式进行构建。注意
attributes和它引用的Attribute对象必须在QSGGeometry的整个生命周期内保持有效。QSGGeometry存储了对attributes的引用,并且不会删除Attribute对象。- allocate(vertexCount[, indexCount=0])¶
- Parameters:
vertexCount – int
indexCount – int
调整此几何对象的顶点和索引数据以适应
vertexCount个顶点和indexCount个索引。在此调用后,顶点和索引数据将失效,调用者必须通过调用 node->markDirty(
DirtyGeometry) 将相关的几何节点标记为脏,以确保渲染器有机会更新内部缓冲区。- attributeCount()¶
- Return type:
整数
返回此几何体使用的属性集中的属性数量。
返回一个包含此几何体属性的数组。数组的大小由
attributeCount()给出。- static defaultAttributes_ColoredPoint2D()¶
- Return type:
便利函数,返回用于每个顶点着色的2D绘制的属性。
- static defaultAttributes_Point2D()¶
- Return type:
便利函数,返回用于2D纯色绘制的属性。
- static defaultAttributes_TexturedPoint2D()¶
- Return type:
便利函数,返回用于纹理2D绘制的属性。
- drawingMode()¶
- Return type:
整数
返回此几何体的绘图模式。
默认值为
DrawTriangleStrip。另请参阅
- indexCount()¶
- Return type:
整数
返回此几何对象中的索引数量。
- indexData()¶
- Return type:
void
返回指向此几何对象的原始索引数据的指针。
- indexDataAsUInt()¶
- Return type:
uint
方便函数,用于将索引数据作为32位无符号整数的不可变数组访问。
- indexDataAsUShort()¶
- Return type:
quint16
方便函数,用于将索引数据作为不可变的16位无符号整数数组访问。
- indexDataPattern()¶
- Return type:
返回此几何体中索引的使用模式。默认模式是
AlwaysUploadPattern。- indexType()¶
- Return type:
整数
返回此几何对象中用于索引的原始类型。
- lineWidth()¶
- Return type:
浮点数
获取当前用于此几何体的线宽或点宽。此属性仅在
drawingMode为DrawLines或DrawLineStrip时适用于线宽。当支持时,它也在drawingMode为DrawPoints时适用于点大小。默认值为
1.0注意
在运行时,点和线的绘制支持可能会受到限制,这取决于平台和图形API。例如,某些API不支持点精灵,因此无法设置除1以外的其他大小。
- markIndexDataDirty()¶
标记此几何体中的顶点已更改,必须重新上传。
此函数仅在顶点使用模式为StaticData且渲染此几何体的渲染器将几何体上传到顶点缓冲对象(VBOs)时有效。
- markVertexDataDirty()¶
标记此几何体中的顶点已更改,必须重新上传。
此函数仅在顶点使用模式为StaticData且渲染此几何体的渲染器将几何体上传到顶点缓冲对象(VBOs)时有效。
- setDrawingMode(mode)¶
- Parameters:
mode – int
设置用于绘制此几何图形的
mode。默认值为
DrawTriangleStrip。另请参阅
- setIndexDataPattern(p)¶
- Parameters:
p –
DataPattern
设置索引的使用模式为
p。默认是
AlwaysUploadPattern。当设置为默认值以外的任何值时,用户必须在更改索引数据后调用markIndexDataDirty(),此外还需要使用DirtyGeometry调用markDirty()。另请参阅
- setLineWidth(w)¶
- Parameters:
w – 浮点数
设置用于此几何图形的线或点宽度为
width。此属性仅在drawingMode为DrawLines或DrawLineStrip时适用于线宽。当支持时,它也在drawingMode为DrawPoints时适用于点大小。注意
在运行时,点和线的绘制支持可能会受到限制,这取决于平台和图形API。例如,某些API不支持点精灵,因此无法设置除1以外的其他大小。
- setVertexDataAsPoint2D(points)¶
- Parameters:
points – QSGGeometry.Point2D 的列表
从QSGGeometry.Point2D列表设置顶点数据。 列表大小必须与QSGGeometry.vertexCount()返回的分配的顶点数匹配。
- setVertexDataPattern(p)¶
- Parameters:
p –
DataPattern
设置顶点的使用模式为
p。默认是
AlwaysUploadPattern。当设置为默认值以外的任何值时,用户必须在更改顶点数据后调用markVertexDataDirty(),此外还需要使用DirtyGeometry调用markDirty()。另请参阅
- sizeOfIndex()¶
- Return type:
整数
返回索引类型的字节大小。
当索引类型为
UnsignedShortType时,此值为2,或者当索引类型为UnsignedIntType时,此值为4。- sizeOfVertex()¶
- Return type:
整数
返回一个顶点的大小(以字节为单位)。
这个值来自属性。
- static updateColoredRectGeometry(g, rect)¶
- Parameters:
g –
QSGGeometryrect –
QRectF
使用
rect中的坐标更新几何体g。该函数假设几何对象包含一个由
ColoredPoint2D顶点组成的单个三角形带- static updateRectGeometry(g, rect)¶
- Parameters:
g –
QSGGeometryrect –
QRectF
使用
rect中的坐标更新几何体g。该函数假设几何对象包含一个由
Point2D顶点组成的单个三角形带- static updateTexturedRectGeometry(g, rect, sourceRect)¶
- Parameters:
g –
QSGGeometryrect –
QRectFsourceRect –
QRectF
使用
rect中的坐标和textureRect中的纹理坐标更新几何体g。textureRect应该在归一化坐标中。g被假定为由四个顶点组成的三角形条带,顶点类型为TexturedPoint2D。- vertexCount()¶
- Return type:
整数
返回此几何对象中的顶点数量。
- vertexData()¶
- Return type:
void
返回指向此几何对象的原始顶点数据的指针。
- vertexDataAsColoredPoint2D()¶
- Return type:
方便函数,用于将顶点数据作为不可变的
ColoredPoint2D数组访问。- vertexDataAsPoint2D()¶
- Return type:
PyObject*
方便函数,用于将顶点数据作为不可变的
Point2D数组访问。- vertexDataAsTexturedPoint2D()¶
- Return type:
方便函数,用于将顶点数据作为不可变的
TexturedPoint2D数组访问。- vertexDataPattern()¶
- Return type:
返回此几何体中顶点的使用模式。默认模式是
AlwaysUploadPattern。- class TexturedPoint2D¶
概要¶
方法¶
def
set()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
- 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 – 浮点数
ny – 浮点数
ntx – 浮点数
nty – 浮点数
将顶点的位置设置为
x和y,并将纹理坐标设置为tx和ty。
- class Point2D¶
概要¶
方法¶
def
set()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
- PySide6.QtQuick.QSGGeometry.Point2D.x¶
- PySide6.QtQuick.QSGGeometry.Point2D.y¶
- set(nx, ny)¶
- Parameters:
nx – 浮点数
ny – 浮点数
将此点的x和y值设置为
x和y。
- class ColoredPoint2D¶
概要¶
方法¶
def
set()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
- 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 – 浮点数
ny – 浮点数
nr – int
ng – int
nb – int
na – int
将顶点的位置设置为
x和y,并将颜色设置为red、green、blue和alpha。
- class Attribute¶
概要¶
静态函数¶
def
create()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
- 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 – 整数
tupleSize – int
primitiveType – int
isPosition – 布尔值
- Return type:
为属性寄存器
pos创建一个新的Attribute,其大小为tupleSize。primitiveType可以是Type中支持的任何类型,例如FloatType或UnsignedByteType。如果属性描述了顶点的位置,应将
isPosition提示设置为true。场景图渲染器可能会使用此信息来执行优化。使用create函数来构造属性,而不是初始化列表,以确保所有字段都被初始化。
- static createWithAttributeType(pos, tupleSize, primitiveType, attributeType)¶
- Parameters:
pos – 整数
tupleSize – int
primitiveType – int
attributeType –
AttributeType
- Return type:
为属性寄存器
pos创建一个新的Attribute,其大小为tupleSize。primitiveType可以是Type支持的任何类型,例如FloatType或UnsignedByteType。attributeType描述了属性的预期用途。使用create函数来构造属性,而不是初始化列表,以确保所有字段都被初始化。