]> git.sesse.net Git - movit/blob - effect.cpp
In ResampleEffect, precompute the Lanczos function into a table.
[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_float(const string &key, float value)
25 {
26         if (params_float.count(key) == 0) {
27                 return false;
28         }
29         *params_float[key] = value;
30         return true;
31 }
32
33 bool Effect::set_vec2(const string &key, const float *values)
34 {
35         if (params_vec2.count(key) == 0) {
36                 return false;
37         }
38         memcpy(params_vec2[key], values, sizeof(float) * 2);
39         return true;
40 }
41
42 bool Effect::set_vec3(const string &key, const float *values)
43 {
44         if (params_vec3.count(key) == 0) {
45                 return false;
46         }
47         memcpy(params_vec3[key], values, sizeof(float) * 3);
48         return true;
49 }
50
51 bool Effect::set_vec4(const string &key, const float *values)
52 {
53         if (params_vec4.count(key) == 0) {
54                 return false;
55         }
56         memcpy(params_vec4[key], values, sizeof(float) * 4);
57         return true;
58 }
59
60 void Effect::register_int(const string &key, int *value)
61 {
62         assert(params_int.count(key) == 0);
63         params_int[key] = value;
64 }
65
66 void Effect::register_float(const string &key, float *value)
67 {
68         assert(params_float.count(key) == 0);
69         params_float[key] = value;
70         register_uniform_float(key, value);
71 }
72
73 void Effect::register_vec2(const string &key, float *values)
74 {
75         assert(params_vec2.count(key) == 0);
76         params_vec2[key] = values;
77         register_uniform_vec2(key, values);
78 }
79
80 void Effect::register_vec3(const string &key, float *values)
81 {
82         assert(params_vec3.count(key) == 0);
83         params_vec3[key] = values;
84         register_uniform_vec3(key, values);
85 }
86
87 void Effect::register_vec4(const string &key, float *values)
88 {
89         assert(params_vec4.count(key) == 0);
90         params_vec4[key] = values;
91         register_uniform_vec4(key, values);
92 }
93
94 void Effect::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num) {}
95
96 void Effect::clear_gl_state() {}
97
98 void Effect::register_uniform_sampler2d(const std::string &key, const GLint *value)
99 {
100         Uniform<int> uniform;
101         uniform.name = key;
102         uniform.value = value;
103         uniform.num_values = 1;
104         uniform.location = -1;
105         uniforms_sampler2d.push_back(uniform);
106 }
107
108 void Effect::register_uniform_bool(const std::string &key, const bool *value)
109 {
110         Uniform<bool> uniform;
111         uniform.name = key;
112         uniform.value = value;
113         uniform.num_values = 1;
114         uniform.location = -1;
115         uniforms_bool.push_back(uniform);
116 }
117
118 void Effect::register_uniform_int(const std::string &key, const int *value)
119 {
120         Uniform<int> uniform;
121         uniform.name = key;
122         uniform.value = value;
123         uniform.num_values = 1;
124         uniform.location = -1;
125         uniforms_int.push_back(uniform);
126 }
127
128 void Effect::register_uniform_float(const std::string &key, const float *value)
129 {
130         Uniform<float> uniform;
131         uniform.name = key;
132         uniform.value = value;
133         uniform.num_values = 1;
134         uniform.location = -1;
135         uniforms_float.push_back(uniform);
136 }
137
138 void Effect::register_uniform_vec2(const std::string &key, const float *values)
139 {
140         Uniform<float> uniform;
141         uniform.name = key;
142         uniform.value = values;
143         uniform.num_values = 1;
144         uniform.location = -1;
145         uniforms_vec2.push_back(uniform);
146 }
147
148 void Effect::register_uniform_vec3(const std::string &key, const float *values)
149 {
150         Uniform<float> uniform;
151         uniform.name = key;
152         uniform.value = values;
153         uniform.num_values = 1;
154         uniform.location = -1;
155         uniforms_vec3.push_back(uniform);
156 }
157
158 void Effect::register_uniform_vec4(const std::string &key, const float *values)
159 {
160         Uniform<float> uniform;
161         uniform.name = key;
162         uniform.value = values;
163         uniform.num_values = 1;
164         uniform.location = -1;
165         uniforms_vec4.push_back(uniform);
166 }
167
168 void Effect::register_uniform_vec2_array(const std::string &key, const float *values, size_t num_values)
169 {
170         Uniform<float> uniform;
171         uniform.name = key;
172         uniform.value = values;
173         uniform.num_values = num_values;
174         uniform.location = -1;
175         uniforms_vec2_array.push_back(uniform);
176 }
177
178 void Effect::register_uniform_vec4_array(const std::string &key, const float *values, size_t num_values)
179 {
180         Uniform<float> uniform;
181         uniform.name = key;
182         uniform.value = values;
183         uniform.num_values = num_values;
184         uniform.location = -1;
185         uniforms_vec4_array.push_back(uniform);
186 }
187
188 void Effect::register_uniform_mat3(const std::string &key, const Matrix3d *matrix)
189 {
190         Uniform<Matrix3d> uniform;
191         uniform.name = key;
192         uniform.value = matrix;
193         uniform.num_values = 1;
194         uniform.location = -1;
195         uniforms_mat3.push_back(uniform);
196 }
197
198 }  // namespace movit