Commit ff6301e2 authored by Sadman Kazi's avatar Sadman Kazi 🎸

Add function to print all active uniforms

parent 6aa2dd73
Pipeline #88 passed with stage
in 2 minutes and 23 seconds
......@@ -35,11 +35,32 @@ Shader::~Shader()
glDeleteProgram(m_program);
}
void Shader::printActiveUniforms() {
GLint i;
GLint count;
GLint size; // size of the variable
GLenum type; // type of the variable (float, vec3 or mat4, etc)
const GLsizei bufSize = 16; // maximum name length
GLchar name[bufSize]; // variable name in GLSL
GLsizei length; // name length
glGetProgramiv(m_program, GL_ACTIVE_UNIFORMS, &count);
std::cout << "Active Uniforms: " << count << std::endl;
for (i = 0; i < count; i++) {
glGetActiveUniform(m_program, (GLuint)i, bufSize, &length, &size, &type, name);
std::cout << "Uniform #" << i << " Type: " << type << " Name: " << name << std::endl;
}
}
void Shader::addUniform(const std::string& uniform) {
int uniformLocation = glGetUniformLocation(m_program, uniform.c_str());
if (uniformLocation < 0) {
if (uniformLocation == -1) {
std::cerr << "Error: Could not find uniform " << uniform << std::endl;
printActiveUniforms();
throw std::exception(); // TODO: Custom exception class
} else {
//once we know that the uniform exists, add it to the hash map
......
......@@ -10,6 +10,7 @@ public:
Shader(const std::string fileName);
void bind();
void printActiveUniforms();
void addUniform(const std::string& uniform);
//methods for setting uniform values
void setUniformI(const std::string& name, int value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment