euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
/// Wayland `wl_shm` 32-bit ARGB8888 pixel format code (little-endian `[B, G, R, A]`).
pub const WL_SHM_FORMAT_ARGB8888: u32 = 0;

/// Wayland `wl_shm` 32-bit XRGB8888 pixel format code (little-endian `[B, G, R, 0xFF]`).
pub const WL_SHM_FORMAT_XRGB8888: u32 = 1;

/// Shared library name for Linux X11 client runtime.
pub(crate) const LINUX_LIB_X11: &str = "libX11.so.6\0";

/// Shared library name for Linux Wayland client runtime.
pub(crate) const LINUX_LIB_WAYLAND: &str = "libwayland-client.so.0\0";

/// Shared library name for Linux XRandR extension runtime.
pub(crate) const LINUX_LIB_XRANDR: &str = "libXrandr.so.2\0";

/// Shared library name for Linux MIT-SHM Xext extension runtime.
pub(crate) const LINUX_LIB_XEXT: &str = "libXext.so.6\0";

/// Shared library name for Linux Vulkan loader (probed for `VK_KHR_wayland_surface` WSI).
pub(crate) const LINUX_LIB_VULKAN: &str = "libvulkan.so.1\0";

/// Environment variable detecting an active native Wayland compositor socket.
pub(crate) const LINUX_WAYLAND_DISPLAY_ENV: &str = "WAYLAND_DISPLAY";

/// Optional environment variable forcing legacy X11 over native Wayland when set to `"1"`.
pub(crate) const LINUX_FORCE_X11_ENV: &str = "EUV_LINUX_FORCE_X11";

/// Dynamic symbol for `XShmQueryExtension`.
pub(crate) const SYM_XSHM_QUERY_EXTENSION: &str = "XShmQueryExtension\0";

/// Dynamic symbol for `XShmCreateImage`.
pub(crate) const SYM_XSHM_CREATE_IMAGE: &str = "XShmCreateImage\0";

/// Dynamic symbol for `XShmAttach`.
pub(crate) const SYM_XSHM_ATTACH: &str = "XShmAttach\0";

/// Dynamic symbol for `XShmDetach`.
pub(crate) const SYM_XSHM_DETACH: &str = "XShmDetach\0";

/// Dynamic symbol for `XShmPutImage`.
pub(crate) const SYM_XSHM_PUT_IMAGE: &str = "XShmPutImage\0";

/// Dynamic symbol for `wl_display_dispatch_pending`.
pub(crate) const SYM_WL_DISPLAY_DISPATCH_PENDING: &str = "wl_display_dispatch_pending\0";

/// Dynamic symbol for `wl_display_dispatch`.
pub(crate) const SYM_WL_DISPLAY_DISPATCH: &str = "wl_display_dispatch\0";

/// Dynamic symbol for `wl_display_flush`.
pub(crate) const SYM_WL_DISPLAY_FLUSH: &str = "wl_display_flush\0";

/// Dynamic symbol for `wl_display_roundtrip`.
pub(crate) const SYM_WL_DISPLAY_ROUNDTRIP: &str = "wl_display_roundtrip\0";

/// Dynamic symbol for `wl_display_disconnect`.
pub(crate) const SYM_WL_DISPLAY_DISCONNECT: &str = "wl_display_disconnect\0";

/// Dynamic symbol for `vkCreateWaylandSurfaceKHR` in `libvulkan.so.1`.
pub(crate) const SYM_VK_CREATE_WAYLAND_SURFACE: &str = "vkCreateWaylandSurfaceKHR\0";

/// Dynamic symbol for `XRRGetScreenInfo`.
pub(crate) const SYM_XRR_GET_SCREEN_INFO: &str = "XRRGetScreenInfo\0";

/// Dynamic symbol for `XRRConfigCurrentRate`.
pub(crate) const SYM_XRR_CONFIG_CURRENT_RATE: &str = "XRRConfigCurrentRate\0";

/// Dynamic symbol for `XRRFreeScreenConfigInfo`.
pub(crate) const SYM_XRR_FREE_SCREEN_CONFIG_INFO: &str = "XRRFreeScreenConfigInfo\0";

/// Environment variable overriding detected display refresh rate in Hertz on Linux.
pub(crate) const LINUX_REFRESH_ENV_VAR: &str = "EUV_REFRESH_RATE_HZ";

/// Dynamic symbol for `XOpenDisplay`.
pub(crate) const SYM_X_OPEN_DISPLAY: &str = "XOpenDisplay\0";

/// Dynamic symbol for `XDefaultScreen`.
pub(crate) const SYM_X_DEFAULT_SCREEN: &str = "XDefaultScreen\0";

/// Dynamic symbol for `XRootWindow`.
pub(crate) const SYM_X_ROOT_WINDOW: &str = "XRootWindow\0";

/// Dynamic symbol for `XCreateSimpleWindow`.
pub(crate) const SYM_X_CREATE_SIMPLE_WINDOW: &str = "XCreateSimpleWindow\0";

/// Dynamic symbol for `XStoreName`.
pub(crate) const SYM_X_STORE_NAME: &str = "XStoreName\0";

/// Dynamic symbol for `XMapWindow`.
pub(crate) const SYM_X_MAP_WINDOW: &str = "XMapWindow\0";

/// Dynamic symbol for `XResizeWindow`.
pub(crate) const SYM_X_RESIZE_WINDOW: &str = "XResizeWindow\0";

/// Dynamic symbol for `XDestroyWindow`.
pub(crate) const SYM_X_DESTROY_WINDOW: &str = "XDestroyWindow\0";

/// Dynamic symbol for `XFlush`.
pub(crate) const SYM_X_FLUSH: &str = "XFlush\0";

/// Dynamic symbol for `XDefaultGC`.
pub(crate) const SYM_X_DEFAULT_GC: &str = "XDefaultGC\0";

/// Dynamic symbol for `XDefaultVisual`.
pub(crate) const SYM_X_DEFAULT_VISUAL: &str = "XDefaultVisual\0";

/// Dynamic symbol for `XDefaultDepth`.
pub(crate) const SYM_X_DEFAULT_DEPTH: &str = "XDefaultDepth\0";

/// Dynamic symbol for `XCreateImage`.
pub(crate) const SYM_X_CREATE_IMAGE: &str = "XCreateImage\0";

/// Dynamic symbol for `XPutImage`.
pub(crate) const SYM_X_PUT_IMAGE: &str = "XPutImage\0";

/// Dynamic symbol for `XFree`.
pub(crate) const SYM_X_FREE: &str = "XFree\0";

/// Dynamic symbol for `XSelectInput`.
pub(crate) const SYM_X_SELECT_INPUT: &str = "XSelectInput\0";

/// Dynamic symbol for `XInternAtom`.
pub(crate) const SYM_X_INTERN_ATOM: &str = "XInternAtom\0";

/// Dynamic symbol for `XSetWMProtocols`.
pub(crate) const SYM_X_SET_WM_PROTOCOLS: &str = "XSetWMProtocols\0";

/// Dynamic symbol for `XPending`.
pub(crate) const SYM_X_PENDING: &str = "XPending\0";

/// Dynamic symbol for `XNextEvent`.
pub(crate) const SYM_X_NEXT_EVENT: &str = "XNextEvent\0";

/// Dynamic symbol for `XLookupString`.
pub(crate) const SYM_X_LOOKUP_STRING: &str = "XLookupString\0";

/// Dynamic symbol for `XResourceManagerString`.
pub(crate) const SYM_X_RESOURCE_MANAGER_STRING: &str = "XResourceManagerString\0";

/// Dynamic symbol for `wl_display_connect`.
pub(crate) const SYM_WL_DISPLAY_CONNECT: &str = "wl_display_connect\0";

/// ICCCM atom name for window manager close requests.
pub(crate) const ATOM_WM_DELETE_WINDOW: &str = "WM_DELETE_WINDOW\0";

/// Environment variable names inspected for HiDPI scale overrides on Linux.
pub(crate) const LINUX_DPI_ENV_VARS: [&str; 3] =
    ["EUV_SCALE_FACTOR", "GDK_SCALE", "QT_SCALE_FACTOR"];

/// Xrdb resource key specifying logical DPI on Linux X11 desktops.
pub(crate) const XFT_DPI_PREFIX: &str = "Xft.dpi:";

/// Standard 96 DPI baseline for X11 scale conversion.
pub(crate) const X11_DEFAULT_DPI: f32 = 96.0;

/// POSIX `RTLD_LAZY` flag for `dlopen`.
pub(crate) const RTLD_LAZY: i32 = 1;

/// X11 `ZPixmap` image format identifier.
pub(crate) const X11_Z_PIXMAP: i32 = 2;

/// Combined X11 input mask (`KeyPress | KeyRelease | ButtonPress | ButtonRelease | PointerMotion | Exposure | VisibilityChange | StructureNotify | FocusChange`).
pub(crate) const X11_EVENT_MASK: isize = 0x0023_804F;

/// X11 `KeyPress` event type.
pub(crate) const X11_KEY_PRESS: i32 = 2;

/// X11 `KeyRelease` event type.
pub(crate) const X11_KEY_RELEASE: i32 = 3;

/// X11 `ButtonPress` event type.
pub(crate) const X11_BUTTON_PRESS: i32 = 4;

/// X11 `ButtonRelease` event type.
pub(crate) const X11_BUTTON_RELEASE: i32 = 5;

/// X11 `MotionNotify` event type.
pub(crate) const X11_MOTION_NOTIFY: i32 = 6;

/// X11 `FocusIn` event type.
pub(crate) const X11_FOCUS_IN: i32 = 9;

/// X11 `FocusOut` event type.
pub(crate) const X11_FOCUS_OUT: i32 = 10;

/// X11 `Expose` event type.
pub(crate) const X11_EXPOSE: i32 = 12;

/// X11 `DestroyNotify` event type.
pub(crate) const X11_DESTROY_NOTIFY: i32 = 17;

/// X11 `UnmapNotify` event type.
pub(crate) const X11_UNMAP_NOTIFY: i32 = 18;

/// X11 `MapNotify` event type.
pub(crate) const X11_MAP_NOTIFY: i32 = 19;

/// X11 `ConfigureNotify` event type.
pub(crate) const X11_CONFIGURE_NOTIFY: i32 = 22;

/// X11 `ClientMessage` event type.
pub(crate) const X11_CLIENT_MESSAGE: i32 = 33;

/// X11 modifier mask for Shift.
pub(crate) const X11_SHIFT_MASK: u32 = 1;

/// X11 modifier mask for Control.
pub(crate) const X11_CTRL_MASK: u32 = 4;

/// X11 modifier mask for Alt (`Mod1`).
pub(crate) const X11_ALT_MASK: u32 = 8;

/// X11 modifier mask for Super/Meta (`Mod4`).
pub(crate) const X11_META_MASK: u32 = 64;

/// Error message when neither Wayland nor X11 display server is reachable.
pub(crate) const ERR_LINUX_NO_DISPLAY: &str = "neither X11 nor Wayland display server available";

/// Dynamic symbol for `wl_display_get_error`.
pub(crate) const SYM_WL_DISPLAY_GET_ERROR: &str = "wl_display_get_error\0";

/// Dynamic symbol for `wl_proxy_marshal_flags`.
pub(crate) const SYM_WL_PROXY_MARSHAL_FLAGS: &str = "wl_proxy_marshal_flags\0";

/// Dynamic symbol for `wl_proxy_add_listener`.
pub(crate) const SYM_WL_PROXY_ADD_LISTENER: &str = "wl_proxy_add_listener\0";

/// Dynamic symbol for `wl_proxy_destroy`.
pub(crate) const SYM_WL_PROXY_DESTROY: &str = "wl_proxy_destroy\0";

