1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QGLSHADERPROGRAM_H
43 #define QGLSHADERPROGRAM_H
45 #include <QtOpenGL/qgl.h>
46 #include <QtGui/qvector2d.h>
47 #include <QtGui/qvector3d.h>
48 #include <QtGui/qvector4d.h>
49 #include <QtGui/qmatrix4x4.h>
56 class QGLShaderProgram;
57 class QGLShaderPrivate;
59 class Q_OPENGL_EXPORT QGLShader : public QObject
69 Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)
71 explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0);
72 QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
75 QGLShader::ShaderType shaderType() const;
77 bool compileSourceCode(const char *source);
78 bool compileSourceCode(const QByteArray& source);
79 bool compileSourceCode(const QString& source);
80 bool compileSourceFile(const QString& fileName);
82 QByteArray sourceCode() const;
84 bool isCompiled() const;
87 GLuint shaderId() const;
89 static bool hasOpenGLShaders(ShaderType type, const QGLContext *context = 0);
92 friend class QGLShaderProgram;
94 Q_DISABLE_COPY(QGLShader)
95 Q_DECLARE_PRIVATE(QGLShader)
98 Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType)
101 class QGLShaderProgramPrivate;
103 #ifndef GL_EXT_geometry_shader4
104 # define GL_LINES_ADJACENCY_EXT 0xA
105 # define GL_LINE_STRIP_ADJACENCY_EXT 0xB
106 # define GL_TRIANGLES_ADJACENCY_EXT 0xC
107 # define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0xD
111 class Q_OPENGL_EXPORT QGLShaderProgram : public QObject
115 explicit QGLShaderProgram(QObject *parent = 0);
116 explicit QGLShaderProgram(const QGLContext *context, QObject *parent = 0);
117 virtual ~QGLShaderProgram();
119 bool addShader(QGLShader *shader);
120 void removeShader(QGLShader *shader);
121 QList<QGLShader *> shaders() const;
123 bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source);
124 bool addShaderFromSourceCode(QGLShader::ShaderType type, const QByteArray& source);
125 bool addShaderFromSourceCode(QGLShader::ShaderType type, const QString& source);
126 bool addShaderFromSourceFile(QGLShader::ShaderType type, const QString& fileName);
128 void removeAllShaders();
131 bool isLinked() const;
137 GLuint programId() const;
139 int maxGeometryOutputVertices() const;
141 void setGeometryOutputVertexCount(int count);
142 int geometryOutputVertexCount() const;
144 void setGeometryInputType(GLenum inputType);
145 GLenum geometryInputType() const;
147 void setGeometryOutputType(GLenum outputType);
148 GLenum geometryOutputType() const;
150 void bindAttributeLocation(const char *name, int location);
151 void bindAttributeLocation(const QByteArray& name, int location);
152 void bindAttributeLocation(const QString& name, int location);
154 int attributeLocation(const char *name) const;
155 int attributeLocation(const QByteArray& name) const;
156 int attributeLocation(const QString& name) const;
158 void setAttributeValue(int location, GLfloat value);
159 void setAttributeValue(int location, GLfloat x, GLfloat y);
160 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
161 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
162 void setAttributeValue(int location, const QVector2D& value);
163 void setAttributeValue(int location, const QVector3D& value);
164 void setAttributeValue(int location, const QVector4D& value);
165 void setAttributeValue(int location, const QColor& value);
166 void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
168 void setAttributeValue(const char *name, GLfloat value);
169 void setAttributeValue(const char *name, GLfloat x, GLfloat y);
170 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
171 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
172 void setAttributeValue(const char *name, const QVector2D& value);
173 void setAttributeValue(const char *name, const QVector3D& value);
174 void setAttributeValue(const char *name, const QVector4D& value);
175 void setAttributeValue(const char *name, const QColor& value);
176 void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
178 void setAttributeArray
179 (int location, const GLfloat *values, int tupleSize, int stride = 0);
180 void setAttributeArray
181 (int location, const QVector2D *values, int stride = 0);
182 void setAttributeArray
183 (int location, const QVector3D *values, int stride = 0);
184 void setAttributeArray
185 (int location, const QVector4D *values, int stride = 0);
186 void setAttributeArray
187 (int location, GLenum type, const void *values, int tupleSize, int stride = 0);
188 void setAttributeArray
189 (const char *name, const GLfloat *values, int tupleSize, int stride = 0);
190 void setAttributeArray
191 (const char *name, const QVector2D *values, int stride = 0);
192 void setAttributeArray
193 (const char *name, const QVector3D *values, int stride = 0);
194 void setAttributeArray
195 (const char *name, const QVector4D *values, int stride = 0);
196 void setAttributeArray
197 (const char *name, GLenum type, const void *values, int tupleSize, int stride = 0);
199 void setAttributeBuffer
200 (int location, GLenum type, int offset, int tupleSize, int stride = 0);
201 void setAttributeBuffer
202 (const char *name, GLenum type, int offset, int tupleSize, int stride = 0);
204 void enableAttributeArray(int location);
205 void enableAttributeArray(const char *name);
206 void disableAttributeArray(int location);
207 void disableAttributeArray(const char *name);
209 int uniformLocation(const char *name) const;
210 int uniformLocation(const QByteArray& name) const;
211 int uniformLocation(const QString& name) const;
213 void setUniformValue(int location, GLfloat value);
214 void setUniformValue(int location, GLint value);
215 void setUniformValue(int location, GLuint value);
216 void setUniformValue(int location, GLfloat x, GLfloat y);
217 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
218 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
219 void setUniformValue(int location, const QVector2D& value);
220 void setUniformValue(int location, const QVector3D& value);
221 void setUniformValue(int location, const QVector4D& value);
222 void setUniformValue(int location, const QColor& color);
223 void setUniformValue(int location, const QPoint& point);
224 void setUniformValue(int location, const QPointF& point);
225 void setUniformValue(int location, const QSize& size);
226 void setUniformValue(int location, const QSizeF& size);
227 void setUniformValue(int location, const QMatrix2x2& value);
228 void setUniformValue(int location, const QMatrix2x3& value);
229 void setUniformValue(int location, const QMatrix2x4& value);
230 void setUniformValue(int location, const QMatrix3x2& value);
231 void setUniformValue(int location, const QMatrix3x3& value);
232 void setUniformValue(int location, const QMatrix3x4& value);
233 void setUniformValue(int location, const QMatrix4x2& value);
234 void setUniformValue(int location, const QMatrix4x3& value);
235 void setUniformValue(int location, const QMatrix4x4& value);
236 void setUniformValue(int location, const GLfloat value[2][2]);
237 void setUniformValue(int location, const GLfloat value[3][3]);
238 void setUniformValue(int location, const GLfloat value[4][4]);
239 void setUniformValue(int location, const QTransform& value);
241 void setUniformValue(const char *name, GLfloat value);
242 void setUniformValue(const char *name, GLint value);
243 void setUniformValue(const char *name, GLuint value);
244 void setUniformValue(const char *name, GLfloat x, GLfloat y);
245 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
246 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
247 void setUniformValue(const char *name, const QVector2D& value);
248 void setUniformValue(const char *name, const QVector3D& value);
249 void setUniformValue(const char *name, const QVector4D& value);
250 void setUniformValue(const char *name, const QColor& color);
251 void setUniformValue(const char *name, const QPoint& point);
252 void setUniformValue(const char *name, const QPointF& point);
253 void setUniformValue(const char *name, const QSize& size);
254 void setUniformValue(const char *name, const QSizeF& size);
255 void setUniformValue(const char *name, const QMatrix2x2& value);
256 void setUniformValue(const char *name, const QMatrix2x3& value);
257 void setUniformValue(const char *name, const QMatrix2x4& value);
258 void setUniformValue(const char *name, const QMatrix3x2& value);
259 void setUniformValue(const char *name, const QMatrix3x3& value);
260 void setUniformValue(const char *name, const QMatrix3x4& value);
261 void setUniformValue(const char *name, const QMatrix4x2& value);
262 void setUniformValue(const char *name, const QMatrix4x3& value);
263 void setUniformValue(const char *name, const QMatrix4x4& value);
264 void setUniformValue(const char *name, const GLfloat value[2][2]);
265 void setUniformValue(const char *name, const GLfloat value[3][3]);
266 void setUniformValue(const char *name, const GLfloat value[4][4]);
267 void setUniformValue(const char *name, const QTransform& value);
269 void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize);
270 void setUniformValueArray(int location, const GLint *values, int count);
271 void setUniformValueArray(int location, const GLuint *values, int count);
272 void setUniformValueArray(int location, const QVector2D *values, int count);
273 void setUniformValueArray(int location, const QVector3D *values, int count);
274 void setUniformValueArray(int location, const QVector4D *values, int count);
275 void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
276 void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
277 void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
278 void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
279 void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
280 void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
281 void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
282 void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
283 void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
285 void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize);
286 void setUniformValueArray(const char *name, const GLint *values, int count);
287 void setUniformValueArray(const char *name, const GLuint *values, int count);
288 void setUniformValueArray(const char *name, const QVector2D *values, int count);
289 void setUniformValueArray(const char *name, const QVector3D *values, int count);
290 void setUniformValueArray(const char *name, const QVector4D *values, int count);
291 void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
292 void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
293 void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
294 void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
295 void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
296 void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
297 void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
298 void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
299 void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
301 static bool hasOpenGLShaderPrograms(const QGLContext *context = 0);
304 void shaderDestroyed();
307 Q_DISABLE_COPY(QGLShaderProgram)
308 Q_DECLARE_PRIVATE(QGLShaderProgram)