Provides an abstract class that should be the base of all material component classes in a scene. 更多...
头: | #include <QMaterial> |
qmake: | QT += 3drender |
Since: | Qt 5.5 |
实例化: | Material |
继承: | Qt3DCore::QComponent |
继承者: |
12 typesQt3DExtras::QDiffuseMapMaterial , Qt3DExtras::QDiffuseSpecularMapMaterial , Qt3DExtras::QDiffuseSpecularMaterial , Qt3DExtras::QGoochMaterial , Qt3DExtras::QMetalRoughMaterial , Qt3DExtras::QMorphPhongMaterial , Qt3DExtras::QNormalDiffuseMapMaterial , Qt3DExtras::QNormalDiffuseSpecularMapMaterial , Qt3DExtras::QPerVertexColorMaterial , Qt3DExtras::QPhongAlphaMaterial , Qt3DExtras::QPhongMaterial ,和 Qt3DExtras::QTextureMaterial |
该类在 Qt 5.5 引入。
void | addParameter (Qt3DRender::QParameter * 参数 ) |
Qt3DRender::QEffect * | effect () const |
QVector<Qt3DRender::QParameter *> | 参数 () const |
void | removeParameter (Qt3DRender::QParameter * 参数 ) |
void | setEffect (Qt3DRender::QEffect * effect ) |
void | effectChanged (Qt3DRender::QEffect * effect ) |
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 实例。
A QParameter defined on a QMaterial overrides parameter (of the same name) defined in a QEffect , QTechnique and QRenderPass , but are overridden by parameter in QRenderPassFilter and QTechniqueFilter .
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 ,和 QParameter .
Specifies the effect to be used with the material.
访问函数:
Qt3DRender::QEffect * | effect () const |
void | setEffect (Qt3DRender::QEffect * effect ) |
通知程序信号:
void | effectChanged (Qt3DRender::QEffect * effect ) |
添加 参数 to the material's parameters.
Returns a vector of the material's current parameters
Remove a 参数 from the material's parameters.