Home · All Classes · All Functions · Overviews

QGLShader Class Reference
[
QtOpenGL module]

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

 #include <QGLShader>

This class is not part of the Qt GUI Framework Edition.

Inherits QObject.

This class was introduced in Qt 4.6.


Public Types

flags ShaderType
enum ShaderTypeBits { VertexShader, FragmentShader, PartialVertexShader, PartialFragmentShader }

Public Functions

QGLShader ( QGLShader::ShaderType type, QObject * parent = 0 )
QGLShader ( const QString & fileName, QGLShader::ShaderType type, QObject * parent = 0 )
QGLShader ( QGLShader::ShaderType type, const QGLContext * context, QObject * parent = 0 )
QGLShader ( const QString & fileName, QGLShader::ShaderType type, const QGLContext * context, QObject * parent = 0 )
virtual ~QGLShader ()
bool compile ( const char * source )
bool compile ( const QByteArray & source )
bool compile ( const QString & source )
bool compileFile ( const QString & fileName )
bool isCompiled () const
QString log () const
bool setShaderBinary ( GLenum format, const void * binary, int length )
bool setShaderBinary ( QGLShader & otherShader, GLenum format, const void * binary, int length )
GLuint shaderId () const
QGLShader::ShaderType shaderType () const
QByteArray sourceCode () const

Static Public Members

QList<GLenum> shaderBinaryFormats ()

Additional Inherited Members


Detailed Description

The QGLShader 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).

QGLShader and QGLShaderProgram shelter the programmer from the details of compiling and linking vertex and fragment shaders.

See also QGLShaderProgram.


Member Type Documentation

enum QGLShader::ShaderTypeBits
flags QGLShader::ShaderType

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

ConstantValueDescription
QGLShader::VertexShader0x0001Vertex shader written in the OpenGL Shading Language (GLSL).
QGLShader::FragmentShader0x0002Fragment shader written in the OpenGL Shading Language (GLSL).
QGLShader::PartialVertexShaderPartialShader | VertexShaderPartial vertex shader that will be concatenated with all other partial vertex shaders at link time.
QGLShader::PartialFragmentShaderPartialShader | FragmentShaderPartial fragment shader that will be concatenated with all other partial fragment shaders at link time.

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


Member Function Documentation

QGLShader::QGLShader ( QGLShader::ShaderType type, QObject * parent = 0 )

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

This constructor is normally followed by a call to compile() or compileFile().

The shader will be associated with the current QGLContext.

See also compile() and compileFile().

QGLShader::QGLShader ( const QString & fileName, QGLShader::ShaderType type, QObject * parent = 0 )

Constructs a new QGLShader object of the specified type from the source code in fileName and attaches it to parent. If the shader could not be loaded, then isCompiled() will return false.

The shader will be associated with the current QGLContext.

See also isCompiled().

QGLShader::QGLShader ( QGLShader::ShaderType type, const QGLContext * context, QObject * parent = 0 )

Constructs a new QGLShader object of the specified type and attaches it to parent. If shader programs are not supported, then QGLShaderProgram::hasShaderPrograms() will return false.

This constructor is normally followed by a call to compile() or compileFile().

The shader will be associated with context.

See also compile() and compileFile().

QGLShader::QGLShader ( const QString & fileName, QGLShader::ShaderType type, const QGLContext * context, QObject * parent = 0 )

Constructs a new QGLShader object of the specified type from the source code in fileName and attaches it to parent. If the shader could not be loaded, then isCompiled() will return false.

The shader will be associated with context.

See also isCompiled().

QGLShader::~QGLShader ()   [virtual]

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

bool QGLShader::compile ( const char * source )

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

If shaderType() is PartialVertexShader or PartialFragmentShader, then this function will always return true, even if the source code is invalid. Partial shaders are compiled when QGLShaderProgram::link() is called.

See also compileFile().

bool QGLShader::compile ( 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.

If shaderType() is PartialVertexShader or PartialFragmentShader, then this function will always return true, even if the source code is invalid. Partial shaders are compiled when QGLShaderProgram::link() is called.

See also compileFile().

bool QGLShader::compile ( 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.

If shaderType() is PartialVertexShader or PartialFragmentShader, then this function will always return true, even if the source code is invalid. Partial shaders are compiled when QGLShaderProgram::link() is called.

See also compileFile().

bool QGLShader::compileFile ( 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.

If shaderType() is PartialVertexShader or PartialFragmentShader, then this function will always return true, even if the source code is invalid. Partial shaders are compiled when QGLShaderProgram::link() is called.

See also compile().

bool QGLShader::isCompiled () const

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

See also compile().

QString QGLShader::log () const

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

See also compile().

bool QGLShader::setShaderBinary ( GLenum format, const void * binary, int length )

Sets the binary code for this shader to the length bytes from the array binary. The format specifies how the binary data should be interpreted by the OpenGL engine. Returns true if the binary was set on the shader; false otherwise.

This function cannot be used with PartialVertexShader or PartialFragmentShader.

If this function succeeds, then the shader will be considered compiled.

See also shaderBinaryFormats().

bool QGLShader::setShaderBinary ( QGLShader & otherShader, GLenum format, const void * binary, int length )

Sets the binary code for this shader to the length bytes from the array binary. The format specifies how the binary data should be interpreted by the OpenGL engine. Returns true if the binary was set on the shader; false otherwise.

The otherShader will also have binary code set on it. This is for the case where binary contains both vertex and fragment shader code.

This function cannot be used with PartialVertexShader or PartialFragmentShader.

If this function succeeds, then the shader will be considered compiled.

See also shaderBinaryFormats().

QList<GLenum> QGLShader::shaderBinaryFormats ()   [static]

Returns a list of all binary formats that are supported by setShaderBinary() on this system.

See also setShaderBinary().

GLuint QGLShader::shaderId () const

Returns the OpenGL identifier associated with this shader.

If shaderType() is PartialVertexShader or PartialFragmentShader, this function will always return zero. Partial shaders are created and compiled when QGLShaderProgram::link() is called.

See also QGLShaderProgram::programId().

QGLShader::ShaderType QGLShader::shaderType () const

Returns the type of this shader.

QByteArray QGLShader::sourceCode () const

Returns the source code for this shader.

See also compile().


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.6.0