QSGGeometryNode Class

QSGGeometryNode 类用于场景图中的所有渲染内容。更多

Header: #include <QSGGeometryNode>
CMake: find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: QT += quick
继承: QSGBasicGeometryNode
继承者:

QSGImageNode,QSGRectangleNode,QSGSimpleRectNode, 以及QSGSimpleTextureNode

公共函数

QSGGeometryNode()
virtual ~QSGGeometryNode() override
QSGMaterial *material() const
QSGMaterial *opaqueMaterial() const
void setMaterial(QSGMaterial *material)
void setOpaqueMaterial(QSGMaterial *material)

详细说明

QSGGeometryNode 由几何体和材质组成。几何体定义要绘制的网格、顶点及其结构。材质定义了填充形状的方式。

下面的代码片段说明了如何使用 QSGGeometryNode 创建一条红线:

QSGGeometry *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 2);
geometry->setDrawingMode(GL_LINES);
geometry->setLineWidth(3);
geometry->vertexDataAsPoint2D()[0].set(0, 0);
geometry->vertexDataAsPoint2D()[1].set(width(), height());

QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
material->setColor(QColor(255, 0, 0));

QSGGeometryNode *node = new QSGGeometryNode;
node->setGeometry(geometry);
node->setFlag(QSGNode::OwnsGeometry);
node->setMaterial(material);
node->setFlag(QSGNode::OwnsMaterial);

几何体节点在添加到场景图之前,必须同时拥有几何体和法线材质。当几何体和材质在节点添加到场景图后发生变化时,用户也应使用QSGNode::markDirty() 将其标记为 "脏"。

几何体节点支持两种类型的材质:opaqueMaterial 和普通材质。opaqueMaterial 在渲染时累积的场景图不透明度为 1 时使用。主要用于特殊情况下的不透明渲染,以避免片段着色器中的额外操作对嵌入式图形芯片的性能产生重大影响。不透明材质是可选的。

注意: 所有带有 QSG 前缀的类都只能在场景图的渲染线程中使用。更多信息请参见场景图和渲染

另请参阅 QSGGeometryQSGMaterial

成员函数文档

QSGGeometryNode::QSGGeometryNode()

创建一个不带几何体和材质的新几何体节点。

[override virtual noexcept] QSGGeometryNode::~QSGGeometryNode()

删除此几何体节点。

标志QSGNode::OwnsMaterialQSGNode::OwnsOpaqueMaterialQSGNode::OwnsGeometry 决定几何节点是否也应删除材料和几何体。默认情况下,这些标志是禁用的。

QSGMaterial *QSGGeometryNode::material() const

返回QSGGeometryNode 的材料。

另请参阅 setMaterial() 。

QSGMaterial *QSGGeometryNode::opaqueMaterial() const

返回QSGGeometryNode 的不透明材料。

另请参见 setOpaqueMaterial()。

void QSGGeometryNode::setMaterial(QSGMaterial *material)

将此几何体节点的材质设置为material

几何体节点在添加到场景图之前必须有材质。

如果在没有再次调用 setMaterial() 的情况下更改了材质,用户还必须使用QSGNode::markDirty() 将该材质标记为脏材质。

另请参阅 material()。

void QSGGeometryNode::setOpaqueMaterial(QSGMaterial *material)

将此几何体的不透明材质设置为material

material() 函数返回的默认材质相比,如果不透明材质不是空值,且几何体项的固有不透明度为 1,渲染器将优先使用不透明材质。

不透明度指的是场景图的不透明度,材质仍可将QSGMaterial::Blending 设置为 true 并绘制透明像素。

如果在没有再次调用 setOpaqueMaterial() 的情况下更改了材质,用户还必须使用QSGNode::markDirty() 将不透明材质标记为 dirty。

另请参阅 opaqueMaterial()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.