]> git.sesse.net Git - movit/blob - effect.cpp
Microoptimization in calculate_scaling_weights.
[movit] / effect.cpp
1 #include <epoxy/gl.h>
2 #include <assert.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <utility>
6
7 #include "effect.h"
8 #include "effect_util.h"
9
10 using namespace Eigen;
11 using namespace std;
12
13 namespace movit {
14
15 bool Effect::set_int(const string &key, int value)
16 {
17         if (params_int.count(key) == 0) {
18                 return false;
19         }
20         *params_int[key] = value;
21         return true;
22 }
23
24 bool Effect::set_ivec2(const string &key, const int *values)
25 {
26         if (params_ivec2.count(key) == 0) {
27                 return false;
28         }
29         memcpy(params_ivec2[key], values, sizeof(int) * 2);
30         return true;
31 }
32
33 bool Effect::set_float(const string &key, float value)
34 {
35         if (params_float.count(key) == 0) {
36                 return false;
37         }
38         *params_float[key] = value;
39         return true;
40 }
41
42 bool Effect::set_vec2(const string &key, const float *values)
43 {
44         if (params_vec2.count(key) == 0) {
45                 return false;
46         }
47         memcpy(params_vec2[key], values, sizeof(float) * 2);
48         return true;
49 }
50
51 bool Effect::set_vec3(const string &key, const float *values)
52 {
53         if (params_vec3.count(key) == 0) {
54                 return false;
55         }
56         memcpy(params_vec3[key], values, sizeof(float) * 3);
57         return true;
58 }
59
60 bool Effect::set_vec4(const string &key, const float *values)
61 {
62         if (params_vec4.count(key) == 0) {
63                 return false;
64         }
65         memcpy(params_vec4[key], values, sizeof(float) * 4);
66         return true;
67 }
68
69 void Effect::register_int(const string &key, int *value)
70 {
71         assert(params_int.count(key) == 0);
72         params_int[key] = value;
73         register_uniform_int(key, value);
74 }
75
76 void Effect::register_ivec2(const string &key, int *values)
77 {
78         assert(params_ivec2.count(key) == 0);
79         params_ivec2[key] = values;
80         register_uniform_ivec2(key, values);
81 }
82
83 void Effect::register_float(const string &key, float *value)
84 {
85         assert(params_float.count(key) == 0);
86         params_float[key] = value;
87         register_uniform_float(key, value);
88 }
89
90 void Effect::register_vec2(const string &key, float *values)
91 {
92         assert(params_vec2.count(key) == 0);
93         params_vec2[key] = values;
94         register_uniform_vec2(key, values);
95 }
96
97 void Effect::register_vec3(const string &key, float *values)
98 {
99         assert(params_vec3.count(key) == 0);
100         params_vec3[key] = values;
101         register_uniform_vec3(key, values);
102 }
103
104 void Effect::register_vec4(const string &key, float *values)
105 {
106         assert(params_vec4.count(key) == 0);
107         params_vec4[key] = values;
108         register_uniform_vec4(key, values);
109 }
110
111 void Effect::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num) {}
112
113 void Effect::clear_gl_state() {}
114
115 void Effect::register_uniform_sampler2d(const std::string &key, const GLint *value)
116 {
117         Uniform<int> uniform;
118         uniform.name = key;
119         uniform.value = value;
120         uniform.num_values = 1;
121         uniform.location = -1;
122         uniforms_sampler2d.push_back(uniform);
123 }
124
125 void Effect::register_uniform_bool(const std::string &key, const bool *value)
126 {
127         Uniform<bool> uniform;
128         uniform.name = key;
129         uniform.value = value;
130         uniform.num_values = 1;
131         uniform.location = -1;
132         uniforms_bool.push_back(uniform);
133 }
134
135 void Effect::register_uniform_int(const std::string &key, const int *value)
136 {
137         Uniform<int> uniform;
138         uniform.name = key;
139         uniform.value = value;
140         uniform.num_values = 1;
141         uniform.location = -1;
142         uniforms_int.push_back(uniform);
143 }
144
145 void Effect::register_uniform_ivec2(const std::string &key, const int *values)
146 {
147         Uniform<int> uniform;
148         uniform.name = key;
149         uniform.value = values;
150         uniform.num_values = 1;
151         uniform.location = -1;
152         uniforms_ivec2.push_back(uniform);
153 }
154
155 void Effect::register_uniform_float(const std::string &key, const float *value)
156 {
157         Uniform<float> uniform;
158         uniform.name = key;
159         uniform.value = value;
160         uniform.num_values = 1;
161         uniform.location = -1;
162         uniforms_float.push_back(uniform);
163 }
164
165 void Effect::register_uniform_vec2(const std::string &key, const float *values)
166 {
167         Uniform<float> uniform;
168         uniform.name = key;
169         uniform.value = values;
170         uniform.num_values = 1;
171         uniform.location = -1;
172         uniforms_vec2.push_back(uniform);
173 }
174
175 void Effect::register_uniform_vec3(const std::string &key, const float *values)
176 {
177         Uniform<float> uniform;
178         uniform.name = key;
179         uniform.value = values;
180         uniform.num_values = 1;
181         uniform.location = -1;
182         uniforms_vec3.push_back(uniform);
183 }
184
185 void Effect::register_uniform_vec4(const std::string &key, const float *values)
186 {
187         Uniform<float> uniform;
188         uniform.name = key;
189         uniform.value = values;
190         uniform.num_values = 1;
191         uniform.location = -1;
192         uniforms_vec4.push_back(uniform);
193 }
194
195 void Effect::register_uniform_float_array(const std::string &key, const float *values, size_t num_values)
196 {
197         Uniform<float> uniform;
198         uniform.name = key;
199         uniform.value = values;
200         uniform.num_values = num_values;
201         uniform.location = -1;
202         uniforms_float_array.push_back(uniform);
203 }
204
205 void Effect::register_uniform_vec2_array(const std::string &key, const float *values, size_t num_values)
206 {
207         Uniform<float> uniform;
208         uniform.name = key;
209         uniform.value = values;
210         uniform.num_values = num_values;
211         uniform.location = -1;
212         uniforms_vec2_array.push_back(uniform);
213 }
214
215 void Effect::register_uniform_vec3_array(const std::string &key, const float *values, size_t num_values)
216 {
217         Uniform<float> uniform;
218         uniform.name = key;
219         uniform.value = values;
220         uniform.num_values = num_values;
221         uniform.location = -1;
222         uniforms_vec3_array.push_back(uniform);
223 }
224
225 void Effect::register_uniform_vec4_array(const std::string &key, const float *values, size_t num_values)
226 {
227         Uniform<float> uniform;
228         uniform.name = key;
229         uniform.value = values;
230         uniform.num_values = num_values;
231         uniform.location = -1;
232         uniforms_vec4_array.push_back(uniform);
233 }
234
235 void Effect::register_uniform_mat3(const std::string &key, const Matrix3d *matrix)
236 {
237         Uniform<Matrix3d> uniform;
238         uniform.name = key;
239         uniform.value = matrix;
240         uniform.num_values = 1;
241         uniform.location = -1;
242         uniforms_mat3.push_back(uniform);
243 }
244
245 }  // namespace movit