QOpenGLShaderProgram Class

The QOpenGLShaderProgram class allows OpenGL shader programs to be linked and used. 更多...

头文件: #include <QOpenGLShaderProgram>
qmake: QT += gui
开始支持版本: Qt 5.0
基类: QObject

公有函数

QOpenGLShaderProgram(QObject *parent = Q_NULLPTR)
virtual ~QOpenGLShaderProgram()
bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)
bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)
bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)
bool addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName)
bool addShader(QOpenGLShader *shader)
bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)
bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)
bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)
bool addShaderFromSourceFile(QOpenGLShader::ShaderType type, 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, int location)
void bindAttributeLocation(const QByteArray &name, int location)
void bindAttributeLocation(const QString &name, int location)
bool create()
QVector<float> defaultInnerTessellationLevels() const
QVector<float> defaultOuterTessellationLevels() const
void disableAttributeArray(int location)
void disableAttributeArray(const char *name)
void enableAttributeArray(int location)
void enableAttributeArray(const char *name)
bool isLinked() const
virtual 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 location, const GLfloat *values, int tupleSize, int stride = 0)
void setAttributeArray(int location, const QVector2D *values, int stride = 0)
void setAttributeArray(int location, const QVector3D *values, int stride = 0)
void setAttributeArray(int location, const QVector4D *values, int stride = 0)
void setAttributeArray(int location, GLenum type, const void *values, int tupleSize, int stride = 0)
void setAttributeArray(const char *name, const GLfloat *values, int tupleSize, int stride = 0)
void setAttributeArray(const char *name, const QVector2D *values, int stride = 0)
void setAttributeArray(const char *name, const QVector3D *values, int stride = 0)
void setAttributeArray(const char *name, const QVector4D *values, int stride = 0)
void setAttributeArray(const char *name, GLenum type, const void *values, int tupleSize, int stride = 0)
void setAttributeBuffer(int location, GLenum type, int offset, int tupleSize, int stride = 0)
void setAttributeBuffer(const char *name, GLenum type, int offset, int tupleSize, int stride = 0)
void setAttributeValue(int location, GLfloat value)
void setAttributeValue(int location, GLfloat x, GLfloat y)
void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z)
void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
void setAttributeValue(int location, const QVector2D &value)
void setAttributeValue(int location, const QVector3D &value)
void setAttributeValue(int location, const QVector4D &value)
void setAttributeValue(int location, const QColor &value)
void setAttributeValue(int location, const GLfloat *values, int columns, int rows)
void setAttributeValue(const char *name, GLfloat value)
void setAttributeValue(const char *name, GLfloat x, GLfloat y)
void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z)
void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
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, const QColor &value)
void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows)
void setDefaultInnerTessellationLevels(const QVector<float> &levels)
void setDefaultOuterTessellationLevels(const QVector<float> &levels)
void setPatchVertexCount(int count)
void setUniformValue(int location, GLfloat value)
void setUniformValue(int location, GLint value)
void setUniformValue(const char *name, const QColor &color)
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 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 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 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 QTransform &value)
void setUniformValue(int location, GLuint value)
void setUniformValue(int location, GLfloat x, GLfloat y)
void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z)
void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
void setUniformValue(int location, const QVector2D &value)
void setUniformValue(int location, const QVector3D &value)
void setUniformValue(int location, const QVector4D &value)
void setUniformValue(int location, const QColor &color)
void setUniformValue(int location, const QPoint &point)
void setUniformValue(int location, const QPointF &point)
void setUniformValue(int location, const QSize &size)
void setUniformValue(int location, const QSizeF &size)
void setUniformValue(int location, const QMatrix2x2 &value)
void setUniformValue(int location, const QMatrix2x3 &value)
void setUniformValue(int location, const QMatrix2x4 &value)
void setUniformValue(int location, const QMatrix3x2 &value)
void setUniformValue(int location, const QMatrix3x3 &value)
void setUniformValue(int location, const QMatrix3x4 &value)
void setUniformValue(int location, const QMatrix4x2 &value)
void setUniformValue(int location, const QMatrix4x3 &value)
void setUniformValue(int location, const QMatrix4x4 &value)
void setUniformValue(int location, const GLfloat[2][2] value)
void setUniformValue(int location, const GLfloat[3][3] value)
void setUniformValue(int location, const GLfloat[4][4] value)
void setUniformValue(int location, const QTransform &value)
void setUniformValue(const char *name, GLfloat value)
void setUniformValue(const char *name, GLint value)
void setUniformValue(const char *name, GLuint value)
void setUniformValue(const char *name, GLfloat x, GLfloat y)
void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z)
void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
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 setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize)
void setUniformValueArray(int location, const GLint *values, int count)
void setUniformValueArray(int location, const GLuint *values, int count)
void setUniformValueArray(int location, const QVector2D *values, int count)
void setUniformValueArray(int location, const QVector3D *values, int count)
void setUniformValueArray(int location, const QVector4D *values, int count)
void setUniformValueArray(int location, const QMatrix2x2 *values, int count)
void setUniformValueArray(int location, const QMatrix2x3 *values, int count)
void setUniformValueArray(int location, const QMatrix2x4 *values, int count)
void setUniformValueArray(int location, const QMatrix3x2 *values, int count)
void setUniformValueArray(int location, const QMatrix3x3 *values, int count)
void setUniformValueArray(int location, const QMatrix3x4 *values, int count)
void setUniformValueArray(int location, const QMatrix4x2 *values, int count)
void setUniformValueArray(int location, const QMatrix4x3 *values, int count)
void setUniformValueArray(int location, const QMatrix4x4 *values, int count)
void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize)
void setUniformValueArray(const char *name, const GLint *values, int count)
void setUniformValueArray(const char *name, const GLuint *values, int count)
void setUniformValueArray(const char *name, const QVector2D *values, int count)
void setUniformValueArray(const char *name, const QVector3D *values, int count)
void setUniformValueArray(const char *name, const QVector4D *values, int count)
void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count)
void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count)
void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count)
void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count)
void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count)
void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count)
void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count)
void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count)
void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count)
QList<QOpenGLShader *> shaders() const
int uniformLocation(const char *name) const
int uniformLocation(const QByteArray &name) const
int uniformLocation(const QString &name) const
  • 32 个公有函数继承自 QObject

