Qt 4.8
qglshaderprogram.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QGLSHADERPROGRAM_H
43 #define QGLSHADERPROGRAM_H
44 
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>
50 
52 
54 
56 
57 #if !defined(QT_OPENGL_ES_1)
58 
59 class QGLShaderProgram;
60 class QGLShaderPrivate;
61 
63 {
64  Q_OBJECT
65 public:
67  {
68  Vertex = 0x0001,
69  Fragment = 0x0002,
70  Geometry = 0x0004
71  };
72  Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)
73 
74  explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0);
75  QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
76  virtual ~QGLShader();
77 
78  QGLShader::ShaderType shaderType() const;
79 
80  bool compileSourceCode(const char *source);
81  bool compileSourceCode(const QByteArray& source);
82  bool compileSourceCode(const QString& source);
83  bool compileSourceFile(const QString& fileName);
84 
85  QByteArray sourceCode() const;
86 
87  bool isCompiled() const;
88  QString log() const;
89 
90  GLuint shaderId() const;
91 
92  static bool hasOpenGLShaders(ShaderType type, const QGLContext *context = 0);
93 
94 private:
95  friend class QGLShaderProgram;
96 
99 };
100 
101 Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType)
102 
103 
105 
106 #ifndef GL_EXT_geometry_shader4
107 # define GL_LINES_ADJACENCY_EXT 0xA
108 # define GL_LINE_STRIP_ADJACENCY_EXT 0xB
109 # define GL_TRIANGLES_ADJACENCY_EXT 0xC
110 # define GL_TRIANGLE_STRIP_ADJACENCY_EXT 0xD
111 #endif
112 
113 
115 {
116  Q_OBJECT
117 public:
118  explicit QGLShaderProgram(QObject *parent = 0);
119  explicit QGLShaderProgram(const QGLContext *context, QObject *parent = 0);
120  virtual ~QGLShaderProgram();
121 
122  bool addShader(QGLShader *shader);
123  void removeShader(QGLShader *shader);
124  QList<QGLShader *> shaders() const;
125 
126  bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source);
127  bool addShaderFromSourceCode(QGLShader::ShaderType type, const QByteArray& source);
128  bool addShaderFromSourceCode(QGLShader::ShaderType type, const QString& source);
129  bool addShaderFromSourceFile(QGLShader::ShaderType type, const QString& fileName);
130 
131  void removeAllShaders();
132 
133  virtual bool link();
134  bool isLinked() const;
135  QString log() const;
136 
137  bool bind();
138  void release();
139 
140  GLuint programId() const;
141 
142  int maxGeometryOutputVertices() const;
143 
144  void setGeometryOutputVertexCount(int count);
145  int geometryOutputVertexCount() const;
146 
147  void setGeometryInputType(GLenum inputType);
148  GLenum geometryInputType() const;
149 
150  void setGeometryOutputType(GLenum outputType);
151  GLenum geometryOutputType() const;
152 
153  void bindAttributeLocation(const char *name, int location);
154  void bindAttributeLocation(const QByteArray& name, int location);
155  void bindAttributeLocation(const QString& name, int location);
156 
157  int attributeLocation(const char *name) const;
158  int attributeLocation(const QByteArray& name) const;
159  int attributeLocation(const QString& name) const;
160 
161  void setAttributeValue(int location, GLfloat value);
162  void setAttributeValue(int location, GLfloat x, GLfloat y);
163  void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
164  void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
165  void setAttributeValue(int location, const QVector2D& value);
166  void setAttributeValue(int location, const QVector3D& value);
167  void setAttributeValue(int location, const QVector4D& value);
168  void setAttributeValue(int location, const QColor& value);
169  void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
170 
171  void setAttributeValue(const char *name, GLfloat value);
172  void setAttributeValue(const char *name, GLfloat x, GLfloat y);
173  void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
174  void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
175  void setAttributeValue(const char *name, const QVector2D& value);
176  void setAttributeValue(const char *name, const QVector3D& value);
177  void setAttributeValue(const char *name, const QVector4D& value);
178  void setAttributeValue(const char *name, const QColor& value);
179  void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
180 
181  void setAttributeArray
182  (int location, const GLfloat *values, int tupleSize, int stride = 0);
183  void setAttributeArray
184  (int location, const QVector2D *values, int stride = 0);
185  void setAttributeArray
186  (int location, const QVector3D *values, int stride = 0);
187  void setAttributeArray
188  (int location, const QVector4D *values, int stride = 0);
189  void setAttributeArray
190  (int location, GLenum type, const void *values, int tupleSize, int stride = 0);
191  void setAttributeArray
192  (const char *name, const GLfloat *values, int tupleSize, int stride = 0);
193  void setAttributeArray
194  (const char *name, const QVector2D *values, int stride = 0);
195  void setAttributeArray
196  (const char *name, const QVector3D *values, int stride = 0);
197  void setAttributeArray
198  (const char *name, const QVector4D *values, int stride = 0);
199  void setAttributeArray
200  (const char *name, GLenum type, const void *values, int tupleSize, int stride = 0);
201 
202  void setAttributeBuffer
203  (int location, GLenum type, int offset, int tupleSize, int stride = 0);
204  void setAttributeBuffer
205  (const char *name, GLenum type, int offset, int tupleSize, int stride = 0);
206 
207 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
208  void setAttributeArray
209  (int location, QMacCompatGLenum type, const void *values, int tupleSize, int stride = 0);
210  void setAttributeArray
211  (const char *name, QMacCompatGLenum type, const void *values, int tupleSize, int stride = 0);
212  void setAttributeBuffer
213  (int location, QMacCompatGLenum type, int offset, int tupleSize, int stride = 0);
214  void setAttributeBuffer
215  (const char *name, QMacCompatGLenum type, int offset, int tupleSize, int stride = 0);
216 #endif
217 
218  void enableAttributeArray(int location);
219  void enableAttributeArray(const char *name);
220  void disableAttributeArray(int location);
221  void disableAttributeArray(const char *name);
222 
223  int uniformLocation(const char *name) const;
224  int uniformLocation(const QByteArray& name) const;
225  int uniformLocation(const QString& name) const;
226 
227 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
228  void setUniformValue(int location, QMacCompatGLint value);
229  void setUniformValue(int location, QMacCompatGLuint value);
230  void setUniformValue(const char *name, QMacCompatGLint value);
231  void setUniformValue(const char *name, QMacCompatGLuint value);
232  void setUniformValueArray(int location, const QMacCompatGLint *values, int count);
233  void setUniformValueArray(int location, const QMacCompatGLuint *values, int count);
234  void setUniformValueArray(const char *name, const QMacCompatGLint *values, int count);
235  void setUniformValueArray(const char *name, const QMacCompatGLuint *values, int count);
236 #endif
237 
238  void setUniformValue(int location, GLfloat value);
239  void setUniformValue(int location, GLint value);
240  void setUniformValue(int location, GLuint value);
241  void setUniformValue(int location, GLfloat x, GLfloat y);
242  void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
243  void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
244  void setUniformValue(int location, const QVector2D& value);
245  void setUniformValue(int location, const QVector3D& value);
246  void setUniformValue(int location, const QVector4D& value);
247  void setUniformValue(int location, const QColor& color);
248  void setUniformValue(int location, const QPoint& point);
249  void setUniformValue(int location, const QPointF& point);
250  void setUniformValue(int location, const QSize& size);
251  void setUniformValue(int location, const QSizeF& size);
252  void setUniformValue(int location, const QMatrix2x2& value);
253  void setUniformValue(int location, const QMatrix2x3& value);
254  void setUniformValue(int location, const QMatrix2x4& value);
255  void setUniformValue(int location, const QMatrix3x2& value);
256  void setUniformValue(int location, const QMatrix3x3& value);
257  void setUniformValue(int location, const QMatrix3x4& value);
258  void setUniformValue(int location, const QMatrix4x2& value);
259  void setUniformValue(int location, const QMatrix4x3& value);
260  void setUniformValue(int location, const QMatrix4x4& value);
261  void setUniformValue(int location, const GLfloat value[2][2]);
262  void setUniformValue(int location, const GLfloat value[3][3]);
263  void setUniformValue(int location, const GLfloat value[4][4]);
264  void setUniformValue(int location, const QTransform& value);
265 
266  void setUniformValue(const char *name, GLfloat value);
267  void setUniformValue(const char *name, GLint value);
268  void setUniformValue(const char *name, GLuint value);
269  void setUniformValue(const char *name, GLfloat x, GLfloat y);
270  void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
271  void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
272  void setUniformValue(const char *name, const QVector2D& value);
273  void setUniformValue(const char *name, const QVector3D& value);
274  void setUniformValue(const char *name, const QVector4D& value);
275  void setUniformValue(const char *name, const QColor& color);
276  void setUniformValue(const char *name, const QPoint& point);
277  void setUniformValue(const char *name, const QPointF& point);
278  void setUniformValue(const char *name, const QSize& size);
279  void setUniformValue(const char *name, const QSizeF& size);
280  void setUniformValue(const char *name, const QMatrix2x2& value);
281  void setUniformValue(const char *name, const QMatrix2x3& value);
282  void setUniformValue(const char *name, const QMatrix2x4& value);
283  void setUniformValue(const char *name, const QMatrix3x2& value);
284  void setUniformValue(const char *name, const QMatrix3x3& value);
285  void setUniformValue(const char *name, const QMatrix3x4& value);
286  void setUniformValue(const char *name, const QMatrix4x2& value);
287  void setUniformValue(const char *name, const QMatrix4x3& value);
288  void setUniformValue(const char *name, const QMatrix4x4& value);
289  void setUniformValue(const char *name, const GLfloat value[2][2]);
290  void setUniformValue(const char *name, const GLfloat value[3][3]);
291  void setUniformValue(const char *name, const GLfloat value[4][4]);
292  void setUniformValue(const char *name, const QTransform& value);
293 
294  void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize);
295  void setUniformValueArray(int location, const GLint *values, int count);
296  void setUniformValueArray(int location, const GLuint *values, int count);
297  void setUniformValueArray(int location, const QVector2D *values, int count);
298  void setUniformValueArray(int location, const QVector3D *values, int count);
299  void setUniformValueArray(int location, const QVector4D *values, int count);
300  void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
301  void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
302  void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
303  void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
304  void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
305  void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
306  void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
307  void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
308  void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
309 
310  void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize);
311  void setUniformValueArray(const char *name, const GLint *values, int count);
312  void setUniformValueArray(const char *name, const GLuint *values, int count);
313  void setUniformValueArray(const char *name, const QVector2D *values, int count);
314  void setUniformValueArray(const char *name, const QVector3D *values, int count);
315  void setUniformValueArray(const char *name, const QVector4D *values, int count);
316  void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
317  void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
318  void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
319  void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
320  void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
321  void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
322  void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
323  void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
324  void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
325 
326  static bool hasOpenGLShaderPrograms(const QGLContext *context = 0);
327 
328 private Q_SLOTS:
329  void shaderDestroyed();
330 
331 private:
334 
335  bool init();
336 };
337 
338 #endif
339 
341 
343 
344 #endif
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QGenericMatrix class is a template class that represents a NxM transformation matrix with N colum...
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
#define Q_OPENGL_EXPORT
Definition: qglobal.h:1455
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QVector4D class represents a vector or vertex in 4D space.
Definition: qvector4d.h:60
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
static bool init
const char * name
The QGLShader class allows OpenGL shaders to be compiled.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
The QVector2D class represents a vector or vertex in 2D space.
Definition: qvector2d.h:60
static OSStatus setAttributeValue(EventRef event, const QList< QAElement > &elements)
quint16 values[128]
#define Q_OBJECT
Definition: qobjectdefs.h:157
unsigned int GLenum
Definition: main.cpp:50
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
typedef GLint
Definition: glfunctions.h:67
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
ShaderTypeBit
This enum specifies the type of QGLShader that is being created.
#define QT_END_HEADER
Definition: qglobal.h:137
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
static QString fileName(const QString &fileUrl)
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62