src/opengl/qglshaderprogram.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    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 
       
    51 QT_BEGIN_HEADER
       
    52 
       
    53 QT_BEGIN_NAMESPACE
       
    54 
       
    55 QT_MODULE(OpenGL)
       
    56 
       
    57 #if !defined(QT_OPENGL_ES_1_CL) && !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 ShaderTypeBits
       
    67     {
       
    68         VertexShader            = 0x0001,
       
    69         FragmentShader          = 0x0002,
       
    70 
       
    71         PartialShader           = 0x1000,
       
    72 
       
    73         PartialVertexShader     = PartialShader | VertexShader,
       
    74         PartialFragmentShader   = PartialShader | FragmentShader
       
    75     };
       
    76     Q_DECLARE_FLAGS(ShaderType, ShaderTypeBits)
       
    77 
       
    78     explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0);
       
    79     QGLShader(const QString& fileName, QGLShader::ShaderType type, QObject *parent = 0);
       
    80     QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
       
    81     QGLShader(const QString& fileName, QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0);
       
    82     virtual ~QGLShader();
       
    83 
       
    84     QGLShader::ShaderType shaderType() const;
       
    85 
       
    86     bool compile(const char *source);
       
    87     bool compile(const QByteArray& source);
       
    88     bool compile(const QString& source);
       
    89     bool compileFile(const QString& fileName);
       
    90 
       
    91     bool setShaderBinary(GLenum format, const void *binary, int length);
       
    92     bool setShaderBinary(QGLShader& otherShader, GLenum format, const void *binary, int length);
       
    93 
       
    94     static QList<GLenum> shaderBinaryFormats();
       
    95 
       
    96     QByteArray sourceCode() const;
       
    97 
       
    98     bool isCompiled() const;
       
    99     QString log() const;
       
   100 
       
   101     GLuint shaderId() const;
       
   102 
       
   103 private:
       
   104     QGLShaderPrivate *d;
       
   105 
       
   106     friend class QGLShaderProgram;
       
   107 
       
   108     Q_DISABLE_COPY(QGLShader)
       
   109 };
       
   110 
       
   111 Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType)
       
   112 
       
   113 
       
   114 class QGLShaderProgramPrivate;
       
   115 
       
   116 class Q_OPENGL_EXPORT QGLShaderProgram : public QObject
       
   117 {
       
   118     Q_OBJECT
       
   119 public:
       
   120     explicit QGLShaderProgram(QObject *parent = 0);
       
   121     explicit QGLShaderProgram(const QGLContext *context, QObject *parent = 0);
       
   122     virtual ~QGLShaderProgram();
       
   123 
       
   124     bool addShader(QGLShader *shader);
       
   125     void removeShader(QGLShader *shader);
       
   126     QList<QGLShader *> shaders() const;
       
   127 
       
   128     bool addShader(QGLShader::ShaderType type, const char *source);
       
   129     bool addShader(QGLShader::ShaderType type, const QByteArray& source);
       
   130     bool addShader(QGLShader::ShaderType type, const QString& source);
       
   131     bool addShaderFromFile(QGLShader::ShaderType type, const QString& fileName);
       
   132 
       
   133     void removeAllShaders();
       
   134 
       
   135     QByteArray programBinary(int *format) const;
       
   136     bool setProgramBinary(int format, const QByteArray& binary);
       
   137     static QList<int> programBinaryFormats();
       
   138 
       
   139     virtual bool link();
       
   140     bool isLinked() const;
       
   141     QString log() const;
       
   142 
       
   143     bool enable();
       
   144     static void disable();
       
   145 
       
   146     GLuint programId() const;
       
   147 
       
   148     void bindAttributeLocation(const char *name, int location);
       
   149     void bindAttributeLocation(const QByteArray& name, int location);
       
   150     void bindAttributeLocation(const QString& name, int location);
       
   151 
       
   152     int attributeLocation(const char *name) const;
       
   153     int attributeLocation(const QByteArray& name) const;
       
   154     int attributeLocation(const QString& name) const;
       
   155 
       
   156     void setAttributeValue(int location, GLfloat value);
       
   157     void setAttributeValue(int location, GLfloat x, GLfloat y);
       
   158     void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z);
       
   159     void setAttributeValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
       
   160     void setAttributeValue(int location, const QVector2D& value);
       
   161     void setAttributeValue(int location, const QVector3D& value);
       
   162     void setAttributeValue(int location, const QVector4D& value);
       
   163     void setAttributeValue(int location, const QColor& value);
       
   164     void setAttributeValue(int location, const GLfloat *values, int columns, int rows);
       
   165 
       
   166     void setAttributeValue(const char *name, GLfloat value);
       
   167     void setAttributeValue(const char *name, GLfloat x, GLfloat y);
       
   168     void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
       
   169     void setAttributeValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
       
   170     void setAttributeValue(const char *name, const QVector2D& value);
       
   171     void setAttributeValue(const char *name, const QVector3D& value);
       
   172     void setAttributeValue(const char *name, const QVector4D& value);
       
   173     void setAttributeValue(const char *name, const QColor& value);
       
   174     void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows);
       
   175 
       
   176     void setAttributeArray
       
   177         (int location, const GLfloat *values, int size, int stride = 0);
       
   178     void setAttributeArray
       
   179         (int location, const QVector2D *values, int stride = 0);
       
   180     void setAttributeArray
       
   181         (int location, const QVector3D *values, int stride = 0);
       
   182     void setAttributeArray
       
   183         (int location, const QVector4D *values, int stride = 0);
       
   184     void setAttributeArray
       
   185         (const char *name, const GLfloat *values, int size, int stride = 0);
       
   186     void setAttributeArray
       
   187         (const char *name, const QVector2D *values, int stride = 0);
       
   188     void setAttributeArray
       
   189         (const char *name, const QVector3D *values, int stride = 0);
       
   190     void setAttributeArray
       
   191         (const char *name, const QVector4D *values, int stride = 0);
       
   192     void disableAttributeArray(int location);
       
   193     void disableAttributeArray(const char *name);
       
   194 
       
   195     int uniformLocation(const char *name) const;
       
   196     int uniformLocation(const QByteArray& name) const;
       
   197     int uniformLocation(const QString& name) const;
       
   198 
       
   199     void setUniformValue(int location, GLfloat value);
       
   200     void setUniformValue(int location, GLint value);
       
   201     void setUniformValue(int location, GLuint value);
       
   202     void setUniformValue(int location, GLfloat x, GLfloat y);
       
   203     void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z);
       
   204     void setUniformValue(int location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
       
   205     void setUniformValue(int location, const QVector2D& value);
       
   206     void setUniformValue(int location, const QVector3D& value);
       
   207     void setUniformValue(int location, const QVector4D& value);
       
   208     void setUniformValue(int location, const QColor& color);
       
   209     void setUniformValue(int location, const QPoint& point);
       
   210     void setUniformValue(int location, const QPointF& point);
       
   211     void setUniformValue(int location, const QSize& size);
       
   212     void setUniformValue(int location, const QSizeF& size);
       
   213     void setUniformValue(int location, const QMatrix2x2& value);
       
   214     void setUniformValue(int location, const QMatrix2x3& value);
       
   215     void setUniformValue(int location, const QMatrix2x4& value);
       
   216     void setUniformValue(int location, const QMatrix3x2& value);
       
   217     void setUniformValue(int location, const QMatrix3x3& value);
       
   218     void setUniformValue(int location, const QMatrix3x4& value);
       
   219     void setUniformValue(int location, const QMatrix4x2& value);
       
   220     void setUniformValue(int location, const QMatrix4x3& value);
       
   221     void setUniformValue(int location, const QMatrix4x4& value);
       
   222     void setUniformValue(int location, const GLfloat value[4][4]);
       
   223     void setUniformValue(int location, const QTransform& value);
       
   224 
       
   225     void setUniformValue(const char *name, GLfloat value);
       
   226     void setUniformValue(const char *name, GLint value);
       
   227     void setUniformValue(const char *name, GLuint value);
       
   228     void setUniformValue(const char *name, GLfloat x, GLfloat y);
       
   229     void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z);
       
   230     void setUniformValue(const char *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
       
   231     void setUniformValue(const char *name, const QVector2D& value);
       
   232     void setUniformValue(const char *name, const QVector3D& value);
       
   233     void setUniformValue(const char *name, const QVector4D& value);
       
   234     void setUniformValue(const char *name, const QColor& color);
       
   235     void setUniformValue(const char *name, const QPoint& point);
       
   236     void setUniformValue(const char *name, const QPointF& point);
       
   237     void setUniformValue(const char *name, const QSize& size);
       
   238     void setUniformValue(const char *name, const QSizeF& size);
       
   239     void setUniformValue(const char *name, const QMatrix2x2& value);
       
   240     void setUniformValue(const char *name, const QMatrix2x3& value);
       
   241     void setUniformValue(const char *name, const QMatrix2x4& value);
       
   242     void setUniformValue(const char *name, const QMatrix3x2& value);
       
   243     void setUniformValue(const char *name, const QMatrix3x3& value);
       
   244     void setUniformValue(const char *name, const QMatrix3x4& value);
       
   245     void setUniformValue(const char *name, const QMatrix4x2& value);
       
   246     void setUniformValue(const char *name, const QMatrix4x3& value);
       
   247     void setUniformValue(const char *name, const QMatrix4x4& value);
       
   248     void setUniformValue(const char *name, const GLfloat value[4][4]);
       
   249     void setUniformValue(const char *name, const QTransform& value);
       
   250 
       
   251     void setUniformValueArray(int location, const GLfloat *values, int count, int size);
       
   252     void setUniformValueArray(int location, const GLint *values, int count);
       
   253     void setUniformValueArray(int location, const GLuint *values, int count);
       
   254     void setUniformValueArray(int location, const QVector2D *values, int count);
       
   255     void setUniformValueArray(int location, const QVector3D *values, int count);
       
   256     void setUniformValueArray(int location, const QVector4D *values, int count);
       
   257     void setUniformValueArray(int location, const QMatrix2x2 *values, int count);
       
   258     void setUniformValueArray(int location, const QMatrix2x3 *values, int count);
       
   259     void setUniformValueArray(int location, const QMatrix2x4 *values, int count);
       
   260     void setUniformValueArray(int location, const QMatrix3x2 *values, int count);
       
   261     void setUniformValueArray(int location, const QMatrix3x3 *values, int count);
       
   262     void setUniformValueArray(int location, const QMatrix3x4 *values, int count);
       
   263     void setUniformValueArray(int location, const QMatrix4x2 *values, int count);
       
   264     void setUniformValueArray(int location, const QMatrix4x3 *values, int count);
       
   265     void setUniformValueArray(int location, const QMatrix4x4 *values, int count);
       
   266 
       
   267     void setUniformValueArray(const char *name, const GLfloat *values, int count, int size);
       
   268     void setUniformValueArray(const char *name, const GLint *values, int count);
       
   269     void setUniformValueArray(const char *name, const GLuint *values, int count);
       
   270     void setUniformValueArray(const char *name, const QVector2D *values, int count);
       
   271     void setUniformValueArray(const char *name, const QVector3D *values, int count);
       
   272     void setUniformValueArray(const char *name, const QVector4D *values, int count);
       
   273     void setUniformValueArray(const char *name, const QMatrix2x2 *values, int count);
       
   274     void setUniformValueArray(const char *name, const QMatrix2x3 *values, int count);
       
   275     void setUniformValueArray(const char *name, const QMatrix2x4 *values, int count);
       
   276     void setUniformValueArray(const char *name, const QMatrix3x2 *values, int count);
       
   277     void setUniformValueArray(const char *name, const QMatrix3x3 *values, int count);
       
   278     void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count);
       
   279     void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count);
       
   280     void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count);
       
   281     void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count);
       
   282 
       
   283     static bool hasShaderPrograms(const QGLContext *context = 0);
       
   284 
       
   285 private Q_SLOTS:
       
   286     void shaderDestroyed();
       
   287 
       
   288 private:
       
   289     QGLShaderProgramPrivate *d;
       
   290 
       
   291     Q_DISABLE_COPY(QGLShaderProgram)
       
   292 
       
   293     bool init();
       
   294 };
       
   295 
       
   296 #endif
       
   297 
       
   298 QT_END_NAMESPACE
       
   299 
       
   300 QT_END_HEADER
       
   301 
       
   302 #endif