本页内容

QOpenGLShaderProgram Class

QOpenGLShaderProgram 类允许链接和使用 OpenGL 着色器程序。更多内容...

头文件: #include <QOpenGLShaderProgram>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpenGL)
target_link_libraries(mytarget PRIVATE Qt6::OpenGL)
qmake: QT += opengl
继承自: QObject

公共函数

QOpenGLShaderProgram(QObject*parent= nullptr)
虚拟 ~QOpenGLShaderProgram()
bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const char*source)
bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QByteArray&source)
bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType类型, const QString&源)
bool addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypetype, const QString&fileName)
bool addShader(QOpenGLShader*shader)
bool addShaderFromSourceCode(QOpenGLShader::ShaderType类型, const char*源代码)
bool addShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QByteArray&source)
bool addShaderFromSourceCode(QOpenGLShader::ShaderTypetype, const QString&source)
bool addShaderFromSourceFile(QOpenGLShader::ShaderTypetype, const QString&fileName)
int attributeLocation(const char*name) const
int attributeLocation(const QByteArray&name) const
int 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() const
QList<float> defaultOuterTessellationLevels() const
void disableAttributeArray(int位置)
void disableAttributeArray(const char*name)
void enableAttributeArray(int位置)
void enableAttributeArray(const char*name)
bool isLinked() const
虚拟 bool link()
QString log() const
int maxGeometryOutputVertices() const
int patchVertexCount() const
GLuint programId() const
void release()
void removeAllShaders()
void removeShader(QOpenGLShader*shader)
void setAttributeArray(int位置, const QVector2D*值, int步长= 0)
void setAttributeArray(intlocation, const QVector3D*values, intstride= 0)
void setAttributeArray(int位置, const QVector4D*值, int步长= 0)
void setAttributeArray(int位置, const GLfloat*值, int元组大小, int步长= 0)
void setAttributeArray(int位置, GLenum类型, const void*值, int元组大小, int步长= 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(int位置, GLenum类型, int偏移量, int元组大小, int步长= 0)
void setAttributeBuffer(const char*name, GLenumtype, intoffset, inttupleSize, intstride= 0)
void setAttributeValue(int位置, GLfloat值)
void setAttributeValue(int位置, const QColor&值)
void setAttributeValue(int位置, const QVector2D&值)
void setAttributeValue(int位置, const QVector3D&值)
void setAttributeValue(int位置, const QVector4D&值)
void setAttributeValue(int位置, GLfloatx, GLfloaty)
void setAttributeValue(int位置, GLfloatx, GLfloaty, GLfloatz)
void setAttributeValue(int位置, const GLfloat*值, int列数, int行数)
void setAttributeValue(int位置, GLfloatx, GLfloaty, GLfloatz, GLfloatw)
void setAttributeValue(const char*name, GLfloatvalue)
void setAttributeValue(const char*name, const QColor&value)
void setAttributeValue(const char*name, const QVector2D&value)
void setAttributeValue(const char*name, const 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(const char*name, const 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(int位置, GLfloat值)
void setUniformValue(int位置, GLint值)
void setUniformValue(const char*name, const QMatrix3x4&value)
void setUniformValue(const char*name, const QMatrix4x2&value)
void setUniformValue(const char*name, const QMatrix4x3&value)
void setUniformValue(const char*name, const QMatrix4x4&value)
void 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(int位置, const GLfloat[2][2]值)
void setUniformValue(int位置, const GLfloat[3][3]值)
void setUniformValue(int位置, const GLfloat[4][4]值)
void setUniformValue(const char*name, GLfloatx, GLfloaty)
void setUniformValue(const char*name, GLfloatx, GLfloaty, GLfloatz)
void setUniformValue(const char*name, GLfloatx, GLfloaty, GLfloatz, GLfloatw)
void setUniformValue(int位置, GLuint值)
void setUniformValue(int位置, const QColor&颜色)
void setUniformValue(int位置, const QMatrix2x2&值)
void setUniformValue(int位置, const QMatrix2x3&值)
void setUniformValue(int位置, const QMatrix2x4&值)
void setUniformValue(int位置, const QMatrix2x2&值)
void setUniformValue(int位置, const QMatrix3x3&值)
void setUniformValue(int位置, const QMatrix3x4&值)
void setUniformValue(int位置, const QMatrix3x2&值)
void setUniformValue(int位置, const QMatrix4x3&值)
void setUniformValue(int位置, const QMatrix4x4&值)
void setUniformValue(int位置, const QPoint&点)
void setUniformValue(int位置, const QPointF&点)
void setUniformValue(int位置, const QSize&大小)
void setUniformValue(int位置, const QSizeF&大小)
void setUniformValue(int位置, const QTransform&值)
void setUniformValue(int位置, const QVector2D&值)
void setUniformValue(int位置, const QVector3D&值)
void setUniformValue(int位置, const QVector4D&值)
void setUniformValue(int位置, GLfloatx, GLfloaty)
void setUniformValue(int位置, GLfloatx, GLfloaty, GLfloatz)
void setUniformValue(int位置, GLfloatx, GLfloaty, GLfloatz, GLfloatw)
void setUniformValue(const char*name, GLfloatvalue)
void setUniformValue(const char*name, GLintvalue)
void setUniformValue(const char*name, GLuintvalue)
void setUniformValue(const char*name, const GLfloat[2][2]value)
void setUniformValue(const char*name, const GLfloat[3][3]value)
void 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)
void setUniformValue(const char*name, const QMatrix3x2&value)
void setUniformValue(const char*name, const QMatrix3x3&value)
void setUniformValueArray(int位置, const GLint*值, int计数)
void setUniformValueArray(int位置, const GLuint*值, int计数)
void setUniformValueArray(int位置, const QMatrix2x2*值, int计数)
void setUniformValueArray(int位置, const QMatrix2x3*值, int计数)
void setUniformValueArray(int位置, const QMatrix2x4*值, int计数)
void setUniformValueArray(int位置, const QMatrix3x2*值, int计数)
void setUniformValueArray(int位置, const QMatrix3x3*值, int计数)
void setUniformValueArray(int位置, const QMatrix3x4*值, int计数)
void setUniformValueArray(int位置, const QMatrix4x2*值, int计数)
void setUniformValueArray(int位置, const QMatrix4x3*值, int计数)
void setUniformValueArray(int位置, const QMatrix4x4*值, int计数)
void setUniformValueArray(int位置, const QVector2D*值, int计数)
void setUniformValueArray(int位置, const QVector3D*值, int计数)
void setUniformValueArray(int位置, const QVector4D*值, int计数)
void setUniformValueArray(int位置, const GLfloat*值, int计数, int元组大小)
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)
void setUniformValueArray(const char*name, const QMatrix2x4*values, intcount)
void setUniformValueArray(const char*name, const QMatrix3x2*values, intcount)
void setUniformValueArray(const char*name, const QMatrix3x3*values, intcount)
void setUniformValueArray(const char*name, const QMatrix3x4*values, intcount)
void setUniformValueArray(const char*name, const QMatrix4x2*values, intcount)
void setUniformValueArray(const char*name, const QMatrix4x3*values, intcount)
void setUniformValueArray(const char*name, const QMatrix4x4*values, intcount)
void 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(const char*name, const GLfloat*values, intcount, inttupleSize)
QList<QOpenGLShader *> shaders() const
int uniformLocation(const char*name) const
int uniformLocation(const QByteArray&name) const
int uniformLocation(const QString&name) const

静态公共成员

bool hasOpenGLShaderPrograms(QOpenGLContext *context = nullptr)

详细说明

简介

该类支持用 OpenGL 着色语言 (GLSL) 和 OpenGL/ES 着色语言 (GLSL/ES) 编写的光栅着色器程序。

QOpenGLShader 和 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);