/// Dynamic symbol for `wl_proxy_get_version`.
pub(crate) const SYM_WL_PROXY_GET_VERSION: &str = "wl_proxy_get_version\0";

/// Exported Wayland protocol descriptor symbol for `wl_registry_interface`.
pub(crate) const SYM_WL_REGISTRY_INTERFACE: &str = "wl_registry_interface\0";

/// Exported Wayland protocol descriptor symbol for `wl_compositor_interface`.
pub(crate) const SYM_WL_COMPOSITOR_INTERFACE: &str = "wl_compositor_interface\0";

/// Exported Wayland protocol descriptor symbol for `wl_surface_interface`.
pub(crate) const SYM_WL_SURFACE_INTERFACE: &str = "wl_surface_interface\0";

/// Exported Wayland protocol descriptor symbol for `wl_shm_interface`.
pub(crate) const SYM_WL_SHM_INTERFACE: &str = "wl_shm_interface\0";

/// Exported Wayland protocol descriptor symbol for `wl_shm_pool_interface`.
pub(crate) const SYM_WL_SHM_POOL_INTERFACE: &str = "wl_shm_pool_interface\0";

/// Exported Wayland protocol descriptor symbol for `wl_buffer_interface`.
pub(crate) const SYM_WL_BUFFER_INTERFACE: &str = "wl_buffer_interface\0";

/// Dynamic symbol for `vkCreateXlibSurfaceKHR` in `libvulkan.so.1`.
pub(crate) const SYM_VK_CREATE_XLIB_SURFACE: &str = "vkCreateXlibSurfaceKHR\0";

/// Dynamic libc symbol for anonymous Linux shared memory (`memfd_create`).
pub(crate) const SYM_MEMFD_CREATE: &str = "memfd_create\0";

/// Wayland registry global interface name for `wl_compositor`.
pub(crate) const WL_IFACE_COMPOSITOR: &str = "wl_compositor";

/// Wayland registry global interface name for `wl_shm`.
pub(crate) const WL_IFACE_SHM: &str = "wl_shm";

/// Anonymous `memfd_create` buffer name for Wayland software presentation.
pub(crate) const WL_MEMFD_NAME: &str = "euv-wayland-shm\0";

/// Fallback `/dev/shm` directory prefix when `memfd_create` is unavailable.
pub(crate) const LINUX_DEV_SHM_PREFIX: &str = "/dev/shm/euv-wl-shm";

/// Wayland `wl_display.get_registry` request opcode.
pub(crate) const WL_OPCODE_DISPLAY_GET_REGISTRY: u32 = 1;

/// Wayland `wl_registry.bind` request opcode.
pub(crate) const WL_OPCODE_REGISTRY_BIND: u32 = 0;

/// Wayland `wl_compositor.create_surface` request opcode.
pub(crate) const WL_OPCODE_COMPOSITOR_CREATE_SURFACE: u32 = 0;

/// Wayland `wl_shm.create_pool` request opcode.
pub(crate) const WL_OPCODE_SHM_CREATE_POOL: u32 = 0;

/// Wayland `wl_shm_pool.create_buffer` request opcode.
pub(crate) const WL_OPCODE_SHM_POOL_CREATE_BUFFER: u32 = 0;

/// Wayland `wl_shm_pool.destroy` request opcode.
pub(crate) const WL_OPCODE_SHM_POOL_DESTROY: u32 = 1;

/// Wayland `wl_buffer.destroy` request opcode.
pub(crate) const WL_OPCODE_BUFFER_DESTROY: u32 = 0;

/// Wayland `wl_surface.attach` request opcode.
pub(crate) const WL_OPCODE_SURFACE_ATTACH: u32 = 1;

/// Wayland `wl_surface.damage` request opcode (surface version < 4 fallback).
pub(crate) const WL_OPCODE_SURFACE_DAMAGE: u32 = 2;

/// Wayland `wl_surface.commit` request opcode.
pub(crate) const WL_OPCODE_SURFACE_COMMIT: u32 = 6;

/// Wayland `wl_surface.set_buffer_scale` request opcode (surface version >= 3).
pub(crate) const WL_OPCODE_SURFACE_SET_BUFFER_SCALE: u32 = 8;

/// Wayland `wl_surface.damage_buffer` request opcode (surface version >= 4).
pub(crate) const WL_OPCODE_SURFACE_DAMAGE_BUFFER: u32 = 9;

/// Minimum `wl_surface` interface version required for `wl_surface.set_buffer_scale`.
pub(crate) const WL_SURFACE_BUFFER_SCALE_MIN_VERSION: u32 = 3;

/// Wayland `WL_MARSHAL_FLAG_DESTROY` flag destroying a client proxy on marshal.
pub(crate) const WL_MARSHAL_FLAG_DESTROY: u32 = 1;

/// Maximum `wl_compositor` protocol version bound for `wl_surface.damage_buffer` support.
pub(crate) const WL_COMPOSITOR_MAX_VERSION: u32 = 4;

/// Maximum `wl_shm` protocol version bound for software pool creation.
pub(crate) const WL_SHM_MAX_VERSION: u32 = 1;

/// POSIX `PROT_READ | PROT_WRITE` protection mask for `mmap`.
pub(crate) const LINUX_MMAP_PROT_RW: i32 = 3;

/// POSIX `MAP_SHARED` flag for `mmap`.
pub(crate) const LINUX_MMAP_SHARED: i32 = 1;

/// Linux `MFD_CLOEXEC` flag for `memfd_create`.
pub(crate) const LINUX_MFD_CLOEXEC: u32 = 1;

/// POSIX `O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC` open flags on Linux (`2 | 64 | 128 | 524288`).
pub(crate) const LINUX_SHM_OPEN_FLAGS: i32 = 524_482;

/// POSIX file mode `0o600` for fallback `/dev/shm` files.
pub(crate) const LINUX_SHM_FILE_MODE: u32 = 0o600;

/// Number of double-buffered Wayland `wl_shm` slots per window.
pub(crate) const WL_SHM_SLOT_COUNT: usize = 2;

/// Error message when Wayland software presentation lacks a live display, surface, or `wl_shm` global.
pub(crate) const ERR_LINUX_WL_SURFACE_MISSING: &str =
    "wayland software presentation missing wl_display, wl_surface, or wl_shm";

/// Error message when POSIX shared-memory allocation (`memfd_create` / `mmap`) fails.
pub(crate) const ERR_LINUX_WL_SHM_ALLOC: &str = "failed to allocate Wayland wl_shm memory mapping";

/// Error message when `wl_shm_pool` or `wl_buffer` creation fails.
pub(crate) const ERR_LINUX_WL_BUFFER_CREATE: &str =
    "failed to create Wayland wl_shm_pool or wl_buffer";

/// Error message when all double-buffered Wayland shm slots are still busy awaiting `wl_buffer.release`.
pub(crate) const ERR_LINUX_WL_NO_FREE_BUFFER: &str =
    "no free Wayland wl_shm buffer slot available (all buffers busy)";

/// Error message when `wl_display_flush` or `wl_display_get_error` reports a compositor failure.
pub(crate) const ERR_LINUX_WL_DISPLAY_FLUSH: &str =
    "wayland surface commit or wl_display_flush failed";

/// Error message when framebuffer pixel dimensions or backing slice are invalid for presentation.
pub(crate) const ERR_LINUX_INVALID_FRAMEBUFFER: &str =
    "invalid framebuffer dimensions or truncated pixel buffer";

/// Error message when X11 presentation lacks a valid `Display*`, `Window`, `GC`, or `Visual*`.
pub(crate) const ERR_LINUX_X11_SURFACE_MISSING: &str =
    "X11 presentation missing Display, Window, GC, Visual, or XPutImage symbols";

/// Error message when direct GPU presentation is requested without available Vulkan WSI surface support.
pub(crate) const ERR_LINUX_GPU_DIRECT_UNAVAILABLE: &str =
    "Linux direct GPU presentation requires active Vulkan WSI or EGL/GLES3 surface support";

/// Error message when Linux dynamic EGL/GLES3 initialization or swap fails.
pub(crate) const ERR_LINUX_EGL_UNAVAILABLE: &str =
    "Linux dynamic libEGL.so.1 / libGLESv2.so.2 presentation unavailable";

/// Shared library name for dynamic EGL loading on Linux.
pub(crate) const LINUX_LIB_EGL: &str = "libEGL.so.1\0";

/// Shared library name for dynamic OpenGL ES 3 loading on Linux.
pub(crate) const LINUX_LIB_GLESV2: &str = "libGLESv2.so.2\0";

/// Shared library name for dynamic Wayland EGL window bindings on Linux.
pub(crate) const LINUX_LIB_WAYLAND_EGL: &str = "libwayland-egl.so.1\0";

/// Dynamic Xlib symbol returning the underlying socket file descriptor for `poll()`.
pub(crate) const SYM_X_CONNECTION_NUMBER: &str = "XConnectionNumber\0";

/// Dynamic Wayland symbol returning the compositor socket file descriptor for `poll()`.
pub(crate) const SYM_WL_DISPLAY_GET_FD: &str = "wl_display_get_fd\0";

/// Dynamic Wayland symbol preparing a thread-safe `poll()` read on `wl_display`.
pub(crate) const SYM_WL_DISPLAY_PREPARE_READ: &str = "wl_display_prepare_read\0";

/// Dynamic Wayland symbol reading events from the Wayland socket after `poll()`.
pub(crate) const SYM_WL_DISPLAY_READ_EVENTS: &str = "wl_display_read_events\0";

/// Dynamic Wayland symbol canceling a prepared read when `poll()` woke on another fd.
pub(crate) const SYM_WL_DISPLAY_CANCEL_READ: &str = "wl_display_cancel_read\0";

/// Exported Wayland protocol descriptor symbol for `wl_callback_interface`.
pub(crate) const SYM_WL_CALLBACK_INTERFACE: &str = "wl_callback_interface\0";

/// Wayland `wl_surface.frame` request opcode (`3`) for compositor VSync pacing.
pub(crate) const WL_OPCODE_SURFACE_FRAME: u32 = 3;

/// POSIX `POLLIN` event bit (`0x0001`).
pub(crate) const LINUX_POLLIN: i16 = 0x0001;

/// Linux `O_NONBLOCK | O_CLOEXEC` flags (`0x0008_0800`) for `pipe2`.
pub(crate) const LINUX_PIPE_NONBLOCK_CLOEXEC: i32 = 0x0008_0800;

/// Dynamic EGL symbol `eglGetDisplay`.
pub(crate) const SYM_EGL_GET_DISPLAY: &str = "eglGetDisplay\0";

/// Dynamic EGL symbol `eglInitialize`.
pub(crate) const SYM_EGL_INITIALIZE: &str = "eglInitialize\0";

/// Dynamic EGL symbol `eglBindAPI`.
pub(crate) const SYM_EGL_BIND_API: &str = "eglBindAPI\0";

/// Dynamic EGL symbol `eglChooseConfig`.
pub(crate) const SYM_EGL_CHOOSE_CONFIG: &str = "eglChooseConfig\0";

/// Dynamic EGL symbol `eglCreateContext`.
pub(crate) const SYM_EGL_CREATE_CONTEXT: &str = "eglCreateContext\0";

/// Dynamic EGL symbol `eglCreateWindowSurface`.
pub(crate) const SYM_EGL_CREATE_WINDOW_SURFACE: &str = "eglCreateWindowSurface\0";

/// Dynamic EGL symbol `eglMakeCurrent`.
pub(crate) const SYM_EGL_MAKE_CURRENT: &str = "eglMakeCurrent\0";

