]> git.sesse.net Git - movit/blob - effect.cpp
927acd52e7934774ba0b43eea4b61202f7b9bf4e
[movit] / effect.cpp
1 #include <stdio.h>
2 #include <string.h>
3 #include <assert.h>
4 #include "effect.h"
5
6 bool Effect::set_int(const std::string &key, int value)
7 {
8         if (params_int.count(key) == 0) {
9                 return false;
10         }
11         *params_int[key] = value;
12         return true;
13 }
14
15 bool Effect::set_float(const std::string &key, float value)
16 {
17         if (params_float.count(key) == 0) {
18                 return false;
19         }
20         *params_float[key] = value;
21         return true;
22 }
23
24 bool Effect::set_vec3(const std::string &key, const float *values)
25 {
26         if (params_vec3.count(key) == 0) {
27                 return false;
28         }
29         memcpy(params_vec3[key], values, sizeof(float) * 3);
30         return true;
31 }
32
33 void Effect::register_int(const std::string &key, int *value)
34 {
35         assert(params_int.count(key) == 0);
36         params_int[key] = value;
37 }
38
39 void Effect::register_float(const std::string &key, float *value)
40 {
41         assert(params_float.count(key) == 0);
42         params_float[key] = value;
43 }
44
45 void Effect::register_vec3(const std::string &key, float *values)
46 {
47         assert(params_vec3.count(key) == 0);
48         params_vec3[key] = values;
49 }
50
51 // Output convenience uniforms for each parameter.
52 // These will be filled in per-frame.
53 std::string Effect::output_convenience_uniforms()
54 {
55         std::string output = "";
56         for (std::map<std::string, float*>::const_iterator it = params_float.begin();
57              it != params_float.end();
58              ++it) {
59                 char buf[256];
60                 sprintf(buf, "uniform float PREFIX(%s);\n", it->first.c_str());
61                 output.append(buf);
62         }
63         for (std::map<std::string, float*>::const_iterator it = params_vec3.begin();
64              it != params_vec3.end();
65              ++it) {
66                 char buf[256];
67                 sprintf(buf, "uniform vec3 PREFIX(%s);\n", it->first.c_str());
68                 output.append(buf);
69         }
70         return output;
71 }