二进制着色器与程序

二进制着色器可通过在QOpenGLShader::shaderId()的返回值上调用glShaderBinary() 来指定。随后,可将包含该二进制的QOpenGLShader 实例使用addShader()添加到着色器程序中,并按常规方式通过link()进行链接。

二进制程序可通过在programId()的返回值上调用glProgramBinaryOES() 来指定。随后,应用程序应调用link(),该函数会检测到程序已指定并链接完毕,从而允许对着色器程序执行其他操作。着色器程序的ID可通过create()函数显式创建。

程序二进制文件的缓存

从 Qt 5.9 开始,系统内置了将程序二进制文件缓存到磁盘的功能。 要启用此功能,请改用addCacheableShaderFromSourceCode() 和addCacheableShaderFromSourceFile()。在 OpenGL ES 3.x 上下文中或支持GL_ARB_get_program_binary 时,这将透明地将程序二进制文件缓存到QStandardPaths::CacheLocation 下。当不支持时,调用可缓存的函数变体与调用普通函数变体效果相同。

注意:某些 驱动程序即使声明支持该扩展或提供 OpenGL ES 3.0,也可能不提供任何二进制格式。在这种情况下,程序二进制支持将被禁用。

安全注意事项

Qt OpenGLShaderProgram 处理的所有数据均应为可信内容。着色器源代码(可能经过微小修改后)将传递给底层 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着色器磁盘缓存的程序二进制文件。这通常会显著提升性能。

