errorman

不积跬步,无以至千里

导航

QOpenGLShader Class

Posted on 2023-03-15 21:01  Clemens  阅读(51)  评论(0编辑  收藏  举报

Detailed Description

此类支持使用 OpenGL 着色语言 (GLSL) 和 OpenGL/ES 着色语言 (GLSL/ES) 编写的着色器。
QOpenGLShader 和 QOpenGLShaderProgram 使程序员免于编译和链接顶点和片段着色器的细节。
另见 QOpenGLShaderProgram。

 

Member Type Documentation

enum QOpenGLShader::ShaderTypeBit
flags QOpenGLShader::ShaderType
此枚举指定正在创建的 QOpenGLShader 的类型。
Constant Value Description
QOpenGLShader::Vertex 0x0001 用 OpenGL 着色语言 (GLSL) 编写的顶点着色器。
QOpenGLShader::Fragment 0x0002 用 OpenGL 着色语言 (GLSL) 编写的片段着色器。
QOpenGLShader::Geometry 0x0004 用 OpenGL 着色语言 (GLSL) 编写的几何着色器(需要 OpenGL >= 3.2 或 OpenGL ES >= 3.2)。
QOpenGLShader::TessellationControl 0x0008 以 OpenGL 着色语言 (GLSL) 编写的曲面细分控制着色器(需要 OpenGL >= 4.0 或 OpenGL ES >= 3.2)。
QOpenGLShader::TessellationEvaluation 0x0010 以 OpenGL 着色语言 (GLSL) 编写的细分评估着色器(需要 OpenGL >= 4.0 或 OpenGL ES >= 3.2)。
QOpenGLShader::Compute 0x0020 计算以 OpenGL 着色语言 (GLSL) 编写的着色器(需要 OpenGL >= 4.3 或 OpenGL ES >= 3.1)。

 

Member Function Documentation

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

构造一个指定type的新QOpenGLShader对象,并将其附加到父对象parent上。如果不支持着色器程序,则QOpenGLShaderProgram::hasOpenGLShaderPrograms()将返回false。

通常会在此构造函数后调用compileSourceCode()或compileSourceFile()。 该着色器将与当前的QOpenGLContext相关联。

另请参见compileSourceCode()和compileSourceFile()。

 

[virtual] QOpenGLShader::~QOpenGLShader()

删除这个着色器。如果该着色器已经附加到一个 QOpenGLShaderProgram 对象上,那么实际的着色器将一直存在,直到 QOpenGLShaderProgram 被销毁。

 

bool QOpenGLShader::compileSourceCode(const char *source)

设置该着色器的source并对其进行编译。如果成功编译了source,则返回 true,否则返回 false。

另请参见 compileSourceFile()。

 

bool QOpenGLShader::compileSourceCode(const QByteArray &source)

这是一个重载函数。

设置该着色器的source并对其进行编译。如果成功编译了source,则返回 true,否则返回 false。

另请参见 compileSourceFile()。

 

bool QOpenGLShader::compileSourceCode(const QString &source)

这是一个重载函数。

设置该着色器的source并对其进行编译。如果成功编译了source,则返回 true,否则返回 false。

另请参见 compileSourceFile()。

 

bool QOpenGLShader::compileSourceFile(const QString &fileName)

将该着色器的源代码设置为 fileName 文件的内容,并对其进行编译。如果可以打开文件并且成功编译了源代码,则返回 true,否则返回 false。

另请参见 compileSourceCode()。

 

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

如果该系统支持类型为 type 的着色器程序,则返回 true,否则返回 false。

context 参数用于解析 GLSL 扩展。如果 context 为 nullptr,则使用 QOpenGLContext::currentContext()。

 

bool QOpenGLShader::isCompiled() const

如果该着色器已编译,则返回 true,否则返回 false。

另请参见 compileSourceCode() 和 compileSourceFile()。

 

QString QOpenGLShader::log() const

返回上一次编译期间出现的错误和警告。

另请参见 compileSourceCode() 和 compileSourceFile()。

 

GLuint QOpenGLShader::shaderId() const

返回与该着色器相关联的 OpenGL 标识符。

另请参见 QOpenGLShaderProgram::programId()。

 

QOpenGLShader::ShaderType QOpenGLShader::shaderType() const

返回该着色器的类型。

 

QByteArray QOpenGLShader::sourceCode() const

返回该着色器的源代码。

另请参见 compileSourceCode()。