Small program to quickly test OpenGL GLSL shaders.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

61 lines
1.6 KiB

#include <GL/glew.h>
#include "shader_testing.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, len: %d, type: %s, name: %s \n",
i, length, 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, len: %d, type: %s, name: %s \n",
i, length, 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";
default: return "???";
}
}