8 #include "effect_util.h"
11 bool Effect::set_int(const std::string &key, int value)
13 if (params_int.count(key) == 0) {
16 *params_int[key] = value;
20 bool Effect::set_float(const std::string &key, float value)
22 if (params_float.count(key) == 0) {
25 *params_float[key] = value;
29 bool Effect::set_vec2(const std::string &key, const float *values)
31 if (params_vec2.count(key) == 0) {
34 memcpy(params_vec2[key], values, sizeof(float) * 2);
38 bool Effect::set_vec3(const std::string &key, const float *values)
40 if (params_vec3.count(key) == 0) {
43 memcpy(params_vec3[key], values, sizeof(float) * 3);
47 bool Effect::set_vec4(const std::string &key, const float *values)
49 if (params_vec4.count(key) == 0) {
52 memcpy(params_vec4[key], values, sizeof(float) * 4);
56 void Effect::register_int(const std::string &key, int *value)
58 assert(params_int.count(key) == 0);
59 params_int[key] = value;
62 void Effect::register_float(const std::string &key, float *value)
64 assert(params_float.count(key) == 0);
65 params_float[key] = value;
68 void Effect::register_vec2(const std::string &key, float *values)
70 assert(params_vec2.count(key) == 0);
71 params_vec2[key] = values;
74 void Effect::register_vec3(const std::string &key, float *values)
76 assert(params_vec3.count(key) == 0);
77 params_vec3[key] = values;
80 void Effect::register_vec4(const std::string &key, float *values)
82 assert(params_vec4.count(key) == 0);
83 params_vec4[key] = values;
86 // Output convenience uniforms for each parameter.
87 // These will be filled in per-frame.
88 std::string Effect::output_convenience_uniforms() const
90 std::string output = "";
91 for (std::map<std::string, float*>::const_iterator it = params_float.begin();
92 it != params_float.end();
95 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
98 for (std::map<std::string, float*>::const_iterator it = params_vec2.begin();
99 it != params_vec2.end();
102 sprintf(buf, "uniform vec2 PREFIX(%s);\n", it->first.c_str());
105 for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
106 it != params_vec3.end();
109 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
112 for (std::map<std::string, float*>::const_iterator it = params_vec4.begin();
113 it != params_vec4.end();
116 sprintf(buf, "uniform vec4 PREFIX(%s);\n", it->first.c_str());
122 void Effect::set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
124 for (std::map<std::string, float*>::const_iterator it = params_float.begin();
125 it != params_float.end();
127 set_uniform_float(glsl_program_num, prefix, it->first, *it->second);
129 for (std::map<std::string, float*>::const_iterator it = params_vec2.begin();
130 it != params_vec2.end();
132 set_uniform_vec2(glsl_program_num, prefix, it->first, it->second);
134 for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
135 it != params_vec3.end();
137 set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);
139 for (std::map<std::string, float*>::const_iterator it = params_vec4.begin();
140 it != params_vec4.end();
142 set_uniform_vec4(glsl_program_num, prefix, it->first, it->second);
146 void Effect::clear_gl_state() {}