一、描述
QOpenGLShader 类允许编译 OpenGL 着色器。
此类支持以 OpenGL 着色语言 (GLSL) 和 OpenGL/ES 着色语言 (GLSL/ES) 编写的着色器。
此类使程序员免于编写编译着色器的细节。
二、类型成员
1、enum QOpenGLShader::ShaderTypeBit:此枚举指定正在创建的 QOpenGLShader 的类型。
- Vertex:顶点着色器
- Fragment:片段着色器
- Geometry:几何着色器
- TessellationControl:镶嵌控制着色器
- TessellationEvaluation:曲面细分评估着色器
- Compute:计算着色器
三、成员函数
1、bool compileSourceCode(const char *source)
bool compileSourceCode(const QByteArray &source)
bool compileSourceCode(const QString &source)
设置此着色器的源代码并对其进行编译。返回是否编译成功。
2、bool compileSourceFile(const QString &fileName)
将此着色器的源代码设置为 fileName 的内容并对其进行编译。如果可以打开文件并编译源代码,则返回 true,否则返回 false。
3、【static】bool hasOpenGLShaders(QOpenGLShader::ShaderType type, QOpenGLContext *context = nullptr)
当前系统是否支持 type 类型的着色器程序。context 用于解析 GLSL 扩展。
4、bool isCompiled()
此着色器是否已编译。
5、QString log()
返回上次编译期间发生的错误和警告。
6、GLuint shaderId()
返回与此着色器关联的 OpenGL 标识符。
7、QOpenGLShader::ShaderType shaderType()
返回此着色器的类型。
8、QByteArray sourceCode()
返回此着色器的源代码。