/// Dynamic EGL symbol `eglSwapInterval`.
pub(crate) const SYM_EGL_SWAP_INTERVAL: &str = "eglSwapInterval\0";

/// Dynamic EGL symbol `eglSwapBuffers`.
pub(crate) const SYM_EGL_SWAP_BUFFERS: &str = "eglSwapBuffers\0";

/// Dynamic EGL symbol `eglDestroySurface`.
pub(crate) const SYM_EGL_DESTROY_SURFACE: &str = "eglDestroySurface\0";

/// Dynamic EGL symbol `eglDestroyContext`.
pub(crate) const SYM_EGL_DESTROY_CONTEXT: &str = "eglDestroyContext\0";

/// Dynamic EGL symbol `eglTerminate`.
pub(crate) const SYM_EGL_TERMINATE: &str = "eglTerminate\0";

/// Dynamic Wayland-EGL symbol `wl_egl_window_create`.
pub(crate) const SYM_WL_EGL_WINDOW_CREATE: &str = "wl_egl_window_create\0";

/// Dynamic Wayland-EGL symbol `wl_egl_window_resize`.
pub(crate) const SYM_WL_EGL_WINDOW_RESIZE: &str = "wl_egl_window_resize\0";

/// Dynamic Wayland-EGL symbol `wl_egl_window_destroy`.
pub(crate) const SYM_WL_EGL_WINDOW_DESTROY: &str = "wl_egl_window_destroy\0";

/// Dynamic GLES3 symbol `glCreateShader`.
pub(crate) const SYM_GL_CREATE_SHADER: &str = "glCreateShader\0";

/// Dynamic GLES3 symbol `glShaderSource`.
pub(crate) const SYM_GL_SHADER_SOURCE: &str = "glShaderSource\0";

/// Dynamic GLES3 symbol `glCompileShader`.
pub(crate) const SYM_GL_COMPILE_SHADER: &str = "glCompileShader\0";

/// Dynamic GLES3 symbol `glGetShaderiv`.
pub(crate) const SYM_GL_GET_SHADERIV: &str = "glGetShaderiv\0";

/// Dynamic GLES3 symbol `glDeleteShader`.
pub(crate) const SYM_GL_DELETE_SHADER: &str = "glDeleteShader\0";

/// Dynamic GLES3 symbol `glCreateProgram`.
pub(crate) const SYM_GL_CREATE_PROGRAM: &str = "glCreateProgram\0";

/// Dynamic GLES3 symbol `glAttachShader`.
pub(crate) const SYM_GL_ATTACH_SHADER: &str = "glAttachShader\0";

/// Dynamic GLES3 symbol `glLinkProgram`.
pub(crate) const SYM_GL_LINK_PROGRAM: &str = "glLinkProgram\0";

/// Dynamic GLES3 symbol `glGetProgramiv`.
pub(crate) const SYM_GL_GET_PROGRAMIV: &str = "glGetProgramiv\0";

/// Dynamic GLES3 symbol `glDeleteProgram`.
pub(crate) const SYM_GL_DELETE_PROGRAM: &str = "glDeleteProgram\0";

/// Dynamic GLES3 symbol `glUseProgram`.
pub(crate) const SYM_GL_USE_PROGRAM: &str = "glUseProgram\0";

/// Dynamic GLES3 symbol `glGetUniformLocation`.
pub(crate) const SYM_GL_GET_UNIFORM_LOCATION: &str = "glGetUniformLocation\0";

/// Dynamic GLES3 symbol `glUniform1i`.
pub(crate) const SYM_GL_UNIFORM1I: &str = "glUniform1i\0";

/// Dynamic GLES3 symbol `glUniform2f`.
pub(crate) const SYM_GL_UNIFORM2F: &str = "glUniform2f\0";

/// Dynamic GLES3 symbol `glGenVertexArrays`.
pub(crate) const SYM_GL_GEN_VERTEX_ARRAYS: &str = "glGenVertexArrays\0";

/// Dynamic GLES3 symbol `glBindVertexArray`.
pub(crate) const SYM_GL_BIND_VERTEX_ARRAY: &str = "glBindVertexArray\0";

/// Dynamic GLES3 symbol `glDeleteVertexArrays`.
pub(crate) const SYM_GL_DELETE_VERTEX_ARRAYS: &str = "glDeleteVertexArrays\0";

/// Dynamic GLES3 symbol `glGenBuffers`.
pub(crate) const SYM_GL_GEN_BUFFERS: &str = "glGenBuffers\0";

/// Dynamic GLES3 symbol `glBindBuffer`.
pub(crate) const SYM_GL_BIND_BUFFER: &str = "glBindBuffer\0";

/// Dynamic GLES3 symbol `glBufferData`.
pub(crate) const SYM_GL_BUFFER_DATA: &str = "glBufferData\0";

/// Dynamic GLES3 symbol `glBufferSubData`.
pub(crate) const SYM_GL_BUFFER_SUB_DATA: &str = "glBufferSubData\0";

/// Dynamic GLES3 symbol `glDeleteBuffers`.
pub(crate) const SYM_GL_DELETE_BUFFERS: &str = "glDeleteBuffers\0";

/// Dynamic GLES3 symbol `glEnableVertexAttribArray`.
pub(crate) const SYM_GL_ENABLE_VERTEX_ATTRIB_ARRAY: &str = "glEnableVertexAttribArray\0";

/// Dynamic GLES3 symbol `glVertexAttribPointer`.
pub(crate) const SYM_GL_VERTEX_ATTRIB_POINTER: &str = "glVertexAttribPointer\0";

/// Dynamic GLES3 symbol `glVertexAttribIPointer`.
pub(crate) const SYM_GL_VERTEX_ATTRIB_IPOINTER: &str = "glVertexAttribIPointer\0";

/// Dynamic GLES3 symbol `glVertexAttribDivisor`.
pub(crate) const SYM_GL_VERTEX_ATTRIB_DIVISOR: &str = "glVertexAttribDivisor\0";

/// Dynamic GLES3 symbol `glGenTextures`.
pub(crate) const SYM_GL_GEN_TEXTURES: &str = "glGenTextures\0";

/// Dynamic GLES3 symbol `glBindTexture`.
pub(crate) const SYM_GL_BIND_TEXTURE: &str = "glBindTexture\0";

/// Dynamic GLES3 symbol `glTexParameteri`.
pub(crate) const SYM_GL_TEX_PARAMETERI: &str = "glTexParameteri\0";

/// Dynamic GLES3 symbol `glTexStorage2D`.
pub(crate) const SYM_GL_TEX_STORAGE_2D: &str = "glTexStorage2D\0";

/// Dynamic GLES3 symbol `glTexImage2D`.
pub(crate) const SYM_GL_TEX_IMAGE_2D: &str = "glTexImage2D\0";

/// Dynamic GLES3 symbol `glTexSubImage2D`.
pub(crate) const SYM_GL_TEX_SUB_IMAGE_2D: &str = "glTexSubImage2D\0";

/// Dynamic GLES3 symbol `glDeleteTextures`.
pub(crate) const SYM_GL_DELETE_TEXTURES: &str = "glDeleteTextures\0";

/// Dynamic GLES3 symbol `glActiveTexture`.
pub(crate) const SYM_GL_ACTIVE_TEXTURE: &str = "glActiveTexture\0";

/// Dynamic GLES3 symbol `glPixelStorei`.
pub(crate) const SYM_GL_PIXEL_STOREI: &str = "glPixelStorei\0";

/// Dynamic GLES3 symbol `glViewport`.
pub(crate) const SYM_GL_VIEWPORT: &str = "glViewport\0";

/// Dynamic GLES3 symbol `glEnable`.
pub(crate) const SYM_GL_ENABLE: &str = "glEnable\0";

/// Dynamic GLES3 symbol `glDisable`.
pub(crate) const SYM_GL_DISABLE: &str = "glDisable\0";

/// Dynamic GLES3 symbol `glBlendFuncSeparate`.
pub(crate) const SYM_GL_BLEND_FUNC_SEPARATE: &str = "glBlendFuncSeparate\0";

/// Dynamic GLES3 symbol `glScissor`.
pub(crate) const SYM_GL_SCISSOR: &str = "glScissor\0";

/// Dynamic GLES3 symbol `glClearColor`.
pub(crate) const SYM_GL_CLEAR_COLOR: &str = "glClearColor\0";

/// Dynamic GLES3 symbol `glClear`.
pub(crate) const SYM_GL_CLEAR: &str = "glClear\0";

/// Dynamic GLES3 symbol `glDrawArraysInstanced`.
pub(crate) const SYM_GL_DRAW_ARRAYS_INSTANCED: &str = "glDrawArraysInstanced\0";

/// Dynamic GLES3 symbol `glDrawArrays`.
pub(crate) const SYM_GL_DRAW_ARRAYS: &str = "glDrawArrays\0";

/// Dynamic GLES3 symbol `glUniform4f`.
pub(crate) const SYM_GL_UNIFORM4F: &str = "glUniform4f\0";

/// Dynamic GLES3 symbol `glUniformMatrix4fv`.
pub(crate) const SYM_GL_UNIFORM_MATRIX4FV: &str = "glUniformMatrix4fv\0";

/// Dynamic GLES3 symbol `glGetIntegerv`.
pub(crate) const SYM_GL_GET_INTEGERV: &str = "glGetIntegerv\0";

/// Dynamic GLES3 symbol `glGenFramebuffers`.
pub(crate) const SYM_GL_GEN_FRAMEBUFFERS: &str = "glGenFramebuffers\0";

/// Dynamic GLES3 symbol `glBindFramebuffer`.
pub(crate) const SYM_GL_BIND_FRAMEBUFFER: &str = "glBindFramebuffer\0";

/// Dynamic GLES3 symbol `glFramebufferTexture2D`.
pub(crate) const SYM_GL_FRAMEBUFFER_TEXTURE_2D: &str = "glFramebufferTexture2D\0";

/// Dynamic GLES3 symbol `glDeleteFramebuffers`.
pub(crate) const SYM_GL_DELETE_FRAMEBUFFERS: &str = "glDeleteFramebuffers\0";

/// Dynamic GLES3 symbol `glGenRenderbuffers`.
pub(crate) const SYM_GL_GEN_RENDERBUFFERS: &str = "glGenRenderbuffers\0";

/// Dynamic GLES3 symbol `glBindRenderbuffer`.
pub(crate) const SYM_GL_BIND_RENDERBUFFER: &str = "glBindRenderbuffer\0";

/// Dynamic GLES3 symbol `glRenderbufferStorage`.
pub(crate) const SYM_GL_RENDERBUFFER_STORAGE: &str = "glRenderbufferStorage\0";

/// Dynamic GLES3 symbol `glFramebufferRenderbuffer`.
pub(crate) const SYM_GL_FRAMEBUFFER_RENDERBUFFER: &str = "glFramebufferRenderbuffer\0";

/// Dynamic GLES3 symbol `glDeleteRenderbuffers`.
pub(crate) const SYM_GL_DELETE_RENDERBUFFERS: &str = "glDeleteRenderbuffers\0";

/// Dynamic GLES3 symbol `glDepthMask`.
pub(crate) const SYM_GL_DEPTH_MASK: &str = "glDepthMask\0";

/// Dynamic GLES3 symbol `glDepthFunc`.
pub(crate) const SYM_GL_DEPTH_FUNC: &str = "glDepthFunc\0";

/// Dynamic GLES3 symbol `glClearDepthf`.
pub(crate) const SYM_GL_CLEAR_DEPTHF: &str = "glClearDepthf\0";

/// GLSL ES3 scene uniform `u_wake_tex`.
pub(crate) const LINUX_GL_UNIFORM_WAKE_TEX: &str = "u_wake_tex\0";

