Qt3DRender::QParameter Class
class Qt3DRender::QParameter用于存储名称和值对。这与着色器统一变量相对应。更多...
| 头文件: | #include <Qt3DRender/QParameter> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS 3drender) target_link_libraries(mytarget PRIVATE Qt6::3drender) |
| qmake: | QT += 3drender |
| 在 QML 中: | Parameter |
| 继承自: | Qt3DCore::QNode |
| 状态: | 已弃用 |
该类已弃用。我们强烈建议不要在新的代码中使用它。
属性
公共函数
| QParameter(Qt3DCore::QNode *parent = nullptr) | |
| QParameter(const QString &name, Qt3DRender::QAbstractTexture *texture, Qt3DCore::QNode *parent = nullptr) | |
| QParameter(const QString &name, const QVariant &value, Qt3DCore::QNode *parent = nullptr) | |
| QString | name() const |
| QVariant | value() const |
公共槽位
信号
| void | nameChanged(const QString &name) |
| void | valueChanged(const QVariant &value) |
详细说明
可以通过QRenderPass 、QTechnique 、QEffect 、QMaterial 、QTechniqueFilter 、QRenderPassFilter 来引用一个QParameter。在运行时,根据渲染的给定步骤所选定的着色器,如果该着色器中包含一个名称与QParameter匹配的uniform,则QParameter中所包含的值将被转换并上传。
QParameter *param = new QParameter();
param->setName(QStringLiteral("diffuseColor"));
param->setValue(QColor::fromRgbF(0.0f, 0.0f, 1.0f, 1.0f));
// Alternatively you can create and set a QParameter this way
QParameter *param2 = new QParameter(QStringLiteral("diffuseColor"), QColor::fromRgbF(0.0f, 0.0f, 1.0f, 1.0f));
// Such QParameters will work with the following GLSL uniform shader declarations
// uniform vec4 diffuseColor;
// uniform vec3 diffuseColor;
// uniform vec2 diffuseColor;
// uniform float diffuseColor;注意:必须谨慎 确保 QParameter 封装的值确实能够转换为实际 uniform 所期望的类型。如果实际着色器 uniform 的类型为 float,却传入以 int 形式存储的值,可能会导致未定义的行为。
注意:当 目标uniform是数组时 ,名称应为该uniform的名称后附加 [0]。
注意:QParameter 节点无法禁用。
QParameter *param = new QParameter();
QVariantList values = QVariantList() << 0.0f << 1.0f << 2.0f << 3.0f << 4.0f << 883.0f << 1340.0f << 1584.0f;
param->setName(QStringLiteral("diffuseValues[0]"));
param->setValue(values);
// Matching GLSL shader uniform declaration
// uniform float diffuseValues[8];在支持纹理方面,QParameter 的值应设置为与着色器统一变量的采样器类型相匹配的适当QAbstractTexture 子类。
QTexture2D *texture = new QTexture2D();
...
QParameter *param = new QParameter();
param->setName(QStringLiteral("diffuseTexture"));
param->setValue(QVariant::fromValue(texture));
// Works with the following GLSL uniform shader declaration
// uniform sampler2D diffuseTexture另请参阅 QAbstractTexture 。
属性文档
name : QString
指定参数的名称
访问函数:
| QString | name() const |
| void | setName(const QString &name) |
通知信号:
| void | nameChanged(const QString &name) |
value : QVariant
指定参数的值
访问函数:
| QVariant | value() const |
| void | setValue(const QVariant &dv) |
通知信号:
| void | valueChanged(const QVariant &value) |
成员函数文档
[explicit] QParameter::QParameter(Qt3DCore::QNode *parent = nullptr)
使用指定的parent 创建一个新的QParameter。
[explicit] QParameter::QParameter(const QString &name, Qt3DRender::QAbstractTexture *texture, Qt3DCore::QNode *parent = nullptr)
创建一个具有指定parent name 的新QParameter,并从texture 中获取其值。
[explicit] QParameter::QParameter(const QString &name, const QVariant &value, Qt3DCore::QNode *parent = nullptr)
根据指定的parent 、name 和value 创建一个新的QParameter。
© 2026 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.