00001 #include "AbstractShader.h"
00002
00004
00011 class ShaderObj
00012 {
00013 public:
00014 GLuint shaderID;
00015 GLuint sbackface;
00016 GLuint stransfer_func;
00017 GLuint spartiell;
00018 GLuint sLightSourcePos;
00019 GLuint IsMode;
00020 GLuint sSlideValue;
00021 GLuint scentral_differences;
00022 GLuint sMaxIntensity;
00023 GLuint sPreshading;
00024
00025 GLuint sInterpolation;
00026 GLuint sStepsize;
00027 GLuint sResolution;
00028 GLuint sAdaptiv;
00029 GLuint sBackground;
00030 GLuint sClipping;
00031 GLuint sTransferGradient;
00032 };
00033
00035
00041 class Shader : public AbstractShader
00042 {
00043 public:
00047 Shader()
00048 {
00049 gTransformQuadric = createShader("gquadric_vert.glsl","gquadric_frag.glsl");
00050 gSlices = createShader("gquadric_vert.glsl","visu_slices.frag");
00051 gVisu = createShader("gquadric_vert.glsl","visu.frag");
00052 gVisuAvg = createShader("gquadric_vert.glsl","visu_avg.frag");
00053 gVisuFirst = createShader("gquadric_vert.glsl","visu_first.frag");
00054 gVisuMIP = createShader("gquadric_vert.glsl","visu_mip.frag");
00055 gVisuShadow = createShader("gquadric_vert.glsl","visu_shadow.frag");
00056 gVisuAvgShadow = createShader("gquadric_vert.glsl","visu_avg_shadow.frag");
00057 gVisuFirstShadow = createShader("gquadric_vert.glsl","visu_first_shadow.frag");
00058 gVisuMIPShadow = createShader("gquadric_vert.glsl","visu_mip_shadow.frag");
00059 gVisuContour = createShader("gquadric_vert.glsl","visu_contour.frag");
00060 gVisuAvgContour = createShader("gquadric_vert.glsl","visu_avg_contour.frag");
00061 gVisuFirstContour = createShader("gquadric_vert.glsl","visu_first_contour.frag");
00062 gVisuMIPContour = createShader("gquadric_vert.glsl","visu_mip_contour.frag");
00063
00064 gVisuExploration = createShader("gquadric_vert.glsl","visu_exploration.frag");
00065 gVisuAvgExploration = createShader("gquadric_vert.glsl","visu_avg_exploration.frag");
00066 gVisuFirstExploration = createShader("gquadric_vert.glsl","visu_first_exploration.frag");
00067 gVisuMIPExploration = createShader("gquadric_vert.glsl","visu_mip_exploration.frag");
00068
00069
00070
00071 };
00072
00076 ~Shader()
00077 {
00078 glDeleteShader(gTransformQuadric.shaderID);
00079 glDeleteShader(gSlices.shaderID);
00080 glDeleteShader(gVisu.shaderID);
00081 glDeleteShader(gVisuAvg.shaderID);
00082 glDeleteShader(gVisuFirst.shaderID);
00083 glDeleteShader(gVisuMIP.shaderID);
00084 glDeleteShader(gVisuShadow.shaderID);
00085 glDeleteShader(gVisuAvgShadow.shaderID);
00086 glDeleteShader(gVisuFirstShadow.shaderID);
00087 glDeleteShader(gVisuMIPShadow.shaderID);
00088 glDeleteShader(gVisuContour.shaderID);
00089 glDeleteShader(gVisuAvgContour.shaderID);
00090 glDeleteShader(gVisuFirstContour.shaderID);
00091 glDeleteShader(gVisuMIPContour.shaderID);
00092 glDeleteShader(gVisuExploration.shaderID);
00093 glDeleteShader(gVisuAvgExploration.shaderID);
00094 glDeleteShader(gVisuFirstExploration.shaderID);
00095 glDeleteShader(gVisuMIPExploration.shaderID);
00096 }
00097
00104 ShaderObj createShader(const char* vertexshadername, const char* fragmentshadername)
00105 {
00106 ShaderObj shaderID;
00107 GLhandleARB vertexShaderHandle;
00108 GLhandleARB fragmentShaderHandle;
00109 vertexShaderHandle = loadShader(vertexshadername,GL_VERTEX_SHADER);
00110 fragmentShaderHandle = loadShader(fragmentshadername,GL_FRAGMENT_SHADER);
00111 shaderID.shaderID = glCreateProgramObjectARB();
00112 glAttachObjectARB(shaderID.shaderID,vertexShaderHandle);
00113 glAttachObjectARB(shaderID.shaderID,fragmentShaderHandle);
00114 glLinkProgramARB(shaderID.shaderID);
00115
00116 shaderID.sbackface = glGetUniformLocationARB(shaderID.shaderID,"sBackFace");
00117 shaderID.stransfer_func = glGetUniformLocationARB(shaderID.shaderID,"sTransfer");
00118 shaderID.spartiell = glGetUniformLocationARB(shaderID.shaderID,"sPartiel");
00119 shaderID.sLightSourcePos = glGetUniformLocationARB(shaderID.shaderID,"sLightSourcePos");
00120 shaderID.IsMode = glGetUniformLocationARB(shaderID.shaderID,"IsMode");
00121 shaderID.sSlideValue = glGetUniformLocationARB(shaderID.shaderID, "sSlideValue");
00122 shaderID.scentral_differences = glGetUniformLocationARB(shaderID.shaderID, "preprocess");
00123 shaderID.sMaxIntensity = glGetUniformLocationARB(shaderID.shaderID, "sMaxIntensity");
00124 shaderID.sPreshading = glGetUniformLocationARB(shaderID.shaderID, "sPreshading");
00125
00126 shaderID.sInterpolation = glGetUniformLocationARB(shaderID.shaderID, "sInterpolation");
00127 shaderID.sResolution = glGetUniformLocationARB(shaderID.shaderID, "resolution");
00128 shaderID.sStepsize = glGetUniformLocationARB(shaderID.shaderID, "stepsize");
00129 shaderID.sAdaptiv = glGetUniformLocationARB(shaderID.shaderID, "sAdaptiv");
00130 shaderID.sBackground = glGetUniformLocationARB(shaderID.shaderID, "sBackground");
00131 shaderID.sClipping = glGetUniformLocationARB(shaderID.shaderID, "sClipping");
00132 shaderID.sTransferGradient = glGetUniformLocationARB(shaderID.shaderID, "sTransferGradient");
00133
00134
00135 return shaderID;
00136 }
00137
00155 void start(int shadingmode, float slidingx, float slidingy, float slidingz, int slidemode, int slicing, float slidevalue,int central_differences, int maxintensity, int preshading, int interpolation, Vector resolution, float steps, int adaptiv,int clipping, int withgradient)
00156 {
00157 ShaderObj Shader = gTransformQuadric;
00158
00159 if(slicing == 1 && slidemode > 1) Shader = gSlices;
00160 else
00161 {
00162 switch(shadingmode)
00163 {
00164 case 1:
00165 switch(maxintensity)
00166 {
00167 case 0: Shader = gVisuContour;
00168 break;
00169 case 1: Shader = gVisuMIPContour;
00170 break;
00171 case 2: Shader = gVisuAvgContour;
00172 break;
00173 case 3: Shader = gVisuFirstContour;
00174 break;
00175 }
00176 break;
00177 case 2:
00178 switch(maxintensity)
00179 {
00180 case 0: Shader = gVisuShadow;
00181 break;
00182 case 1: Shader = gVisuMIPShadow;
00183 break;
00184 case 2: Shader = gVisuAvgShadow;
00185 break;
00186 case 3: Shader = gVisuFirstShadow;
00187 break;
00188 }
00189 break;
00190 case 3:
00191 switch(maxintensity)
00192 {
00193 case 0: Shader = gVisuExploration;
00194 break;
00195 case 1: Shader = gVisuMIPExploration;
00196 break;
00197 case 2: Shader = gVisuAvgExploration;
00198 break;
00199 case 3: Shader = gVisuFirstExploration;
00200 break;
00201 }
00202 break;
00203 case 0:
00204 switch(maxintensity)
00205 {
00206 case 0: Shader = gVisu;
00207 break;
00208 case 1: Shader = gVisuMIP;
00209 break;
00210 case 2: Shader = gVisuAvg;
00211 break;
00212 case 3: Shader = gVisuFirst;
00213 break;
00214 }
00215 }
00216 }
00217
00218 if(slicing == 0)
00219 {
00220 glUseProgramObjectARB(Shader.shaderID);
00221 glUniform1iARB(Shader.sBackground, 0);
00222 glUniform1iARB(Shader.sbackface, 1);
00223 glUniform1iARB(Shader.stransfer_func,3);
00224 glUniform1iARB(Shader.spartiell,4);
00225 glUniform3fARB(Shader.sLightSourcePos, slidingx,slidingy,slidingz);
00226 glUniform1iARB(Shader.IsMode, 1);
00227 glUniform1iARB(Shader.scentral_differences,central_differences);
00228
00229 glUniform1iARB(Shader.sInterpolation,interpolation);
00230 glUniform3fARB(Shader.sResolution,1.0f/resolution.GetX(), 1.0f/resolution.GetY(), 1.0f/resolution.GetZ());
00231 glUniform1fARB(Shader.sStepsize,1.0f/steps);
00232 glUniform1iARB(Shader.sAdaptiv,adaptiv);
00233 glUniform1iARB(Shader.sClipping,clipping);
00234 glUniform1iARB(Shader.sTransferGradient, withgradient);
00235 }
00236 else
00237 {
00238 glUseProgramObjectARB(Shader.shaderID);
00239 glUniform1iARB(Shader.sBackground, 0);
00240 glUniform1iARB(Shader.sbackface, 1);
00241 glUniform1iARB(Shader.stransfer_func,3);
00242 glUniform1iARB(Shader.spartiell,4);
00243 glUniform3fARB(Shader.sLightSourcePos, slidingx,slidingy,slidingz);
00244 glUniform1iARB(Shader.IsMode, slidemode);
00245 glUniform1fARB(Shader.sSlideValue, slidevalue);
00246 glUniform1iARB(Shader.scentral_differences,central_differences);
00247 glUniform1iARB(Shader.sMaxIntensity, maxintensity);
00248 glUniform1iARB(Shader.sPreshading, preshading);
00249
00250 glUniform1iARB(Shader.sInterpolation,interpolation);
00251 glUniform3fARB(Shader.sResolution,1.0f/resolution.GetX(), 1.0f/resolution.GetY(), 1.0f/resolution.GetZ());
00252 glUniform1fARB(Shader.sStepsize,1.0f/steps);
00253 glUniform1iARB(Shader.sAdaptiv,adaptiv);
00254 glUniform1iARB(Shader.sClipping,clipping);
00255 glUniform1iARB(Shader.sTransferGradient, withgradient);
00256 }
00257 };
00258
00262 void stop()
00263 {
00264 glUseProgramObjectARB(0);
00265 };
00266
00267 private:
00268 ShaderObj gTransformQuadric;
00269 ShaderObj gSlices;
00270 ShaderObj gVisu;
00271 ShaderObj gVisuAvg;
00272 ShaderObj gVisuFirst;
00273 ShaderObj gVisuMIP;
00274 ShaderObj gVisuShadow;
00275 ShaderObj gVisuAvgShadow;
00276 ShaderObj gVisuFirstShadow;
00277 ShaderObj gVisuMIPShadow;
00278 ShaderObj gVisuContour;
00279 ShaderObj gVisuAvgContour;
00280 ShaderObj gVisuFirstContour;
00281 ShaderObj gVisuMIPContour;
00282 ShaderObj gVisuExploration;
00283 ShaderObj gVisuAvgExploration;
00284 ShaderObj gVisuFirstExploration;
00285 ShaderObj gVisuMIPExploration;
00286 };