QOpenGLShader Class

The QOpenGLShader class allows OpenGL shaders to be compiled. More...

Header: #include <QOpenGLShader>
qmake: QT += gui
Since: Qt 5.0
Inherits: QObject

Public Types

flags ShaderType
enum ShaderTypeBit { Vertex, Fragment, Geometry, TessellationControl, TessellationEvaluation, Compute }

Public Functions

QOpenGLShader(QOpenGLShader::ShaderType type, QObject *parent = Q_NULLPTR)
virtual ~QOpenGLShader()
bool compileSourceCode(const char *source)
bool compileSourceCode(const QByteArray &source)
bool compileSourceCode(const QString &source)
bool compileSourceFile(const QString &fileName)
bool isCompiled() const
QString log() const
GLuint shaderId() const
QOpenGLShader::ShaderType shaderType() const
QByteArray sourceCode() const
  • 31 public functions inherited from QObject

Static Public Members

bool hasOpenGLShaders(ShaderType type, QOpenGLContext *context = Q_NULLPTR)
  • 11 static public members inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 2 signals inherited from QObject
  • 9 protected functions inherited from QObject

Detailed Description

The QOpenGLShader class allows OpenGL shaders to be compiled.

This class supports shaders written in the OpenGL Shading Language (GLSL) and in the OpenGL/ES Shading Language (GLSL/ES).

QOpenGLShader and QOpenGLShaderProgram shelter the programmer from the details of compiling and linking vertex and fragment shaders.

See also QOpenGLShaderProgram.

Member Type Documentation

enum QOpenGLShader::ShaderTypeBit
flags QOpenGLShader::ShaderType

This enum specifies the type of QOpenGLShader that is being created.

ConstantValueDescription
QOpenGLShader::Vertex0x0001Vertex shader written in the OpenGL Shading Language (GLSL).
QOpenGLShader::Fragment0x0002Fragment shader written in the OpenGL Shading Language (GLSL).
QOpenGLShader::Geometry0x0004Geometry shaders written in the OpenGL Shading Language (GLSL) based on the OpenGL core feature (requires OpenGL >= 3.2).
QOpenGLShader::TessellationControl0x0008Tessellation control shaders written in the OpenGL shading language (GLSL), based on the core feature (requires OpenGL >= 4.0).
QOpenGLShader::TessellationEvaluation0x0010Tessellation evaluation shaders written in the OpenGL shading language (GLSL), based on the core feature (requires OpenGL >= 4.0).
QOpenGLShader::Compute0x0020Compute shaders written in the OpenGL shading language (GLSL), based on the core feature (requires OpenGL >= 4.3).

The ShaderType type is a typedef for QFlags<ShaderTypeBit>. It stores an OR combination of ShaderTypeBit values.

Member Function Documentation

QOpenGLShader::QOpenGLShader(QOpenGLShader::ShaderType type, QObject *parent = Q_NULLPTR)

Constructs a new QOpenGLShader object of the specified type and attaches it to parent. If shader programs are not supported, QOpenGLShaderProgram::hasOpenGLShaderPrograms() will return false.

This constructor is normally followed by a call to compileSourceCode() or compileSourceFile().

The shader will be associated with the current QOpenGLContext.

See also compileSourceCode() and compileSourceFile().

[virtual] QOpenGLShader::~QOpenGLShader()

Deletes this shader. If the shader has been attached to a QOpenGLShaderProgram object, then the actual shader will stay around until the QOpenGLShaderProgram is destroyed.

bool QOpenGLShader::compileSourceCode(const char *source)

Sets the source code for this shader and compiles it. Returns true if the source was successfully compiled, false otherwise.

See also compileSourceFile().

bool QOpenGLShader::compileSourceCode(const QByteArray &source)

This is an overloaded function.

Sets the source code for this shader and compiles it. Returns true if the source was successfully compiled, false otherwise.

See also compileSourceFile().

bool QOpenGLShader::compileSourceCode(const QString &source)

This is an overloaded function.

Sets the source code for this shader and compiles it. Returns true if the source was successfully compiled, false otherwise.

See also compileSourceFile().

bool QOpenGLShader::compileSourceFile(const QString &fileName)

Sets the source code for this shader to the contents of fileName and compiles it. Returns true if the file could be opened and the source compiled, false otherwise.

See also compileSourceCode().

[static] bool QOpenGLShader::hasOpenGLShaders(ShaderType type, QOpenGLContext *context = Q_NULLPTR)

Returns true if shader programs of type type are supported on this system; false otherwise.

The context is used to resolve the GLSL extensions. If context is null, then QOpenGLContext::currentContext() is used.

bool QOpenGLShader::isCompiled() const

Returns true if this shader has been compiled; false otherwise.

See also compileSourceCode() and compileSourceFile().

QString QOpenGLShader::log() const

Returns the errors and warnings that occurred during the last compile.

See also compileSourceCode() and compileSourceFile().

GLuint QOpenGLShader::shaderId() const

Returns the OpenGL identifier associated with this shader.

See also QOpenGLShaderProgram::programId().

QOpenGLShader::ShaderType QOpenGLShader::shaderType() const

Returns the type of this shader.

QByteArray QOpenGLShader::sourceCode() const

Returns the source code for this shader.

See also compileSourceCode().

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