QOpenGLShader 类

QOpenGLShader 类允许编译 OpenGL 着色器。 更多...

头: #include <QOpenGLShader>
CMake: find_package(Qt6 COMPONENTS OpenGL REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: QT += opengl
Since: Qt 5.0
继承: QObject

公共类型

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

公共函数

  QOpenGLShader (QOpenGLShader::ShaderType type , QObject * parent = 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

静态公共成员

bool hasOpenGLShaders (QOpenGLShader::ShaderType type , QOpenGLContext * context = nullptr)

详细描述

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.

另请参阅 QOpenGLShaderProgram .

成员类型文档编制

enum QOpenGLShader:: ShaderTypeBit
flags QOpenGLShader:: ShaderType

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

常量 描述
QOpenGLShader::Vertex 0x0001 Vertex shader written in the OpenGL Shading Language (GLSL).
QOpenGLShader::Fragment 0x0002 Fragment shader written in the OpenGL Shading Language (GLSL).
QOpenGLShader::Geometry 0x0004 Geometry shaders written in the OpenGL Shading Language (GLSL) (requires OpenGL >= 3.2 or OpenGL ES >= 3.2).
QOpenGLShader::TessellationControl 0x0008 Tessellation control shaders written in the OpenGL shading language (GLSL) (requires OpenGL >= 4.0 or OpenGL ES >= 3.2).
QOpenGLShader::TessellationEvaluation 0x0010 Tessellation evaluation shaders written in the OpenGL shading language (GLSL) (requires OpenGL >= 4.0 or OpenGL ES >= 3.2).
QOpenGLShader::Compute 0x0020 Compute shaders written in the OpenGL shading language (GLSL) (requires OpenGL >= 4.3 or OpenGL ES >= 3.1).

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

成员函数文档编制

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

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

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

The shader will be associated with the current QOpenGLContext .

另请参阅 compileSourceCode () 和 compileSourceFile ().

[虚拟] 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 被销毁。

bool QOpenGLShader:: compileSourceCode (const char * source )

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

另请参阅 compileSourceFile ().

bool QOpenGLShader:: compileSourceCode (const QByteArray & source )

这是重载函数。

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

另请参阅 compileSourceFile ().

bool QOpenGLShader:: compileSourceCode (const QString & source )

这是重载函数。

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

另请参阅 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.

另请参阅 compileSourceCode ().

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

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

context is used to resolve the GLSL extensions. If context is nullptr ,那么 QOpenGLContext::currentContext () is used.

bool QOpenGLShader:: isCompiled () const

返回 true if this shader has been compiled; false otherwise.

另请参阅 compileSourceCode () 和 compileSourceFile ().

QString QOpenGLShader:: log () const

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

另请参阅 compileSourceCode () 和 compileSourceFile ().

GLuint QOpenGLShader:: shaderId () const

Returns the OpenGL identifier associated with this shader.

另请参阅 QOpenGLShaderProgram::programId ().

QOpenGLShader::ShaderType QOpenGLShader:: shaderType () const

Returns the type of this shader.

QByteArray QOpenGLShader:: sourceCode () const

Returns the source code for this shader.

另请参阅 compileSourceCode ().