Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qopenglshaderprogram.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QOPENGLSHADERPROGRAM_H
6#define QOPENGLSHADERPROGRAM_H
7
8#include <QtCore/qobject.h>
9#include <QtOpenGL/qtopenglglobal.h>
10
11#include <QtGui/qopengl.h>
12#include <QtGui/qvector2d.h>
13#include <QtGui/qvector3d.h>
14#include <QtGui/qvector4d.h>
15#include <QtGui/qmatrix4x4.h>
16
17QT_BEGIN_NAMESPACE
18
19
20class QOpenGLContext;
21class QOpenGLShaderProgram;
23
24class Q_OPENGL_EXPORT QOpenGLShader : public QObject
25{
26 Q_OBJECT
27public:
28 enum ShaderTypeBit
29 {
30 Vertex = 0x0001,
31 Fragment = 0x0002,
32 Geometry = 0x0004,
33 TessellationControl = 0x0008,
34 TessellationEvaluation = 0x0010,
35 Compute = 0x0020
36 };
37 Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)
38
39 explicit QOpenGLShader(QOpenGLShader::ShaderType type, QObject *parent = nullptr);
40 ~QOpenGLShader();
41
42 QOpenGLShader::ShaderType shaderType() const;
43
44 bool compileSourceCode(const char *source);
45 bool compileSourceCode(const QByteArray& source);
46 bool compileSourceCode(const QString& source);
47 bool compileSourceFile(const QString& fileName);
48
49 QByteArray sourceCode() const;
50
51 bool isCompiled() const;
52 QString log() const;
53
54 GLuint shaderId() const;
55
56 static bool hasOpenGLShaders(ShaderType type, QOpenGLContext *context = nullptr);
57
58private:
59 friend class QOpenGLShaderProgram;
60
61 Q_DISABLE_COPY(QOpenGLShader)
62 Q_DECLARE_PRIVATE(QOpenGLShader)
63};
64
65Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLShader::ShaderType)
66
67
68class QOpenGLShaderProgramPrivate;
69
70class Q_OPENGL_EXPORT QOpenGLShaderProgram : public QObject
71{
72 Q_OBJECT
73public:
74 explicit QOpenGLShaderProgram(QObject *parent = nullptr);
75 ~QOpenGLShaderProgram();
76
77 bool addShader(QOpenGLShader *shader);
78 void removeShader(QOpenGLShader *shader);
79 QList<QOpenGLShader *> shaders() const;
80
81 bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source);
82 bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray& source);
83 bool addShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString& source);
84 bool addShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString& fileName);
85
86 bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const char *source);
87 bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QByteArray &source);
88 bool addCacheableShaderFromSourceCode(QOpenGLShader::ShaderType type, const QString &source);
89 bool addCacheableShaderFromSourceFile(QOpenGLShader::ShaderType type, const QString &fileName);
90
91 void removeAllShaders();
92
93 virtual bool link();
94 bool isLinked() const;
95 QString log() const;
96
97 bool bind();
98 void release();
99
100 bool create();
101
102 GLuint programId() const;
103
104 int maxGeometryOutputVertices() const;
105
106 void setPatchVertexCount(int count);
107 int patchVertexCount() const;
108
109 void setDefaultOuterTessellationLevels(const QList<float> &levels);
110 QList<float> defaultOuterTessellationLevels() const;
111
112 void setDefaultInnerTessellationLevels(const QList<float> &levels);
113 QList<float> defaultInnerTessellationLevels() const;
114
115 void bindAttributeLocation(const char *name, int location);
116 void bindAttributeLocation(const QByteArray& name, int location);
117 void bindAttributeLocation(const QString& name, int location);
118
119 int attributeLocation(const char *name) const;
120 int attributeLocation(const QByteArray& name) const;
121 int attributeLocation(const QString& name) const;
122
123 void setAttributeValue(int location, GLfloat value);
124 void setAttributeValue(int location, GLfloat x, GLfloat y);
125 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
126 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
127 void setAttributeValue(int location, const QVector2D& value);
128 void setAttributeValue(int location, const QVector3D& value);
129 void setAttributeValue(int location, const QVector4D& value);
130 void setAttributeValue(int location, const QColor& value);
131 void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
132
133 void setAttributeValue(const char *name, GLfloat value);
134 void setAttributeValue(const char *name, GLfloat x, GLfloat y);
135 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
136 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
137 void setAttributeValue(const char *name, const QVector2D& value);
138 void setAttributeValue(const char *name, const QVector3D& value);
139 void setAttributeValue(const char *name, const QVector4D& value);
140 void setAttributeValue(const char *name, const QColor& value);
141 void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
142
143 void setAttributeArray
144 (int location, const GLfloat *values, int tupleSize, int stride = 0);
145 void setAttributeArray
146 (int location, const QVector2D *values, int stride = 0);
147 void setAttributeArray
148 (int location, const QVector3D *values, int stride = 0);
149 void setAttributeArray
150 (int location, const QVector4D *values, int stride = 0);
151 void setAttributeArray
152 (int location, GLenum type, const void *values, int tupleSize, int stride = 0);
153 void setAttributeArray
154 (const char *name, const GLfloat *values, int tupleSize, int stride = 0);
155 void setAttributeArray
156 (const char *name, const QVector2D *values, int stride = 0);
157 void setAttributeArray
158 (const char *name, const QVector3D *values, int stride = 0);
159 void setAttributeArray
160 (const char *name, const QVector4D *values, int stride = 0);
161 void setAttributeArray
162 (const char *name, GLenum type, const void *values, int tupleSize, int stride = 0);
163
164 void setAttributeBuffer
165 (int location, GLenum type, int offset, int tupleSize, int stride = 0);
166 void setAttributeBuffer
167 (const char *name, GLenum type, int offset, int tupleSize, int stride = 0);
168
169 void enableAttributeArray(int location);
170 void enableAttributeArray(const char *name);
171 void disableAttributeArray(int location);
172 void disableAttributeArray(const char *name);
173
174 int uniformLocation(const char *name) const;
175 int uniformLocation(const QByteArray& name) const;
176 int uniformLocation(const QString& name) const;
177
178 void setUniformValue(int location, GLfloat value);
179 void setUniformValue(int location, GLint value);
180 void setUniformValue(int location, GLuint value);
181 void setUniformValue(int location, GLfloat x, GLfloat y);
182 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
183 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
184 void setUniformValue(int location, const QVector2D& value);
185 void setUniformValue(int location, const QVector3D& value);
186 void setUniformValue(int location, const QVector4D& value);
187 void setUniformValue(int location, const QColor& color);
188 void setUniformValue(int location, const QPoint& point);
189 void setUniformValue(int location, const QPointF& point);
190 void setUniformValue(int location, const QSize& size);
191 void setUniformValue(int location, const QSizeF& size);
192 void setUniformValue(int location, const QMatrix2x2& value);
193 void setUniformValue(int location, const QMatrix2x3& value);
194 void setUniformValue(int location, const QMatrix2x4& value);
195 void setUniformValue(int location, const QMatrix3x2& value);
196 void setUniformValue(int location, const QMatrix3x3& value);
197 void setUniformValue(int location, const QMatrix3x4& value);
198 void setUniformValue(int location, const QMatrix4x2& value);
199 void setUniformValue(int location, const QMatrix4x3& value);
200 void setUniformValue(int location, const QMatrix4x4& value);
201 void setUniformValue(int location, const GLfloat value[2][2]);
202 void setUniformValue(int location, const GLfloat value[3][3]);
203 void setUniformValue(int location, const GLfloat value[4][4]);
204 void setUniformValue(int location, const QTransform& value);
205
206 void setUniformValue(const char *name, GLfloat value);
207 void setUniformValue(const char *name, GLint value);
208 void setUniformValue(const char *name, GLuint value);
209 void setUniformValue(const char *name, GLfloat x, GLfloat y);
210 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
211 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
212 void setUniformValue(const char *name, const QVector2D& value);
213 void setUniformValue(const char *name, const QVector3D& value);
214 void setUniformValue(const char *name, const QVector4D& value);
215 void setUniformValue(const char *name, const QColor& color);
216 void setUniformValue(const char *name, const QPoint& point);
217 void setUniformValue(const char *name, const QPointF& point);
218 void setUniformValue(const char *name, const QSize& size);
219 void setUniformValue(const char *name, const QSizeF& size);
220 void setUniformValue(const char *name, const QMatrix2x2& value);
221 void setUniformValue(const char *name, const QMatrix2x3& value);
222 void setUniformValue(const char *name, const QMatrix2x4& value);
223 void setUniformValue(const char *name, const QMatrix3x2& value);
224 void setUniformValue(const char *name, const QMatrix3x3& value);
225 void setUniformValue(const char *name, const QMatrix3x4& value);
226 void setUniformValue(const char *name, const QMatrix4x2& value);
227 void setUniformValue(const char *name, const QMatrix4x3& value);
228 void setUniformValue(const char *name, const QMatrix4x4& value);
229 void setUniformValue(const char *name, const GLfloat value[2][2]);
230 void setUniformValue(const char *name, const GLfloat value[3][3]);
231 void setUniformValue(const char *name, const GLfloat value[4][4]);
232 void setUniformValue(const char *name, const QTransform& value);
233
234 void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize);
235 void setUniformValueArray(int location, const GLint *values, int count);
236 void setUniformValueArray(int location, const GLuint *values, int count);
237 void setUniformValueArray(int location, const QVector2D *values, int count);
238 void setUniformValueArray(int location, const QVector3D *values, int count);
239 void setUniformValueArray(int location, const QVector4D *values, int count);
240 void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
241 void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
242 void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
243 void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
244 void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
245 void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
246 void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
247 void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
248 void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
249
250 void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize);
251 void setUniformValueArray(const char *name, const GLint *values, int count);
252 void setUniformValueArray(const char *name, const GLuint *values, int count);
253 void setUniformValueArray(const char *name, const QVector2D *values, int count);
254 void setUniformValueArray(const char *name, const QVector3D *values, int count);
255 void setUniformValueArray(const char *name, const QVector4D *values, int count);
256 void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
257 void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
258 void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
259 void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
260 void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
261 void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
262 void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
263 void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
264 void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
265
266 static bool hasOpenGLShaderPrograms(QOpenGLContext *context = nullptr);
267
268private Q_SLOTS:
269 void shaderDestroyed();
270
271private:
272 Q_DISABLE_COPY(QOpenGLShaderProgram)
273 Q_DECLARE_PRIVATE(QOpenGLShaderProgram)
274
275 bool init();
276};
277
278QT_END_NAMESPACE
279
280#endif
QOpenGLSharedResourceGuard * shaderGuard
QOpenGLExtraFunctions * glfuncs
bool compile(QOpenGLShader *q)
QOpenGLSharedResourceGuard * programGuard
bool hasShader(QOpenGLShader::ShaderType type) const
QList< QOpenGLShader * > shaders
QOpenGLProgramBinaryCache::ProgramDesc binaryProgram
QList< QOpenGLShader * > anonShaders
The QOpenGLShaderProgram class allows OpenGL shader programs to be linked and used.
The QOpenGLShader class allows OpenGL shaders to be compiled.
#define GL_GEOMETRY_SHADER
#define GL_TESS_CONTROL_SHADER
#define GL_COMPUTE_SHADER
#define GL_TESS_EVALUATION_SHADER
#define GL_MAX_GEOMETRY_OUTPUT_VERTICES
#define GL_PATCH_VERTICES
#define setUniformGenericMatrixArray(colfunc, location, values, count, type, cols, rows)
static const char qualifierDefines[]
static bool supportsTessellation(const QSurfaceFormat &f)
static QVersionDirectivePosition findVersionDirectivePosition(const char *source)
static QShader::Stage qt_shaderTypeToStage(QOpenGLShader::ShaderType type)
static bool supportsGeometry(const QSurfaceFormat &f)
#define setUniformMatrixArray(func, location, values, count, type, cols, rows)
static QOpenGLShader::ShaderType qt_shaderStageToType(QShader::Stage stage)
static bool supportsCompute(const QSurfaceFormat &f)
static const char blendEquationAdvancedHeader[]
constexpr QVersionDirectivePosition(int position=0, int line=-1)
constexpr bool hasPosition() const