QMaterial Class

(Qt3DRender::QMaterial)

Provides an abstract class that should be the base of all material component classes in a scene. 更多...

属性

  • effect : Qt3DRender::QEffect *

公有函数

QMaterial(Qt3DCore::QNode *parent = nullptr)
~QMaterial()
void addParameter(QParameter *parameter)
QEffect *effect() const
QVector<QParameter *> parameters() const
void removeParameter(QParameter *parameter)

公有槽函数

void setEffect(QEffect *effect)

信号

void effectChanged(QEffect *effect)

受保护的函数

QMaterial(QMaterialPrivate &dd, Qt3DCore::QNode *parent = nullptr)

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 10 个静态公有成员继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

Provides an abstract class that should be the base of all material component classes in a scene.

QMaterial provides a way to specify the rendering of an entity. Any aspect can define its own subclass of QMaterial so that a Material can be used to describe a visual element; for example, the way sound should reflect off an element, the temperature of a surface, and so on.

In itself, a QMaterial doesn't do anything. It's only when it references a QEffect node that a QMaterial becomes useful.

In practice, it often happens that a single QEffect is being referenced by several QMaterial components. This allows to only create the effect, techniques, passes and shaders once while allowing to specify the material by adding QParameter instances.

A QParameter defined on a QMaterial is overridden by a QParameter (of the same name) defined in a QTechniqueFilter or a QRenderPassFilter.


  QMaterial *material1 = new QMaterial();
  QMaterial *material2 = new QMaterial();

  // Create effect, technique, render pass and shader
  QEffect *effect = new QEffect();
  QTechnique *gl3Technique = new QTechnique();
  QRenderPass *gl3Pass = new QRenderPass();
  QShaderProgram *glShader = new QShaderProgram();

  // Set the shader on the render pass
  gl3Pass->setShaderProgram(glShader);

  // Add the pass to the technique
  gl3Technique->addRenderPass(gl3Pass);

  // Set the targeted GL version for the technique
  gl3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
  gl3Technique->graphicsApiFilter()->setMajorVersion(3);
  gl3Technique->graphicsApiFilter()->setMinorVersion(1);
  gl3Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile);

  // Add the technique to the effect
  effect->addTechnique(gl3Technique);

  // Set the effect on the materials
  material1->setEffect(effect);
  material2->setEffect(effect);

  // Set different parameters on the materials
  const QString parameterName = QStringLiteral("color");
  material1->addParameter(new QParameter(parameterName, QColor::fromRgbF(0.0f, 1.0f, 0.0f, 1.0f);
  material2->addParameter(new QParameter(parameterName, QColor::fromRgbF(1.0f, 1.0f, 1.0f, 1.0f);

参见 QEffect, QTechnique, and QParameter.

属性

effect : Qt3DRender::QEffect *

Specifies the effect to be used with the material.

访问函数:

QEffect *effect() const
void setEffect(QEffect *effect)

Notifier signal:

void effectChanged(QEffect *effect)

成员函数

QMaterial::QMaterial(Qt3DCore::QNode *parent = nullptr)

Default constructs an instance of QMaterial.

[protected] QMaterial::QMaterial(QMaterialPrivate &dd, Qt3DCore::QNode *parent = nullptr)

Copy constructor.

QMaterial::~QMaterial()

Destroys the instance of QMaterial.

void QMaterial::addParameter(QParameter *parameter)

Add a parameter to the material's parameters.

QVector<QParameter *> QMaterial::parameters() const

Returns a vector of the material's current parameters

void QMaterial::removeParameter(QParameter *parameter)

Remove a parameter from the material's parameters.