   C++ GLSL Shader Class
  HelloI am trying to make a class that will handle GLSL shader programs.Idea is to feed it with the uniform variables one by one with name,value (and type?).After the shader program is built it would then go through all and find the locations.Using the shader program would then load all the uniform variable values automatically.The problem is the uniform variable, it can be of different data types and number of elements to 1f 2f 3f 4f, 1i 2i 3i etc.... Below is how far I made it..#include <list>class Uniform{public:  Uniform();  ~Uniform();  private:string name;  GLUint location;  ?????? type  ?????? value;}class Shader{public:  Shader();  ~Shader();    void ShaderInit();private:  list <Uniform> uni;  GLchar *vsSource; // Buffer with vertex shader source text  GLchar *fsSource; // Buffer with fragment shader source text  GLuint vs;   // Vertex Shader  GLuint fs;   // Fragment Shader  GLuint sp;   // Shader Program};   
  Google says overloaded functions for each type..Then probably a union for different data types.But how to store the type?   ;  I don't know if you're against them or not, but you could always use templates, to fit any type.   ;  Or possibly a void pointer if you're careful about it.   ;  Well if you think about it the only two types you can upload to glUniform is float and int, and various arrays and matrices of those. You could create a vector of unions between these, and then a vector of your own enums for the type. (Or you can just store floats and ints in separate vectors).union Uniform_Var {  float f;  int   i;};enum Uniform_Type {  INT_1,  INT_2,  ...  FLOAT_1,   FLOAT_2,  ...  FLOAT_4x3,  FLOAT_4x4};struct Uniform_Def{  Uniform_Type type;  int index; //Where in the vars vector it starts}vector<Uniform_Var> vars;vector<Uniform_Def> defs;for(i=0;i<defs.size(),i++){  switch(defs.type) {   case INT_1: glUniform1i(<location>,vars[defs.index].i);   case INT_2: glUniform2iv(<location>,&(vars[defs.index].i));  }}Also remember that GLSL uniforms are persistant to the shader, so there's really no need to store these values client side.   ;  I want it to support opengl 3.3 4.0 and GLSL 4.0 also so I added GLint,GLuint,GLfloat and GLdouble to a union. I forgot matrices so I just added a number of elements variable.Quote:Original post by karwostsWell if you think about it the only two types you can upload to glUniform is float and int, and various arrays and matrices of those. You could create a vector of unions between these, and then a vector of your own enums for the type. (Or you can just store floats and ints in separate vectors).*** Source Snippet Removed ***Also remember that GLSL uniforms are persistant to the shader, so there's really no need to store these values client side.I store default values..that are loaded into the shader when you use it. And also ability to change the values before shader program is used.;Quote:Original post by DigiMan ShartI don't know if you're against them or not, but you could always use templates, to fit any type.No not against them.. just do not know hot to use them :)And also can I add them to: list <Uniform> uniIf they are different classes from the same template class ?[Edited by - mrr on April 5, 2010 11:24:07 AM]