Hierarchical Edge Bundle 1.0
J:/Caro/C++_Coding/HierarchicalEdgeBundle/HierarchicalEdgeBundle/header/Shader.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "AbstractShader.h"
00003 #include "ShaderObj.h"
00004 #include <vector>
00005 
00007 
00013 class Shader : public AbstractShader
00014 {
00015 public:
00019         Shader(ShaderObj* shaderobj)
00020         {
00021                 gTransformQuadric = createShader(shaderobj->vertexshader,shaderobj->fragmentshader, shaderobj);
00022 
00023                 //glDeleteShader(vertexShaderHandle);
00024                 //glDeleteShader(fragmentShaderHandle);
00025         };
00026 
00030         ~Shader()
00031         {
00032                 glDeleteShader(gTransformQuadric->shaderID);
00033         }
00034 
00041         ShaderObj* createShader(const char* vertexshadername, const char* fragmentshadername, ShaderObj* shaderID)
00042         {
00043                 GLhandleARB vertexShaderHandle;
00044                 GLhandleARB fragmentShaderHandle;
00045                 vertexShaderHandle   = loadShader(vertexshadername,GL_VERTEX_SHADER);
00046                 fragmentShaderHandle = loadShader(fragmentshadername,GL_FRAGMENT_SHADER);
00047                 shaderID->shaderID = glCreateProgramObjectARB();
00048                 glAttachObjectARB(shaderID->shaderID,vertexShaderHandle);
00049                 glAttachObjectARB(shaderID->shaderID,fragmentShaderHandle);
00050                 glLinkProgramARB(shaderID->shaderID);
00051 
00052                 for(unsigned int i = 0; i  < shaderID->parameters.size(); i++)
00053                 {
00054                         shaderID->parameters[i]->id = glGetUniformLocationARB(shaderID->shaderID, shaderID->parameters[i]->var);
00055                 }
00056         
00057                 return shaderID;
00058         }
00059         
00077         void start(ShaderObj* obj)
00078         {
00079                 ShaderObj* Shader = gTransformQuadric;
00080                 glUseProgramObjectARB(obj->shaderID);
00081 
00082                 for(unsigned int i = 0; i < obj->parameters.size(); i++)
00083                 {
00084                         switch(obj->parameters[i]->type)
00085                         {
00086                         case ParameterObj::PT_INT: 
00087                                         glUniform1iARB(obj->parameters[i]->id, (int)obj->parameters[i]->value[0]);
00088                                 break;
00089                         case ParameterObj::PT_FLOAT: 
00090                                         glUniform1fARB(obj->parameters[i]->id, obj->parameters[i]->value[0]);
00091                                 break;
00092                         case ParameterObj::PT_INT2: 
00093                                         glUniform2iARB(obj->parameters[i]->id, (int)obj->parameters[i]->value[0], (int)obj->parameters[i]->value[1]);
00094                                 break;
00095                         case ParameterObj::PT_FLOAT2: 
00096                                         glUniform2fARB(obj->parameters[i]->id, obj->parameters[i]->value[0], obj->parameters[i]->value[1]);
00097                                 break;
00098                         case ParameterObj::PT_INT3: 
00099                                 glUniform3iARB(obj->parameters[i]->id, (int)obj->parameters[i]->value[0], (int)obj->parameters[i]->value[1], (int)obj->parameters[2]->value[2]); 
00100                                 break;
00101                         case ParameterObj::PT_FLOAT3: 
00102                                         glUniform3fARB(obj->parameters[i]->id, obj->parameters[i]->value[0], obj->parameters[i]->value[1], obj->parameters[2]->value[2]); 
00103                                 break;
00104                         /*case ParameterObj::PT_MAT2: 
00105                                         glUniformMatrix2fvARB(obj->parameters[i]->id, &obj->parameters[i]->value[0]);
00106                                 break;
00107                         case ParameterObj::PT_MAT3: 
00108                                         glUniformMatrix3fvARB(obj->parameters[i]->id, &obj->parameters[i]->value[0]);
00109                                 break;
00110                         case ParameterObj::PT_MAT4: 
00111                                         glUniformMatrix4fvARB(obj->parameters[i]->id, &obj->parameters[i]->value[0]);
00112                                 break;*/
00113                         }
00114                 }
00115         };
00116 
00120         void stop()
00121         {
00122                 glUseProgramObjectARB(0);
00123         };
00124 
00125 private:
00126         ShaderObj* gTransformQuadric;
00127 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines