1 #define GL_GLEXT_PROTOTYPES 1
12 void set_uniform_float(GLhandleARB glsl_program_num, const std::string &prefix, const std::string &key, float value)
14 std::string name = prefix + "_" + key;
15 GLuint l = glGetUniformLocation(glsl_program_num, name.c_str());
20 glUniform1f(l, value);
24 void set_uniform_vec3(GLhandleARB glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
26 std::string name = prefix + "_" + key;
27 GLuint l = glGetUniformLocation(glsl_program_num, name.c_str());
32 glUniform3fv(l, 1, values);
36 bool Effect::set_int(const std::string &key, int value)
38 if (params_int.count(key) == 0) {
41 *params_int[key] = value;
45 bool Effect::set_float(const std::string &key, float value)
47 if (params_float.count(key) == 0) {
50 *params_float[key] = value;
54 bool Effect::set_vec3(const std::string &key, const float *values)
56 if (params_vec3.count(key) == 0) {
59 memcpy(params_vec3[key], values, sizeof(float) * 3);
63 void Effect::register_int(const std::string &key, int *value)
65 assert(params_int.count(key) == 0);
66 params_int[key] = value;
69 void Effect::register_float(const std::string &key, float *value)
71 assert(params_float.count(key) == 0);
72 params_float[key] = value;
75 void Effect::register_vec3(const std::string &key, float *values)
77 assert(params_vec3.count(key) == 0);
78 params_vec3[key] = values;
81 // Output convenience uniforms for each parameter.
82 // These will be filled in per-frame.
83 std::string Effect::output_convenience_uniforms()
85 std::string output = "";
86 for (std::map<std::string, float*>::const_iterator it = params_float.begin();
87 it != params_float.end();
90 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
93 for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
94 it != params_vec3.end();
97 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
103 void Effect::set_uniforms(GLhandleARB glsl_program_num, const std::string& prefix)
105 for (std::map<std::string, float*>::const_iterator it = params_float.begin();
106 it != params_float.end();
108 set_uniform_float(glsl_program_num, prefix, it->first, *it->second);
110 for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
111 it != params_vec3.end();
113 set_uniform_vec3(glsl_program_num, prefix, it->first, it->second);