File: ProgramGLSL.h

package info (click to toggle)
colmap 3.5-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 20,564 kB
  • sloc: ansic: 170,595; cpp: 95,339; python: 2,335; makefile: 183; sh: 51
file content (267 lines) | stat: -rwxr-xr-x 9,404 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
////////////////////////////////////////////////////////////////////////////
//	File:		ProgramGLSL.h
//	Author:		Changchang Wu
//	Description : Interface for ProgramGLSL classes
//		ProgramGLSL:	Glsl Program
//		FilterGLSL:		Glsl Gaussian Filters
//		ShaderBag:	    base class of ShaderBagPKSL and ShaderBagGLSL
//
//	Copyright (c) 2007 University of North Carolina at Chapel Hill
//	All Rights Reserved
//
//	Permission to use, copy, modify and distribute this software and its
//	documentation for educational, research and non-profit purposes, without
//	fee, and without a written agreement is hereby granted, provided that the
//	above copyright notice and the following paragraph appear in all copies.
//
//	The University of North Carolina at Chapel Hill make no representations
//	about the suitability of this software for any purpose. It is provided
//	'as is' without express or implied warranty.
//
//	Please send BUG REPORTS to ccwu@cs.unc.edu
//
////////////////////////////////////////////////////////////////////////////


#ifndef _PROGRAM_GLSL_H
#define _PROGRAM_GLSL_H


#include "ProgramGPU.h"

class ProgramGLSL:public ProgramGPU
{
	class ShaderObject
	{
		GLuint		_shaderID;
		int			_type;
		int			_compiled;
		static int ReadShaderFile(const char * source,  char *& code);
		void CheckCompileLog();
	public:
		void PrintCompileLog(ostream & os  );
		int inline IsValidShaderObject(){	return _shaderID && _compiled;}
		int IsValidVertexShader();
		int IsValidFragmentShader();
		GLuint GetShaderID(){return _shaderID;}
		~ShaderObject();
		ShaderObject(int shadertype,  const char * source, int filesource =0);
	};

protected:
	int			_linked;
	GLint		_TextureParam0;
	GLuint		_programID;
private:
	void AttachShaderObject(ShaderObject& shader);
	void DetachShaderObject(ShaderObject& shader);

public:
	void ReLink();
	int IsNative();
	int	UseProgram();
	void PrintLinkLog(std::ostream&os);
	int ValidateProgram();
	void CheckLinkLog();
	int LinkProgram();
	operator GLuint (){return _programID;}
    virtual void * GetProgramID() { return (void*) _programID; }
public:
	ProgramGLSL();
	~ProgramGLSL();
	ProgramGLSL(const char* frag_source);
};


class GLTexImage;
class FilterGLSL : public FilterProgram
{
private:
	ProgramGPU* CreateFilterH(float kernel[], int width);
	ProgramGPU* CreateFilterV(float kernel[], int height);
	ProgramGPU* CreateFilterHPK(float kernel[], int width);
	ProgramGPU* CreateFilterVPK(float kernel[], int height);
public:
    void MakeFilterProgram(float kernel[],  int width);
public:
    FilterGLSL(float sigma) ;
};

class SiftParam;

/////////////////////////////////////////////////////////////////////////////////
//class ShaderBag
//desciption:	pure virtual class
//				provides storage and usage interface of all the shaders for SIFT
//				two implementations are  ShaderBagPKSL and ShaderBagGLSL
/////////////////////////////////////////////////////////////////////////////////
class ShaderBag
{
public:
	//shader:	rgb to gray
	ProgramGPU  * s_gray;
	//shader:	copy keypoint to PBO
	ProgramGPU  * s_copy_key;
	//shader:	debug view
	ProgramGPU  * s_debug;
	//shader:	orientation
	//shader:	assign simple orientation to keypoints if hardware is low
	ProgramGPU  * s_orientation;
	//shader:	display gaussian levels
	ProgramGPU  * s_display_gaussian;
	//shader:	display difference of gassian
	ProgramGPU  * s_display_dog;
	//shader:	display  gradient
	ProgramGPU  * s_display_grad;
	//shader:	display keypoints as red(maximum) and blue (minimum)
	ProgramGPU  * s_display_keys;
	//shader:	up/down-sample
	ProgramGPU  * s_sampling;
	//shader:	compute gradient/dog
	ProgramGPU  * s_grad_pass;
	ProgramGPU  * s_dog_pass;
	//shader:   keypoint detection in one pass
	ProgramGPU  * s_keypoint;
	ProgramGPU  * s_seperate_sp;
	//shader:   feature list generations..
	ProgramGPU	* s_genlist_init_tight;
	ProgramGPU	* s_genlist_init_ex;
	ProgramGPU	* s_genlist_histo;
	ProgramGPU	* s_genlist_start;
	ProgramGPU	* s_genlist_step;
	ProgramGPU	* s_genlist_end;
	ProgramGPU	* s_zero_pass;
	//shader:	generate vertex to display SIFT as a square
	ProgramGPU  * s_vertex_list;
	//shader:	descriptor
	ProgramGPU  * s_descriptor_fp;
	//shader:	copy pixels to margin
	ProgramGPU	* s_margin_copy;
public:
	FilterProgram  *         f_gaussian_skip0;
	vector<FilterProgram*>   f_gaussian_skip0_v;
	FilterProgram  *         f_gaussian_skip1;
	FilterProgram  **        f_gaussian_step;
    int                     _gaussian_step_num;
public:
	virtual void SetGenListInitParam(int w, int h){};
	virtual void SetGenListEndParam(int ktex){};
	virtual void SetMarginCopyParam(int xmax, int ymax){};
	virtual void LoadDescriptorShader(){};
	virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma){};
	virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex, float step){};
	virtual void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step){};
	virtual void LoadOrientationShader() =0;
	virtual void SetGenListStartParam(float width, int tex0) =0;
	virtual void LoadGenListShader(int ndoglev, int nlev)=0;
	virtual void UnloadProgram()=0;
	virtual void LoadKeypointShader(float threshold, float edgeTrheshold) = 0;
	virtual void LoadFixedShaders()=0;
	virtual void LoadDisplayShaders() = 0;
	virtual void SetDogTexParam(int texU, int texD)=0;
	virtual void SetGradPassParam(int texP=0){}
	virtual void SetGenListStepParam(int tex, int tex0) = 0;
	virtual void SetGenVBOParam( float width, float fwidth, float size)=0;