静态公有成员

bool hasOpenGLShaderPrograms(QOpenGLContext *context = Q_NULLPTR)
  • 10 个静态公有成员继承自 QObject

其他继承的成员

  • 1 个属性继承自 QObject
  • 1 个公有槽函数继承自 QObject
  • 2 个信号继承自 QObject
  • 1 个公有变量继承自 QObject
  • 9 个受保护的函数继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

The QOpenGLShaderProgram class allows OpenGL shader programs to be linked and used.

Introduction

此类支持以OpenGL着色语言 (GLSL) 和 OpenGL/ES着色语言 (OpenGL/ES) 编写的着色器程序.

QOpenGLShaderQOpenGLShaderProgram 使程序员免于编译和链接顶点和片段着色器的细节.

下面的示例使用提供的源代码创建一个顶点着色器程序. 一旦编译和链接, 着色器程序通过 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() 的返回值指定二进制着色器. 然后可以使用 addShader() 将包含二进制文件的 QOpenGLShader 实例添加到着色器程序中, 并使用 link() 以通常的方式链接.

可以使用 programId() glProgramBinaryOES() 的返回值指定二进制程序. 然后应用程序应该调用 link(), 它会注意到程序已经被指定和链接, 允许对着色器程序执行其他操作. 着色器程序的id可以使用 create() 函数显示创建.

缓存程序二进制

从Qt5.9开始, 内置了对在磁盘上缓存程序二进制文件的支持. 要启用此功能, 请切换到使用 addCacheableShaderFromSourceCode() 和 addCacheableShaderFromSourceFile(). 使用 OpenGL ES 3.x 上下文或支持 GL_ARB_get_program_binary, 这将透明地缓存 QStandardPaths::GenericCacheLocationQStandardPaths::CacheLocation 下的程序二进制文件. 当支持不可用时, 调用可缓存的函数变体等同于正常的变体.

注意: 一些驱动程序没有任何可用的二进制格式, 即使它们宣传扩展或提供 OpenGL ES 3.0. 在这种情况下, 程序二进制支持将被禁用.

参见 QOpenGLShader.

成员函数

QOpenGLShaderProgram::QOpenGLShaderProgram(QObject *parent = Q_NULLPTR)

Constructs a new shader program and attaches it to parent. The program will be invalid until addShader() is called.

The shader program will be associated with the current QOpenGLContext.

参见 addShader().

[virtual] QOpenGLShaderProgram::~QOpenGLShaderProgram()

Deletes this shader program.

bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)

