8 #include "effect_util.h"
13 bool Effect::set_int(const string &key, int value)
15 if (params_int.count(key) == 0) {
18 *params_int[key] = value;
22 bool Effect::set_float(const string &key, float value)
24 if (params_float.count(key) == 0) {
27 *params_float[key] = value;
31 bool Effect::set_vec2(const string &key, const float *values)
33 if (params_vec2.count(key) == 0) {
36 memcpy(params_vec2[key], values, sizeof(float) * 2);
40 bool Effect::set_vec3(const string &key, const float *values)
42 if (params_vec3.count(key) == 0) {
45 memcpy(params_vec3[key], values, sizeof(float) * 3);
49 bool Effect::set_vec4(const string &key, const float *values)
51 if (params_vec4.count(key) == 0) {
54 memcpy(params_vec4[key], values, sizeof(float) * 4);
58 void Effect::register_int(const string &key, int *value)
60 assert(params_int.count(key) == 0);
61 params_int[key] = value;
64 void Effect::register_float(const string &key, float *value)
66 assert(params_float.count(key) == 0);
67 params_float[key] = value;
70 void Effect::register_vec2(const string &key, float *values)
72 assert(params_vec2.count(key) == 0);
73 params_vec2[key] = values;
76 void Effect::register_vec3(const string &key, float *values)
78 assert(params_vec3.count(key) == 0);
79 params_vec3[key] = values;
82 void Effect::register_vec4(const string &key, float *values)
84 assert(params_vec4.count(key) == 0);
85 params_vec4[key] = values;
88 // Output convenience uniforms for each parameter.
89 // These will be filled in per-frame.
90 string Effect::output_convenience_uniforms() const
93 for (map<string, float*>::const_iterator it = params_float.begin();
94 it != params_float.end();
97 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
100 for (map<string, float*>::const_iterator it = params_vec2.begin();
101 it != params_vec2.end();
104 sprintf(buf, "uniform vec2 PREFIX(%s);\n", it->first.c_str());
107 for (map<string, float*>::const_iterator it = params_vec3.begin();
108 it != params_vec3.end();
111 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
114 for (map<string, float*>::const_iterator it = params_vec4.begin();
115 it != params_vec4.end();
118 sprintf(buf, "uniform vec4 PREFIX(%s);\n", it->first.c_str());
124 void Effect::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num)
126 for (map<string, float*>::const_iterator it = params_float.begin();
127 it != params_float.end();
129 set_uniform_float(glsl_program_num, prefix, it->first, *it->second);
131 for (map<string, float*>::const_iterator it = params_vec2.begin();
132 it != params_vec2.end();
134 set_uniform_vec2(glsl_program_num, prefix, it->first, it->second);
136 for (map<string, float*>::const_iterator it = params_vec3.begin();
137 it != params_vec3.end();
139 set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);
141 for (map<string, float*>::const_iterator it = params_vec4.begin();
142 it != params_vec4.end();
144 set_uniform_vec4(glsl_program_num, prefix, it->first, it->second);
148 void Effect::clear_gl_state() {}