Main Page | Class Hierarchy | Class List | Directories | File List

ProgGLSL.h

00001 #ifndef __PROG_GLSL__
00002 #define __PROG_GLSL__
00003 
00004 #include "ShaderGLSL.h"
00005 #include "TextureSet.h"
00006 #include <QString>
00007 #include <QStringList>
00008 #include <QList>
00009 
00010 namespace apig {
00011     
00012     class Uniform;
00013     class UniformGLSL;
00014     class ProgParam;
00015     
00020     class ProgGLSL {
00021         public:
00022             //ProgGLSL() : created(false), linked(false) {}
00023             //~ProgGLSL();
00024             //ProgGLSL();     // un contexte OpenGL doit etre actif
00025             static ProgGLSL* create();     // un contexte OpenGL doit etre actif, retourne NULL ssi une erreur est survenue
00026             ~ProgGLSL();
00027             
00028         // méthodes de chargement :
00029         //-------------------------
00030             // les méthodes suivantes retournent NULL si une erreur a survenu :
00031             static ProgGLSL* loadSubDir(QString rootName);                                  // ouvre une boîte de dialogue et propose de choisir un sous-répertoire de <rootName>
00032             static ProgGLSL* loadDir(QString dirName);                                      // charge toutes les sources du sous-répertoire <dirName>
00033             static ProgGLSL* load(QString name);                                            // charge les fichiers <name>.vert et <name>.frag
00034             static ProgGLSL* load(QString vertName, QString fragName);                      // charge le vertex shader <vertName> et le fragment shader <fragName> (avec extensions)
00035             static ProgGLSL* loadFrag(QString dirName, QString fragName = QString::null);   // charge le fragment shader <dirName/fragName> avec le (seul) vertex shader se trouvant dans le même répertoire
00036         
00037         // méthodes pour l'activation du programme :
00038         //------------------------------------------
00039             void activate();    // active le programme et actualise les variables liées
00040             void deactivate();
00041             bool isLinked() const;          // true ssi le prog a ete linke correctement
00042             void activateTextures() const;  // doit être appelé pendant que le programme est activé, si les textures attachées ont été changées
00043             
00044         // méthodes utiles :
00045         //------------------
00046             // la liste des sources de type <shaderType> présents dans le répertoire <dirName> :
00047             static QStringList sourcesList(QString dirName, ShaderGLSL::Type shaderType, bool relative=true);
00048     
00049         // méthodes de vérifications :
00050         //----------------------------
00051             void validate();            // valide et affiche des infos de validation
00052             void printInfo() const;     // affiche la liste d'attributs et uniforms actifs
00053             void printActiveAttribs() const;    // affiche la liste d'attributs actifs
00054             void printActiveUniforms() const;   // affiche la liste d'uniforms actifs
00055             
00056         // phases de chargement d'un programme (a appeler dans cet ordre) :
00057         //-----------------------------------------------------------------
00058             //void create();
00059             void bindShaderFile(QString fileName, ShaderGLSL::Type type);
00060             void bindShaderSource(QString source, ShaderGLSL::Type type);
00061             void link();
00062     
00063         // méthodes d'actualisation de variables (a faire apres le linkage et avant la premiere activation) :
00064         //---------------------------------------------------------------------------------------------------
00065             // les variables seront automatiquement actualisées à l'activation du programme en utilisant la valeur pointée juste avant l'activation
00066             // si warn==true et la variable n'existe pas, un message de warning est affiché (utiliser warn=false pour les variables optionnelles)
00067             void addUniform(Uniform *uniform, bool warn=true, bool ownUniform=true);    // si ownUniform==true, la suppression de <uniform> est prise en charge
00068             void addUniform(QString name, const float  *value, bool warn=true);
00069             void addUniform(QString name, const int    *value, bool warn=true);
00070             void addUniform(QString name, const bool   *value, bool warn=true);
00071             void addUniformVec2(QString name, const float *value, bool warn=true);
00072             void addUniformVec3(QString name, const float *value, bool warn=true);
00073             void addUniformVec4(QString name, const float *value, bool warn=true);
00074             void addUniformIVec2(QString name, const int *value, bool warn=true);
00075             void addUniformIVec3(QString name, const int *value, bool warn=true);
00076             void addUniformIVec4(QString name, const int *value, bool warn=true);
00077             void addUniformBVec2(QString name, const bool *value, bool warn=true);
00078             void addUniformBVec3(QString name, const bool *value, bool warn=true);
00079             void addUniformBVec4(QString name, const bool *value, bool warn=true);
00080             void addUniformMat2(QString name, const float *value, bool warn=true);      // les coefficients de la matrice comme succession de colonnes (column-major order)
00081             void addUniformMat3(QString name, const float *value, bool warn=true);      // les coefficients de la matrice comme succession de colonnes (column-major order)
00082             void addUniformMat4(QString name, const float *value, bool warn=true);      // les coefficients de la matrice comme succession de colonnes (column-major order)
00083             void addTexture(QString name, Texture *texture, bool warn=true);
00084             
00085         // méthodes pour changer la valeur d'une variable (a faire quand le programme est actif) :
00086         //----------------------------------------------------------------------------------------
00087             // si warn==true et la variable n'existe pas, un message de warning est affiché (utiliser warn=false pour les variables optionnelles)
00088             void setUniform(QString name, int   value, bool warn=true);
00089             void setUniform(QString name, float value, bool warn=true);
00090             void setUniform(QString name, bool value, bool warn=true);
00091             void setUniformVec2(QString name, float v0, float v1, bool warn=true);
00092             void setUniformVec3(QString name, float v0, float v1, float v2, bool warn=true);
00093             void setUniformVec4(QString name, float v0, float v1, float v2, float v3, bool warn=true);
00094             void setUniformVec2(QString name, const float *value, bool warn=true);
00095             void setUniformVec3(QString name, const float *value, bool warn=true);
00096             void setUniformVec4(QString name, const float *value, bool warn=true);
00097             void setUniformIVec2(QString name, int v0, int v1, bool warn=true);
00098             void setUniformIVec3(QString name, int v0, int v1, int v2, bool warn=true);
00099             void setUniformIVec4(QString name, int v0, int v1, int v2, int v3, bool warn=true);
00100             void setUniformIVec2(QString name, const int *value, bool warn=true);
00101             void setUniformIVec3(QString name, const int *value, bool warn=true);
00102             void setUniformIVec4(QString name, const int *value, bool warn=true);
00103             void setUniformBVec2(QString name, bool v0, bool v1, bool warn=true);
00104             void setUniformBVec3(QString name, bool v0, bool v1, bool v2, bool warn=true);
00105             void setUniformBVec4(QString name, bool v0, bool v1, bool v2, bool v3, bool warn=true);
00106             void setUniformBVec2(QString name, const bool *value, bool warn=true);
00107             void setUniformBVec3(QString name, const bool *value, bool warn=true);
00108             void setUniformBVec4(QString name, const bool *value, bool warn=true);
00109             void setUniformMat2(QString name, const float *value, bool warn=true);    // les coefficients de la matrice comme succession de colonnes (column-major order)
00110             void setUniformMat3(QString name, const float *value, bool warn=true);    // les coefficients de la matrice comme succession de colonnes (column-major order)
00111             void setUniformMat4(QString name, const float *value, bool warn=true);    // les coefficients de la matrice comme succession de colonnes (column-major order)
00112             
00113         private:
00114             ProgGLSL(GLuint id) : id(id), linked(false) {}
00115             void updateVariables() const;
00116             void clearParameters();
00117             UniformGLSL* createUniformGLSL(QString name, bool warn) const;          // retourne NULL si la variable <name> n'existe pas
00118             void bindShaderDir(QString dirName, ShaderGLSL::Type shaderType);       // <dirName> relatif au répertoire de base
00119             void attach(ShaderGLSL shader);
00120             void detach(ShaderGLSL shader);
00121             QString getInfoLog() const;
00122             GLint getProgParam(GLenum paramName) const;
00123             static QString typeEnumString(GLenum type);     // convertit en QString une enum représentant un type GLSL
00124     
00125         private:
00126             GLuint id;                      // id OpenGL du programme
00127             bool linked;                    // true ssi le programme a été linké avec succès
00128             QList<ShaderGLSL> shaders;      // liste des shaders formant ce programme
00129             QList<ProgParam*> parameters;   // la liste des variables attachées au programme
00130             TextureSet textures;            // la liste des textures attachées au programme
00131         };
00132     }
00133 
00134 #endif
00135 

Generated on Fri Nov 14 20:49:47 2008 for Api Graphics by  doxygen 1.4.4