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 get_uniform_offset_and_size(GLuint glsl_program_num, const string &prefix, const string &key, GLint *offset, GLint *size)
19 string name = prefix + "_" + key;
21 const GLchar *name_cstr = name.c_str();
22 glGetUniformIndices(glsl_program_num, 1, &name_cstr, &index);
24 if (index == GL_INVALID_INDEX) {
29 glGetActiveUniformsiv(glsl_program_num, 1, &index, GL_UNIFORM_OFFSET, offset);
31 glGetActiveUniformsiv(glsl_program_num, 1, &index, GL_UNIFORM_SIZE, size);
35 void set_uniform_int(GLuint glsl_program_num, const string &prefix, const string &key, int value)
37 GLint location = get_uniform_location(glsl_program_num, prefix, key);
42 glUniform1i(location, value);
46 void set_uniform_float(GLuint glsl_program_num, const string &prefix, const string &key, float value)
48 GLint location = get_uniform_location(glsl_program_num, prefix, key);
53 glUniform1f(location, value);
57 void set_uniform_vec2(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
59 GLint location = get_uniform_location(glsl_program_num, prefix, key);
64 glUniform2fv(location, 1, values);
68 void set_uniform_vec3(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
70 GLint location = get_uniform_location(glsl_program_num, prefix, key);
75 glUniform3fv(location, 1, values);
79 void set_uniform_vec4(GLuint glsl_program_num, const string &prefix, const string &key, const float *values)
81 GLint location = get_uniform_location(glsl_program_num, prefix, key);
86 glUniform4fv(location, 1, values);
90 void set_uniform_vec2_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values)
92 GLint location = get_uniform_location(glsl_program_num, prefix, key);
97 glUniform2fv(location, num_values, values);
101 void set_uniform_vec4_array(GLuint glsl_program_num, const string &prefix, const string &key, const float *values, size_t num_values)
103 GLint location = get_uniform_location(glsl_program_num, prefix, key);
104 if (location == -1) {
108 glUniform4fv(location, num_values, values);
112 void set_uniform_mat3(GLuint glsl_program_num, const string &prefix, const string &key, const Eigen::Matrix3d& matrix)
114 GLint location = get_uniform_location(glsl_program_num, prefix, key);
115 if (location == -1) {
120 // Convert to float (GLSL has no double matrices).
122 for (unsigned y = 0; y < 3; ++y) {
123 for (unsigned x = 0; x < 3; ++x) {
124 matrixf[y + x * 3] = matrix(y, x);
128 glUniformMatrix3fv(location, 1, GL_FALSE, matrixf);