1 #define GL_GLEXT_PROTOTYPES 1
12 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value)
14 std::string name = prefix + "_" + key;
15 GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
20 glUniform1f(l, value);
24 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
26 std::string name = prefix + "_" + key;
27 GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
32 glUniform2fv(l, 1, values);
36 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
38 std::string name = prefix + "_" + key;
39 GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
44 glUniform3fv(l, 1, values);
48 bool Effect::set_int(const std::string &key, int value)
50 if (params_int.count(key) == 0) {
53 *params_int[key] = value;
57 bool Effect::set_float(const std::string &key, float value)
59 if (params_float.count(key) == 0) {
62 *params_float[key] = value;
66 bool Effect::set_vec2(const std::string &key, const float *values)
68 if (params_vec2.count(key) == 0) {
71 memcpy(params_vec2[key], values, sizeof(float) * 2);
75 bool Effect::set_vec3(const std::string &key, const float *values)
77 if (params_vec3.count(key) == 0) {
80 memcpy(params_vec3[key], values, sizeof(float) * 3);
84 void Effect::register_int(const std::string &key, int *value)
86 assert(params_int.count(key) == 0);
87 params_int[key] = value;
90 void Effect::register_float(const std::string &key, float *value)
92 assert(params_float.count(key) == 0);
93 params_float[key] = value;
96 void Effect::register_vec2(const std::string &key, float *values)
98 assert(params_vec2.count(key) == 0);
99 params_vec2[key] = values;
102 void Effect::register_vec3(const std::string &key, float *values)
104 assert(params_vec3.count(key) == 0);
105 params_vec3[key] = values;
108 // Output convenience uniforms for each parameter.
109 // These will be filled in per-frame.
110 std::string Effect::output_convenience_uniforms()
112 std::string output = "";
113 for (std::map<std::string, float*>::const_iterator it = params_float.begin();
114 it != params_float.end();
117 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
120 for (std::map<std::string, float*>::const_iterator it = params_vec2.begin();
121 it != params_vec2.end();
124 sprintf(buf, "uniform vec2 PREFIX(%s);\n", it->first.c_str());
127 for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
128 it != params_vec3.end();
131 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
137 void Effect::set_uniforms(GLuint glsl_program_num, const std::string& prefix)
139 for (std::map<std::string, float*>::const_iterator it = params_float.begin();
140 it != params_float.end();
142 set_uniform_float(glsl_program_num, prefix, it->first, *it->second);
144 for (std::map<std::string, float*>::const_iterator it = params_vec2.begin();
145 it != params_vec2.end();
147 set_uniform_vec2(glsl_program_num, prefix, it->first, it->second);
149 for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
150 it != params_vec3.end();
152 set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);