]> git.sesse.net Git - movit/blob - effect.cpp
Release Movit 1.5.2.
[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         register_uniform_int(key, value);
65 }
66
67 void Effect::register_float(const string &key, float *value)
68 {
69         assert(params_float.count(key) == 0);
70         params_float[key] = value;
71         register_uniform_float(key, value);
72 }
73
74 void Effect::register_vec2(const string &key, float *values)
75 {
76         assert(params_vec2.count(key) == 0);
77         params_vec2[key] = values;
78         register_uniform_vec2(key, values);
79 }
80
81 void Effect::register_vec3(const string &key, float *values)
82 {
83         assert(params_vec3.count(key) == 0);
84         params_vec3[key] = values;
85         register_uniform_vec3(key, values);
86 }
87
88 void Effect::register_vec4(const string &key, float *values)
89 {
90         assert(params_vec4.count(key) == 0);
91         params_vec4[key] = values;
92         register_uniform_vec4(key, values);
93 }
94
95 void Effect::set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num) {}
96
97 void Effect::clear_gl_state() {}
98
99 void Effect::register_uniform_sampler2d(const std::string &key, const GLint *value)
100 {
101         Uniform<int> uniform;
102         uniform.name = key;
103         uniform.value = value;
104         uniform.num_values = 1;
105         uniform.location = -1;
106         uniforms_sampler2d.push_back(uniform);
107 }
108
109 void Effect::register_uniform_bool(const std::string &key, const bool *value)
110 {
111         Uniform<bool> uniform;
112         uniform.name = key;
113         uniform.value = value;
114         uniform.num_values = 1;
115         uniform.location = -1;
116         uniforms_bool.push_back(uniform);
117 }
118
119 void Effect::register_uniform_int(const std::string &key, const int *value)
120 {
121         Uniform<int> uniform;
122         uniform.name = key;
123         uniform.value = value;
124         uniform.num_values = 1;
125         uniform.location = -1;
126         uniforms_int.push_back(uniform);
127 }
128
129 void Effect::register_uniform_float(const std::string &key, const float *value)
130 {
131         Uniform<float> uniform;
132         uniform.name = key;
133         uniform.value = value;
134         uniform.num_values = 1;
135         uniform.location = -1;
136         uniforms_float.push_back(uniform);
137 }
138
139 void Effect::register_uniform_vec2(const std::string &key, const float *values)
140 {
141         Uniform<float> uniform;
142         uniform.name = key;
143         uniform.value = values;
144         uniform.num_values = 1;
145         uniform.location = -1;
146         uniforms_vec2.push_back(uniform);
147 }
148
149 void Effect::register_uniform_vec3(const std::string &key, const float *values)
150 {
151         Uniform<float> uniform;
152         uniform.name = key;
153         uniform.value = values;
154         uniform.num_values = 1;
155         uniform.location = -1;
156         uniforms_vec3.push_back(uniform);
157 }
158
159 void Effect::register_uniform_vec4(const std::string &key, const float *values)
160 {
161         Uniform<float> uniform;
162         uniform.name = key;
163         uniform.value = values;
164         uniform.num_values = 1;
165         uniform.location = -1;
166         uniforms_vec4.push_back(uniform);
167 }
168
169 void Effect::register_uniform_float_array(const std::string &key, const float *values, size_t num_values)
170 {
171         Uniform<float> uniform;
172         uniform.name = key;
173         uniform.value = values;
174         uniform.num_values = num_values;
175         uniform.location = -1;
176         uniforms_float_array.push_back(uniform);
177 }
178
179 void Effect::register_uniform_vec2_array(const std::string &key, const float *values, size_t num_values)
180 {
181         Uniform<float> uniform;
182         uniform.name = key;
183         uniform.value = values;
184         uniform.num_values = num_values;
185         uniform.location = -1;
186         uniforms_vec2_array.push_back(uniform);
187 }
188
189 void Effect::register_uniform_vec3_array(const std::string &key, const float *values, size_t num_values)
190 {
191         Uniform<float> uniform;
192         uniform.name = key;
193         uniform.value = values;
194         uniform.num_values = num_values;
195         uniform.location = -1;
196         uniforms_vec3_array.push_back(uniform);
197 }
198
199 void Effect::register_uniform_vec4_array(const std::string &key, const float *values, size_t num_values)
200 {
201         Uniform<float> uniform;
202         uniform.name = key;
203         uniform.value = values;
204         uniform.num_values = num_values;
205         uniform.location = -1;
206         uniforms_vec4_array.push_back(uniform);
207 }
208
209 void Effect::register_uniform_mat3(const std::string &key, const Matrix3d *matrix)
210 {
211         Uniform<Matrix3d> uniform;
212         uniform.name = key;
213         uniform.value = matrix;
214         uniform.num_values = 1;
215         uniform.location = -1;
216         uniforms_mat3.push_back(uniform);
217 }
218
219 }  // namespace movit