|  | Home · All Classes · Modules

# QGLShader Class Reference
[QtOpenGL module]

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

Inherits QObject.

### Types

- class ShaderType
- enum ShaderTypeBit { Vertex, Fragment }

### Methods

- __init__ (self, ShaderType, QObject parent = None)
- __init__ (self, ShaderType, QGLContext, QObject parent = None)
- bool compileSourceCode (self, QByteArray)
- bool compileSourceCode (self, QStringQString)
- bool compileSourceFile (self, QStringQString)
- bool isCompiled (self)
- QStringQString log (self)
- int shaderId (self)
- ShaderType shaderType (self)
- QByteArray sourceCode (self)

## 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.

## Type Documentation

### QGLShader.ShaderTypeBit

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

Constant | Value | Description
--- | --- | ---
`QGLShader.Vertex` | `0x0001` | Vertex shader written in the OpenGL Shading Language (GLSL).
`QGLShader.Fragment` | `0x0002` | Fragment shader written in the OpenGL Shading Language (GLSL).

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

## Method Documentation

### QGLShader.__init__ (self, ShaderType, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

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

The shader will be associated with the current QGLContext.

See also compileSourceCode() and compileSourceFile().

### QGLShader.__init__ (self, ShaderType, QGLContext, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

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

The shader will be associated with context.

See also compileSourceCode() and compileSourceFile().

### bool QGLShader.compileSourceCode (self, QByteArray)

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

See also compileSourceFile().

### bool QGLShader.compileSourceCode (self, QStringQString)

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 QGLShader.compileSourceFile (self, QStringQString)

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().

### bool QGLShader.isCompiled (self)

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

See also compileSourceCode() and compileSourceFile().

### QStringQString QGLShader.log (self)

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

See also compileSourceCode() and compileSourceFile().

### int QGLShader.shaderId (self)

Returns the OpenGL identifier associated with this shader.

See also QGLShaderProgram.programId().

### ShaderType QGLShader.shaderType (self)

Returns the type of this shader.

### QByteArray QGLShader.sourceCode (self)

Returns the source code for this shader.

See also compileSourceCode().