Registers the shader of the specified type and source to this program. Unlike addShaderFromSourceCode(), this function does not perform compilation. Compilation is deferred to link(), and may not happen at all, because link() may potentially use a program binary from Qt's shader disk cache. This will typically lead to a significant increase in performance.

Returns true if the shader has been registered or, in the non-cached case, compiled successfully; false if there was an error. The compilation error messages can be retrieved via log().

When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for example, or the OpenGL context has no support for context binaries, calling this function is equivalent to addShaderFromSourceCode().

This function was introduced in Qt 5.9.

参见 addShaderFromSourceCode() and addCacheableShaderFromSourceFile().

bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)

This is an overloaded function.

Registers the shader of the specified type and source to this program. Unlike addShaderFromSourceCode(), this function does not perform compilation. Compilation is deferred to link(), and may not happen at all, because link() may potentially use a program binary from Qt's shader disk cache. This will typically lead to a significant increase in performance.

Returns true if the shader has been registered or, in the non-cached case, compiled successfully; false if there was an error. The compilation error messages can be retrieved via log().

When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for example, or the OpenGL context has no support for context binaries, calling this function is equivalent to addShaderFromSourceCode().

This function was introduced in Qt 5.9.

参见 addShaderFromSourceCode() and addCacheableShaderFromSourceFile().

bool QOpenGLShaderProgram::addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)

This is an overloaded function.

Registers the shader of the specified type and source to this program. Unlike addShaderFromSourceCode(), this function does not perform compilation. Compilation is deferred to link(), and may not happen at all, because link() may potentially use a program binary from Qt's shader disk cache. This will typically lead to a significant increase in performance.

When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for example, or the OpenGL context has no support for context binaries, calling this function is equivalent to addShaderFromSourceCode().

This function was introduced in Qt 5.9.

参见 addShaderFromSourceCode() and addCacheableShaderFromSourceFile().

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

Registers the shader of the specified type and fileName to this program. Unlike addShaderFromSourceFile(), this function does not perform compilation. Compilation is deferred to link(), and may not happen at all, because link() may potentially use a program binary from Qt's shader disk cache. This will typically lead to a significant increase in performance.

Returns true if the file has been read successfully, false if the file could not be opened or the normal, non-cached compilation of the shader has failed. The compilation error messages can be retrieved via log().

When the disk cache is disabled, via Qt::AA_DisableShaderDiskCache for example, or the OpenGL context has no support for context binaries, calling this function is equivalent to addShaderFromSourceFile().

This function was introduced in Qt 5.9.

参见 addShaderFromSourceFile() and addCacheableShaderFromSourceCode().

bool QOpenGLShaderProgram::addShader(QOpenGLShader *shader)

Adds a compiled shader to this shader program. Returns true if the shader could be added, or false otherwise.

Ownership of the shader object remains with the caller. It will not be deleted when this QOpenGLShaderProgram instance is deleted. This allows the caller to add the same shader to multiple shader programs.

参见 addShaderFromSourceCode(), addShaderFromSourceFile(), removeShader(), link(), and removeAllShaders().

bool QOpenGLShaderProgram::addShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source)

Compiles source as a shader of the specified type and adds it to this shader program. Returns true if compilation was successful, false otherwise. The compilation errors and warnings will be made available via log().

This function is intended to be a short-cut for quickly adding vertex and fragment shaders to a shader program without creating an instance of QOpenGLShader first.

参见 addShader(), addShaderFromSourceFile(), removeShader(), link(), log(), and removeAllShaders().

bool QOpenGLShaderProgram::addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source)

This is an overloaded function.

Compiles source as a shader of the specified type and adds it to this shader program. Returns true if compilation was successful, false otherwise. The compilation errors and warnings will be made available via log().

This function is intended to be a short-cut for quickly adding vertex and fragment shaders to a shader program without creating an instance of QOpenGLShader first.

参见 addShader(), addShaderFromSourceFile(), removeShader(), link(), log(), and removeAllShaders().

bool QOpenGLShaderProgram::addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source)

This is an overloaded function.

Compiles source as a shader of the specified type and adds it to this shader program. Returns true if compilation was successful, false otherwise. The compilation errors and warnings will be made available via log().

This function is intended to be a short-cut for quickly adding vertex and fragment shaders to a shader program without creating an instance of QOpenGLShader first.

参见 addShader(), addShaderFromSourceFile(), removeShader(), link(), log(), and removeAllShaders().

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

