Blame view

stim/gl/gl_spider.h 12 KB
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
1
2
3
  #ifndef STIM_GL_SPIDER_H
  #define STIM_GL_SPIDER_H
  
a9b45efe   Pavel Govyadinov   changes to spider
4
  #include <GL/glew.h>
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
5
  #include <GL/glut.h>
a9b45efe   Pavel Govyadinov   changes to spider
6
7
8
  #include <cuda.h>
  #include <cuda_gl_interop.h>
  #include <cudaGL.h>
1a456186   Pavel Govyadinov   Added directional...
9
  #include <math.h>
4cefeb6d   Pavel Govyadinov   Changes to the re...
10
  #include "gl_texture.h"
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
11
12
13
  #include "../visualization/camera.h"
  #include "./error.h"
  #include "../math/vector.h"
4cefeb6d   Pavel Govyadinov   Changes to the re...
14
  #include "../math/rect.h"
a9b45efe   Pavel Govyadinov   changes to spider
15
16
  #include "../cuda/cost.h"
  #include "../cuda/glbind.h"
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
17
18
19
20
21
22
23
24
  
  namespace stim
  {
  
  template<typename T>
  class gl_spider : public virtual gl_texture<T>
  {
  	//doen't use gl_texture really, just needs the GLuint id.
4cefeb6d   Pavel Govyadinov   Changes to the re...
25
  	//doesn't even need the texture iD really.
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
26
27
28
29
30
31
  	private:
  		stim::camera rotator;
  		stim::vec<float> position;  	//vector designating the position of the spider.
  		stim::vec<float> direction;	//vector designating the orientation of the spider
  						//always a unit vector.
  		stim::vec<float> magnitude;	//magnitude of the direction vector.
4cefeb6d   Pavel Govyadinov   Changes to the re...
32
33
  						//mag[0] = length.
  						//mag[1] = width.
4cefeb6d   Pavel Govyadinov   Changes to the re...
34
  		using gl_texture<T>::texID;
a9f956be   Pavel Govyadinov   Fixed the cost fu...
35
  		//float (*S)[][];
32c433c7   Pavel Govyadinov   recovered the maj...
36
  		//using image_stack<T>::S;
a9b45efe   Pavel Govyadinov   changes to spider
37
38
39
40
41
42
  		cudaArray* c_Array;
  		//void** devPtr;
  		//size_t size;
  		cudaGraphicsResource_t resource;
  		GLuint fboID;
  		GLuint texbufferID;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
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
  
  		void
  		findOptimalDirection()
  		{
  			/* Method for finding the best direction for the spider.
  			   Uses the camera to rotate. Then Calls Evaluate to find new cost.
  			*/
  		}
  
  		void
  		findOptimalPosition()
  		{
  			/* Method for finding the best direction for the spider.
  			   Not sure if necessary since the next position for the spider
  			   will be at direction * magnitude. */
  		}
  	
  		void
  		findOptimalScale()
  		{
  			/* Method for finding the best scale for the spider.
  			   changes the x, y, z size of the spider to minimize the cost
  			   function. */
  		}
  
  		void
  		Evaluate()
  		{	
  			/* Uses uniform sampler2D in order to take a difference between
  			   the colors of two textures. 1st texture is the spider template,
  			   the 2nd is the location of the spider's overlap with the
  			   gl_template 
  	
  			   does the spider need to track it's location? Prob not since
  			   position can be set with gl_texture coordinates */
  		
  		}
a9b45efe   Pavel Govyadinov   changes to spider
80
  		
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
81
82
83
84
85
  		void
  		Optimize()
  		{
  			/*find the optimum direction and scale */ 
  		}
13c2a7d4   Pavel Govyadinov   some changes to t...
86
  		/*
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
87
88
89
  		void
  		Step()
  		{
13c2a7d4   Pavel Govyadinov   some changes to t...
90
  			// move to the new position 
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
91
  		}
13c2a7d4   Pavel Govyadinov   some changes to t...
92
  		*/
a9f956be   Pavel Govyadinov   Fixed the cost fu...
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
268
269
270
271
272
273
  		
  		void
  		GenerateFBO(unsigned int width, unsigned int height)
  		{
  			glGenFramebuffers(1, &fboID);
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);
  			int numChannels = 1;
  			unsigned char* texels = new unsigned char[width * height * numChannels];
  			glGenTextures(1, &texbufferID);
  			glBindTexture(GL_TEXTURE_2D, texbufferID);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  			glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE,
  				 width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texels);   
  			delete[] texels;
  			glBindFramebuffer(GL_FRAMEBUFFER, 0); 
  			glBindTexture(GL_TEXTURE_2D, 0);
  		}
  
  		void
  		UpdateBuffer(float v_x, float v_y)
  		{	
  			//std::cout << v_y << std::endl;
  			float len = 10.0;
  			stim::vec<float>p1; 
          	        stim::vec<float>p2; 
  	                stim::vec<float>p3; 
                  	stim::vec<float>p4;	
  			p1 = hor.p(1,1);
  			p2 = hor.p(1,0);
  			p3 = hor.p(0,0);
  			p4 = hor.p(0,1);
  			glBegin(GL_QUADS);
  				glTexCoord3f(
  					p1[0],
  					p1[1],
  					p1[2]
  					);
  				//glVertex2f(0.0,0.0);
  				glVertex2f(v_x,v_y);
  				glTexCoord3f(
  					p2[0],
  					p2[1],
  					p2[2]
  					);
  				//glVertex2f(1.0, 0.0);
  				glVertex2f(v_x+len, v_y);
  				glTexCoord3f(
  					p3[0],
  					p3[1],
  					p3[2]
  					);
  				//glVertex2f(1.0, 2.0);
  				glVertex2f(v_x+len, v_y+len);
  				glTexCoord3f(
  					p4[0],
  					p4[1],
  					p4[2]
  					);
  				//glVertex2f(0.0, 2.0);
  				glVertex2f(v_x, v_y+len);
  			 glEnd();
  			 p1 = ver.p(1,1);
  			 p2 = ver.p(1,0);
  			 p3 = ver.p(0,0);
  			 p4 = ver.p(0,1);
  		 	 glBegin(GL_QUADS);
  				glTexCoord3f(
  					p1[0],
  					p1[1],
  					p1[2]
  					);
  				//glVertex2f(1.0, 0.0);
  				glVertex2f(v_x+len, v_y);
  				glTexCoord3f(
  					p2[0],
  					p2[1],
  					p2[2]
  					);
  				//glVertex2f(2.0, 0.0);
  				glVertex2f(v_x+2*len, v_y);
  				glTexCoord3f(
  					p3[0],
  					p3[1],
  					p3[2]
  					);
  				//glVertex2f(2.0, 2.0);
  				glVertex2f(v_x+2*len, v_y+len);
  				glTexCoord3f(
  					p4[0],
  					p4[1],
  					p4[2]
  					);
  				//glVertex2f(1.0, 2.0);
  				glVertex2f(v_x+len, v_y+len);
  			glEnd();
  		}
  
  		void
  		Update(float v_x, float v_y, vec<float> dir)
  		{
  			vec<float> Y(1.0,0.0,0.0);
  			if(cos(Y.dot(dir))< 0.087){
  				Y[0] = 0.0; Y[1] = 1.0;}
  			hor = stim::rect<float>(magnitude, position, dir.norm(),
  				((Y.cross(dir)).cross(dir)).norm());
  			ver = stim::rect<float>(magnitude, position, dir.norm(),
  				 hor.n());
  			UpdateBuffer(v_x, v_y);
  		}
  
  
  		void
  		Sample(vec<float> in = (0,0,1), int numSamples = 1089, int solidAngle = M_PI/2)
  		{
  			GenerateFBO(20, numSamples*10);
  
  			float samples[numSamples][3];    	//Set up the variables
  							 	//necessary for sample generation
  			vec<float> d_s = in.cart2sph();
  			vec<float> temp;
  			int dim = (sqrt(numSamples)-1)/2;
  			std::cout << dim << std::endl;
  			float y_0 	= 0.0;
  			float len 	= 10.0;
  			float p0  	= M_PI/3;
  			float dt  	= solidAngle/(1.0 * dim);
  			float dp  	= p0/(1.0*dim);
  	
  			
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);//set up GL buffer		
  			glFramebufferTexture2D(
  				GL_FRAMEBUFFER,
  				GL_COLOR_ATTACHMENT0,
  				GL_TEXTURE_2D,
  				texbufferID,
  				0);
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);
  			GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
  			glDrawBuffers(1, DrawBuffers);
  			glBindTexture(GL_TEXTURE_2D, texbufferID);
  			glClearColor(0,0,0,0);
  			glClear(GL_COLOR_BUFFER_BIT);
  			glMatrixMode(GL_PROJECTION);
  			glLoadIdentity();
  			glMatrixMode(GL_MODELVIEW);
  			glLoadIdentity();
  			glViewport(0,0,2.0*len, numSamples*len);
  			gluOrtho2D(0.0,2.0*len,0.0,numSamples*len);
  			glEnable(GL_TEXTURE_3D);
  			glBindTexture(GL_TEXTURE_3D, texID);
  			
  			//Loop over the samples
  			int idx;
  			for(int i = -dim; i <= dim; i++){
  				for(int j = -dim; j <= dim; j++){
  					//Create linear index
  					idx = (i+dim)*(dim*2+1) + (j+dim);
  		//			std::cerr << i+dim << "," << j+dim << ":" << idx << std::endl;
  
  					temp[0] = 1; 			//rotate vector
  					temp[1] = d_s[1]+dt*i;
  					temp[2] = d_s[2]+dp*j;
  
  					temp = temp.sph2cart();		//back to cart
  					samples[idx][0] = temp[0];	//save sample vector
  					samples[idx][1] = temp[1];
  					samples[idx][2] = temp[2];
  
  					Update(0.0, y_0+(idx)*10, temp); 
  				}
  			}
  			//Finalize GL_buffer
  			glBindTexture(GL_TEXTURE_3D, 0);                      
  			glDisable(GL_TEXTURE_3D);
  			glBindFramebuffer(GL_FRAMEBUFFER,0);
  			glBindTexture(GL_TEXTURE_2D, 0);
  		}
  
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
274
  	public:
4cefeb6d   Pavel Govyadinov   Changes to the re...
275
  
13c2a7d4   Pavel Govyadinov   some changes to t...
276
277
278
279
  		stim::rect<float> hor;
  		stim::rect<float> ver;	
  
  
13c2a7d4   Pavel Govyadinov   some changes to t...
280
281
  		gl_spider
  		()
4cefeb6d   Pavel Govyadinov   Changes to the re...
282
283
284
  		{
  			setPosition(0.0,0.0,0.0);
  			setDirection(1.0,1.0,1.0);
13c2a7d4   Pavel Govyadinov   some changes to t...
285
  			setMagnitude(0.1,0.1);
a9b45efe   Pavel Govyadinov   changes to spider
286
287
  			//GenerateFBO(400,200);
  			//Update();
4cefeb6d   Pavel Govyadinov   Changes to the re...
288
289
  		}
  
13c2a7d4   Pavel Govyadinov   some changes to t...
290
291
  		gl_spider
  		(vec<float> pos, vec<float> dir, vec<float> mag)
4cefeb6d   Pavel Govyadinov   Changes to the re...
292
293
294
295
  		{
  			position = pos;
  			direction = dir;
  			magnitude = mag;
a9b45efe   Pavel Govyadinov   changes to spider
296
297
  			//GenerateFBO(400,200);
  			//Update();
13c2a7d4   Pavel Govyadinov   some changes to t...
298
299
300
301
302
303
304
305
306
  		}
  		//temporary cost for convenience.	
  		gl_spider
  		(float pos_x, float pos_y, float pos_z, float dir_x, float dir_y, float dir_z,
  			float mag_x, float mag_y)
  		{
  			setPosition(pos_x, pos_y, pos_z);
  			setDirection(dir_x, dir_y, dir_z);
  			setMagnitude(mag_x, mag_y);
a9b45efe   Pavel Govyadinov   changes to spider
307
308
309
310
311
312
313
314
  			//GenerateFBO(400,200);
  			//Update();
  		}
  		
  		void
  		attachSpider(GLuint id)
  		{
  			texID = id;
a9f956be   Pavel Govyadinov   Fixed the cost fu...
315
316
  			Sample(direction);
  			//GenerateFBO(20,10000);
1a456186   Pavel Govyadinov   Added directional...
317
  		//	Update();
a9f956be   Pavel Govyadinov   Fixed the cost fu...
318
  		//	generateVectorField(direction, 4.0);
a39577bf   Pavel Govyadinov   Changes to the sp...
319
320
321
322
323
  		}
  
  		void
  		Update()
  		{
13c2a7d4   Pavel Govyadinov   some changes to t...
324
325
326
  			vec<float> Y(1.0,0.0,0.0);
  			if(cos(Y.dot(direction))< 0.087){
  				Y[0] = 0.0; Y[1] = 1.0;}
879321c4   Pavel Govyadinov   minor changes
327
328
  			hor = stim::rect<float>(magnitude, position, direction.norm(),
  				((Y.cross(direction)).cross(direction)).norm());
13c2a7d4   Pavel Govyadinov   some changes to t...
329
  			ver = stim::rect<float>(magnitude, position, direction.norm(),
879321c4   Pavel Govyadinov   minor changes
330
  				 hor.n());
a9f956be   Pavel Govyadinov   Fixed the cost fu...
331
332
  			//UpdateBuffer();
  			generateVectorField(direction, 4.0);
4cefeb6d   Pavel Govyadinov   Changes to the re...
333
  		}
1a456186   Pavel Govyadinov   Added directional...
334
  
a39577bf   Pavel Govyadinov   Changes to the sp...
335
  		
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
336
  		vec<float>
a39577bf   Pavel Govyadinov   Changes to the sp...
337
  		getPosition()
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
338
339
340
341
342
  		{
  			return position;
  		}
  	
  		vec<float>
a39577bf   Pavel Govyadinov   Changes to the sp...
343
  		getDirection()
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
344
345
346
347
348
  		{
  			return direction;
  		}
  
  		vec<float>
a39577bf   Pavel Govyadinov   Changes to the sp...
349
  		getMagnitude()
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
  		{
  			return magnitude;
  		}
  	
  		void
  		setPosition(vec<float> pos)
  		{
  			position = pos;
  		}
  		
  		void
  		setPosition(float x, float y, float z)
  		{
  			position[0] = x;
  			position[1] = y;
  			position[2] = z;
  		}
  
  		void
  		setDirection(vec<float> dir)
  		{
  			direction = dir;
  		}
  		
  		void
  		setDirection(float x, float y, float z)
  		{
  			direction[0] = x;
  			direction[1] = y;
  			direction[2] = z;
  		}
  		
  		void
  		setMagnitude(vec<float> mag)
  		{
  			magnitude = mag;
  		}
  		
  		void
4cefeb6d   Pavel Govyadinov   Changes to the re...
389
  		setMagnitude(float x, float y)
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
390
391
392
  		{
  			magnitude[0] = x;
  			magnitude[1] = y;
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
393
  		}
a9b45efe   Pavel Govyadinov   changes to spider
394
395
396
397
398
399
  	
  		GLuint
  		getFB()
  		{
  			return fboID;
  		}
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
400
  
13c2a7d4   Pavel Govyadinov   some changes to t...
401
402
403
404
405
  		void
  		Step()
  		{
  			std::cout << position[0] << "," << position[1] << "," << position[1]
  				<< std::endl;
a39577bf   Pavel Govyadinov   Changes to the sp...
406
407
  			setPosition(direction*magnitude[1]/2+position);
  			Update();
13c2a7d4   Pavel Govyadinov   some changes to t...
408
409
410
411
  			std::cout << position[0] << "," << position[1] << "," << position[1]
  				<< std::endl;
  			
  		}
a9b45efe   Pavel Govyadinov   changes to spider
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
  
  		void
  		UpdateBuffer()
  		{	
  			stim::vec<float>p1; 
          	        stim::vec<float>p2; 
  	                stim::vec<float>p3; 
                  	stim::vec<float>p4;	
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);
  			glFramebufferTexture2D(
  				GL_FRAMEBUFFER,
  				GL_COLOR_ATTACHMENT0,
  				GL_TEXTURE_2D,
  				texbufferID,
  				0);
  			glBindFramebuffer(GL_FRAMEBUFFER, fboID);
  			GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
  			glDrawBuffers(1, DrawBuffers);
  			glBindTexture(GL_TEXTURE_2D, texbufferID);
  			glClearColor(0,0,0,0);
  			glClear(GL_COLOR_BUFFER_BIT);
  			glMatrixMode(GL_PROJECTION);
  			glLoadIdentity();
  			glMatrixMode(GL_MODELVIEW);
  			glLoadIdentity();
  			glViewport(0,0,400,200);
  			gluOrtho2D(0.0,2.0,0.0,2.0);
  			glEnable(GL_TEXTURE_3D);
  			glBindTexture(GL_TEXTURE_3D, texID);
  			p1 = hor.p(1,1);
  			p2 = hor.p(1,0);
  			p3 = hor.p(0,0);
  			p4 = hor.p(0,1);
  			glBegin(GL_QUADS);
  				glTexCoord3f(
  					p1[0],
  					p1[1],
  					p1[2]
  					);
  				glVertex2f(0.0,0.0);
  				glTexCoord3f(
  					p2[0],
  					p2[1],
  					p2[2]
  					);
  				glVertex2f(1.0, 0.0);
  				glTexCoord3f(
  					p3[0],
  					p3[1],
  					p3[2]
  					);
  				glVertex2f(1.0, 2.0);
  				glTexCoord3f(
  					p4[0],
  					p4[1],
  					p4[2]
  					);
  				glVertex2f(0.0, 2.0);
  			 glEnd();
  			 p1 = ver.p(1,1);
  			 p2 = ver.p(1,0);
  			 p3 = ver.p(0,0);
  			 p4 = ver.p(0,1);
  		 	 glBegin(GL_QUADS);
  				glTexCoord3f(
  					p1[0],
  					p1[1],
  					p1[2]
  					);
  				glVertex2f(1.0, 0.0);
  				glTexCoord3f(
  					p2[0],
  					p2[1],
  					p2[2]
  					);
  				glVertex2f(2.0, 0.0);
  				glTexCoord3f(
  					p3[0],
  					p3[1],
  					p3[2]
  					);
  				glVertex2f(2.0, 2.0);
  				glTexCoord3f(
  					p4[0],
  					p4[1],
  					p4[2]
  					);
  				glVertex2f(1.0, 2.0);
  			glEnd();
1a456186   Pavel Govyadinov   Added directional...
501
502
503
504
505
506
  			glBindTexture(GL_TEXTURE_3D, 0);                      
  			glDisable(GL_TEXTURE_3D);
  			glBindFramebuffer(GL_FRAMEBUFFER,0);
  			glBindTexture(GL_TEXTURE_2D, 0);
  		}
  
1a456186   Pavel Govyadinov   Added directional...
507
508
509
510
  		
  		void
  		generateVectorField(stim::vec<float> d, float dim)
  		{
a9f956be   Pavel Govyadinov   Fixed the cost fu...
511
  			vec<float> d_s = d.cart2sph();
1a456186   Pavel Govyadinov   Added directional...
512
513
514
515
516
517
518
  			vec<float> temp;
  			float Dim 	= (float) dim;
  			float y_0 	= 0.0;
  			float x_0 	= 0.0;
  			float len 	= 4.0/(2.0*Dim+1.0);
  			float t0  	= M_PI/2;
  			float p0  	= M_PI/3;
83d27214   Pavel Govyadinov   fixed the bug whe...
519
520
  			float dt  	= t0/Dim;
  			float dp  	= p0/Dim;
1a456186   Pavel Govyadinov   Added directional...
521
522
523
524
525
526
527
528
  			for(int i = -dim; i <= dim; i++){
  				for(int j = -dim; j <= dim; j++){
  					//field[i+dim][j+dim][0] = d[0];
  					//field[i+dim][j+dim][1] = d[1]+dt*i;
  					//field[i+dim][j+dim][2] = d[2]+dp*j;
  					temp[0] = 1;
  					temp[1] = d_s[1]+dt*i;
  					temp[2] = d_s[2]+dp*j;
a9f956be   Pavel Govyadinov   Fixed the cost fu...
529
530
  					temp = temp.sph2cart();
  					Update(x_0+2.0*(i+dim)*len, y_0+(j+dim)*len, temp); 
1a456186   Pavel Govyadinov   Added directional...
531
532
533
534
535
  				}
  			}
  			
  		}
  		                                                                   
a9b45efe   Pavel Govyadinov   changes to spider
536
  
a9b45efe   Pavel Govyadinov   changes to spider
537
538
539
540
541
  
  
  		void
  		initCuda()
  		{	
1a456186   Pavel Govyadinov   Added directional...
542
  			stim::cudaSetDevice();
a9f956be   Pavel Govyadinov   Fixed the cost fu...
543
544
545
  			GLint max;
  			glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
  			std::cout << max << std::endl;
a9b45efe   Pavel Govyadinov   changes to spider
546
547
548
549
550
551
552
553
  		}
  		
  		void
  		createResource()
  		{
  			HANDLE_ERROR(
  				cudaGraphicsGLRegisterImage(
  					 &resource,
0fdb4ed4   Pavel Govyadinov   fixed the issue w...
554
  				 	texbufferID,
a9b45efe   Pavel Govyadinov   changes to spider
555
  				 	GL_TEXTURE_2D,
0fdb4ed4   Pavel Govyadinov   fixed the issue w...
556
557
  				 	//CU_GRAPHICS_REGISTER_FLAGS_NONE)
  					cudaGraphicsMapFlagsReadOnly)
a9b45efe   Pavel Govyadinov   changes to spider
558
  			);
a9b45efe   Pavel Govyadinov   changes to spider
559
560
561
562
563
564
565
566
  		} 
  		
  		void
  		destroyResource()
  		{
  			HANDLE_ERROR(
  				cudaGraphicsUnregisterResource(resource)
  			);		
a9b45efe   Pavel Govyadinov   changes to spider
567
568
  		}
  
1a456186   Pavel Govyadinov   Added directional...
569
  
a9f956be   Pavel Govyadinov   Fixed the cost fu...
570
  		int
a9b45efe   Pavel Govyadinov   changes to spider
571
  		getCost()
0fdb4ed4   Pavel Govyadinov   fixed the issue w...
572
  		{
a9b45efe   Pavel Govyadinov   changes to spider
573
  			createResource();
a9f956be   Pavel Govyadinov   Fixed the cost fu...
574
  			int cost = 	get_cost(resource);
a9b45efe   Pavel Govyadinov   changes to spider
575
576
577
  			destroyResource();
  			return cost;
  		}
4cefeb6d   Pavel Govyadinov   Changes to the re...
578
  };
fb0bc2f1   Pavel Govyadinov   added the gl_spid...
579
580
  }
  #endif