-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilter.h
More file actions
179 lines (155 loc) · 4.22 KB
/
filter.h
File metadata and controls
179 lines (155 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/** Copyright (C) 2016, Gavin J Stark. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @file filter.h
* @brief Image filters
*
*/
/*a Wrapper
*/
#ifdef __INC_FILTER
#else
#define __INC_FILTER
/*a Includes
*/
#include "timer.h"
#include "texture.h"
#include "shader.h"
#include <map>
#include <string>
/*a Defines
*/
#define MAX_FILTER_TEXTURES 8
#define MAX_FILTER_PROJECTIONS 2
#define MAX_FILTER_TIMERS 8
typedef enum
{
filter_timer_compile,
filter_timer_execute,
filter_timer_internal_1,
filter_timer_internal_2,
} t_filter_timer;
/*a Types
*/
/*t t_len_string
*/
typedef struct
{
const char *ptr;
int len;
} t_len_string;
/*t t_point_value
*/
typedef struct
{
int x;
int y;
float value;
float vec_x;
float vec_y;
int extra[4];
} t_point_value;
/*t t_exec_context
*/
typedef struct
{
t_texture_ptr textures[16];
t_point_value *points;
int num_points;
int use_ids;
} t_exec_context;
/*t t_filter_texture
*/
typedef struct {
int ec_id;
t_texture_ptr texture;
GLint sampler_id;
} t_filter_texture;
/*t fp_validity
*/
enum {
fp_valid_string=1,
fp_valid_real=2,
fp_valid_integer=4,
fp_valid_gl_id=8,
};
/*t t_filter_parameter
*/
typedef struct
{
int valid_values;
const char *string;
double real;
int integer;
GLint gl_id;
} t_filter_parameter;
/*t c_filter
*/
class c_filter
{
private:
virtual int do_compile(void) {return 0;};
virtual int do_execute(t_exec_context *ec) {return 0;};
std::map <std::string, t_filter_parameter> *parameter_map;
void get_parameter_value(t_filter_parameter *fp);
void set_parameter(t_filter_parameter *fp, double value);
void set_parameter(t_filter_parameter *fp, int value);
void set_parameter(t_filter_parameter *fp, const char *value);
int read_int_list(t_len_string *string, int *ints, int max_ints);
protected:
void set_parameters_from_map(struct t_parameter_def *parameter_defns, void *parameters);
void set_filename(const char *dirname, const char *suffix, t_len_string *filename, char **filter_filename);
void get_shader_defines(char **shader_defines);
int get_shader_uniform_ids(void);
int get_texture_uniform_ids(int num_dest);
int set_texture_uniforms(t_exec_context *ec, int num_dest);
int set_shader_uniforms(void);
public:
c_filter(t_len_string *textures, t_len_string *parameters);
virtual ~c_filter();
int compile(void) {return this->do_compile();};
int execute(t_exec_context *ec) {return this->do_execute(ec);};
int uniform_set(const char *uniform, float value); // used in batch, needs to be replaced with set_parameter
int set_parameter(const char *name, double value);
int set_parameter(const char *name, int value);
int set_parameter(const char *name, const char *value);
int unset_parameter(const char *name);
const char *parse_error;
GLuint filter_pid;
int bind_projection(int n, class c_lens_projection *projection);
int bind_texture(int n, t_texture_ptr texture);
t_texture_ptr bound_texture(t_exec_context *ec, int n);
int num_textures;
t_filter_texture textures[MAX_FILTER_TEXTURES];
int num_projections;
class c_lens_projection *projections[MAX_FILTER_PROJECTIONS];
t_sl_timer timers[MAX_FILTER_TIMERS];
};
/*a External functions
*/
/*f filter_from_string
filter string must be:
<filter type>:<filename>(<options list>)[&<uniform_name>=<float>]
*/
c_filter *
filter_from_string(const char *optarg);
/*a Wrapper
*/
#endif
/*a Editor preferences and notes
mode: c ***
c-basic-offset: 4 ***
c-default-style: (quote ((c-mode . "k&r") (c++-mode . "k&r"))) ***
outline-regexp: "/\\\*a\\\|[\t ]*\/\\\*[b-z][\t ]" ***
*/