Compiles the contents of fileName as a shader of the specified type and adds it to this shader program. Returns true if compilation was successful, false otherwise. The compilation errors and warnings will be made available via log().

This function is intended to be a short-cut for quickly adding vertex and fragment shaders to a shader program without creating an instance of QOpenGLShader first.

参见 addShader() and addShaderFromSourceCode().

int QOpenGLShaderProgram::attributeLocation(const char *name) const

Returns the location of the attribute name within this shader program's parameter list. Returns -1 if name is not a valid attribute for this shader program.

参见 uniformLocation() and bindAttributeLocation().

int QOpenGLShaderProgram::attributeLocation(const QByteArray &name) const

This is an overloaded function.

Returns the location of the attribute name within this shader program's parameter list. Returns -1 if name is not a valid attribute for this shader program.

参见 uniformLocation() and bindAttributeLocation().

int QOpenGLShaderProgram::attributeLocation(const QString &name) const

This is an overloaded function.

Returns the location of the attribute name within this shader program's parameter list. Returns -1 if name is not a valid attribute for this shader program.

参见 uniformLocation() and bindAttributeLocation().

bool QOpenGLShaderProgram::bind()

Binds this shader program to the active QOpenGLContext and makes it the current shader program. Any previously bound shader program is released. This is equivalent to calling glUseProgram() on programId(). Returns true if the program was successfully bound; false otherwise. If the shader program has not yet been linked, or it needs to be re-linked, this function will call link().

参见 link() and release().

void QOpenGLShaderProgram::bindAttributeLocation(const char *name, int location)

Binds the attribute name to the specified location. This function can be called before or after the program has been linked. Any attributes that have not been explicitly bound when the program is linked will be assigned locations automatically.

When this function is called after the program has been linked, the program will need to be relinked for the change to take effect.

参见 attributeLocation().

void QOpenGLShaderProgram::bindAttributeLocation(const QByteArray &name, int location)

This is an overloaded function.

Binds the attribute name to the specified location. This function can be called before or after the program has been linked. Any attributes that have not been explicitly bound when the program is linked will be assigned locations automatically.

When this function is called after the program has been linked, the program will need to be relinked for the change to take effect.

参见 attributeLocation().

void QOpenGLShaderProgram::bindAttributeLocation(const QString &name, int location)

This is an overloaded function.

Binds the attribute name to the specified location. This function can be called before or after the program has been linked. Any attributes that have not been explicitly bound when the program is linked will be assigned locations automatically.

When this function is called after the program has been linked, the program will need to be relinked for the change to take effect.

参见 attributeLocation().

bool QOpenGLShaderProgram::create()

Requests the shader program's id to be created immediately. Returns true if successful; false otherwise.

This function is primarily useful when combining QOpenGLShaderProgram with other OpenGL functions that operate directly on the shader program id, like GL_OES_get_program_binary.

When the shader program is used normally, the shader program's id will be created on demand.

This function was introduced in Qt 5.3.

参见 programId().

QVector<float> QOpenGLShaderProgram::defaultInnerTessellationLevels() const

Returns the default inner tessellation levels to be used by the tessellation primitive generator in the event that the tessellation control shader does not output them. For more details on OpenGL and Tessellation shaders see OpenGL Tessellation Shaders.

Returns a QVector of floats describing the inner tessellation levels. The vector will always have two elements but not all of them make sense for every mode of tessellation.

Note: This returns the global OpenGL state value. It is not specific to this QOpenGLShaderProgram instance.

参见 setDefaultInnerTessellationLevels() and defaultOuterTessellationLevels().

QVector<float> QOpenGLShaderProgram::defaultOuterTessellationLevels() const

Returns the default outer tessellation levels to be used by the tessellation primitive generator in the event that the tessellation control shader does not output them. For more details on OpenGL and Tessellation shaders see OpenGL Tessellation Shaders.

Returns a QVector of floats describing the outer tessellation levels. The vector will always have four elements but not all of them make sense for every mode of tessellation.

Note: This returns the global OpenGL state value. It is not specific to this QOpenGLShaderProgram instance.

参见 setDefaultOuterTessellationLevels() and defaultInnerTessellationLevels().

void QOpenGLShaderProgram::disableAttributeArray(int location)

Disables the vertex array at location in this shader program that was enabled by a previous call to enableAttributeArray().

参见 enableAttributeArray(), setAttributeArray(), setAttributeValue(), and setUniformValue().

void QOpenGLShaderProgram::disableAttributeArray(const char *name)

This is an overloaded function.