/// GLSL ES3 scene uniform `u_time_agit_hor_aspect`.
pub(crate) const LINUX_GL_UNIFORM_OCEAN_TIME: &str = "u_time_agit_hor_aspect\0";

/// GLSL ES3 scene uniform `u_roll_boat_uv`.
pub(crate) const LINUX_GL_UNIFORM_OCEAN_ROLL: &str = "u_roll_boat_uv\0";

/// GLSL ES3 scene uniform `u_sun_dir_wake`.
pub(crate) const LINUX_GL_UNIFORM_OCEAN_SUN: &str = "u_sun_dir_wake\0";

/// GLSL ES3 scene uniform `u_camera_pos`.
pub(crate) const LINUX_GL_UNIFORM_CAM_POS: &str = "u_camera_pos\0";

/// GLSL ES3 scene uniform `u_sun_dir_fog`.
pub(crate) const LINUX_GL_UNIFORM_SUN_FOG: &str = "u_sun_dir_fog\0";

/// GLSL ES3 scene uniform `u_sun_color_ambient`.
pub(crate) const LINUX_GL_UNIFORM_SUN_COL: &str = "u_sun_color_ambient\0";

/// GLSL ES3 scene uniform `u_sky_horizon_tod`.
pub(crate) const LINUX_GL_UNIFORM_SKY_HOR: &str = "u_sky_horizon_tod\0";

/// GLSL ES3 scene uniform `u_sky_zenith_aspect`.
pub(crate) const LINUX_GL_UNIFORM_SKY_ZEN: &str = "u_sky_zenith_aspect\0";

/// GLSL ES3 scene uniform `u_view_proj`.
pub(crate) const LINUX_GL_UNIFORM_VIEW_PROJ: &str = "u_view_proj\0";

/// GLSL ES3 uniform name `u_viewport`.
pub(crate) const LINUX_GL_UNIFORM_VIEWPORT: &str = "u_viewport\0";

/// GLSL ES3 uniform name `u_scroll_offset`.
pub(crate) const LINUX_GL_UNIFORM_SCROLL_OFFSET: &str = "u_scroll_offset\0";

/// GLSL ES3 sampler uniform `u_glyph_r8`.
pub(crate) const LINUX_GL_UNIFORM_GLYPH_R8: &str = "u_glyph_r8\0";

/// GLSL ES3 sampler uniform `u_glyph_rgba8`.
pub(crate) const LINUX_GL_UNIFORM_GLYPH_RGBA8: &str = "u_glyph_rgba8\0";

/// GLSL ES3 sampler uniform `u_image_tex`.
pub(crate) const LINUX_GL_UNIFORM_IMAGE_TEX: &str = "u_image_tex\0";

/// GLSL ES3 sampler uniform `u_external_tex`.
pub(crate) const LINUX_GL_UNIFORM_EXTERNAL_TEX: &str = "u_external_tex\0";

/// `EGL_OPENGL_ES_API` (`0x30A0`).
pub(crate) const LINUX_EGL_OPENGL_ES_API: u32 = 0x30A0;

/// `EGL_SURFACE_TYPE` (`0x3033`).
pub(crate) const LINUX_EGL_SURFACE_TYPE: i32 = 0x3033;

/// `EGL_WINDOW_BIT` (`0x0004`).
pub(crate) const LINUX_EGL_WINDOW_BIT: i32 = 0x0004;

/// `EGL_RENDERABLE_TYPE` (`0x3040`).
pub(crate) const LINUX_EGL_RENDERABLE_TYPE: i32 = 0x3040;

/// `EGL_OPENGL_ES3_BIT` (`0x0040`).
pub(crate) const LINUX_EGL_OPENGL_ES3_BIT: i32 = 0x0040;

/// `EGL_RED_SIZE` (`0x3024`).
pub(crate) const LINUX_EGL_RED_SIZE: i32 = 0x3024;

/// `EGL_GREEN_SIZE` (`0x3023`).
pub(crate) const LINUX_EGL_GREEN_SIZE: i32 = 0x3023;

/// `EGL_BLUE_SIZE` (`0x3022`).
pub(crate) const LINUX_EGL_BLUE_SIZE: i32 = 0x3022;

/// `EGL_ALPHA_SIZE` (`0x3021`).
pub(crate) const LINUX_EGL_ALPHA_SIZE: i32 = 0x3021;

/// `EGL_NONE` (`0x3038`).
pub(crate) const LINUX_EGL_NONE: i32 = 0x3038;

/// `EGL_CONTEXT_CLIENT_VERSION` (`0x3098`).
pub(crate) const LINUX_EGL_CONTEXT_CLIENT_VERSION: i32 = 0x3098;

/// `GL_VERTEX_SHADER` (`0x8B31`).
pub(crate) const LINUX_GL_VERTEX_SHADER: u32 = 0x8B31;

/// `GL_FRAGMENT_SHADER` (`0x8B30`).
pub(crate) const LINUX_GL_FRAGMENT_SHADER: u32 = 0x8B30;

/// `GL_COMPILE_STATUS` (`0x8B81`).
pub(crate) const LINUX_GL_COMPILE_STATUS: u32 = 0x8B81;

/// `GL_LINK_STATUS` (`0x8B82`).
pub(crate) const LINUX_GL_LINK_STATUS: u32 = 0x8B82;

/// `GL_ARRAY_BUFFER` (`0x8892`).
pub(crate) const LINUX_GL_ARRAY_BUFFER: u32 = 0x8892;

/// `GL_STATIC_DRAW` (`0x88E4`).
pub(crate) const LINUX_GL_STATIC_DRAW: u32 = 0x88E4;

/// `GL_STREAM_DRAW` (`0x88E0`).
pub(crate) const LINUX_GL_STREAM_DRAW: u32 = 0x88E0;

/// `GL_TRIANGLES` (`0x0004`).
pub(crate) const LINUX_GL_TRIANGLES: u32 = 0x0004;

/// `GL_FLOAT` (`0x1406`).
pub(crate) const LINUX_GL_FLOAT: u32 = 0x1406;

/// `GL_UNSIGNED_INT` (`0x1405`).
pub(crate) const LINUX_GL_UNSIGNED_INT: u32 = 0x1405;

/// `GL_UNSIGNED_BYTE` (`0x1401`).
pub(crate) const LINUX_GL_UNSIGNED_BYTE: u32 = 0x1401;

/// `GL_TEXTURE_2D` (`0x0DE1`).
pub(crate) const LINUX_GL_TEXTURE_2D: u32 = 0x0DE1;

/// `GL_TEXTURE0` (`0x84C0`).
pub(crate) const LINUX_GL_TEXTURE0: u32 = 0x84C0;

/// `GL_TEXTURE1` (`0x84C1`).
pub(crate) const LINUX_GL_TEXTURE1: u32 = 0x84C1;

/// `GL_TEXTURE2` (`0x84C2`).
pub(crate) const LINUX_GL_TEXTURE2: u32 = 0x84C2;

/// `GL_TEXTURE3` (`0x84C3`).
pub(crate) const LINUX_GL_TEXTURE3: u32 = 0x84C3;

/// `GL_TEXTURE_MIN_FILTER` (`0x2801`).
pub(crate) const LINUX_GL_TEXTURE_MIN_FILTER: u32 = 0x2801;

/// `GL_TEXTURE_MAG_FILTER` (`0x2800`).
pub(crate) const LINUX_GL_TEXTURE_MAG_FILTER: u32 = 0x2800;

/// `GL_TEXTURE_WRAP_S` (`0x2802`).
pub(crate) const LINUX_GL_TEXTURE_WRAP_S: u32 = 0x2802;

/// `GL_TEXTURE_WRAP_T` (`0x2803`).
pub(crate) const LINUX_GL_TEXTURE_WRAP_T: u32 = 0x2803;

/// `GL_LINEAR` (`0x2601`).
pub(crate) const LINUX_GL_LINEAR: i32 = 0x2601;

/// `GL_CLAMP_TO_EDGE` (`0x812F`).
pub(crate) const LINUX_GL_CLAMP_TO_EDGE: i32 = 0x812F;

/// `GL_R8` (`0x8229`).
pub(crate) const LINUX_GL_R8: u32 = 0x8229;

/// `GL_RED` (`0x1903`).
pub(crate) const LINUX_GL_RED: u32 = 0x1903;

/// `GL_RGBA8` (`0x8058`).
pub(crate) const LINUX_GL_RGBA8: u32 = 0x8058;

/// `GL_RGBA` (`0x1908`).
pub(crate) const LINUX_GL_RGBA: u32 = 0x1908;

/// `GL_UNPACK_ALIGNMENT` (`0x0CF5`).
pub(crate) const LINUX_GL_UNPACK_ALIGNMENT: u32 = 0x0CF5;

/// `GL_UNPACK_ROW_LENGTH` (`0x0CF2`).
pub(crate) const LINUX_GL_UNPACK_ROW_LENGTH: u32 = 0x0CF2;

/// `GL_BLEND` (`0x0BE2`).
pub(crate) const LINUX_GL_BLEND: u32 = 0x0BE2;

/// `GL_SCISSOR_TEST` (`0x0C11`).
pub(crate) const LINUX_GL_SCISSOR_TEST: u32 = 0x0C11;

/// `GL_SRC_ALPHA` (`0x0302`).
pub(crate) const LINUX_GL_SRC_ALPHA: u32 = 0x0302;

/// `GL_ONE_MINUS_SRC_ALPHA` (`0x0303`).
pub(crate) const LINUX_GL_ONE_MINUS_SRC_ALPHA: u32 = 0x0303;

/// `GL_ONE` (`1`).
pub(crate) const LINUX_GL_ONE: u32 = 1;

/// `GL_COLOR_BUFFER_BIT` (`0x4000`).
pub(crate) const LINUX_GL_COLOR_BUFFER_BIT: u32 = 0x4000;

/// `GL_DEPTH_BUFFER_BIT` (`0x0100`).
pub(crate) const LINUX_GL_DEPTH_BUFFER_BIT: u32 = 0x0100;

/// `GL_DEPTH_TEST` (`0x0B71`).
pub(crate) const LINUX_GL_DEPTH_TEST: u32 = 0x0B71;

/// `GL_LESS` (`0x0201`).
pub(crate) const LINUX_GL_LESS: u32 = 0x0201;

/// `GL_FRAMEBUFFER` (`0x8D40`).
pub(crate) const LINUX_GL_FRAMEBUFFER: u32 = 0x8D40;

/// `GL_RENDERBUFFER` (`0x8D41`).
pub(crate) const LINUX_GL_RENDERBUFFER: u32 = 0x8D41;

/// `GL_COLOR_ATTACHMENT0` (`0x8CE0`).
pub(crate) const LINUX_GL_COLOR_ATTACHMENT0: u32 = 0x8CE0;

/// `GL_DEPTH_ATTACHMENT` (`0x8D00`).
pub(crate) const LINUX_GL_DEPTH_ATTACHMENT: u32 = 0x8D00;

/// `GL_DEPTH_COMPONENT24` (`0x81A6`).
pub(crate) const LINUX_GL_DEPTH_COMPONENT24: u32 = 0x81A6;

/// `GL_MAX_TEXTURE_SIZE` (`0x0D33`).
pub(crate) const LINUX_GL_MAX_TEXTURE_SIZE: u32 = 0x0D33;

/// `GL_UNPACK_SKIP_ROWS` (`0x0CF3`).
pub(crate) const LINUX_GL_UNPACK_SKIP_ROWS: u32 = 0x0CF3;

/// `GL_UNPACK_SKIP_PIXELS` (`0x0CF4`).
pub(crate) const LINUX_GL_UNPACK_SKIP_PIXELS: u32 = 0x0CF4;

