QParameter Class▲
-
Header: Qt3DRender/QParameter
-
Since: Qt 5.7
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS 3drender)
target_link_libraries(mytarget PRIVATE Qt6::3drender)
-
qmake: QT += 3drender
-
Inherited By:
-
Instantiated By: qml-qt3d-render-parameter.xml
-
Inherits: Qt3DCore::QNode
Detailed Description▲
A QParameter can be referenced by a QRenderPass, QTechnique, QEffect, QMaterial, QTechniqueFilter, QRenderPassFilter. At runtime, depending on which shader is selected for a given step of the rendering, the value contained in a QParameter will be converted and uploaded if the shader contains a uniform with a name matching that of the QParameter.
QParameter *
param =
new
QParameter();
param-&
gt;setName(QStringLiteral("diffuseColor"
));
param-&
gt;setValue(QColor::
fromRgbF(0.0
f, 0.0
f, 1.0
f, 1.0
f));
// Alternatively you can create and set a QParameter this way
QParameter *
param2 =
new
QParameter(QStringLiteral("diffuseColor"
), QColor::
fromRgbF(0.0
f, 0.0
f, 1.0
f, 1.0
f));
// Such QParameters will work with the following GLSL uniform shader declarations
// uniform vec4 diffuseColor;
// uniform vec3 diffuseColor;
// uniform vec2 diffuseColor;
// uniform float diffuseColor;
some care must be taken to ensure the value wrapped by a QParameter can actually be converted to what the real uniform expect. Giving a value stored as an int where the actual shader uniform is of type float could result in undefined behaviors.
when the targeted uniform is an array, the name should be the name of the uniform with [0] appended to it.
QParameter node can not be disabled.
QParameter *
param =
new
QParameter();
QVariantList values =
QVariantList() &
lt;&
lt; 0.0
f &
lt;&
lt; 1.0
f &
lt;&
lt; 2.0
f &
lt;&
lt; 3.0
f &
lt;&
lt; 4.0
f &
lt;&
lt; 883.0
f &
lt;&
lt; 1340.0
f &
lt;&
lt; 1584.0
f;
param-&
gt;setName(QStringLiteral("diffuseValues[0]"
));
param-&
gt;setValue(values);
// Matching GLSL shader uniform declaration
// uniform float diffuseValues[8];
When it comes to texture support, the QParameter value should be set to the appropriate QAbstractTexture subclass that matches the sampler type of the shader uniform.
QTexture2D *
texture =
new
QTexture2D();
...
QParameter *
param =
new
QParameter();
param-&
gt;setName(QStringLiteral("diffuseTexture"
));
param-&
gt;setValue(QVariant::
fromValue(texture));
// Works with the following GLSL uniform shader declaration
// uniform sampler2D diffuseTexture
See Also▲
See also QAbstractTexture
Property Documentation▲
name : QString▲
Specifies the name of the parameter
Access functions:
-
name() const
-
void setName(const &name)
Notifier signal:
-
void nameChanged(const &name)
value : QVariant▲
Specifies the value of the parameter
Access functions:
-
value() const
-
void setValue(const &dv)
Notifier signal:
-
void valueChanged(const &value)
Member Function Documentation▲
[explicit] QParameter::QParameter(Qt3DCore::QNode *parent = nullptr)▲
Constructs a new QParameter with the specified parent.
[explicit] QParameter::QParameter(const QString &name, const QVariant &value, Qt3DCore::QNode *parent = nullptr)▲
Constructs a new QParameter with the specified parent name and value.
[explicit] QParameter::QParameter(const QString &name, Qt3DRender::QAbstractTexture *texture, Qt3DCore::QNode *parent = nullptr)▲
Constructs a new QParameter with the specified parent name and takes its value from texture.