Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git
scenefx/include/render/fx_renderer/shaders.h (5.1K)
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 GLint compress_ceil;
131 GLint compress_knee;
132 GLint compress_invert;
133
134 // Only used for the effects shader
135 struct {
136 GLint size;
137 GLint position;
138 struct shader_corner_radii radius;
139
140 GLint clip_size;
141 GLint clip_position;
142 struct shader_corner_radii clip_radius;
143 } effects;
144 };
145
146 bool link_tex_program(struct tex_shader *shader, enum fx_tex_shader_source source,
147 bool effects);
148
149 struct box_shadow_shader {
150 GLuint program;
151 GLint proj;
152 GLint color;
153 GLint pos_attrib;
154 GLint position;
155 GLint size;
156 GLint blur_sigma;
157 GLint corner_radius;
158
159 GLint clip_position;
160 GLint clip_size;
161 struct shader_corner_radii clip_radius;
162 };
163
164 bool link_box_shadow_program(struct box_shadow_shader *shader);
165
166 struct bevel_shader {
167 GLuint program;
168 GLint proj;
169 GLint color;
170 GLint pos_attrib;
171 GLint position;
172 GLint size;
173 GLint corner_radius;
174 // The shared corner-shape exponent (see corner_alpha.frag) — the rim has
175 // to trace the same superellipse every other corner cut does.
176 GLint corner_shape;
177 GLint thickness;
178 GLint light_dir;
179 GLint light_intensity;
180 GLint shade_intensity;
181 GLint shoulder;
182 GLint focus;
183 GLint focus_color;
184 GLint focus_sharpness;
185 };
186
187 bool link_bevel_program(struct bevel_shader *shader);
188
189 struct frame_shader {
190 GLuint program;
191 GLint proj;
192 GLint color;
193 GLint pos_attrib;
194 GLint position;
195 GLint size;
196 GLint corner_radius;
197 GLint corner_shape;
198 // Thickness at a side's midpoint and at the corner pieces.
199 GLint band;
200 GLint band_min;
201 GLint corner_len;
202 GLint gap;
203 GLint hovered;
204 GLint hover_color;
205 GLint swell_curve;
206 GLint bulge;
207 GLint exclusion;
208 GLint buttons;
209 };
210
211 bool link_frame_program(struct frame_shader *shader);
212
213 struct droplet_shader {
214 GLuint program;
215 GLint proj;
216 GLint pos_attrib;
217 GLint tex;
218 GLint tex_size;
219 GLint position;
220 GLint size;
221 GLint attach_r;
222 GLint sheet_r;
223 GLint bow_rise;
224 GLint blend_k;
225 GLint curve;
226 GLint band_px;
227 GLint refr;
228 GLint ghost;
229 GLint compress_ceil;
230 GLint compress_knee;
231 GLint compress_invert;
232 };
233
234 bool link_droplet_program(struct droplet_shader *shader);
235
236 struct blur_shader {
237 GLuint program;
238 GLint proj;
239 GLint tex_proj;
240 GLint tex;
241 GLint pos_attrib;
242 GLint radius;
243 GLint halfpixel;
244 };
245
246 bool link_blur1_program(struct blur_shader *shader);
247 bool link_blur2_program(struct blur_shader *shader);
248
249 struct blur_effects_shader {
250 GLuint program;
251 GLint proj;
252 GLint tex_proj;
253 GLint tex;
254 GLint pos_attrib;
255 GLfloat noise;
256 GLfloat brightness;
257 GLfloat contrast;
258 GLfloat saturation;
259 };
260
261 bool link_blur_effects_program(struct blur_effects_shader *shader);
262
263 #endif