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