QShaderProgram Class

(Qt3DRender::QShaderProgram)

Encapsulates a Shader Program. More...

Header: #include <QShaderProgram>
qmake: QT += 3drender
Since: Qt 5.5
Instantiated By: ShaderProgram
Inherits: Qt3DCore::QNode

Public Types

enum ShaderType { Vertex, Fragment, TessellationControl, TessellationEvaluation, Geometry, Compute }
enum Status { NotReady, Ready, Error }

Properties

Public Functions

QShaderProgram(Qt3DCore::QNode *parent = nullptr)
virtual ~QShaderProgram()
QByteArray computeShaderCode() const
QByteArray fragmentShaderCode() const
QByteArray geometryShaderCode() const
QString log() const
void setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode)
QByteArray shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const
Qt3DRender::QShaderProgram::Status status() const
QByteArray tessellationControlShaderCode() const
QByteArray tessellationEvaluationShaderCode() const
QByteArray vertexShaderCode() const

Public Slots

void setComputeShaderCode(const QByteArray &computeShaderCode)
void setFragmentShaderCode(const QByteArray &fragmentShaderCode)
void setGeometryShaderCode(const QByteArray &geometryShaderCode)
void setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode)
void setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode)
void setVertexShaderCode(const QByteArray &vertexShaderCode)

Signals

void computeShaderCodeChanged(const QByteArray &computeShaderCode)
void fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode)
void geometryShaderCodeChanged(const QByteArray &geometryShaderCode)
void logChanged(const QString &log)
void statusChanged(Qt3DRender::QShaderProgram::Status status)
void tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode)
void tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode)
void vertexShaderCodeChanged(const QByteArray &vertexShaderCode)

Static Public Members

QByteArray loadSource(const QUrl &sourceUrl)
const QMetaObject staticMetaObject
  • 9 static public members inherited from QObject

Reimplemented Protected Functions

virtual void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override

Detailed Description

Encapsulates a Shader Program.

A shader program consists of several different shaders, such as vertex and fragment shaders.

Qt3D will automatically populate a set of default uniforms if they are encountered during the shader instrospection phase.

Default UniformAssociated Qt3D Parameter nameGLSL declaration
ModelMatrixmodelMatrixuniform mat4 modelMatrix;
ViewMatrixviewMatrixuniform mat4 viewMatrix;
ProjectionMatrixprojectionMatrixuniform mat4 projectionMatrix;
ModelViewMatrixmodelViewuniform mat4 modelView;
ViewProjectionMatrixviewProjectionMatrixuniform mat4 viewProjectionMatrix;
ModelViewProjectionMatrixmodelViewProjection
mvp
uniform mat4 modelViewProjection;
uniform mat4 mvp;
InverseModelMatrixinverseModelMatrixuniform mat4 inverseModelMatrix;
InverseViewMatrixinverseViewMatrixuniform mat4 inverseViewMatrix;
InverseProjectionMatrixinverseProjectionMatrixuniform mat4 inverseProjectionMatrix;
InverseModelViewMatrixinverseModelViewuniform mat4 inverseModelView;
InverseViewProjectionMatrixinverseViewProjectionMatrixuniform mat4 inverseViewProjectionMatrix;
InverseModelViewProjectionMatrixinverseModelViewProjectionuniform mat4 inverseModelViewProjection;
ModelNormalMatrixmodelNormalMatrixuniform mat3 modelNormalMatrix;
ModelViewNormalMatrixmodelViewNormaluniform mat3 modelViewNormal;
ViewportMatrixviewportMatrixuniform mat4 viewportMatrix;
InverseViewportMatrixinverseViewportMatrixuniform mat4 inverseViewportMatrix;
AspectRatio
(surface width / surface height)
aspectRatiouniform float aspectRatio;
Exposureexposureuniform float exposure;
Gammagammauniform float gamma;
Time
(in nano seconds)
timeuniform float time;
EyePositioneyePositionuniform vec3 eyePosition;
SkinningPaletteskinningPalette[0]const int maxJoints = 100;
uniform mat4 skinningPalette[maxJoints];

Member Type Documentation

