Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
scenefx/include/render/fx_renderer/shaders.h (4.9K)
1 #ifndef _FX_SHADERS_H
2 #define _FX_SHADERS_H
3
4 #include <GLES2/gl2.h>
5 #include <stdbool.h>
6 #include <scenefx/types/fx/clipped_region.h>
7 #include "types/fx/clipped_region.h"
8
9 struct fx_renderer;
10
11 GLuint compile_shader(GLuint type, const GLchar *src);
12
13 GLuint link_program(const GLchar *frag_src);
14
15 bool check_gl_ext(const char *exts, const char *ext);
16
17 void load_gl_proc(void *proc_ptr, const char *name);
18
19 enum fx_tex_shader_source {
20 SHADER_SOURCE_TEXTURE_RGBA = 1,
21 SHADER_SOURCE_TEXTURE_RGBX = 2,
22 SHADER_SOURCE_TEXTURE_EXTERNAL = 3,
23 };
24
25 struct shader_corner_radii {
26 GLint top_left;
27 GLint top_right;
28 GLint bottom_left;
29 GLint bottom_right;
30 // The program's shared "corner_shape" uniform (see corner_alpha.frag).
31 // One location per program; radius and clip_radius instances of the same
32 // program resolve to the same location, which is harmless.
33 GLint shape;
34 };
35
36 void uniform_corner_radii_set(const struct shader_corner_radii *uniform,
37 const struct fx_corner_fradii *corners);
38
39 // Renderer-global corner-shape exponent fed to every rounded-corner shader:
40 // 2 (default) = circular arcs, > 2 = superellipse squircle corners.
41 float fx_corner_shape(void);
42
43 struct quad_shader {
44 GLuint program;
45 GLint proj;
46 GLint color;
47 GLint pos_attrib;
48
49 // Only used for the effects shader
50 struct {
51 GLint clip_size;
52 GLint clip_position;
53 struct shader_corner_radii clip_radius;
54 } effects;
55 };
56
57 bool link_quad_program(struct quad_shader *shader, bool clip);
58
59 struct quad_grad_shader {
60 int max_len;
61
62 GLuint program;
63 GLint proj;
64 GLint colors;
65 GLint size;
66 GLint degree;
67 GLint grad_box;
68 GLint pos_attrib;
69 GLint linear;
70 GLint origin;
71 GLint count;
72 GLint blend;
73 };
74
75 bool link_quad_grad_program(struct quad_grad_shader *shader, int max_len);
76
77 struct quad_round_shader {
78 GLuint program;
79 GLint proj;
80 GLint color;
81 GLint pos_attrib;
82 GLint size;
83 GLint position;
84
85 struct shader_corner_radii radius;
86
87 GLint clip_size;
88 GLint clip_position;
89 struct shader_corner_radii clip_radius;
90 GLint fade_inset;
91 GLint fade_mode;
92 };
93
94 bool link_quad_round_program(struct quad_round_shader *shader);
95
96 struct quad_grad_round_shader {
97 GLuint program;
98 GLint proj;
99 GLint color;
100 GLint pos_attrib;
101 GLint size;
102 GLint position;
103
104 GLint colors;
105 GLint grad_size;
106 GLint degree;
107 GLint grad_box;
108 GLint linear;
109 GLint origin;
110 GLint count;
111 GLint blend;
112
113 struct shader_corner_radii radius;
114
115 int max_len;
116 };
117
118 bool link_quad_grad_round_program(struct quad_grad_round_shader *shader, int max_len);
119
120 struct tex_shader {
121 GLuint program;
122 GLint proj;
123 GLint tex_proj;
124 GLint tex;
125 GLint alpha;
126 GLint pos_attrib;
127
128 GLint discard_transparent;
129
130 // Only used for the effects shader
131 struct {
132 GLint size;
133 GLint position;
134 struct shader_corner_radii radius;
135
136 GLint clip_size;
137 GLint clip_position;
138 struct shader_corner_radii clip_radius;
139 } effects;
140 };
141
142 bool link_tex_program(struct tex_shader *shader, enum fx_tex_shader_source source,
143 bool effects);
144
145 struct box_shadow_shader {
146 GLuint program;
147 GLint proj;
148 GLint color;
149 GLint pos_attrib;
150 GLint position;
151 GLint size;
152 GLint blur_sigma;
153 GLint corner_radius;
154
155 GLint clip_position;
156 GLint clip_size;
157 struct shader_corner_radii clip_radius;
158 };
159
160 bool link_box_shadow_program(struct box_shadow_shader *shader);
161
162 struct bevel_shader {
163 GLuint program;
164 GLint proj;
165 GLint color;
166 GLint pos_attrib;
167 GLint position;
168 GLint size;
169 GLint corner_radius;
170 // The shared corner-shape exponent (see corner_alpha.frag) — the rim has
171 // to trace the same superellipse every other corner cut does.
172 GLint corner_shape;
173 GLint thickness;
174 GLint light_dir;
175 GLint light_intensity;
176 GLint shade_intensity;
177 GLint shoulder;
178 GLint focus;
179 GLint focus_color;
180 GLint focus_sharpness;
181 };
182
183 bool link_bevel_program(struct bevel_shader *shader);
184
185 struct frame_shader {
186 GLuint program;
187 GLint proj;
188 GLint color;
189 GLint pos_attrib;
190 GLint position;
191 GLint size;
192 GLint corner_radius;
193 GLint corner_shape;
194 // Thickness at a side's midpoint and at the corner pieces.
195 GLint band;
196 GLint band_min;
197 GLint corner_len;
198 GLint gap;
199 GLint hovered;
200 GLint hover_color;
201 GLint swell_curve;
202 GLint bulge;
203 GLint exclusion;
204 };
205
206 bool link_frame_program(struct frame_shader *shader);
207
208 struct droplet_shader {
209 GLuint program;
210 GLint proj;
211 GLint pos_attrib;
212 GLint tex;
213 GLint tex_size;
214 GLint position;
215 GLint size;
216 GLint attach_r;
217 GLint sheet_r;
218 GLint bow_rise;
219 GLint blend_k;
220 GLint curve;
221 GLint band_px;
222 GLint refr;
223 GLint ghost;
224 };
225
226 bool link_droplet_program(struct droplet_shader *shader);
227
228 struct blur_shader {
229 GLuint program;
230 GLint proj;
231 GLint tex_proj;
232 GLint tex;
233 GLint pos_attrib;
234 GLint radius;
235 GLint halfpixel;
236 };
237
238 bool link_blur1_program(struct blur_shader *shader);
239 bool link_blur2_program(struct blur_shader *shader);
240
241 struct blur_effects_shader {
242 GLuint program;
243 GLint proj;
244 GLint tex_proj;
245 GLint tex;
246 GLint pos_attrib;
247 GLfloat noise;
248 GLfloat brightness;
249 GLfloat contrast;
250 GLfloat saturation;
251 };
252
253 bool link_blur_effects_program(struct blur_effects_shader *shader);
254
255 #endif