| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
|---|
| 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 qt-info@nokia.com.
|
|---|
| 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 |
|
|---|
| 51 | QT_BEGIN_HEADER
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | QT_MODULE(OpenGL)
|
|---|
| 56 |
|
|---|
| 57 | #if !defined(QT_OPENGL_ES_1)
|
|---|
| 58 |
|
|---|
| 59 | class QGLShaderProgram;
|
|---|
| 60 | class QGLShaderPrivate;
|
|---|
| 61 |
|
|---|
| 62 | class Q_OPENGL_EXPORT QGLShader : public QObject
|
|---|
| 63 | {
|
|---|
| 64 | Q_OBJECT
|
|---|
| 65 | public:
|
|---|
| 66 | enum ShaderTypeBit
|
|---|
| 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 |
|
|---|
| 97 | Q_DISABLE_COPY(QGLShader)
|
|---|
| 98 | Q_DECLARE_PRIVATE(QGLShader)
|
|---|
| 99 | };
|
|---|
| 100 |
|
|---|
| 101 | Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType)
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | class QGLShaderProgramPrivate;
|
|---|
| 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 |
|
|---|
| 114 | class Q_OPENGL_EXPORT QGLShaderProgram : public QObject
|
|---|
| 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:
|
|---|
| 332 | Q_DISABLE_COPY(QGLShaderProgram)
|
|---|
| 333 | Q_DECLARE_PRIVATE(QGLShaderProgram)
|
|---|
| 334 |
|
|---|
| 335 | bool init();
|
|---|
| 336 | };
|
|---|
| 337 |
|
|---|
| 338 | #endif
|
|---|
| 339 |
|
|---|
| 340 | QT_END_NAMESPACE
|
|---|
| 341 |
|
|---|
| 342 | QT_END_HEADER
|
|---|
| 343 |
|
|---|
| 344 | #endif
|
|---|