Disables the vertex array called name in this shader program that was enabled by a previous call to enableAttributeArray().

参见 enableAttributeArray(), setAttributeArray(), setAttributeValue(), and setUniformValue().

void QOpenGLShaderProgram::enableAttributeArray(int location)

Enables the vertex array at location in this shader program so that the value set by setAttributeArray() on location will be used by the shader program.

参见 disableAttributeArray(), setAttributeArray(), setAttributeValue(), and setUniformValue().

void QOpenGLShaderProgram::enableAttributeArray(const char *name)

This is an overloaded function.

Enables the vertex array called name in this shader program so that the value set by setAttributeArray() on name will be used by the shader program.

参见 disableAttributeArray(), setAttributeArray(), setAttributeValue(), and setUniformValue().

[static] bool QOpenGLShaderProgram::hasOpenGLShaderPrograms(QOpenGLContext *context = Q_NULLPTR)

Returns true if shader programs written in the OpenGL Shading Language (GLSL) are supported on this system; false otherwise.

The context is used to resolve the GLSL extensions. If context is null, then QOpenGLContext::currentContext() is used.

bool QOpenGLShaderProgram::isLinked() const

Returns true if this shader program has been linked; false otherwise.

参见 link().

Links together the shaders that were added to this program with addShader(). Returns true if the link was successful or false otherwise. If the link failed, the error messages can be retrieved with log().

Subclasses can override this function to initialize attributes and uniform variables for use in specific shader programs.

If the shader program was already linked, calling this function again will force it to be re-linked.

When shaders were added to this program via addCacheableShaderFromSourceCode() or addCacheableShaderFromSourceFile(), program binaries are supported, and a cached binary is available on disk, actual compilation and linking are skipped. Instead, link() will initialize the program with the binary blob via glProgramBinary(). If there is no cached version of the program or it was generated with a different driver version, the shaders will be compiled from source and the program will get linked normally. This allows seamless upgrading of the graphics drivers, without having to worry about potentially incompatible binary formats.

参见 addShader() and log().

QString QOpenGLShaderProgram::log() const

Returns the errors and warnings that occurred during the last link() or addShader() with explicitly specified source code.

参见 link().

int QOpenGLShaderProgram::maxGeometryOutputVertices() const

Returns the hardware limit for how many vertices a geometry shader can output.

int QOpenGLShaderProgram::patchVertexCount() const

Returns the number of vertices per-patch to be used when rendering.

Note: This returns the global OpenGL state value. It is not specific to this QOpenGLShaderProgram instance.

参见 setPatchVertexCount().

GLuint QOpenGLShaderProgram::programId() const

Returns the OpenGL identifier associated with this shader program.

参见 QOpenGLShader::shaderId().

void QOpenGLShaderProgram::release()

Releases the active shader program from the current QOpenGLContext. This is equivalent to calling glUseProgram(0).

参见 bind().

void QOpenGLShaderProgram::removeAllShaders()

Removes all of the shaders that were added to this program previously. The QOpenGLShader objects for the shaders will not be deleted if they were constructed externally. QOpenGLShader objects that are constructed internally by QOpenGLShaderProgram will be deleted.

参见 addShader() and removeShader().

void QOpenGLShaderProgram::removeShader(QOpenGLShader *shader)

Removes shader from this shader program. The object is not deleted.

The shader program must be valid in the current QOpenGLContext.

参见 addShader(), link(), and removeAllShaders().

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

Sets an array of vertex values on the attribute at location in this shader program. The tupleSize indicates the number of components per vertex (1, 2, 3, or 4), and the stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on the location. Otherwise the value specified with setAttributeValue() for location will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

Sets an array of 2D vertex values on the attribute at location in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on the location. Otherwise the value specified with setAttributeValue() for location will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

Sets an array of 3D vertex values on the attribute at location in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on the location. Otherwise the value specified with setAttributeValue() for location will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

Sets an array of 4D vertex values on the attribute at location in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on the location. Otherwise the value specified with setAttributeValue() for location will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

Sets an array of vertex values on the attribute at location in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The type indicates the type of elements in the values array, usually GL_FLOAT, GL_UNSIGNED_BYTE, etc. The tupleSize indicates the number of components per vertex: 1, 2, 3, or 4.

The array will become active when enableAttributeArray() is called on the location. Otherwise the value specified with setAttributeValue() for location will be used.

The setAttributeBuffer() function can be used to set the attribute array to an offset within a vertex buffer.

