5 changed files with 113 additions and 79 deletions
@ -0,0 +1,109 @@ |
|||||||
|
|
||||||
|
// NOTE: get useful debug messages from opengl
|
||||||
|
// https://www.khronos.org/opengl/wiki/Debug_Output
|
||||||
|
|
||||||
|
#include <GL/glew.h> |
||||||
|
|
||||||
|
#include "shader.h" |
||||||
|
|
||||||
|
|
||||||
|
void dumpShader(GLuint prog_id); |
||||||
|
void openglDebugCallback(GLenum source, |
||||||
|
GLenum type, |
||||||
|
GLuint id, |
||||||
|
GLenum severity, |
||||||
|
GLsizei length, |
||||||
|
const GLchar* message, |
||||||
|
const void* userParam); |
||||||
|
|
||||||
|
|
||||||
|
#ifdef GL_DEBUG_IMPLEMENTATION |
||||||
|
|
||||||
|
const char* |
||||||
|
glEnumToString(GLenum e) |
||||||
|
{ |
||||||
|
switch (e) { |
||||||
|
case GL_FLOAT_MAT4: return "GL_FLOAT_MAT4"; |
||||||
|
case GL_FLOAT_VEC3: return "GL_FLOAT_VEC3"; |
||||||
|
case GL_FLOAT_VEC4: return "GL_FLOAT_VEC4"; |
||||||
|
|
||||||
|
case GL_DEBUG_TYPE_ERROR: return "GL_DEBUG_TYPE_ERROR"; |
||||||
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: return "GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR"; |
||||||
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: return "GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR"; |
||||||
|
case GL_DEBUG_TYPE_PORTABILITY: return "GL_DEBUG_TYPE_PORTABILITY"; |
||||||
|
case GL_DEBUG_TYPE_PERFORMANCE: return "GL_DEBUG_TYPE_PERFORMANCE"; |
||||||
|
case GL_DEBUG_TYPE_MARKER: return "GL_DEBUG_TYPE_MARKER"; |
||||||
|
case GL_DEBUG_TYPE_PUSH_GROUP: return "GL_DEBUG_TYPE_PUSH_GROUP"; |
||||||
|
case GL_DEBUG_TYPE_POP_GROUP: return "GL_DEBUG_TYPE_POP_GROUP"; |
||||||
|
case GL_DEBUG_TYPE_OTHER: return "GL_DEBUG_TYPE_OTHER"; |
||||||
|
|
||||||
|
case GL_DEBUG_SEVERITY_HIGH: return "GL_DEBUG_SEVERITY_HIGH"; |
||||||
|
case GL_DEBUG_SEVERITY_MEDIUM: return "GL_DEBUG_SEVERITY_MEDIUM"; |
||||||
|
case GL_DEBUG_SEVERITY_LOW: return "GL_DEBUG_SEVERITY_LOW"; |
||||||
|
case GL_DEBUG_SEVERITY_NOTIFICATION: return "GL_DEBUG_SEVERITY_NOTIFICATION"; |
||||||
|
|
||||||
|
default: return "???"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
openglDebugCallback(GLenum source, |
||||||
|
GLenum type, |
||||||
|
GLuint id, |
||||||
|
GLenum severity, |
||||||
|
GLsizei length, |
||||||
|
const GLchar* message, |
||||||
|
const void* userParam) |
||||||
|
{ |
||||||
|
std::cout << ((type == GL_DEBUG_TYPE_ERROR) ? "Error" : "Debug") |
||||||
|
<< (type == GL_DEBUG_TYPE_ERROR ? "** GL Error **" : "") |
||||||
|
<< ", type: " << glEnumToString(type) |
||||||
|
<< ", severity: " << glEnumToString(severity) |
||||||
|
<< ", message: " << message << "\n"; |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
dumpShader(GLuint prog_id) |
||||||
|
{ |
||||||
|
printf("------------------------\n"); |
||||||
|
printf("%s(), dumping shader info, program id: %d\n", |
||||||
|
__FUNCTION__, prog_id); |
||||||
|
|
||||||
|
GLint active_uniforms; |
||||||
|
GLint active_uniform_blocks; |
||||||
|
GLint active_attribs; |
||||||
|
|
||||||
|
// NOTE: unused uniforms/attributes get optimized away
|
||||||
|
// https://www.khronos.org/opengl/wiki/Program_Introspection#Attributes
|
||||||
|
glGetProgramiv(prog_id, GL_ACTIVE_UNIFORMS, &active_uniforms); |
||||||
|
glGetProgramiv(prog_id, GL_ACTIVE_UNIFORM_BLOCKS, &active_uniform_blocks); |
||||||
|
glGetProgramiv(prog_id, GL_ACTIVE_ATTRIBUTES, &active_attribs); |
||||||
|
|
||||||
|
printf("active uniforms: %d\n", active_uniforms); |
||||||
|
printf("active uniform blocks: %d\n", active_uniform_blocks); |
||||||
|
printf("active attributes: %d\n", active_attribs); |
||||||
|
|
||||||
|
GLchar uni_name[256]; |
||||||
|
GLsizei length; |
||||||
|
GLint size; |
||||||
|
GLenum type; |
||||||
|
|
||||||
|
for (int i = 0; i < active_uniforms; i++) { |
||||||
|
glGetActiveUniform(prog_id, i, sizeof(uni_name), |
||||||
|
&length, &size, &type, uni_name); |
||||||
|
printf("uniform idx: %d, type: %s, name: %s \n", |
||||||
|
i, glEnumToString(type), uni_name); |
||||||
|
} |
||||||
|
|
||||||
|
for (int i = 0; i < active_attribs; i++) { |
||||||
|
glGetActiveAttrib(prog_id, i, sizeof(uni_name), |
||||||
|
&length, &size, &type, uni_name); |
||||||
|
printf("attribute idx: %d, type: %s, name: %s \n", |
||||||
|
i, glEnumToString(type), uni_name); |
||||||
|
} |
||||||
|
|
||||||
|
printf("------------------------\n"); |
||||||
|
} |
||||||
|
|
||||||
|
#endif // ifdef GL_DEBUG_IMPLEMENTATION
|
||||||
|
|
||||||
@ -1,62 +0,0 @@ |
|||||||
|
|
||||||
#include <GL/glew.h> |
|
||||||
|
|
||||||
#include "shader.h" |
|
||||||
|
|
||||||
|
|
||||||
const char* gl_enum_to_string(GLenum e); |
|
||||||
|
|
||||||
|
|
||||||
void |
|
||||||
dumpShader(GLuint prog_id) |
|
||||||
{ |
|
||||||
std::cout << "dumping shader info, program id: " << prog_id << "\n"; |
|
||||||
|
|
||||||
GLint active_uniforms; |
|
||||||
GLint active_uniform_blocks; |
|
||||||
GLint active_attribs; |
|
||||||
|
|
||||||
// NOTE: unused uniforms/attributes get optimized away |
|
||||||
// https://www.khronos.org/opengl/wiki/Program_Introspection#Attributes |
|
||||||
// https://stackoverflow.com/questions/54811319/how-to-get-from-glgetattriblocation-to-glgetactiveattrib-index |
|
||||||
glGetProgramiv(prog_id, GL_ACTIVE_UNIFORMS, &active_uniforms); |
|
||||||
glGetProgramiv(prog_id, GL_ACTIVE_UNIFORM_BLOCKS, &active_uniform_blocks); |
|
||||||
glGetProgramiv(prog_id, GL_ACTIVE_ATTRIBUTES, &active_attribs); |
|
||||||
|
|
||||||
printf("active uniforms: %d\n", active_uniforms); |
|
||||||
printf("active uniform blocks: %d\n", active_uniform_blocks); |
|
||||||
printf("active attributes: %d\n", active_attribs); |
|
||||||
|
|
||||||
GLchar uni_name[256]; |
|
||||||
GLsizei length; |
|
||||||
GLint size; |
|
||||||
GLenum type; |
|
||||||
|
|
||||||
for (int i = 0; i < active_uniforms; i++) { |
|
||||||
glGetActiveUniform(prog_id, i, sizeof(uni_name), |
|
||||||
&length, &size, &type, uni_name); |
|
||||||
printf("uniform idx: %d, type: %s, name: %s \n", |
|
||||||
i, gl_enum_to_string(type), uni_name); |
|
||||||
} |
|
||||||
|
|
||||||
for (int i = 0; i < active_attribs; i++) { |
|
||||||
glGetActiveAttrib(prog_id, i, sizeof(uni_name), |
|
||||||
&length, &size, &type, uni_name); |
|
||||||
printf("attribute idx: %d, type: %s, name: %s \n", |
|
||||||
i, gl_enum_to_string(type), uni_name); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
const char* |
|
||||||
gl_enum_to_string(GLenum e) |
|
||||||
{ |
|
||||||
switch (e) { |
|
||||||
case 0x8b5c: return "GL_FLOAT_MAT4"; |
|
||||||
case 0x8b51: return "GL_FLOAT_VEC3"; |
|
||||||
case 0x8B52: return "GL_FLOAT_VEC4"; |
|
||||||
|
|
||||||
default: return "???"; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Loading…
Reference in new issue