check_error();
}
+void set_uniform_vec4(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
+{
+ GLint location = get_uniform_location(glsl_program_num, prefix, key);
+ if (location == -1) {
+ return;
+ }
+ check_error();
+ glUniform4fv(location, 1, values);
+ check_error();
+}
+
void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values)
{
GLint location = get_uniform_location(glsl_program_num, prefix, key);
return true;
}
+bool Effect::set_vec4(const std::string &key, const float *values)
+{
+ if (params_vec4.count(key) == 0) {
+ return false;
+ }
+ memcpy(params_vec4[key], values, sizeof(float) * 4);
+ return true;
+}
+
void Effect::register_int(const std::string &key, int *value)
{
assert(params_int.count(key) == 0);
params_vec3[key] = values;
}
+void Effect::register_vec4(const std::string &key, float *values)
+{
+ assert(params_vec4.count(key) == 0);
+ params_vec4[key] = values;
+}
+
void Effect::register_1d_texture(const std::string &key, float *values, size_t size)
{
assert(params_tex_1d.count(key) == 0);
sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
output.append(buf);
}
+ for (std::map<std::string, float*>::const_iterator it = params_vec4.begin();
+ it != params_vec4.end();
+ ++it) {
+ char buf[256];
+ sprintf(buf, "uniform vec4 PREFIX(%s);\n", it->first.c_str());
+ output.append(buf);
+ }
for (std::map<std::string, Texture1D>::const_iterator it = params_tex_1d.begin();
it != params_tex_1d.end();
++it) {
++it) {
set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);
}
+ for (std::map<std::string, float*>::const_iterator it = params_vec4.begin();
+ it != params_vec4.end();
+ ++it) {
+ set_uniform_vec4(glsl_program_num, prefix, it->first, it->second);
+ }
for (std::map<std::string, Texture1D>::iterator it = params_tex_1d.begin();
it != params_tex_1d.end();
float r, g, b;
};
+// Can alias on a float[4].
+struct RGBATriplet {
+ RGBATriplet(float r, float g, float b, float a)
+ : r(r), g(g), b(b), a(a) {}
+
+ float r, g, b, a;
+};
+
// Convenience functions that deal with prepending the prefix.
GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key);
void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value);
void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value);
void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
+void set_uniform_vec4(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values);
void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values);
void set_uniform_mat3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const Eigen::Matrix3d &matrix);
virtual bool set_float(const std::string &key, float value) MUST_CHECK_RESULT;
virtual bool set_vec2(const std::string &key, const float *values) MUST_CHECK_RESULT;
virtual bool set_vec3(const std::string &key, const float *values) MUST_CHECK_RESULT;
+ virtual bool set_vec4(const std::string &key, const float *values) MUST_CHECK_RESULT;
protected:
// Register a parameter. Whenever set_*() is called with the same key,
// Thus, ints that you register will _not_ be converted to GLSL uniforms.
void register_int(const std::string &key, int *value);
- // These correspond directly to float/vec2/vec3 in GLSL.
+ // These correspond directly to float/vec2/vec3/vec4 in GLSL.
void register_float(const std::string &key, float *value);
void register_vec2(const std::string &key, float *values);
void register_vec3(const std::string &key, float *values);
+ void register_vec4(const std::string &key, float *values);
// This will register a 1D texture, which will be bound to a sampler
// when your GLSL code runs (so it corresponds 1:1 to a sampler2D uniform
std::map<std::string, float *> params_float;
std::map<std::string, float *> params_vec2;
std::map<std::string, float *> params_vec3;
+ std::map<std::string, float *> params_vec4;
std::map<std::string, Texture1D> params_tex_1d;
};