Note: Normalization will be enabled. If this is not desired, call glVertexAttribPointer directly through QOpenGLFunctions.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), disableAttributeArray(), and setAttributeBuffer().

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

This is an overloaded function.

Sets an array of vertex values on the attribute called name in this shader program. The tupleSize indicates the number of components per vertex (1, 2, 3, or 4), and the stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on name. Otherwise the value specified with setAttributeValue() for name will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

This is an overloaded function.

Sets an array of 2D vertex values on the attribute called name in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on name. Otherwise the value specified with setAttributeValue() for name will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

This is an overloaded function.

Sets an array of 3D vertex values on the attribute called name in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on name. Otherwise the value specified with setAttributeValue() for name will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

This is an overloaded function.

Sets an array of 4D vertex values on the attribute called name in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The array will become active when enableAttributeArray() is called on name. Otherwise the value specified with setAttributeValue() for name will be used.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), and disableAttributeArray().

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

This is an overloaded function.

Sets an array of vertex values on the attribute called name in this shader program. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in values.

The type indicates the type of elements in the values array, usually GL_FLOAT, GL_UNSIGNED_BYTE, etc. The tupleSize indicates the number of components per vertex: 1, 2, 3, or 4.

The array will become active when enableAttributeArray() is called on the name. Otherwise the value specified with setAttributeValue() for name will be used.

The setAttributeBuffer() function can be used to set the attribute array to an offset within a vertex buffer.

参见 setAttributeValue(), setUniformValue(), enableAttributeArray(), disableAttributeArray(), and setAttributeBuffer().

void QOpenGLShaderProgram::setAttributeBuffer(int location, GLenum type, int offset, int tupleSize, int stride = 0)

Sets an array of vertex values on the attribute at location in this shader program, starting at a specific offset in the currently bound vertex buffer. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in the value array.

The type indicates the type of elements in the vertex value array, usually GL_FLOAT, GL_UNSIGNED_BYTE, etc. The tupleSize indicates the number of components per vertex: 1, 2, 3, or 4.

The array will become active when enableAttributeArray() is called on the location. Otherwise the value specified with setAttributeValue() for location will be used.

Note: Normalization will be enabled. If this is not desired, call glVertexAttribPointer directly through QOpenGLFunctions.

参见 setAttributeArray().

void QOpenGLShaderProgram::setAttributeBuffer(const char *name, GLenum type, int offset, int tupleSize, int stride = 0)

This is an overloaded function.

Sets an array of vertex values on the attribute called name in this shader program, starting at a specific offset in the currently bound vertex buffer. The stride indicates the number of bytes between vertices. A default stride value of zero indicates that the vertices are densely packed in the value array.

The type indicates the type of elements in the vertex value array, usually GL_FLOAT, GL_UNSIGNED_BYTE, etc. The tupleSize indicates the number of components per vertex: 1, 2, 3, or 4.

The array will become active when enableAttributeArray() is called on the name. Otherwise the value specified with setAttributeValue() for name will be used.

参见 setAttributeArray().

void QOpenGLShaderProgram::setAttributeValue(int location, GLfloat value)

Sets the attribute at location in the current context to value.

参见 setUniformValue().

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

Sets the attribute at location in the current context to the 2D vector (x, y).

参见 setUniformValue().

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

Sets the attribute at location in the current context to the 3D vector (x, y, z).

参见 setUniformValue().

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

Sets the attribute at location in the current context to the 4D vector (x, y, z, w).

参见 setUniformValue().

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

Sets the attribute at location in the current context to value.

参见 setUniformValue().

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

Sets the attribute at location in the current context to value.

参见 setUniformValue().

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

Sets the attribute at location in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(int location, const QColor &value)

Sets the attribute at location in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(int location, const GLfloat *values, int columns, int rows)

Sets the attribute at location in the current context to the contents of values, which contains columns elements, each consisting of rows elements. The rows value should be 1, 2, 3, or 4. This function is typically used to set matrix values and column vectors.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, GLfloat value)

This is an overloaded function.

Sets the attribute called name in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, GLfloat x, GLfloat y)

This is an overloaded function.

Sets the attribute called name in the current context to the 2D vector (x, y).

参见 setUniformValue().

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

This is an overloaded function.

Sets the attribute called name in the current context to the 3D vector (x, y, z).

参见 setUniformValue().

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

This is an overloaded function.

Sets the attribute called name in the current context to the 4D vector (x, y, z, w).

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, const QVector2D &value)