如果着色器已注册,或者在未缓存的情况下已成功编译,则返回 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着色器磁盘缓存的程序二进制文件。这通常会显著提升性能。

如果着色器已注册,或者在未缓存的情况下已成功编译,则返回 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着色器磁盘缓存的程序二进制文件。这通常会显著提升性能。

当磁盘缓存被禁用(例如通过Qt::AA_DisableShaderDiskCache )或 OpenGL 上下文不支持上下文二进制文件时,调用此函数等同于调用addShaderFromSourceCode()。

这是一个重载函数。

另请参阅 addShaderFromSourceCode() 和addCacheableShaderFromSourceFile()。

bool QOpenGLShaderProgram::addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName)

将指定type 和fileName 的着色器注册到该程序中。与addShaderFromSourceFile()不同,此函数不会执行编译。编译操作将推迟到link()中进行,并且可能根本不会发生,因为link()可能会使用来自Qt着色器磁盘缓存的程序二进制文件。这通常会显著提升性能。

如果文件已成功读取,则返回 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()。

另请参阅 link() 和release()。

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()。

将使用addShader()添加到该程序中的着色器进行链接。如果链接成功,则返回true ;否则返回false。如果链接失败,可通过log()获取错误信息。

子类可以重写此函数,以初始化特定着色器程序中要使用的属性和统一变量。

如果着色器程序已链接,再次调用此函数将强制其重新链接。

当通过addCacheableShaderFromSourceCode() 或addCacheableShaderFromSourceFile() 将着色器添加到该程序时,如果支持程序二进制文件,且磁盘上存在缓存的二进制文件,则会跳过实际的编译和链接过程。取而代之的是,link() 将通过 glProgramBinary() 使用二进制数据块初始化该程序。 如果不存在该程序的缓存版本,或者该程序是使用不同驱动程序版本生成的,则将从源代码编译着色器,并按常规方式链接程序。这使得图形驱动程序能够无缝升级,无需担心二进制格式可能出现的不兼容问题。

另请参阅 addShader() 和log()。

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 对象是在外部创建的,则不会被删除。由QOpenGLShaderProgram 在内部创建的QOpenGLShader 对象将被删除。

另请参阅 addShader() 和removeShader()。

void QOpenGLShaderProgram::removeShader(QOpenGLShader *shader)