public:
    void CreateGaussianFilters(SiftParam&param);
    void SelectInitialSmoothingFilter(int octave_min, SiftParam&param);
    void LoadDynamicShaders(SiftParam& param);
	ShaderBag();
	virtual ~ShaderBag();
};


class ShaderBagGLSL:public ShaderBag
{
	GLint _param_dog_texu;
	GLint _param_dog_texd;
	GLint _param_ftex_width;
	GLint _param_genlist_start_tex0;
	GLint _param_genlist_step_tex0;
	GLint _param_genvbo_size;
	GLint _param_orientation_gtex;
	GLint _param_orientation_size;
	GLint _param_orientation_stex;
	GLint _param_margin_copy_truncate;
	GLint _param_genlist_init_bbox;
	GLint _param_descriptor_gtex;
	GLint _param_descriptor_size;
	GLint _param_descriptor_dsize;
public:
	virtual void SetMarginCopyParam(int xmax, int ymax);
	void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step);
	void LoadOrientationShader();
	void LoadDescriptorShaderF2();
	virtual void LoadDescriptorShader();
	virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex = 0, float step = 1.0f);
	virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma);
	static void  WriteOrientationCodeToStream(ostream& out);
	static ProgramGLSL* LoadGenListStepShader(int start, int step);
	virtual void SetGenListInitParam(int w, int h);
	virtual void SetGenListStartParam(float width, int tex0);
	virtual void LoadGenListShader(int ndoglev, int nlev);
	virtual void UnloadProgram();
	virtual void LoadKeypointShader(float threshold, float edgeTrheshold);
	virtual void LoadFixedShaders();
	virtual void LoadDisplayShaders();
	virtual void SetDogTexParam(int texU, int texD);
	virtual void SetGenListStepParam(int tex, int tex0);
	virtual void SetGenVBOParam( float width, float fwidth, float size);
	virtual ~ShaderBagGLSL(){}
};


class ShaderBagPKSL:public ShaderBag
{
private:
	GLint	_param_dog_texu;
	GLint	_param_dog_texd;
	GLint	_param_dog_texi;
	GLint	_param_margin_copy_truncate;
	GLint	_param_grad_pass_texp;
	GLint	_param_genlist_init_bbox;
	GLint	_param_genlist_start_tex0;
	GLint	_param_ftex_width;
	GLint	_param_genlist_step_tex0;
	GLint	_param_genlist_end_ktex;
	GLint	_param_genvbo_size;
	GLint	_param_orientation_gtex;
	GLint	_param_orientation_otex;
	GLint	_param_orientation_size;
	GLint	_param_descriptor_gtex;
	GLint	_param_descriptor_otex;
	GLint	_param_descriptor_size;
	GLint	_param_descriptor_dsize;

    //
    ProgramGLSL* s_rect_description;
public:
    ShaderBagPKSL () {s_rect_description = NULL; }
	virtual ~ShaderBagPKSL() {if(s_rect_description) delete s_rect_description; }
	virtual void LoadFixedShaders();
	virtual void LoadDisplayShaders();
	virtual void LoadOrientationShader() ;
	virtual void SetGenListStartParam(float width, int tex0) ;
	virtual void LoadGenListShader(int ndoglev, int nlev);
	virtual void UnloadProgram();
	virtual void LoadKeypointShader(float threshold, float edgeTrheshold) ;
	virtual void LoadDescriptorShader();
	virtual void LoadDescriptorShaderF2();
    static ProgramGLSL* LoadDescriptorProgramRECT();
	static ProgramGLSL* LoadDescriptorProgramPKSL();
/////////////////
	virtual void SetDogTexParam(int texU, int texD);
	virtual void SetGradPassParam(int texP);
	virtual void SetGenListStepParam(int tex, int tex0);
	virtual void SetGenVBOParam( float width, float fwidth, float size);
	virtual void SetFeatureDescirptorParam(int gtex, int otex, float dwidth, float fwidth, float width, float height, float sigma);
	virtual void SetFeatureOrientationParam(int gtex, int width, int height, float sigma, int stex, float step);
	virtual void SetSimpleOrientationInput(int oTex, float sigma, float sigma_step);
	virtual void SetGenListEndParam(int ktex);
	virtual void SetGenListInitParam(int w, int h);
	virtual void SetMarginCopyParam(int xmax, int ymax);
};


#endif