QOpenGLShaderProgram Class
QOpenGLShaderProgram 类允许链接和使用 OpenGL 着色程序。更多
Header: | #include <QOpenGLShaderProgram> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS OpenGL) target_link_libraries(mytarget PRIVATE Qt6::OpenGL) |
qmake: | QT += opengl |
继承: | QObject |
- 所有成员(包括继承成员)的列表
- QOpenGLShaderProgram 是3D 渲染的一部分。
公共函数
QOpenGLShaderProgram(QObject*parent= nullptr) | |
虚拟 | ~QOpenGLShaderProgram() |
bool | addCacheableShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const char*source) |
虚拟 | addCacheableShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QByteArray&source) |
bool | addCacheableShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QString&source) |
bool | addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypetype, const QString&fileName) |
bool | addShader(QOpenGLShader*shader) |
布尔 | addShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const char*source) |
bool | addShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QByteArray&source) |
bool | addShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QString&source) |
bool | addShaderFromSourceFile(QOpenGLShader::ShaderTypetype, const QString&fileName) |
(QOpenGLShader | attributeLocation(const char*name) const |
(QByteArr) | attributeLocation(const QByteArray&name) const |
文件名 | attributeLocation(const QString&name) const |
bool | bind() |
void | bindAttributeLocation(const char*name, intlocation) |
void | bindAttributeLocation(const QByteArray&name, intlocation) |
void | bindAttributeLocation(const QString&name, intlocation) |
bool | create() |
QList<float | defaultInnerTessellationLevels常数 |
QList<float | defaultOuterTessellationLevels常数 |
void | disableAttributeArray(intlocation) |
void | disableAttributeArray(const char*name) |
void | enableAttributeArray(intlocation) |
void | enableAttributeArray(const char*name) |
bool | isLinked() const |
虚拟 bool | link() |
QString | log()常量 |
int | maxGeometryOutputVertices() const |
int | patchVertexCount()常量 |
GLuint | programId()常量 |
void | release() |
void | removeAllShaders() |
void | removeShader(QOpenGLShader*shader) |
void | setAttributeArray(intlocation, const QVector2D*values, intstride= 0) |
void | setAttributeArray(intlocation, const QVector3D*values, intstride= 0) |
void | setAttributeArray(intlocation, const QVector4D*values, intstride= 0) |
void | setAttributeArray(intlocation, const GLfloat*values, inttupleSize, intstride= 0) |
void | setAttributeArray(intlocation, GLenumtype, const void*values, inttupleSize, intstride= 0) |
void | setAttributeArray(const char*name, const QVector2D*values, intstride= 0) |
void | setAttributeArray(const char*name, const QVector3D*values, intstride= 0) |
void | setAttributeArray(const char*name, const QVector4D*values, intstride= 0) |
void | setAttributeArray(const char*name, const GLfloat*values, inttupleSize, intstride= 0) |
void | setAttributeArray(const char*name, GLenumtype, const void*values, inttupleSize, intstride= 0) |
void | setAttributeBuffer(intlocation, GLenumtype, intoffset, inttupleSize, intstride= 0) |
void | setAttributeBuffer(const char*name, GLenumtype, intoffset, inttupleSize, intstride= 0) |
void | setAttributeValue(intlocation, GLfloatvalue) |
void | setAttributeValue(intlocation, const QColor&value) |
void | setAttributeValue(intlocation, const QVector2D&value) |
无效 | setAttributeValue(intlocation, const QVector3D&value) |
void | setAttributeValue(intlocation, const QVector4D&value) |
void | setAttributeValue(intlocation, GLfloatx, GLfloaty) |
void | setAttributeValue(intlocation, GLfloatx, GLfloaty, GLfloatz) |
void | setAttributeValue(intlocation, const GLfloat*values, intcolumns, introws) |
void | setAttributeValue(intlocation, GLfloatx, GLfloaty, GLfloatz, GLfloatw) |
void | setAttributeValue(const char*name, GLfloatvalue) |
void | setAttributeValue(const char*name, const QColor&value) |
void | setAttributeValue(常量 char *name、常量 QVector2D&value) |
void | setAttributeValue(常量 char*name、常量 QVector3D&value) |
void | setAttributeValue(const char*name, const QVector4D&value) |
void | setAttributeValue(const char*name, GLfloatx, GLfloaty) |
void | setAttributeValue(const char*name, GLfloatx, GLfloaty, GLfloatz) |
void | setAttributeValue(常量 char *name、常量 GLfloat *values、intcolumns、introws) |
void | setAttributeValue(const char*name, GLfloatx, GLfloaty, GLfloatz, GLfloatw) |
void | setDefaultInnerTessellationLevels(const QList<float>&levels) |
void | setDefaultOuterTessellationLevels(const QList<float>&levels) |
void | setPatchVertexCount(intcount) |
void | setUniformValue(intlocation, GLfloatvalue) |
void | setUniformValue(intlocation, GLintvalue) |
void | setUniformValue(const char*name, const QMatrix3x4&value) |
void | setUniformValue(const char*name, const QMatrix4x2&value) |
无效 | setUniformValue(const char*name, const QMatrix4x3&value) |
无效 | setUniformValue(const char*name, const QMatrix4x4&value) |
无效 | setUniformValue(const char*name, const QPoint&point) |
void | setUniformValue(const char*name, const QPointF&point) |
void | setUniformValue(const char*name, const QSize&size) |
void | setUniformValue(const char*name, const QSizeF&size) |
void | setUniformValue(const char*name, const QTransform&value) |
void | setUniformValue(const char*name, const QVector2D&value) |
void | setUniformValue(const char*name, const QVector3D&value) |
void | setUniformValue(const char*name, const QVector4D&value) |
void | setUniformValue(intlocation, const GLfloat[2][2]value) |
void | setUniformValue(intlocation, const GLfloat[3][3]value) |
void | setUniformValue(intlocation、常量 GLfloat[4][4]值) |
void | setUniformValue(常量字符 *名称,GLfloatx,GLfloaty) |
void | setUniformValue(const char*name, GLfloatx, GLfloaty, GLfloatz) |
void | setUniformValue(const char*name, GLfloatx, GLfloaty, GLfloatz, GLfloatw) |
void | setUniformValue(intlocation, GLuintvalue) |
void | setUniformValue(intlocation, const QColor&color) |
void | setUniformValue(intlocation, const QMatrix2x2&value) |
void | setUniformValue(intlocation, const QMatrix2x3&value) |
void | setUniformValue(intlocation, const QMatrix2x4&value) |
void | setUniformValue(intlocation, const QMatrix3x2&value) |
void | setUniformValue(intlocation, const QMatrix3x3&value) |
void | setUniformValue(intlocation, const QMatrix3x4&value) |
void | setUniformValue(intlocation, const QMatrix4x2&value) |
void | setUniformValue(intlocation, const QMatrix4x3&value) |
void | setUniformValue(intlocation, const QMatrix4x4&value) |
void | setUniformValue(intlocation, const QPoint&point) |
void | setUniformValue(intlocation, const QPointF&point) |
void | setUniformValue(intlocation, const QSize&size) |
void | setUniformValue(intlocation, const QSizeF&size) |
void | setUniformValue(intlocation, const QTransform&value) |
void | setUniformValue(intlocation, const QVector2D&value) |
void | setUniformValue(intlocation, const QVector3D&value) |
void | setUniformValue(intlocation, const QVector4D&value) |
void | setUniformValue(intlocation, GLfloatx, GLfloaty) |
void | setUniformValue(intlocation, GLfloatx, GLfloaty, GLfloatz) |
void | setUniformValue(intlocation, GLfloatx, GLfloaty, GLfloatz, GLfloatw) |
void | setUniformValue(常量字符 *名称、GLfloat值) |
void | setUniformValue(常量字符 *名称、GLint值) |
void | setUniformValue(常量字符 *名,GLuint值) |
无效 | setUniformValue(常数 GLfloat[2][2]值)。 |
无效 | setUniformValue(常量字符 *名,常量 GLfloat[3][3]值) |
无效 | setUniformValue(const char*name, const GLfloat[4][4]value) |
void | setUniformValue(const char*name, const QColor&color) |
void | setUniformValue(const char*name, const QMatrix2x2&value) |
void | setUniformValue(const char*name, const QMatrix2x3&value) |
void | setUniformValue(const char*name, const QMatrix2x4&value) |
无效 | setUniformValue(const char*name, const QMatrix3x2&value) |
无效 | setUniformValue(const char*name, const QMatrix3x3&value) |
void | setUniformValueArray(intlocation, const GLint*values, intcount) |
void | setUniformValueArray(intlocation, const GLuint*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix2x2*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix2x3*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix2x4*values, intcount) |
无效 | setUniformValueArray(intlocation, const QMatrix3x2*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix3x3*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix3x4*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix4x2*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix4x3*values, intcount) |
void | setUniformValueArray(intlocation, const QMatrix4x4*values, intcount) |
void | setUniformValueArray(intlocation, const QVector2D*values, intcount) |
void | setUniformValueArray(intlocation, const QVector3D*values, intcount) |
void | setUniformValueArray(intlocation, const QVector4D*values, intcount) |
void | setUniformValueArray(intlocation, const GLfloat*values, intcount, inttupleSize) |
void | setUniformValueArray(const char*name, const GLint*values, intcount)。 |
void | setUniformValueArray(const char*name, const GLuint*values, intcount) |
void | setUniformValueArray(const char*name, const QMatrix2x2*values, intcount) |
void | setUniformValueArray(const char*name, const QMatrix2x3*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix2x4*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix3x2*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix3x3*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix3x4*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix4x2*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix4x3*values, intcount) |
无效 | setUniformValueArray(const char*name, const QMatrix4x4*values, intcount) |
无效 | setUniformValueArray(const char*name, const QVector2D*values, intcount) |
void | setUniformValueArray(const char*name, const QVector3D*values, intcount) |
void | setUniformValueArray(const char*name, const QVector4D*values, intcount) |
void | setUniformValueArray(常量字符*name、常量 GLfloat *values、intcount、inttupleSize)。 |
QList<QOpenGLShader *> | shaders()常量 |
(const char *name) | uniformLocation(const char*name) const |
(const char *name) | uniformLocation(const QByteArray&name) const |
int | uniformLocation(const QString&name) const |
静态公共成员
bool | hasOpenGLShaderPrograms(QOpenGLContext *context = nullptr) |
详细说明
简介
该类支持以 OpenGL 着色语言(GLSL)和 OpenGL/ES 着色语言(GLSL/ES)编写的着色器程序。
QOpenGLShader QOpenGLShaderProgram 和 QOpenGLShaderProgram 可使程序员免于编译和链接顶点与片段着色器的细节。
下面的示例使用提供的源code
创建了一个顶点着色器程序。编译和链接完成后,着色器程序将通过调用QOpenGLShaderProgram::bind() 在当前QOpenGLContext 中激活:
QOpenGLShader shader(QOpenGLShader::Vertex); shader.compileSourceCode(code); QOpenGLShaderProgram program(context); program.addShader(&shader); program.link(); program.bind();
编写可移植着色器
由于对标准顶点属性和统一变量的支持程度不同,着色器程序很难在不同的 OpenGL 实现中重复使用。特别是,GLSL/ES 缺少桌面 OpenGL 系统中的所有标准变量:gl_Vertex
,gl_Normal
,gl_Color
, 等等。桌面 OpenGL 缺乏变量限定符highp
,mediump
, 和lowp
。
QOpenGLShaderProgram 类通过在所有着色器程序前加上以下桌面 OpenGL 上的行,使编写可移植着色器的过程变得更简单:
#define highp #define mediump #define lowp
这使得在桌面系统上运行大多数 GLSL/ES 着色程序成为可能。程序员应仅限于使用 GLSL/ES 中的功能,避免使用只能在桌面系统上运行的标准变量名。
简单着色器示例
program.addShaderFromSourceCode(QOpenGLShader::Vertex, "attribute highp vec4 vertex;\n" "uniform highp mat4 matrix;\n" "void main(void)\n" "{\n" " gl_Position = matrix * vertex;\n" "}"); program.addShaderFromSourceCode(QOpenGLShader::Fragment, "uniform mediump vec4 color;\n" "void main(void)\n" "{\n" " gl_FragColor = color;\n" "}"); program.link(); program.bind(); int vertexLocation = program.attributeLocation("vertex"); int matrixLocation = program.uniformLocation("matrix"); int colorLocation = program.uniformLocation("color");
激活上述着色器程序后,我们可以绘制一个绿色三角形,如下所示:
static GLfloat const triangleVertices[] = { 60.0f, 10.0f, 0.0f, 110.0f, 110.0f, 0.0f, 10.0f, 110.0f, 0.0f }; QColor color(0, 255, 0, 255); QMatrix4x4 pmvMatrix; pmvMatrix.ortho(rect()); program.enableAttributeArray(vertexLocation); program.setAttributeArray(vertexLocation, triangleVertices, 3); program.setUniformValue(matrixLocation, pmvMatrix); program.setUniformValue(colorLocation, color); glDrawArrays(GL_TRIANGLES, 0, 3); program.disableAttributeArray(vertexLocation);
二进制着色器和程序
二进制着色器可使用glShaderBinary()
对QOpenGLShader::shaderId() 的返回值进行指定。然后,可以使用addShader() 将包含二进制文件的QOpenGLShader 实例添加到着色器程序中,并使用link() 以常规方式进行链接。
二进制程序可以使用glProgramBinaryOES()
对programId() 的返回值进行指定。然后,应用程序应调用link() ,它将注意到程序已被指定并链接,从而允许对着色器程序执行其他操作。着色器程序的 id 可以使用create() 函数明确创建。
缓存程序二进制文件
从 Qt 5.9 开始,内置了对磁盘缓存程序二进制文件的支持。要启用此功能,请改用addCacheableShaderFromSourceCode() 和addCacheableShaderFromSourceFile() 函数。在 OpenGL ES 3.x 上下文或支持GL_ARB_get_program_binary
的情况下,这将透明地缓存QStandardPaths::GenericCacheLocation 或QStandardPaths::CacheLocation 下的程序二进制文件。在不支持的情况下,调用可缓存函数变体等同于调用普通函数变体。
注意: 有些驱动程序没有任何可用的二进制格式,即使它们宣传扩展或提供 OpenGL ES 3.0。在这种情况下,程序二进制支持将被禁用。
安全考虑
QOpenGLShaderProgram 使用的所有数据都是可信内容。着色器源代码可能在经过最小的修改后被传递给底层 OpenGL 实现的编译器,从 Qt 的角度来看,编译器是一个黑盒。
警告: 建议应用程序开发人员在向addShaderFromSourceFile() 等函数传递用户提供的内容之前,仔细考虑潜在的影响。
另请参阅 QOpenGLShader 。
成员函数文档
[explicit]
QOpenGLShaderProgram::QOpenGLShaderProgram(QObject *parent = nullptr)
构建一个新的着色器程序,并将其附加到parent 。在调用addShader() 之前,该程序无效。
着色器程序将与当前的QOpenGLContext 关联。
另请参阅 addShader() 。
[virtual noexcept]
QOpenGLShaderProgram::~QOpenGLShaderProgram()
删除此着色器程序。
bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)
将指定type 和source 的着色器注册到此程序中。与addShaderFromSourceCode() 不同,该函数不执行编译。编译将推迟到link() 进行,也可能根本不进行编译,因为link() 有可能使用 Qt XML 着色器磁盘缓存中的程序二进制文件。这通常会显著提高性能。
如果着色器已注册成功,或在无缓存的情况下已编译成功,则返回 true;如果出现错误,则返回 false。编译错误信息可通过log() 获取。
当磁盘缓存被禁用(例如通过Qt::AA_DisableShaderDiskCache )或 OpenGL 上下文不支持上下文二进制文件时,调用此函数等同于addShaderFromSourceCode() 。
另请参见 addShaderFromSourceCode() 和addCacheableShaderFromSourceFile()。
bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)
这是一个重载函数。
将指定type 和source 的着色器注册到本程序中。与addShaderFromSourceCode() 不同,该函数不执行编译。编译将推迟到link() 进行,也可能根本不进行编译,因为link() 有可能使用 Qt XML 着色器磁盘缓存中的程序二进制文件。这通常会显著提高性能。
如果着色器已注册成功,或在无缓存的情况下已编译成功,则返回 true;如果出现错误,则返回 false。编译错误信息可通过log() 获取。
当磁盘缓存被禁用(例如通过Qt::AA_DisableShaderDiskCache )或 OpenGL 上下文不支持上下文二进制文件时,调用此函数等同于addShaderFromSourceCode() 。
另请参见 addShaderFromSourceCode() 和addCacheableShaderFromSourceFile()。
bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)
这是一个重载函数。
将指定type 和source 的着色器注册到本程序中。与addShaderFromSourceCode() 不同,该函数不执行编译。编译将推迟到link() 进行,也可能根本不进行编译,因为link() 有可能使用 Qt XML 着色器磁盘缓存中的程序二进制文件。这通常会显著提高性能。
当磁盘缓存被禁用(例如通过Qt::AA_DisableShaderDiskCache )或 OpenGL 上下文不支持上下文二进制文件时,调用该函数等同于addShaderFromSourceCode()。
另请参见 addShaderFromSourceCode() 和addCacheableShaderFromSourceFile()。
bool QOpenGLShaderProgram::addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName)
将指定type 和fileName 的着色器注册到此程序中。与addShaderFromSourceFile() 不同,该函数不执行编译。编译将推迟到link() 进行,也可能根本不进行编译,因为link() 有可能使用 Qt XML 着色器磁盘缓存中的程序二进制文件。这通常会显著提高性能。
如果文件已成功读取,则返回 true;如果文件无法打开或着色器的正常非缓存编译失败,则返回 false。编译错误信息可通过log() 获取。
当磁盘缓存被禁用(例如通过Qt::AA_DisableShaderDiskCache )或 OpenGL 上下文不支持上下文二进制文件时,调用该函数等同于addShaderFromSourceFile() 。
另请参见 addShaderFromSourceFile() 和addCacheableShaderFromSourceCode()。
bool QOpenGLShaderProgram::addShader(QOpenGLShader *shader)
将已编译的shader 添加到此着色器程序中。如果可以添加着色器,则返回true
,否则返回 false。
shader 对象的所有权归调用者所有。删除此QOpenGLShaderProgram 实例时,它不会被删除。这样,调用者就可以在多个着色器程序中添加同一个着色器。
另请参阅 addShaderFromSourceCode(),addShaderFromSourceFile(),removeShader(),link() 和removeAllShaders().
bool QOpenGLShaderProgram::addShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)
将source 编译为指定type 的着色器,并将其添加到此着色器程序中。如果编译成功,则返回true
,否则返回 false。编译错误和警告将通过log() 提供。
该函数是一种快捷方式,可用于在不首先创建QOpenGLShader 实例的情况下,将顶点和片段着色器快速添加到着色器程序中。
另请参见 addShader(),addShaderFromSourceFile(),removeShader(),link(),log() 和removeAllShaders().
bool QOpenGLShaderProgram::addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)
这是一个重载函数。
将source 编译为指定type 的着色器,并将其添加到此着色器程序中。如果编译成功,则返回true
,否则返回 false。编译错误和警告将通过log() 提供。
该函数是一种快捷方式,可用于在不首先创建QOpenGLShader 实例的情况下,将顶点和片段着色器快速添加到着色器程序中。
另请参见 addShader(),addShaderFromSourceFile(),removeShader(),link(),log() 和removeAllShaders().
bool QOpenGLShaderProgram::addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)
这是一个重载函数。
将source 编译为指定type 的着色器,并将其添加到此着色器程序中。如果编译成功,则返回true
,否则返回 false。编译错误和警告将通过log() 提供。
该函数是一种快捷方式,可用于在不首先创建QOpenGLShader 实例的情况下,将顶点和片段着色器快速添加到着色器程序中。
另请参见 addShader(),addShaderFromSourceFile(),removeShader(),link(),log() 和removeAllShaders().
bool QOpenGLShaderProgram::addShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName)
将fileName 的内容编译为指定type 的着色器,并将其添加到此着色器程序中。如果编译成功,则返回true
,否则返回 false。编译错误和警告将通过log() 提供。
该函数是一种快捷方式,可用于在不首先创建QOpenGLShader 实例的情况下,将顶点和片段着色器快速添加到着色器程序中。
另请参见 addShader() 和addShaderFromSourceCode()。
int QOpenGLShaderProgram::attributeLocation(const char *name) const
返回name 属性在此着色器程序参数列表中的位置。如果name 不是此着色器程序的有效属性,则返回 -1。
另请参阅 uniformLocation() 和bindAttributeLocation()。
int QOpenGLShaderProgram::attributeLocation(const QByteArray &name) const
这是一个重载函数。
返回name 属性在此着色器程序参数列表中的位置。如果name 不是此着色器程序的有效属性,则返回 -1。
另请参阅 uniformLocation() 和bindAttributeLocation()。
int QOpenGLShaderProgram::attributeLocation(const QString &name) const
这是一个重载函数。
返回name 属性在此着色器程序参数列表中的位置。如果name 不是此着色器程序的有效属性,则返回 -1。
另请参阅 uniformLocation() 和bindAttributeLocation()。
bool QOpenGLShaderProgram::bind()
将此着色器程序绑定到活动的QOpenGLContext 上,并使其成为当前着色器程序。之前绑定的着色器程序将被释放。这相当于在programId() 上调用glUseProgram()
。如果程序绑定成功,则返回true
;否则返回 false。如果着色器程序尚未链接或需要重新链接,该函数将调用link() 。
void QOpenGLShaderProgram::bindAttributeLocation(const char *name, int location)
将属性name 与指定的location 绑定。此函数可在程序链接之前或之后调用。程序链接时未明确绑定的属性将自动分配位置。
如果在程序链接后调用此函数,则需要重新链接程序才能使更改生效。
另请参阅 attributeLocation()。
void QOpenGLShaderProgram::bindAttributeLocation(const QByteArray &name, int location)
这是一个重载函数。
将属性name 与指定的location 绑定。该函数可在程序链接之前或之后调用。任何在程序链接时未明确绑定的属性都将自动分配位置。
如果在程序链接后调用此函数,则需要重新链接程序才能使更改生效。
另请参阅 attributeLocation()。
void QOpenGLShaderProgram::bindAttributeLocation(const QString &name, int location)
这是一个重载函数。
将属性name 与指定的location 绑定。该函数可在程序链接之前或之后调用。任何在程序链接时未明确绑定的属性都将自动分配位置。
如果在程序链接后调用此函数,则需要重新链接程序才能使更改生效。
另请参阅 attributeLocation()。
bool QOpenGLShaderProgram::create()
请求立即创建着色器程序的 ID。如果成功,则返回true
;否则返回false
。
该函数主要用于将QOpenGLShaderProgram 与其他直接对着色器程序 ID 进行操作的 OpenGL 函数(如GL_OES_get_program_binary
)结合使用。
正常使用着色器程序时,着色器程序的 id 将按需创建。
另请参阅 programId() 。
QList<float> QOpenGLShaderProgram::defaultInnerTessellationLevels() const
如果细分控制着色器没有输出默认内部细分级别,则返回细分基元生成器使用的默认内部细分级别。有关 OpenGL 和细分着色器的更多详情,请参阅OpenGL 细分着色器。
返回描述内部细分级别的浮点QList 。该向量始终有两个元素,但并非所有元素对每种细分模式都有意义。
注意: 这将返回全局 OpenGL 状态值。它并不特定于此QOpenGLShaderProgram 实例。
注: 此函数仅支持 OpenGL >= 4.0,在 OpenGL ES 3.2 中不会返回有效结果。
另请参阅 setDefaultInnerTessellationLevels() 和defaultOuterTessellationLevels()。
QList<float> QOpenGLShaderProgram::defaultOuterTessellationLevels() const
如果细分控制着色器没有输出默认外部细分级别,则返回细分基元生成器使用的默认外部细分级别。有关 OpenGL 和细分着色器的更多详情,请参阅OpenGL 细分着色器。
返回描述外部细分级别的浮点QList 。该向量始终有四个元素,但并非所有元素都适用于每种细分模式。
注意: 这将返回全局 OpenGL 状态值。它并不特定于此QOpenGLShaderProgram 实例。
注: 此函数仅支持 OpenGL >= 4.0,在 OpenGL ES 3.2 下不会返回有效结果。
另请参阅 setDefaultOuterTessellationLevels() 和defaultInnerTessellationLevels()。
void QOpenGLShaderProgram::disableAttributeArray(int location)
在此着色器程序中禁用location 的顶点数组,该数组由之前调用enableAttributeArray() 启用。
另请参阅 enableAttributeArray(),setAttributeArray(),setAttributeValue() 和setUniformValue().
void QOpenGLShaderProgram::disableAttributeArray(const char *name)
这是一个重载函数。
禁用此着色器程序中名为name 的顶点数组,该顶点数组已通过调用enableAttributeArray() 启用。
另请参阅 enableAttributeArray(),setAttributeArray(),setAttributeValue() 和setUniformValue().
void QOpenGLShaderProgram::enableAttributeArray(int location)
在此着色器程序中启用location 上的顶点数组,以便着色器程序使用setAttributeArray() 在location 上设置的值。
另请参见 disableAttributeArray()、setAttributeArray()、setAttributeValue() 和setUniformValue()。
void QOpenGLShaderProgram::enableAttributeArray(const char *name)
这是一个重载函数。
在此着色器程序中启用名为name 的顶点数组,以便着色器程序使用setAttributeArray() 在name 上设置的值。
另请参见 disableAttributeArray()、setAttributeArray()、setAttributeValue() 和setUniformValue() 。
[static]
bool QOpenGLShaderProgram::hasOpenGLShaderPrograms(QOpenGLContext *context = nullptr)
如果本系统支持以 OpenGL 着色语言(GLSL)编写的着色器程序,则返回true
;否则返回 false。
context 用于解析 GLSL 扩展名。如果context 是nullptr
,则使用QOpenGLContext::currentContext()。
bool QOpenGLShaderProgram::isLinked() const
如果此着色器程序已被链接,则返回true
;否则返回 false。
另请参见 link().
[virtual]
bool QOpenGLShaderProgram::link()
将通过addShader() 添加到本程序的着色器链接到一起。如果链接成功,则返回true
,否则返回 false。如果链接失败,可通过log() 获取错误信息。
子类可以覆盖此函数,以初始化属性和统一变量,供特定着色器程序使用。
如果着色器程序已被链接,再次调用此函数将强制其重新链接。
如果着色器是通过addCacheableShaderFromSourceCode() 或addCacheableShaderFromSourceFile() 添加到此程序中的,支持程序二进制文件,且磁盘上有缓存的二进制文件,则会跳过实际编译和链接。相反,link() 将通过 glProgramBinary() 使用二进制 blob 初始化程序。如果没有缓存的程序版本,或者程序是在不同的驱动程序版本下生成的,则将从源代码编译着色器,并正常链接程序。这样就可以无缝升级图形驱动程序,而不必担心可能不兼容的二进制格式。
QString QOpenGLShaderProgram::log() const
返回上一次使用明确指定的源代码执行link() 或addShader() 时出现的错误和警告。
另请参见 link()。
int QOpenGLShaderProgram::maxGeometryOutputVertices() const
返回几何着色器可输出顶点数量的硬件限制。
int QOpenGLShaderProgram::patchVertexCount() const
返回渲染时使用的每个补丁的顶点数量。
注意: 这将返回全局 OpenGL 状态值。它并非针对此QOpenGLShaderProgram 实例。
另请参阅 setPatchVertexCount().
GLuint QOpenGLShaderProgram::programId() const
返回与此着色器程序相关的 OpenGL 标识。
另请参阅 QOpenGLShader::shaderId().
void QOpenGLShaderProgram::release()
从当前QOpenGLContext 中释放活动着色器程序。这相当于调用glUseProgram(0)
。
另请参阅 bind() 。
void QOpenGLShaderProgram::removeAllShaders()
删除之前添加到此程序中的所有着色器。如果着色器的QOpenGLShader 对象是由外部构建的,则不会被删除。QOpenGLShader 对象是由QOpenGLShaderProgram 内部构建的,则会被删除。
另请参阅 addShader() 和removeShader()。
void QOpenGLShaderProgram::removeShader(QOpenGLShader *shader)
从该着色器程序中删除shader 。对象不会被删除。
着色器程序必须在当前QOpenGLContext 中有效。
另请参阅 addShader()、link() 和removeAllShaders()。
void QOpenGLShaderProgram::setAttributeArray(int location, const QVector2D *values, int stride = 0)
在此着色器程序中location 的属性上设置二维顶点values 的数组。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在location 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为location 指定的值。
另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray() 。
void QOpenGLShaderProgram::setAttributeArray(int location, const QVector3D *values, int stride = 0)
在此着色器程序中location 的属性上设置三维顶点values 的数组。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在location 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为location 指定的值。
另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray() 。
void QOpenGLShaderProgram::setAttributeArray(int location, const QVector4D *values, int stride = 0)
在此着色器程序中location 的属性上设置 4D 顶点values 数组。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在location 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为location 指定的值。
另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray() 。
void QOpenGLShaderProgram::setAttributeArray(int location, const GLfloat *values, int tupleSize, int stride = 0)
在此着色器程序中设置location 处属性的顶点values 数组。tupleSize 表示每个顶点的分量数(1、2、3 或 4),stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在location 上调用enableAttributeArray() 时,数组将处于活动状态。否则,将使用setAttributeValue() 为location 指定的值。
另请参阅 setAttributeValue(),setUniformValue(),enableAttributeArray() 和disableAttributeArray() 。
void QOpenGLShaderProgram::setAttributeArray(int location, GLenum type, const void *values, int tupleSize, int stride = 0)
在此着色器程序中设置location 属性上的顶点values 数组。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
type 表示values 数组中元素的类型,通常为GL_FLOAT
,GL_UNSIGNED_BYTE
等。tupleSize 表示每个顶点的分量数:1、2、3 或 4。
在location 上调用enableAttributeArray() 时,数组将处于活动状态。否则,将使用setAttributeValue() 为location 指定的值。
setAttributeBuffer() 函数可用于将属性数组设置为顶点缓冲区内的偏移量。
注: 将启用规范化。如果不希望这样做,可通过QOpenGLFunctions 直接调用 glVertexAttribPointer。
另请参阅 setAttributeValue(),setUniformValue(),enableAttributeArray(),disableAttributeArray() 和setAttributeBuffer().
void QOpenGLShaderProgram::setAttributeArray(const char *name, const QVector2D *values, int stride = 0)
这是一个重载函数。
在此着色器程序中,在名为name 的属性上设置二维顶点数组values 。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在name 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为name 指定的值。
另请参见 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray()。
void QOpenGLShaderProgram::setAttributeArray(const char *name, const QVector3D *values, int stride = 0)
这是一个重载函数。
在此着色器程序中,在名为name 的属性上设置三维顶点数组values 。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在name 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为name 指定的值。
另请参见 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray()。
void QOpenGLShaderProgram::setAttributeArray(const char *name, const QVector4D *values, int stride = 0)
这是一个重载函数。
在此着色器程序中,在名为name 的属性上设置一个 4D 顶点数组values 。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在name 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为name 指定的值。
另请参见 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray()。
void QOpenGLShaderProgram::setAttributeArray(const char *name, const GLfloat *values, int tupleSize, int stride = 0)
这是一个重载函数。
在此着色器程序中设置name 属性上的顶点values 数组。tupleSize 表示每个顶点的分量数(1、2、3 或 4),stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
在name 上调用enableAttributeArray() 时,数组将处于活动状态。否则,将使用setAttributeValue() 为name 指定的值。
另请参见 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray()。
void QOpenGLShaderProgram::setAttributeArray(const char *name, GLenum type, const void *values, int tupleSize, int stride = 0)
这是一个重载函数。
在此着色器程序中,在名为name 的属性上设置顶点数组values 。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在values 中密集排列。
type 表示values 数组中元素的类型,通常为GL_FLOAT
,GL_UNSIGNED_BYTE
等。tupleSize 表示每个顶点的分量数:1、2、3 或 4。
在name 上调用enableAttributeArray() 时,数组将处于活动状态。否则,将使用setAttributeValue() 为name 指定的值。
setAttributeBuffer() 函数可用于将属性数组设置为顶点缓冲区内的偏移量。
另请参见 setAttributeValue()、setUniformValue()、enableAttributeArray()、disableAttributeArray() 和setAttributeBuffer() 。
void QOpenGLShaderProgram::setAttributeBuffer(int location, GLenum type, int offset, int tupleSize, int stride = 0)
从当前绑定的顶点缓冲区中的特定offset 开始,在此着色器程序中location 的属性上设置顶点值数组。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在值数组中密集排列。
type 表示顶点值数组中元素的类型,通常为GL_FLOAT
,GL_UNSIGNED_BYTE
等。tupleSize 表示每个顶点的分量数:1、2、3 或 4。
在location 上调用enableAttributeArray() 时,该数组将处于活动状态。否则,将使用setAttributeValue() 为location 指定的值。
注意: 将启用规范化。如果不希望这样,请直接通过QOpenGLFunctions 调用 glVertexAttribPointer。
另请参阅 setAttributeArray() 。
void QOpenGLShaderProgram::setAttributeBuffer(const char *name, GLenum type, int offset, int tupleSize, int stride = 0)
这是一个重载函数。
从当前绑定的顶点缓冲区中的特定offset 开始,在此着色器程序中名为name 的属性上设置顶点值数组。stride 表示顶点之间的字节数。stride 的默认值为零,表示顶点在值数组中密集排列。
type 表示顶点值数组中元素的类型,通常为GL_FLOAT
,GL_UNSIGNED_BYTE
等。tupleSize 表示每个顶点的分量数:1、2、3 或 4。
在name 上调用enableAttributeArray() 时,数组将处于活动状态。否则,将使用setAttributeValue() 为name 指定的值。
另请参见 setAttributeArray()。
void QOpenGLShaderProgram::setAttributeValue(int location, GLfloat value)
将当前上下文中location 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(int location, const QColor &value)
将当前上下文中location 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(int location, const QVector2D &value)
将当前上下文中location 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(int location, const QVector3D &value)
将当前上下文中location 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(int location, const QVector4D &value)
将当前上下文中location 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y)
将当前上下文中location 处的属性设置为二维向量 (x,y)。
另请参阅 setUniformValue().
void QOpenGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z)
将当前上下文中location 处的属性设置为三维矢量 (x,y,z)。
另请参阅 setUniformValue().
void QOpenGLShaderProgram::setAttributeValue(int location, const GLfloat *values, int columns, int rows)
将当前上下文中location 的属性设置为values 的内容, 包含columns 元素,每个 元素由rows 元素组成。rows 的值应为 1、2、3 或 4。该函数通常用于设置矩阵值和列向量。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
将当前上下文中location 处的属性设置为 4D 向量 (x,y,z,w)。
另请参阅 setUniformValue().
void QOpenGLShaderProgram::setAttributeValue(const char *name, GLfloat value)
这是一个重载函数。
将当前上下文中名为name 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(const char *name, const QColor &value)
这是一个重载函数。
将当前上下文中名为name 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(const char *name, const QVector2D &value)
这是一个重载函数。
将当前上下文中名为name 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(const char *name, const QVector3D &value)
这是一个重载函数。
将当前上下文中名为name 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(const char *name, const QVector4D &value)
这是一个重载函数。
将当前上下文中名为name 的属性设置为value 。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y)
这是一个重载函数。
将当前上下文中名为name 的属性设置为二维向量 (x,y)。
另请参见 setUniformValue().
void QOpenGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z)
这是一个重载函数。
将当前上下文中名为name 的属性设置为 3D 向量 (x,y,z)。
另请参见 setUniformValue().
void QOpenGLShaderProgram::setAttributeValue(const char *name, const GLfloat *values, int columns, int rows)
这是一个重载函数。
将当前上下文中名为name 的属性设置为values 的内容, 包含columns 元素,每个 元素由rows 元素组成。rows 的值应为 1、2、3 或 4。该函数通常用于设置矩阵值和列向量。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
这是一个重载函数。
将当前上下文中名为name 的属性设置为 4D 向量 (x,y,z,w)。
另请参阅 setUniformValue() 。
void QOpenGLShaderProgram::setDefaultInnerTessellationLevels(const QList<float> &levels)
在细分控制着色器没有将默认外部细分级别输出到levels 的情况下,设置细分基元生成器使用的默认外部细分级别。有关 OpenGL 和细分着色器的更多详情,请参阅OpenGL 细分着色器。
levels 参数应为由 2 个浮点数组成的QList 。并非所有值都适用于所有细分模式。如果指定的矢量元素少于 2 个,剩余元素的默认值将为 1。
注意: 这将修改全局 OpenGL 状态,而不是针对QOpenGLShaderProgram 实例。您应在需要时在您的呈现函数中调用该函数,因为QOpenGLShaderProgram 不会为您应用该函数。这纯粹是一个便利函数。
注意: 此函数仅适用于 OpenGL >= 4.0,不支持 OpenGL ES 3.2。
另请参阅 defaultInnerTessellationLevels() 和setDefaultOuterTessellationLevels()。
void QOpenGLShaderProgram::setDefaultOuterTessellationLevels(const QList<float> &levels)
在细分控制着色器没有将默认外部细分级别输出到levels 的情况下,设置细分基元生成器使用的默认外部细分级别。有关 OpenGL 和细分着色器的更多详情,请参阅OpenGL 细分着色器。
levels 参数应为由 4 个浮点组成的QList 。并非所有值都适用于所有细分模式。如果指定的矢量元素少于 4 个,剩余元素的默认值将为 1。
注意: 这将修改全局 OpenGL 状态,而不是针对QOpenGLShaderProgram 实例。您应在需要时在您的呈现函数中调用该函数,因为QOpenGLShaderProgram 不会为您应用该函数。这纯粹是一个便利函数。
注意: 此函数仅适用于 OpenGL >= 4.0,不支持 OpenGL ES 3.2。
另请参阅 defaultOuterTessellationLevels() 和setDefaultInnerTessellationLevels()。
void QOpenGLShaderProgram::setPatchVertexCount(int count)
使用此函数可向 OpenGL 指定count 补丁中的顶点数。补丁是一种自定义 OpenGL 基元,其解释完全由细分着色器阶段定义。因此,只有在使用包含细分阶段着色器的QOpenGLShaderProgram 时,调用此函数才有意义。在使用 OpenGL 细分时,唯一可以使用glDraw*()
函数渲染的基元是GL_PATCHES
。
这相当于调用 glPatchParameteri(GL_PATCH_VERTICES, count)。
注意: 这将修改全局 OpenGL 状态,并非针对此QOpenGLShaderProgram 实例。您应在需要时在您的渲染函数中调用该函数,因为QOpenGLShaderProgram 不会为您应用该函数。这纯粹是一个便利函数。
另请参阅 patchVertexCount().
void QOpenGLShaderProgram::setUniformValue(int location, GLfloat value)
将当前上下文中位于location 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, GLint value)
将当前上下文中位于location 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 3x4 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat3x4)。取而代之的是,它将统一矩阵视为 vec4 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 4x2 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 mat4x2 等 GLSL 类型。取而代之的是,它将统一矩阵视为 vec2 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 4x3 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 mat4x3 等 GLSL 类型。取而代之的是,它将统一矩阵视为 vec3 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 4x4 矩阵value 。
另请参见 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QPoint &point)
这是一个重载函数。
将当前上下文中与name 相关联的统一变量设置为point 的 x 坐标和 y 坐标。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const QPointF &point)
这是一个重载函数。
将当前上下文中与name 相关联的统一变量设置为point 的 x 坐标和 y 坐标。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const QSize &size)
这是一个重载函数。
将当前上下文中与name 相关联的统一变量设置为给定size 的宽度和高度。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const QSizeF &size)
这是一个重载函数。
将当前上下文中与name 相关联的统一变量设置为给定size 的宽度和高度。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const QTransform &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为指定为QTransform 值的 3x3 变换矩阵value 。
要在着色器中将QTransform 值设置为 4x4 矩阵,请使用setUniformValue(name, QMatrix4x4(value))
。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QVector2D &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QVector3D &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QVector4D &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, const GLfloat[2][2] value)
这是一个重载函数。
将当前上下文中位于location 的统一变量设置为 2x2 矩阵value 。矩阵元素必须以列主序指定。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const GLfloat[3][3] value)
这是一个重载函数。
将当前上下文中位于location 的统一变量设置为 3x3 矩阵value 。矩阵元素必须以列主序指定。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const GLfloat[4][4] value)
这是一个重载函数。
将当前上下文中位于location 的统一变量设置为 4x4 矩阵value 。矩阵元素必须以列主序指定。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为二维向量 (x,y)。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 3D 向量 (x,y,z)。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 4D 向量 (x,y,z,w)。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, GLuint value)
将当前上下文中location 的 uniform 变量设置为value 。此函数应在设置采样器值时使用。
注意: 此函数不支持现代 OpenGL 版本中的无符号 int,因此将value 视为 GLint 并调用 glUniform1i。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, const QColor &color)
将当前上下文中location 的均匀变量设置为color 的红、绿、蓝和 alpha 分量。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x2 &value)
将当前上下文中location 的均匀变量设置为 2x2 矩阵value 。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x3 &value)
将当前上下文中位于location 的统一变量设置为 2x3 矩阵value 。
注: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat2x3)。取而代之的是,它将统一矩阵视为 vec3 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x4 &value)
将当前上下文中位于location 的统一变量设置为 2x4 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat2x4)。取而代之的是,它将统一矩阵视为 vec4 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x2 &value)
将当前上下文中位于location 的统一变量设置为 3x2 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat3x2)。取而代之的是,它将统一矩阵视为 vec2 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x3 &value)
将当前上下文中location 的统一变量设置为 3x3 矩阵value 。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x4 &value)
将当前上下文中位于location 的统一变量设置为 3x4 矩阵value 。
注: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat3x4)。取而代之的是,它将统一矩阵视为 vec4 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x2 &value)
将当前上下文中位于location 的统一变量设置为 4x2 矩阵value 。
注: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat4x2)。取而代之的是,它将统一矩阵视为 vec2 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x3 &value)
将当前上下文中位于location 的统一变量设置为 4x3 矩阵value 。
注: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 mat4x3 等 GLSL 类型。取而代之的是,它将统一矩阵视为 vec3 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x4 &value)
将当前上下文location 中的均匀变量设置为 4x4 矩阵value 。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QPoint &point)
将当前上下文中location 处的均匀变量设置为point 的 x 坐标和 y 坐标。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QPointF &point)
将当前上下文中location 的均匀变量设置为point 的 x 坐标和 y 坐标。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QSize &size)
将当前上下文中location 的统一变量设置为给定size 的宽度和高度。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QSizeF &size)
将当前上下文中location 的统一变量设置为给定size 的宽度和高度。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, const QTransform &value)
将当前上下文中location 处的统一变量设置为 3x3 变换矩阵value ,该矩阵指定为QTransform 值。
要在着色器中将QTransform 值设置为 4x4 矩阵,请使用setUniformValue(location, QMatrix4x4(value))
。
void QOpenGLShaderProgram::setUniformValue(int location, const QVector2D &value)
将当前上下文中位于location 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, const QVector3D &value)
将当前上下文中位于location 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, const QVector4D &value)
将当前上下文中位于location 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y)
将当前上下文中location 处的均匀变量设置为二维向量 (x,y)。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z)
将当前上下文中location 处的均匀变量设置为三维向量 (x,y,z)。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
将当前上下文中location 处的均匀变量设置为 4D 向量 (x,y,z,w)。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, GLfloat value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, GLint value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为value 。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, GLuint value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为value 。此函数应在设置采样器值时使用。
注意: 此函数不支持现代 OpenGL 版本中的无符号 int,因此将value 视为 GLint 并调用 glUniform1i。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const GLfloat[2][2] value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 2x2 矩阵value 。矩阵元素必须以列主序指定。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const GLfloat[3][3] value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 3x3 矩阵value 。矩阵元素必须以列主序指定。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const GLfloat[4][4] value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 4x4 矩阵value 。矩阵元素必须以列主序指定。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValue(const char *name, const QColor &color)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为color 的红色、绿色、蓝色和 alpha 分量。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 2x2 矩阵value 。
另请参见 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 2x3 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat2x3)。取而代之的是,它将统一矩阵视为 vec3 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 2x4 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat2x4)。取而代之的是,它将统一矩阵视为 vec4 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 3x2 矩阵value 。
注意: 此函数不支持非正方形矩阵,即现代 OpenGL 版本中的 GLSL 类型(如 mat3x2)。取而代之的是,它将统一矩阵视为 vec2 数组。
另请参见 setAttributeValue()。
void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3 &value)
这是一个重载函数。
将当前上下文中名为name 的统一变量设置为 3x3 矩阵value 。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const GLint *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 元素。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValueArray(int location, const GLuint *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 元素。此重载应在设置采样器值数组时使用。
注意: 此函数不支持现代 OpenGL 版本中的无符号 int,因此将values 视为 GLint 并调用 glUniform1iv。
另请参阅 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 2x2 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 2x3 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 2x4 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 3x2 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 3x3 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 3x4 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 4x2 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 4x3 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 4x4 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 2D 向量元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 3D 向量元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const QVector4D *values, int count)
将当前上下文中location 的统一变量数组设置为values 的count 4D 向量元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize)
将当前上下文中location 的统一变量数组设置为values 的count 元素。每个元素都有tupleSize 组件。tupleSize 必须是 1、2、3 或 4。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const GLint *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 元素。
另请参阅 setAttributeValue() 。
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const GLuint *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 中的count 元素。此重载应在设置采样器值数组时使用。
另请参阅 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x2 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 2x2 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x3 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 2x3 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x4 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 2x4 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x2 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 3x2 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x3 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 3x3 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x4 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 3x4 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x2 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 4x2 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x3 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 4x3 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x4 *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 4x4 矩阵元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 2D 向量元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QVector3D *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 3D 向量元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *values, int count)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 4D 向量元素。
另请参见 setAttributeValue().
void QOpenGLShaderProgram::setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize)
这是一个重载函数。
将当前上下文中名为name 的统一变量数组设置为values 的count 元素。每个元素都有tupleSize 组件。tupleSize 必须是 1、2、3 或 4。
另请参阅 setAttributeValue() 。
QList<QOpenGLShader *> QOpenGLShaderProgram::shaders() const
返回使用addShader() 添加到此着色器程序的所有着色器的列表。
另请参阅 addShader() 和removeShader()。
int QOpenGLShaderProgram::uniformLocation(const char *name) const
返回统一变量name 在此着色器程序参数列表中的位置。如果name 不是此着色器程序的有效统一变量,则返回 -1。
另请参见 attributeLocation().
int QOpenGLShaderProgram::uniformLocation(const QByteArray &name) const
这是一个重载函数。
返回统一变量name 在此着色器程序参数列表中的位置。如果name 不是此着色器程序的有效统一变量,则返回 -1。
另请参见 attributeLocation().
int QOpenGLShaderProgram::uniformLocation(const QString &name) const
这是一个重载函数。
返回统一变量name 在此着色器程序参数列表中的位置。如果name 不是此着色器程序的有效统一变量,则返回 -1。
另请参见 attributeLocation().
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.