source: trunk/src/opengl/qglshaderprogram.h@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 13.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtOpenGL module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
51QT_BEGIN_HEADER
52
53QT_BEGIN_NAMESPACE
54
55QT_MODULE(OpenGL)
56
57#if !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
58
59class QGLShaderProgram;
60class QGLShaderPrivate;
61
62class Q_OPENGL_EXPORT QGLShader : public QObject
63{
64 Q_OBJECT
65public:
66 enum ShaderTypeBit
67 {
68 Vertex = 0x0001,
69 Fragment = 0x0002
70 };
71 Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)
72
73 explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0);
74 QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
75 virtual ~QGLShader();
76
77 QGLShader::ShaderType shaderType() const;
78
79 bool compileSourceCode(const char *source);
80 bool compileSourceCode(const QByteArray& source);
81 bool compileSourceCode(const QString& source);
82 bool compileSourceFile(const QString& fileName);
83
84 QByteArray sourceCode() const;
85
86 bool isCompiled() const;
87 QString log() const;
88
89 GLuint shaderId() const;
90
91private:
92 friend class QGLShaderProgram;
93
94 Q_DISABLE_COPY(QGLShader)
95 Q_DECLARE_PRIVATE(QGLShader)
96};
97
98Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType)
99
100
101class QGLShaderProgramPrivate;
102
103class Q_OPENGL_EXPORT QGLShaderProgram : public QObject
104{
105 Q_OBJECT
106public:
107 explicit QGLShaderProgram(QObject *parent = 0);
108 explicit QGLShaderProgram(const QGLContext *context, QObject *parent = 0);
109 virtual ~QGLShaderProgram();
110
111 bool addShader(QGLShader *shader);
112 void removeShader(QGLShader *shader);
113 QList<QGLShader *> shaders() const;
114
115 bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source);
116 bool addShaderFromSourceCode(QGLShader::ShaderType type, const QByteArray& source);
117 bool addShaderFromSourceCode(QGLShader::ShaderType type, const QString& source);
118 bool addShaderFromSourceFile(QGLShader::ShaderType type, const QString& fileName);
119
120 void removeAllShaders();
121
122 virtual bool link();
123 bool isLinked() const;
124 QString log() const;
125
126 bool bind();
127 void release();
128
129 GLuint programId() const;
130
131 void bindAttributeLocation(const char *name, int location);
132 void bindAttributeLocation(const QByteArray& name, int location);
133 void bindAttributeLocation(const QString& name, int location);
134
135 int attributeLocation(const char *name) const;
136 int attributeLocation(const QByteArray& name) const;
137 int attributeLocation(const QString& name) const;
138
139 void setAttributeValue(int location, GLfloat value);
140 void setAttributeValue(int location, GLfloat x, GLfloat y);
141 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
142 void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
143 void setAttributeValue(int location, const QVector2D& value);
144 void setAttributeValue(int location, const QVector3D& value);
145 void setAttributeValue(int location, const QVector4D& value);
146 void setAttributeValue(int location, const QColor& value);
147 void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
148
149 void setAttributeValue(const char *name, GLfloat value);
150 void setAttributeValue(const char *name, GLfloat x, GLfloat y);
151 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
152 void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
153 void setAttributeValue(const char *name, const QVector2D& value);
154 void setAttributeValue(const char *name, const QVector3D& value);
155 void setAttributeValue(const char *name, const QVector4D& value);
156 void setAttributeValue(const char *name, const QColor& value);
157 void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
158
159 void setAttributeArray
160 (int location, const GLfloat *values, int tupleSize, int stride = 0);
161 void setAttributeArray
162 (int location, const QVector2D *values, int stride = 0);
163 void setAttributeArray
164 (int location, const QVector3D *values, int stride = 0);
165 void setAttributeArray
166 (int location, const QVector4D *values, int stride = 0);
167 void setAttributeArray
168 (const char *name, const GLfloat *values, int tupleSize, int stride = 0);
169 void setAttributeArray
170 (const char *name, const QVector2D *values, int stride = 0);
171 void setAttributeArray
172 (const char *name, const QVector3D *values, int stride = 0);
173 void setAttributeArray
174 (const char *name, const QVector4D *values, int stride = 0);
175
176 void enableAttributeArray(int location);
177 void enableAttributeArray(const char *name);
178 void disableAttributeArray(int location);
179 void disableAttributeArray(const char *name);
180
181 int uniformLocation(const char *name) const;
182 int uniformLocation(const QByteArray& name) const;
183 int uniformLocation(const QString& name) const;
184
185#ifdef Q_MAC_COMPAT_GL_FUNCTIONS
186 void setUniformValue(int location, QMacCompatGLint value);
187 void setUniformValue(int location, QMacCompatGLuint value);
188 void setUniformValue(const char *name, QMacCompatGLint value);
189 void setUniformValue(const char *name, QMacCompatGLuint value);
190 void setUniformValueArray(int location, const QMacCompatGLint *values, int count);
191 void setUniformValueArray(int location, const QMacCompatGLuint *values, int count);
192 void setUniformValueArray(const char *name, const QMacCompatGLint *values, int count);
193 void setUniformValueArray(const char *name, const QMacCompatGLuint *values, int count);
194#endif
195
196 void setUniformValue(int location, GLfloat value);
197 void setUniformValue(int location, GLint value);
198 void setUniformValue(int location, GLuint value);
199 void setUniformValue(int location, GLfloat x, GLfloat y);
200 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
201 void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
202 void setUniformValue(int location, const QVector2D& value);
203 void setUniformValue(int location, const QVector3D& value);
204 void setUniformValue(int location, const QVector4D& value);
205 void setUniformValue(int location, const QColor& color);
206 void setUniformValue(int location, const QPoint& point);
207 void setUniformValue(int location, const QPointF& point);
208 void setUniformValue(int location, const QSize& size);
209 void setUniformValue(int location, const QSizeF& size);
210 void setUniformValue(int location, const QMatrix2x2& value);
211 void setUniformValue(int location, const QMatrix2x3& value);
212 void setUniformValue(int location, const QMatrix2x4& value);
213 void setUniformValue(int location, const QMatrix3x2& value);
214 void setUniformValue(int location, const QMatrix3x3& value);
215 void setUniformValue(int location, const QMatrix3x4& value);
216 void setUniformValue(int location, const QMatrix4x2& value);
217 void setUniformValue(int location, const QMatrix4x3& value);
218 void setUniformValue(int location, const QMatrix4x4& value);
219 void setUniformValue(int location, const GLfloat value[4][4]);
220 void setUniformValue(int location, const QTransform& value);
221
222 void setUniformValue(const char *name, GLfloat value);
223 void setUniformValue(const char *name, GLint value);
224 void setUniformValue(const char *name, GLuint value);
225 void setUniformValue(const char *name, GLfloat x, GLfloat y);
226 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
227 void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
228 void setUniformValue(const char *name, const QVector2D& value);
229 void setUniformValue(const char *name, const QVector3D& value);
230 void setUniformValue(const char *name, const QVector4D& value);
231 void setUniformValue(const char *name, const QColor& color);
232 void setUniformValue(const char *name, const QPoint& point);
233 void setUniformValue(const char *name, const QPointF& point);
234 void setUniformValue(const char *name, const QSize& size);
235 void setUniformValue(const char *name, const QSizeF& size);
236 void setUniformValue(const char *name, const QMatrix2x2& value);
237 void setUniformValue(const char *name, const QMatrix2x3& value);
238 void setUniformValue(const char *name, const QMatrix2x4& value);
239 void setUniformValue(const char *name, const QMatrix3x2& value);
240 void setUniformValue(const char *name, const QMatrix3x3& value);
241 void setUniformValue(const char *name, const QMatrix3x4& value);
242 void setUniformValue(const char *name, const QMatrix4x2& value);
243 void setUniformValue(const char *name, const QMatrix4x3& value);
244 void setUniformValue(const char *name, const QMatrix4x4& value);
245 void setUniformValue(const char *name, const GLfloat value[4][4]);
246 void setUniformValue(const char *name, const QTransform& value);
247
248 void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize);
249 void setUniformValueArray(int location, const GLint *values, int count);
250 void setUniformValueArray(int location, const GLuint *values, int count);
251 void setUniformValueArray(int location, const QVector2D *values, int count);
252 void setUniformValueArray(int location, const QVector3D *values, int count);
253 void setUniformValueArray(int location, const QVector4D *values, int count);
254 void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
255 void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
256 void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
257 void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
258 void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
259 void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
260 void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
261 void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
262 void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
263
264 void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize);
265 void setUniformValueArray(const char *name, const GLint *values, int count);
266 void setUniformValueArray(const char *name, const GLuint *values, int count);
267 void setUniformValueArray(const char *name, const QVector2D *values, int count);
268 void setUniformValueArray(const char *name, const QVector3D *values, int count);
269 void setUniformValueArray(const char *name, const QVector4D *values, int count);
270 void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
271 void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
272 void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
273 void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
274 void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
275 void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
276 void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
277 void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
278 void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
279
280 static bool hasOpenGLShaderPrograms(const QGLContext *context = 0);
281
282private Q_SLOTS:
283 void shaderDestroyed();
284
285private:
286 Q_DISABLE_COPY(QGLShaderProgram)
287 Q_DECLARE_PRIVATE(QGLShaderProgram)
288
289 bool init();
290};
291
292#endif
293
294QT_END_NAMESPACE
295
296QT_END_HEADER
297
298#endif
Note: See TracBrowser for help on using the repository browser.