This is an overloaded function.

Sets the attribute called name in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, const QVector3D &value)

This is an overloaded function.

Sets the attribute called name in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, const QVector4D &value)

This is an overloaded function.

Sets the attribute called name in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, const QColor &value)

This is an overloaded function.

Sets the attribute called name in the current context to value.

参见 setUniformValue().

void QOpenGLShaderProgram::setAttributeValue(const char *name, const GLfloat *values, int columns, int rows)

This is an overloaded function.

Sets the attribute called name in the current context to the contents of values, which contains columns elements, each consisting of rows elements. The rows value should be 1, 2, 3, or 4. This function is typically used to set matrix values and column vectors.

参见 setUniformValue().

void QOpenGLShaderProgram::setDefaultInnerTessellationLevels(const QVector<float> &levels)

Sets the default outer tessellation levels to be used by the tessellation primitive generator in the event that the tessellation control shader does not output them to levels. For more details on OpenGL and Tessellation shaders see OpenGL Tessellation Shaders.

The levels argument should be a QVector consisting of 2 floats. Not all of the values make sense for all tessellation modes. If you specify a vector with fewer than 2 elements, the remaining elements will be given a default value of 1.

Note: This modifies global OpenGL state and is not specific to this QOpenGLShaderProgram instance. You should call this in your render function when needed, as QOpenGLShaderProgram will not apply this for you. This is purely a convenience function.

参见 defaultInnerTessellationLevels() and setDefaultOuterTessellationLevels().

void QOpenGLShaderProgram::setDefaultOuterTessellationLevels(const QVector<float> &levels)

Sets the default outer tessellation levels to be used by the tessellation primitive generator in the event that the tessellation control shader does not output them to levels. For more details on OpenGL and Tessellation shaders see OpenGL Tessellation Shaders.

The levels argument should be a QVector consisting of 4 floats. Not all of the values make sense for all tessellation modes. If you specify a vector with fewer than 4 elements, the remaining elements will be given a default value of 1.

Note: This modifies global OpenGL state and is not specific to this QOpenGLShaderProgram instance. You should call this in your render function when needed, as QOpenGLShaderProgram will not apply this for you. This is purely a convenience function.

参见 defaultOuterTessellationLevels() and setDefaultInnerTessellationLevels().

void QOpenGLShaderProgram::setPatchVertexCount(int count)

Use this function to specify to OpenGL the number of vertices in a patch to count. A patch is a custom OpenGL primitive whose interpretation is entirely defined by the tessellation shader stages. Therefore, calling this function only makes sense when using a QOpenGLShaderProgram containing tessellation stage shaders. When using OpenGL tessellation, the only primitive that can be rendered with glDraw*() functions is GL_PATCHES.

This is equivalent to calling glPatchParameteri(GL_PATCH_VERTICES, count).

Note: This modifies global OpenGL state and is not specific to this QOpenGLShaderProgram instance. You should call this in your render function when needed, as QOpenGLShaderProgram will not apply this for you. This is purely a convenience function.

参见 patchVertexCount().

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

Sets the uniform variable at location in the current context to value.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to value.

参见 setAttributeValue().

void QOpenGLShaderProgram::setUniformValue(const char *name, const QColor &color)

This is an overloaded function.

Sets the uniform variable called name in the current context to the red, green, blue, and alpha components of color.

参见 setAttributeValue().

void QOpenGLShaderProgram::setUniformValue(const char *name, const QPoint &point)

This is an overloaded function.

Sets the uniform variable associated with name in the current context to the x and y coordinates of point.

参见 setAttributeValue().

void QOpenGLShaderProgram::setUniformValue(const char *name, const QPointF &point)

This is an overloaded function.

Sets the uniform variable associated with name in the current context to the x and y coordinates of point.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable associated with name in the current context to the width and height of the given size.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable associated with name in the current context to the width and height of the given size.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 2x2 matrix value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 2x3 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat2x3, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec3.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 2x4 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat2x4, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec4.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 3x2 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat3x2, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec2.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 3x3 matrix value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 3x4 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat3x4, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec4.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 4x2 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat4x2, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec2.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 4x3 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat4x3, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec3.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 4x4 matrix value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 2x2 matrix value. The matrix elements must be specified in column-major order.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 3x3 matrix value. The matrix elements must be specified in column-major order.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 4x4 matrix value. The matrix elements must be specified in column-major order.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to a 3x3 transformation matrix value that is specified as a QTransform value.

