8 #include "effect_util.h"
14 bool Effect::set_int(const string &key, int value)
16 if (params_int.count(key) == 0) {
19 *params_int[key] = value;
23 bool Effect::set_float(const string &key, float value)
25 if (params_float.count(key) == 0) {
28 *params_float[key] = value;
32 bool Effect::set_vec2(const string &key, const float *values)
34 if (params_vec2.count(key) == 0) {
37 memcpy(params_vec2[key], values, sizeof(float) * 2);
41 bool Effect::set_vec3(const string &key, const float *values)
43 if (params_vec3.count(key) == 0) {
46 memcpy(params_vec3[key], values, sizeof(float) * 3);
50 bool Effect::set_vec4(const string &key, const float *values)
52 if (params_vec4.count(key) == 0) {
55 memcpy(params_vec4[key], values, sizeof(float) * 4);
59 void Effect::register_int(const string &key, int *value)
61 assert(params_int.count(key) == 0);
62 params_int[key] = value;
65 void Effect::register_float(const string &key, float *value)
67 assert(params_float.count(key) == 0);
68 params_float[key] = value;
71 void Effect::register_vec2(const string &key, float *values)
73 assert(params_vec2.count(key) == 0);
74 params_vec2[key] = values;
77 void Effect::register_vec3(const string &key, float *values)
79 assert(params_vec3.count(key) == 0);
80 params_vec3[key] = values;
83 void Effect::register_vec4(const string &key, float *values)
85 assert(params_vec4.count(key) == 0);
86 params_vec4[key] = values;
89 // Output convenience uniforms for each parameter.
90 // These will be filled in per-frame.
91 string Effect::output_convenience_uniforms() const
94 for (map<string, float*>::const_iterator it = params_float.begin();
95 it != params_float.end();
98 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
101 for (map<string, float*>::const_iterator it = params_vec2.begin();
102 it != params_vec2.end();
105 sprintf(buf, "uniform vec2 PREFIX(%s);\n", it->first.c_str());
108 for (map<string, float*>::const_iterator it = params_vec3.begin();
109 it != params_vec3.end();
112 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
115 for (map<string, float*>::const_iterator it = params_vec4.begin();
116 it != params_vec4.end();
119 sprintf(buf, "uniform vec4 PREFIX(%s);\n", it->first.c_str());
125 void Effect::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num)
127 for (map<string, float*>::const_iterator it = params_float.begin();
128 it != params_float.end();
130 set_uniform_float(glsl_program_num, prefix, it->first, *it->second);
132 for (map<string, float*>::const_iterator it = params_vec2.begin();
133 it != params_vec2.end();
135 set_uniform_vec2(glsl_program_num, prefix, it->first, it->second);
137 for (map<string, float*>::const_iterator it = params_vec3.begin();
138 it != params_vec3.end();
140 set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);
142 for (map<string, float*>::const_iterator it = params_vec4.begin();
143 it != params_vec4.end();
145 set_uniform_vec4(glsl_program_num, prefix, it->first, it->second);
149 void Effect::clear_gl_state() {}