enum QShaderProgram::ShaderType

This enum identifies the type of shader used.

ConstantValueDescription
Qt3DRender::QShaderProgram::Vertex0Vertex shader
Qt3DRender::QShaderProgram::Fragment1Fragment shader
Qt3DRender::QShaderProgram::TessellationControl2Tesselation control shader
Qt3DRender::QShaderProgram::TessellationEvaluation3Tesselation evaluation shader
Qt3DRender::QShaderProgram::Geometry4Geometry shader
Qt3DRender::QShaderProgram::Compute5Compute shader

enum QShaderProgram::Status

This enum identifies the status of shader used.

ConstantValueDescription
Qt3DRender::QShaderProgram::NotReady0The shader hasn't been compiled and linked yet
Qt3DRender::QShaderProgram::Ready1The shader was successfully compiled
Qt3DRender::QShaderProgram::Error2An error occurred while compiling the shader

Property Documentation

computeShaderCode : QByteArray

Holds the compute shader code used by this shader program.

Access functions:

QByteArray computeShaderCode() const
void setComputeShaderCode(const QByteArray &computeShaderCode)

Notifier signal:

void computeShaderCodeChanged(const QByteArray &computeShaderCode)

fragmentShaderCode : QByteArray

Holds the fragment shader code used by this shader program.

Access functions:

QByteArray fragmentShaderCode() const
void setFragmentShaderCode(const QByteArray &fragmentShaderCode)

Notifier signal:

void fragmentShaderCodeChanged(const QByteArray &fragmentShaderCode)

geometryShaderCode : QByteArray

Holds the geometry shader code used by this shader program.

Access functions:

QByteArray geometryShaderCode() const
void setGeometryShaderCode(const QByteArray &geometryShaderCode)

Notifier signal:

void geometryShaderCodeChanged(const QByteArray &geometryShaderCode)

log : const QString

Holds the log of the current shader program. This is useful to diagnose a compilation failure of the shader program.

Access functions:

QString log() const

Notifier signal:

void logChanged(const QString &log)

status : const Status

Holds the status of the current shader program.

Access functions:

Qt3DRender::QShaderProgram::Status status() const

Notifier signal:

void statusChanged(Qt3DRender::QShaderProgram::Status status)

tessellationControlShaderCode : QByteArray

Holds the tesselation control shader code used by this shader program.

Access functions:

QByteArray tessellationControlShaderCode() const
void setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode)

Notifier signal:

void tessellationControlShaderCodeChanged(const QByteArray &tessellationControlShaderCode)

tessellationEvaluationShaderCode : QByteArray

Holds the tesselation evaluation shader code used by this shader program.

Access functions:

QByteArray tessellationEvaluationShaderCode() const
void setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode)

Notifier signal:

void tessellationEvaluationShaderCodeChanged(const QByteArray &tessellationEvaluationShaderCode)

vertexShaderCode : QByteArray

Holds the vertex shader code used by this shader program.

Access functions:

QByteArray vertexShaderCode() const
void setVertexShaderCode(const QByteArray &vertexShaderCode)

Notifier signal:

void vertexShaderCodeChanged(const QByteArray &vertexShaderCode)

Member Function Documentation

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

Default constructs an instance of QShaderProgram.

[virtual] QShaderProgram::~QShaderProgram()

Destroys the instance of QShaderProgram. The destructor is virtual.

[static] QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl)

Returns the shader code loaded from sourceUrl.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[override virtual protected] void QShaderProgram::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)

Reimplemented from QNode::sceneChangeEvent().

Posts a scene change with parameter change.

void QShaderProgram::setShaderCode(Qt3DRender::QShaderProgram::ShaderType type, const QByteArray &shaderCode)

Sets the shader code for type of shader to the shaderCode.

See also shaderCode().

QByteArray QShaderProgram::shaderCode(Qt3DRender::QShaderProgram::ShaderType type) const

Returns the shader code for type.

See also setShaderCode().

Qt3DRender::QShaderProgram::Status QShaderProgram::status() const

Returns the status of the current shader program.

Note: Getter function for property status.

© 2019 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.