CSCI441 OpenGL Library 5.21.1.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
ShaderUtils.hpp
Go to the documentation of this file.
1
14#ifndef CSCI441_SHADER_UTILS_HPP
15#define CSCI441_SHADER_UTILS_HPP
16
17#include "constants.h"
18
19#ifdef CSCI441_USE_GLEW
20 #include <GL/glew.h>
21#else
22 #include <glad/gl.h>
23#endif
24
25#include <cstdio>
26#include <cstring>
27#include <fstream>
28#include <string>
29
30//********************************************************************************************************************
31
32namespace CSCI441_INTERNAL::ShaderUtils {
33 static bool sDEBUG = true;
34
35 // Enables console output
36 [[maybe_unused]] void enableDebugMessages();
37
38 // Disables console output
39 [[maybe_unused]] void disableDebugMessages();
40
41 // Converts a GLenum data type variable to the string name of the associated value
42 // GLenum data type
43 // const char* name of data type
44 const char* GLSL_type_to_string( GLenum type );
45
46 // Converts a GLenum shader type variable to the string name of the associated value
47 // GLenum shader type
48 // const char* name of shader type
49 const char* GL_shader_type_to_string( GLenum type );
50
51 // Converts a GLenum primitive type variable to the string name of the associated value
52 // GLenum primitive type
53 // const char* name of primitive type
54 const char* GL_primitive_type_to_string( GLenum type );
55
56 // Reads the contents of a text file to a character array
57 // const char* filename of shader file to read in
58 // char*& character array to store the contents of the file. Will allocate memory and populate within the function
59 // bool true if file was successfully opened and read. false otherwise
60 bool readTextFromFile( const char* filename, GLchar* &output );
61
62 // Reads the contents of a text file and compiles the associated shader type
63 // const char* filename of shader file to read in
64 // GLenum type of shader file corresponds to
65 // GLuint shader handle if compilation successful. -1 otherwise
66 GLuint compileShader( const char *filename, GLenum shaderType );
67
68 // Prints the shader log for the associated Shader handle
69 void printShaderLog( GLuint shaderHandle );
70
71 // Prints the shader log for the associated Shader Program handle after linking
72 void printProgramLog( GLuint programHandle );
73
74 // Prints the shader log for the associated Shader Program handle
75 void printProgramInfoLog( GLuint programHandle );
76
77 // Prints the shader log for the associated Program Pipeline handle
78 void printProgramPipelineLog( GLuint pipelineHandle );
79
80 // Prints subroutine information from a Shader program
81 // GLuint Shader Program handle to inspect
82 // GLenum Shader Stage to inspect
83 // GLboolean if opening output line should be printed to console
84 GLboolean printSubroutineInfo(GLuint programHandle, GLenum shaderStage, GLboolean printHeader );
85
86 // Uses Shader Program introspection to print contents of Shader Program
87 // GLuint Shader Program handle to inspect
88 // GLboolean if Shader Program contains a vertex shader
89 // GLboolean if Shader Program contains a tessellation control shader
90 // GLboolean if Shader Program contains a tessellation evaluation shader
91 // GLboolean if Shader Program contains a geometry shader
92 // GLboolean if Shader Program contains a fragment shader
93 // GLboolean if Shader Program contains a compute shader
94 // GLboolean if closing output line should be printed to console (defaults to true)
95 void printShaderProgramInfo( GLuint programHandle,
96 GLboolean hasVertexShader,
97 GLboolean hasTessControlShader, GLboolean hasTessEvalShader,
98 GLboolean hasGeometryShader,
99 GLboolean hasFragmentShader,
100 GLboolean hasComputeShader,
101 GLboolean useLastNewLine );
102}
103
104//********************************************************************************************************************
105
106[[maybe_unused]]
107inline void CSCI441_INTERNAL::ShaderUtils::enableDebugMessages() {
108 sDEBUG = true;
109}
110
111[[maybe_unused]]
112inline void CSCI441_INTERNAL::ShaderUtils::disableDebugMessages() {
113 sDEBUG = false;
114}
115
116//********************************************************************************************************************
117
118inline bool CSCI441_INTERNAL::ShaderUtils::readTextFromFile(
119 const char *filename,
120 GLchar* &output
121){
122 std::string buf = std::string("");
123 std::string line;
124
125 std::ifstream in(filename);
126 if( !in.is_open() ) {
127 fprintf( stderr, "[ERROR]: Could not open file %s\n", filename );
128 return false;
129 }
130 while( std::getline(in, line) ) {
131 buf += line + "\n";
132 }
133
134 output = new GLchar[buf.length()+1];
135 strncpy(output, buf.c_str(), buf.length());
136 output[buf.length()] = '\0';
137
138 in.close();
139
140 return true;
141}
142
143inline const char* CSCI441_INTERNAL::ShaderUtils::GLSL_type_to_string(
144 const GLenum type
145) {
146 switch(type) {
147 case GL_FLOAT: return "float";
148 case GL_FLOAT_VEC2: return "vec2";
149 case GL_FLOAT_VEC3: return "vec3";
150 case GL_FLOAT_VEC4: return "vec4";
151 case GL_DOUBLE: return "double";
152 case GL_DOUBLE_VEC2: return "dvec2";
153 case GL_DOUBLE_VEC3: return "dvec3";
154 case GL_DOUBLE_VEC4: return "dvec4";
155 case GL_INT: return "int";
156 case GL_INT_VEC2: return "ivec2";
157 case GL_INT_VEC3: return "ivec3";
158 case GL_INT_VEC4: return "ivec4";
159 case GL_UNSIGNED_INT: return "unsigned int";
160 case GL_UNSIGNED_INT_VEC2: return "uvec2";
161 case GL_UNSIGNED_INT_VEC3: return "uvec3";
162 case GL_UNSIGNED_INT_VEC4: return "uvec4";
163 case GL_BOOL: return "bool";
164 case GL_BOOL_VEC2: return "bvec2";
165 case GL_BOOL_VEC3: return "bvec3";
166 case GL_BOOL_VEC4: return "bvec4";
167 case GL_FLOAT_MAT2: return "mat2";
168 case GL_FLOAT_MAT3: return "mat3";
169 case GL_FLOAT_MAT4: return "mat4";
170 case GL_FLOAT_MAT2x3: return "mat2x3";
171 case GL_FLOAT_MAT2x4: return "mat2x4";
172 case GL_FLOAT_MAT3x2: return "mat3x2";
173 case GL_FLOAT_MAT3x4: return "mat3x4";
174 case GL_FLOAT_MAT4x2: return "mat4x2";
175 case GL_FLOAT_MAT4x3: return "mat4x3";
176 case GL_DOUBLE_MAT2: return "dmat2";
177 case GL_DOUBLE_MAT3: return "dmat3";
178 case GL_DOUBLE_MAT4: return "dmat4";
179 case GL_DOUBLE_MAT2x3: return "dmat2x3";
180 case GL_DOUBLE_MAT2x4: return "dmat2x4";
181 case GL_DOUBLE_MAT3x2: return "dmat3x2";
182 case GL_DOUBLE_MAT3x4: return "dmat3x4";
183 case GL_DOUBLE_MAT4x2: return "dmat4x2";
184 case GL_DOUBLE_MAT4x3: return "dmat4x3";
185 case GL_SAMPLER_1D: return "sampler1D";
186 case GL_SAMPLER_2D: return "sampler2D";
187 case GL_SAMPLER_3D: return "sampler3D";
188 case GL_SAMPLER_CUBE: return "samplerCube";
189 case GL_SAMPLER_1D_SHADOW: return "sampler1DShadow";
190 case GL_SAMPLER_2D_SHADOW: return "sampler2DShadow";
191 case GL_SAMPLER_1D_ARRAY: return "sampler1DArray";
192 case GL_SAMPLER_2D_ARRAY: return "sampler2DArray";
193 case GL_SAMPLER_2D_MULTISAMPLE: return "sampler2DMS";
194 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: return "sampler2DMSArray";
195 case GL_SAMPLER_CUBE_SHADOW: return "samplerCubeShadow";
196 case GL_SAMPLER_BUFFER: return "samplerBuffer";
197 case GL_SAMPLER_2D_RECT: return "sampler2DRect";
198 case GL_SAMPLER_2D_RECT_SHADOW: return "sampler2DRectShadow";
199 case GL_INT_SAMPLER_1D: return "isampler1D";
200 case GL_INT_SAMPLER_2D: return "isampler2D";
201 case GL_INT_SAMPLER_3D: return "isampler3D";
202 case GL_INT_SAMPLER_CUBE: return "isamplerCube";
203 case GL_INT_SAMPLER_1D_ARRAY: return "isampler1DArray";
204 case GL_INT_SAMPLER_2D_ARRAY: return "isampler2DArray";
205 case GL_INT_SAMPLER_2D_MULTISAMPLE: return "isampler2DMS";
206 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return "isampler2DMSArray";
207 case GL_INT_SAMPLER_BUFFER: return "isamplerBuffer";
208 case GL_INT_SAMPLER_2D_RECT: return "isampler2DRect";
209 case GL_UNSIGNED_INT_SAMPLER_1D: return "usampler1D";
210 case GL_UNSIGNED_INT_SAMPLER_2D: return "usampler2D";
211 case GL_UNSIGNED_INT_SAMPLER_3D: return "usampler3D";
212 case GL_UNSIGNED_INT_SAMPLER_CUBE: return "usamplerCube";
213 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: return "usampler1DArray";
214 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: return "usampler2DArray";
215 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: return "usampler2DMS";
216 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return "usampler2DMSArray";
217 case GL_UNSIGNED_INT_SAMPLER_BUFFER: return "usamplerBuffer";
218 case GL_UNSIGNED_INT_SAMPLER_2D_RECT: return "usampler2DRect";
219 case GL_IMAGE_1D: return "image1D";
220 case GL_IMAGE_2D: return "image2D";
221 case GL_IMAGE_3D: return "image3D";
222 case GL_IMAGE_2D_RECT: return "image2DRect";
223 case GL_IMAGE_CUBE: return "imageCube";
224 case GL_IMAGE_BUFFER: return "imageBuffer";
225 case GL_IMAGE_1D_ARRAY: return "image1DArray";
226 case GL_IMAGE_2D_ARRAY: return "image2DArray";
227 case GL_IMAGE_2D_MULTISAMPLE: return "image2DMS";
228 case GL_IMAGE_2D_MULTISAMPLE_ARRAY: return "image2DMSArray";
229 case GL_INT_IMAGE_1D: return "iimage1D";
230 case GL_INT_IMAGE_2D: return "iimage2D";
231 case GL_INT_IMAGE_3D: return "iimage3D";
232 case GL_INT_IMAGE_2D_RECT: return "iimage2DRect";
233 case GL_INT_IMAGE_CUBE: return "iimageCube";
234 case GL_INT_IMAGE_BUFFER: return "iimageBuffer";
235 case GL_INT_IMAGE_1D_ARRAY: return "iimage1DArray";
236 case GL_INT_IMAGE_2D_ARRAY: return "iimage2DArray";
237 case GL_INT_IMAGE_2D_MULTISAMPLE: return "iimage2DMS";
238 case GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return "iimage2DMSArray";
239 case GL_UNSIGNED_INT_IMAGE_1D: return "uimage1D";
240 case GL_UNSIGNED_INT_IMAGE_2D: return "uimage2D";
241 case GL_UNSIGNED_INT_IMAGE_3D: return "uimage3D";
242 case GL_UNSIGNED_INT_IMAGE_2D_RECT: return "uimage2DRect";
243 case GL_UNSIGNED_INT_IMAGE_CUBE: return "uimageCube";
244 case GL_UNSIGNED_INT_IMAGE_BUFFER: return "uimageBuffer";
245 case GL_UNSIGNED_INT_IMAGE_1D_ARRAY: return "uimage1DArray";
246 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: return "uimage2DArray";
247 case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE: return "uimage2DMS";
248 case GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY: return "uimage2DMSArray";
249 case GL_UNSIGNED_INT_ATOMIC_COUNTER: return "atomic_uint";
250 default: break;
251 }
252 return "other data type";
253}
254
255inline const char* CSCI441_INTERNAL::ShaderUtils::GL_shader_type_to_string(
256 const GLenum type
257) {
258 switch(type) {
259 case GL_VERTEX_SHADER: return "Vertex Shader";
260 case GL_TESS_CONTROL_SHADER: return "Tess Ctrl Shader";
261 case GL_TESS_EVALUATION_SHADER: return "Tess Eval Shader";
262 case GL_GEOMETRY_SHADER: return "Geometry Shader";
263 case GL_FRAGMENT_SHADER: return "Fragment Shader";
264 case GL_COMPUTE_SHADER: return "Compute Shader";
265 default: break;
266 }
267 return "other shader type";
268}
269
270inline const char* CSCI441_INTERNAL::ShaderUtils::GL_primitive_type_to_string(
271 const GLenum type
272) {
273 switch(type) {
274 case GL_POINTS: return "Points";
275 case GL_LINES: return "Lines";
276 case GL_LINE_STRIP: return "Line Strip";
277 case GL_LINE_LOOP: return "Line Loop";
278 case GL_LINES_ADJACENCY: return "Line Adjacency";
279 case GL_TRIANGLES: return "Triangles";
280 case GL_TRIANGLE_STRIP: return "Triangle Strip";
281 case GL_TRIANGLES_ADJACENCY: return "Triangle Adjacency";
282 case GL_PATCHES: return "Patches";
283 default: break;
284 }
285 return "other primitive type";
286}
287
288inline void CSCI441_INTERNAL::ShaderUtils::printShaderLog(
289 const GLuint shaderHandle
290) {
291 // check if the handle is to a vertex/fragment shader
292 if( glIsShader( shaderHandle ) ) {
293 GLint maxLength = 0, status = 0, infoLogLength = 0;
294 glGetShaderiv( shaderHandle, GL_INFO_LOG_LENGTH, &maxLength );
295
296 // create a buffer of designated length
297 const auto infoLog = new GLchar[maxLength];
298
299 glGetShaderiv( shaderHandle, GL_COMPILE_STATUS, &status );
300 if( sDEBUG ) printf( "[INFO]: | Shader Handle %2d: Compile%-26s |\n", shaderHandle, (status == 1 ? "d Successfully" : "r Error") );
301
302 // get the info log for the vertex/tesselation/geometry/fragment/compute shader
303 glGetShaderInfoLog(shaderHandle, maxLength, &infoLogLength, infoLog );
304
305 if(infoLogLength > 0 ) {
306 // print info to terminal
307 if( sDEBUG ) printf( "[INFO]: | Shader Handle %d: %s\n", shaderHandle, infoLog );
308 }
309
310 delete[] infoLog;
311 } else {
312 if( sDEBUG ) fprintf( stderr, "[WARN]: | Handle %-3d is not for a Shader |\n", shaderHandle );
313 }
314}
315
316inline void CSCI441_INTERNAL::ShaderUtils::printProgramLog(
317 const GLuint programHandle
318) {
319 // check if the handle is to a vertex/fragment shader
320 if( glIsProgram( programHandle ) ) {
321 GLint status = 0;
322 glGetProgramiv( programHandle, GL_LINK_STATUS, &status );
323 if( sDEBUG ) printf("[INFO]: | Program Handle %2d: Linke%-28s |\n", programHandle, (status == 1 ? "d Successfully" : "r Error") );
324
325 printProgramInfoLog(programHandle);
326 } else {
327 if( sDEBUG ) fprintf( stderr, "[WARN]: | Handle %-3d is not for a Shader Program |\n", programHandle );
328 }
329}
330
331inline void CSCI441_INTERNAL::ShaderUtils::printProgramInfoLog(
332 const GLuint programHandle
333) {
334 // check if the handle is to a vertex/fragment shader
335 if( glIsProgram( programHandle ) ) {
336 GLint maxLength = 0, infoLogLength = 0;
337 glGetProgramiv( programHandle, GL_INFO_LOG_LENGTH, &maxLength );
338
339 // create a buffer of designated length
340 const auto infoLog = new GLchar[maxLength];
341
342 // get the info log for the vertex/tesselation/geometry/fragment/compute shader
343 glGetProgramInfoLog(programHandle, maxLength, &infoLogLength, infoLog );
344
345 if(infoLogLength > 0 ) {
346 // print info to terminal
347 if( sDEBUG ) printf( "[INFO]: | Program Handle %d: %s\n", programHandle, infoLog );
348 }
349
350 delete[] infoLog;
351 } else {
352 if( sDEBUG ) fprintf( stderr, "[WARN]: | Handle %-3d is not for a Shader Program |\n", programHandle );
353 }
354}
355
356inline void CSCI441_INTERNAL::ShaderUtils::printProgramPipelineLog(
357 const GLuint pipelineHandle
358) {
359 // check if the handle is to a shader program pipeline
360 if( glIsProgramPipeline( pipelineHandle ) ) {
361 GLint maxLength = 0, infoLogLength = 0;
362
363 glGetProgramPipelineiv( pipelineHandle, GL_INFO_LOG_LENGTH, &maxLength );
364
365 // create a buffer of designated length
366 const auto infoLog = new GLchar[maxLength];
367
368 // get the info log for the shader program pipeline
369 glGetProgramPipelineInfoLog(pipelineHandle, maxLength, &infoLogLength, infoLog );
370
371 if( infoLogLength > 0 ) {
372 // print info to terminal
373 if( sDEBUG ) printf( "[INFO]: | Pipeline Handle %d: %s\n", pipelineHandle, infoLog );
374 }
375
376 delete[] infoLog;
377 } else {
378 if( sDEBUG ) fprintf( stderr, "[WARN]: | Handle %-3d is not for a Shader Program Pipeline |\n", pipelineHandle );
379 }
380}
381
382inline GLboolean CSCI441_INTERNAL::ShaderUtils::printSubroutineInfo(
383 const GLuint programHandle,
384 const GLenum shaderStage,
385 const GLboolean printHeader
386) {
387 GLint numSubroutineUniforms = 0;
388 glGetProgramStageiv(programHandle, shaderStage, GL_ACTIVE_SUBROUTINE_UNIFORMS, &numSubroutineUniforms);
389 bool headerPrinted = false;
390 if( numSubroutineUniforms > 0 ) {
391 if( printHeader ) {
392 printf( "[INFO]: >--------------------------------------------------------<\n");
393 headerPrinted = true;
394 }
395 printf("[INFO]: | GL_ACTIVE_SUBROUTINE_UNIFORMS (%-15s): %5i |\n", CSCI441_INTERNAL::ShaderUtils::GL_shader_type_to_string(shaderStage), numSubroutineUniforms);
396 for(int i = 0; i < numSubroutineUniforms; i++ ) {
397 GLchar subroutineName[256];
398 GLint max_length = 256, actual_length = 0;
399 GLint numCompatibleSubroutines = 0;
400
401 glGetActiveSubroutineUniformName(programHandle, shaderStage, i, max_length, &actual_length, subroutineName );
402 glGetActiveSubroutineUniformiv(programHandle, shaderStage, i, GL_NUM_COMPATIBLE_SUBROUTINES, &numCompatibleSubroutines );
403
404 const auto compatibleSubroutines = new GLint[numCompatibleSubroutines];
405 glGetActiveSubroutineUniformiv(programHandle, shaderStage, i, GL_COMPATIBLE_SUBROUTINES, compatibleSubroutines );
406
407 GLint loc = glGetSubroutineUniformLocation(programHandle, shaderStage, subroutineName );
408
409 printf("[INFO]: | %i) name: %-15s #subRoutines: %-5i loc: %2i |\n", i, subroutineName, numCompatibleSubroutines, loc );
410
411 for(int j = 0; j < numCompatibleSubroutines; j++ ) {
412 GLint idx = compatibleSubroutines[j];
413
414 GLchar subroutineImplName[64];
415 GLint max_length2 = 64, actual_length2 = 0;
416 glGetActiveSubroutineName(programHandle, shaderStage, idx, max_length2, &actual_length2, subroutineImplName );
417
418 printf("[INFO]: | %i) subroutine: %-25s index: %2i |\n", j, subroutineImplName, idx );
419 }
420
421 delete[] compatibleSubroutines;
422 }
423 }
424 return !headerPrinted;
425}
426
427inline void CSCI441_INTERNAL::ShaderUtils::printShaderProgramInfo(
428 const GLuint programHandle,
429 const GLboolean hasVertexShader,
430 const GLboolean hasTessControlShader,
431 const GLboolean hasTessEvalShader,
432 const GLboolean hasGeometryShader,
433 const GLboolean hasFragmentShader,
434 const GLboolean hasComputeShader,
435 const GLboolean useLastNewLine = true
436) {
437 GLint major = 0, minor = 0;
438 glGetIntegerv(GL_MAJOR_VERSION, &major);
439 glGetIntegerv(GL_MINOR_VERSION, &minor);
440
441 GLuint shaders[6] = {0};
442 GLint max_count = 6;
443 GLint actual_count = 0;
444
445 GLint maxAttributeNameLength = 0;
446 GLint maxUniformNameLength = 0;
447
448 // get max var name from program
449 // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetActiveAttrib.xhtml
450 glGetProgramiv(programHandle, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeNameLength);
451 glGetProgramiv(programHandle, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformNameLength);
452
453 glGetAttachedShaders(programHandle, max_count, &actual_count, shaders );
454 if(actual_count > 0) {
455 if( sDEBUG ) printf( "[INFO]: >--------------------------------------------------------<\n");
456 if( sDEBUG ) printf("[INFO]: | GL_ATTACHED_SHADERS: %33i |\n", actual_count);
457 for(int i = 0; i < actual_count; i++ ) {
458 GLint shaderType;
459 glGetShaderiv( shaders[i], GL_SHADER_TYPE, &shaderType );
460 if( sDEBUG ) printf("[INFO]: | %i) %-38s Handle: %2i |\n", i, GL_shader_type_to_string(shaderType), shaders[i]);
461 }
462 }
463
464 if(sDEBUG) {
465 if(hasGeometryShader) {
466 if( major > 3 || (major >= 3 && minor >= 2) ) {
467 GLint verticesOut = 0, inputType = 0, outputType = 0;
468 glGetProgramiv(programHandle, GL_GEOMETRY_VERTICES_OUT, &verticesOut);
469 glGetProgramiv(programHandle, GL_GEOMETRY_INPUT_TYPE, &inputType);
470 glGetProgramiv(programHandle, GL_GEOMETRY_OUTPUT_TYPE, &outputType);
471
472 printf( "[INFO]: >--------------------------------------------------------<\n");
473 printf( "[INFO]: | GEOMETRY SHADER PRIMITIVE I/O |\n");
474 printf( "[INFO]: | Input Type: %40s |\n", GL_primitive_type_to_string(inputType) );
475 printf( "[INFO]: | Output Type: %39s |\n", GL_primitive_type_to_string(outputType) );
476 printf( "[INFO]: | Max Vertices Out: %34d |\n", verticesOut );
477 }
478 }
479 }
480
481 if(hasVertexShader) {
482 GLint numActiveAttributes = 0;
483 glGetProgramiv(programHandle, GL_ACTIVE_ATTRIBUTES, &numActiveAttributes );
484 if( numActiveAttributes > 0 ) {
485 if( sDEBUG ) printf( "[INFO]: >--------------------------------------------------------<\n");
486 if( sDEBUG ) printf( "[INFO]: | GL_ACTIVE_ATTRIBUTES: %32i |\n", numActiveAttributes );
487 for( int i = 0; i < numActiveAttributes; i++ ) {
488 const auto name = new GLchar[maxAttributeNameLength];
489 GLint actual_length = 0, size = 0;
490 GLenum type = GL_NONE;
491 glGetActiveAttrib(programHandle, i, maxAttributeNameLength, &actual_length, &size, &type, name );
492 if( size > 1 ) {
493 for( int j = 0; j < size; j++ ) {
494 // length of string + max array value size (technically it depends on the size of GL type, but I'm not aware a way to get the size)
495 // + array accessors + null
496 int max_array_size = actual_length + 4 + 2 + 1;
497 const auto array_name = new GLchar[max_array_size];
498
499 snprintf( array_name, max_array_size, "%s[%i]", name, j );
500 GLint location = glGetAttribLocation(programHandle, array_name);
501 if( sDEBUG ) printf( "[INFO]: | %i) type: %-15s name: %-13s loc: %2i |\n", i, GLSL_type_to_string( type ), array_name, location );
502 delete[] array_name;
503 }
504 } else {
505 GLint location = glGetAttribLocation(programHandle, name );
506 if( sDEBUG ) printf( "[INFO]: | %i) type: %-15s name: %-13s loc: %2i |\n",i, GLSL_type_to_string( type ), name, location );
507 }
508
509 delete[] name;
510 }
511 }
512 }
513
514 GLint numActiveUniforms = 0;
515 glGetProgramiv(programHandle, GL_ACTIVE_UNIFORMS, &numActiveUniforms);
516 if( numActiveUniforms > 0 ) {
517 constexpr int NUM_PROPS = 6;
518 GLenum props[NUM_PROPS] = {GL_REFERENCED_BY_VERTEX_SHADER,
519 GL_REFERENCED_BY_TESS_CONTROL_SHADER,
520 GL_REFERENCED_BY_TESS_EVALUATION_SHADER,
521 GL_REFERENCED_BY_GEOMETRY_SHADER,
522 GL_REFERENCED_BY_FRAGMENT_SHADER,
523 GL_NONE};
524
525 if((major == 4 && minor >= 3) || major > 4) {
526 props[5] = GL_REFERENCED_BY_COMPUTE_SHADER;
527 }
528 GLint results[NUM_PROPS] = {0};
529
530 if( sDEBUG ) printf( "[INFO]: >--------------------------------------------------------<\n" );
531 if( sDEBUG ) printf("[INFO]: | GL_ACTIVE_UNIFORMS: %34i |\n", numActiveUniforms);
532 for(int uIdx = 0; uIdx < numActiveUniforms; uIdx++) {
533 const auto name = new GLchar[maxUniformNameLength];
534 GLint actual_length = 0, size = 0, location = -1;
535 GLenum type = GL_NONE;
536 glGetActiveUniform(programHandle, uIdx, maxUniformNameLength, &actual_length, &size, &type, name );
537 if(size > 1) {
538 for(int j = 0; j < size; j++) {
539 int max_array_size = actual_length + 4 + 2 + 1;
540 const auto array_name = new GLchar[max_array_size];
541 snprintf(array_name, max_array_size, "%s[%i]", name, j);
542 location = glGetUniformLocation(programHandle, array_name);
543 if(location != -1) {
544 if (sDEBUG) printf("[INFO]: | %2i) type: %-15s name: %-13s loc: %2i |\n", uIdx, GLSL_type_to_string(type), array_name, location);
545 }
546 delete[] array_name;
547 }
548 } else {
549 location = glGetUniformLocation(programHandle, name);
550 if(location != -1) {
551 if (sDEBUG) printf("[INFO]: | %2i) type: %-15s name: %-13s loc: %2i |\n", uIdx, GLSL_type_to_string(type), name, location);
552 }
553 }
554
555 if(((major == 4 && minor >= 3) || major > 4) && location != -1) {
556 glGetProgramResourceiv(programHandle, GL_UNIFORM, uIdx, NUM_PROPS, props, NUM_PROPS, nullptr, results);
557 if( sDEBUG ) printf("[INFO]: | Used in: %-4s %-4s %-4s %-3s %-4s %-4s Shader(s) |\n", (results[0] ? "Vert" : ""), (results[1] ? "Ctrl" : ""), (results[2] ? "Eval" : ""), (results[3] ? "Geo" : ""), (results[4] ? "Frag" : ""), (results[5] ? "Comp" : ""));
558 }
559
560 delete[] name;
561 }
562 }
563
564 GLint numActiveUniformBlocks = 0;
565 glGetProgramiv(programHandle, GL_ACTIVE_UNIFORM_BLOCKS, &numActiveUniformBlocks);
566 if( numActiveUniformBlocks > 0 ) {
567 int vsCount, tcsCount, tesCount, gsCount, fsCount, csCount;
568 vsCount = tcsCount = tesCount = gsCount = fsCount = csCount = 0;
569
570 if( sDEBUG ) printf( "[INFO]: >--------------------------------------------------------<\n");
571 if( sDEBUG ) printf("[INFO]: | GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: %20d |\n", numActiveUniformBlocks);
572 for(int i = 0; i < numActiveUniformBlocks; i++ ) {
573 GLint numActiveUniformsInBlock = 0, bindingPoint = 0;
574 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &numActiveUniformsInBlock );
575 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_BINDING, &bindingPoint);
576
577 GLint actualLen;
578 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_NAME_LENGTH, &actualLen);
579 const auto name = new GLchar[actualLen];
580 glGetActiveUniformBlockName(programHandle, i, actualLen, nullptr, name);
581
582 const auto indices = new GLint[numActiveUniformsInBlock];
583 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, indices);
584
585 const auto offsets = new GLint[numActiveUniformsInBlock];
586 glGetActiveUniformsiv(programHandle, numActiveUniformsInBlock, (GLuint*)indices, GL_UNIFORM_OFFSET, offsets);
587
588 if( sDEBUG ) printf("[INFO]: | %d) %-19s binding: %3d |\n", i, name, bindingPoint);
589
590 GLint vs, tcs, tes, gs, fs, cs;
591 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER, &vs); if( vs ) vsCount++;
592 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER, &tcs); if( tcs) tcsCount++;
593 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER, &tes); if( tes) tesCount++;
594 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER, &gs); if( gs ) gsCount++;
595 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER, &fs); if( fs ) fsCount++;
596 if((major == 4 && minor >= 3) || major > 4) {
597 glGetActiveUniformBlockiv(programHandle, i, GL_UNIFORM_BLOCK_REFERENCED_BY_COMPUTE_SHADER, &cs); if( cs ) csCount++;
598 }
599 if( sDEBUG ) printf("[INFO]: | Used in: %-4s %-4s %-4s %-3s %-4s %-4s Shader(s) |\n", (vs ? "Vert" : ""), (tcs ? "Ctrl" : ""), (tes ? "Eval" : ""), (gs ? "Geo" : ""), (fs ? "Frag" : ""), (cs ? "Comp" : ""));
600
601 const auto name2 = new char[maxUniformNameLength];
602 for(int j = 0; j < numActiveUniformsInBlock; j++) {
603 GLenum type;
604 int uniSize;
605 glGetActiveUniform(programHandle, indices[j], maxUniformNameLength, &actualLen, &uniSize, &type, name2);
606
607 constexpr GLsizei NUM_ATOMIC_PROPERTIES = 1;
608 GLint atomicIndex[NUM_ATOMIC_PROPERTIES] = {-1};
609 if((major == 4 && minor >= 3) || major > 4) {
610 GLenum atomicProps[NUM_ATOMIC_PROPERTIES] = {GL_ATOMIC_COUNTER_BUFFER_INDEX};
611 glGetProgramResourceiv(programHandle, GL_UNIFORM, indices[j], NUM_ATOMIC_PROPERTIES, atomicProps, NUM_ATOMIC_PROPERTIES, nullptr, atomicIndex);
612 }
613
614 if( atomicIndex[0] == -1 && sDEBUG ) {
615 printf("[INFO]: | %2d) type: %-15s name: %-21s |\n", j, GLSL_type_to_string(type), name2);
616 printf("[INFO]: | uniform index: %3d offset: %4d |\n", indices[j], offsets[j]);
617 }
618 }
619
620 delete[] name;
621 delete[] indices;
622 delete[] offsets;
623 delete[] name2;
624 }
625
626 if( vsCount + tcsCount + tesCount + gsCount + fsCount + csCount > 0 ) {
627 GLint maxUniBlocks = 0;
628 glGetIntegerv( GL_MAX_COMBINED_UNIFORM_BLOCKS, &maxUniBlocks );
629 if( sDEBUG ) printf( "[INFO]: | Shader Uniform Block Counts %2d/%2d |\n", numActiveUniformBlocks, maxUniBlocks);
630 if( hasVertexShader ) {
631 GLint maxVertexUniformBlocks = 0;
632 glGetIntegerv( GL_MAX_VERTEX_UNIFORM_BLOCKS, &maxVertexUniformBlocks );
633
634 if( sDEBUG ) printf( "[INFO]: | Vertex Shader Uniform Blocks: %18d/%2d |\n", vsCount, maxVertexUniformBlocks );
635 }
636 if( hasTessControlShader ) {
637 GLint maxTessControlUniformBlocks = 0;
638 glGetIntegerv( GL_MAX_TESS_CONTROL_UNIFORM_BLOCKS, &maxTessControlUniformBlocks );
639
640 if( sDEBUG ) printf( "[INFO]: | Tess Ctrl Shader Uniform Blocks: %15d/%2d |\n", tcsCount, maxTessControlUniformBlocks );
641 }
642 if( hasTessEvalShader ) {
643 GLint maxTessEvalUniformBlocks = 0;
644 glGetIntegerv( GL_MAX_TESS_EVALUATION_UNIFORM_BLOCKS, &maxTessEvalUniformBlocks );
645
646 if( sDEBUG ) printf( "[INFO]: | Tess Eval Shader Uniform Blocks: %15d/%2d |\n", tesCount, maxTessEvalUniformBlocks );
647 }
648 if( hasGeometryShader ) {
649 GLint maxGeometryUniformBlocks = 0;
650 glGetIntegerv( GL_MAX_GEOMETRY_UNIFORM_BLOCKS, &maxGeometryUniformBlocks );
651
652 if( sDEBUG ) printf( "[INFO]: | Geometry Shader Uniform Blocks: %16d/%2d |\n", gsCount, maxGeometryUniformBlocks );
653 }
654 if( hasFragmentShader ) {
655 GLint maxFragmentUniformBlocks = 0;
656 glGetIntegerv( GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &maxFragmentUniformBlocks );
657
658 if( sDEBUG ) printf( "[INFO]: | Fragment Shader Uniform Blocks: %16d/%2d |\n", fsCount, maxFragmentUniformBlocks );
659 }
660 if( hasComputeShader ) {
661 GLint maxComputeUniformBlocks = 0;
662 glGetIntegerv( GL_MAX_COMPUTE_UNIFORM_BLOCKS, &maxComputeUniformBlocks );
663
664 if( sDEBUG ) printf( "[INFO]: | Compute Shader Uniform Blocks: %17d/%2d |\n", csCount, maxComputeUniformBlocks );
665 }
666 }
667 }
668
669 if (sDEBUG) {
670 if ((major == 4 && minor >=3) || major > 4) {
671 GLint numFragOutputs; //Where GL will write the number of outputs
672 glGetProgramInterfaceiv(programHandle, GL_PROGRAM_OUTPUT,GL_ACTIVE_RESOURCES, &numFragOutputs);
673
674 printf( "[INFO]: >--------------------------------------------------------<\n");
675 printf( "[INFO]: | GL_PROGRAM_OUTPUT: %35d |\n", numFragOutputs);
676
677 if(numFragOutputs > 0) {
678 GLint maxLen = 0;
679 glGetProgramInterfaceiv(programHandle, GL_PROGRAM_OUTPUT, GL_MAX_NAME_LENGTH, &maxLen);
680
681 const auto outputName = new GLchar[maxLen];
682
683 //Now you can query for the names and indices of the outputs
684 for (GLint i = 0; i < numFragOutputs; i++) {
685 GLsizei actualLength = 0;
686 glGetProgramResourceName(programHandle, GL_PROGRAM_OUTPUT, i, maxLen, &actualLength, outputName);
687 GLint location = glGetFragDataLocation(programHandle, outputName);
688 GLint index = glGetFragDataIndex(programHandle, outputName);
689 printf( "[INFO]: | %3d) name: %-18s location: %3d index: %3d |\n", i, outputName, location, index );
690 }
691
692 delete[] outputName;
693 }
694 }
695 }
696
697 if( sDEBUG ) {
698 if((major == 4 && minor >= 3) || major > 4) {
699 GLint numSSBO = 0;
700 glGetProgramInterfaceiv(programHandle, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numSSBO);
701 if(numSSBO > 0) {
702 GLint maxLen = 0;
703 glGetProgramInterfaceiv(programHandle, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &maxLen);
704 const auto ssboName = new GLchar[maxLen];
705 GLsizei ssboNameLen = 0;
706
707 constexpr int NUM_PROPS = 7;
708 GLenum props[NUM_PROPS] = {GL_BUFFER_BINDING,
709 GL_REFERENCED_BY_VERTEX_SHADER,
710 GL_REFERENCED_BY_TESS_CONTROL_SHADER, GL_REFERENCED_BY_TESS_EVALUATION_SHADER,
711 GL_REFERENCED_BY_GEOMETRY_SHADER,
712 GL_REFERENCED_BY_FRAGMENT_SHADER,
713 GL_REFERENCED_BY_COMPUTE_SHADER};
714 GLsizei numWritten = 0;
715 GLint results[NUM_PROPS] = {0};
716
717 int vSSB, teSSB, tcSSB, gSSB, fSSB, cSSB;
718 vSSB = teSSB = tcSSB = gSSB = fSSB = cSSB = 0;
719
720 printf( "[INFO]: >--------------------------------------------------------<\n");
721 printf( "[INFO]: | GL_SHADER_STORAGE_BLOCK: %29d |\n", numSSBO );
722 for(int i = 0; i < numSSBO; i++) {
723 glGetProgramResourceName(programHandle, GL_SHADER_STORAGE_BLOCK, i, maxLen, &ssboNameLen, ssboName);
724 GLuint ssboIndex = glGetProgramResourceIndex(programHandle, GL_SHADER_STORAGE_BLOCK, ssboName);
725 glGetProgramResourceiv(programHandle, GL_SHADER_STORAGE_BLOCK, i, NUM_PROPS, props, NUM_PROPS, &numWritten, results);
726
727 printf( "[INFO]: | %3d) name: %-19s index: %3d binding: %3d |\n", i, ssboName, ssboIndex, results[0] );
728 printf( "[INFO]: | Used in: %-4s %-4s %-4s %-3s %-4s %-4s Shader(s) |\n", (results[1] ? "Vert" : ""), (results[2] ? "Ctrl" : ""), (results[3] ? "Eval" : ""), (results[4] ? "Geo" : ""), (results[5] ? "Frag" : ""), (results[6] ? "Comp" : ""));
729
730 if(results[1]) vSSB++;
731 if(results[2]) teSSB++;
732 if(results[3]) tcSSB++;
733 if(results[4]) gSSB++;
734 if(results[5]) fSSB++;
735 if(results[6]) cSSB++;
736 }
737
738 GLint maxSSBCounters = 0;
739 glGetIntegerv( GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &maxSSBCounters );
740 printf( "[INFO]: | Shader Storage Block Counts: %2d/%2d |\n", numSSBO, maxSSBCounters );
741 if(hasVertexShader) {
742 GLint maxVertSSB = 0;
743 glGetIntegerv( GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &maxVertSSB );
744 printf( "[INFO]: | Vertex Shader Storage Blocks: %2d/%2d |\n", vSSB, maxVertSSB );
745 }
746 if(hasTessControlShader) {
747 GLint maxTESSB = 0;
748 glGetIntegerv( GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &maxTESSB );
749 printf( "[INFO]: | Tess Ctrl Shader Storage Blocks: %2d/%2d |\n", teSSB, maxTESSB );
750 }
751 if(hasTessEvalShader) {
752 GLint maxTCSSB = 0;
753 glGetIntegerv( GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &maxTCSSB );
754 printf( "[INFO]: | Tess Eval Shader Storage Blocks: %2d/%2d |\n", tcSSB, maxTCSSB );
755 }
756 if(hasGeometryShader) {
757 GLint maxGeoSSB = 0;
758 glGetIntegerv( GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &maxGeoSSB );
759 printf( "[INFO]: | Geometry Shader Storage Blocks: %2d/%2d |\n", gSSB, maxGeoSSB );
760 }
761 if(hasFragmentShader) {
762 GLint maxFragSSB = 0;
763 glGetIntegerv( GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, &maxFragSSB );
764 printf( "[INFO]: | Fragment Shader Storage Blocks: %2d/%2d |\n", fSSB, maxFragSSB );
765 }
766 if(hasComputeShader) {
767 GLint maxComputeSSB = 0;
768 glGetIntegerv( GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &maxComputeSSB );
769 printf( "[INFO]: | Compute Shader Storage Blocks: %2d/%2d |\n", cSSB, maxComputeSSB );
770 }
771
772 delete[] ssboName;
773 }
774 }
775
776 if((major == 4 && minor >= 2) || major > 4) {
777 GLint numAtomicCounters = 0;
778 glGetProgramInterfaceiv(programHandle, GL_ATOMIC_COUNTER_BUFFER, GL_ACTIVE_RESOURCES, &numAtomicCounters);
779
780 if(numAtomicCounters > 0) {
781 constexpr int NUM_PROPS = 6;
782 GLenum props[NUM_PROPS] = {GL_REFERENCED_BY_VERTEX_SHADER,
783 GL_REFERENCED_BY_TESS_CONTROL_SHADER,
784 GL_REFERENCED_BY_TESS_EVALUATION_SHADER,
785 GL_REFERENCED_BY_GEOMETRY_SHADER,
786 GL_REFERENCED_BY_FRAGMENT_SHADER,
787 GL_NONE};
788
789 if((major == 4 && minor >= 3) || major > 4) {
790 props[5] = GL_REFERENCED_BY_COMPUTE_SHADER;
791 }
792
793 GLsizei numWritten = 0;
794 GLint results[NUM_PROPS] = {0};
795
796 printf( "[INFO]: >--------------------------------------------------------<\n");
797 printf("[INFO]: | GL_ATOMIC_COUNTER_BUFFER: %28d |\n", numAtomicCounters );
798
799 int vAC, teAC, tcAC, gAC, fAC, cAC;
800 vAC = teAC = tcAC = gAC = fAC = cAC = 0;
801
802 for(GLint acIdx = 0; acIdx < numAtomicCounters; acIdx++) {
803 GLint binding = -1, bufferSize = 0, nac = 0;
804
805 glGetActiveAtomicCounterBufferiv(programHandle, acIdx, GL_ATOMIC_COUNTER_BUFFER_BINDING, &binding);
806 glGetActiveAtomicCounterBufferiv(programHandle, acIdx, GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE, &bufferSize);
807 glGetActiveAtomicCounterBufferiv(programHandle, acIdx, GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS, &nac);
808
809 const auto uniformIndices = new GLint[nac];
810 const auto atomicOffsets = new GLint[nac];
811 const auto atomicName = new GLchar[maxUniformNameLength];
812
813 glGetActiveAtomicCounterBufferiv(programHandle, acIdx, GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES, uniformIndices);
814 glGetActiveUniformsiv(programHandle, nac, (GLuint*)uniformIndices, GL_UNIFORM_OFFSET, atomicOffsets);
815 glGetProgramResourceiv(programHandle, GL_ATOMIC_COUNTER_BUFFER, acIdx, NUM_PROPS, props, NUM_PROPS, &numWritten, results);
816
817 // increment counts of which shaders have an atomic counter
818 if(results[0]) vAC++;
819 if(results[1]) teAC++;
820 if(results[2]) tcAC++;
821 if(results[3]) gAC++;
822 if(results[4]) fAC++;
823 if(results[5]) cAC++;
824
825 printf( "[INFO]: | %d) binding: %11d buffer size: %4d |\n", acIdx, binding, bufferSize );
826 printf( "[INFO]: | Used in: %-4s %-4s %-4s %-3s %-4s %-4s Shader(s) |\n", (results[0] ? "Vert" : ""), (results[1] ? "Ctrl" : ""), (results[2] ? "Eval" : ""), (results[3] ? "Geo" : ""), (results[4] ? "Frag" : ""), (results[5] ? "Comp" : ""));
827
828 GLint acCtr = 0, actualLen = 0, uniSize = 0;
829 GLenum type = GL_NONE;
830 for(GLint uniIdx = 0; uniIdx < nac; uniIdx++) {
831 glGetActiveUniform(programHandle, uniformIndices[uniIdx], maxUniformNameLength, &actualLen, &uniSize, &type, atomicName);
832
833 constexpr GLsizei NUM_ATOMIC_PROPERTIES = 1;
834 GLenum atomicProps[NUM_ATOMIC_PROPERTIES] = {GL_ATOMIC_COUNTER_BUFFER_INDEX};
835 GLint atomicIndex [NUM_ATOMIC_PROPERTIES] = {-1};
836 glGetProgramResourceiv(programHandle, GL_UNIFORM, uniformIndices[uniIdx], NUM_ATOMIC_PROPERTIES, atomicProps, NUM_ATOMIC_PROPERTIES, nullptr, atomicIndex);
837
838 if(atomicIndex[0] == acIdx) {
839 printf( "[INFO]: | %3d) type: %-15s name: %-21s |\n", acCtr++, GLSL_type_to_string(type), atomicName );
840 printf( "[INFO]: | uniform index: %3d offset: %7d |\n", uniformIndices[uniIdx], atomicOffsets[uniIdx] );
841 }
842 }
843
844 delete[] uniformIndices;
845 delete[] atomicOffsets;
846 delete[] atomicName;
847 }
848
849 GLint maxAtomicCounters = 0;
850 glGetIntegerv( GL_MAX_COMBINED_ATOMIC_COUNTERS, &maxAtomicCounters );
851 printf("[INFO]: | Atomic Counter Counts: %4d/%4d |\n", numAtomicCounters, maxAtomicCounters );
852 if(hasVertexShader) {
853 GLint maxVertAtomicCounters = 0;
854 glGetIntegerv( GL_MAX_VERTEX_ATOMIC_COUNTERS, &maxVertAtomicCounters );
855 printf( "[INFO]: | Vertex Atomic Counters: %4d/%4d |\n", vAC, maxVertAtomicCounters );
856 }
857 if(hasTessControlShader) {
858 GLint maxTCAtomicCounters = 0;
859 glGetIntegerv( GL_MAX_TESS_CONTROL_ATOMIC_COUNTERS, &maxTCAtomicCounters );
860 printf( "[INFO]: | Tess Ctrl Atomic Counters: %4d/%4d |\n", teAC, maxTCAtomicCounters );
861 }
862 if(hasTessEvalShader) {
863 GLint maxTEAtomicCounters = 0;
864 glGetIntegerv( GL_MAX_TESS_EVALUATION_ATOMIC_COUNTERS, &maxTEAtomicCounters );
865 printf( "[INFO]: | Tess Eval Atomic Counters: %4d/%4d |\n", tcAC, maxTEAtomicCounters );
866 }
867 if(hasGeometryShader) {
868 GLint maxGeoAtomicCounters = 0;
869 glGetIntegerv( GL_MAX_GEOMETRY_ATOMIC_COUNTERS, &maxGeoAtomicCounters );
870 printf( "[INFO]: | Geometry Atomic Counters: %4d/%4d |\n", gAC, maxGeoAtomicCounters );
871 }
872 if(hasFragmentShader) {
873 GLint maxFragAtomicCounters = 0;
874 glGetIntegerv( GL_MAX_FRAGMENT_ATOMIC_COUNTERS, &maxFragAtomicCounters );
875 printf( "[INFO]: | Fragment Atomic Counters: %4d/%4d |\n", fAC, maxFragAtomicCounters );
876 }
877 if(hasComputeShader) {
878 GLint maxComputeAtomicCounters = 0;
879 glGetIntegerv( GL_MAX_COMPUTE_ATOMIC_COUNTERS, &maxComputeAtomicCounters );
880 printf( "[INFO]: | Compute Atomic Counters: %4d/%4d |\n", cAC, maxComputeAtomicCounters );
881 }
882 }
883 }
884
885 if( major >= 4 ) {
886 GLboolean printHeader = GL_TRUE;
887 if( hasVertexShader ) printHeader = printSubroutineInfo(programHandle, GL_VERTEX_SHADER, printHeader );
888 if( hasTessControlShader) printHeader = printSubroutineInfo(programHandle, GL_TESS_CONTROL_SHADER, printHeader );
889 if( hasTessEvalShader) printHeader = printSubroutineInfo(programHandle, GL_TESS_EVALUATION_SHADER, printHeader );
890 if( hasGeometryShader ) printHeader = printSubroutineInfo(programHandle, GL_GEOMETRY_SHADER, printHeader );
891 if( hasFragmentShader ) printHeader = printSubroutineInfo(programHandle, GL_FRAGMENT_SHADER, printHeader );
892 if( hasComputeShader ) printSubroutineInfo(programHandle, GL_COMPUTE_SHADER, printHeader );
893 }
894 }
895
896 if(useLastNewLine && sDEBUG) printf( "[INFO]: \\--------------------------------------------------------/\n\n");
897}
898
899inline GLuint CSCI441_INTERNAL::ShaderUtils::compileShader(
900 const char *filename,
901 const GLenum shaderType
902) {
903 // will hold contents of shader source code, loaded from file
904 GLchar *shaderString;
905
906 // read in each text file and store the contents in a string
907 if( readTextFromFile( filename, shaderString ) ) {
908 // generate a shader handle for the corresponding shader type
909 GLuint shaderHandle = glCreateShader( shaderType );
910
911 // send the contents of each program to the GPU
912 glShaderSource( shaderHandle, 1, (const char**)&shaderString, nullptr );
913
914 // we are good programmers so free up the memory used by each buffer
915 delete [] shaderString;
916
917 // compile each shader on the GPU
918 glCompileShader( shaderHandle );
919
920 // check the shader log
921 printShaderLog( shaderHandle );
922
923 // return the handle of our shader
924 return shaderHandle;
925 } else {
926 return 0;
927 }
928}
929
930#endif // CSCI441_SHADER_UTILS_HPP