QGLShader Class

The QGLShader class allows OpenGL shaders to be compiled. 更多...

头文件: #include <QGLShader>
qmake: QT += opengl
开始支持版本: Qt 4.6
基类: QObject

This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

公有类型

flags ShaderType
enum ShaderTypeBit { Vertex, Fragment, Geometry }

公有函数

QGLShader(QGLShader::ShaderType type, QObject *parent = Q_NULLPTR)
QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = Q_NULLPTR)
virtual ~QGLShader()
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
QGLShader::ShaderType shaderType() const
QByteArray sourceCode() const
  • 32 个公有函数继承自 QObject

静态公有成员

bool hasOpenGLShaders(ShaderType type, const QGLContext *context = Q_NULLPTR)
  • 10 个静态公有成员继承自 QObject

其他继承的成员

  • 1 个属性继承自 QObject
  • 1 个公有槽函数继承自 QObject
  • 2 个信号继承自 QObject
  • 1 个公有变量继承自 QObject
  • 9 个受保护的函数继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

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.

Note: This class has been deprecated in favor of QOpenGLShader.

参见 QGLShaderProgram.

成员类型

enum QGLShader::ShaderTypeBit
flags QGLShader::ShaderType

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

ConstantValueDescription
QGLShader::Vertex0x0001Vertex shader written in the OpenGL Shading Language (GLSL).
QGLShader::Fragment0x0002Fragment shader written in the OpenGL Shading Language (GLSL).
QGLShader::Geometry0x0004Geometry shaders written in the OpenGL Shading Language (GLSL), based on the GL_EXT_geometry_shader4 extension.

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

成员函数

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

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.

参见 compileSourceCode() and compileSourceFile().

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

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.

参见 compileSourceCode() and compileSourceFile().

[virtual] QGLShader::~QGLShader()

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::compileSourceCode(const char *source)

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

参见 compileSourceFile().

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

参见 compileSourceFile().

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

参见 compileSourceFile().

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

参见 compileSourceCode().

[static] bool QGLShader::hasOpenGLShaders(ShaderType type, const QGLContext *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 QGLContext::currentContext() is used.

This function was introduced in Qt 4.7.

bool QGLShader::isCompiled() const

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

参见 compileSourceCode() and compileSourceFile().

QString QGLShader::log() const

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

参见 compileSourceCode() and compileSourceFile().

GLuint QGLShader::shaderId() const

Returns the OpenGL identifier associated with this shader.

参见 QGLShaderProgram::programId().

QGLShader::ShaderType QGLShader::shaderType() const

Returns the type of this shader.

QByteArray QGLShader::sourceCode() const

Returns the source code for this shader.

参见 compileSourceCode().