ngl: renderer errors on macOS
Steps to reproduce
- On a macOS machine
- Compile GTK 4.13.6 (or main)
- Run gtk4-demo
Current behavior
The window remains black and a lot of logging is dumped, ending with:
(gtk4-demo:2017): Gsk-CRITICAL **: 11:17:32.325: Failed to load shader program: Compilation failure in shader.
Source Code:
1| #version 410
2| #define N_TEXTURES 16
3| #define N_EXTERNAL_TEXTURES 0
4| #define GSK_VERTEX_SHADER 1
5| #define GSK_VARIATION 0u
6| #define GSK_SHADER_CLIP GSK_GPU_SHADER_CLIP_NONE
7| #ifndef _COMMON_
8| #define _COMMON_
9|
10| void main_clip_none (void);
11| void main_clip_rect (void);
12| void main_clip_rounded (void);
13|
14| #ifndef _ENUMS_
15| #define _ENUMS_
16|
[...]
2371| run (out vec4 color,
2372| out vec2 position)
2373| {
2374| #if 0
2375| vec4 pixel = gsk_texture_straight_alpha (_tex_id, _tex_coord);
2376| #else
2377| vec4 pixel = gsk_texture (_tex_id, _tex_coord);
2378| pixel = color_unpremultiply (pixel);
2379| #endif
2380| pixel = _color_matrix * pixel + _color_offset;
2381| pixel = clamp (pixel, 0.0, 1.0);
2382|
2383| color = color_premultiply (pixel) * rect_coverage (_rect, _pos);
2384| position = _pos;
2385| }
2386|
2387| #endif
2388|
Error Message:
ERROR: 0:1297: Unknown identifier 'binding' in layout
ERROR: 0:1314: Unknown identifier 'binding' in layout
ERROR: 0:1781: Use of undeclared identifier 'push'
ERROR: 0:1919: Use of undeclared identifier 'push'
ERROR: 0:1920: Use of undeclared identifier 'push'
ERROR: 0:1921: Use of undeclared identifier 'push'
ERROR: 0:2151: Use of undeclared identifier 'push'
ERROR: 0:2166: Use of undeclared identifier 'push'
Expected outcome
The renderer should just work, right?
Version information
GTK main branch (29c77254) on macOS 14.3.
Additional information
Full dump of one error
(gtk4-demo:2139): Gsk-CRITICAL **: 11:26:05.304: Failed to load shader program: Compilation failure in shader.
Source Code:
1| #version 410
2| #define N_TEXTURES 16
3| #define N_EXTERNAL_TEXTURES 0
4| #define GSK_VERTEX_SHADER 1
5| #define GSK_VARIATION 0u
6| #define GSK_SHADER_CLIP GSK_GPU_SHADER_CLIP_ROUNDED
7| #ifndef _COMMON_
8| #define _COMMON_
9|
10| void main_clip_none (void);
11| void main_clip_rect (void);
12| void main_clip_rounded (void);
13|
14| #ifndef _ENUMS_
15| #define _ENUMS_
16|
17| #define GSK_GPU_PATTERN_STACK_SIZE 16
18|
19| #define GSK_GPU_SHADER_CLIP_NONE 0u
20| #define GSK_GPU_SHADER_CLIP_RECT 1u
21| #define GSK_GPU_SHADER_CLIP_ROUNDED 2u
22|
23| #define GSK_GPU_PATTERN_DONE 0u
24| #define GSK_GPU_PATTERN_COLOR 1u
25| #define GSK_GPU_PATTERN_OPACITY 2u
26| #define GSK_GPU_PATTERN_TEXTURE 3u
27| #define GSK_GPU_PATTERN_STRAIGHT_ALPHA 4u
28| #define GSK_GPU_PATTERN_COLOR_MATRIX 5u
29| #define GSK_GPU_PATTERN_GLYPHS 6u
30| #define GSK_GPU_PATTERN_LINEAR_GRADIENT 7u
31| #define GSK_GPU_PATTERN_REPEATING_LINEAR_GRADIENT 8u
32| #define GSK_GPU_PATTERN_RADIAL_GRADIENT 9u
33| #define GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT 10u
34| #define GSK_GPU_PATTERN_CONIC_GRADIENT 11u
35| #define GSK_GPU_PATTERN_CLIP 12u
36| #define GSK_GPU_PATTERN_ROUNDED_CLIP 13u
37| #define GSK_GPU_PATTERN_REPEAT_PUSH 14u
38| #define GSK_GPU_PATTERN_POSITION_POP 15u
39| #define GSK_GPU_PATTERN_PUSH_COLOR 16u
40| #define GSK_GPU_PATTERN_POP_CROSS_FADE 17u
41| #define GSK_GPU_PATTERN_POP_MASK_ALPHA 18u
42| #define GSK_GPU_PATTERN_POP_MASK_INVERTED_ALPHA 19u
43| #define GSK_GPU_PATTERN_POP_MASK_LUMINANCE 20u
44| #define GSK_GPU_PATTERN_POP_MASK_INVERTED_LUMINANCE 21u
45| #define GSK_GPU_PATTERN_AFFINE 22u
46| #define GSK_GPU_PATTERN_BLEND_DEFAULT 23u
47| #define GSK_GPU_PATTERN_BLEND_MULTIPLY 24u
48| #define GSK_GPU_PATTERN_BLEND_SCREEN 25u
49| #define GSK_GPU_PATTERN_BLEND_OVERLAY 26u
50| #define GSK_GPU_PATTERN_BLEND_DARKEN 27u
51| #define GSK_GPU_PATTERN_BLEND_LIGHTEN 28u
52| #define GSK_GPU_PATTERN_BLEND_COLOR_DODGE 29u
53| #define GSK_GPU_PATTERN_BLEND_COLOR_BURN 30u
54| #define GSK_GPU_PATTERN_BLEND_HARD_LIGHT 31u
55| #define GSK_GPU_PATTERN_BLEND_SOFT_LIGHT 32u
56| #define GSK_GPU_PATTERN_BLEND_DIFFERENCE 33u
57| #define GSK_GPU_PATTERN_BLEND_EXCLUSION 34u
58| #define GSK_GPU_PATTERN_BLEND_COLOR 35u
59| #define GSK_GPU_PATTERN_BLEND_HUE 36u
60| #define GSK_GPU_PATTERN_BLEND_SATURATION 37u
61| #define GSK_GPU_PATTERN_BLEND_LUMINOSITY 38u
62|
63| #define GSK_MASK_MODE_ALPHA 0u
64| #define GSK_MASK_MODE_INVERTED_ALPHA 1u
65| #define GSK_MASK_MODE_LUMINANCE 2u
66| #define GSK_MASK_MODE_INVERTED_LUMINANCE 3u
67|
68| #define TOP 0u
69| #define RIGHT 1u
70| #define BOTTOM 2u
71| #define LEFT 3u
72|
73| #define TOP_LEFT 0u
74| #define TOP_RIGHT 1u
75| #define BOTTOM_RIGHT 2u
76| #define BOTTOM_LEFT 3u
77|
78| #define SLICE_TOP_LEFT 0u
79| #define SLICE_TOP 1u
80| #define SLICE_TOP_RIGHT 2u
81| #define SLICE_RIGHT 3u
82| #define SLICE_BOTTOM_RIGHT 4u
83| #define SLICE_BOTTOM 5u
84| #define SLICE_BOTTOM_LEFT 6u
85| #define SLICE_LEFT 7u
86|
87| #endif
88|
89| #ifdef VULKAN
90| #ifdef HAVE_VULKAN_1_2
91| #extension GL_EXT_nonuniform_qualifier : enable
92| #endif
93|
94|
95| layout(push_constant) uniform PushConstants {
96| mat4 mvp;
97| mat3x4 clip;
98| vec2 scale;
99| } push;
100|
101| layout(constant_id=0) const uint GSK_SHADER_CLIP = GSK_GPU_SHADER_CLIP_NONE;
102| layout(constant_id=1) const uint GSK_N_IMMUTABLE_SAMPLERS = 32;
103| layout(constant_id=2) const uint GSK_N_SAMPLERS = 32;
104| layout(constant_id=3) const uint GSK_N_BUFFERS = 32;
105| layout(constant_id=4) const uint GSK_VARIATION = 0;
106|
107| #define GSK_GLOBAL_MVP push.mvp
108| #define GSK_GLOBAL_CLIP push.clip
109| #define GSK_GLOBAL_CLIP_RECT push.clip[0]
110| #define GSK_GLOBAL_SCALE push.scale
111|
112| #define GSK_VERTEX_INDEX gl_VertexIndex
113|
114| #ifdef GSK_VERTEX_SHADER
115| #define IN(_loc) layout(location = _loc) in
116| #define PASS(_loc) layout(location = _loc) out
117| #define PASS_FLAT(_loc) layout(location = _loc) flat out
118| #endif
119|
120|
121| #ifdef GSK_FRAGMENT_SHADER
122| #define PASS(_loc) layout(location = _loc) in
123| #define PASS_FLAT(_loc) layout(location = _loc) flat in
124|
125| layout(set = 0, binding = 0) uniform sampler2D immutable_textures[GSK_N_IMMUTABLE_SAMPLERS];
126| layout(set = 0, binding = 1) uniform sampler2D textures[GSK_N_SAMPLERS];
127| layout(set = 1, binding = 0) readonly buffer FloatBuffers {
128| float floats[];
129| } buffers[GSK_N_BUFFERS];
130|
131| layout(location = 0) out vec4 out_color;
132|
133| vec4
134| gsk_texture (uint id,
135| vec2 pos)
136| {
137| if ((id & 1) != 0)
138| {
139| id >>= 1;
140| if (id < 16)
141| {
142| if (id < 8)
143| {
144| if (id < 4)
145| {
146| if (id < 2)
147| {
148| if (id < 1)
149| return texture (immutable_textures[0], pos);
150| else if (GSK_N_IMMUTABLE_SAMPLERS > 1)
151| return texture (immutable_textures[1], pos);
152| }
153| else if (GSK_N_IMMUTABLE_SAMPLERS > 2)
154| {
155| if (id < 3)
156| return texture (immutable_textures[2], pos);
157| else if (GSK_N_IMMUTABLE_SAMPLERS > 3)
158| return texture (immutable_textures[3], pos);
159| }
160| }
161| else if (GSK_N_IMMUTABLE_SAMPLERS > 4)
162| {
163| if (id < 6)
164| {
165| if (id < 5)
166| return texture (immutable_textures[4], pos);
167| else if (GSK_N_IMMUTABLE_SAMPLERS > 5)
168| return texture (immutable_textures[5], pos);
169| }
170| else if (GSK_N_IMMUTABLE_SAMPLERS > 6)
171| {
172| if (id < 7)
173| return texture (immutable_textures[6], pos);
174| else if (GSK_N_IMMUTABLE_SAMPLERS > 7)
175| return texture (immutable_textures[7], pos);
176| }
177| }
178| }
179| else if (GSK_N_IMMUTABLE_SAMPLERS > 8)
180| {
181| if (id < 12)
182| {
183| if (id < 10)
184| {
185| if (id < 9)
186| return texture (immutable_textures[8], pos);
187| else if (GSK_N_IMMUTABLE_SAMPLERS > 9)
188| return texture (immutable_textures[9], pos);
189| }
190| else if (GSK_N_IMMUTABLE_SAMPLERS > 10)
191| {
192| if (id < 11)
193| return texture (immutable_textures[10], pos);
194| else if (GSK_N_IMMUTABLE_SAMPLERS > 11)
195| return texture (immutable_textures[11], pos);
196| }
197| }
198| else if (GSK_N_IMMUTABLE_SAMPLERS > 12)
199| {
200| if (id < 14)
201| {
202| if (id < 13)
203| return texture (immutable_textures[12], pos);
204| else if (GSK_N_IMMUTABLE_SAMPLERS > 13)
205| return texture (immutable_textures[13], pos);
206| }
207| else if (GSK_N_IMMUTABLE_SAMPLERS > 14)
208| {
209| if (id < 15)
210| return texture (immutable_textures[14], pos);
211| else if (GSK_N_IMMUTABLE_SAMPLERS > 15)
212| return texture (immutable_textures[15], pos);
213| }
214| }
215| }
216| }
217| else if (GSK_N_IMMUTABLE_SAMPLERS > 16)
218| {
219| if (id < 24)
220| {
221| if (id < 20)
222| {
223| if (id < 18)
224| {
225| if (id < 17)
226| return texture (immutable_textures[16], pos);
227| else if (GSK_N_IMMUTABLE_SAMPLERS > 17)
228| return texture (immutable_textures[17], pos);
229| }
230| else if (GSK_N_IMMUTABLE_SAMPLERS > 18)
231| {
232| if (id < 19)
233| return texture (immutable_textures[18], pos);
234| else if (GSK_N_IMMUTABLE_SAMPLERS > 19)
235| return texture (immutable_textures[19], pos);
236| }
237| }
238| else if (GSK_N_IMMUTABLE_SAMPLERS > 20)
239| {
240| if (id < 22)
241| {
242| if (id < 21)
243| return texture (immutable_textures[20], pos);
244| else if (GSK_N_IMMUTABLE_SAMPLERS > 21)
245| return texture (immutable_textures[21], pos);
246| }
247| else if (GSK_N_IMMUTABLE_SAMPLERS > 22)
248| {
249| if (id < 23)
250| return texture (immutable_textures[22], pos);
251| else if (GSK_N_IMMUTABLE_SAMPLERS > 23)
252| return texture (immutable_textures[23], pos);
253| }
254| }
255| }
256| else if (GSK_N_IMMUTABLE_SAMPLERS > 24)
257| {
258| if (id < 28)
259| {
260| if (id < 26)
261| {
262| if (id < 25)
263| return texture (immutable_textures[24], pos);
264| else if (GSK_N_IMMUTABLE_SAMPLERS > 25)
265| return texture (immutable_textures[25], pos);
266| }
267| else if (GSK_N_IMMUTABLE_SAMPLERS > 26)
268| {
269| if (id < 27)
270| return texture (immutable_textures[26], pos);
271| else if (GSK_N_IMMUTABLE_SAMPLERS > 27)
272| return texture (immutable_textures[27], pos);
273| }
274| }
275| else if (GSK_N_IMMUTABLE_SAMPLERS > 28)
276| {
277| if (id < 30)
278| {
279| if (id < 29)
280| return texture (immutable_textures[28], pos);
281| else if (GSK_N_IMMUTABLE_SAMPLERS > 29)
282| return texture (immutable_textures[29], pos);
283| }
284| else if (GSK_N_IMMUTABLE_SAMPLERS > 30)
285| {
286| if (id < 31)
287| return texture (immutable_textures[30], pos);
288| else if (GSK_N_IMMUTABLE_SAMPLERS > 31)
289| return texture (immutable_textures[31], pos);
290| }
291| }
292| }
293| }
294| }
295| else
296| {
297| id >>= 1;
298| #ifdef HAVE_VULKAN_1_2
299| return texture (textures[nonuniformEXT (id)], pos);
300| #else
301| if (id < 16)
302| {
303| if (id < 8)
304| {
305| if (id < 4)
306| {
307| if (id < 2)
308| {
309| if (id < 1)
310| return texture (textures[0], pos);
311| else if (GSK_N_SAMPLERS > 1)
312| return texture (textures[1], pos);
313| }
314| else if (GSK_N_SAMPLERS > 2)
315| {
316| if (id < 3)
317| return texture (textures[2], pos);
318| else if (GSK_N_SAMPLERS > 3)
319| return texture (textures[3], pos);
320| }
321| }
322| else if (GSK_N_SAMPLERS > 4)
323| {
324| if (id < 6)
325| {
326| if (id < 5)
327| return texture (textures[4], pos);
328| else if (GSK_N_SAMPLERS > 5)
329| return texture (textures[5], pos);
330| }
331| else if (GSK_N_SAMPLERS > 6)
332| {
333| if (id < 7)
334| return texture (textures[6], pos);
335| else if (GSK_N_SAMPLERS > 7)
336| return texture (textures[7], pos);
337| }
338| }
339| }
340| else if (GSK_N_SAMPLERS > 8)
341| {
342| if (id < 12)
343| {
344| if (id < 10)
345| {
346| if (id < 9)
347| return texture (textures[8], pos);
348| else if (GSK_N_SAMPLERS > 9)
349| return texture (textures[9], pos);
350| }
351| else if (GSK_N_SAMPLERS > 10)
352| {
353| if (id < 11)
354| return texture (textures[10], pos);
355| else if (GSK_N_SAMPLERS > 11)
356| return texture (textures[11], pos);
357| }
358| }
359| else if (GSK_N_SAMPLERS > 12)
360| {
361| if (id < 14)
362| {
363| if (id < 13)
364| return texture (textures[12], pos);
365| else if (GSK_N_SAMPLERS > 13)
366| return texture (textures[13], pos);
367| }
368| else if (GSK_N_SAMPLERS > 14)
369| {
370| if (id < 15)
371| return texture (textures[14], pos);
372| else if (GSK_N_SAMPLERS > 15)
373| return texture (textures[15], pos);
374| }
375| }
376| }
377| }
378| else if (GSK_N_SAMPLERS > 16)
379| {
380| if (id < 24)
381| {
382| if (id < 20)
383| {
384| if (id < 18)
385| {
386| if (id < 17)
387| return texture (textures[16], pos);
388| else if (GSK_N_SAMPLERS > 17)
389| return texture (textures[17], pos);
390| }
391| else if (GSK_N_SAMPLERS > 18)
392| {
393| if (id < 19)
394| return texture (textures[18], pos);
395| else if (GSK_N_SAMPLERS > 19)
396| return texture (textures[19], pos);
397| }
398| }
399| else if (GSK_N_SAMPLERS > 20)
400| {
401| if (id < 22)
402| {
403| if (id < 21)
404| return texture (textures[20], pos);
405| else if (GSK_N_SAMPLERS > 21)
406| return texture (textures[21], pos);
407| }
408| else if (GSK_N_SAMPLERS > 22)
409| {
410| if (id < 23)
411| return texture (textures[22], pos);
412| else if (GSK_N_SAMPLERS > 23)
413| return texture (textures[23], pos);
414| }
415| }
416| }
417| else if (GSK_N_SAMPLERS > 24)
418| {
419| if (id < 28)
420| {
421| if (id < 26)
422| {
423| if (id < 25)
424| return texture (textures[24], pos);
425| else if (GSK_N_SAMPLERS > 25)
426| return texture (textures[25], pos);
427| }
428| else if (GSK_N_SAMPLERS > 26)
429| {
430| if (id < 27)
431| return texture (textures[26], pos);
432| else if (GSK_N_SAMPLERS > 27)
433| return texture (textures[27], pos);
434| }
435| }
436| else if (GSK_N_SAMPLERS > 28)
437| {
438| if (id < 30)
439| {
440| if (id < 29)
441| return texture (textures[28], pos);
442| else if (GSK_N_SAMPLERS > 29)
443| return texture (textures[29], pos);
444| }
445| else if (GSK_N_SAMPLERS > 30)
446| {
447| if (id < 31)
448| return texture (textures[30], pos);
449| else if (GSK_N_SAMPLERS > 31)
450| return texture (textures[31], pos);
451| }
452| }
453| }
454| }
455| #endif
456| }
457| return vec4 (1.0, 0.0, 0.8, 1.0);
458| }
459|
460| ivec2
461| gsk_texture_size (uint id,
462| int lod)
463| {
464| if ((id & 1) != 0)
465| {
466| id >>= 1;
467| if (id < 16)
468| {
469| if (id < 8)
470| {
471| if (id < 4)
472| {
473| if (id < 2)
474| {
475| if (id < 1)
476| return textureSize (immutable_textures[0], lod);
477| else if (GSK_N_IMMUTABLE_SAMPLERS > 1)
478| return textureSize (immutable_textures[1], lod);
479| }
480| else if (GSK_N_IMMUTABLE_SAMPLERS > 2)
481| {
482| if (id < 3)
483| return textureSize (immutable_textures[2], lod);
484| else if (GSK_N_IMMUTABLE_SAMPLERS > 3)
485| return textureSize (immutable_textures[3], lod);
486| }
487| }
488| else if (GSK_N_IMMUTABLE_SAMPLERS > 4)
489| {
490| if (id < 6)
491| {
492| if (id < 5)
493| return textureSize (immutable_textures[4], lod);
494| else if (GSK_N_IMMUTABLE_SAMPLERS > 5)
495| return textureSize (immutable_textures[5], lod);
496| }
497| else if (GSK_N_IMMUTABLE_SAMPLERS > 6)
498| {
499| if (id < 7)
500| return textureSize (immutable_textures[6], lod);
501| else if (GSK_N_IMMUTABLE_SAMPLERS > 7)
502| return textureSize (immutable_textures[7], lod);
503| }
504| }
505| }
506| else if (GSK_N_IMMUTABLE_SAMPLERS > 8)
507| {
508| if (id < 12)
509| {
510| if (id < 10)
511| {
512| if (id < 9)
513| return textureSize (immutable_textures[8], lod);
514| else if (GSK_N_IMMUTABLE_SAMPLERS > 9)
515| return textureSize (immutable_textures[9], lod);
516| }
517| else if (GSK_N_IMMUTABLE_SAMPLERS > 10)
518| {
519| if (id < 11)
520| return textureSize (immutable_textures[10], lod);
521| else if (GSK_N_IMMUTABLE_SAMPLERS > 11)
522| return textureSize (immutable_textures[11], lod);
523| }
524| }
525| else if (GSK_N_IMMUTABLE_SAMPLERS > 12)
526| {
527| if (id < 14)
528| {
529| if (id < 13)
530| return textureSize (immutable_textures[12], lod);
531| else if (GSK_N_IMMUTABLE_SAMPLERS > 13)
532| return textureSize (immutable_textures[13], lod);
533| }
534| else if (GSK_N_IMMUTABLE_SAMPLERS > 14)
535| {
536| if (id < 15)
537| return textureSize (immutable_textures[14], lod);
538| else if (GSK_N_IMMUTABLE_SAMPLERS > 15)
539| return textureSize (immutable_textures[15], lod);
540| }
541| }
542| }
543| }
544| else if (GSK_N_IMMUTABLE_SAMPLERS > 16)
545| {
546| if (id < 24)
547| {
548| if (id < 20)
549| {
550| if (id < 18)
551| {
552| if (id < 17)
553| return textureSize (immutable_textures[16], lod);
554| else if (GSK_N_IMMUTABLE_SAMPLERS > 17)
555| return textureSize (immutable_textures[17], lod);
556| }
557| else if (GSK_N_IMMUTABLE_SAMPLERS > 18)
558| {
559| if (id < 19)
560| return textureSize (immutable_textures[18], lod);
561| else if (GSK_N_IMMUTABLE_SAMPLERS > 19)
562| return textureSize (immutable_textures[19], lod);
563| }
564| }
565| else if (GSK_N_IMMUTABLE_SAMPLERS > 20)
566| {
567| if (id < 22)
568| {
569| if (id < 21)
570| return textureSize (immutable_textures[20], lod);
571| else if (GSK_N_IMMUTABLE_SAMPLERS > 21)
572| return textureSize (immutable_textures[21], lod);
573| }
574| else if (GSK_N_IMMUTABLE_SAMPLERS > 22)
575| {
576| if (id < 23)
577| return textureSize (immutable_textures[22], lod);
578| else if (GSK_N_IMMUTABLE_SAMPLERS > 23)
579| return textureSize (immutable_textures[23], lod);
580| }
581| }
582| }
583| else if (GSK_N_IMMUTABLE_SAMPLERS > 24)
584| {
585| if (id < 28)
586| {
587| if (id < 26)
588| {
589| if (id < 25)
590| return textureSize (immutable_textures[24], lod);
591| else if (GSK_N_IMMUTABLE_SAMPLERS > 25)
592| return textureSize (immutable_textures[25], lod);
593| }
594| else if (GSK_N_IMMUTABLE_SAMPLERS > 26)
595| {
596| if (id < 27)
597| return textureSize (immutable_textures[26], lod);
598| else if (GSK_N_IMMUTABLE_SAMPLERS > 27)
599| return textureSize (immutable_textures[27], lod);
600| }
601| }
602| else if (GSK_N_IMMUTABLE_SAMPLERS > 28)
603| {
604| if (id < 30)
605| {
606| if (id < 29)
607| return textureSize (immutable_textures[28], lod);
608| else if (GSK_N_IMMUTABLE_SAMPLERS > 29)
609| return textureSize (immutable_textures[29], lod);
610| }
611| else if (GSK_N_IMMUTABLE_SAMPLERS > 30)
612| {
613| if (id < 31)
614| return textureSize (immutable_textures[30], lod);
615| else if (GSK_N_IMMUTABLE_SAMPLERS > 31)
616| return textureSize (immutable_textures[31], lod);
617| }
618| }
619| }
620| }
621| }
622| else
623| {
624| id >>= 1;
625| #ifdef HAVE_VULKAN_1_2
626| return textureSize (textures[nonuniformEXT (id)], lod);
627| #else
628| if (id < 16)
629| {
630| if (id < 8)
631| {
632| if (id < 4)
633| {
634| if (id < 2)
635| {
636| if (id < 1)
637| return textureSize (textures[0], lod);
638| else if (GSK_N_SAMPLERS > 1)
639| return textureSize (textures[1], lod);
640| }
641| else if (GSK_N_SAMPLERS > 2)
642| {
643| if (id < 3)
644| return textureSize (textures[2], lod);
645| else if (GSK_N_SAMPLERS > 3)
646| return textureSize (textures[3], lod);
647| }
648| }
649| else if (GSK_N_SAMPLERS > 4)
650| {
651| if (id < 6)
652| {
653| if (id < 5)
654| return textureSize (textures[4], lod);
655| else if (GSK_N_SAMPLERS > 5)
656| return textureSize (textures[5], lod);
657| }
658| else if (GSK_N_SAMPLERS > 6)
659| {
660| if (id < 7)
661| return textureSize (textures[6], lod);
662| else if (GSK_N_SAMPLERS > 7)
663| return textureSize (textures[7], lod);
664| }
665| }
666| }
667| else if (GSK_N_SAMPLERS > 8)
668| {
669| if (id < 12)
670| {
671| if (id < 10)
672| {
673| if (id < 9)
674| return textureSize (textures[8], lod);
675| else if (GSK_N_SAMPLERS > 9)
676| return textureSize (textures[9], lod);
677| }
678| else if (GSK_N_SAMPLERS > 10)
679| {
680| if (id < 11)
681| return textureSize (textures[10], lod);
682| else if (GSK_N_SAMPLERS > 11)
683| return textureSize (textures[11], lod);
684| }
685| }
686| else if (GSK_N_SAMPLERS > 12)
687| {
688| if (id < 14)
689| {
690| if (id < 13)
691| return textureSize (textures[12], lod);
692| else if (GSK_N_SAMPLERS > 13)
693| return textureSize (textures[13], lod);
694| }
695| else if (GSK_N_SAMPLERS > 14)
696| {
697| if (id < 15)
698| return textureSize (textures[14], lod);
699| else if (GSK_N_SAMPLERS > 15)
700| return textureSize (textures[15], lod);
701| }
702| }
703| }
704| }
705| else if (GSK_N_SAMPLERS > 16)
706| {
707| if (id < 24)
708| {
709| if (id < 20)
710| {
711| if (id < 18)
712| {
713| if (id < 17)
714| return textureSize (textures[16], lod);
715| else if (GSK_N_SAMPLERS > 17)
716| return textureSize (textures[17], lod);
717| }
718| else if (GSK_N_SAMPLERS > 18)
719| {
720| if (id < 19)
721| return textureSize (textures[18], lod);
722| else if (GSK_N_SAMPLERS > 19)
723| return textureSize (textures[19], lod);
724| }
725| }
726| else if (GSK_N_SAMPLERS > 20)
727| {
728| if (id < 22)
729| {
730| if (id < 21)
731| return textureSize (textures[20], lod);
732| else if (GSK_N_SAMPLERS > 21)
733| return textureSize (textures[21], lod);
734| }
735| else if (GSK_N_SAMPLERS > 22)
736| {
737| if (id < 23)
738| return textureSize (textures[22], lod);
739| else if (GSK_N_SAMPLERS > 23)
740| return textureSize (textures[23], lod);
741| }
742| }
743| }
744| else if (GSK_N_SAMPLERS > 24)
745| {
746| if (id < 28)
747| {
748| if (id < 26)
749| {
750| if (id < 25)
751| return textureSize (textures[24], lod);
752| else if (GSK_N_SAMPLERS > 25)
753| return textureSize (textures[25], lod);
754| }
755| else if (GSK_N_SAMPLERS > 26)
756| {
757| if (id < 27)
758| return textureSize (textures[26], lod);
759| else if (GSK_N_SAMPLERS > 27)
760| return textureSize (textures[27], lod);
761| }
762| }
763| else if (GSK_N_SAMPLERS > 28)
764| {
765| if (id < 30)
766| {
767| if (id < 29)
768| return textureSize (textures[28], lod);
769| else if (GSK_N_SAMPLERS > 29)
770| return textureSize (textures[29], lod);
771| }
772| else if (GSK_N_SAMPLERS > 30)
773| {
774| if (id < 31)
775| return textureSize (textures[30], lod);
776| else if (GSK_N_SAMPLERS > 31)
777| return textureSize (textures[31], lod);
778| }
779| }
780| }
781| }
782| #endif
783| }
784| return ivec2 (1, 1);
785| }
786|
787| vec4
788| gsk_texel_fetch (uint id,
789| ivec2 pos,
790| int lod)
791| {
792| if ((id & 1) != 0)
793| {
794| id >>= 1;
795| if (id < 16)
796| {
797| if (id < 8)
798| {
799| if (id < 4)
800| {
801| if (id < 2)
802| {
803| if (id < 1)
804| return texelFetch (immutable_textures[0], pos, lod);
805| else if (GSK_N_IMMUTABLE_SAMPLERS > 1)
806| return texelFetch (immutable_textures[1], pos, lod);
807| }
808| else if (GSK_N_IMMUTABLE_SAMPLERS > 2)
809| {
810| if (id < 3)
811| return texelFetch (immutable_textures[2], pos, lod);
812| else if (GSK_N_IMMUTABLE_SAMPLERS > 3)
813| return texelFetch (immutable_textures[3], pos, lod);
814| }
815| }
816| else if (GSK_N_IMMUTABLE_SAMPLERS > 4)
817| {
818| if (id < 6)
819| {
820| if (id < 5)
821| return texelFetch (immutable_textures[4], pos, lod);
822| else if (GSK_N_IMMUTABLE_SAMPLERS > 5)
823| return texelFetch (immutable_textures[5], pos, lod);
824| }
825| else if (GSK_N_IMMUTABLE_SAMPLERS > 6)
826| {
827| if (id < 7)
828| return texelFetch (immutable_textures[6], pos, lod);
829| else if (GSK_N_IMMUTABLE_SAMPLERS > 7)
830| return texelFetch (immutable_textures[7], pos, lod);
831| }
832| }
833| }
834| else if (GSK_N_IMMUTABLE_SAMPLERS > 8)
835| {
836| if (id < 12)
837| {
838| if (id < 10)
839| {
840| if (id < 9)
841| return texelFetch (immutable_textures[8], pos, lod);
842| else if (GSK_N_IMMUTABLE_SAMPLERS > 9)
843| return texelFetch (immutable_textures[9], pos, lod);
844| }
845| else if (GSK_N_IMMUTABLE_SAMPLERS > 10)
846| {
847| if (id < 11)
848| return texelFetch (immutable_textures[10], pos, lod);
849| else if (GSK_N_IMMUTABLE_SAMPLERS > 11)
850| return texelFetch (immutable_textures[11], pos, lod);
851| }
852| }
853| else if (GSK_N_IMMUTABLE_SAMPLERS > 12)
854| {
855| if (id < 14)
856| {
857| if (id < 13)
858| return texelFetch (immutable_textures[12], pos, lod);
859| else if (GSK_N_IMMUTABLE_SAMPLERS > 13)
860| return texelFetch (immutable_textures[13], pos, lod);
861| }
862| else if (GSK_N_IMMUTABLE_SAMPLERS > 14)
863| {
864| if (id < 15)
865| return texelFetch (immutable_textures[14], pos, lod);
866| else if (GSK_N_IMMUTABLE_SAMPLERS > 15)
867| return texelFetch (immutable_textures[15], pos, lod);
868| }
869| }
870| }
871| }
872| else if (GSK_N_IMMUTABLE_SAMPLERS > 16)
873| {
874| if (id < 24)
875| {
876| if (id < 20)
877| {
878| if (id < 18)
879| {
880| if (id < 17)
881| return texelFetch (immutable_textures[16], pos, lod);
882| else if (GSK_N_IMMUTABLE_SAMPLERS > 17)
883| return texelFetch (immutable_textures[17], pos, lod);
884| }
885| else if (GSK_N_IMMUTABLE_SAMPLERS > 18)
886| {
887| if (id < 19)
888| return texelFetch (immutable_textures[18], pos, lod);
889| else if (GSK_N_IMMUTABLE_SAMPLERS > 19)
890| return texelFetch (immutable_textures[19], pos, lod);
891| }
892| }
893| else if (GSK_N_IMMUTABLE_SAMPLERS > 20)
894| {
895| if (id < 22)
896| {
897| if (id < 21)
898| return texelFetch (immutable_textures[20], pos, lod);
899| else if (GSK_N_IMMUTABLE_SAMPLERS > 21)
900| return texelFetch (immutable_textures[21], pos, lod);
901| }
902| else if (GSK_N_IMMUTABLE_SAMPLERS > 22)
903| {
904| if (id < 23)
905| return texelFetch (immutable_textures[22], pos, lod);
906| else if (GSK_N_IMMUTABLE_SAMPLERS > 23)
907| return texelFetch (immutable_textures[23], pos, lod);
908| }
909| }
910| }
911| else if (GSK_N_IMMUTABLE_SAMPLERS > 24)
912| {
913| if (id < 28)
914| {
915| if (id < 26)
916| {
917| if (id < 25)
918| return texelFetch (immutable_textures[24], pos, lod);
919| else if (GSK_N_IMMUTABLE_SAMPLERS > 25)
920| return texelFetch (immutable_textures[25], pos, lod);
921| }
922| else if (GSK_N_IMMUTABLE_SAMPLERS > 26)
923| {
924| if (id < 27)
925| return texelFetch (immutable_textures[26], pos, lod);
926| else if (GSK_N_IMMUTABLE_SAMPLERS > 27)
927| return texelFetch (immutable_textures[27], pos, lod);
928| }
929| }
930| else if (GSK_N_IMMUTABLE_SAMPLERS > 28)
931| {
932| if (id < 30)
933| {
934| if (id < 29)
935| return texelFetch (immutable_textures[28], pos, lod);
936| else if (GSK_N_IMMUTABLE_SAMPLERS > 29)
937| return texelFetch (immutable_textures[29], pos, lod);
938| }
939| else if (GSK_N_IMMUTABLE_SAMPLERS > 30)
940| {
941| if (id < 31)
942| return texelFetch (immutable_textures[30], pos, lod);
943| else if (GSK_N_IMMUTABLE_SAMPLERS > 31)
944| return texelFetch (immutable_textures[31], pos, lod);
945| }
946| }
947| }
948| }
949| }
950| else
951| {
952| id >>= 1;
953| #ifdef HAVE_VULKAN_1_2
954| return texelFetch (textures[nonuniformEXT (id)], pos, lod);
955| #else
956| if (id < 16)
957| {
958| if (id < 8)
959| {
960| if (id < 4)
961| {
962| if (id < 2)
963| {
964| if (id < 1)
965| return texelFetch (textures[0], pos, lod);
966| else if (GSK_N_SAMPLERS > 1)
967| return texelFetch (textures[1], pos, lod);
968| }
969| else if (GSK_N_SAMPLERS > 2)
970| {
971| if (id < 3)
972| return texelFetch (textures[2], pos, lod);
973| else if (GSK_N_SAMPLERS > 3)
974| return texelFetch (textures[3], pos, lod);
975| }
976| }
977| else if (GSK_N_SAMPLERS > 4)
978| {
979| if (id < 6)
980| {
981| if (id < 5)
982| return texelFetch (textures[4], pos, lod);
983| else if (GSK_N_SAMPLERS > 5)
984| return texelFetch (textures[5], pos, lod);
985| }
986| else if (GSK_N_SAMPLERS > 6)
987| {
988| if (id < 7)
989| return texelFetch (textures[6], pos, lod);
990| else if (GSK_N_SAMPLERS > 7)
991| return texelFetch (textures[7], pos, lod);
992| }
993| }
994| }
995| else if (GSK_N_SAMPLERS > 8)
996| {
997| if (id < 12)
998| {
999| if (id < 10)
1000| {
1001| if (id < 9)
1002| return texelFetch (textures[8], pos, lod);
1003| else if (GSK_N_SAMPLERS > 9)
1004| return texelFetch (textures[9], pos, lod);
1005| }
1006| else if (GSK_N_SAMPLERS > 10)
1007| {
1008| if (id < 11)
1009| return texelFetch (textures[10], pos, lod);
1010| else if (GSK_N_SAMPLERS > 11)
1011| return texelFetch (textures[11], pos, lod);
1012| }
1013| }
1014| else if (GSK_N_SAMPLERS > 12)
1015| {
1016| if (id < 14)
1017| {
1018| if (id < 13)
1019| return texelFetch (textures[12], pos, lod);
1020| else if (GSK_N_SAMPLERS > 13)
1021| return texelFetch (textures[13], pos, lod);
1022| }
1023| else if (GSK_N_SAMPLERS > 14)
1024| {
1025| if (id < 15)
1026| return texelFetch (textures[14], pos, lod);
1027| else if (GSK_N_SAMPLERS > 15)
1028| return texelFetch (textures[15], pos, lod);
1029| }
1030| }
1031| }
1032| }
1033| else if (GSK_N_SAMPLERS > 16)
1034| {
1035| if (id < 24)
1036| {
1037| if (id < 20)
1038| {
1039| if (id < 18)
1040| {
1041| if (id < 17)
1042| return texelFetch (textures[16], pos, lod);
1043| else if (GSK_N_SAMPLERS > 17)
1044| return texelFetch (textures[17], pos, lod);
1045| }
1046| else if (GSK_N_SAMPLERS > 18)
1047| {
1048| if (id < 19)
1049| return texelFetch (textures[18], pos, lod);
1050| else if (GSK_N_SAMPLERS > 19)
1051| return texelFetch (textures[19], pos, lod);
1052| }
1053| }
1054| else if (GSK_N_SAMPLERS > 20)
1055| {
1056| if (id < 22)
1057| {
1058| if (id < 21)
1059| return texelFetch (textures[20], pos, lod);
1060| else if (GSK_N_SAMPLERS > 21)
1061| return texelFetch (textures[21], pos, lod);
1062| }
1063| else if (GSK_N_SAMPLERS > 22)
1064| {
1065| if (id < 23)
1066| return texelFetch (textures[22], pos, lod);
1067| else if (GSK_N_SAMPLERS > 23)
1068| return texelFetch (textures[23], pos, lod);
1069| }
1070| }
1071| }
1072| else if (GSK_N_SAMPLERS > 24)
1073| {
1074| if (id < 28)
1075| {
1076| if (id < 26)
1077| {
1078| if (id < 25)
1079| return texelFetch (textures[24], pos, lod);
1080| else if (GSK_N_SAMPLERS > 25)
1081| return texelFetch (textures[25], pos, lod);
1082| }
1083| else if (GSK_N_SAMPLERS > 26)
1084| {
1085| if (id < 27)
1086| return texelFetch (textures[26], pos, lod);
1087| else if (GSK_N_SAMPLERS > 27)
1088| return texelFetch (textures[27], pos, lod);
1089| }
1090| }
1091| else if (GSK_N_SAMPLERS > 28)
1092| {
1093| if (id < 30)
1094| {
1095| if (id < 29)
1096| return texelFetch (textures[28], pos, lod);
1097| else if (GSK_N_SAMPLERS > 29)
1098| return texelFetch (textures[29], pos, lod);
1099| }
1100| else if (GSK_N_SAMPLERS > 30)
1101| {
1102| if (id < 31)
1103| return texelFetch (textures[30], pos, lod);
1104| else if (GSK_N_SAMPLERS > 31)
1105| return texelFetch (textures[31], pos, lod);
1106| }
1107| }
1108| }
1109| }
1110| #endif
1111| }
1112| return vec4 (1.0, 0.0, 0.8, 1.0);
1113| }
1114|
1115| #ifdef HAVE_VULKAN_1_2
1116| #define gsk_get_buffer(id) buffers[nonuniformEXT (id)]
1117| #define gsk_get_float(id) gsk_get_buffer(id >> 22).floats[id & 0x3FFFFF]
1118| #else
1119| float
1120| gsk_get_float (uint id)
1121| {
1122| uint buffer_id = id >> 22;
1123| uint float_id = id & 0x3FFFFF;
1124| if (buffer_id < 16)
1125| {
1126| if (buffer_id < 8)
1127| {
1128| if (buffer_id < 4)
1129| {
1130| if (buffer_id < 2)
1131| {
1132| if (buffer_id < 1)
1133| return buffers[0].floats[float_id];
1134| else if (GSK_N_BUFFERS > 1)
1135| return buffers[1].floats[float_id];
1136| }
1137| else if (GSK_N_BUFFERS > 2)
1138| {
1139| if (buffer_id < 3)
1140| return buffers[2].floats[float_id];
1141| else if (GSK_N_BUFFERS > 3)
1142| return buffers[3].floats[float_id];
1143| }
1144| }
1145| else if (GSK_N_BUFFERS > 4)
1146| {
1147| if (buffer_id < 6)
1148| {
1149| if (buffer_id < 5)
1150| return buffers[4].floats[float_id];
1151| else if (GSK_N_BUFFERS > 5)
1152| return buffers[5].floats[float_id];
1153| }
1154| else if (GSK_N_BUFFERS > 6)
1155| {
1156| if (buffer_id < 7)
1157| return buffers[6].floats[float_id];
1158| else if (GSK_N_BUFFERS > 7)
1159| return buffers[7].floats[float_id];
1160| }
1161| }
1162| }
1163| else if (GSK_N_BUFFERS > 8)
1164| {
1165| if (buffer_id < 12)
1166| {
1167| if (buffer_id < 10)
1168| {
1169| if (buffer_id < 9)
1170| return buffers[8].floats[float_id];
1171| else if (GSK_N_BUFFERS > 9)
1172| return buffers[9].floats[float_id];
1173| }
1174| else if (GSK_N_BUFFERS > 10)
1175| {
1176| if (buffer_id < 11)
1177| return buffers[10].floats[float_id];
1178| else if (GSK_N_BUFFERS > 11)
1179| return buffers[11].floats[float_id];
1180| }
1181| }
1182| else if (GSK_N_BUFFERS > 12)
1183| {
1184| if (buffer_id < 14)
1185| {
1186| if (buffer_id < 13)
1187| return buffers[12].floats[float_id];
1188| else if (GSK_N_BUFFERS > 13)
1189| return buffers[13].floats[float_id];
1190| }
1191| else if (GSK_N_BUFFERS > 14)
1192| {
1193| if (buffer_id < 15)
1194| return buffers[14].floats[float_id];
1195| else if (GSK_N_BUFFERS > 15)
1196| return buffers[15].floats[float_id];
1197| }
1198| }
1199| }
1200| }
1201| else if (GSK_N_BUFFERS > 16)
1202| {
1203| if (buffer_id < 24)
1204| {
1205| if (buffer_id < 20)
1206| {
1207| if (buffer_id < 18)
1208| {
1209| if (buffer_id < 17)
1210| return buffers[16].floats[float_id];
1211| else if (GSK_N_BUFFERS > 17)
1212| return buffers[17].floats[float_id];
1213| }
1214| else if (GSK_N_BUFFERS > 18)
1215| {
1216| if (buffer_id < 19)
1217| return buffers[18].floats[float_id];
1218| else if (GSK_N_BUFFERS > 19)
1219| return buffers[19].floats[float_id];
1220| }
1221| }
1222| else if (GSK_N_BUFFERS > 20)
1223| {
1224| if (buffer_id < 22)
1225| {
1226| if (buffer_id < 21)
1227| return buffers[20].floats[float_id];
1228| else if (GSK_N_BUFFERS > 21)
1229| return buffers[21].floats[float_id];
1230| }
1231| else if (GSK_N_BUFFERS > 22)
1232| {
1233| if (buffer_id < 23)
1234| return buffers[22].floats[float_id];
1235| else if (GSK_N_BUFFERS > 23)
1236| return buffers[23].floats[float_id];
1237| }
1238| }
1239| }
1240| else if (GSK_N_BUFFERS > 24)
1241| {
1242| if (buffer_id < 28)
1243| {
1244| if (buffer_id < 26)
1245| {
1246| if (buffer_id < 25)
1247| return buffers[24].floats[float_id];
1248| else if (GSK_N_BUFFERS > 25)
1249| return buffers[25].floats[float_id];
1250| }
1251| else if (GSK_N_BUFFERS > 26)
1252| {
1253| if (buffer_id < 27)
1254| return buffers[26].floats[float_id];
1255| else if (GSK_N_BUFFERS > 27)
1256| return buffers[27].floats[float_id];
1257| }
1258| }
1259| else if (GSK_N_BUFFERS > 28)
1260| {
1261| if (buffer_id < 30)
1262| {
1263| if (buffer_id < 29)
1264| return buffers[28].floats[float_id];
1265| else if (GSK_N_BUFFERS > 29)
1266| return buffers[29].floats[float_id];
1267| }
1268| else if (GSK_N_BUFFERS > 30)
1269| {
1270| if (buffer_id < 31)
1271| return buffers[30].floats[float_id];
1272| else if (GSK_N_BUFFERS > 31)
1273| return buffers[31].floats[float_id];
1274| }
1275| }
1276| }
1277| }
1278| return 0.0;
1279| }
1280| #endif
1281| #define gsk_get_int(id) (floatBitsToInt(gsk_get_float(id)))
1282| #define gsk_get_uint(id) (floatBitsToUint(gsk_get_float(id)))
1283|
1284| void
1285| gsk_set_output_color (vec4 color)
1286| {
1287| out_color = color;
1288| }
1289|
1290| #endif
1291| #else
1292| precision highp float;
1293|
1294| #if defined(GSK_GLES) && __VERSION__ < 310
1295| layout(std140)
1296| #else
1297| layout(std140, binding = 0)
1298| #endif
1299| uniform PushConstants
1300| {
1301| mat4 mvp;
1302| mat3x4 clip;
1303| vec2 scale;
1304| } push;
1305|
1306| #define GSK_GLOBAL_MVP push.mvp
1307| #define GSK_GLOBAL_CLIP push.clip
1308| #define GSK_GLOBAL_CLIP_RECT push.clip[0]
1309| #define GSK_GLOBAL_SCALE push.scale
1310|
1311| #if defined(GSK_GLES) && __VERSION__ < 310
1312| layout(std140)
1313| #else
1314| layout(std140, binding = 1)
1315| #endif
1316| uniform Floats
1317| {
1318| vec4 really_just_floats[1024];
1319| } floats[11];
1320|
1321| #if N_EXTERNAL_TEXTURES > 0
1322| uniform samplerExternalOES external_textures[N_EXTERNAL_TEXTURES];
1323| #endif
1324| #if N_TEXTURES > 0
1325| uniform sampler2D textures[N_TEXTURES];
1326| #endif
1327|
1328| #define GSK_VERTEX_INDEX gl_VertexID
1329|
1330|
1331| #ifdef GSK_VERTEX_SHADER
1332| #define IN(_loc) in
1333| #define PASS(_loc) out
1334| #define PASS_FLAT(_loc) flat out
1335| #endif
1336|
1337|
1338| #ifdef GSK_FRAGMENT_SHADER
1339| #define PASS(_loc) in
1340| #define PASS_FLAT(_loc) flat in
1341|
1342| float
1343| gsk_get_float (int id)
1344| {
1345| int float_id = id & 0x3FFFFF;
1346| int array_id = (id >> 22) & 0xFF;
1347| switch (array_id)
1348| {
1349| case 0:
1350| return floats[0].really_just_floats[float_id >> 2][float_id & 3];
1351| case 1:
1352| return floats[1].really_just_floats[float_id >> 2][float_id & 3];
1353| case 2:
1354| return floats[2].really_just_floats[float_id >> 2][float_id & 3];
1355| case 3:
1356| return floats[3].really_just_floats[float_id >> 2][float_id & 3];
1357| case 4:
1358| return floats[4].really_just_floats[float_id >> 2][float_id & 3];
1359| case 5:
1360| return floats[5].really_just_floats[float_id >> 2][float_id & 3];
1361| case 6:
1362| return floats[6].really_just_floats[float_id >> 2][float_id & 3];
1363| case 7:
1364| return floats[7].really_just_floats[float_id >> 2][float_id & 3];
1365| case 8:
1366| return floats[8].really_just_floats[float_id >> 2][float_id & 3];
1367| case 9:
1368| return floats[9].really_just_floats[float_id >> 2][float_id & 3];
1369| case 10:
1370| return floats[10].really_just_floats[float_id >> 2][float_id & 3];
1371| default:
1372| return 0.0;
1373| }
1374| }
1375|
1376| float
1377| gsk_get_float (uint id)
1378| {
1379| return gsk_get_float (int (id));
1380| }
1381|
1382| #define gsk_get_int(id) (floatBitsToInt(gsk_get_float(id)))
1383| #define gsk_get_uint(id) (floatBitsToUint(gsk_get_float(id)))
1384|
1385| #ifdef GSK_GLES
1386|
1387| vec4
1388| gsk_texture (uint id,
1389| vec2 pos)
1390| {
1391| if ((id & 1u) != 0u)
1392| {
1393| switch (id >> 1u)
1394| {
1395| case 0u:
1396| #if N_EXTERNAL_TEXTURES > 0
1397| return texture (external_textures[0], pos);
1398| #endif
1399| #if N_EXTERNAL_TEXTURES > 1
1400| case 1u:
1401| return texture (external_textures[1], pos);
1402| #endif
1403| case 2u:
1404| #if N_EXTERNAL_TEXTURES > 2
1405| return texture (external_textures[2], pos);
1406| #endif
1407| case 3u:
1408| #if N_EXTERNAL_TEXTURES > 3
1409| return texture (external_textures[3], pos);
1410| #endif
1411| case 4u:
1412| #if N_EXTERNAL_TEXTURES > 4
1413| return texture (external_textures[4], pos);
1414| #endif
1415| case 5u:
1416| #if N_EXTERNAL_TEXTURES > 5
1417| return texture (external_textures[5], pos);
1418| #endif
1419| default:
1420| break;
1421| }
1422| }
1423| else
1424| {
1425| switch (id >> 1u)
1426| {
1427| case 0u:
1428| #if N_TEXTURES > 0
1429| return texture (textures[0], pos);
1430| #endif
1431| case 1u:
1432| #if N_TEXTURES > 1
1433| return texture (textures[1], pos);
1434| #endif
1435| case 2u:
1436| #if N_TEXTURES > 2
1437| return texture (textures[2], pos);
1438| #endif
1439| case 3u:
1440| #if N_TEXTURES > 3
1441| return texture (textures[3], pos);
1442| #endif
1443| case 4u:
1444| #if N_TEXTURES > 4
1445| return texture (textures[4], pos);
1446| #endif
1447| case 5u:
1448| #if N_TEXTURES > 5
1449| return texture (textures[5], pos);
1450| #endif
1451| case 6u:
1452| #if N_TEXTURES > 6
1453| return texture (textures[6], pos);
1454| #endif
1455| case 7u:
1456| #if N_TEXTURES > 7
1457| return texture (textures[7], pos);
1458| #endif
1459| case 8u:
1460| #if N_TEXTURES > 8
1461| return texture (textures[8], pos);
1462| #endif
1463| case 9u:
1464| #if N_TEXTURES > 9
1465| return texture (textures[9], pos);
1466| #endif
1467| case 10u:
1468| #if N_TEXTURES > 10
1469| return texture (textures[10], pos);
1470| #endif
1471| case 11u:
1472| #if N_TEXTURES > 11
1473| return texture (textures[11], pos);
1474| #endif
1475| case 12u:
1476| #if N_TEXTURES > 12
1477| return texture (textures[12], pos);
1478| #endif
1479| case 13u:
1480| #if N_TEXTURES > 13
1481| return texture (textures[13], pos);
1482| #endif
1483| case 14u:
1484| #if N_TEXTURES > 14
1485| return texture (textures[14], pos);
1486| #endif
1487| case 15u:
1488| #if N_TEXTURES > 15
1489| return texture (textures[15], pos);
1490| #endif
1491| default:
1492| break;
1493| }
1494| }
1495| return vec4 (1.0, 0.0, 0.8, 1.0);
1496| }
1497|
1498| ivec2
1499| gsk_texture_size (uint id,
1500| int lod)
1501| {
1502| if ((id & 1u) != 0u)
1503| {
1504| switch (id >> 1u)
1505| {
1506| case 0u:
1507| #if N_EXTERNAL_TEXTURES > 0
1508| return textureSize (external_textures[0], lod);
1509| #endif
1510| #if N_EXTERNAL_TEXTURES > 1
1511| case 1u:
1512| return textureSize (external_textures[1], lod);
1513| #endif
1514| case 2u:
1515| #if N_EXTERNAL_TEXTURES > 2
1516| return textureSize (external_textures[2], lod);
1517| #endif
1518| case 3u:
1519| #if N_EXTERNAL_TEXTURES > 3
1520| return textureSize (external_textures[3], lod);
1521| #endif
1522| case 4u:
1523| #if N_EXTERNAL_TEXTURES > 4
1524| return textureSize (external_textures[4], lod);
1525| #endif
1526| case 5u:
1527| #if N_EXTERNAL_TEXTURES > 5
1528| return textureSize (external_textures[5], lod);
1529| #endif
1530| default:
1531| break;
1532| }
1533| }
1534| else
1535| {
1536| switch (id >> 1u)
1537| {
1538| case 0u:
1539| #if N_TEXTURES > 0
1540| return textureSize (textures[0], lod);
1541| #endif
1542| case 1u:
1543| #if N_TEXTURES > 1
1544| return textureSize (textures[1], lod);
1545| #endif
1546| case 2u:
1547| #if N_TEXTURES > 2
1548| return textureSize (textures[2], lod);
1549| #endif
1550| case 3u:
1551| #if N_TEXTURES > 3
1552| return textureSize (textures[3], lod);
1553| #endif
1554| case 4u:
1555| #if N_TEXTURES > 4
1556| return textureSize (textures[4], lod);
1557| #endif
1558| case 5u:
1559| #if N_TEXTURES > 5
1560| return textureSize (textures[5], lod);
1561| #endif
1562| case 6u:
1563| #if N_TEXTURES > 6
1564| return textureSize (textures[6], lod);
1565| #endif
1566| case 7u:
1567| #if N_TEXTURES > 7
1568| return textureSize (textures[7], lod);
1569| #endif
1570| case 8u:
1571| #if N_TEXTURES > 8
1572| return textureSize (textures[8], lod);
1573| #endif
1574| case 9u:
1575| #if N_TEXTURES > 9
1576| return textureSize (textures[9], lod);
1577| #endif
1578| case 10u:
1579| #if N_TEXTURES > 10
1580| return textureSize (textures[10], lod);
1581| #endif
1582| case 11u:
1583| #if N_TEXTURES > 11
1584| return textureSize (textures[11], lod);
1585| #endif
1586| case 12u:
1587| #if N_TEXTURES > 12
1588| return textureSize (textures[12], lod);
1589| #endif
1590| case 13u:
1591| #if N_TEXTURES > 13
1592| return textureSize (textures[13], lod);
1593| #endif
1594| case 14u:
1595| #if N_TEXTURES > 14
1596| return textureSize (textures[14], lod);
1597| #endif
1598| case 15u:
1599| #if N_TEXTURES > 15
1600| return textureSize (textures[15], lod);
1601| #endif
1602| default:
1603| break;
1604| }
1605| }
1606| return ivec2 (1, 1);
1607| }
1608|
1609| vec4
1610| gsk_texel_fetch (uint id,
1611| ivec2 pos,
1612| int lod)
1613| {
1614| if ((id & 1u) != 0u)
1615| {
1616| switch (id >> 1u)
1617| {
1618| case 0u:
1619| #if N_EXTERNAL_TEXTURES > 0
1620| return texelFetch (external_textures[0], pos, lod);
1621| #endif
1622| #if N_EXTERNAL_TEXTURES > 1
1623| case 1u:
1624| return texelFetch (external_textures[1], pos, lod);
1625| #endif
1626| case 2u:
1627| #if N_EXTERNAL_TEXTURES > 2
1628| return texelFetch (external_textures[2], pos, lod);
1629| #endif
1630| case 3u:
1631| #if N_EXTERNAL_TEXTURES > 3
1632| return texelFetch (external_textures[3], pos, lod);
1633| #endif
1634| case 4u:
1635| #if N_EXTERNAL_TEXTURES > 4
1636| return texelFetch (external_textures[4], pos, lod);
1637| #endif
1638| case 5u:
1639| #if N_EXTERNAL_TEXTURES > 5
1640| return texelFetch (external_textures[5], pos, lod);
1641| #endif
1642| default:
1643| break;
1644| }
1645| }
1646| else
1647| {
1648| switch (id >> 1u)
1649| {
1650| case 0u:
1651| #if N_TEXTURES > 0
1652| return texelFetch (textures[0], pos, lod);
1653| #endif
1654| case 1u:
1655| #if N_TEXTURES > 1
1656| return texelFetch (textures[1], pos, lod);
1657| #endif
1658| case 2u:
1659| #if N_TEXTURES > 2
1660| return texelFetch (textures[2], pos, lod);
1661| #endif
1662| case 3u:
1663| #if N_TEXTURES > 3
1664| return texelFetch (textures[3], pos, lod);
1665| #endif
1666| case 4u:
1667| #if N_TEXTURES > 4
1668| return texelFetch (textures[4], pos, lod);
1669| #endif
1670| case 5u:
1671| #if N_TEXTURES > 5
1672| return texelFetch (textures[5], pos, lod);
1673| #endif
1674| case 6u:
1675| #if N_TEXTURES > 6
1676| return texelFetch (textures[6], pos, lod);
1677| #endif
1678| case 7u:
1679| #if N_TEXTURES > 7
1680| return texelFetch (textures[7], pos, lod);
1681| #endif
1682| case 8u:
1683| #if N_TEXTURES > 8
1684| return texelFetch (textures[8], pos, lod);
1685| #endif
1686| case 9u:
1687| #if N_TEXTURES > 9
1688| return texelFetch (textures[9], pos, lod);
1689| #endif
1690| case 10u:
1691| #if N_TEXTURES > 10
1692| return texelFetch (textures[10], pos, lod);
1693| #endif
1694| case 11u:
1695| #if N_TEXTURES > 11
1696| return texelFetch (textures[11], pos, lod);
1697| #endif
1698| case 12u:
1699| #if N_TEXTURES > 12
1700| return texelFetch (textures[12], pos, lod);
1701| #endif
1702| case 13u:
1703| #if N_TEXTURES > 13
1704| return texelFetch (textures[13], pos, lod);
1705| #endif
1706| case 14u:
1707| #if N_TEXTURES > 14
1708| return texelFetch (textures[14], pos, lod);
1709| #endif
1710| case 15u:
1711| #if N_TEXTURES > 15
1712| return texelFetch (textures[15], pos, lod);
1713| #endif
1714| default:
1715| break;
1716| }
1717| }
1718| return vec4 (1.0, 0.0, 0.8, 1.0);
1719| }
1720|
1721| #else /* !GSK_GLES */
1722|
1723| #define gsk_texture(id, pos) texture (textures[id >> 1], pos)
1724| #define gsk_texture_size(id, lod) textureSize (textures[id >> 1], lod)
1725| #define gsk_texel_fetch(id, pos, lod) texelFetch (textures[id >> 1], pos, lod)
1726|
1727| #endif
1728|
1729| layout(location = 0) out vec4 out_color;
1730| void
1731| gsk_set_output_color (vec4 color)
1732| {
1733| out_color = color;
1734| }
1735|
1736| #endif
1737| #endif
1738|
1739| #ifndef _COLOR_
1740| #define _COLOR_
1741|
1742| vec4
1743| color_premultiply (vec4 color)
1744| {
1745| return vec4 (color.rgb, 1.0) * color.a;
1746| }
1747|
1748| vec4
1749| color_unpremultiply (vec4 color)
1750| {
1751| return color.a > 0.0 ? color / vec4 (color.aaa, 1.0) : color;
1752| }
1753|
1754| float
1755| luminance (vec3 color)
1756| {
1757| return dot (vec3 (0.2126, 0.7152, 0.0722), color);
1758| }
1759|
1760| #endif /* _COLOR_ */
1761| #ifndef _RECT_
1762| #define _RECT_
1763|
1764| struct Rect
1765| {
1766| /* x,y and y,w make up the 2 points of this rect,
1767| note that this is not containing width or height */
1768| vec4 bounds;
1769| };
1770|
1771| Rect
1772| rect_new_size (vec4 coords)
1773| {
1774| return Rect (coords + vec4 (0.0, 0.0, coords.xy));
1775| }
1776|
1777| Rect
1778| rect_from_gsk (vec4 coords)
1779| {
1780| Rect result = rect_new_size (coords);
1781| result.bounds *= GSK_GLOBAL_SCALE.xyxy;
1782| return result;
1783| }
1784|
1785| float
1786| rect_distance (Rect r, vec2 p)
1787| {
1788| vec4 distance = (r.bounds - p.xyxy) * vec4(1.0, 1.0, -1.0, -1.0);
1789| vec2 max2 = max (distance.xy, distance.zw);
1790| return length (max (max2, 0.0)) + min (max(max2.x, max2.y), 0.0);
1791| }
1792|
1793| vec2
1794| rect_size (Rect r)
1795| {
1796| return r.bounds.zw - r.bounds.xy;
1797| }
1798|
1799| Rect
1800| rect_round_larger (Rect r)
1801| {
1802| return Rect (vec4 (floor(r.bounds.xy), ceil (r.bounds.zw)));
1803| }
1804|
1805| Rect
1806| rect_round_larger_smaller (Rect r)
1807| {
1808| return Rect (mix (floor(r.bounds), ceil (r.bounds), bvec4(0, 1, 1, 0)));
1809| }
1810|
1811| Rect
1812| rect_round_smaller_larger (Rect r)
1813| {
1814| return Rect (mix (floor(r.bounds), ceil (r.bounds), bvec4(1, 0, 0, 1)));
1815| }
1816|
1817| Rect
1818| rect_intersect (Rect a, Rect b)
1819| {
1820| vec4 result = vec4(max(a.bounds.xy, b.bounds.xy), min(a.bounds.zw, b.bounds.zw));
1821| if (any (greaterThanEqual (result.xy, result.zw)))
1822| return Rect (vec4(0.0));
1823| return Rect(result);
1824| }
1825|
1826| Rect
1827| rect_union (Rect a, Rect b)
1828| {
1829| return Rect (vec4 (min (a.bounds.xy, b.bounds.xy), max (a.bounds.zw, b.bounds.zw)));
1830| }
1831|
1832| vec2
1833| rect_get_coord (Rect r, vec2 pt)
1834| {
1835| return (pt - r.bounds.xy) / rect_size (r);
1836| }
1837|
1838| #ifdef GSK_FRAGMENT_SHADER
1839|
1840| float
1841| rect_coverage (Rect r,
1842| vec2 p,
1843| vec2 dFdp)
1844| {
1845| Rect prect = Rect(vec4(p - 0.5 * dFdp, p + 0.5 * dFdp));
1846| Rect coverect = rect_intersect (r, prect);
1847| vec2 coverage = rect_size(coverect) / dFdp;
1848| return coverage.x * coverage.y;
1849| }
1850|
1851| float
1852| rect_coverage (Rect r, vec2 p)
1853| {
1854| return rect_coverage (r, p, abs (fwidth (p)));
1855| }
1856|
1857|
1858| #endif
1859|
1860| #endif
1861| #ifndef _ROUNDED_RECT_
1862| #define _ROUNDED_RECT_
1863|
1864| #ifndef _ELLIPSE_
1865| #define _ELLIPSE_
1866|
1867| struct Ellipse
1868| {
1869| vec2 center;
1870| vec2 radius;
1871| };
1872|
1873| float
1874| ellipse_distance (Ellipse r, vec2 p)
1875| {
1876| vec2 e = r.radius;
1877| p = p - r.center;
1878|
1879| if (e.x == e.y)
1880| return length (p) - e.x;
1881|
1882| /* from https://www.shadertoy.com/view/tt3yz7 */
1883| vec2 pAbs = abs(p);
1884| vec2 ei = 1.0 / e;
1885| vec2 e2 = e*e;
1886| vec2 ve = ei * vec2(e2.x - e2.y, e2.y - e2.x);
1887|
1888| vec2 t = vec2(0.70710678118654752, 0.70710678118654752);
1889| for (int i = 0; i < 3; i++) {
1890| vec2 v = ve*t*t*t;
1891| vec2 u = normalize(pAbs - v) * length(t * e - v);
1892| vec2 w = ei * (v + u);
1893| t = normalize(clamp(w, 0.0, 1.0));
1894| }
1895|
1896| vec2 nearestAbs = t * e;
1897| float dist = length(pAbs - nearestAbs);
1898| return dot(pAbs, pAbs) < dot(nearestAbs, nearestAbs) ? -dist : dist;
1899| }
1900|
1901| #endif
1902|
1903| struct RoundedRect
1904| {
1905| vec4 bounds;
1906| vec4 corner_widths;
1907| vec4 corner_heights;
1908| };
1909|
1910| RoundedRect
1911| rounded_rect_from_rect (Rect r)
1912| {
1913| return RoundedRect (r.bounds, vec4 (0.0), vec4 (0.0));
1914| }
1915|
1916| RoundedRect
1917| rounded_rect_from_gsk (mat3x4 gsk_rounded_rect)
1918| {
1919| return RoundedRect ((gsk_rounded_rect[0].xyxy + vec4 (0.0, 0.0, gsk_rounded_rect[0].zw)) * GSK_GLOBAL_SCALE.xyxy,
1920| gsk_rounded_rect[1] * GSK_GLOBAL_SCALE.xxxx,
1921| gsk_rounded_rect[2] * GSK_GLOBAL_SCALE.yyyy);
1922| }
1923|
1924| float
1925| rounded_rect_distance (RoundedRect r, vec2 p)
1926| {
1927| Rect bounds = Rect(vec4(r.bounds));
1928|
1929| float bounds_distance = rect_distance (bounds, p);
1930|
1931| Ellipse tl = Ellipse (r.bounds.xy + vec2( r.corner_widths.x, r.corner_heights.x),
1932| vec2(r.corner_widths.x, r.corner_heights.x));
1933| Ellipse tr = Ellipse (r.bounds.zy + vec2(-r.corner_widths.y, r.corner_heights.y),
1934| vec2(r.corner_widths.y, r.corner_heights.y));
1935| Ellipse br = Ellipse (r.bounds.zw + vec2(-r.corner_widths.z, -r.corner_heights.z),
1936| vec2(r.corner_widths.z, r.corner_heights.z));
1937| Ellipse bl = Ellipse (r.bounds.xw + vec2( r.corner_widths.w, -r.corner_heights.w),
1938| vec2(r.corner_widths.w, r.corner_heights.w));
1939|
1940| vec4 distances = vec4(ellipse_distance (tl, p),
1941| ellipse_distance (tr, p),
1942| ellipse_distance (br, p),
1943| ellipse_distance (bl, p));
1944|
1945| bvec4 is_out = bvec4(p.x < tl.center.x && p.y < tl.center.y,
1946| p.x > tr.center.x && p.y < tr.center.y,
1947| p.x > br.center.x && p.y > br.center.y,
1948| p.x < bl.center.x && p.y > bl.center.y);
1949| distances = mix (vec4(bounds_distance), distances, is_out);
1950|
1951| vec2 max2 = max (distances.xy, distances.zw);
1952| return max (max2.x, max2.y);
1953| }
1954|
1955| RoundedRect
1956| rounded_rect_shrink (RoundedRect r, vec4 amount)
1957| {
1958| vec4 new_bounds = r.bounds + vec4(1.0,1.0,-1.0,-1.0) * amount.wxyz;
1959| vec4 new_widths = max (r.corner_widths - sign (r.corner_widths) * amount.wyyw, 0.0);
1960| vec4 new_heights = max (r.corner_heights - sign (r.corner_heights) * amount.xxzz, 0.0);
1961| new_widths = min (new_widths, new_bounds.z - new_bounds.x);
1962| new_heights = min (new_heights, new_bounds.w - new_bounds.y);
1963|
1964| return RoundedRect (new_bounds, new_widths, new_heights);
1965| }
1966|
1967| void
1968| rounded_rect_scale (inout RoundedRect r,
1969| vec2 scale)
1970| {
1971| r.bounds *= scale.xyxy;
1972| r.corner_widths *= scale.xxxx;
1973| r.corner_heights *= scale.yyyy;
1974| }
1975|
1976| void
1977| rounded_rect_offset (inout RoundedRect r,
1978| vec2 offset)
1979| {
1980| r.bounds += offset.xyxy;
1981| }
1982|
1983| bool
1984| rounded_rect_is_slicable (RoundedRect r)
1985| {
1986| vec2 size = rect_size (Rect (r.bounds));
1987| return (r.corner_widths[TOP_LEFT] + r.corner_widths[BOTTOM_RIGHT] <= size.x ||
1988| r.corner_heights[TOP_LEFT] + r.corner_heights[BOTTOM_RIGHT] <= size.y)
1989| && (r.corner_widths[BOTTOM_LEFT] + r.corner_widths[TOP_RIGHT] <= size.x ||
1990| r.corner_heights[BOTTOM_LEFT] + r.corner_heights[TOP_RIGHT] <= size.y);
1991| }
1992|
1993| Rect
1994| rounded_rect_intersection_fallback_slice (RoundedRect outside,
1995| RoundedRect inside,
1996| uint slice)
1997| {
1998| switch (slice)
1999| {
2000| default:
2001| case SLICE_TOP:
2002| case SLICE_RIGHT:
2003| case SLICE_BOTTOM:
2004| case SLICE_LEFT:
2005| return Rect (vec4 (0.0));
2006|
2007| case SLICE_TOP_LEFT:
2008| return Rect (vec4 (outside.bounds.xy, 0.5 * (outside.bounds.xy + outside.bounds.zw)));
2009|
2010| case SLICE_TOP_RIGHT:
2011| return Rect (vec4 (0.5 * (outside.bounds.x + outside.bounds.z), outside.bounds.y,
2012| outside.bounds.z, 0.5 * (outside.bounds.y + outside.bounds.w)));
2013|
2014| case SLICE_BOTTOM_RIGHT:
2015| return Rect (vec4 (0.5 * (outside.bounds.xy + outside.bounds.zw), outside.bounds.zw));
2016|
2017| case SLICE_BOTTOM_LEFT:
2018| return Rect (vec4 (outside.bounds.x, 0.5 * (outside.bounds.y + outside.bounds.w),
2019| 0.5 * (outside.bounds.x + outside.bounds.z), outside.bounds.w));
2020| }
2021| }
2022|
2023| Rect
2024| rounded_rect_intersection_slice (RoundedRect outside,
2025| RoundedRect inside,
2026| uint slice)
2027| {
2028| float left, right, top, bottom;
2029|
2030| if (!rounded_rect_is_slicable (outside) ||
2031| !rounded_rect_is_slicable (inside))
2032| return rounded_rect_intersection_fallback_slice (outside, inside, slice);
2033|
2034| switch (slice)
2035| {
2036| case SLICE_TOP_LEFT:
2037| return Rect (vec4 (outside.bounds.x,
2038| outside.bounds.y,
2039| max (outside.bounds.x + outside.corner_widths[TOP_LEFT],
2040| inside.bounds.x + inside.corner_widths[TOP_LEFT]),
2041| max (outside.bounds.y + outside.corner_heights[TOP_LEFT],
2042| inside.bounds.y + inside.corner_heights[TOP_LEFT])));
2043|
2044| case SLICE_TOP:
2045| left = max (outside.bounds.x + outside.corner_widths[TOP_LEFT],
2046| inside.bounds.x + inside.corner_widths[TOP_LEFT]);
2047| right = min (outside.bounds.z - outside.corner_widths[TOP_RIGHT],
2048| inside.bounds.z - inside.corner_widths[TOP_RIGHT]);
2049| return Rect (vec4 (left,
2050| outside.bounds.y,
2051| max (left, right),
2052| max (outside.bounds.y, inside.bounds.y)));
2053|
2054| case SLICE_TOP_RIGHT:
2055| left = max (min (outside.bounds.z - outside.corner_widths[TOP_RIGHT],
2056| inside.bounds.z - inside.corner_widths[TOP_RIGHT]),
2057| max (outside.bounds.x + outside.corner_widths[TOP_LEFT],
2058| inside.bounds.x + inside.corner_widths[TOP_LEFT]));
2059| return Rect (vec4 (left,
2060| outside.bounds.y,
2061| outside.bounds.z,
2062| max (outside.bounds.y + outside.corner_heights[TOP_RIGHT],
2063| inside.bounds.y + inside.corner_heights[TOP_RIGHT])));
2064|
2065| case SLICE_RIGHT:
2066| top = max (outside.bounds.y + outside.corner_heights[TOP_RIGHT],
2067| inside.bounds.y + inside.corner_heights[TOP_RIGHT]);
2068| bottom = min (outside.bounds.w - outside.corner_heights[BOTTOM_RIGHT],
2069| inside.bounds.w - inside.corner_heights[BOTTOM_RIGHT]);
2070| return Rect (vec4 (min (outside.bounds.z, inside.bounds.z),
2071| top,
2072| outside.bounds.z,
2073| max (bottom, top)));
2074|
2075| case SLICE_BOTTOM_RIGHT:
2076| left = max (min (outside.bounds.z - outside.corner_widths[BOTTOM_RIGHT],
2077| inside.bounds.z - inside.corner_widths[BOTTOM_RIGHT]),
2078| max (outside.bounds.x + outside.corner_widths[BOTTOM_LEFT],
2079| inside.bounds.x + inside.corner_widths[BOTTOM_LEFT]));
2080| bottom = max (min (outside.bounds.w - outside.corner_heights[BOTTOM_RIGHT],
2081| inside.bounds.w - inside.corner_heights[BOTTOM_RIGHT]),
2082| max (outside.bounds.y + outside.corner_heights[TOP_RIGHT],
2083| inside.bounds.y + inside.corner_heights[TOP_RIGHT]));
2084| return Rect (vec4 (left,
2085| bottom,
2086| outside.bounds.z,
2087| outside.bounds.w));
2088|
2089| case SLICE_BOTTOM:
2090| left = max (outside.bounds.x + outside.corner_widths[BOTTOM_LEFT],
2091| inside.bounds.x + inside.corner_widths[BOTTOM_LEFT]);
2092| right = min (outside.bounds.z - outside.corner_widths[BOTTOM_RIGHT],
2093| inside.bounds.z - inside.corner_widths[BOTTOM_RIGHT]);
2094| return Rect (vec4 (left,
2095| min (outside.bounds.w, inside.bounds.w),
2096| max (left, right),
2097| outside.bounds.w));
2098|
2099| case SLICE_BOTTOM_LEFT:
2100| bottom = max (min (outside.bounds.w - outside.corner_heights[BOTTOM_LEFT],
2101| inside.bounds.w - inside.corner_heights[BOTTOM_LEFT]),
2102| max (outside.bounds.y + outside.corner_heights[TOP_LEFT],
2103| inside.bounds.y + inside.corner_heights[TOP_LEFT]));
2104| return Rect (vec4 (outside.bounds.x,
2105| bottom,
2106| max (outside.bounds.x + outside.corner_widths[BOTTOM_LEFT],
2107| inside.bounds.x + inside.corner_widths[BOTTOM_LEFT]),
2108| outside.bounds.w));
2109|
2110| case SLICE_LEFT:
2111| top = max (outside.bounds.y + outside.corner_heights[TOP_LEFT],
2112| inside.bounds.y + inside.corner_heights[TOP_LEFT]);
2113| bottom = min (outside.bounds.w - outside.corner_heights[BOTTOM_LEFT],
2114| inside.bounds.w - inside.corner_heights[BOTTOM_LEFT]);
2115| return Rect (vec4 (outside.bounds.x,
2116| top,
2117| max (outside.bounds.x, inside.bounds.x),
2118| max (bottom, top)));
2119|
2120| default:
2121| return Rect (vec4 (0.0));
2122| }
2123| }
2124|
2125| #ifdef GSK_FRAGMENT_SHADER
2126|
2127| float
2128| rounded_rect_coverage (RoundedRect r, vec2 p)
2129| {
2130| vec2 fw = abs (fwidth (p));
2131| float distance_scale = max (fw.x, fw.y);
2132| float distance = rounded_rect_distance (r, p) / distance_scale;
2133| float coverage = 0.5 - distance;
2134|
2135| return clamp (coverage, 0.0, 1.0);
2136| }
2137|
2138| #endif
2139|
2140| #endif
2141|
2142| #define PI 3.1415926535897932384626433832795
2143| #define SQRT1_2 1.4142135623730951
2144|
2145| Rect
2146| rect_clip (Rect r)
2147| {
2148| if (GSK_SHADER_CLIP == GSK_GPU_SHADER_CLIP_NONE)
2149| return r;
2150| else
2151| return rect_intersect (r, rect_from_gsk (GSK_GLOBAL_CLIP_RECT));
2152| }
2153|
2154| #ifdef GSK_VERTEX_SHADER
2155|
2156| const vec2 offsets[6] = vec2[6](vec2(0.0, 0.0),
2157| vec2(1.0, 0.0),
2158| vec2(0.0, 1.0),
2159| vec2(0.0, 1.0),
2160| vec2(1.0, 0.0),
2161| vec2(1.0, 1.0));
2162|
2163| void
2164| gsk_set_position (vec2 pos)
2165| {
2166| gl_Position = GSK_GLOBAL_MVP * vec4 (pos, 0.0, 1.0);
2167| }
2168|
2169| vec2
2170| rect_get_position (Rect rect)
2171| {
2172| Rect r = rect_round_larger (rect_clip (rect));
2173|
2174| vec2 pos = mix (r.bounds.xy, r.bounds.zw, offsets[GSK_VERTEX_INDEX]);
2175|
2176| return pos;
2177| }
2178|
2179| vec2
2180| border_get_position (RoundedRect outside,
2181| RoundedRect inside)
2182| {
2183| uint slice_index = uint (GSK_VERTEX_INDEX) / 6u;
2184| uint vert_index = uint (GSK_VERTEX_INDEX) % 6u;
2185|
2186| Rect rect = rounded_rect_intersection_slice (outside, inside, slice_index);
2187|
2188| switch (slice_index)
2189| {
2190| case SLICE_TOP_LEFT:
2191| rect = rect_round_larger (rect);
2192| rect.bounds = rect.bounds.xwzy;
2193| break;
2194| case SLICE_TOP:
2195| rect = rect_round_smaller_larger (rect);
2196| break;
2197| case SLICE_TOP_RIGHT:
2198| rect = rect_round_larger (rect);
2199| break;
2200| case SLICE_RIGHT:
2201| rect = rect_round_larger_smaller (rect);
2202| break;
2203| case SLICE_BOTTOM_RIGHT:
2204| rect = rect_round_larger (rect);
2205| rect.bounds = rect.bounds.zyxw;
2206| break;
2207| case SLICE_BOTTOM:
2208| rect = rect_round_smaller_larger (rect);
2209| break;
2210| case SLICE_BOTTOM_LEFT:
2211| rect = rect_round_larger (rect);
2212| rect.bounds = rect.bounds.zwxy;
2213| break;
2214| case SLICE_LEFT:
2215| rect = rect_round_larger_smaller (rect);
2216| break;
2217| }
2218|
2219| vec2 pos = mix (rect.bounds.xy, rect.bounds.zw, offsets[vert_index]);
2220|
2221| return pos;
2222| }
2223|
2224| vec2
2225| scale_tex_coord (vec2 in_pos,
2226| Rect in_rect,
2227| vec4 tex_rect)
2228| {
2229| return tex_rect.xy + (in_pos - in_rect.bounds.xy) / rect_size (in_rect) * tex_rect.zw;
2230| }
2231|
2232| void run (out vec2 pos);
2233|
2234| void
2235| main (void)
2236| {
2237| vec2 pos;
2238|
2239| run (pos);
2240|
2241| gsk_set_position (pos);
2242| }
2243|
2244| #endif /* GSK_VERTEX_SHADER */
2245|
2246|
2247| #ifdef GSK_FRAGMENT_SHADER
2248|
2249| vec4
2250| gsk_texture_straight_alpha (uint tex_id,
2251| vec2 pos)
2252| {
2253| vec2 size = vec2 (gsk_texture_size (tex_id, 0));
2254| pos *= size;
2255| size -= vec2 (1.0);
2256| /* GL_CLAMP_TO_EDGE */
2257| pos = clamp (pos - 0.5, vec2 (0.0), size);
2258| ivec2 ipos = ivec2 (pos);
2259| pos = fract (pos);
2260| vec4 tl = gsk_texel_fetch (tex_id, ipos, 0);
2261| tl.rgb *= tl.a;
2262| vec4 tr = gsk_texel_fetch (tex_id, ipos + ivec2(1, 0), 0);
2263| tr.rgb *= tr.a;
2264| vec4 bl = gsk_texel_fetch (tex_id, ipos + ivec2(0, 1), 0);
2265| bl.rgb *= bl.a;
2266| vec4 br = gsk_texel_fetch (tex_id, ipos + ivec2(1, 1), 0);
2267| br.rgb *= br.a;
2268| return mix (mix (tl, tr, pos.x), mix (bl, br, pos.x), pos.y);
2269| }
2270|
2271| void run (out vec4 color,
2272| out vec2 pos);
2273|
2274| void
2275| main_clip_none (void)
2276| {
2277| vec4 color;
2278| vec2 pos;
2279|
2280| run (color, pos);
2281|
2282| gsk_set_output_color (color);
2283| }
2284|
2285| void
2286| main_clip_rect (void)
2287| {
2288| vec4 color;
2289| vec2 pos;
2290|
2291| run (color, pos);
2292|
2293| Rect clip = rect_from_gsk (GSK_GLOBAL_CLIP_RECT);
2294|
2295| float coverage = rect_coverage (clip, pos);
2296| color *= coverage;
2297|
2298| gsk_set_output_color (color);
2299| }
2300|
2301| void
2302| main_clip_rounded (void)
2303| {
2304| vec4 color;
2305| vec2 pos;
2306|
2307| run (color, pos);
2308|
2309| RoundedRect clip = rounded_rect_from_gsk (GSK_GLOBAL_CLIP);
2310|
2311| float coverage = rounded_rect_coverage (clip, pos);
2312| color *= coverage;
2313|
2314| gsk_set_output_color (color);
2315| }
2316|
2317| void
2318| main (void)
2319| {
2320| if (GSK_SHADER_CLIP == GSK_GPU_SHADER_CLIP_NONE)
2321| main_clip_none ();
2322| else if (GSK_SHADER_CLIP == GSK_GPU_SHADER_CLIP_RECT)
2323| main_clip_rect ();
2324| else if (GSK_SHADER_CLIP == GSK_GPU_SHADER_CLIP_ROUNDED)
2325| main_clip_rounded ();
2326| }
2327|
2328| #endif /* GSK_FRAGMENT_SHADER */
2329|
2330| #endif
2331|
2332|
2333| PASS(0) vec2 _pos;
2334| PASS_FLAT(1) Rect _rect;
2335| PASS_FLAT(2) vec4 _color;
2336| PASS(3) vec2 _tex_coord;
2337| PASS_FLAT(4) uint _tex_id;
2338|
2339|
2340|
2341| #ifdef GSK_VERTEX_SHADER
2342|
2343| IN(0) vec4 in_rect;
2344| IN(1) vec4 in_color;
2345| IN(2) vec4 in_tex_rect;
2346| IN(3) uint in_tex_id;
2347|
2348| void
2349| run (out vec2 pos)
2350| {
2351| Rect r = rect_from_gsk (in_rect);
2352|
2353| pos = rect_get_position (r);
2354|
2355| _pos = pos;
2356| _rect = r;
2357| _color = color_premultiply (in_color);
2358| _tex_coord = rect_get_coord (rect_from_gsk (in_tex_rect), pos);
2359| _tex_id = in_tex_id;
2360| }
2361|
2362| #endif
2363|
2364|
2365|
2366| #ifdef GSK_FRAGMENT_SHADER
2367|
2368| void
2369| run (out vec4 color,
2370| out vec2 position)
2371| {
2372| float alpha = gsk_texture (_tex_id, _tex_coord).a * rect_coverage (_rect, _pos);
2373| color = _color * alpha;
2374| position = _pos;
2375| }
2376|
2377| #endif
Error Message:
ERROR: 0:1297: Unknown identifier 'binding' in layout
ERROR: 0:1314: Unknown identifier 'binding' in layout
ERROR: 0:1781: Use of undeclared identifier 'push'
ERROR: 0:1919: Use of undeclared identifier 'push'
ERROR: 0:1920: Use of undeclared identifier 'push'
ERROR: 0:1921: Use of undeclared identifier 'push'
ERROR: 0:2151: Use of undeclared identifier 'push'
ERROR: 0:2166: Use of undeclared identifier 'push'