Browse Source

move debugging output into new header 'GLDebug.h'

main
cinnaboot 5 years ago
parent
commit
d59be5bbe2
  1. 109
      src/GLDebug.h
  2. 62
      src/dumpShader.inl
  3. 17
      src/main.cpp
  4. 3
      src/shader.cpp
  5. 1
      src/tiny_gltf.cc

109
src/GLDebug.h

@ -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

62
src/dumpShader.inl

@ -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 "???";
}
}

17
src/main.cpp

@ -7,6 +7,7 @@
#include "asset.h"
#include "dumbLog.h"
#include "GLDebug.h"
#include "shader.h"
#include "types.h"
@ -168,22 +169,6 @@ initRenderState(memory_arena* arena)
return rs;
}
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: " << type
<< ", severity: " << severity
<< ", message: " << message << "\n";
}
bool
initGraphics(SDLHandles* handles)
{

3
src/shader.cpp

@ -10,9 +10,10 @@
#include <glm/gtc/matrix_transform.hpp>
#include "asset.h"
#define GL_DEBUG_IMPLEMENTATION
#include "GLDebug.h"
#include "shader.h"
#include "dumpShader.inl"
// NOTE: forward declarations

1
src/tiny_gltf.cc

@ -1,3 +1,4 @@
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define TINYGLTF_IMPLEMENTATION

Loading…
Cancel
Save