To set a QTransform value as a 4x4 matrix in a shader, use setUniformValue(name, QMatrix4x4(value)).

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

Sets the uniform variable at location in the current context to value. This function should be used when setting sampler values.

Note: This function is not aware of unsigned int support in modern OpenGL versions and therefore treats value as a GLint and calls glUniform1i.

参见 setAttributeValue().

void QOpenGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y)

Sets the uniform variable at location in the current context to the 2D vector (x, y).

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to the 3D vector (x, y, z).

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to the 4D vector (x, y, z, w).

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to value.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to value.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to value.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to the red, green, blue, and alpha components of color.

参见 setAttributeValue().

void QOpenGLShaderProgram::setUniformValue(int location, const QPoint &point)

Sets the uniform variable at location in the current context to the x and y coordinates of point.

参见 setAttributeValue().

void QOpenGLShaderProgram::setUniformValue(int location, const QPointF &point)

Sets the uniform variable at location in the current context to the x and y coordinates of point.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to the width and height of the given size.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to the width and height of the given size.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 2x2 matrix value.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 2x3 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat2x3, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec3.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 2x4 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat2x4, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec4.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 3x2 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat3x2, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec2.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 3x3 matrix value.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 3x4 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat3x4, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec4.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 4x2 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat4x2, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec2.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 4x3 matrix value.

Note: This function is not aware of non square matrix support, that is, GLSL types like mat4x3, that is present in modern OpenGL versions. Instead, it treats the uniform as an array of vec3.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 4x4 matrix value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable at location in the current context to a 2x2 matrix value. The matrix elements must be specified in column-major order.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable at location in the current context to a 3x3 matrix value. The matrix elements must be specified in column-major order.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable at location in the current context to a 4x4 matrix value. The matrix elements must be specified in column-major order.

参见 setAttributeValue().

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

Sets the uniform variable at location in the current context to a 3x3 transformation matrix value that is specified as a QTransform value.

To set a QTransform value as a 4x4 matrix in a shader, use setUniformValue(location, QMatrix4x4(value)).

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

This is an overloaded function.

Sets the uniform variable called name in the current context to value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to value. This function should be used when setting sampler values.

Note: This function is not aware of unsigned int support in modern OpenGL versions and therefore treats value as a GLint and calls glUniform1i.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to the 2D vector (x, y).

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to the 3D vector (x, y, z).

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to the 4D vector (x, y, z, w).

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to value.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable called name in the current context to value.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count elements of values. Each element has tupleSize components. The tupleSize must be 1, 2, 3, or 4.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count elements of values. This overload should be used when setting an array of sampler values.

Note: This function is not aware of unsigned int support in modern OpenGL versions and therefore treats values as a GLint and calls glUniform1iv.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 2D vector elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 3D vector elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 4D vector elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 2x2 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 2x3 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 2x4 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 3x2 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 3x3 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 3x4 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 4x2 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 4x3 matrix elements of values.

参见 setAttributeValue().

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

Sets the uniform variable array at location in the current context to the count 4x4 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count elements of values. Each element has tupleSize components. The tupleSize must be 1, 2, 3, or 4.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count elements of values. This overload should be used when setting an array of sampler values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 2D vector elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 3D vector elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 4D vector elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 2x2 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 2x3 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 2x4 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 3x2 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 3x3 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 3x4 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 4x2 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 4x3 matrix elements of values.

参见 setAttributeValue().

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

This is an overloaded function.

Sets the uniform variable array called name in the current context to the count 4x4 matrix elements of values.

参见 setAttributeValue().

QList<QOpenGLShader *> QOpenGLShaderProgram::shaders() const

Returns a list of all shaders that have been added to this shader program using addShader().

参见 addShader() and removeShader().

int QOpenGLShaderProgram::uniformLocation(const char *name) const

Returns the location of the uniform variable name within this shader program's parameter list. Returns -1 if name is not a valid uniform variable for this shader program.

参见 attributeLocation().

int QOpenGLShaderProgram::uniformLocation(const QByteArray &name) const

This is an overloaded function.

Returns the location of the uniform variable name within this shader program's parameter list. Returns -1 if name is not a valid uniform variable for this shader program.

参见 attributeLocation().

int QOpenGLShaderProgram::uniformLocation(const QString &name) const

This is an overloaded function.

Returns the location of the uniform variable name within this shader program's parameter list. Returns -1 if name is not a valid uniform variable for this shader program.

参见 attributeLocation().