00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025
00026 #ifndef _PROGRAM_GLSL_H
00027 #define _PROGRAM_GLSL_H
00028
00029
00030 #include "ProgramGPU.h"
00031
00032 class ProgramGLSL:public ProgramGPU
00033 {
00034 class ShaderObject
00035 {
00036 GLuint _shaderID;
00037 int _type;
00038 int _compiled;
00039 static int ReadShaderFile(const char * source, char *& code);
00040 void CheckCompileLog();
00041 public:
00042 void PrintCompileLog(ostream & os );
00043 int inline IsValidShaderObject(){ return _shaderID && _compiled;}
00044 int IsValidVertexShader();
00045 int IsValidFragmentShader();
00046 GLuint GetShaderID(){return _shaderID;}
00047 ~ShaderObject();
00048 ShaderObject(int shadertype, const char * source, int filesource =0);
00049 };
00050
00051 protected:
00052 int _linked;
00053 GLuint _programID;
00054 private:
00055 void AttachShaderObject(ShaderObject& shader);
00056 void DetachShaderObject(ShaderObject& shader);
00057
00058 public:
00059 void ReLink();
00060 int IsNative();
00061 int UseProgram();
00062 void PrintLinkLog(std::ostream&os);
00063 int ValidateProgram();
00064 void CheckLinkLog();
00065 int LinkProgram();
00066 operator GLuint (){return _programID;}
00067 virtual void * GetProgramID() { return (void*) _programID; }
00068 public:
00069 ProgramGLSL();
00070 ~ProgramGLSL();
00071 ProgramGLSL(const char* frag_source);
00072 };
00073
00074
00075 class GLTexImage;
00076 class FilterGLSL : public FilterProgram
00077 {
00078 private:
00079 ProgramGPU* CreateFilterH(float kernel[], int width);
00080 ProgramGPU* CreateFilterV(float kernel[], int height);
00081 ProgramGPU* CreateFilterHPK(float kernel[], int width);
00082 ProgramGPU* CreateFilterVPK(float kernel[], int height);
00083 public:
00084 void MakeFilterProgram(float kernel[], int width);
00085 public:
00086 FilterGLSL(float sigma) ;
00087 };
00088
00089 class SiftParam;
00090
00092
00093
00094
00095
00097 class ShaderBag
00098 {
00099 public:
00100
00101 ProgramGPU * s_gray;
00102
00103 ProgramGPU * s_copy_key;
00104
00105 ProgramGPU * s_debug;
00106
00107
00108 ProgramGPU * s_orientation;
00109
00110 ProgramGPU * s_display_gaussian;
00111
00112 ProgramGPU * s_display_dog;
00113
00114 ProgramGPU * s_display_grad;
00115
00116 ProgramGPU * s_display_keys;
00117
00118 ProgramGPU * s_sampling;
00119
00120 ProgramGPU * s_grad_pass;
00121 ProgramGPU * s_dog_pass;
00122
00123 ProgramGPU * s_keypoint;
00124 ProgramGPU * s_seperate_sp;
00125
00126 ProgramGPU * s_genlist_init_tight;
00127 ProgramGPU * s_genlist_init_ex;
00128 ProgramGPU * s_genlist_histo;
00129 ProgramGPU * s_genlist_start;
00130 ProgramGPU * s_genlist_step;
00131 ProgramGPU * s_genlist_end;
00132 ProgramGPU * s_zero_pass;
00133
00134 ProgramGPU * s_vertex_list;
00135
00136 ProgramGPU * s_descriptor_fp;
00137
00138 ProgramGPU * s_margin_copy;
00139 public:
00140 FilterProgram * f_gaussian_skip0;
00141 vector<FilterProgram*> f_gaussian_skip0_v;
00142 FilterProgram * f_gaussian_skip1;
00143 FilterProgram ** f_gaussian_step;
00144 int _gaussian_step_num;
00145 public:
00146 virtual void SetGenListInitParam(int w, int h){};
00147 virtual void SetGenListEndParam(int ktex){};
00148 virtual void SetMarginCopyParam(int xmax, int ymax){};
00149 virtual void LoadDescriptorShader(){};
00150 virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma){};
00151 virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex, float step){};
00152 virtual void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step){};
00153 virtual void LoadOrientationShader() =0;
00154 virtual void SetGenListStartParam(float width, int tex0) =0;
00155 virtual void LoadGenListShader(int ndoglev, int nlev)=0;
00156 virtual void UnloadProgram()=0;
00157 virtual void LoadKeypointShader(float threshold, float edgeTrheshold) = 0;
00158 virtual void LoadFixedShaders()=0;
00159 virtual void LoadDisplayShaders() = 0;
00160 virtual void SetDogTexParam(int texU, int texD)=0;
00161 virtual void SetGradPassParam(int texP=0){}
00162 virtual void SetGenListStepParam(int tex, int tex0) = 0;
00163 virtual void SetGenVBOParam( float width, float fwidth, float size)=0;
00164 public:
00165 void CreateGaussianFilters(SiftParam¶m);
00166 void SelectInitialSmoothingFilter(int octave_min, SiftParam¶m);
00167 void LoadDynamicShaders(SiftParam& param);
00168 ShaderBag();
00169 virtual ~ShaderBag();
00170 };
00171
00172
00173 class ShaderBagGLSL:public ShaderBag
00174 {
00175 GLint _param_dog_texu;
00176 GLint _param_dog_texd;
00177 GLint _param_ftex_width;
00178 GLint _param_genlist_start_tex0;
00179 GLint _param_genlist_step_tex;
00180 GLint _param_genlist_step_tex0;
00181 GLint _param_genvbo_size;
00182 GLint _param_orientation_gtex;
00183 GLint _param_orientation_size;
00184 GLint _param_orientation_stex;
00185 GLint _param_margin_copy_truncate;
00186 GLint _param_genlist_init_bbox;
00187 GLint _param_descriptor_gtex;
00188 GLint _param_descriptor_size;
00189 GLint _param_descriptor_dsize;
00190 public:
00191 virtual void SetMarginCopyParam(int xmax, int ymax);
00192 void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step);
00193 void LoadOrientationShader();
00194 void LoadDescriptorShaderF2();
00195 virtual void LoadDescriptorShader();
00196 virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex = 0, float step = 1.0f);
00197 virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma);
00198 static void WriteOrientationCodeToStream(ostream& out);
00199 static ProgramGLSL* LoadGenListStepShader(int start, int step);
00200 virtual void SetGenListInitParam(int w, int h);
00201 virtual void SetGenListStartParam(float width, int tex0);
00202 virtual void LoadGenListShader(int ndoglev, int nlev);
00203 virtual void UnloadProgram();
00204 virtual void LoadKeypointShader(float threshold, float edgeTrheshold);
00205 virtual void LoadFixedShaders();
00206 virtual void LoadDisplayShaders();
00207 virtual void SetDogTexParam(int texU, int texD);
00208 virtual void SetGenListStepParam(int tex, int tex0);
00209 virtual void SetGenVBOParam( float width, float fwidth, float size);
00210 virtual ~ShaderBagGLSL(){}
00211 };
00212
00213
00214 class ShaderBagPKSL:public ShaderBag
00215 {
00216 private:
00217 GLint _param_dog_texu;
00218 GLint _param_dog_texd;
00219 GLint _param_margin_copy_truncate;
00220 GLint _param_grad_pass_texp;
00221 GLint _param_genlist_init_bbox;
00222 GLint _param_genlist_start_tex0;
00223 GLint _param_ftex_width;
00224 GLint _param_genlist_step_tex;
00225 GLint _param_genlist_step_tex0;
00226 GLint _param_genlist_end_ktex;
00227 GLint _param_genvbo_size;
00228 GLint _param_orientation_gtex;
00229 GLint _param_orientation_otex;
00230 GLint _param_orientation_size;
00231 GLint _param_descriptor_gtex;
00232 GLint _param_descriptor_otex;
00233 GLint _param_descriptor_size;
00234 GLint _param_descriptor_dsize;
00235
00236
00237 ProgramGLSL* s_rect_description;
00238 public:
00239 ShaderBagPKSL () {s_rect_description = NULL; }
00240 virtual ~ShaderBagPKSL() {if(s_rect_description) delete s_rect_description; }
00241 virtual void LoadFixedShaders();
00242 virtual void LoadDisplayShaders();
00243 virtual void LoadOrientationShader() ;
00244 virtual void SetGenListStartParam(float width, int tex0) ;
00245 virtual void LoadGenListShader(int ndoglev, int nlev);
00246 virtual void UnloadProgram();
00247 virtual void LoadKeypointShader(float threshold, float edgeTrheshold) ;
00248 virtual void LoadDescriptorShader();
00249 virtual void LoadDescriptorShaderF2();
00250 static ProgramGLSL* LoadDescriptorProgramRECT();
00251 static ProgramGLSL* LoadDescriptorProgramPKSL();
00253 virtual void SetDogTexParam(int texU, int texD);
00254 virtual void SetGradPassParam(int texP);
00255 virtual void SetGenListStepParam(int tex, int tex0);
00256 virtual void SetGenVBOParam( float width, float fwidth, float size);
00257 virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma);
00258 virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex, float step);
00259 virtual void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step);
00260 virtual void SetGenListEndParam(int ktex);
00261 virtual void SetGenListInitParam(int w, int h);
00262 virtual void SetMarginCopyParam(int xmax, int ymax);
00263 };
00264
00265
00266 #endif
00267