/// Unit quad triangle corners matching `GLSL_ES3_UI_VERTEX_SHADER` attribute location `0`.
pub(crate) const LINUX_GL_UNIT_QUAD: [f32; 12] =
    [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0];

/// Hardware GLSL ES 3.0 full-screen triangle vertex shader for offscreen Linux GPU scene passes.
pub(crate) const LINUX_GL_SCENE_FULLSCREEN_VERT: &str = "#version 300 es\n\
precision highp float;\n\
precision highp int;\n\
out highp vec2 v_uv;\n\
void main() {\n\
    vec2 p = vec2((gl_VertexID == 1) ? 3.0 : -1.0, (gl_VertexID == 2) ? 3.0 : -1.0);\n\
    gl_Position = vec4(p, 0.0, 1.0);\n\
    v_uv = vec2(p.x * 0.5 + 0.5, 0.5 - p.y * 0.5);\n\
}\n";

/// Hardware GLSL ES 3.0 8-wave isotropic Nyquist-AA Gerstner ocean, C2 quintic storm sky, Toksvig dual-lobe GGX sun glitter, PBF wake, and hull foam fragment shader.
pub(crate) const LINUX_GL_SCENE_OCEAN_FRAG: &str = r#"#version 300 es
precision highp float;
precision highp int;
precision highp sampler2D;
in highp vec2 v_uv;
uniform highp vec4 u_time_agit_hor_aspect;
uniform highp vec4 u_roll_boat_uv;
uniform highp vec4 u_sun_dir_wake;
uniform highp sampler2D u_wake_tex;
out vec4 out_color;
const vec4 EUV_OCEAN_WAVES[8] = vec4[8](
    vec4( 0.2419,  0.9703,  0.56, 0.205),
    vec4(-0.5592,  0.8290,  0.94, 0.145),
    vec4( 0.7986,  0.6018,  1.58, 0.092),
    vec4(-0.9455,  0.3256,  2.63, 0.056),
    vec4( 0.5299,  0.8480,  4.38, 0.034),
    vec4(-0.7880, -0.6157,  7.21, 0.021),
    vec4( 0.7314, -0.6820, 11.85, 0.013),
    vec4(-0.3746,  0.9272, 19.30, 0.0078)
);
const float EUV_OCEAN_SPEEDS[8] = float[8](0.84, 1.12, 1.48, 1.92, 2.46, 3.08, 3.82, 4.68);
vec3 euv_aces(vec3 hdr) {
    vec3 x = max(hdr, vec3(0.0));
    float luma = dot(x, vec3(0.2126, 0.7152, 0.0722));
    float sat_roll = 1.0 / (1.0 + luma * 0.14);
    vec3 agx_in = mix(vec3(luma), x, 0.78 + 0.22 * sat_roll);
    vec3 num = agx_in * (2.51 * agx_in + 0.03);
    vec3 den = agx_in * (2.43 * agx_in + 0.59) + 0.14;
    return pow(clamp(num / max(den, vec3(0.0001)), vec3(0.0), vec3(1.0)), vec3(1.0 / 2.2));
}
float euv_hash_i2(ivec2 cell) {
    uint n = uint(cell.x) * 374761393u + uint(cell.y) * 668265263u;
    n = (n ^ (n >> 13u)) * 1274126177u;
    n ^= n >> 16u;
    return float(n & 0x00FFFFFFu) * (1.0 / 16777215.0);
}
float euv_noise(vec2 p) {
    vec2 fl = floor(p);
    vec2 f = p - fl;
    vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
    ivec2 i = ivec2(fl);
    float a = euv_hash_i2(i);
    float b = euv_hash_i2(i + ivec2(1, 0));
    float c = euv_hash_i2(i + ivec2(0, 1));
    float d = euv_hash_i2(i + ivec2(1, 1));
    return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
float euv_cloud_fbm(vec2 p, int octs) {
    float val = 0.0;
    float amp = 0.54;
    vec2 q = p;
    for (int i = 0; i < 4; ++i) {
        if (i >= octs) {
            break;
        }
        val += euv_noise(q) * amp;
        q = vec2(q.x * 1.92 - q.y * 0.58 + 3.1, q.x * 0.58 + q.y * 1.92 - 1.7);
        amp *= 0.50;
    }
    return clamp(val, 0.0, 1.0);
}
vec3 euv_sky(vec3 ray, vec3 sun_dir, vec2 sun_az_dir, float sim_time, bool high_detail) {
    float ry = max(ray.y, 0.0);
    float sdot = clamp(dot(ray, sun_dir), 0.0, 1.0);
    float sp2 = sdot * sdot;
    float sp4 = sp2 * sp2;
    float sp16 = sp4 * sp4 * sp4 * sp4;
    float sp64 = sp16 * sp16 * sp16 * sp16;
    float az_d = clamp(dot(normalize(vec2(ray.x, ray.z)), sun_az_dir), 0.0, 1.0);
    float az2 = az_d * az_d;
    float sun_az_glow = az2 * az2;
    float disk = smoothstep(0.99905, 0.99968, sdot);
    float corona = exp(-(1.0 - sdot) * 460.0);
    float sky_t = smoothstep(0.0, 0.56, ry);
    vec3 horiz = vec3(0.14, 0.13, 0.17) + vec3(0.76, 0.40, 0.17) * sp16 + vec3(1.18, 0.82, 0.44) * sp64;
    vec3 zenith = vec3(0.010, 0.022, 0.048);
    vec3 base_sky = mix(horiz, zenith, sky_t);
    float horiz_clear = smoothstep(0.002, 0.035, ry);
    if (horiz_clear > 0.001) {
        float strat_y = pow(ry, 0.62) * 3.95;
        vec2 base_c = vec2(ray.x * (1.68 + 0.42 * (1.0 - min(ry, 1.0))) + sim_time * 0.015, strat_y * 2.28 + sim_time * 0.007);
        float warp_a = euv_noise(base_c * vec2(0.62, 0.72) + vec2(3.1, -1.4));
        float warp_b = high_detail ? euv_noise(base_c * vec2(1.60, 1.85) + vec2(-2.3, 5.7)) : 0.5;
        vec2 c_uv = base_c + vec2((warp_a - 0.5) * 1.10 + (warp_b - 0.5) * 0.36, (warp_a - 0.5) * 0.62 - (warp_b - 0.5) * 0.20);
        float cloud_raw = euv_cloud_fbm(c_uv, high_detail ? 4 : 2);
        float billow = 0.0;
        float wisp_ridge = 0.0;
        if (high_detail) {
            float g1 = euv_noise(c_uv * vec2(3.10, 4.40) + vec2(8.4, -3.9));
            float r_raw = 1.0 - abs(euv_noise(c_uv * vec2(5.2, 8.4) + vec2(1.9, -2.6)) * 2.0 - 1.0);
            billow = g1 * 0.14;
            wisp_ridge = r_raw * r_raw * 0.09;
        }
        float cloud_field = clamp(cloud_raw * 0.78 + billow + wisp_ridge, 0.0, 1.0);
        float overhead = smoothstep(0.04, 0.26, ry);
        float clearing = sun_az_glow * exp(-ry * 7.0) * 0.56;
        float cloud_cov = smoothstep(0.25, 0.68, cloud_field + overhead * 0.34 - clearing);
        float cloud_dark = (0.52 + 0.40 * overhead) * cloud_cov;
        float rim_sample = high_detail ? euv_cloud_fbm(c_uv + vec2(sun_dir.x * 0.32, 0.18), 2) : (cloud_field * 0.90);
        float edge_lacy = 1.0 - abs(cloud_cov * 2.0 - 1.0);
        float sun_lit_edge = (clamp((cloud_field - rim_sample) * 3.0 + 0.12, 0.0, 1.0) + edge_lacy * edge_lacy * 0.36) * (0.16 + 0.84 * sun_az_glow) * (1.0 - overhead * 0.58);
        float wisp_tex = high_detail ? ((cloud_field - 0.5) * 0.042 + wisp_ridge * 0.12) : 0.0;
        vec3 cloud_col = high_detail
            ? max(vec3(0.006, 0.010, 0.018), vec3(0.012, 0.018, 0.028) + vec3(0.046, 0.056, 0.076) * (1.0 - cloud_dark) + vec3(0.82, 0.94, 1.08) * wisp_tex + vec3(0.84 + 0.54 * sp4, 0.58 + 0.36 * sp4, 0.30 + 0.16 * sp4) * sun_lit_edge)
            : (vec3(0.004, 0.018, 0.036) + vec3(0.016, 0.056, 0.094) * (1.0 - cloud_dark) + vec3(0.42 + 0.26 * sp4, 0.34 + 0.20 * sp4, 0.24 + 0.14 * sp4) * sun_lit_edge);
        float cloud_alpha = clamp(cloud_cov * (0.72 + 0.24 * overhead) * horiz_clear, 0.0, 0.96);
        base_sky = mix(base_sky, cloud_col, cloud_alpha);
    }
    if (high_detail) {
        base_sky += vec3(4.2, 3.35, 2.30) * disk + vec3(1.15, 0.78, 0.42) * (corona * 0.95);
    }
    return base_sky;
}
void main() {
    const float INV_TAU = 0.15915494;
    const float TAU = 6.283185307;
    float sim_time = u_time_agit_hor_aspect.x;
    float agitation = max(u_time_agit_hor_aspect.y, 1.0);
    float horizon_v = u_time_agit_hor_aspect.z;
    float aspect = max(u_time_agit_hor_aspect.w, 0.25);
    float roll_cos = u_roll_boat_uv.x;
    float roll_sin = u_roll_boat_uv.y;
    vec2 boat_uv = u_roll_boat_uv.zw;
    vec3 sun_dir = normalize(u_sun_dir_wake.xyz);
    vec2 sun_az_dir = normalize(vec2(sun_dir.x, sun_dir.z));
    float wake_active = u_sun_dir_wake.w;
    float raw_dx = (v_uv.x - 0.5) * 2.0 * aspect;
    float raw_dy = (horizon_v - v_uv.y) * 2.0;
    float rx_u = raw_dx * roll_cos + raw_dy * roll_sin;
    float ry_u = -raw_dx * roll_sin + raw_dy * roll_cos;
    vec3 ray_u = vec3(rx_u, ry_u, 1.62);
    float inv_rlen = inversesqrt(dot(ray_u, ray_u));
    vec3 ray = ray_u * inv_rlen;
    float inv_res_y = max(abs(dFdy(v_uv.y)), 1.0 / 16384.0);
    float d_ry = (2.0 * inv_res_y) * inv_rlen * max(1.0 - ray.y * ray.y, 0.15);
    float d_rx = (2.0 * inv_res_y) * inv_rlen;
    vec3 hdr;
    if (ray.y >= 0.0) {
        hdr = euv_sky(ray, sun_dir, sun_az_dir, sim_time, true);
    } else {
        float neg_ry_true = max(-ray.y, 1.0e-4);
        float dist_true = 1.42 / neg_ry_true;
        float dist = min(dist_true, 600.0);
        float px_span_z = dist_true * (d_ry / neg_ry_true);
        float px_span_x = dist_true * d_rx;
        float px_span = max(px_span_z, px_span_x);
        vec2 wp0 = ray.xz * dist;
        if (dist < 18.0) {
            float p_fade = 1.0 - smoothstep(10.0, 18.0, dist);
            float t0 = fract(sim_time * 0.84 * INV_TAU);
            float ph0 = (fract(dot(wp0, vec2(0.2419, 0.9703)) * 0.56 * INV_TAU) + t0) * TAU;
            float h_p = 0.205 * agitation * (exp(sin(ph0) - 1.0) - 0.42) * p_fade;
            dist = clamp((1.42 - h_p) / neg_ry_true, 0.5, 600.0);
            wp0 = ray.xz * dist;
        }
        vec2 fwd_xz = normalize(ray.xz);
        vec2 right_xz = vec2(fwd_xz.y, -fwd_xz.x);
        vec2 wp = wp0;
        float h = 0.0;
        vec2 grad = vec2(0.0);
        float crest_acc = 0.0;
        float normal_var = 0.0009;
        for (int wi = 0; wi < 8; ++wi) {
            vec4 wave = EUV_OCEAN_WAVES[wi];
            vec2 wdir = wave.xy;
            float freq = wave.z;
            float amp = wave.w * agitation;
            float w_span = max(max(abs(dot(wdir, fwd_xz)) * px_span_z, abs(dot(wdir, right_xz)) * px_span_x), px_span_z * 0.55);
            float nyq = freq * w_span * 2.25;
            float aa_w = (nyq < 4.5) ? exp(-0.5 * nyq * nyq) : 0.0;
            float rms_s = wave.w * min(agitation, 1.45) * freq;
            normal_var += 0.10 * rms_s * rms_s * (1.0 - aa_w * aa_w);
            if (aa_w > 0.0005) {
                float t_ph = fract(sim_time * EUV_OCEAN_SPEEDS[wi] * INV_TAU);
                float s_ph = fract(dot(wp, wdir) * freq * INV_TAU);
                float ph = (s_ph + t_ph) * TAU;
                float sp = sin(ph);
                float cp = cos(ph);
                float steep_k = 0.42 + 0.58 * aa_w;
                float sharp_e = exp(-(1.0 - sp) * steep_k);
                h += amp * (sharp_e - 0.42) * aa_w;
                float slope = amp * freq * steep_k * sharp_e * cp * aa_w;
                grad += wdir * slope;
                crest_acc += sharp_e * amp * aa_w;
                wp += wdir * (cp * amp * 0.78 * aa_w);
            }
        }
        float near_steep = 1.0 + 0.36 * exp(-dist * 0.082);
        grad *= near_steep;
        float cap_nyq1 = px_span * 14.5 * 2.25;
        float cap_aa1 = (cap_nyq1 < 4.5) ? exp(-0.5 * cap_nyq1 * cap_nyq1) : 0.0;
        normal_var += 0.0012 * (1.0 - cap_aa1 * cap_aa1) * min(agitation, 1.45);
        if (cap_aa1 > 0.001) {
            float p1a = (fract(dot(wp0, vec2( 0.8572,  0.5150)) * 14.2 * INV_TAU) + fract(sim_time * 3.7 * INV_TAU)) * TAU;
            float p1b = (fract(dot(wp0, vec2(-0.4226,  0.9063)) * 18.7 * INV_TAU) + fract(sim_time * 4.4 * INV_TAU)) * TAU;
            float p1c = (fract(dot(wp0, vec2( 0.9613, -0.2756)) * 23.4 * INV_TAU) + fract(sim_time * 5.1 * INV_TAU)) * TAU;
            float g1a = cos(p1a) * 0.044 * cap_aa1 * agitation;
            float g1b = cos(p1b) * 0.036 * cap_aa1 * agitation;
            float g1c = cos(p1c) * 0.028 * cap_aa1 * agitation;
            grad += vec2(0.8572, 0.5150) * g1a + vec2(-0.4226, 0.9063) * g1b + vec2(0.9613, -0.2756) * g1c;
        }
        float cap_nyq2 = px_span * 34.0 * 2.25;
        float cap_aa2 = (cap_nyq2 < 4.5) ? exp(-0.5 * cap_nyq2 * cap_nyq2) : 0.0;
        normal_var += 0.0006 * (1.0 - cap_aa2 * cap_aa2) * min(agitation, 1.45);
        if (cap_aa2 > 0.001) {
            float p2a = (fract(dot(wp0, vec2(-0.7547, -0.6561)) * 31.8 * INV_TAU) + fract(sim_time * 6.2 * INV_TAU)) * TAU;
            float p2b = (fract(dot(wp0, vec2( 0.2924, -0.9563)) * 41.3 * INV_TAU) + fract(sim_time * 7.3 * INV_TAU)) * TAU;
            float g2a = cos(p2a) * 0.022 * cap_aa2 * agitation;
            float g2b = cos(p2b) * 0.016 * cap_aa2 * agitation;
            grad += vec2(-0.7547, -0.6561) * g2a + vec2(0.2924, -0.9563) * g2b;
        }
        normal_var = clamp(normal_var + min(px_span * 0.006, 0.016), 0.0005, 0.036);
        float wake_foam = 0.0;
        if (wake_active > 0.001) {
            vec2 wake_uv = clamp(v_uv, vec2(0.5 / 96.0, 0.5 / 72.0), vec2(1.0 - 0.5 / 96.0, 1.0 - 0.5 / 72.0));
            vec4 wk = texture(u_wake_tex, wake_uv);
            vec2 edge_d = min(v_uv, vec2(1.0) - v_uv);
            float edge_win = smoothstep(0.0, 0.045, edge_d.x) * smoothstep(0.0, 0.045, edge_d.y);
            float w_gain = clamp(wake_active, 0.0, 1.0) * edge_win;
            vec2 flow = clamp((wk.rg - vec2(128.0 / 255.0)) * 4.0 * 0.22, vec2(-0.20), vec2(0.20)) * w_gain;
            grad += flow;
            wake_foam = wk.b * w_gain;
        }
        vec2 raw_bd = vec2((v_uv.x - boat_uv.x) * aspect, v_uv.y - boat_uv.y);
        vec2 rot_bd = vec2(raw_bd.x * roll_cos - raw_bd.y * roll_sin, raw_bd.x * roll_sin + raw_bd.y * roll_cos);
        vec2 boat_local = vec2(rot_bd.x / 0.145, rot_bd.y / 0.036);
        float boat_ring_d2 = dot(boat_local, boat_local);
        if (boat_ring_d2 > 0.30 && boat_ring_d2 < 12.8) {
            float r_hull = sqrt(boat_ring_d2);
            float rip_env = exp(-max(r_hull - 0.85, 0.0) * 1.08) * smoothstep(0.55, 0.92, r_hull);
            float rip_ph = (fract(r_hull * 16.5 * INV_TAU) - fract(sim_time * 4.2 * INV_TAU)) * TAU;
            float rip_wave = cos(rip_ph) * 0.34 * rip_env;
            float inv_rh = 1.0 / max(r_hull, 0.1);
            grad += vec2(boat_local.x * inv_rh * rip_wave, boat_local.y * inv_rh * rip_wave * 1.38);
        }
        vec3 norm = normalize(vec3(-grad.x, 1.0, -grad.y));
        vec3 view_dir = -ray;
        float ndv = clamp(dot(norm, view_dir), 0.005, 1.0);
        float om_nv = 1.0 - ndv;
        float om_nv2 = om_nv * om_nv;
        float fresnel = clamp(0.0204 + (0.94 - min(normal_var * 1.8, 0.32)) * (om_nv2 * om_nv2 * om_nv), 0.022, 0.90);
        vec3 refl_dir = reflect(ray, norm);
        refl_dir.y = max(refl_dir.y, 0.008);
        vec3 sky_refl = euv_sky(normalize(refl_dir), sun_dir, sun_az_dir, sim_time, false);
        vec3 half_vec = normalize(view_dir + sun_dir);
        float ndl = max(dot(norm, sun_dir), 0.0);
        float ndh = max(dot(norm, half_vec), 0.0);
        float vdh = clamp(dot(view_dir, half_vec), 0.0, 1.0);
        float om_vh = 1.0 - vdh;
        float om_vh2 = om_vh * om_vh;
        float fresnel_h = 0.0204 + 0.9796 * (om_vh2 * om_vh2 * om_vh);
        float a1_sq = 0.00045 + normal_var * 0.22;
        float d1 = ndh * ndh * (a1_sq - 1.0) + 1.0;
        float ndf1 = a1_sq / max(3.14159265 * d1 * d1, 1.0e-5);
        float k1 = sqrt(a1_sq) * 0.5;
        float vis1 = 0.25 / max((ndv * (1.0 - k1) + k1) * (ndl * (1.0 - k1) + k1), 0.012);
        float a2_sq = 0.0040 + normal_var * 0.34;
        float d2 = ndh * ndh * (a2_sq - 1.0) + 1.0;
        float ndf2 = a2_sq / max(3.14159265 * d2 * d2, 1.0e-5);
        float k2 = sqrt(a2_sq) * 0.5;
        float vis2 = 0.25 / max((ndv * (1.0 - k2) + k2) * (ndl * (1.0 - k2) + k2), 0.032);
        float core_e = min(ndf1 * vis1 * ndl * fresnel_h, 14.0);
        float sheen_e = min(ndf2 * vis2 * ndl * fresnel_h, 2.2);
        vec3 spec = vec3(1.48, 1.32, 1.06) * (core_e * 0.78) + vec3(1.24, 0.86, 0.48) * (sheen_e * 0.18);
        float sss_dot = clamp(dot(-view_dir, sun_dir), 0.0, 1.0);
        float sss = clamp(h * 2.35 + 0.26, 0.0, 1.0) * exp(-dist * 0.048) * (0.45 + 0.55 * (sss_dot * sss_dot * sss_dot));
        vec3 deep_body = vec3(0.0002, 0.056, 0.116) + vec3(0.0010, 0.40, 0.54) * sss;
        float refl_weight = clamp(fresnel * 0.52 + 0.020, 0.020, 0.68);
        hdr = mix(deep_body, sky_refl, refl_weight) + spec;
        if (rot_bd.y > -0.01 && rot_bd.y < 0.24 && abs(rot_bd.x) < 0.22) {
            float ripple = sin(rot_bd.y * 95.0 - sim_time * 4.5 + grad.x * 6.0) * 0.012;
            float rx_b = abs(rot_bd.x + ripple);
            float y_fade = smoothstep(-0.01, 0.032, rot_bd.y) * smoothstep(0.24, 0.10, rot_bd.y);
            float tri_mask = smoothstep(0.14, 0.02, rx_b + max(rot_bd.y, 0.0) * 0.55) * y_fade;
            hdr = mix(hdr, vec3(0.55, 0.52, 0.48), tri_mask * 0.32);
        }
        float crest_norm = crest_acc / max(agitation, 1.0);
        float steep_foam = smoothstep(0.54, 0.74, crest_norm) * clamp(agitation - 1.08, 0.0, 1.0);
        float total_foam = clamp(steep_foam * 0.45 + wake_foam * 0.28, 0.0, 0.54);
        hdr = mix(hdr, vec3(0.78, 0.90, 0.96), total_foam);
        if (boat_ring_d2 < 4.5) {
            if (boat_ring_d2 < 1.12) {
                float contact_ao = (1.0 - smoothstep(0.18, 1.06, boat_ring_d2)) * 0.44;
                hdr *= vec3(1.0 - contact_ao, 1.0 - contact_ao * 0.82, 1.0 - contact_ao * 0.72);
            }
            float foam_ny = boat_local.y - 0.16;
            float foam_d2 = boat_local.x * boat_local.x * 1.16 + foam_ny * foam_ny * 1.08;
            float rim_band = smoothstep(0.42, 0.82, foam_d2) * (1.0 - smoothstep(0.88, 1.54, foam_d2)) * smoothstep(-0.45, 0.24, boat_local.y);
            float aft_wake = smoothstep(0.22, 0.82, boat_local.x) * (1.0 - smoothstep(0.88, 1.62, boat_local.x)) * (1.0 - smoothstep(0.18, 1.20, abs(boat_local.y - 0.26))) * 0.46;
            float collar_mask = clamp(rim_band + aft_wake, 0.0, 1.0);
            if (collar_mask > 0.02) {
                float lacy_a = euv_noise(wp0 * 8.2 + vec2(2.3, -1.7));
                float lacy_b = euv_noise(wp0 * 21.0 + vec2(-sim_time * 0.85, 4.1));
                float flecks = euv_noise(wp0 * 42.0 + vec2(7.1, -sim_time * 1.35));
                float foam_pat = smoothstep(0.46, 0.78, lacy_a * 0.42 + lacy_b * 0.36 + flecks * 0.22);
                float spray_dots = smoothstep(0.74, 0.88, flecks) * rim_band * 0.72 * smoothstep(0.08, 0.015, px_span);
                float hull_foam = clamp(collar_mask * foam_pat * 0.78 + spray_dots, 0.0, 0.86);
                hdr = mix(hdr, vec3(0.92, 0.97, 1.0), hull_foam);
            }
        }
        float horiz_blend = exp(-neg_ry_true * 56.0);
        float dist_haze = 1.0 - exp(-dist * 0.0020);
        float pixel_hor_aa = 1.0 - smoothstep(0.0, d_ry * 1.75, neg_ry_true);
        float atm_mix = clamp(max(max(horiz_blend, dist_haze), pixel_hor_aa), 0.0, 1.0);
        float atm_w = clamp((atm_mix - 0.002) * (1.0 / 0.998), 0.0, 1.0);
        if (atm_w > 0.0) {
            vec3 fog_col = euv_sky(normalize(vec3(ray.x, max(0.0005, d_ry * 0.5), ray.z)), sun_dir, sun_az_dir, sim_time, false);
            hdr = mix(hdr, fog_col, atm_w);
        }
    }
    out_color = vec4(euv_aces(hdr), 1.0);
}
"#;

/// Hardware GLSL ES 3.0 origami paper boat vertex shader.
pub(crate) const LINUX_GL_SCENE_BOAT_VERT: &str = "#version 300 es\n\
precision highp float;\n\
layout(location = 0) in vec4 a_pos_ndc;\n\
layout(location = 1) in vec4 a_color;\n\
out vec4 v_color;\n\
void main() {\n\
    gl_Position = vec4(a_pos_ndc.xy, 0.0, 1.0);\n\
    v_color = a_color;\n\
}\n";

/// Hardware GLSL ES 3.0 origami paper boat fragment shader.
pub(crate) const LINUX_GL_SCENE_BOAT_FRAG: &str = "#version 300 es\n\
precision highp float;\n\
in vec4 v_color;\n\
out vec4 out_color;\n\
void main() {\n\
    out_color = v_color;\n\
}\n";

/// Hardware GLSL ES 3.0 3D atmospheric sky gradient fragment shader.
pub(crate) const LINUX_GL_SCENE_3D_SKY_FRAG: &str = r#"#version 300 es
precision highp float;
in highp vec2 v_uv;
uniform highp vec4 u_camera_pos;
uniform highp vec4 u_sun_color_ambient;
uniform highp vec4 u_sky_horizon_tod;
uniform highp vec4 u_sky_zenith_aspect;
out vec4 out_color;
vec3 euv_aces(vec3 hdr) {
    vec3 x = max(hdr, vec3(0.0));
    vec3 num = x * (2.51 * x + 0.03);
    vec3 den = x * (2.43 * x + 0.59) + 0.14;
    return pow(clamp(num / max(den, vec3(0.0001)), vec3(0.0), vec3(1.0)), vec3(1.0 / 2.2));
}
void main() {
    float sky_t = clamp(1.0 - v_uv.y * 1.15, 0.0, 1.0);
    vec3 col = mix(u_sky_horizon_tod.rgb, u_sky_zenith_aspect.rgb, smoothstep(0.0, 0.85, sky_t));
    float sun_glow = pow(clamp(1.0 - abs(v_uv.x - 0.55) * 1.6, 0.0, 1.0) * clamp(1.0 - abs(v_uv.y - 0.34) * 2.2, 0.0, 1.0), 3.0);
    col += u_sun_color_ambient.rgb * sun_glow * 0.45;
    out_color = vec4(euv_aces(col * u_camera_pos.w), 1.0);
}
"#;

/// Hardware GLSL ES 3.0 instanced 3D PBR open-world vertex shader.
pub(crate) const LINUX_GL_SCENE_3D_MESH_VERT: &str = r#"#version 300 es
precision highp float;
layout(location = 0) in vec4 a_pos;
layout(location = 1) in vec4 a_norm;
layout(location = 2) in vec4 a_submat;
layout(location = 3) in vec4 a_m0;
layout(location = 4) in vec4 a_m1;
layout(location = 5) in vec4 a_m2;
layout(location = 6) in vec4 a_m3;
layout(location = 7) in vec4 a_albedo_met;
layout(location = 8) in vec4 a_emissive_rough;
uniform highp mat4 u_view_proj;
out highp vec3 v_world_pos;
out highp vec3 v_world_norm;
out highp vec4 v_base_met;
out highp vec4 v_emissive_rough;
out highp float v_submat_mode;
out highp float v_detail_mode;
void main() {
    float detail_mode = a_m3.w;
    vec4 m3_fixed = vec4(a_m3.xyz, 1.0);
    mat4 model = mat4(a_m0, a_m1, a_m2, m3_fixed);
    vec4 wp = model * vec4(a_pos.xyz, 1.0);
    gl_Position = u_view_proj * wp;
    vec3 c0 = a_m0.xyz;
    vec3 c1 = a_m1.xyz;
    vec3 c2 = a_m2.xyz;
    mat3 cof = mat3(cross(c1, c2), cross(c2, c0), cross(c0, c1));
    v_world_pos = wp.xyz;
    v_world_norm = normalize(cof * a_norm.xyz);
    v_base_met = (a_submat.w > 0.5)
        ? vec4(a_submat.rgb, a_albedo_met.w)
        : vec4(a_albedo_met.rgb * a_submat.rgb, a_albedo_met.w);
    v_emissive_rough = a_emissive_rough;
    v_submat_mode = a_submat.w;
    v_detail_mode = detail_mode;
}
"#;

/// Hardware GLSL ES 3.0 flagship instanced 3D PBR open-world fragment shader with analytical ray-traced Fresnel reflections, clearcoat, contact AO, multi-bounce GI, and volumetric haze.
pub(crate) const LINUX_GL_SCENE_3D_MESH_FRAG: &str = r#"#version 300 es
precision highp float;
in highp vec3 v_world_pos;
in highp vec3 v_world_norm;
in highp vec4 v_base_met;
in highp vec4 v_emissive_rough;
in highp float v_submat_mode;
in highp float v_detail_mode;
uniform highp vec4 u_camera_pos;
uniform highp vec4 u_sun_dir_fog;
uniform highp vec4 u_sun_color_ambient;
uniform highp vec4 u_sky_horizon_tod;
uniform highp vec4 u_sky_zenith_aspect;
out vec4 out_color;
vec3 euv_aces(vec3 hdr) {
    vec3 x = max(hdr, vec3(0.0));
    vec3 num = x * (2.51 * x + 0.03);
    vec3 den = x * (2.43 * x + 0.59) + 0.14;
    return pow(clamp(num / max(den, vec3(0.0001)), vec3(0.0), vec3(1.0)), vec3(1.0 / 2.2));
}
float euv_hash(vec2 cell) {
    vec2 p = fract(cell * vec2(0.1031, 0.1030));
    p += dot(p, p.yx + 33.33);
    return fract((p.x + p.y) * p.x);
}
float euv_noise(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    float a = euv_hash(i);
    float b = euv_hash(i + vec2(1.0, 0.0));
    float c = euv_hash(i + vec2(0.0, 1.0));
    float d = euv_hash(i + vec2(1.0, 1.0));
    return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
void main() {
    vec3 norm = normalize(v_world_norm);
    vec3 view_dir = normalize(u_camera_pos.xyz - v_world_pos);
    vec3 sun_dir = normalize(u_sun_dir_fog.xyz);
    float dist = length(u_camera_pos.xyz - v_world_pos);
    float fw_pos = length(fwidth(v_world_pos));
    float fw_xz = length(fwidth(v_world_pos.xz));
    vec3 base_col = v_base_met.rgb;
    float metallic = clamp(v_base_met.w, 0.0, 1.0);
    float roughness = clamp(v_emissive_rough.w, 0.05, 1.0);
    vec3 emissive = (v_submat_mode > 1.5) ? base_col * 1.15 : v_emissive_rough.rgb;
    float env_boost = 0.85;
    if (v_detail_mode > 0.5 && v_detail_mode < 1.5 && norm.y > 0.82) {
        float wpx = v_world_pos.x;
        float wpz = v_world_pos.z;
        float abs_x = abs(wpx);
        float edge_aa = clamp(fw_xz * 0.9, 0.035, 0.36);
        float curb_w = smoothstep(9.9 - edge_aa, 9.9 + edge_aa, abs_x);
        float walk_w = smoothstep(10.6 - edge_aa, 10.6 + edge_aa, abs_x);
        float micro_fade = 1.0 - smoothstep(22.0, 70.0, dist);
        float grain_n = euv_hash(floor(vec2(wpx * 4.3, wpz * 4.3))) - 0.5;
        float om_curb = 1.0 - curb_w;
        float inner_lin = 1.0 - clamp(abs(abs_x - 3.65) * 0.85, 0.0, 1.0);
        float outer_lin = 1.0 - clamp(abs(abs_x - 6.85) * 0.95, 0.0, 1.0);
        float tire_wear = clamp(inner_lin * inner_lin + outer_lin * outer_lin, 0.0, 1.0) * om_curb;
        float gutter_band = (1.0 - clamp(abs(abs_x - 9.75) * 2.8, 0.0, 1.0)) * om_curb;
        float puddle_fade = 1.0 - smoothstep(48.0, 120.0, dist);
        float p_coarse = euv_noise(vec2(wpx * 0.14 + 3.1, wpz * 0.08 - 1.7));
        float p_fine = euv_noise(vec2(wpx * 0.38 - 5.4, wpz * 0.24 + 2.9));
        float center_crown = (1.0 - clamp(abs_x * 0.65, 0.0, 1.0)) * om_curb;
        float puddle_raw = p_coarse * 0.66 + p_fine * 0.34 + tire_wear * 0.14 + gutter_band * 0.16 - center_crown * 0.24;
        float puddle = smoothstep(0.44, 0.90, puddle_raw) * om_curb * puddle_fade;
        float tarmac_scale = (1.0 + grain_n * 0.24 * micro_fade * (1.0 - puddle)) * (1.0 - 0.14 * tire_wear) * (1.0 - 0.38 * puddle) * (1.0 - 0.30 * gutter_band);
        vec3 road_col = base_col * tarmac_scale;
        float yellow_w = (1.0 - smoothstep(0.085 - edge_aa, 0.085 + edge_aa, abs(abs_x - 0.22))) * om_curb;
        if (yellow_w > 0.01) {
            float pv = (1.0 - 0.14 * puddle) * (0.92 + grain_n * 0.14 * micro_fade);
            road_col = mix(road_col, vec3(0.88, 0.62, 0.10) * pv, yellow_w * 0.94);
        }
        float dash_on = (fract(wpz * 0.125) < 0.42) ? 1.0 : 0.0;
        float lane_w = (1.0 - smoothstep(0.085 - edge_aa, 0.085 + edge_aa, abs(abs_x - 4.65))) * dash_on * om_curb;
        float shoulder_w = (1.0 - smoothstep(0.10 - edge_aa, 0.10 + edge_aa, abs(abs_x - 8.95))) * om_curb;
        float cross_cell = (wpz + 18.0) - 40.0 * floor((wpz + 18.0) / 40.0) - 20.0;
        float cross_w = (abs(cross_cell) < 1.80 && abs_x < 8.40 && abs_x > 0.55 && fract(wpx * 0.85) < 0.50) ? (0.85 * om_curb) : 0.0;
        float white_w = max(max(shoulder_w, lane_w), cross_w);
        if (white_w > 0.01) {
            float pv = (1.0 - 0.16 * puddle) * (0.90 + grain_n * 0.12 * micro_fade);
            road_col = mix(road_col, vec3(0.78, 0.81, 0.86) * pv, white_w * 0.90);
        }
        vec3 curb_col = vec3(0.36, 0.38, 0.42) * (1.0 + grain_n * 0.10 * micro_fade);
        float tile_seam = (fract(wpx * 0.45) < 0.045 || fract(wpz * 0.45) < 0.045) ? 0.72 : 1.0;
        vec3 walk_col = vec3(0.24, 0.26, 0.30) * tile_seam * (1.0 + grain_n * 0.10 * micro_fade);
        base_col = mix(mix(road_col, curb_col, curb_w), walk_col, walk_w);
        roughness = mix(mix(roughness, 0.06, puddle), 0.78, walk_w);
        env_boost = mix(0.85, 1.85, puddle);
    } else if (v_detail_mode > 1.5 && v_detail_mode < 2.5 && abs(norm.y) < 0.35 && v_submat_mode < 0.5) {
        float u_coord = (abs(norm.x) > abs(norm.z)) ? v_world_pos.z : v_world_pos.x;
        float world_y = v_world_pos.y;
        float dist_fade = 1.0 - smoothstep(130.0, 320.0, dist);
        float px_sz = max(fw_pos * 0.75, dist * 0.0022);
        if (world_y < 3.45) {
            float su_s = u_coord * 0.26;
            float fx_s = fract(su_s);
            float fy_s = clamp(world_y / 3.45, 0.0, 1.0);
            float pane_w = smoothstep(0.08, 0.14, fx_s) * (1.0 - smoothstep(0.86, 0.92, fx_s)) * smoothstep(0.14, 0.22, fy_s) * (1.0 - smoothstep(0.86, 0.92, fy_s)) * dist_fade;
            float sh = euv_hash(vec2(floor(su_s), 7.0));
            vec3 shop_glow = (sh < 0.40) ? vec3(1.18, 0.78, 0.36) : ((sh < 0.62) ? vec3(0.28, 0.88, 1.18) : ((sh < 0.80) ? vec3(1.12, 0.32, 0.68) : vec3(0.0)));
            base_col = mix(base_col * 0.64, base_col * 0.40, pane_w);
            emissive += shop_glow * (pane_w * (0.55 + 0.55 * (1.0 - fy_s)) * 0.92);
            roughness = mix(roughness, 0.12, pane_w);
        } else {
            float su = u_coord * 0.48;
            float sy = world_y * 0.33;
            float fx_win = fract(su);
            float fy_win = fract(sy);
            float aa_u = clamp(px_sz * 0.48, 0.018, 0.32);
            float aa_v = clamp(px_sz * 0.33, 0.018, 0.32);
            float pane_u = smoothstep(0.14 - aa_u, 0.14 + aa_u, fx_win) * (1.0 - smoothstep(0.86 - aa_u, 0.86 + aa_u, fx_win));
            float pane_v = smoothstep(0.18 - aa_v, 0.18 + aa_v, fy_win) * (1.0 - smoothstep(0.84 - aa_v, 0.84 + aa_v, fy_win));
            float pane_w = clamp(pane_u * pane_v * dist_fade, 0.0, 1.0);
            float spandrel = (fy_win < 0.14 || fy_win > 0.88) ? 0.70 : 0.84;
            vec3 wall_base = base_col * spandrel;
            float ch = euv_hash(vec2(floor(su), floor(sy)));
            float room_lvl = 0.68 + fract(ch * 17.3) * 0.45;
            float blind_grad = clamp(0.48 + 0.66 * (1.0 - fy_win), 0.38, 1.14);
            float r_scale = pane_w * room_lvl * blind_grad;
            if (ch < 0.22) {
                base_col = mix(wall_base, base_col * 0.86, pane_w);
                emissive += vec3(1.24, 0.86, 0.42) * r_scale;
            } else if (ch < 0.33) {
                base_col = mix(wall_base, base_col * 0.84, pane_w);
                emissive += vec3(0.28, 0.86, 1.24) * r_scale;
            } else if (ch < 0.42) {
                base_col = mix(wall_base, base_col * 0.88, pane_w);
                emissive += vec3(0.96, 0.94, 0.88) * (r_scale * 0.82);
            } else if (ch < 0.50) {
                base_col = mix(wall_base, base_col * 0.84, pane_w);
                emissive += vec3(1.06, 0.34, 0.72) * (r_scale * 0.86);
            } else {
                float dark_g = clamp(0.36 + 0.22 * fy_win, 0.32, 0.62);
                base_col = mix(wall_base, base_col * dark_g, pane_w);
            }
            roughness = mix(roughness, 0.10, pane_w);
            env_boost = mix(0.85, 1.45, pane_w);
        }
    } else if (v_detail_mode > 2.5 && norm.y > 0.80) {
        vec2 wp = v_world_pos.xz;
        float aa_w = 1.0 / (1.0 + fw_xz * 0.85);
        float w_a = cos(wp.x * 0.42 + wp.y * 0.64 + u_sky_horizon_tod.w * 2.4) * 0.08 * aa_w;
        float w_b = cos(-wp.x * 0.78 + wp.y * 0.52 + u_sky_horizon_tod.w * 3.1) * 0.06 * aa_w;
        norm = normalize(vec3(w_a - w_b, 1.0, w_a + w_b));
        base_col = vec3(0.015, 0.095, 0.145);
        roughness = 0.08;
        metallic = 0.02;
        env_boost = 1.65;
    }
    vec3 half_vec = normalize(view_dir + sun_dir);
    float ndl = max(dot(norm, sun_dir), 0.0);
    float ndv = max(dot(norm, view_dir), 0.002);
    float ndh = max(dot(norm, half_vec), 0.0);
    float hdv = max(dot(half_vec, view_dir), 0.0);
    float a2 = roughness * roughness * roughness * roughness;
    float d_den = ndh * ndh * (a2 - 1.0) + 1.0;
    float ndf = a2 / max(3.14159265 * d_den * d_den, 0.0001);
    vec3 f0 = mix(vec3(0.04), base_col, metallic);
    vec3 fresnel = f0 + (vec3(1.0) - f0) * pow(1.0 - hdv, 5.0);
    float k_g = (roughness + 1.0);
    k_g = (k_g * k_g) * 0.125;
    float g_v = ndv / (ndv * (1.0 - k_g) + k_g);
    float g_l = ndl / (ndl * (1.0 - k_g) + k_g);
    vec3 spec = (ndf * g_v * g_l * fresnel) / max(4.0 * ndv * ndl, 0.001);
    float clearcoat = (metallic > 0.30 || roughness < 0.22) ? 0.55 : 0.0;
    if (clearcoat > 0.0) {
        float cc_den = ndh * ndh * (0.004 - 1.0) + 1.0;
        float cc_ndf = 0.004 / max(3.14159265 * cc_den * cc_den, 0.0001);
        float cc_f = 0.04 + 0.96 * pow(1.0 - hdv, 5.0);
        spec += vec3(cc_ndf * cc_f * clearcoat * 0.32);
    }
    float canyon_shadow = 1.0 - smoothstep(10.5, 22.0, abs(v_world_pos.x)) * (1.0 - smoothstep(0.0, 14.0, v_world_pos.y)) * 0.38;
    float contact_ao = (v_detail_mode > 0.5 && v_detail_mode < 1.5)
        ? (0.76 + 0.24 * (1.0 - smoothstep(9.2, 13.5, abs(v_world_pos.x)) * 0.45))
        : (0.70 + 0.30 * smoothstep(0.0, 2.4, v_world_pos.y));
    vec3 kd = (vec3(1.0) - fresnel) * (1.0 - metallic);
    vec3 direct = (kd * base_col / 3.14159265 + spec) * u_sun_color_ambient.rgb * (ndl * 1.48 * canyon_shadow);
    vec3 refl_dir = reflect(-view_dir, norm);
    float refl_y = clamp(refl_dir.y * 0.5 + 0.5, 0.0, 1.0);
    vec3 env_refl = mix(u_sky_horizon_tod.rgb, u_sky_zenith_aspect.rgb, refl_y);
    float sun_refl = pow(max(dot(refl_dir, sun_dir), 0.0), mix(96.0, 12.0, roughness));
    env_refl += u_sun_color_ambient.rgb * sun_refl * (1.35 - roughness * 0.9);
    float facade_refl_band = smoothstep(0.18, 0.85, abs(refl_dir.x)) * (1.0 - smoothstep(0.05, 0.58, abs(refl_dir.y)));
    if (facade_refl_band > 0.01 && (env_boost > 1.05 || metallic > 0.30 || roughness < 0.28)) {
        float win_u = v_world_pos.z * 0.22 + refl_dir.z * 6.0;
        float win_v = refl_dir.y * 9.0 + v_world_pos.y * 0.18;
        float win_h = euv_hash(floor(vec2(win_u, win_v)));
        vec3 win_col = (win_h < 0.35) ? vec3(1.15, 0.78, 0.38) : ((win_h < 0.62) ? vec3(0.28, 0.86, 1.20) : ((win_h < 0.80) ? vec3(1.05, 0.32, 0.70) : vec3(0.12, 0.16, 0.24)));
        float win_grid = smoothstep(0.12, 0.28, fract(win_u)) * (1.0 - smoothstep(0.72, 0.88, fract(win_u)));
        env_refl += win_col * (facade_refl_band * win_grid * (0.42 + 0.55 * (1.0 - roughness)));
    }
    float lamp_z = abs(fract((v_world_pos.z + 10.0) * 0.05) - 0.5) * 20.0;
    float lamp_x = abs(abs(v_world_pos.x) - 10.2);
    float lamp_pool = exp(-(lamp_x * lamp_x * 0.08 + lamp_z * lamp_z * 0.055)) * smoothstep(-0.2, 0.8, norm.y);
    vec3 city_gi = (vec3(0.26, 0.34, 0.52) * 0.18 + vec3(1.05, 0.72, 0.36) * (lamp_pool * 0.52)) * (1.0 - smoothstep(14.0, 42.0, v_world_pos.y));
    float sky_w = norm.y * 0.5 + 0.5;
    vec3 hemi = mix(u_sky_horizon_tod.rgb * 0.44 + city_gi, u_sky_zenith_aspect.rgb * 0.92 + u_sky_horizon_tod.rgb * 0.36, sky_w);
    vec3 f_env = f0 + (max(vec3(1.0 - roughness), f0) - f0) * pow(1.0 - ndv, 5.0);
    vec3 ambient = (base_col * (1.0 - metallic * 0.65) * hemi + env_refl * f_env * env_boost) * (0.46 + u_sun_color_ambient.w) * contact_ao;
    vec3 hdr = direct + ambient + emissive;
    float fog_t = 1.0 - exp(-dist * u_sun_dir_fog.w);
    float sun_scatter = pow(max(dot(-view_dir, sun_dir), 0.0), 6.0);
    vec3 fog_color = u_sky_horizon_tod.rgb + u_sun_color_ambient.rgb * (sun_scatter * 0.36);
    hdr = mix(hdr, fog_color, clamp(fog_t, 0.0, 0.86));
    out_color = vec4(euv_aces(hdr * u_camera_pos.w), 1.0);
}
"#;