9 GLint get_uniform_location(GLuint glsl_program_num, const string &prefix, const string &key)
11 string name = prefix + "_" + key;
12 return glGetUniformLocation(glsl_program_num, name.c_str());
15 void set_uniform_int(GLuint glsl_program_num, const string &prefix, const string &key, int value)
17 GLint location = get_uniform_location(glsl_program_num, prefix, key);
22 glUniform1i(location, value);
26 void set_uniform_float(GLuint glsl_program_num, const string &prefix, const string &key, float value)
28 GLint location = get_uniform_location(glsl_program_num, prefix, key);
33 glUniform1f(location, value);
37 void set_uniform_vec2(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
39 GLint location = get_uniform_location(glsl_program_num, prefix, key);
44 glUniform2fv(location, 1, values);
48 void set_uniform_vec3(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
50 GLint location = get_uniform_location(glsl_program_num, prefix, key);
55 glUniform3fv(location, 1, values);
59 void set_uniform_vec4(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
61 GLint location = get_uniform_location(glsl_program_num, prefix, key);
66 glUniform4fv(location, 1, values);
70 void set_uniform_vec4_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values)
72 GLint location = get_uniform_location(glsl_program_num, prefix, key);
77 glUniform4fv(location, num_values, values);
81 void set_uniform_mat3(GLuint glsl_program_num, const string &prefix, const string &key, const Eigen::Matrix3d& matrix)
83 GLint location = get_uniform_location(glsl_program_num, prefix, key);
89 // Convert to float (GLSL has no double matrices).
91 for (unsigned y = 0; y < 3; ++y) {
92 for (unsigned x = 0; x < 3; ++x) {
93 matrixf[y + x * 3] = matrix(y, x);
97 glUniformMatrix3fv(location, 1, GL_FALSE, matrixf);