ShaderMan.cpp
Go to the documentation of this file.
00001 
00002 //      File:           ShaderMan.cpp
00003 //      Author:         Changchang Wu
00004 //      Description :   implementation of the ShaderMan class.
00005 //                              A Shader Manager that calls different implementation of shaders
00006 //
00007 //
00008 //      Copyright (c) 2007 University of North Carolina at Chapel Hill
00009 //      All Rights Reserved
00010 //
00011 //      Permission to use, copy, modify and distribute this software and its
00012 //      documentation for educational, research and non-profit purposes, without
00013 //      fee, and without a written agreement is hereby granted, provided that the
00014 //      above copyright notice and the following paragraph appear in all copies.
00015 //      
00016 //      The University of North Carolina at Chapel Hill make no representations
00017 //      about the suitability of this software for any purpose. It is provided
00018 //      'as is' without express or implied warranty. 
00019 //
00020 //      Please send BUG REPORTS to ccwu@cs.unc.edu
00021 //
00023 
00024 
00025 #include "GL/glew.h"
00026 #include <vector>
00027 #include <iostream>
00028 #include <stdlib.h>
00029 #include <math.h>
00030 using std::vector;
00031 using std::ostream;
00032 using std::endl;
00033 
00034 
00035 #include "ProgramGLSL.h"
00036 #include "GlobalUtil.h"
00037 #include "GLTexImage.h"
00038 #include "SiftGPU.h"
00039 #include "ShaderMan.h"
00040 
00042 ShaderBag   * ShaderMan::s_bag = NULL;
00043 
00045 // Construction/Destruction
00047 
00048 void ShaderMan::InitShaderMan(SiftParam&param)
00049 {
00050         if(s_bag) return;
00051 
00052         if(GlobalUtil::_usePackedTex )  s_bag = new ShaderBagPKSL;
00053         else                                    s_bag =new ShaderBagGLSL;       
00054 
00055     GlobalUtil::StartTimer("Load Programs");
00056         s_bag->LoadFixedShaders();
00057     s_bag->LoadDynamicShaders(param);
00058         if(GlobalUtil::_UseSiftGPUEX)   s_bag->LoadDisplayShaders();
00059     GlobalUtil::StopTimer();
00060 
00061         GlobalUtil::CheckErrorsGL("InitShaderMan");
00062 }
00063 
00064 
00065 void ShaderMan::DestroyShaders()
00066 {
00067         if(s_bag) delete s_bag;
00068     s_bag   =   NULL; 
00069 }
00070 
00071 void ShaderMan::UnloadProgram()
00072 {
00073         if(s_bag) s_bag->UnloadProgram();
00074 }
00075 
00076 void ShaderMan::FilterImage(FilterProgram* filter, GLTexImage *dst, GLTexImage *src, GLTexImage*tmp)
00077 {
00078     if(filter == NULL) return; 
00079 
00081     src->FillMargin(filter->_size, 0);
00082 
00083         //output parameter
00084         if(tmp) tmp->AttachToFBO(0);
00085         else dst->AttachToFBO(0);
00086 
00087 
00088         //input parameter
00089         src->BindTex();
00090         dst->FitTexViewPort();
00091 
00092         //horizontal filter
00093         filter->s_shader_h->UseProgram();
00094         dst->DrawQuad();
00095 
00096         //parameters
00097         if(tmp)
00098         {
00099                 // fill margin for out-of-boundary lookup
00100                 tmp->DetachFBO(0);
00101                 tmp->AttachToFBO(0);
00102                 tmp->FillMargin(0, filter->_size);
00103                 tmp->DetachFBO(0);
00104                 dst->AttachToFBO(0);
00105                 tmp->BindTex();
00106         }
00107         else
00108         {
00109                 glFinish();
00110                 // fill margin for out-of-boundary lookup
00111                 dst->FillMargin(0, filter->_size);
00112                 dst->BindTex();
00113         }
00114 
00115         //vertical filter
00116         filter->s_shader_v->UseProgram();
00117         dst->DrawQuad();
00118 
00119 
00120         //clean up
00121         dst->UnbindTex();
00122         dst->DetachFBO(0);
00123 
00124         //
00125         ShaderMan::UnloadProgram();
00126 }
00127 
00128 
00129 void ShaderMan::FilterInitialImage(GLTexImage* tex, GLTexImage* buf)
00130 {
00131     if(s_bag->f_gaussian_skip0) FilterImage(s_bag->f_gaussian_skip0, tex, tex, buf);
00132 }
00133 
00134 void ShaderMan::FilterSampledImage(GLTexImage* tex, GLTexImage* buf)
00135 {
00136     if(s_bag->f_gaussian_skip1) FilterImage(s_bag->f_gaussian_skip1, tex, tex, buf);
00137 }
00138 
00139 void ShaderMan::TextureCopy(GLTexImage*dst, GLTexImage*src)
00140 {
00141 
00142         dst->AttachToFBO(0);
00143 
00144         src->BindTex();
00145 
00146         dst->FitTexViewPort();
00147 
00148         dst->DrawQuad();
00149 
00150         dst->UnbindTex();
00151 //      ShaderMan::UnloadProgram();
00152         dst->DetachFBO(0);
00153         return;
00154 }
00155 void ShaderMan::TextureDownSample(GLTexImage *dst, GLTexImage *src, int scale)
00156 {
00157         //output parameter
00158         
00159         dst->AttachToFBO(0);
00160 
00161         //input parameter
00162         src->BindTex();
00163 
00164         //
00165         dst->FitTexViewPort();
00166 
00167         s_bag->s_sampling->UseProgram();
00168 
00169         dst->DrawQuadDS(scale);
00170         src->UnbindTex();
00171 
00172         UnloadProgram();
00173 
00174         dst->DetachFBO(0); 
00175 }
00176 
00177 void ShaderMan::TextureUpSample(GLTexImage *dst, GLTexImage *src, int scale)
00178 {
00179 
00180         //output parameter
00181         dst->AttachToFBO(0);
00182         //input parameter
00183         src->BindTex();
00184 
00185         dst->FitTexViewPort();
00186 
00187         GlobalUtil::SetTextureParameterUS();
00188 
00189         if(GlobalUtil::_usePackedTex)
00190         {
00191                 s_bag->s_sampling->UseProgram();
00192         }
00193 
00194         dst->DrawQuadUS(scale);
00195         src->UnbindTex();
00196 
00197         UnloadProgram();
00198 
00199         dst->DetachFBO(0);
00200 
00201         GlobalUtil::SetTextureParameter();
00202 }
00203 
00204 
00205 
00206 void ShaderMan::UseShaderDisplayGaussian()
00207 {
00208         if(s_bag && s_bag->s_display_gaussian) s_bag->s_display_gaussian->UseProgram();
00209 }
00210 
00211 void ShaderMan::UseShaderDisplayDOG()
00212 {
00213         if(s_bag && s_bag->s_display_dog) s_bag->s_display_dog->UseProgram();
00214 }
00215 
00216 
00217 
00218 void ShaderMan::UseShaderRGB2Gray()
00219 {
00220         if(s_bag && s_bag->s_gray)s_bag->s_gray->UseProgram();
00221 }
00222 
00223 
00224 void ShaderMan::UseShaderDisplayGrad()
00225 {
00226         if(s_bag && s_bag->s_display_grad) s_bag->s_display_grad->UseProgram();
00227 }
00228 
00229 
00230 void ShaderMan::UseShaderDisplayKeypoints()
00231 {
00232         if(s_bag && s_bag->s_display_keys) s_bag->s_display_keys->UseProgram();
00233 }
00234 
00235 
00236 
00237 
00238 
00239 void ShaderMan::UseShaderGradientPass(int texP)
00240 {
00241         s_bag->s_grad_pass->UseProgram();
00242         s_bag->SetGradPassParam(texP);  
00243 }
00244 
00245 
00246 void ShaderMan::UseShaderKeypoint(int texU, int texD)
00247 {
00248         s_bag->s_keypoint->UseProgram();
00249         s_bag->SetDogTexParam(texU, texD);
00250 }
00251 
00252 
00253 
00254 void ShaderMan::UseShaderGenListInit(int w, int h, int tight)
00255 {
00256         if(tight)
00257         {
00258                 s_bag->s_genlist_init_tight->UseProgram();
00259         }else
00260         {
00261                 s_bag->s_genlist_init_ex->UseProgram();
00262                 s_bag->SetGenListInitParam(w, h);
00263         }
00264 }
00265 
00266 void ShaderMan::UseShaderGenListHisto()
00267 {
00268         s_bag->s_genlist_histo->UseProgram();
00269 
00270 }
00271 
00272 
00273 
00274 
00275 void ShaderMan::UseShaderGenListStart(float fw, int tex0)
00276 {
00277         s_bag->s_genlist_start->UseProgram();
00278         s_bag->SetGenListStartParam(fw, tex0);
00279 }
00280 
00281 void ShaderMan::UseShaderGenListStep(int tex, int tex0)
00282 {
00283         s_bag->s_genlist_step->UseProgram();
00284         s_bag->SetGenListStepParam( tex,  tex0);
00285 }
00286 
00287 void ShaderMan::UseShaderGenListEnd(int ktex)
00288 {
00289         s_bag->s_genlist_end->UseProgram();
00290         s_bag->SetGenListEndParam(ktex);
00291 }
00292 
00293 void ShaderMan::UseShaderDebug()
00294 {
00295         if(s_bag->s_debug)      s_bag->s_debug->UseProgram();
00296 }
00297 
00298 void ShaderMan::UseShaderZeroPass()
00299 {
00300         if(s_bag->s_zero_pass) s_bag->s_zero_pass->UseProgram();
00301 }
00302 
00303 void ShaderMan::UseShaderGenVBO( float width, float fwidth, float size)
00304 {
00305         s_bag->s_vertex_list->UseProgram();
00306         s_bag->SetGenVBOParam(width, fwidth, size);
00307 }
00308 void ShaderMan::UseShaderMarginCopy(int xmax, int ymax)
00309 {
00310         s_bag->s_margin_copy->UseProgram();
00311         s_bag->SetMarginCopyParam(xmax, ymax);
00312         
00313 }
00314 void ShaderMan::UseShaderCopyKeypoint()
00315 {
00316         s_bag->s_copy_key->UseProgram();
00317 }
00318 
00319 void ShaderMan::UseShaderSimpleOrientation(int oTex, float sigma, float sigma_step)
00320 {
00321         s_bag->s_orientation->UseProgram();
00322         s_bag->SetSimpleOrientationInput(oTex, sigma, sigma_step);
00323 }
00324 
00325 
00326 
00327 void ShaderMan::UseShaderOrientation(int gtex, int width, int height, float sigma, int auxtex, float step, int keypoint_list)
00328 {
00329         s_bag->s_orientation->UseProgram();
00330 
00331         //changes in v345. 
00332         //set sigma to 0 to identify keypoit list mode
00333         //set sigma to negative to identify fixed_orientation
00334         if(keypoint_list) sigma = 0.0f;
00335         else if(GlobalUtil::_FixedOrientation) sigma = - sigma;
00336 
00337         s_bag->SetFeatureOrientationParam(gtex, width, height, sigma, auxtex, step);
00338 }
00339 
00340 void ShaderMan::UseShaderDescriptor(int gtex, int otex, int dwidth, int fwidth,  int width, int height, float sigma)
00341 {
00342         s_bag->s_descriptor_fp->UseProgram();
00343         s_bag->SetFeatureDescirptorParam(gtex, otex, (float)dwidth,  (float)fwidth, (float)width, (float)height, sigma);
00344 }
00345 
00346 void ShaderMan::SelectInitialSmoothingFilter(int octave_min, SiftParam&param)
00347 {
00348     s_bag->SelectInitialSmoothingFilter(octave_min, param);
00349 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


rgbd_registration
Author(s): Ross Kidson
autogenerated on Thu May 23 2013 15:36:53