7 GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key)
9 std::string name = prefix + "_" + key;
10 return glGetUniformLocation(glsl_program_num, name.c_str());
13 void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value)
15 GLint location = get_uniform_location(glsl_program_num, prefix, key);
20 glUniform1i(location, value);
24 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value)
26 GLint location = get_uniform_location(glsl_program_num, prefix, key);
31 glUniform1f(location, value);
35 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
37 GLint location = get_uniform_location(glsl_program_num, prefix, key);
42 glUniform2fv(location, 1, values);
46 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
48 GLint location = get_uniform_location(glsl_program_num, prefix, key);
53 glUniform3fv(location, 1, values);
57 void set_uniform_vec4(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
59 GLint location = get_uniform_location(glsl_program_num, prefix, key);
64 glUniform4fv(location, 1, values);
68 void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values)
70 GLint location = get_uniform_location(glsl_program_num, prefix, key);
75 glUniform4fv(location, num_values, values);
79 void set_uniform_mat3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const Eigen::Matrix3d& matrix)
81 GLint location = get_uniform_location(glsl_program_num, prefix, key);
87 // Convert to float (GLSL has no double matrices).
89 for (unsigned y = 0; y < 3; ++y) {
90 for (unsigned x = 0; x < 3; ++x) {
91 matrixf[y + x * 3] = matrix(y, x);
95 glUniformMatrix3fv(location, 1, GL_FALSE, matrixf);