8 #include "effect_util.h"
12 bool Effect::set_int(const string &key, int value)
14 if (params_int.count(key) == 0) {
17 *params_int[key] = value;
21 bool Effect::set_float(const string &key, float value)
23 if (params_float.count(key) == 0) {
26 *params_float[key] = value;
30 bool Effect::set_vec2(const string &key, const float *values)
32 if (params_vec2.count(key) == 0) {
35 memcpy(params_vec2[key], values, sizeof(float) * 2);
39 bool Effect::set_vec3(const string &key, const float *values)
41 if (params_vec3.count(key) == 0) {
44 memcpy(params_vec3[key], values, sizeof(float) * 3);
48 bool Effect::set_vec4(const string &key, const float *values)
50 if (params_vec4.count(key) == 0) {
53 memcpy(params_vec4[key], values, sizeof(float) * 4);
57 void Effect::register_int(const string &key, int *value)
59 assert(params_int.count(key) == 0);
60 params_int[key] = value;
63 void Effect::register_float(const string &key, float *value)
65 assert(params_float.count(key) == 0);
66 params_float[key] = value;
69 void Effect::register_vec2(const string &key, float *values)
71 assert(params_vec2.count(key) == 0);
72 params_vec2[key] = values;
75 void Effect::register_vec3(const string &key, float *values)
77 assert(params_vec3.count(key) == 0);
78 params_vec3[key] = values;
81 void Effect::register_vec4(const string &key, float *values)
83 assert(params_vec4.count(key) == 0);
84 params_vec4[key] = values;
87 // Output convenience uniforms for each parameter.
88 // These will be filled in per-frame.
89 string Effect::output_convenience_uniforms() const
92 for (map<string, float*>::const_iterator it = params_float.begin();
93 it != params_float.end();
96 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
99 for (map<string, float*>::const_iterator it = params_vec2.begin();
100 it != params_vec2.end();
103 sprintf(buf, "uniform vec2 PREFIX(%s);\n", it->first.c_str());
106 for (map<string, float*>::const_iterator it = params_vec3.begin();
107 it != params_vec3.end();
110 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
113 for (map<string, float*>::const_iterator it = params_vec4.begin();
114 it != params_vec4.end();
117 sprintf(buf, "uniform vec4 PREFIX(%s);\n", it->first.c_str());
123 void Effect::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num)
125 for (map<string, float*>::const_iterator it = params_float.begin();
126 it != params_float.end();
128 set_uniform_float(glsl_program_num, prefix, it->first, *it->second);
130 for (map<string, float*>::const_iterator it = params_vec2.begin();
131 it != params_vec2.end();
133 set_uniform_vec2(glsl_program_num, prefix, it->first, it->second);
135 for (map<string, float*>::const_iterator it = params_vec3.begin();
136 it != params_vec3.end();
138 set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);
140 for (map<string, float*>::const_iterator it = params_vec4.begin();
141 it != params_vec4.end();
143 set_uniform_vec4(glsl_program_num, prefix, it->first, it->second);
147 void Effect::clear_gl_state() {}