ProgramGLSL.h
Go to the documentation of this file.
00001 
00002 //      File:           ProgramGLSL.h
00003 //      Author:         Changchang Wu
00004 //      Description : Interface for ProgramGLSL classes
00005 //              ProgramGLSL:    Glsl Program
00006 //              FilterGLSL:             Glsl Gaussian Filters
00007 //              ShaderBag:          base class of ShaderBagPKSL and ShaderBagGLSL
00008 //
00009 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00010 //      All Rights Reserved
00011 //
00012 //      Permission to use, copy, modify and distribute this software and its
00013 //      documentation for educational, research and non-profit purposes, without
00014 //      fee, and without a written agreement is hereby granted, provided that the
00015 //      above copyright notice and the following paragraph appear in all copies.
00016 //      
00017 //      The University of North Carolina at Chapel Hill make no representations
00018 //      about the suitability of this software for any purpose. It is provided
00019 //      'as is' without express or implied warranty. 
00020 //
00021 //      Please send BUG REPORTS to ccwu@cs.unc.edu
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         GLint           _TextureParam0;
00054         GLuint          _programID; 
00055 private:
00056         void AttachShaderObject(ShaderObject& shader);
00057         void DetachShaderObject(ShaderObject& shader);
00058 
00059 public:
00060         void ReLink();
00061         int IsNative();
00062         int     UseProgram();
00063         void PrintLinkLog(std::ostream&os);
00064         int ValidateProgram();
00065         void CheckLinkLog();
00066         int LinkProgram();
00067         operator GLuint (){return _programID;}
00068     virtual void * GetProgramID() { return (void*) _programID; }
00069 public:
00070         ProgramGLSL();
00071         ~ProgramGLSL();
00072         ProgramGLSL(const char* frag_source);
00073 };
00074 
00075 
00076 class GLTexImage;
00077 class FilterGLSL : public FilterProgram
00078 {
00079 private:
00080         ProgramGPU* CreateFilterH(float kernel[], int width);
00081         ProgramGPU* CreateFilterV(float kernel[], int height);
00082         ProgramGPU* CreateFilterHPK(float kernel[], int width);
00083         ProgramGPU* CreateFilterVPK(float kernel[], int height);
00084 public:
00085     void MakeFilterProgram(float kernel[],  int width);
00086 public:
00087     FilterGLSL(float sigma) ;
00088 };
00089 
00090 class SiftParam; 
00091 
00093 //class ShaderBag
00094 //desciption:   pure virtual class
00095 //                              provides storage and usage interface of all the shaders for SIFT
00096 //                              two implementations are  ShaderBagPKSL and ShaderBagGLSL
00098 class ShaderBag
00099 {
00100 public:
00101         //shader:       rgb to gray
00102         ProgramGPU  * s_gray;
00103         //shader:       copy keypoint to PBO
00104         ProgramGPU  * s_copy_key;
00105         //shader:       debug view
00106         ProgramGPU  * s_debug;
00107         //shader:       orientation
00108         //shader:       assign simple orientation to keypoints if hardware is low
00109         ProgramGPU  * s_orientation;
00110         //shader:       display gaussian levels
00111         ProgramGPU  * s_display_gaussian;
00112         //shader:       display difference of gassian
00113         ProgramGPU  * s_display_dog;
00114         //shader:       display  gradient
00115         ProgramGPU  * s_display_grad;
00116         //shader:       display keypoints as red(maximum) and blue (minimum)
00117         ProgramGPU  * s_display_keys;
00118         //shader:       up/down-sample
00119         ProgramGPU  * s_sampling;
00120         //shader:       compute gradient/dog
00121         ProgramGPU  * s_grad_pass;
00122         ProgramGPU  * s_dog_pass;
00123         //shader:   keypoint detection in one pass
00124         ProgramGPU  * s_keypoint;
00125         ProgramGPU  * s_seperate_sp;
00126         //shader:   feature list generations..
00127         ProgramGPU      * s_genlist_init_tight;
00128         ProgramGPU      * s_genlist_init_ex;
00129         ProgramGPU      * s_genlist_histo;
00130         ProgramGPU      * s_genlist_start;
00131         ProgramGPU      * s_genlist_step;
00132         ProgramGPU      * s_genlist_end;
00133         ProgramGPU      * s_zero_pass;
00134         //shader:       generate vertex to display SIFT as a square
00135         ProgramGPU  * s_vertex_list;
00136         //shader:       descriptor
00137         ProgramGPU  * s_descriptor_fp;
00138         //shader:       copy pixels to margin
00139         ProgramGPU      * s_margin_copy;
00140 public:
00141         FilterProgram  *         f_gaussian_skip0;
00142         vector<FilterProgram*>   f_gaussian_skip0_v;
00143         FilterProgram  *         f_gaussian_skip1;
00144         FilterProgram  **        f_gaussian_step;
00145     int                     _gaussian_step_num;
00146 public:
00147         virtual void SetGenListInitParam(int w, int h){};
00148         virtual void SetGenListEndParam(int ktex){};
00149         virtual void SetMarginCopyParam(int xmax, int ymax){};
00150         virtual void LoadDescriptorShader(){};
00151         virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma){};
00152         virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex, float step){};
00153         virtual void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step){};
00154         virtual void LoadOrientationShader() =0;
00155         virtual void SetGenListStartParam(float width, int tex0) =0;
00156         virtual void LoadGenListShader(int ndoglev, int nlev)=0;
00157         virtual void UnloadProgram()=0;
00158         virtual void LoadKeypointShader(float threshold, float edgeTrheshold) = 0;
00159         virtual void LoadFixedShaders()=0;
00160         virtual void LoadDisplayShaders() = 0;
00161         virtual void SetDogTexParam(int texU, int texD)=0;
00162         virtual void SetGradPassParam(int texP=0){}
00163         virtual void SetGenListStepParam(int tex, int tex0) = 0;
00164         virtual void SetGenVBOParam( float width, float fwidth, float size)=0;
00165 public:
00166     void CreateGaussianFilters(SiftParam&param);
00167     void SelectInitialSmoothingFilter(int octave_min, SiftParam&param);
00168     void LoadDynamicShaders(SiftParam& param); 
00169         ShaderBag();
00170         virtual ~ShaderBag(); 
00171 };
00172 
00173 
00174 class ShaderBagGLSL:public ShaderBag
00175 {
00176         GLint _param_dog_texu;
00177         GLint _param_dog_texd;
00178         GLint _param_ftex_width;
00179         GLint _param_genlist_start_tex0;
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_dog_texi;
00220         GLint   _param_margin_copy_truncate;
00221         GLint   _param_grad_pass_texp;
00222         GLint   _param_genlist_init_bbox;
00223         GLint   _param_genlist_start_tex0;
00224         GLint   _param_ftex_width;
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 


siftgpu
Author(s): Changchang Wu (library), Bence Magyar (ROS wrapper)
autogenerated on Thu Jan 2 2014 11:38:01