11 GLint get_uniform_location(GLuint glsl_program_num, const string &prefix, const string &key)
13 string name = prefix + "_" + key;
14 return glGetUniformLocation(glsl_program_num, name.c_str());
17 void set_uniform_int(GLuint glsl_program_num, const string &prefix, const string &key, int value)
19 GLint location = get_uniform_location(glsl_program_num, prefix, key);
24 glUniform1i(location, value);
28 void set_uniform_float(GLuint glsl_program_num, const string &prefix, const string &key, float value)
30 GLint location = get_uniform_location(glsl_program_num, prefix, key);
35 glUniform1f(location, value);
39 void set_uniform_vec2(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
41 GLint location = get_uniform_location(glsl_program_num, prefix, key);
46 glUniform2fv(location, 1, values);
50 void set_uniform_vec3(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
52 GLint location = get_uniform_location(glsl_program_num, prefix, key);
57 glUniform3fv(location, 1, values);
61 void set_uniform_vec4(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
63 GLint location = get_uniform_location(glsl_program_num, prefix, key);
68 glUniform4fv(location, 1, values);
72 void set_uniform_vec4_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values)
74 GLint location = get_uniform_location(glsl_program_num, prefix, key);
79 glUniform4fv(location, num_values, values);
83 void set_uniform_mat3(GLuint glsl_program_num, const string &prefix, const string &key, const Eigen::Matrix3d& matrix)
85 GLint location = get_uniform_location(glsl_program_num, prefix, key);
91 // Convert to float (GLSL has no double matrices).
93 for (unsigned y = 0; y < 3; ++y) {
94 for (unsigned x = 0; x < 3; ++x) {
95 matrixf[y + x * 3] = matrix(y, x);
99 glUniformMatrix3fv(location, 1, GL_FALSE, matrixf);