从该着色器程序中移除shader 。该对象不会被删除。

该着色器程序必须在当前的QOpenGLContext 中有效。

另请参阅 addShader()、link() 和removeAllShaders()。

void QOpenGLShaderProgram::setAttributeArray(int location, const QVector2D *values, int stride = 0)

在本着色器程序中,将一个二维顶点数组values 设置到location 属性上。stride 表示相邻顶点之间的字节数。默认的stride 值为零,表示顶点在values 中以密集方式排列。

当在location 上调用enableAttributeArray() 时,该数组将生效。否则,将使用setAttributeValue() 为location 指定的值。

另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray(),以及disableAttributeArray()。

void QOpenGLShaderProgram::setAttributeArray(int location, const QVector3D *values, int stride = 0)

在本着色器程序中,将一个包含3D顶点values 的数组设置到location 处的属性上。stride 表示相邻顶点之间的字节数。默认的stride 值为零,表示顶点在values 中以密集方式排列。

当对location 调用enableAttributeArray() 时,该数组将生效。否则,将使用通过setAttributeValue() 为location 指定的值。

另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray(),以及disableAttributeArray()。

void QOpenGLShaderProgram::setAttributeArray(int location, const QVector4D *values, int stride = 0)

在本着色器程序中,将一个 4D 顶点数组values 设置到属性location 上。stride 表示相邻顶点之间的字节数。默认值stride 为零,表示顶点在values 中以密集方式排列。

当对location 调用enableAttributeArray() 时,该数组将生效。否则,将使用通过setAttributeValue() 为location 指定的值。

另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray(),以及disableAttributeArray()。

void QOpenGLShaderProgram::setAttributeArray(int location, const GLfloat *values, int tupleSize, int stride = 0)

在本着色器程序中,将顶点数组values 设置到location 属性上。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)

在本着色器程序中,将顶点values 数组设置到location 属性上。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)

在该着色器程序中,将一个二维顶点数组values 设置到名为name 的属性上。stride 表示相邻顶点之间的字节数。默认的stride 值为零,表示顶点在values 中以密集方式排列。

当对name 调用enableAttributeArray()时,该数组将生效。否则,将使用通过setAttributeValue()为name 指定的值。

这是一个重载函数。

另请参阅 setAttributeValue()、setUniformValue()、enableAttributeArray() 和disableAttributeArray()。

void QOpenGLShaderProgram::setAttributeArray(const char *name, const QVector3D *values, int stride = 0)

在该着色器程序中,将名为name 的属性设置为一个包含3D顶点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)

在此着色器程序中,将顶点数组values 设置到名为name 的属性上。tupleSize 表示每个顶点的分量数(1、2、3或4),stride 表示相邻顶点之间的字节数。默认的stride 值为0,表示顶点在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)

在该着色器程序中,将顶点values 数组设置到名为name 的属性上。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)

在此着色器程序中,将顶点值数组设置到location 处的属性上,从当前绑定的顶点缓冲区中指定的offset 开始。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)

在该着色器程序中,将顶点值数组设置到名为name 的属性上,从当前绑定的顶点缓冲区中的特定offset 开始。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 的属性设置为 2D 向量 (x,y)。

另请参阅 setUniformValue()。

void QOpenGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z)

将当前上下文中location 的属性设置为 3D 向量 (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 处的属性设置为4维向量(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 的属性设置为三维向量(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 指定补丁(patch)中顶点的数量,以便调用 `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 的uniform变量设置为3×4矩阵value 。

注意:此 函数不支持非方阵,即现代 OpenGL 版本中存在的 mat3x4 等 GLSL 类型。相反,它将该统一变量视为一个 vec4 数组。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2 &value)

将当前上下文中名为name 的uniform变量设置为4x2矩阵value 。

注意:该 函数不支持非方阵,即现代 OpenGL 版本中存在的 mat4x2 等 GLSL 类型。相反,它将该统一变量视为一个 vec2 数组。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3 &value)

将当前上下文中名为name 的uniform变量设置为4x3矩阵value 。

注意:该 函数不支持非方阵,即现代 OpenGL 版本中存在的 mat4x3 等 GLSL 类型。相反,它将该统一变量视为一个 vec3 数组。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4 &value)

将当前上下文中名为name 的统一变量设置为4×4矩阵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 关联的uniform变量设置为给定size 的宽度和高度。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QSizeF &size)

将当前上下文中与name 关联的uniform变量设置为给定size 的宽度和高度。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QTransform &value)

将当前上下文中名为name 的统一变量设置为3x3变换矩阵value ,该矩阵以QTransform 值的形式指定。

若要在着色器中将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 处的uniform变量设置为2×2矩阵value 。矩阵元素必须按列优先顺序指定。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const GLfloat[3][3] value)

将当前上下文中位于location 处的uniform变量设置为3×3矩阵value 。矩阵元素必须按列优先顺序指定。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const GLfloat[4][4] value)

将当前上下文中位于location 处的uniform变量设置为4×4矩阵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 的统一变量设置为三维向量(x,y,z )。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)

将当前上下文中名为name 的统一变量设置为4维向量(x 、y 、z 、w )。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, GLuint value)

将当前上下文中位于location 处的uniform变量设置为value 。在设置采样器值时应使用此函数。

注意:该函数 不支持现代 OpenGL 版本中的无符号整数(unsigned int),因此将 `value ` 视为 `GLint` 并调用 `glUniform1i`。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QColor &color)

将当前上下文中位于location 的 uniform 变量设置为color 的红、绿、蓝和透明度分量。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x2 &value)

将当前上下文中location 处的uniform变量设置为2×2矩阵value 。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x3 &value)

将当前上下文中位于location 处的uniform变量设置为2x3矩阵value 。

注意:该函数 不支持非方阵,即现代 OpenGL 版本中存在的 mat2x3 等 GLSL 类型。相反,它将该 uniform 视为一个 vec3 数组。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x4 &value)

将当前上下文中位于location 处的uniform变量设置为2×4矩阵value 。

注意:该函数 不支持非方阵,即现代 OpenGL 版本中存在的 GLSL 类型(如 mat2x4)。相反,它将该 uniform 视为一个 vec4 数组。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x2 &value)

将当前上下文中位于location 处的uniform变量设置为3×2矩阵value 。

注意:该函数 不支持非方阵(即现代 OpenGL 版本中存在的 mat3x2 等 GLSL 类型)。相反,它将该 uniform 视为一个 vec2 数组。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x3 &value)

将当前上下文中位于location 的统一变量设置为 3×3 矩阵value 。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x4 &value)

将当前上下文中位于location 处的uniform变量设置为3x4矩阵value 。

注意:该函数 不支持非方阵,即现代 OpenGL 版本中存在的 mat3x4 等 GLSL 类型。相反,它将该 uniform 视为一个 vec4 数组。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x2 &value)

将当前上下文中位于location 处的uniform变量设置为4x2矩阵value 。

注意:该函数 不支持非方阵,即现代 OpenGL 版本中存在的 GLSL 类型(如 mat4x2)。相反,它将该 uniform 视为一个 vec2 数组。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x3 &value)

将当前上下文中位于location 处的uniform变量设置为4x3矩阵value 。

注意:该函数 不支持非方阵,即现代 OpenGL 版本中存在的 mat4x3 等 GLSL 类型。相反,它将该 uniform 视为一个 vec3 数组。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x4 &value)

将当前上下文中位于location 的统一变量设置为 4×4 矩阵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 的 uniform 变量设置为给定size 的宽度和高度。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QSizeF &size)

将当前上下文中位于location 的 uniform 变量设置为给定size 的宽度和高度。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QTransform &value)

将当前上下文中位于location 处的uniform变量设置为3x3变换矩阵value ,该矩阵以QTransform 值的形式指定。

若要在着色器中将QTransform 的值设置为4x4矩阵,请使用setUniformValue(location, QMatrix4x4(value)) 。

void QOpenGLShaderProgram::setUniformValue(int location, const QVector2D &value)

将当前上下文中位于location 的 uniform 变量设置为value 。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QVector3D &value)

将当前上下文中位于location 的 uniform 变量设置为value 。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(int location, const QVector4D &value)

将当前上下文中location 处的uniform变量设置为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 处的uniform变量设置为3维向量(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 版本中的无符号整数(unsigned int),因此将 `value ` 视为 `GLint` 并调用 `glUniform1i`。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const GLfloat[2][2] value)

将当前上下文中名为name 的统一变量设置为2×2矩阵value 。矩阵元素必须按列优先顺序指定。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const GLfloat[3][3] value)

将当前上下文中名为name 的统一变量设置为3×3矩阵value 。矩阵元素必须按列优先顺序指定。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const GLfloat[4][4] value)

将当前上下文中名为name 的统一变量设置为4×4矩阵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 的统一变量设置为2×2矩阵value 。

这是一个重载函数。

另请参见 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3 &value)

将当前上下文中名为name 的uniform变量设置为2×3矩阵value 。

注意:该 函数不支持非方阵,即现代 OpenGL 版本中存在的 mat2x3 等 GLSL 类型。相反,它将该统一变量视为一个 vec3 数组。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4 &value)

将当前上下文中名为name 的uniform变量设置为2×4矩阵value 。

注意:该 函数不支持非方阵,即现代 OpenGL 版本中存在的 mat2x4 等 GLSL 类型。相反,它将该统一变量视为一个 vec4 数组。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2 &value)

将当前上下文中名为name 的uniform变量设置为3×2矩阵value 。

注意:该 函数不支持非方阵,即现代 OpenGL 版本中存在的 mat3x2 等 GLSL 类型。相反,它将该统一变量视为一个 vec2 数组。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3 &value)

将当前上下文中名为name 的统一变量设置为一个3×3矩阵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 版本中的无符号整型,因此将 `values ` 视为 `GLint` 并调用 `glUniform1iv`。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为count 的 2×2 矩阵元素,其值为values 。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为values 的count 个 2×3 矩阵元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为values 的count 个 2×4 矩阵元素。

另请参见 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为values 的count 个 3×2 矩阵元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为values 的count 个 3×3 矩阵元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *values, int count)

将当前上下文中位于location 处的均匀变量数组设置为values 的count 个3×4矩阵元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为count 中的values 的 4×2 矩阵元素。

另请参见 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为values 的count 个 4×3 矩阵元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *values, int count)

将当前上下文中位于location 的均匀变量数组设置为values 的count 个 4×4 矩阵元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count)

将当前上下文中位于location 的统一变量数组设置为values 的count 个二维向量元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count)

将当前上下文中位于location 的统一变量数组设置为values 的count 个三维向量元素。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(int location, const QVector4D *values, int count)

将当前上下文中位于location 处的uniform变量数组设置为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 个2×2矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x3 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 个2×3矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix2x4 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 个2×4矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x2 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 个3×2矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x3 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 3×3矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix3x4 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 3×4矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x2 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 个4×2矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x3 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 个4×3矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QMatrix4x4 *values, int count)

将当前上下文中名为name 的均匀变量数组设置为values 的count 个4×4矩阵元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *values, int count)

将当前上下文中名为name 的统一变量数组设置为values 的count 个二维向量元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QVector3D *values, int count)

将当前上下文中名为name 的统一变量数组设置为values 的count 个3维向量元素。

这是一个重载函数。

另请参阅 setAttributeValue()。

void QOpenGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *values, int count)

将当前上下文中名为name 的uniform变量数组设置为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()。

© 2026 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.