File indexing completed on 2025-02-21 10:12:16
0001
0002
0003
0004 #ifndef QOPENGLSHADERPROGRAM_H
0005 #define QOPENGLSHADERPROGRAM_H
0006
0007 #include <QtCore/qobject.h>
0008 #include <QtOpenGL/qtopenglglobal.h>
0009
0010 #include <QtGui/qopengl.h>
0011 #include <QtGui/qvector2d.h>
0012 #include <QtGui/qvector3d.h>
0013 #include <QtGui/qvector4d.h>
0014 #include <QtGui/qmatrix4x4.h>
0015
0016 QT_BEGIN_NAMESPACE
0017
0018
0019 class QOpenGLContext;
0020 class QOpenGLShaderProgram;
0021 class QOpenGLShaderPrivate;
0022
0023 class Q_OPENGL_EXPORT QOpenGLShader : public QObject
0024 {
0025 Q_OBJECT
0026 public:
0027 enum ShaderTypeBit
0028 {
0029 Vertex = 0x0001,
0030 Fragment = 0x0002,
0031 Geometry = 0x0004,
0032 TessellationControl = 0x0008,
0033 TessellationEvaluation = 0x0010,
0034 Compute = 0x0020
0035 };
0036 Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)
0037
0038 explicit QOpenGLShader(QOpenGLShader::ShaderType type, QObject *parent = nullptr);
0039 ~QOpenGLShader();
0040
0041 QOpenGLShader::ShaderType shaderType() const;
0042
0043 bool compileSourceCode(const char *source);
0044 bool compileSourceCode(const QByteArray& source);
0045 bool compileSourceCode(const QString& source);
0046 bool compileSourceFile(const QString& fileName);
0047
0048 QByteArray sourceCode() const;
0049
0050 bool isCompiled() const;
0051 QString log() const;
0052
0053 GLuint shaderId() const;
0054
0055 static bool hasOpenGLShaders(ShaderType type, QOpenGLContext *context = nullptr);
0056
0057 private:
0058 friend class QOpenGLShaderProgram;
0059
0060 Q_DISABLE_COPY(QOpenGLShader)
0061 Q_DECLARE_PRIVATE(QOpenGLShader)
0062 };
0063
0064 Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLShader::ShaderType)
0065
0066
0067 class QOpenGLShaderProgramPrivate;
0068
0069 class Q_OPENGL_EXPORT QOpenGLShaderProgram : public QObject
0070 {
0071 Q_OBJECT
0072 public:
0073 explicit QOpenGLShaderProgram(QObject *parent = nullptr);
0074 ~QOpenGLShaderProgram();
0075
0076 bool addShader(QOpenGLShader *shader);
0077 void removeShader(QOpenGLShader *shader);
0078 QList<QOpenGLShader *> shaders() const;
0079
0080 bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source);
0081 bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray& source);
0082 bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString& source);
0083 bool addShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString& fileName);
0084
0085 bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source);
0086 bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source);
0087 bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source);
0088 bool addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName);
0089
0090 void removeAllShaders();
0091
0092 virtual bool link();
0093 bool isLinked() const;
0094 QString log() const;
0095
0096 bool bind();
0097 void release();
0098
0099 bool create();
0100
0101 GLuint programId() const;
0102
0103 int maxGeometryOutputVertices() const;
0104
0105 void setPatchVertexCount(int count);
0106 int patchVertexCount() const;
0107
0108 void setDefaultOuterTessellationLevels(const QList<float> &levels);
0109 QList<float> defaultOuterTessellationLevels() const;
0110
0111 void setDefaultInnerTessellationLevels(const QList<float> &levels);
0112 QList<float> defaultInnerTessellationLevels() const;
0113
0114 void bindAttributeLocation(const char *name, int location);
0115 void bindAttributeLocation(const QByteArray& name, int location);
0116 void bindAttributeLocation(const QString& name, int location);
0117
0118 int attributeLocation(const char *name) const;
0119 int attributeLocation(const QByteArray& name) const;
0120 int attributeLocation(const QString& name) const;
0121
0122 void setAttributeValue(int location, GLfloat value);
0123 void setAttributeValue(int location, GLfloat x, GLfloat y);
0124 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
0125 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
0126 void setAttributeValue(int location, const QVector2D& value);
0127 void setAttributeValue(int location, const QVector3D& value);
0128 void setAttributeValue(int location, const QVector4D& value);
0129 void setAttributeValue(int location, const QColor& value);
0130 void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
0131
0132 void setAttributeValue(const char *name, GLfloat value);
0133 void setAttributeValue(const char *name, GLfloat x, GLfloat y);
0134 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
0135 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
0136 void setAttributeValue(const char *name, const QVector2D& value);
0137 void setAttributeValue(const char *name, const QVector3D& value);
0138 void setAttributeValue(const char *name, const QVector4D& value);
0139 void setAttributeValue(const char *name, const QColor& value);
0140 void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
0141
0142 void setAttributeArray
0143 (int location, const GLfloat *values, int tupleSize, int stride = 0);
0144 void setAttributeArray
0145 (int location, const QVector2D *values, int stride = 0);
0146 void setAttributeArray
0147 (int location, const QVector3D *values, int stride = 0);
0148 void setAttributeArray
0149 (int location, const QVector4D *values, int stride = 0);
0150 void setAttributeArray
0151 (int location, GLenum type, const void *values, int tupleSize, int stride = 0);
0152 void setAttributeArray
0153 (const char *name, const GLfloat *values, int tupleSize, int stride = 0);
0154 void setAttributeArray
0155 (const char *name, const QVector2D *values, int stride = 0);
0156 void setAttributeArray
0157 (const char *name, const QVector3D *values, int stride = 0);
0158 void setAttributeArray
0159 (const char *name, const QVector4D *values, int stride = 0);
0160 void setAttributeArray
0161 (const char *name, GLenum type, const void *values, int tupleSize, int stride = 0);
0162
0163 void setAttributeBuffer
0164 (int location, GLenum type, int offset, int tupleSize, int stride = 0);
0165 void setAttributeBuffer
0166 (const char *name, GLenum type, int offset, int tupleSize, int stride = 0);
0167
0168 void enableAttributeArray(int location);
0169 void enableAttributeArray(const char *name);
0170 void disableAttributeArray(int location);
0171 void disableAttributeArray(const char *name);
0172
0173 int uniformLocation(const char *name) const;
0174 int uniformLocation(const QByteArray& name) const;
0175 int uniformLocation(const QString& name) const;
0176
0177 void setUniformValue(int location, GLfloat value);
0178 void setUniformValue(int location, GLint value);
0179 void setUniformValue(int location, GLuint value);
0180 void setUniformValue(int location, GLfloat x, GLfloat y);
0181 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
0182 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
0183 void setUniformValue(int location, const QVector2D& value);
0184 void setUniformValue(int location, const QVector3D& value);
0185 void setUniformValue(int location, const QVector4D& value);
0186 void setUniformValue(int location, const QColor& color);
0187 void setUniformValue(int location, const QPoint& point);
0188 void setUniformValue(int location, const QPointF& point);
0189 void setUniformValue(int location, const QSize& size);
0190 void setUniformValue(int location, const QSizeF& size);
0191 void setUniformValue(int location, const QMatrix2x2& value);
0192 void setUniformValue(int location, const QMatrix2x3& value);
0193 void setUniformValue(int location, const QMatrix2x4& value);
0194 void setUniformValue(int location, const QMatrix3x2& value);
0195 void setUniformValue(int location, const QMatrix3x3& value);
0196 void setUniformValue(int location, const QMatrix3x4& value);
0197 void setUniformValue(int location, const QMatrix4x2& value);
0198 void setUniformValue(int location, const QMatrix4x3& value);
0199 void setUniformValue(int location, const QMatrix4x4& value);
0200 void setUniformValue(int location, const GLfloat value[2][2]);
0201 void setUniformValue(int location, const GLfloat value[3][3]);
0202 void setUniformValue(int location, const GLfloat value[4][4]);
0203 void setUniformValue(int location, const QTransform& value);
0204
0205 void setUniformValue(const char *name, GLfloat value);
0206 void setUniformValue(const char *name, GLint value);
0207 void setUniformValue(const char *name, GLuint value);
0208 void setUniformValue(const char *name, GLfloat x, GLfloat y);
0209 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
0210 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
0211 void setUniformValue(const char *name, const QVector2D& value);
0212 void setUniformValue(const char *name, const QVector3D& value);
0213 void setUniformValue(const char *name, const QVector4D& value);
0214 void setUniformValue(const char *name, const QColor& color);
0215 void setUniformValue(const char *name, const QPoint& point);
0216 void setUniformValue(const char *name, const QPointF& point);
0217 void setUniformValue(const char *name, const QSize& size);
0218 void setUniformValue(const char *name, const QSizeF& size);
0219 void setUniformValue(const char *name, const QMatrix2x2& value);
0220 void setUniformValue(const char *name, const QMatrix2x3& value);
0221 void setUniformValue(const char *name, const QMatrix2x4& value);
0222 void setUniformValue(const char *name, const QMatrix3x2& value);
0223 void setUniformValue(const char *name, const QMatrix3x3& value);
0224 void setUniformValue(const char *name, const QMatrix3x4& value);
0225 void setUniformValue(const char *name, const QMatrix4x2& value);
0226 void setUniformValue(const char *name, const QMatrix4x3& value);
0227 void setUniformValue(const char *name, const QMatrix4x4& value);
0228 void setUniformValue(const char *name, const GLfloat value[2][2]);
0229 void setUniformValue(const char *name, const GLfloat value[3][3]);
0230 void setUniformValue(const char *name, const GLfloat value[4][4]);
0231 void setUniformValue(const char *name, const QTransform& value);
0232
0233 void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize);
0234 void setUniformValueArray(int location, const GLint *values, int count);
0235 void setUniformValueArray(int location, const GLuint *values, int count);
0236 void setUniformValueArray(int location, const QVector2D *values, int count);
0237 void setUniformValueArray(int location, const QVector3D *values, int count);
0238 void setUniformValueArray(int location, const QVector4D *values, int count);
0239 void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
0240 void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
0241 void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
0242 void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
0243 void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
0244 void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
0245 void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
0246 void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
0247 void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
0248
0249 void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize);
0250 void setUniformValueArray(const char *name, const GLint *values, int count);
0251 void setUniformValueArray(const char *name, const GLuint *values, int count);
0252 void setUniformValueArray(const char *name, const QVector2D *values, int count);
0253 void setUniformValueArray(const char *name, const QVector3D *values, int count);
0254 void setUniformValueArray(const char *name, const QVector4D *values, int count);
0255 void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
0256 void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
0257 void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
0258 void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
0259 void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
0260 void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
0261 void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
0262 void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
0263 void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
0264
0265 static bool hasOpenGLShaderPrograms(QOpenGLContext *context = nullptr);
0266
0267 private Q_SLOTS:
0268 void shaderDestroyed();
0269
0270 private:
0271 Q_DISABLE_COPY(QOpenGLShaderProgram)
0272 Q_DECLARE_PRIVATE(QOpenGLShaderProgram)
0273
0274 bool init();
0275 };
0276
0277 QT_END_NAMESPACE
0278
0279 #endif