00001 #include "AbstractShader.h" 00002 00004 00011 class ShaderObj 00012 { 00013 public: 00014 GLuint shaderID; 00015 GLuint velocityTex; 00016 GLuint valueTex; 00017 GLuint gridTex; 00018 GLuint rot; 00019 GLuint value1; 00020 }; 00021 00023 00029 class Shader : public AbstractShader 00030 { 00031 public: 00035 Shader() 00036 { 00037 qBackground = createShader("background_vert.glsl","background_frag.glsl"); 00038 gTransformQuadric = createShader("gquadric_vert.glsl","gquadric_frag.glsl"); 00039 qTexture = createShader("texture_vert.glsl","texture_frag.glsl"); 00040 qVertical = createShader("blur_vert_vert.glsl","blur_vert_fraq.glsl"); 00041 qHorizontal = createShader("blur_hori_vert.glsl","blur_hori_fraq.glsl"); 00042 qBackground2 = createShader("background_vert.glsl","background2_frag.glsl"); 00043 qBackground3 = createShader("background_vert.glsl","background3_frag.glsl"); 00044 }; 00045 00049 ~Shader() 00050 { 00051 glDeleteShader(gTransformQuadric.shaderID); 00052 glDeleteShader(qBackground.shaderID); 00053 glDeleteShader(qTexture.shaderID); 00054 glDeleteShader(qVertical.shaderID); 00055 glDeleteShader(qHorizontal.shaderID); 00056 glDeleteShader(qBackground2.shaderID); 00057 } 00058 00065 ShaderObj createShader(const char* vertexshadername, const char* fragmentshadername) 00066 { 00067 std::cout << "Create Shader beginn: " << std::endl; 00068 ShaderObj shaderID; 00069 GLhandleARB vertexShaderHandle; 00070 GLhandleARB fragmentShaderHandle; 00071 00072 vertexShaderHandle = loadShader(vertexshadername,GL_VERTEX_SHADER); 00073 fragmentShaderHandle = loadShader(fragmentshadername,GL_FRAGMENT_SHADER); 00074 00075 shaderID.shaderID = glCreateProgramObjectARB(); 00076 00077 glAttachObjectARB(shaderID.shaderID,vertexShaderHandle); 00078 glAttachObjectARB(shaderID.shaderID,fragmentShaderHandle); 00079 glLinkProgramARB(shaderID.shaderID); 00080 00081 shaderID.velocityTex = glGetUniformLocationARB(shaderID.shaderID, "velocityTex"); 00082 shaderID.valueTex = glGetUniformLocationARB(shaderID.shaderID, "valueTex"); 00083 shaderID.gridTex = glGetUniformLocationARB(shaderID.shaderID, "gridTex"); 00084 shaderID.rot = glGetUniformLocationARB(shaderID.shaderID, "rot"); 00085 shaderID.value1 = glGetUniformLocationARB(shaderID.shaderID, "value1"); 00086 00087 std::cout << "Create Shader end " << std::endl; 00088 00089 return shaderID; 00090 } 00091 00109 void start(int mode) 00110 { 00111 ShaderObj shaderObj; 00112 00113 switch(mode) 00114 { 00115 case 0: shaderObj = gTransformQuadric; 00116 break; 00117 case 1: shaderObj = qBackground; 00118 break; 00119 case 2: shaderObj = qTexture; 00120 break; 00121 case 3: 00122 shaderObj = qVertical; 00123 break; 00124 case 4: 00125 shaderObj = qHorizontal; 00126 break; 00127 case 5: 00128 shaderObj = qBackground2; 00129 break; 00130 case 6: 00131 shaderObj = qBackground3; 00132 break; 00133 } 00134 00135 glUseProgramObjectARB(shaderObj.shaderID); 00136 glUniform1iARB(shaderObj.velocityTex, 0); 00137 glUniform1iARB(shaderObj.valueTex, 1); 00138 glUniform1iARB(shaderObj.gridTex, 2); 00139 }; 00140 00144 void stop() 00145 { 00146 glUseProgramObjectARB(0); 00147 }; 00148 00149 00150 ShaderObj gTransformQuadric; 00151 ShaderObj qBackground; 00152 ShaderObj qTexture; 00153 ShaderObj qHorizontal; 00154 ShaderObj qVertical; 00155 ShaderObj qBackground2; 00156 ShaderObj qBackground3; 00157 };