GLSLShader.cpp 16.6 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
#define EXPORTING 1

#include "Utils/GLSLShader.h"
#include <iostream>
#include <fstream>
29
#include <vector>
Pierre Kraemer's avatar
Pierre Kraemer committed
30
31
32
33
34
35
36
37
38
39


namespace CGoGN
{

namespace Utils
{

GLSLShader::GLSLShader()
{
40
41
42
43
	m_vertex_shader_object = 0;
	m_fragment_shader_object = 0;
	m_geom_shader_object = 0;
	m_program_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
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
}


bool GLSLShader::areGeometryShadersSupported()
{
	if ( ! glewGetExtension("GL_EXT_geometry_shader4")) return false;
	return true;
}

bool GLSLShader::areShadersSupported()
{
	if ( ! glewGetExtension("GL_ARB_vertex_shader")) return false;
	if ( ! glewGetExtension("GL_ARB_fragment_shader")) return false;
	if ( ! glewGetExtension("GL_ARB_shader_objects")) return false;
	if ( ! glewGetExtension("GL_ARB_shading_language_100")) return false;

	return true;
}


bool GLSLShader::areVBOSupported()
{
	if (!glewGetExtension("GL_ARB_vertex_buffer_object"))
		return false;
	return true;
}



char* GLSLShader::loadSourceFile(  const std::string& filename)
{
	std::ifstream	file;
	int				file_size;
	char*			shader_source;


	/*** opening file ***/
	file.open( filename.c_str() , std::ios::in | std::ios::binary );

	if( !file.good() )
	{
		std::cerr << "ERROR - GLSLShader::loadSourceFile() - unable to open the file " << filename << "." << std::endl;
		return NULL;
	}


	/*** reading file ***/
	try
	{
		/* get file size */
		file.seekg( 0, std::ios::end );
		file_size = file.tellg();
		file.seekg( 0, std::ios::beg );

		/* allocate shader source table */
		shader_source = new char [ file_size+1 ];

		/* read source file */
		file.read( shader_source, file_size );
		shader_source[ file_size ] = '\0';
	}
	catch( std::exception& io_exception )
	{
		std::cerr << "ERROR - GLSLShader::loadSourceFile() - " << io_exception.what() << std::endl;
		file.close();
		return NULL;
	}


	/*** termination ***/
	file.close();
	return shader_source;
}


bool GLSLShader::loadVertexShader(  const std::string& filename )
{
	bool	flag;
	char	*vertex_shader_source;


	vertex_shader_source = loadSourceFile( filename );

	if( !vertex_shader_source )
	{
		std::cerr << "ERROR - GLSLShader::loadVertexShader() - error occured while loading source file." << std::endl;
		return false;
	}


	flag = loadVertexShaderSourceString( vertex_shader_source );
	delete [] vertex_shader_source;


	return flag;
}


142
bool GLSLShader::loadFragmentShader(const std::string& filename )
Pierre Kraemer's avatar
Pierre Kraemer committed
143
144
{
	bool	flag;
145
	char	*fragment_shader_source;
Pierre Kraemer's avatar
Pierre Kraemer committed
146
147


148
	fragment_shader_source = loadSourceFile( filename );
Pierre Kraemer's avatar
Pierre Kraemer committed
149

150
	if( !fragment_shader_source )
Pierre Kraemer's avatar
Pierre Kraemer committed
151
	{
152
		std::cerr << "ERROR - GLSLShader::loadFragmentShader() - error occured while loading source file." << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
153
154
155
156
		return false;
	}


157
158
	flag = loadFragmentShaderSourceString( fragment_shader_source );
	delete [] fragment_shader_source;
Pierre Kraemer's avatar
Pierre Kraemer committed
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


	return flag;
}


bool GLSLShader::loadGeometryShader(const std::string& filename )
{
	bool	flag;
	char	*geom_shader_source;

	geom_shader_source = loadSourceFile( filename );



	if( !geom_shader_source )
	{
		std::cerr << "ERROR - GLSLShader::loadGeometryShader() - error occured while loading source file." << std::endl;
		return false;
	}

	flag = loadGeometryShaderSourceString( geom_shader_source );
	delete [] geom_shader_source;


	return flag;
}


bool GLSLShader::loadVertexShaderSourceString( const char *vertex_shader_source )
{
	int		status;
	char	*info_log;


	/*** create shader object ***/
195
	m_vertex_shader_object = glCreateShaderObjectARB( GL_VERTEX_SHADER_ARB );
Pierre Kraemer's avatar
Pierre Kraemer committed
196

197
	if( !m_vertex_shader_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
198
199
200
201
202
203
204
205
206
207
208
	{
		std::cerr << "ERROR - GLSLShader::loadVertexShader() - unable to create shader object." << std::endl;
		return false;
	}


	/*** load source file ***/
	if( !vertex_shader_source )
	{
		std::cerr << "ERROR - GLSLShader::loadVertexShader() - source string is empty." << std::endl;

209
210
		glDeleteObjectARB( m_vertex_shader_object );
		m_vertex_shader_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
211
212
213
214

		return false;
	}

215
	glShaderSourceARB( m_vertex_shader_object, 1, (const char**)&vertex_shader_source, NULL );
Pierre Kraemer's avatar
Pierre Kraemer committed
216
217
218


	/*** compile shader object ***/
219
	glCompileShaderARB( m_vertex_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
220

221
	glGetObjectParameterivARB( m_vertex_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
224
	if( !status )
	{
		std::cerr << "ERROR - GLshader::loadVertexShader() - error occured while compiling shader." << std::endl;
225
		info_log = getInfoLog( m_vertex_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
226
227
228
		std::cerr << "  COMPILATION " << info_log << std::endl;
		delete [] info_log;

229
230
		glDeleteObjectARB( m_vertex_shader_object );
		m_vertex_shader_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
231
232
233
234
235
236
237
238
239
240

		return false;
	}


	/*** termination ***/
	return true;
}


241
bool GLSLShader::loadFragmentShaderSourceString( const char *fragment_shader_source )
Pierre Kraemer's avatar
Pierre Kraemer committed
242
243
244
245
246
247
{
	int		status;
	char	*info_log;


	/*** create shader object ***/
248
	m_fragment_shader_object = glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
Pierre Kraemer's avatar
Pierre Kraemer committed
249

250
	if( !m_fragment_shader_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
251
	{
252
		std::cerr << "ERROR - GLSLShader::loadFragmentShader() - unable to create shader object." << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
253
254
255
256
257
		return false;
	}


	/*** load source file ***/
258
	if( !fragment_shader_source )
Pierre Kraemer's avatar
Pierre Kraemer committed
259
	{
260
		std::cerr << "ERROR - GLSLShader::loadFragmentShader() - source string is empty." << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
261

262
263
		glDeleteObjectARB( m_fragment_shader_object );
		m_fragment_shader_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
264
265
266
267

		return false;
	}

268
	glShaderSourceARB( m_fragment_shader_object, 1, (const char**)&fragment_shader_source, NULL );
Pierre Kraemer's avatar
Pierre Kraemer committed
269
270
271


	/*** compile shader object ***/
272
	glCompileShaderARB( m_fragment_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
273

274
	glGetObjectParameterivARB( m_fragment_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
Pierre Kraemer's avatar
Pierre Kraemer committed
275
276
	if( !status )
	{
277
278
		std::cerr << "ERROR - GLshader::loadFragmentShader() - error occured while compiling shader." << std::endl;
		info_log = getInfoLog( m_fragment_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
279
280
281
		std::cerr << "  COMPILATION " << info_log << std::endl;
		delete [] info_log;

282
283
		glDeleteObjectARB( m_fragment_shader_object );
		m_fragment_shader_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302

		return false;
	}


	/*** termination ***/
	return true;
}



bool GLSLShader::loadGeometryShaderSourceString( const char *geom_shader_source )
{
	int		status;
	char	*info_log;


	/*** create shader object ***/
	// glCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB );
303
	m_geom_shader_object = glCreateShader(GL_GEOMETRY_SHADER_EXT);
Pierre Kraemer's avatar
Pierre Kraemer committed
304
305


306
	if( !m_geom_shader_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
307
308
309
310
311
312
313
314
315
316
317
	{
		std::cerr << "ERROR - GLSLShader::loadGeometryShader() - unable to create shader object." << std::endl;
		return false;
	}


	/*** load source file ***/
	if( !geom_shader_source )
	{
		std::cerr << "ERROR - GLSLShader::loadGeometryShader() - source string is empty." << std::endl;

318
319
		glDeleteObjectARB( m_geom_shader_object );
		m_geom_shader_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
320
321
322
323

		return false;
	}

324
	glShaderSourceARB( m_geom_shader_object, 1, (const char**)&geom_shader_source, NULL );
Pierre Kraemer's avatar
Pierre Kraemer committed
325
326
327


	/*** compile shader object ***/
328
	glCompileShaderARB( m_geom_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
329

330
	glGetObjectParameterivARB( m_geom_shader_object, GL_OBJECT_COMPILE_STATUS_ARB, &status );
Pierre Kraemer's avatar
Pierre Kraemer committed
331
332
333
	if( !status )
	{
		std::cerr << "ERROR - GLshader::loadGeometryShader() - error occured while compiling shader." << std::endl;
334
		info_log = getInfoLog( m_geom_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
335
336
337
		std::cerr << "  COMPILATION " << info_log << std::endl;
		delete [] info_log;

338
339
		glDeleteObjectARB( m_geom_shader_object );
		m_geom_shader_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

		return false;
	}


	/*** termination ***/
	return true;
}


char* GLSLShader::getInfoLog( GLhandleARB obj )
{
	char	*info_log;
	int		info_log_length;
	int		length;


	glGetObjectParameterivARB( obj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length );

	info_log = new char [info_log_length];
	glGetInfoLogARB( obj, info_log_length, &length, info_log );


	return info_log;
}


bool GLSLShader::create(GLint inputGeometryPrimitive,GLint outputGeometryPrimitive)
{
	int		status;
	char	*info_log;


	/*** check if shaders are loaded ***/
374
	if( !m_vertex_shader_object || !m_fragment_shader_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
375
	{
376
		std::cerr << "ERROR - GLSLShader::create() - shaders are not defined." << std::endl;
Pierre Kraemer's avatar
Pierre Kraemer committed
377
378
379
380
381
		return false;
	}


	/*** create program object ***/
382
	m_program_object = glCreateProgramObjectARB();
Pierre Kraemer's avatar
Pierre Kraemer committed
383

384
	if( !m_program_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
385
386
387
388
389
390
391
	{
		std::cerr << "ERROR - GLSLShader::create() - unable to create program object." << std::endl;
		return false;
	}


	/*** attach shaders to program object ***/
392
393
394
	glAttachObjectARB( m_program_object, m_vertex_shader_object );
	glAttachObjectARB( m_program_object, m_fragment_shader_object );
	if (m_geom_shader_object)
Pierre Kraemer's avatar
Pierre Kraemer committed
395
	{
396
		glAttachObjectARB( m_program_object, m_geom_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
397

398
399
		glProgramParameteriEXT(m_program_object,GL_GEOMETRY_INPUT_TYPE_EXT,inputGeometryPrimitive);
		glProgramParameteriEXT(m_program_object,GL_GEOMETRY_OUTPUT_TYPE_EXT,outputGeometryPrimitive);
Pierre Kraemer's avatar
Pierre Kraemer committed
400
401
		int temp;
		glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT,&temp);
402
		glProgramParameteriEXT(m_program_object,GL_GEOMETRY_VERTICES_OUT_EXT,temp);
Pierre Kraemer's avatar
Pierre Kraemer committed
403
404
405
406
	}


	/*** link program object ***/
407
	glLinkProgramARB( m_program_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
408

409
	glGetObjectParameterivARB( m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status );
Pierre Kraemer's avatar
Pierre Kraemer committed
410
411
412
	if( !status )
	{
		std::cerr << "ERROR - GLSLShader::create() - error occured while linking shader program." << std::endl;
413
		info_log = getInfoLog( m_program_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
414
415
416
		std::cerr << "  LINK " << info_log << std::endl;
		delete [] info_log;

417
418
419
420
421
422
		glDetachObjectARB( m_program_object, m_vertex_shader_object );
		glDetachObjectARB( m_program_object, m_fragment_shader_object );
		if (m_geom_shader_object)
			glDetachObjectARB( m_program_object, m_geom_shader_object );
		glDeleteObjectARB( m_program_object );
		m_program_object = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
423
424
425
426
427
428
429
430

		return false;
	}

	return true;
}


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
bool GLSLShader::link()
{
	int		status;
	char	*info_log;


	/*** link program object ***/
	glLinkProgramARB( m_program_object );

	glGetObjectParameterivARB( m_program_object, GL_OBJECT_LINK_STATUS_ARB, &status );
	if( !status )
	{
		std::cerr << "ERROR - GLSLShader::create() - error occured while linking shader program." << std::endl;
		info_log = getInfoLog( m_program_object );
		std::cerr << "  LINK " << info_log << std::endl;
		delete [] info_log;

		glDetachObjectARB( m_program_object, m_vertex_shader_object );
		glDetachObjectARB( m_program_object, m_fragment_shader_object );
		if (m_geom_shader_object)
			glDetachObjectARB( m_program_object, m_geom_shader_object );
		glDeleteObjectARB( m_program_object );
		m_program_object = 0;

		return false;
	}

	return true;
}




Pierre Kraemer's avatar
Pierre Kraemer committed
464
465
bool GLSLShader::bind()
{
466
	if( m_program_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
467
	{
468
		glUseProgramObjectARB( m_program_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
469
470
471
472
473
474
475
476
477

		return true;
	}
	else  return false;
}


void GLSLShader::unbind()
{
478
	if( m_program_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
479
480
481
482
483
484
485
486
	{
		glUseProgramObjectARB( 0 );
	}
}


bool GLSLShader::isBinded()
{
487
	return ( m_program_object && m_program_object == glGetHandleARB(GL_PROGRAM_OBJECT_ARB) );
Pierre Kraemer's avatar
Pierre Kraemer committed
488
489
490
491
492
}


GLSLShader::~GLSLShader()
{
493
	if( m_program_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
494
495
496
	{
		unbind();

497
		if( m_vertex_shader_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
498
		{
499
500
			glDetachObjectARB( m_program_object, m_vertex_shader_object );
			glDeleteObjectARB( m_vertex_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
501
		}
502
		if( m_fragment_shader_object )
Pierre Kraemer's avatar
Pierre Kraemer committed
503
		{
504
505
			glDetachObjectARB( m_program_object, m_fragment_shader_object );
			glDeleteObjectARB( m_fragment_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
506
		}
507
		if (m_geom_shader_object)
Pierre Kraemer's avatar
Pierre Kraemer committed
508
		{
509
510
			glDetachObjectARB( m_program_object, m_geom_shader_object );
			glDeleteObjectARB( m_geom_shader_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
511
512
		}

513
		glDeleteObjectARB( m_program_object );
Pierre Kraemer's avatar
Pierre Kraemer committed
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
	}
}


std::string GLSLShader::findFile(const std::string filename)
{
// cherche d'abord dans le repertoire courant
	std::ifstream file;
	file.open(filename.c_str(),std::ios::in );
	if (!file.fail())
	{
		file.close();
		return filename;
	}
	file.close();

// LA MACRO SHADERPATH contient le chemin du repertoire qui contient les fichiers textes
	std::string st(SHADERPATH);
	st.append(filename);

	std::ifstream file2; // on ne peut pas réutiliser file ????
	file2.open(st.c_str(),std::ios::in);
	if (!file2.fail())
	{
		file2.close();
		return st;
	}

	return filename;
}


bool GLSLShader::init()
{
	GLenum error = glewInit();

	if (error != GLEW_OK)
		std::cerr << "Error: " << glewGetErrorString(error) << std::endl;
	else
		std::cout << "Status: Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;

	if (!areVBOSupported())
		std::cout << "VBO not supported !" << std::endl;

	if(!areShadersSupported()) {
		std::cout << "Shaders not supported !" << std::endl;
		return false;
	}
	return true; 
}

bool GLSLShader::loadShaders(const std::string& vs, const std::string& ps)
{
	std::string vss = findFile(vs);
	if(!loadVertexShader(vss)) return false;
	
	std::string pss = findFile(ps);
571
	if(!loadFragmentShader(pss)) return false;
Pierre Kraemer's avatar
Pierre Kraemer committed
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586

	if(!create()) {
		std::cout << "Unable to create the shaders !" << std::endl;
		return false;
	}
	std::cout << "Shaders loaded (" << vs << "," << ps << ")" << std::endl;
	return true; 
}

bool GLSLShader::loadShaders(const std::string& vs, const std::string& ps, const std::string& gs, GLint inputGeometryPrimitive,GLint outputGeometryPrimitive)
{
	std::string vss = findFile(vs);
	if(!loadVertexShader(vss)) return false;

	std::string pss = findFile(ps);
587
	if(!loadFragmentShader(pss)) return false;
Pierre Kraemer's avatar
Pierre Kraemer committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

	std::string gss = findFile(gs);
	bool geomShaderLoaded = loadGeometryShader(gss);

	if (!geomShaderLoaded)
	{
		std::cerr << "Error while loading geometry shader" << std::endl;
	}


	if(!create(inputGeometryPrimitive,outputGeometryPrimitive))
	{
		std::cout << "Unable to create the shaders !" << std::endl;
		return false;
	}

	std::cout << "Shaders loaded (" << vs << "," << ps << "," << gs <<")" << std::endl;
	return true;
}

608

609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680

bool GLSLShader::validateProgram()
{
	if(!m_program_object)
		return false;

	glValidateProgram(m_program_object);
	GLint Result = GL_FALSE;
	glGetProgramiv(m_program_object, GL_VALIDATE_STATUS, &Result);

	if(Result == GL_FALSE)
	{
		std::cout << "Validate program:" << std::endl;
		int InfoLogLength;
		glGetProgramiv(m_program_object, GL_INFO_LOG_LENGTH, &InfoLogLength);
		std::vector<char> Buffer(InfoLogLength);
		glGetProgramInfoLog(m_program_object, InfoLogLength, NULL, &Buffer[0]);
		std::cout <<  &(Buffer[0]) << std::endl;
		return false;
	}

	return true;
}

bool GLSLShader::checkProgram()
{
	GLint Result = GL_FALSE;
	glGetProgramiv(m_program_object, GL_LINK_STATUS, &Result);

	int InfoLogLength;
	glGetProgramiv(m_program_object, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> Buffer(std::max(InfoLogLength, int(1)));
	glGetProgramInfoLog(m_program_object, InfoLogLength, NULL, &Buffer[0]);
	std::cout << &Buffer[0] << std::endl;

	return Result == GL_TRUE;
}

bool GLSLShader::checkShader(int shaderType)
{
	GLint Result = GL_FALSE;
	int InfoLogLength;
	GLhandleARB id;

	switch(shaderType)
	{
	case VERTEX_SHADER:
		id = m_vertex_shader_object;
		break;
	case FRAGMENT_SHADER:
		id = m_fragment_shader_object;
		break;
	case GEOMETRY_SHADER:
		id = m_geom_shader_object;
		break;
	default:
		std::cerr << "Error unkown shader type"<< std::endl;
		return false;
		break;
	}

	glGetShaderiv(id, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(id, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> Buffer(InfoLogLength);
	glGetShaderInfoLog(id, InfoLogLength, NULL, &Buffer[0]);
	std::cout << &Buffer[0] << std::endl;

	return Result == GL_TRUE;
}



Sylvain Thery's avatar
Sylvain Thery committed
681
void GLSLShader::bindAttrib(unsigned int att, const char* name) const
682
{
683
	glBindAttribLocation(m_program_object,att,name);
684
685
686
687
}



Pierre Kraemer's avatar
Pierre Kraemer committed
688
689
690

} // namespace Utils
} // namespace CGoGN