webgl2 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.md +41 -44
- package/demo.js +13 -5
- package/index.js +66 -27
- package/package.json +5 -3
- package/src/webgl2_context.js +2555 -2483
- package/src/webgl2_resources.js +91 -0
- package/src/webgpu_context.js +1291 -1098
- package/webgl2.debug.wasm +0 -0
- package/webgl2.wasm +0 -0
package/src/webgl2_context.js
CHANGED
|
@@ -1,2483 +1,2555 @@
|
|
|
1
|
-
// Thin forwarding WasmWebGL2RenderingContext and helpers
|
|
2
|
-
// This module contains the class and small helpers that operate on the
|
|
3
|
-
// WebAssembly instance. It is intentionally minimal: JS forwards calls to
|
|
4
|
-
// WASM and reads last-error strings when needed.
|
|
5
|
-
|
|
6
|
-
/** @typedef {number} u32 */
|
|
7
|
-
|
|
8
|
-
// Errno constants (must match src/webgl2_context.rs)
|
|
9
|
-
export const ERR_OK = 0;
|
|
10
|
-
export const ERR_INVALID_HANDLE = 1;
|
|
11
|
-
export const ERR_OOM = 2;
|
|
12
|
-
export const ERR_INVALID_ARGS = 3;
|
|
13
|
-
export const ERR_NOT_IMPLEMENTED = 4;
|
|
14
|
-
export const ERR_GL = 5;
|
|
15
|
-
export const ERR_INTERNAL = 6;
|
|
16
|
-
|
|
17
|
-
import { WasmWebGLTexture } from './webgl2_texture.js';
|
|
18
|
-
import {
|
|
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
|
-
this.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
this.
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.
|
|
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
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
mem.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
border >>> 0,
|
|
396
|
-
format >>> 0,
|
|
397
|
-
type_ >>> 0,
|
|
398
|
-
ptr >>> 0,
|
|
399
|
-
len >>> 0
|
|
400
|
-
);
|
|
401
|
-
_checkErr(code, this._instance);
|
|
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
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
this.
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
this._assertNotDestroyed();
|
|
487
|
-
const ex = this._instance.exports;
|
|
488
|
-
if (!ex || typeof ex.
|
|
489
|
-
throw new Error('
|
|
490
|
-
}
|
|
491
|
-
const handle =
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
this._assertNotDestroyed();
|
|
501
|
-
const ex = this._instance.exports;
|
|
502
|
-
if (!ex || typeof ex.
|
|
503
|
-
throw new Error('
|
|
504
|
-
}
|
|
505
|
-
const
|
|
506
|
-
const code = ex.
|
|
507
|
-
_checkErr(code, this._instance);
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
this._assertNotDestroyed();
|
|
512
|
-
const ex = this._instance.exports;
|
|
513
|
-
if (!ex || typeof ex.
|
|
514
|
-
throw new Error('
|
|
515
|
-
}
|
|
516
|
-
const
|
|
517
|
-
const code = ex.
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
this.
|
|
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
|
-
mem.
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
const
|
|
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
|
-
const
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
const
|
|
799
|
-
const
|
|
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
|
-
const
|
|
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
|
-
if (
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
const
|
|
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
|
-
this.
|
|
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
|
-
const
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
ex.
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
ex.
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
const
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
ex.
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
const
|
|
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
|
-
const
|
|
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
|
-
const
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
if (
|
|
1274
|
-
|
|
1275
|
-
}
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
if (
|
|
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
|
-
this.
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
_checkErr(code, this._instance);
|
|
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
|
-
const
|
|
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
|
-
const
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
this._assertNotDestroyed();
|
|
1446
|
-
const ex = this._instance.exports;
|
|
1447
|
-
if (!ex || typeof ex.
|
|
1448
|
-
throw new Error('
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
this.
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
throw new Error(
|
|
1496
|
-
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
this.
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
const
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
this.
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
this.
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
if (!
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
const len =
|
|
1721
|
-
const ptr = ex.wasm_alloc(len);
|
|
1722
|
-
if (ptr === 0) throw new Error('Failed to allocate memory for
|
|
1723
|
-
|
|
1724
|
-
try {
|
|
1725
|
-
const mem = new Uint8Array(ex.memory.buffer);
|
|
1726
|
-
mem.set(
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
this.
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
this._assertNotDestroyed();
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
const
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
const
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
const
|
|
1831
|
-
if (
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
const
|
|
1938
|
-
return
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
const
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
this.
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
this.
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
this.
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
const
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
this.
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
this.
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
this.
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
}
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
if (
|
|
2378
|
-
|
|
2379
|
-
}
|
|
2380
|
-
|
|
2381
|
-
//
|
|
2382
|
-
const
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
//
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
const
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
1
|
+
// Thin forwarding WasmWebGL2RenderingContext and helpers
|
|
2
|
+
// This module contains the class and small helpers that operate on the
|
|
3
|
+
// WebAssembly instance. It is intentionally minimal: JS forwards calls to
|
|
4
|
+
// WASM and reads last-error strings when needed.
|
|
5
|
+
|
|
6
|
+
/** @typedef {number} u32 */
|
|
7
|
+
|
|
8
|
+
// Errno constants (must match src/webgl2_context.rs)
|
|
9
|
+
export const ERR_OK = 0;
|
|
10
|
+
export const ERR_INVALID_HANDLE = 1;
|
|
11
|
+
export const ERR_OOM = 2;
|
|
12
|
+
export const ERR_INVALID_ARGS = 3;
|
|
13
|
+
export const ERR_NOT_IMPLEMENTED = 4;
|
|
14
|
+
export const ERR_GL = 5;
|
|
15
|
+
export const ERR_INTERNAL = 6;
|
|
16
|
+
|
|
17
|
+
import { WasmWebGLTexture } from './webgl2_texture.js';
|
|
18
|
+
import {
|
|
19
|
+
WasmWebGLShader,
|
|
20
|
+
WasmWebGLProgram,
|
|
21
|
+
WasmWebGLBuffer,
|
|
22
|
+
WasmWebGLRenderbuffer,
|
|
23
|
+
WasmWebGLFramebuffer,
|
|
24
|
+
WasmWebGLVertexArrayObject,
|
|
25
|
+
WasmWebGLQuery,
|
|
26
|
+
WasmWebGLSampler,
|
|
27
|
+
WasmWebGLSync,
|
|
28
|
+
WasmWebGLTransformFeedback,
|
|
29
|
+
WasmWebGLUniformLocation
|
|
30
|
+
} from './webgl2_resources.js';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @implements {WebGL2RenderingContext}
|
|
34
|
+
*/
|
|
35
|
+
export class WasmWebGL2RenderingContext {
|
|
36
|
+
// Constants
|
|
37
|
+
FRAGMENT_SHADER = 0x8B30;
|
|
38
|
+
VERTEX_SHADER = 0x8B31;
|
|
39
|
+
TRIANGLES = 0x0004;
|
|
40
|
+
TRIANGLE_STRIP = 0x0005;
|
|
41
|
+
COLOR_BUFFER_BIT = 0x00004000;
|
|
42
|
+
DEPTH_BUFFER_BIT = 0x00000100;
|
|
43
|
+
DEPTH_TEST = 0x0B71;
|
|
44
|
+
STENCIL_TEST = 0x0B90;
|
|
45
|
+
SCISSOR_TEST = 0x0C11;
|
|
46
|
+
STENCIL_BUFFER_BIT = 0x00000400;
|
|
47
|
+
COMPILE_STATUS = 0x8B81;
|
|
48
|
+
LINK_STATUS = 0x8B82;
|
|
49
|
+
DELETE_STATUS = 0x8B80;
|
|
50
|
+
VALIDATE_STATUS = 0x8B83;
|
|
51
|
+
ARRAY_BUFFER = 0x8892;
|
|
52
|
+
ELEMENT_ARRAY_BUFFER = 0x8893;
|
|
53
|
+
COPY_READ_BUFFER = 0x8F36;
|
|
54
|
+
COPY_WRITE_BUFFER = 0x8F37;
|
|
55
|
+
PIXEL_PACK_BUFFER = 0x88EB;
|
|
56
|
+
PIXEL_UNPACK_BUFFER = 0x88EC;
|
|
57
|
+
UNIFORM_BUFFER = 0x8A11;
|
|
58
|
+
TRANSFORM_FEEDBACK_BUFFER = 0x8C8E;
|
|
59
|
+
STATIC_DRAW = 0x88E4;
|
|
60
|
+
BYTE = 0x1400;
|
|
61
|
+
UNSIGNED_BYTE = 0x1401;
|
|
62
|
+
SHORT = 0x1402;
|
|
63
|
+
UNSIGNED_SHORT = 0x1403;
|
|
64
|
+
INT = 0x1404;
|
|
65
|
+
UNSIGNED_INT = 0x1405;
|
|
66
|
+
FLOAT = 0x1406;
|
|
67
|
+
FLOAT_VEC2 = 0x8B50;
|
|
68
|
+
FLOAT_VEC3 = 0x8B51;
|
|
69
|
+
FLOAT_VEC4 = 0x8B52;
|
|
70
|
+
INT_VEC2 = 0x8B53;
|
|
71
|
+
INT_VEC3 = 0x8B54;
|
|
72
|
+
INT_VEC4 = 0x8B55;
|
|
73
|
+
BOOL = 0x8B56;
|
|
74
|
+
BOOL_VEC2 = 0x8B57;
|
|
75
|
+
BOOL_VEC3 = 0x8B58;
|
|
76
|
+
BOOL_VEC4 = 0x8B59;
|
|
77
|
+
FLOAT_MAT2 = 0x8B5A;
|
|
78
|
+
FLOAT_MAT3 = 0x8B5B;
|
|
79
|
+
FLOAT_MAT4 = 0x8B5C;
|
|
80
|
+
SAMPLER_2D = 0x8B5E;
|
|
81
|
+
SAMPLER_3D = 0x8B5F;
|
|
82
|
+
SAMPLER_CUBE = 0x8B60;
|
|
83
|
+
ACTIVE_UNIFORMS = 0x8B86;
|
|
84
|
+
ACTIVE_ATTRIBUTES = 0x8B89;
|
|
85
|
+
VIEWPORT = 0x0BA2;
|
|
86
|
+
COLOR_CLEAR_VALUE = 0x0C22;
|
|
87
|
+
COLOR_WRITEMASK = 0x0C23;
|
|
88
|
+
DEPTH_WRITEMASK = 0x0B72;
|
|
89
|
+
STENCIL_WRITEMASK = 0x0B98;
|
|
90
|
+
STENCIL_BACK_WRITEMASK = 0x8CA5;
|
|
91
|
+
|
|
92
|
+
DEPTH_FUNC = 0x0B74;
|
|
93
|
+
STENCIL_FUNC = 0x0B92;
|
|
94
|
+
STENCIL_VALUE_MASK = 0x0B93;
|
|
95
|
+
STENCIL_REF = 0x0B97;
|
|
96
|
+
STENCIL_BACK_FUNC = 0x8800;
|
|
97
|
+
STENCIL_BACK_VALUE_MASK = 0x8CA4;
|
|
98
|
+
STENCIL_BACK_REF = 0x8CA3;
|
|
99
|
+
STENCIL_FAIL = 0x0B94;
|
|
100
|
+
STENCIL_PASS_DEPTH_FAIL = 0x0B95;
|
|
101
|
+
STENCIL_PASS_DEPTH_PASS = 0x0B96;
|
|
102
|
+
STENCIL_BACK_FAIL = 0x8801;
|
|
103
|
+
STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802;
|
|
104
|
+
STENCIL_BACK_PASS_DEPTH_PASS = 0x8803;
|
|
105
|
+
|
|
106
|
+
BUFFER_SIZE = 0x8764;
|
|
107
|
+
MAX_VERTEX_ATTRIBS = 0x8869;
|
|
108
|
+
NO_ERROR = 0;
|
|
109
|
+
INVALID_ENUM = 0x0500;
|
|
110
|
+
INVALID_VALUE = 0x0501;
|
|
111
|
+
INVALID_OPERATION = 0x0502;
|
|
112
|
+
OUT_OF_MEMORY = 0x0505;
|
|
113
|
+
|
|
114
|
+
ZERO = 0;
|
|
115
|
+
ONE = 1;
|
|
116
|
+
|
|
117
|
+
CURRENT_VERTEX_ATTRIB = 0x8626;
|
|
118
|
+
VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622;
|
|
119
|
+
VERTEX_ATTRIB_ARRAY_SIZE = 0x8623;
|
|
120
|
+
VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624;
|
|
121
|
+
VERTEX_ATTRIB_ARRAY_TYPE = 0x8625;
|
|
122
|
+
VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A;
|
|
123
|
+
VERTEX_ATTRIB_ARRAY_POINTER = 0x8645;
|
|
124
|
+
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F;
|
|
125
|
+
VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE;
|
|
126
|
+
VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD;
|
|
127
|
+
|
|
128
|
+
RENDERBUFFER = 0x8D41;
|
|
129
|
+
FRAMEBUFFER = 0x8D40;
|
|
130
|
+
READ_FRAMEBUFFER = 0x8CA8;
|
|
131
|
+
DRAW_FRAMEBUFFER = 0x8CA9;
|
|
132
|
+
FRAMEBUFFER_COMPLETE = 0x8CD5;
|
|
133
|
+
FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6;
|
|
134
|
+
FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7;
|
|
135
|
+
FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9;
|
|
136
|
+
FRAMEBUFFER_UNSUPPORTED = 0x8CDD;
|
|
137
|
+
FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56;
|
|
138
|
+
RENDERBUFFER_SAMPLES = 0x8CAB;
|
|
139
|
+
FRAMEBUFFER_UNDEFINED = 0x8219;
|
|
140
|
+
DEPTH_COMPONENT16 = 0x81A5;
|
|
141
|
+
DEPTH_STENCIL = 0x84F9;
|
|
142
|
+
RGBA4 = 0x8056;
|
|
143
|
+
RGB565 = 0x8D62;
|
|
144
|
+
RGB5_A1 = 0x8057;
|
|
145
|
+
RGBA8 = 0x8058;
|
|
146
|
+
RGBA32F = 0x8814;
|
|
147
|
+
RGB32F = 0x8815;
|
|
148
|
+
RGBA16F = 0x881A;
|
|
149
|
+
RGB16F = 0x881B;
|
|
150
|
+
R8UI = 0x8232;
|
|
151
|
+
RG8UI = 0x8238;
|
|
152
|
+
RGB8UI = 0x8D7D;
|
|
153
|
+
RGBA8UI = 0x8D7C;
|
|
154
|
+
R16UI = 0x8234;
|
|
155
|
+
RG16UI = 0x823A;
|
|
156
|
+
RGB16UI = 0x8D77;
|
|
157
|
+
RGBA16UI = 0x8D76;
|
|
158
|
+
R32UI = 0x8236;
|
|
159
|
+
RG32UI = 0x823C;
|
|
160
|
+
RGB32UI = 0x8D71;
|
|
161
|
+
RGBA32UI = 0x8D70;
|
|
162
|
+
R8I = 0x8231;
|
|
163
|
+
RG8I = 0x8237;
|
|
164
|
+
RGB8I = 0x8D8F;
|
|
165
|
+
RGBA8I = 0x8D8E;
|
|
166
|
+
R16I = 0x8233;
|
|
167
|
+
RG16I = 0x8239;
|
|
168
|
+
RGB16I = 0x8D89;
|
|
169
|
+
RGBA16I = 0x8D88;
|
|
170
|
+
R32I = 0x8235;
|
|
171
|
+
RG32I = 0x823B;
|
|
172
|
+
RGB32I = 0x8D83;
|
|
173
|
+
RGBA32I = 0x8D82;
|
|
174
|
+
RED_INTEGER = 0x8D94;
|
|
175
|
+
RG_INTEGER = 0x8D95;
|
|
176
|
+
RGB_INTEGER = 0x8D96;
|
|
177
|
+
RGBA_INTEGER = 0x8D99;
|
|
178
|
+
R32F = 0x822E;
|
|
179
|
+
RG32F = 0x8230;
|
|
180
|
+
R16F = 0x822D;
|
|
181
|
+
RG16F = 0x822F;
|
|
182
|
+
STENCIL_INDEX8 = 0x8D48;
|
|
183
|
+
COLOR_ATTACHMENT0 = 0x8CE0;
|
|
184
|
+
COLOR_ATTACHMENT1 = 0x8CE1;
|
|
185
|
+
COLOR_ATTACHMENT2 = 0x8CE2;
|
|
186
|
+
COLOR_ATTACHMENT3 = 0x8CE3;
|
|
187
|
+
COLOR_ATTACHMENT4 = 0x8CE4;
|
|
188
|
+
COLOR_ATTACHMENT5 = 0x8CE5;
|
|
189
|
+
COLOR_ATTACHMENT6 = 0x8CE6;
|
|
190
|
+
COLOR_ATTACHMENT7 = 0x8CE7;
|
|
191
|
+
DEPTH_ATTACHMENT = 0x8D00;
|
|
192
|
+
STENCIL_ATTACHMENT = 0x8D20;
|
|
193
|
+
DEPTH_STENCIL_ATTACHMENT = 0x821A;
|
|
194
|
+
|
|
195
|
+
LESS = 0x0201;
|
|
196
|
+
EQUAL = 0x0202;
|
|
197
|
+
LEQUAL = 0x0203;
|
|
198
|
+
GREATER = 0x0204;
|
|
199
|
+
NOTEQUAL = 0x0205;
|
|
200
|
+
GEQUAL = 0x0206;
|
|
201
|
+
ALWAYS = 0x0207;
|
|
202
|
+
NEVER = 0x0200;
|
|
203
|
+
|
|
204
|
+
KEEP = 0x1E00;
|
|
205
|
+
REPLACE = 0x1E01;
|
|
206
|
+
INCR = 0x1E02;
|
|
207
|
+
DECR = 0x1E03;
|
|
208
|
+
INVERT = 0x150A;
|
|
209
|
+
INCR_WRAP = 0x8507;
|
|
210
|
+
DECR_WRAP = 0x8508;
|
|
211
|
+
|
|
212
|
+
FRONT = 0x0404;
|
|
213
|
+
BACK = 0x0405;
|
|
214
|
+
FRONT_AND_BACK = 0x0408;
|
|
215
|
+
|
|
216
|
+
TEXTURE_2D = 0x0DE1;
|
|
217
|
+
TEXTURE_3D = 0x806F;
|
|
218
|
+
TEXTURE_2D_ARRAY = 0x8C1A;
|
|
219
|
+
TEXTURE_WRAP_S = 0x2802;
|
|
220
|
+
TEXTURE_WRAP_T = 0x2803;
|
|
221
|
+
TEXTURE_WRAP_R = 0x8072;
|
|
222
|
+
TEXTURE_MAG_FILTER = 0x2800;
|
|
223
|
+
TEXTURE_MIN_FILTER = 0x2801;
|
|
224
|
+
RGBA = 0x1908;
|
|
225
|
+
RED = 0x1903;
|
|
226
|
+
RG = 0x8227;
|
|
227
|
+
UNSIGNED_BYTE = 0x1401;
|
|
228
|
+
FLOAT = 0x1406;
|
|
229
|
+
NEAREST = 0x2600;
|
|
230
|
+
LINEAR = 0x2601;
|
|
231
|
+
NEAREST_MIPMAP_NEAREST = 0x2700;
|
|
232
|
+
LINEAR_MIPMAP_NEAREST = 0x2701;
|
|
233
|
+
NEAREST_MIPMAP_LINEAR = 0x2702;
|
|
234
|
+
LINEAR_MIPMAP_LINEAR = 0x2703;
|
|
235
|
+
REPEAT = 0x2901;
|
|
236
|
+
CLAMP_TO_EDGE = 0x812F;
|
|
237
|
+
MIRRORED_REPEAT = 0x8370;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param {{
|
|
241
|
+
* instance: WebAssembly.Instance,
|
|
242
|
+
* ctxHandle: number,
|
|
243
|
+
* width: number,
|
|
244
|
+
* height: number,
|
|
245
|
+
* debugShaders: boolean,
|
|
246
|
+
* sharedTable: any,
|
|
247
|
+
* tableAllocator: any
|
|
248
|
+
* }} options
|
|
249
|
+
*/
|
|
250
|
+
constructor({ instance, ctxHandle, width, height, debugShaders = false, sharedTable = null, tableAllocator = null, turboGlobals = null }) {
|
|
251
|
+
this._instance = instance;
|
|
252
|
+
this._ctxHandle = ctxHandle;
|
|
253
|
+
this._destroyed = false;
|
|
254
|
+
/** @type {import('./webgl2_resources.js').WasmWebGLProgram | null} */
|
|
255
|
+
this._currentProgram = null;
|
|
256
|
+
// Explicit booleans for clarity
|
|
257
|
+
this._debugShaders = !!debugShaders;
|
|
258
|
+
this._drawingBufferWidth = width;
|
|
259
|
+
this._drawingBufferHeight = height;
|
|
260
|
+
this._sharedTable = sharedTable;
|
|
261
|
+
this._tableAllocator = tableAllocator;
|
|
262
|
+
|
|
263
|
+
// TODO: potentially retrieve those one demand from the main WASM module when shader WASM modules are initialised
|
|
264
|
+
this._turboGlobals = turboGlobals;
|
|
265
|
+
|
|
266
|
+
WasmWebGL2RenderingContext._contexts.set(this._ctxHandle, this);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
get drawingBufferWidth() {
|
|
270
|
+
return this._drawingBufferWidth;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
get drawingBufferHeight() {
|
|
274
|
+
return this._drawingBufferHeight;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
resize(width, height) {
|
|
278
|
+
this._assertNotDestroyed();
|
|
279
|
+
const ex = this._instance.exports;
|
|
280
|
+
if (!ex || typeof ex.wasm_ctx_resize !== 'function') {
|
|
281
|
+
throw new Error('wasm_ctx_resize not found');
|
|
282
|
+
}
|
|
283
|
+
const code = ex.wasm_ctx_resize(this._ctxHandle, width, height);
|
|
284
|
+
_checkErr(code, this._instance);
|
|
285
|
+
this._drawingBufferWidth = width;
|
|
286
|
+
this._drawingBufferHeight = height;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Set the viewport for rendering
|
|
290
|
+
viewport(x, y, width, height) {
|
|
291
|
+
this._assertNotDestroyed();
|
|
292
|
+
const ex = this._instance.exports;
|
|
293
|
+
if (!ex || typeof ex.wasm_ctx_viewport !== 'function') {
|
|
294
|
+
throw new Error('wasm_ctx_viewport not found');
|
|
295
|
+
}
|
|
296
|
+
const code = ex.wasm_ctx_viewport(this._ctxHandle, x | 0, y | 0, width >>> 0, height >>> 0);
|
|
297
|
+
_checkErr(code, this._instance);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** @type {Map<number, WasmWebGL2RenderingContext>} */
|
|
301
|
+
static _contexts = new Map();
|
|
302
|
+
|
|
303
|
+
destroy() {
|
|
304
|
+
if (this._destroyed) return;
|
|
305
|
+
WasmWebGL2RenderingContext._contexts.delete(this._ctxHandle);
|
|
306
|
+
const ex = this._instance.exports;
|
|
307
|
+
if (ex && typeof ex.wasm_destroy_context === 'function') {
|
|
308
|
+
const code = ex.wasm_destroy_context(this._ctxHandle);
|
|
309
|
+
_checkErr(code, this._instance);
|
|
310
|
+
}
|
|
311
|
+
this._destroyed = true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
_assertNotDestroyed() {
|
|
315
|
+
if (this._destroyed) throw new Error('context has been destroyed');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
createTexture() {
|
|
319
|
+
this._assertNotDestroyed();
|
|
320
|
+
const ex = this._instance.exports;
|
|
321
|
+
if (!ex || typeof ex.wasm_ctx_create_texture !== 'function') {
|
|
322
|
+
throw new Error('wasm_ctx_create_texture not found');
|
|
323
|
+
}
|
|
324
|
+
const handle = ex.wasm_ctx_create_texture(this._ctxHandle);
|
|
325
|
+
if (handle === 0) {
|
|
326
|
+
const msg = readErrorMessage(this._instance);
|
|
327
|
+
throw new Error(`Failed to create texture: ${msg}`);
|
|
328
|
+
}
|
|
329
|
+
// Return a thin wrapper object representing the texture.
|
|
330
|
+
return new WasmWebGLTexture(this, handle);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
deleteTexture(tex) {
|
|
334
|
+
this._assertNotDestroyed();
|
|
335
|
+
const ex = this._instance.exports;
|
|
336
|
+
if (!ex || typeof ex.wasm_ctx_delete_texture !== 'function') {
|
|
337
|
+
throw new Error('wasm_ctx_delete_texture not found');
|
|
338
|
+
}
|
|
339
|
+
const handle = tex && typeof tex === 'object' && typeof tex._handle === 'number' ? tex._handle : (tex >>> 0);
|
|
340
|
+
const code = ex.wasm_ctx_delete_texture(this._ctxHandle, handle);
|
|
341
|
+
_checkErr(code, this._instance);
|
|
342
|
+
// If a wrapper object was passed, mark it as deleted.
|
|
343
|
+
if (tex && typeof tex === 'object') {
|
|
344
|
+
try { tex._handle = 0; tex._deleted = true; } catch (e) { /* ignore */ }
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
bindTexture(target, tex) {
|
|
349
|
+
this._assertNotDestroyed();
|
|
350
|
+
const ex = this._instance.exports;
|
|
351
|
+
if (!ex || typeof ex.wasm_ctx_bind_texture !== 'function') {
|
|
352
|
+
throw new Error('wasm_ctx_bind_texture not found');
|
|
353
|
+
}
|
|
354
|
+
const handle = tex && typeof tex === 'object' && typeof tex._handle === 'number' ? tex._handle : (tex >>> 0);
|
|
355
|
+
const code = ex.wasm_ctx_bind_texture(this._ctxHandle, target >>> 0, handle);
|
|
356
|
+
_checkErr(code, this._instance);
|
|
357
|
+
// Record bound texture in JS so we can map units to texture data for texel fetch
|
|
358
|
+
this._boundTexture = handle;
|
|
359
|
+
this._textureUnits = this._textureUnits || [];
|
|
360
|
+
const unit = this._activeTextureUnit || 0;
|
|
361
|
+
this._textureUnits[unit] = handle;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
texImage2D(target, level, internalFormat, width, height, border, format, type_, pixels) {
|
|
365
|
+
this._assertNotDestroyed();
|
|
366
|
+
const ex = this._instance.exports;
|
|
367
|
+
if (!ex || typeof ex.wasm_ctx_tex_image_2d !== 'function') {
|
|
368
|
+
throw new Error('wasm_ctx_tex_image_2d not found');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
let data = pixels;
|
|
372
|
+
if (!data) {
|
|
373
|
+
data = new Uint8Array(width * height * 4);
|
|
374
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
375
|
+
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
376
|
+
} else if (data instanceof ArrayBuffer) {
|
|
377
|
+
data = new Uint8Array(data);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const len = data.length;
|
|
381
|
+
const ptr = ex.wasm_alloc(len);
|
|
382
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for pixel data');
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
386
|
+
mem.set(data, ptr);
|
|
387
|
+
|
|
388
|
+
const code = ex.wasm_ctx_tex_image_2d(
|
|
389
|
+
this._ctxHandle,
|
|
390
|
+
target >>> 0,
|
|
391
|
+
level >>> 0,
|
|
392
|
+
internalFormat >>> 0,
|
|
393
|
+
width >>> 0,
|
|
394
|
+
height >>> 0,
|
|
395
|
+
border >>> 0,
|
|
396
|
+
format >>> 0,
|
|
397
|
+
type_ >>> 0,
|
|
398
|
+
ptr >>> 0,
|
|
399
|
+
len >>> 0
|
|
400
|
+
);
|
|
401
|
+
_checkErr(code, this._instance);
|
|
402
|
+
} finally {
|
|
403
|
+
ex.wasm_free(ptr);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
texImage3D(target, level, internalFormat, width, height, depth, border, format, type_, pixels) {
|
|
408
|
+
this._assertNotDestroyed();
|
|
409
|
+
const ex = this._instance.exports;
|
|
410
|
+
if (!ex || typeof ex.wasm_ctx_tex_image_3d !== 'function') {
|
|
411
|
+
throw new Error('wasm_ctx_tex_image_3d not found');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let data = pixels;
|
|
415
|
+
if (!data) {
|
|
416
|
+
data = new Uint8Array(width * height * depth * 4);
|
|
417
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
418
|
+
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
419
|
+
} else if (data instanceof ArrayBuffer) {
|
|
420
|
+
data = new Uint8Array(data);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const len = data.length;
|
|
424
|
+
const ptr = ex.wasm_alloc(len);
|
|
425
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for pixel data');
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
429
|
+
mem.set(data, ptr);
|
|
430
|
+
|
|
431
|
+
const code = ex.wasm_ctx_tex_image_3d(
|
|
432
|
+
this._ctxHandle,
|
|
433
|
+
target >>> 0,
|
|
434
|
+
level >>> 0,
|
|
435
|
+
internalFormat >>> 0,
|
|
436
|
+
width >>> 0,
|
|
437
|
+
height >>> 0,
|
|
438
|
+
depth >>> 0,
|
|
439
|
+
border >>> 0,
|
|
440
|
+
format >>> 0,
|
|
441
|
+
type_ >>> 0,
|
|
442
|
+
ptr >>> 0,
|
|
443
|
+
len >>> 0
|
|
444
|
+
);
|
|
445
|
+
_checkErr(code, this._instance);
|
|
446
|
+
} finally {
|
|
447
|
+
ex.wasm_free(ptr);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
copyTexImage2D(target, level, internalFormat, x, y, width, height, border) {
|
|
452
|
+
this._assertNotDestroyed();
|
|
453
|
+
const ex = this._instance.exports;
|
|
454
|
+
if (!ex || typeof ex.wasm_ctx_copy_tex_image_2d !== 'function') {
|
|
455
|
+
throw new Error('wasm_ctx_copy_tex_image_2d not found');
|
|
456
|
+
}
|
|
457
|
+
const code = ex.wasm_ctx_copy_tex_image_2d(
|
|
458
|
+
this._ctxHandle,
|
|
459
|
+
target >>> 0,
|
|
460
|
+
level >>> 0,
|
|
461
|
+
internalFormat >>> 0,
|
|
462
|
+
x | 0,
|
|
463
|
+
y | 0,
|
|
464
|
+
width >>> 0,
|
|
465
|
+
height >>> 0,
|
|
466
|
+
border >>> 0
|
|
467
|
+
);
|
|
468
|
+
_checkErr(code, this._instance);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
createFramebuffer() {
|
|
472
|
+
this._assertNotDestroyed();
|
|
473
|
+
const ex = this._instance.exports;
|
|
474
|
+
if (!ex || typeof ex.wasm_ctx_create_framebuffer !== 'function') {
|
|
475
|
+
throw new Error('wasm_ctx_create_framebuffer not found');
|
|
476
|
+
}
|
|
477
|
+
const handle = ex.wasm_ctx_create_framebuffer(this._ctxHandle);
|
|
478
|
+
if (handle === 0) {
|
|
479
|
+
const msg = readErrorMessage(this._instance);
|
|
480
|
+
throw new Error(`Failed to create framebuffer: ${msg}`);
|
|
481
|
+
}
|
|
482
|
+
return new WasmWebGLFramebuffer(this, handle);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
deleteFramebuffer(fb) {
|
|
486
|
+
this._assertNotDestroyed();
|
|
487
|
+
const ex = this._instance.exports;
|
|
488
|
+
if (!ex || typeof ex.wasm_ctx_delete_framebuffer !== 'function') {
|
|
489
|
+
throw new Error('wasm_ctx_delete_framebuffer not found');
|
|
490
|
+
}
|
|
491
|
+
const handle = fb && typeof fb === 'object' && typeof fb._handle === 'number' ? fb._handle : (fb >>> 0);
|
|
492
|
+
const code = ex.wasm_ctx_delete_framebuffer(this._ctxHandle, handle);
|
|
493
|
+
_checkErr(code, this._instance);
|
|
494
|
+
if (fb && typeof fb === 'object') {
|
|
495
|
+
try { fb._handle = 0; fb._deleted = true; } catch (e) { /* ignore */ }
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
bindFramebuffer(target, fb) {
|
|
500
|
+
this._assertNotDestroyed();
|
|
501
|
+
const ex = this._instance.exports;
|
|
502
|
+
if (!ex || typeof ex.wasm_ctx_bind_framebuffer !== 'function') {
|
|
503
|
+
throw new Error('wasm_ctx_bind_framebuffer not found');
|
|
504
|
+
}
|
|
505
|
+
const handle = fb && typeof fb === 'object' && typeof fb._handle === 'number' ? fb._handle : (fb >>> 0);
|
|
506
|
+
const code = ex.wasm_ctx_bind_framebuffer(this._ctxHandle, target >>> 0, handle);
|
|
507
|
+
_checkErr(code, this._instance);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
framebufferTexture2D(target, attachment, textarget, texture, level) {
|
|
511
|
+
this._assertNotDestroyed();
|
|
512
|
+
const ex = this._instance.exports;
|
|
513
|
+
if (!ex || typeof ex.wasm_ctx_framebuffer_texture2d !== 'function') {
|
|
514
|
+
throw new Error('wasm_ctx_framebuffer_texture2d not found');
|
|
515
|
+
}
|
|
516
|
+
const texHandle = texture && typeof texture === 'object' && typeof texture._handle === 'number' ? texture._handle : (texture >>> 0);
|
|
517
|
+
const code = ex.wasm_ctx_framebuffer_texture2d(
|
|
518
|
+
this._ctxHandle,
|
|
519
|
+
target >>> 0,
|
|
520
|
+
attachment >>> 0,
|
|
521
|
+
textarget >>> 0,
|
|
522
|
+
texHandle,
|
|
523
|
+
level >>> 0
|
|
524
|
+
);
|
|
525
|
+
_checkErr(code, this._instance);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
createRenderbuffer() {
|
|
529
|
+
this._assertNotDestroyed();
|
|
530
|
+
const ex = this._instance.exports;
|
|
531
|
+
if (!ex || typeof ex.wasm_ctx_create_renderbuffer !== 'function') {
|
|
532
|
+
throw new Error('wasm_ctx_create_renderbuffer not found');
|
|
533
|
+
}
|
|
534
|
+
const handle = ex.wasm_ctx_create_renderbuffer(this._ctxHandle);
|
|
535
|
+
if (handle === 0) {
|
|
536
|
+
const msg = readErrorMessage(this._instance);
|
|
537
|
+
throw new Error(`Failed to create renderbuffer: ${msg}`);
|
|
538
|
+
}
|
|
539
|
+
return new WasmWebGLRenderbuffer(this, handle);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
bindRenderbuffer(target, renderbuffer) {
|
|
543
|
+
this._assertNotDestroyed();
|
|
544
|
+
const ex = this._instance.exports;
|
|
545
|
+
if (!ex || typeof ex.wasm_ctx_bind_renderbuffer !== 'function') {
|
|
546
|
+
throw new Error('wasm_ctx_bind_renderbuffer not found');
|
|
547
|
+
}
|
|
548
|
+
const rbHandle = renderbuffer && typeof renderbuffer === 'object' && typeof renderbuffer._handle === 'number' ? renderbuffer._handle : (renderbuffer >>> 0);
|
|
549
|
+
const code = ex.wasm_ctx_bind_renderbuffer(this._ctxHandle, target >>> 0, rbHandle);
|
|
550
|
+
_checkErr(code, this._instance);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
deleteRenderbuffer(renderbuffer) {
|
|
554
|
+
this._assertNotDestroyed();
|
|
555
|
+
const ex = this._instance.exports;
|
|
556
|
+
if (!ex || typeof ex.wasm_ctx_delete_renderbuffer !== 'function') {
|
|
557
|
+
throw new Error('wasm_ctx_delete_renderbuffer not found');
|
|
558
|
+
}
|
|
559
|
+
const rbHandle = renderbuffer && typeof renderbuffer === 'object' && typeof renderbuffer._handle === 'number' ? renderbuffer._handle : (renderbuffer >>> 0);
|
|
560
|
+
const code = ex.wasm_ctx_delete_renderbuffer(this._ctxHandle, rbHandle);
|
|
561
|
+
_checkErr(code, this._instance);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
isRenderbuffer(rb) {
|
|
565
|
+
this._assertNotDestroyed();
|
|
566
|
+
if (!rb || typeof rb !== 'object' || !(rb instanceof WasmWebGLRenderbuffer)) return false;
|
|
567
|
+
if (rb._ctx !== this) return false;
|
|
568
|
+
const ex = this._instance.exports;
|
|
569
|
+
return ex.wasm_ctx_is_renderbuffer(this._ctxHandle, rb._handle) !== 0;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
renderbufferStorage(target, internalFormat, width, height) {
|
|
573
|
+
this._assertNotDestroyed();
|
|
574
|
+
const ex = this._instance.exports;
|
|
575
|
+
if (!ex || typeof ex.wasm_ctx_renderbuffer_storage !== 'function') {
|
|
576
|
+
throw new Error('wasm_ctx_renderbuffer_storage not found');
|
|
577
|
+
}
|
|
578
|
+
const code = ex.wasm_ctx_renderbuffer_storage(this._ctxHandle, target >>> 0, internalFormat >>> 0, width | 0, height | 0);
|
|
579
|
+
_checkErr(code, this._instance);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
framebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) {
|
|
583
|
+
this._assertNotDestroyed();
|
|
584
|
+
const ex = this._instance.exports;
|
|
585
|
+
if (!ex || typeof ex.wasm_ctx_framebuffer_renderbuffer !== 'function') {
|
|
586
|
+
throw new Error('wasm_ctx_framebuffer_renderbuffer not found');
|
|
587
|
+
}
|
|
588
|
+
const rbHandle = renderbuffer && typeof renderbuffer === 'object' && typeof renderbuffer._handle === 'number' ? renderbuffer._handle : (renderbuffer >>> 0);
|
|
589
|
+
const code = ex.wasm_ctx_framebuffer_renderbuffer(
|
|
590
|
+
this._ctxHandle,
|
|
591
|
+
target >>> 0,
|
|
592
|
+
attachment >>> 0,
|
|
593
|
+
renderbuffertarget >>> 0,
|
|
594
|
+
rbHandle
|
|
595
|
+
);
|
|
596
|
+
_checkErr(code, this._instance);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
readPixels(x, y, width, height, format, type_, out) {
|
|
600
|
+
this._assertNotDestroyed();
|
|
601
|
+
const ex = this._instance.exports;
|
|
602
|
+
if (!ex || typeof ex.wasm_ctx_read_pixels !== 'function') {
|
|
603
|
+
throw new Error('wasm_ctx_read_pixels not found');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
let bpp = 4;
|
|
607
|
+
if (type_ === 0x1406) { // GL_FLOAT
|
|
608
|
+
if (format === 0x1908) bpp = 16; // GL_RGBA
|
|
609
|
+
else if (format === 0x8227) bpp = 8; // GL_RG
|
|
610
|
+
else if (format === 0x1903) bpp = 4; // GL_RED
|
|
611
|
+
} else if (type_ === 0x1401) { // GL_UNSIGNED_BYTE
|
|
612
|
+
if (format === 0x1908) bpp = 4;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const len = width * height * bpp;
|
|
616
|
+
if (!out || out.byteLength < len) {
|
|
617
|
+
throw new Error(`output buffer too small (need ${len} bytes, have ${out ? out.byteLength : 0})`);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const ptr = ex.wasm_alloc(len);
|
|
621
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for readPixels output');
|
|
622
|
+
|
|
623
|
+
try {
|
|
624
|
+
const code = ex.wasm_ctx_read_pixels(
|
|
625
|
+
this._ctxHandle,
|
|
626
|
+
x | 0,
|
|
627
|
+
y | 0,
|
|
628
|
+
width >>> 0,
|
|
629
|
+
height >>> 0,
|
|
630
|
+
format >>> 0,
|
|
631
|
+
type_ >>> 0,
|
|
632
|
+
ptr >>> 0,
|
|
633
|
+
len >>> 0
|
|
634
|
+
);
|
|
635
|
+
_checkErr(code, this._instance);
|
|
636
|
+
|
|
637
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
638
|
+
const src = mem.subarray(ptr, ptr + len);
|
|
639
|
+
const out_bytes = new Uint8Array(out.buffer, out.byteOffset, len);
|
|
640
|
+
out_bytes.set(src);
|
|
641
|
+
} finally {
|
|
642
|
+
ex.wasm_free(ptr);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// --- Stubs for unimplemented WebGL2 methods (forwarding API surface) ---
|
|
647
|
+
// These are intentionally not implemented in the prototype. They allow
|
|
648
|
+
// callers to detect missing functionality early with a uniform error.
|
|
649
|
+
|
|
650
|
+
createShader(type) {
|
|
651
|
+
this._assertNotDestroyed();
|
|
652
|
+
const ex = this._instance.exports;
|
|
653
|
+
if (!ex || typeof ex.wasm_ctx_create_shader !== 'function') {
|
|
654
|
+
throw new Error('wasm_ctx_create_shader not found');
|
|
655
|
+
}
|
|
656
|
+
const handle = ex.wasm_ctx_create_shader(this._ctxHandle, type >>> 0);
|
|
657
|
+
if (handle === 0) {
|
|
658
|
+
const msg = readErrorMessage(this._instance);
|
|
659
|
+
throw new Error(`Failed to create shader: ${msg}`);
|
|
660
|
+
}
|
|
661
|
+
return new WasmWebGLShader(this, handle);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
shaderSource(shader, source) {
|
|
665
|
+
this._assertNotDestroyed();
|
|
666
|
+
const ex = this._instance.exports;
|
|
667
|
+
if (!ex || typeof ex.wasm_ctx_shader_source !== 'function') {
|
|
668
|
+
throw new Error('wasm_ctx_shader_source not found');
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
672
|
+
const sourceStr = String(source);
|
|
673
|
+
const bytes = new TextEncoder().encode(sourceStr);
|
|
674
|
+
const len = bytes.length;
|
|
675
|
+
const ptr = ex.wasm_alloc(len);
|
|
676
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for shaderSource');
|
|
677
|
+
|
|
678
|
+
try {
|
|
679
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
680
|
+
mem.set(bytes, ptr);
|
|
681
|
+
const code = ex.wasm_ctx_shader_source(this._ctxHandle, shaderHandle, ptr, len);
|
|
682
|
+
_checkErr(code, this._instance);
|
|
683
|
+
} finally {
|
|
684
|
+
ex.wasm_free(ptr);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
compileShader(shader) {
|
|
689
|
+
this._assertNotDestroyed();
|
|
690
|
+
const ex = this._instance.exports;
|
|
691
|
+
if (!ex || typeof ex.wasm_ctx_compile_shader !== 'function') {
|
|
692
|
+
throw new Error('wasm_ctx_compile_shader not found');
|
|
693
|
+
}
|
|
694
|
+
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
695
|
+
const code = ex.wasm_ctx_compile_shader(this._ctxHandle, shaderHandle);
|
|
696
|
+
_checkErr(code, this._instance);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
deleteShader(shader) {
|
|
700
|
+
this._assertNotDestroyed();
|
|
701
|
+
const ex = this._instance.exports;
|
|
702
|
+
if (!ex || typeof ex.wasm_ctx_delete_shader !== 'function') {
|
|
703
|
+
throw new Error('wasm_ctx_delete_shader not found');
|
|
704
|
+
}
|
|
705
|
+
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
706
|
+
const code = ex.wasm_ctx_delete_shader(this._ctxHandle, shaderHandle);
|
|
707
|
+
_checkErr(code, this._instance);
|
|
708
|
+
if (shader && typeof shader === 'object') {
|
|
709
|
+
try { shader._handle = 0; shader._deleted = true; } catch (e) { /* ignore */ }
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
createProgram() {
|
|
714
|
+
this._assertNotDestroyed();
|
|
715
|
+
const ex = this._instance.exports;
|
|
716
|
+
if (!ex || typeof ex.wasm_ctx_create_program !== 'function') {
|
|
717
|
+
throw new Error('wasm_ctx_create_program not found');
|
|
718
|
+
}
|
|
719
|
+
const handle = ex.wasm_ctx_create_program(this._ctxHandle);
|
|
720
|
+
if (handle === 0) {
|
|
721
|
+
const msg = readErrorMessage(this._instance);
|
|
722
|
+
throw new Error(`Failed to create program: ${msg}`);
|
|
723
|
+
}
|
|
724
|
+
return new WasmWebGLProgram(this, handle);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
attachShader(program, shader) {
|
|
728
|
+
this._assertNotDestroyed();
|
|
729
|
+
const ex = this._instance.exports;
|
|
730
|
+
if (!ex || typeof ex.wasm_ctx_attach_shader !== 'function') {
|
|
731
|
+
throw new Error('wasm_ctx_attach_shader not found');
|
|
732
|
+
}
|
|
733
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
734
|
+
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
735
|
+
const code = ex.wasm_ctx_attach_shader(this._ctxHandle, programHandle, shaderHandle);
|
|
736
|
+
_checkErr(code, this._instance);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
detachShader(program, shader) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
740
|
+
|
|
741
|
+
getActiveUniform(program, index) {
|
|
742
|
+
this._assertNotDestroyed();
|
|
743
|
+
const ex = this._instance.exports;
|
|
744
|
+
if (!ex || typeof ex.wasm_ctx_get_active_uniform !== 'function') {
|
|
745
|
+
throw new Error('wasm_ctx_get_active_uniform not found');
|
|
746
|
+
}
|
|
747
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
748
|
+
|
|
749
|
+
// Allocate buffers: size(4) + type(4) + name(256)
|
|
750
|
+
const sizePtr = ex.wasm_alloc(4);
|
|
751
|
+
const typePtr = ex.wasm_alloc(4);
|
|
752
|
+
const nameMaxLen = 256;
|
|
753
|
+
const namePtr = ex.wasm_alloc(nameMaxLen);
|
|
754
|
+
|
|
755
|
+
try {
|
|
756
|
+
const nameLen = ex.wasm_ctx_get_active_uniform(
|
|
757
|
+
this._ctxHandle,
|
|
758
|
+
programHandle,
|
|
759
|
+
index >>> 0,
|
|
760
|
+
sizePtr,
|
|
761
|
+
typePtr,
|
|
762
|
+
namePtr,
|
|
763
|
+
nameMaxLen
|
|
764
|
+
);
|
|
765
|
+
|
|
766
|
+
if (nameLen === 0) {
|
|
767
|
+
return null;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const mem32SizeIdx = sizePtr >>> 2;
|
|
771
|
+
const mem32TypeIdx = typePtr >>> 2;
|
|
772
|
+
|
|
773
|
+
const size = new Int32Array(ex.memory.buffer)[mem32SizeIdx];
|
|
774
|
+
const type_ = new Uint32Array(ex.memory.buffer)[mem32TypeIdx];
|
|
775
|
+
|
|
776
|
+
const nameBytes = new Uint8Array(ex.memory.buffer, namePtr, nameLen);
|
|
777
|
+
const name = new TextDecoder().decode(nameBytes);
|
|
778
|
+
|
|
779
|
+
return { name, size, type: type_ };
|
|
780
|
+
|
|
781
|
+
} finally {
|
|
782
|
+
ex.wasm_free(sizePtr);
|
|
783
|
+
ex.wasm_free(typePtr);
|
|
784
|
+
ex.wasm_free(namePtr);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
getActiveAttrib(program, index) {
|
|
789
|
+
this._assertNotDestroyed();
|
|
790
|
+
const ex = this._instance.exports;
|
|
791
|
+
if (!ex || typeof ex.wasm_ctx_get_active_attrib !== 'function') {
|
|
792
|
+
throw new Error('wasm_ctx_get_active_attrib not found');
|
|
793
|
+
}
|
|
794
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
795
|
+
|
|
796
|
+
// Allocate buffers: size(4) + type(4) + name(256)
|
|
797
|
+
const sizePtr = ex.wasm_alloc(4);
|
|
798
|
+
const typePtr = ex.wasm_alloc(4);
|
|
799
|
+
const nameMaxLen = 256;
|
|
800
|
+
const namePtr = ex.wasm_alloc(nameMaxLen);
|
|
801
|
+
|
|
802
|
+
try {
|
|
803
|
+
const nameLen = ex.wasm_ctx_get_active_attrib(
|
|
804
|
+
this._ctxHandle,
|
|
805
|
+
programHandle,
|
|
806
|
+
index >>> 0,
|
|
807
|
+
sizePtr,
|
|
808
|
+
typePtr,
|
|
809
|
+
namePtr,
|
|
810
|
+
nameMaxLen
|
|
811
|
+
);
|
|
812
|
+
|
|
813
|
+
if (nameLen === 0) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const mem32SizeIdx = sizePtr >>> 2;
|
|
818
|
+
const mem32TypeIdx = typePtr >>> 2;
|
|
819
|
+
|
|
820
|
+
const size = new Int32Array(ex.memory.buffer)[mem32SizeIdx];
|
|
821
|
+
const type_ = new Uint32Array(ex.memory.buffer)[mem32TypeIdx];
|
|
822
|
+
|
|
823
|
+
const nameBytes = new Uint8Array(ex.memory.buffer, namePtr, nameLen);
|
|
824
|
+
const name = new TextDecoder().decode(nameBytes);
|
|
825
|
+
|
|
826
|
+
return { name, size, type: type_ };
|
|
827
|
+
|
|
828
|
+
} finally {
|
|
829
|
+
ex.wasm_free(sizePtr);
|
|
830
|
+
ex.wasm_free(typePtr);
|
|
831
|
+
ex.wasm_free(namePtr);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
linkProgram(program) {
|
|
836
|
+
this._assertNotDestroyed();
|
|
837
|
+
const ex = this._instance.exports;
|
|
838
|
+
if (!ex || typeof ex.wasm_ctx_link_program !== 'function') {
|
|
839
|
+
throw new Error('wasm_ctx_link_program not found');
|
|
840
|
+
}
|
|
841
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
842
|
+
const code = ex.wasm_ctx_link_program(this._ctxHandle, programHandle);
|
|
843
|
+
_checkErr(code, this._instance);
|
|
844
|
+
|
|
845
|
+
// After linking, we need to instantiate the WASM modules on the host.
|
|
846
|
+
if (program && typeof program === 'object') {
|
|
847
|
+
const linkStatus = this.getProgramParameter(program, this.LINK_STATUS);
|
|
848
|
+
if (linkStatus) {
|
|
849
|
+
this._instantiateProgramShaders(program);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
_instantiateProgramShaders(program) {
|
|
855
|
+
const vsWasm = this.getProgramWasm(program, this.VERTEX_SHADER);
|
|
856
|
+
const fsWasm = this.getProgramWasm(program, this.FRAGMENT_SHADER);
|
|
857
|
+
|
|
858
|
+
if (!vsWasm || !fsWasm) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// Allocate table slots for both shaders
|
|
863
|
+
const vsIdx = this._tableAllocator ? this._tableAllocator.allocate() : null;
|
|
864
|
+
const fsIdx = this._tableAllocator ? this._tableAllocator.allocate() : null;
|
|
865
|
+
|
|
866
|
+
const createDebugEnv = (type, instanceRef) => {
|
|
867
|
+
if (!this._debugShaders) return {};
|
|
868
|
+
|
|
869
|
+
const stubCode = this.getProgramDebugStub(program, type);
|
|
870
|
+
if (!stubCode) return {};
|
|
871
|
+
|
|
872
|
+
// // Add sourceURL for debugging
|
|
873
|
+
// const debugName = `shader_stub_program_${program._handle}_${type === this.VERTEX_SHADER ? 'vs' : 'fs'}.js`;
|
|
874
|
+
// const codeWithUrl = stubCode + `\n//# sourceURL=${debugName}`;
|
|
875
|
+
|
|
876
|
+
let stubFuncs;
|
|
877
|
+
try {
|
|
878
|
+
// Eval the stub array
|
|
879
|
+
stubFuncs = (0, eval)(stubCode);
|
|
880
|
+
} catch (e) {
|
|
881
|
+
console.error("Failed to eval debug stub:", e);
|
|
882
|
+
return {};
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
return {
|
|
886
|
+
debug_step: (line, funcIdx, resultPtr) => {
|
|
887
|
+
if (line === 999999) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
const func = stubFuncs[line - 1];
|
|
891
|
+
if (func) {
|
|
892
|
+
const ctx = {
|
|
893
|
+
go: () => {
|
|
894
|
+
// Trampoline logic would go here
|
|
895
|
+
// For now we rely on WASM calling the function after debug_step returns
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
try {
|
|
899
|
+
func.call(ctx);
|
|
900
|
+
} catch (e) {
|
|
901
|
+
console.error("Error in debug stub:", e);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
};
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
let vsModule;
|
|
909
|
+
vsModule = new WebAssembly.Module(vsWasm);
|
|
910
|
+
const vsInstanceRef = { current: null };
|
|
911
|
+
const vsDebugEnv = createDebugEnv(this.VERTEX_SHADER, vsInstanceRef);
|
|
912
|
+
|
|
913
|
+
const env = {
|
|
914
|
+
memory: this._instance.exports.memory,
|
|
915
|
+
__indirect_function_table: this._sharedTable,
|
|
916
|
+
ACTIVE_ATTR_PTR: this._turboGlobals.ACTIVE_ATTR_PTR,
|
|
917
|
+
ACTIVE_UNIFORM_PTR: this._turboGlobals.ACTIVE_UNIFORM_PTR,
|
|
918
|
+
ACTIVE_VARYING_PTR: this._turboGlobals.ACTIVE_VARYING_PTR,
|
|
919
|
+
ACTIVE_PRIVATE_PTR: this._turboGlobals.ACTIVE_PRIVATE_PTR,
|
|
920
|
+
ACTIVE_TEXTURE_PTR: this._turboGlobals.ACTIVE_TEXTURE_PTR,
|
|
921
|
+
ACTIVE_FRAME_SP: this._turboGlobals.ACTIVE_FRAME_SP,
|
|
922
|
+
...vsDebugEnv
|
|
923
|
+
};
|
|
924
|
+
|
|
925
|
+
// Add math builtins from renderer (skipping host)
|
|
926
|
+
const mathFuncs = [
|
|
927
|
+
'gl_sin', 'gl_cos', 'gl_tan', 'gl_asin', 'gl_acos', 'gl_atan', 'gl_atan2',
|
|
928
|
+
'gl_exp', 'gl_exp2', 'gl_log', 'gl_log2', 'gl_pow',
|
|
929
|
+
'gl_sinh', 'gl_cosh', 'gl_tanh', 'gl_asinh', 'gl_acosh', 'gl_atanh'
|
|
930
|
+
];
|
|
931
|
+
for (const name of mathFuncs) {
|
|
932
|
+
if (this._instance.exports[name]) {
|
|
933
|
+
env[name] = this._instance.exports[name];
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
program._vsInstance = new WebAssembly.Instance(vsModule, {
|
|
938
|
+
env
|
|
939
|
+
});
|
|
940
|
+
vsInstanceRef.current = program._vsInstance;
|
|
941
|
+
|
|
942
|
+
// Register in table
|
|
943
|
+
if (this._sharedTable && vsIdx !== null && program._vsInstance.exports.main) {
|
|
944
|
+
this._sharedTable.set(vsIdx, program._vsInstance.exports.main);
|
|
945
|
+
program._vsTableIndex = vsIdx;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
let fsModule;
|
|
949
|
+
fsModule = new WebAssembly.Module(fsWasm);
|
|
950
|
+
const fsInstanceRef = { current: null };
|
|
951
|
+
const fsDebugEnv = createDebugEnv(this.FRAGMENT_SHADER, fsInstanceRef);
|
|
952
|
+
|
|
953
|
+
const fsEnv = {
|
|
954
|
+
memory: this._instance.exports.memory,
|
|
955
|
+
__indirect_function_table: this._sharedTable,
|
|
956
|
+
ACTIVE_ATTR_PTR: this._turboGlobals.ACTIVE_ATTR_PTR,
|
|
957
|
+
ACTIVE_UNIFORM_PTR: this._turboGlobals.ACTIVE_UNIFORM_PTR,
|
|
958
|
+
ACTIVE_VARYING_PTR: this._turboGlobals.ACTIVE_VARYING_PTR,
|
|
959
|
+
ACTIVE_PRIVATE_PTR: this._turboGlobals.ACTIVE_PRIVATE_PTR,
|
|
960
|
+
ACTIVE_TEXTURE_PTR: this._turboGlobals.ACTIVE_TEXTURE_PTR,
|
|
961
|
+
ACTIVE_FRAME_SP: this._turboGlobals.ACTIVE_FRAME_SP,
|
|
962
|
+
...fsDebugEnv
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
for (const name of mathFuncs) {
|
|
966
|
+
if (this._instance.exports[name]) {
|
|
967
|
+
fsEnv[name] = this._instance.exports[name];
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
program._fsInstance = new WebAssembly.Instance(fsModule, {
|
|
972
|
+
env: fsEnv
|
|
973
|
+
});
|
|
974
|
+
fsInstanceRef.current = program._fsInstance;
|
|
975
|
+
|
|
976
|
+
// Register in table
|
|
977
|
+
if (this._sharedTable && fsIdx !== null && program._fsInstance.exports.main) {
|
|
978
|
+
this._sharedTable.set(fsIdx, program._fsInstance.exports.main);
|
|
979
|
+
program._fsTableIndex = fsIdx;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// Notify Rust of table indices (requires Phase 4)
|
|
983
|
+
if (vsIdx !== null && fsIdx !== null) {
|
|
984
|
+
const ex = this._instance.exports;
|
|
985
|
+
if (ex.wasm_ctx_register_shader_indices) {
|
|
986
|
+
ex.wasm_ctx_register_shader_indices(
|
|
987
|
+
this._ctxHandle,
|
|
988
|
+
program._handle,
|
|
989
|
+
vsIdx,
|
|
990
|
+
fsIdx
|
|
991
|
+
);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
getProgramDebugStub(program, shaderType) {
|
|
997
|
+
this._assertNotDestroyed();
|
|
998
|
+
const ex = this._instance.exports;
|
|
999
|
+
if (!ex || typeof ex.wasm_ctx_get_program_debug_stub !== 'function') {
|
|
1000
|
+
return null;
|
|
1001
|
+
}
|
|
1002
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1003
|
+
const len = ex.wasm_ctx_get_program_debug_stub(this._ctxHandle, programHandle, shaderType, 0, 0);
|
|
1004
|
+
if (len === 0) return null;
|
|
1005
|
+
|
|
1006
|
+
const ptr = ex.wasm_alloc(len);
|
|
1007
|
+
if (ptr === 0) return null;
|
|
1008
|
+
|
|
1009
|
+
try {
|
|
1010
|
+
const actualLen = ex.wasm_ctx_get_program_debug_stub(this._ctxHandle, programHandle, shaderType, ptr, len);
|
|
1011
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1012
|
+
const bytes = mem.subarray(ptr, ptr + actualLen);
|
|
1013
|
+
return new TextDecoder().decode(bytes);
|
|
1014
|
+
} finally {
|
|
1015
|
+
ex.wasm_free(ptr);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
deleteProgram(program) {
|
|
1020
|
+
this._assertNotDestroyed();
|
|
1021
|
+
const ex = this._instance.exports;
|
|
1022
|
+
if (!ex || typeof ex.wasm_ctx_delete_program !== 'function') {
|
|
1023
|
+
throw new Error('wasm_ctx_delete_program not found');
|
|
1024
|
+
}
|
|
1025
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1026
|
+
|
|
1027
|
+
// Table indices are now freed by Rust when the Program's refcount reaches zero.
|
|
1028
|
+
// This allows bound programs to remain valid even if deleted by the user,
|
|
1029
|
+
// as required by the WebGL specification.
|
|
1030
|
+
|
|
1031
|
+
const code = ex.wasm_ctx_delete_program(this._ctxHandle, programHandle);
|
|
1032
|
+
_checkErr(code, this._instance);
|
|
1033
|
+
if (program && typeof program === 'object') {
|
|
1034
|
+
try { program._handle = 0; program._deleted = true; } catch (e) { /* ignore */ }
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
useProgram(program) {
|
|
1039
|
+
this._assertNotDestroyed();
|
|
1040
|
+
const ex = this._instance.exports;
|
|
1041
|
+
if (!ex || typeof ex.wasm_ctx_use_program !== 'function') {
|
|
1042
|
+
throw new Error('wasm_ctx_use_program not found');
|
|
1043
|
+
}
|
|
1044
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1045
|
+
const code = ex.wasm_ctx_use_program(this._ctxHandle, programHandle);
|
|
1046
|
+
_checkErr(code, this._instance);
|
|
1047
|
+
this._currentProgram = program;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
getShaderParameter(shader, pname) {
|
|
1051
|
+
this._assertNotDestroyed();
|
|
1052
|
+
const ex = this._instance.exports;
|
|
1053
|
+
if (!ex || typeof ex.wasm_ctx_get_shader_parameter !== 'function') {
|
|
1054
|
+
throw new Error('wasm_ctx_get_shader_parameter not found');
|
|
1055
|
+
}
|
|
1056
|
+
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
1057
|
+
const val = ex.wasm_ctx_get_shader_parameter(this._ctxHandle, shaderHandle, pname >>> 0);
|
|
1058
|
+
|
|
1059
|
+
// WebGL returns boolean for status parameters
|
|
1060
|
+
if (pname === 0x8B81 /* COMPILE_STATUS */ || pname === 0x8B80 /* DELETE_STATUS */) {
|
|
1061
|
+
return !!val;
|
|
1062
|
+
}
|
|
1063
|
+
return val;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
getProgramParameter(program, pname) {
|
|
1067
|
+
this._assertNotDestroyed();
|
|
1068
|
+
const ex = this._instance.exports;
|
|
1069
|
+
if (!ex || typeof ex.wasm_ctx_get_program_parameter !== 'function') {
|
|
1070
|
+
throw new Error('wasm_ctx_get_program_parameter not found');
|
|
1071
|
+
}
|
|
1072
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1073
|
+
const val = ex.wasm_ctx_get_program_parameter(this._ctxHandle, programHandle, pname >>> 0);
|
|
1074
|
+
|
|
1075
|
+
// WebGL returns boolean for status parameters
|
|
1076
|
+
if (pname === 0x8B82 /* LINK_STATUS */ || pname === 0x8B80 /* DELETE_STATUS */ || pname === 0x8B83 /* VALIDATE_STATUS */) {
|
|
1077
|
+
return !!val;
|
|
1078
|
+
}
|
|
1079
|
+
return val;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
getShaderInfoLog(shader) {
|
|
1083
|
+
this._assertNotDestroyed();
|
|
1084
|
+
const ex = this._instance.exports;
|
|
1085
|
+
if (!ex || typeof ex.wasm_ctx_get_shader_info_log !== 'function') {
|
|
1086
|
+
throw new Error('wasm_ctx_get_shader_info_log not found');
|
|
1087
|
+
}
|
|
1088
|
+
const shaderHandle = shader && typeof shader === 'object' && typeof shader._handle === 'number' ? shader._handle : (shader >>> 0);
|
|
1089
|
+
|
|
1090
|
+
const maxLen = 1024;
|
|
1091
|
+
const ptr = ex.wasm_alloc(maxLen);
|
|
1092
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for getShaderInfoLog');
|
|
1093
|
+
|
|
1094
|
+
try {
|
|
1095
|
+
const len = ex.wasm_ctx_get_shader_info_log(this._ctxHandle, shaderHandle, ptr, maxLen);
|
|
1096
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1097
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
1098
|
+
return new TextDecoder().decode(bytes);
|
|
1099
|
+
} finally {
|
|
1100
|
+
ex.wasm_free(ptr);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
getProgramInfoLog(program) {
|
|
1105
|
+
this._assertNotDestroyed();
|
|
1106
|
+
const ex = this._instance.exports;
|
|
1107
|
+
if (!ex || typeof ex.wasm_ctx_get_program_info_log !== 'function') {
|
|
1108
|
+
throw new Error('wasm_ctx_get_program_info_log not found');
|
|
1109
|
+
}
|
|
1110
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1111
|
+
|
|
1112
|
+
const maxLen = 1024;
|
|
1113
|
+
const ptr = ex.wasm_alloc(maxLen);
|
|
1114
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for getProgramInfoLog');
|
|
1115
|
+
|
|
1116
|
+
try {
|
|
1117
|
+
const len = ex.wasm_ctx_get_program_info_log(this._ctxHandle, programHandle, ptr, maxLen);
|
|
1118
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1119
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
1120
|
+
return new TextDecoder().decode(bytes);
|
|
1121
|
+
} finally {
|
|
1122
|
+
ex.wasm_free(ptr);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
getProgramWasm(program, shaderType) {
|
|
1127
|
+
this._assertNotDestroyed();
|
|
1128
|
+
const ex = this._instance.exports;
|
|
1129
|
+
if (!ex || typeof ex.wasm_ctx_get_program_wasm_len !== 'function') {
|
|
1130
|
+
throw new Error('wasm_ctx_get_program_wasm_len not found');
|
|
1131
|
+
}
|
|
1132
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1133
|
+
const len = ex.wasm_ctx_get_program_wasm_len(this._ctxHandle, programHandle, shaderType);
|
|
1134
|
+
if (len === 0) return null;
|
|
1135
|
+
|
|
1136
|
+
const ptr = ex.wasm_alloc(len);
|
|
1137
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for getProgramWasm');
|
|
1138
|
+
|
|
1139
|
+
try {
|
|
1140
|
+
const actualLen = ex.wasm_ctx_get_program_wasm(this._ctxHandle, programHandle, shaderType, ptr, len);
|
|
1141
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1142
|
+
return new Uint8Array(mem.buffer, ptr, actualLen).slice();
|
|
1143
|
+
} finally {
|
|
1144
|
+
ex.wasm_free(ptr);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
getAttribLocation(program, name) {
|
|
1149
|
+
this._assertNotDestroyed();
|
|
1150
|
+
const ex = this._instance.exports;
|
|
1151
|
+
if (!ex || typeof ex.wasm_ctx_get_attrib_location !== 'function') {
|
|
1152
|
+
throw new Error('wasm_ctx_get_attrib_location not found');
|
|
1153
|
+
}
|
|
1154
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1155
|
+
const nameStr = String(name);
|
|
1156
|
+
const bytes = new TextEncoder().encode(nameStr);
|
|
1157
|
+
const len = bytes.length;
|
|
1158
|
+
const ptr = ex.wasm_alloc(len);
|
|
1159
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for getAttribLocation');
|
|
1160
|
+
|
|
1161
|
+
try {
|
|
1162
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1163
|
+
mem.set(bytes, ptr);
|
|
1164
|
+
return ex.wasm_ctx_get_attrib_location(this._ctxHandle, programHandle, ptr, len);
|
|
1165
|
+
} finally {
|
|
1166
|
+
ex.wasm_free(ptr);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
bindAttribLocation(program, index, name) {
|
|
1171
|
+
this._assertNotDestroyed();
|
|
1172
|
+
const ex = this._instance.exports;
|
|
1173
|
+
if (!ex || typeof ex.wasm_ctx_bind_attrib_location !== 'function') {
|
|
1174
|
+
throw new Error('wasm_ctx_bind_attrib_location not found');
|
|
1175
|
+
}
|
|
1176
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1177
|
+
const nameStr = String(name);
|
|
1178
|
+
const bytes = new TextEncoder().encode(nameStr);
|
|
1179
|
+
const len = bytes.length;
|
|
1180
|
+
const ptr = ex.wasm_alloc(len);
|
|
1181
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for bindAttribLocation');
|
|
1182
|
+
|
|
1183
|
+
try {
|
|
1184
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1185
|
+
mem.set(bytes, ptr);
|
|
1186
|
+
const code = ex.wasm_ctx_bind_attrib_location(this._ctxHandle, programHandle, index >>> 0, ptr, len);
|
|
1187
|
+
_checkErr(code, this._instance);
|
|
1188
|
+
} finally {
|
|
1189
|
+
ex.wasm_free(ptr);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
enableVertexAttribArray(index) {
|
|
1194
|
+
this._assertNotDestroyed();
|
|
1195
|
+
const ex = this._instance.exports;
|
|
1196
|
+
if (!ex || typeof ex.wasm_ctx_enable_vertex_attrib_array !== 'function') {
|
|
1197
|
+
throw new Error('wasm_ctx_enable_vertex_attrib_array not found');
|
|
1198
|
+
}
|
|
1199
|
+
const code = ex.wasm_ctx_enable_vertex_attrib_array(this._ctxHandle, index >>> 0);
|
|
1200
|
+
_checkErr(code, this._instance);
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
disableVertexAttribArray(index) {
|
|
1204
|
+
this._assertNotDestroyed();
|
|
1205
|
+
const ex = this._instance.exports;
|
|
1206
|
+
if (!ex || typeof ex.wasm_ctx_disable_vertex_attrib_array !== 'function') {
|
|
1207
|
+
throw new Error('wasm_ctx_disable_vertex_attrib_array not found');
|
|
1208
|
+
}
|
|
1209
|
+
const code = ex.wasm_ctx_disable_vertex_attrib_array(this._ctxHandle, index >>> 0);
|
|
1210
|
+
_checkErr(code, this._instance);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
vertexAttribPointer(index, size, type, normalized, stride, offset) {
|
|
1214
|
+
this._assertNotDestroyed();
|
|
1215
|
+
const ex = this._instance.exports;
|
|
1216
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib_pointer !== 'function') {
|
|
1217
|
+
throw new Error('wasm_ctx_vertex_attrib_pointer not found');
|
|
1218
|
+
}
|
|
1219
|
+
const code = ex.wasm_ctx_vertex_attrib_pointer(
|
|
1220
|
+
this._ctxHandle,
|
|
1221
|
+
index >>> 0,
|
|
1222
|
+
size >>> 0,
|
|
1223
|
+
type >>> 0,
|
|
1224
|
+
normalized ? 1 : 0,
|
|
1225
|
+
stride >>> 0,
|
|
1226
|
+
offset >>> 0
|
|
1227
|
+
);
|
|
1228
|
+
if (code === 5) return; // ERR_GL
|
|
1229
|
+
_checkErr(code, this._instance);
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
vertexAttribIPointer(index, size, type, stride, offset) {
|
|
1233
|
+
this._assertNotDestroyed();
|
|
1234
|
+
const ex = this._instance.exports;
|
|
1235
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib_ipointer !== 'function') {
|
|
1236
|
+
throw new Error('wasm_ctx_vertex_attrib_ipointer not found');
|
|
1237
|
+
}
|
|
1238
|
+
const code = ex.wasm_ctx_vertex_attrib_ipointer(
|
|
1239
|
+
this._ctxHandle,
|
|
1240
|
+
index >>> 0,
|
|
1241
|
+
size >>> 0,
|
|
1242
|
+
type >>> 0,
|
|
1243
|
+
stride >>> 0,
|
|
1244
|
+
offset >>> 0
|
|
1245
|
+
);
|
|
1246
|
+
if (code === 5) return; // ERR_GL
|
|
1247
|
+
_checkErr(code, this._instance);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
vertexAttrib1f(index, v0) {
|
|
1251
|
+
this._assertNotDestroyed();
|
|
1252
|
+
const ex = this._instance.exports;
|
|
1253
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib1f !== 'function') {
|
|
1254
|
+
throw new Error('wasm_ctx_vertex_attrib1f not found');
|
|
1255
|
+
}
|
|
1256
|
+
const code = ex.wasm_ctx_vertex_attrib1f(this._ctxHandle, index >>> 0, +v0);
|
|
1257
|
+
if (code === 5) return; // ERR_GL
|
|
1258
|
+
_checkErr(code, this._instance);
|
|
1259
|
+
}
|
|
1260
|
+
vertexAttrib2f(index, v0, v1) {
|
|
1261
|
+
this._assertNotDestroyed();
|
|
1262
|
+
const ex = this._instance.exports;
|
|
1263
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib2f !== 'function') {
|
|
1264
|
+
throw new Error('wasm_ctx_vertex_attrib2f not found');
|
|
1265
|
+
}
|
|
1266
|
+
const code = ex.wasm_ctx_vertex_attrib2f(this._ctxHandle, index >>> 0, +v0, +v1);
|
|
1267
|
+
if (code === 5) return; // ERR_GL
|
|
1268
|
+
_checkErr(code, this._instance);
|
|
1269
|
+
}
|
|
1270
|
+
vertexAttrib3f(index, v0, v1, v2) {
|
|
1271
|
+
this._assertNotDestroyed();
|
|
1272
|
+
const ex = this._instance.exports;
|
|
1273
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib3f !== 'function') {
|
|
1274
|
+
throw new Error('wasm_ctx_vertex_attrib3f not found');
|
|
1275
|
+
}
|
|
1276
|
+
const code = ex.wasm_ctx_vertex_attrib3f(this._ctxHandle, index >>> 0, +v0, +v1, +v2);
|
|
1277
|
+
if (code === 5) return; // ERR_GL
|
|
1278
|
+
_checkErr(code, this._instance);
|
|
1279
|
+
}
|
|
1280
|
+
vertexAttrib4f(index, v0, v1, v2, v3) {
|
|
1281
|
+
this._assertNotDestroyed();
|
|
1282
|
+
const ex = this._instance.exports;
|
|
1283
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib4f !== 'function') {
|
|
1284
|
+
throw new Error('wasm_ctx_vertex_attrib4f not found');
|
|
1285
|
+
}
|
|
1286
|
+
const code = ex.wasm_ctx_vertex_attrib4f(this._ctxHandle, index >>> 0, +v0, +v1, +v2, +v3);
|
|
1287
|
+
if (code === 5) return; // ERR_GL
|
|
1288
|
+
_checkErr(code, this._instance);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
vertexAttrib1fv(index, v) {
|
|
1292
|
+
if (v && v.length >= 1) {
|
|
1293
|
+
this.vertexAttrib1f(index, v[0]);
|
|
1294
|
+
} else {
|
|
1295
|
+
this._setError(0x0501);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
vertexAttrib2fv(index, v) {
|
|
1299
|
+
if (v && v.length >= 2) {
|
|
1300
|
+
this.vertexAttrib2f(index, v[0], v[1]);
|
|
1301
|
+
} else {
|
|
1302
|
+
this._setError(0x0501);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
vertexAttrib3fv(index, v) {
|
|
1306
|
+
if (v && v.length >= 3) {
|
|
1307
|
+
this.vertexAttrib3f(index, v[0], v[1], v[2]);
|
|
1308
|
+
} else {
|
|
1309
|
+
this._setError(0x0501);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
vertexAttrib4fv(index, v) {
|
|
1313
|
+
if (v && v.length >= 4) {
|
|
1314
|
+
this.vertexAttrib4f(index, v[0], v[1], v[2], v[3]);
|
|
1315
|
+
} else {
|
|
1316
|
+
this._setError(0x0501);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
vertexAttribI4i(index, v0, v1, v2, v3) {
|
|
1321
|
+
this._assertNotDestroyed();
|
|
1322
|
+
const ex = this._instance.exports;
|
|
1323
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib_i4i !== 'function') {
|
|
1324
|
+
throw new Error('wasm_ctx_vertex_attrib_i4i not found');
|
|
1325
|
+
}
|
|
1326
|
+
const code = ex.wasm_ctx_vertex_attrib_i4i(this._ctxHandle, index >>> 0, v0 | 0, v1 | 0, v2 | 0, v3 | 0);
|
|
1327
|
+
if (code === 5) return; // ERR_GL
|
|
1328
|
+
_checkErr(code, this._instance);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
vertexAttribI4ui(index, v0, v1, v2, v3) {
|
|
1332
|
+
this._assertNotDestroyed();
|
|
1333
|
+
const ex = this._instance.exports;
|
|
1334
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib_i4ui !== 'function') {
|
|
1335
|
+
throw new Error('wasm_ctx_vertex_attrib_i4ui not found');
|
|
1336
|
+
}
|
|
1337
|
+
const code = ex.wasm_ctx_vertex_attrib_i4ui(this._ctxHandle, index >>> 0, v0 >>> 0, v1 >>> 0, v2 >>> 0, v3 >>> 0);
|
|
1338
|
+
if (code === 5) return; // ERR_GL
|
|
1339
|
+
_checkErr(code, this._instance);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
vertexAttribI4iv(index, v) {
|
|
1343
|
+
if (v && v.length >= 4) {
|
|
1344
|
+
this.vertexAttribI4i(index, v[0], v[1], v[2], v[3]);
|
|
1345
|
+
} else {
|
|
1346
|
+
this._setError(0x0501);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
vertexAttribI4uiv(index, v) {
|
|
1351
|
+
if (v && v.length >= 4) {
|
|
1352
|
+
this.vertexAttribI4ui(index, v[0], v[1], v[2], v[3]);
|
|
1353
|
+
} else {
|
|
1354
|
+
this._setError(0x0501);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
vertexAttribDivisor(index, divisor) {
|
|
1359
|
+
this._assertNotDestroyed();
|
|
1360
|
+
const ex = this._instance.exports;
|
|
1361
|
+
if (!ex || typeof ex.wasm_ctx_vertex_attrib_divisor !== 'function') {
|
|
1362
|
+
throw new Error('wasm_ctx_vertex_attrib_divisor not found');
|
|
1363
|
+
}
|
|
1364
|
+
const code = ex.wasm_ctx_vertex_attrib_divisor(this._ctxHandle, index >>> 0, divisor >>> 0);
|
|
1365
|
+
_checkErr(code, this._instance);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
createBuffer() {
|
|
1369
|
+
this._assertNotDestroyed();
|
|
1370
|
+
const ex = this._instance.exports;
|
|
1371
|
+
if (!ex || typeof ex.wasm_ctx_create_buffer !== 'function') {
|
|
1372
|
+
throw new Error('wasm_ctx_create_buffer not found');
|
|
1373
|
+
}
|
|
1374
|
+
const handle = ex.wasm_ctx_create_buffer(this._ctxHandle);
|
|
1375
|
+
if (handle === 0) {
|
|
1376
|
+
const msg = readErrorMessage(this._instance);
|
|
1377
|
+
throw new Error(`Failed to create buffer: ${msg}`);
|
|
1378
|
+
}
|
|
1379
|
+
return new WasmWebGLBuffer(this, handle);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
bindBuffer(target, buffer) {
|
|
1383
|
+
this._assertNotDestroyed();
|
|
1384
|
+
const ex = this._instance.exports;
|
|
1385
|
+
if (!ex || typeof ex.wasm_ctx_bind_buffer !== 'function') {
|
|
1386
|
+
throw new Error('wasm_ctx_bind_buffer not found');
|
|
1387
|
+
}
|
|
1388
|
+
const handle = buffer && typeof buffer === 'object' && typeof buffer._handle === 'number' ? buffer._handle : (buffer >>> 0);
|
|
1389
|
+
const code = ex.wasm_ctx_bind_buffer(this._ctxHandle, target >>> 0, handle);
|
|
1390
|
+
_checkErr(code, this._instance);
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
deleteBuffer(buffer) {
|
|
1394
|
+
this._assertNotDestroyed();
|
|
1395
|
+
const ex = this._instance.exports;
|
|
1396
|
+
if (!ex || typeof ex.wasm_ctx_delete_buffer !== 'function') {
|
|
1397
|
+
throw new Error('wasm_ctx_delete_buffer not found');
|
|
1398
|
+
}
|
|
1399
|
+
const handle = buffer && typeof buffer === 'object' && typeof buffer._handle === 'number' ? buffer._handle : (buffer >>> 0);
|
|
1400
|
+
const code = ex.wasm_ctx_delete_buffer(this._ctxHandle, handle);
|
|
1401
|
+
_checkErr(code, this._instance); if (buffer && typeof buffer === 'object') {
|
|
1402
|
+
try { buffer._handle = 0; buffer._deleted = true; } catch (e) { /* ignore */ }
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
bufferData(target, data, usage) {
|
|
1407
|
+
this._assertNotDestroyed();
|
|
1408
|
+
const ex = this._instance.exports;
|
|
1409
|
+
if (!ex || typeof ex.wasm_ctx_buffer_data !== 'function') {
|
|
1410
|
+
throw new Error('wasm_ctx_buffer_data not found');
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
let bytes;
|
|
1414
|
+
if (data instanceof ArrayBuffer) {
|
|
1415
|
+
bytes = new Uint8Array(data);
|
|
1416
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
1417
|
+
bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
1418
|
+
} else if (typeof data === 'number') {
|
|
1419
|
+
bytes = new Uint8Array(data);
|
|
1420
|
+
} else {
|
|
1421
|
+
throw new Error('Invalid data type for bufferData');
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
const len = bytes.length;
|
|
1425
|
+
if (len === 0) {
|
|
1426
|
+
const code = ex.wasm_ctx_buffer_data(this._ctxHandle, target >>> 0, 0, 0, usage >>> 0);
|
|
1427
|
+
_checkErr(code, this._instance);
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
const ptr = ex.wasm_alloc(len);
|
|
1432
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for bufferData');
|
|
1433
|
+
|
|
1434
|
+
try {
|
|
1435
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1436
|
+
mem.set(bytes, ptr);
|
|
1437
|
+
const code = ex.wasm_ctx_buffer_data(this._ctxHandle, target >>> 0, ptr, len, usage >>> 0);
|
|
1438
|
+
_checkErr(code, this._instance);
|
|
1439
|
+
} finally {
|
|
1440
|
+
ex.wasm_free(ptr);
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
bufferSubData(target, offset, data) {
|
|
1445
|
+
this._assertNotDestroyed();
|
|
1446
|
+
const ex = this._instance.exports;
|
|
1447
|
+
if (!ex || typeof ex.wasm_ctx_buffer_sub_data !== 'function') {
|
|
1448
|
+
throw new Error('wasm_ctx_buffer_sub_data not found');
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
let bytes;
|
|
1452
|
+
if (data instanceof Uint8Array) bytes = data;
|
|
1453
|
+
else if (ArrayBuffer.isView(data)) bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
1454
|
+
else if (data instanceof ArrayBuffer) bytes = new Uint8Array(data);
|
|
1455
|
+
else bytes = new Uint8Array(data); // Fallback for arrays
|
|
1456
|
+
|
|
1457
|
+
const len = bytes.length;
|
|
1458
|
+
const ptr = ex.wasm_alloc(len);
|
|
1459
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for bufferSubData');
|
|
1460
|
+
|
|
1461
|
+
try {
|
|
1462
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1463
|
+
mem.set(bytes, ptr);
|
|
1464
|
+
const code = ex.wasm_ctx_buffer_sub_data(this._ctxHandle, target >>> 0, offset >>> 0, ptr, len);
|
|
1465
|
+
_checkErr(code, this._instance);
|
|
1466
|
+
} finally {
|
|
1467
|
+
ex.wasm_free(ptr);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
copyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size) {
|
|
1471
|
+
this._assertNotDestroyed();
|
|
1472
|
+
const ex = this._instance.exports;
|
|
1473
|
+
if (!ex || typeof ex.wasm_ctx_copy_buffer_sub_data !== 'function') {
|
|
1474
|
+
throw new Error('wasm_ctx_copy_buffer_sub_data not found');
|
|
1475
|
+
}
|
|
1476
|
+
const code = ex.wasm_ctx_copy_buffer_sub_data(
|
|
1477
|
+
this._ctxHandle,
|
|
1478
|
+
readTarget >>> 0,
|
|
1479
|
+
writeTarget >>> 0,
|
|
1480
|
+
readOffset >>> 0,
|
|
1481
|
+
writeOffset >>> 0,
|
|
1482
|
+
size >>> 0
|
|
1483
|
+
);
|
|
1484
|
+
_checkErr(code, this._instance);
|
|
1485
|
+
}
|
|
1486
|
+
getBufferParameter(target, pname) {
|
|
1487
|
+
this._assertNotDestroyed();
|
|
1488
|
+
const ex = this._instance.exports;
|
|
1489
|
+
if (!ex || typeof ex.wasm_ctx_get_buffer_parameter !== 'function') {
|
|
1490
|
+
throw new Error('wasm_ctx_get_buffer_parameter not found');
|
|
1491
|
+
}
|
|
1492
|
+
const val = ex.wasm_ctx_get_buffer_parameter(this._ctxHandle, target >>> 0, pname >>> 0);
|
|
1493
|
+
if (val < 0) {
|
|
1494
|
+
const msg = readErrorMessage(this._instance);
|
|
1495
|
+
throw new Error(`getBufferParameter failed: ${msg}`);
|
|
1496
|
+
}
|
|
1497
|
+
return val;
|
|
1498
|
+
}
|
|
1499
|
+
isBuffer(buffer) {
|
|
1500
|
+
this._assertNotDestroyed();
|
|
1501
|
+
if (!buffer || typeof buffer !== 'object' || !(buffer instanceof WasmWebGLBuffer)) return false;
|
|
1502
|
+
if (buffer._ctx !== this) return false;
|
|
1503
|
+
const ex = this._instance.exports;
|
|
1504
|
+
return ex.wasm_ctx_is_buffer(this._ctxHandle, buffer._handle) !== 0;
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
drawArrays(mode, first, count) {
|
|
1508
|
+
this._assertNotDestroyed();
|
|
1509
|
+
const ex = this._instance.exports;
|
|
1510
|
+
if (!ex || typeof ex.wasm_ctx_draw_arrays !== 'function') {
|
|
1511
|
+
throw new Error('wasm_ctx_draw_arrays not found');
|
|
1512
|
+
}
|
|
1513
|
+
const code = ex.wasm_ctx_draw_arrays(this._ctxHandle, mode >>> 0, first >>> 0, count >>> 0);
|
|
1514
|
+
_checkErr(code, this._instance);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
drawElements(mode, count, type, offset) {
|
|
1518
|
+
this._assertNotDestroyed();
|
|
1519
|
+
const ex = this._instance.exports;
|
|
1520
|
+
if (!ex || typeof ex.wasm_ctx_draw_elements !== 'function') {
|
|
1521
|
+
throw new Error('wasm_ctx_draw_elements not found');
|
|
1522
|
+
}
|
|
1523
|
+
const code = ex.wasm_ctx_draw_elements(this._ctxHandle, mode >>> 0, count >>> 0, type >>> 0, offset >>> 0);
|
|
1524
|
+
_checkErr(code, this._instance);
|
|
1525
|
+
}
|
|
1526
|
+
drawArraysInstanced(mode, first, count, instanceCount) {
|
|
1527
|
+
this._assertNotDestroyed();
|
|
1528
|
+
const ex = this._instance.exports;
|
|
1529
|
+
if (!ex || typeof ex.wasm_ctx_draw_arrays_instanced !== 'function') {
|
|
1530
|
+
throw new Error('wasm_ctx_draw_arrays_instanced not found');
|
|
1531
|
+
}
|
|
1532
|
+
const code = ex.wasm_ctx_draw_arrays_instanced(this._ctxHandle, mode >>> 0, first | 0, count | 0, instanceCount | 0);
|
|
1533
|
+
_checkErr(code, this._instance);
|
|
1534
|
+
}
|
|
1535
|
+
drawElementsInstanced(mode, count, type, offset, instanceCount) {
|
|
1536
|
+
this._assertNotDestroyed();
|
|
1537
|
+
const ex = this._instance.exports;
|
|
1538
|
+
if (!ex || typeof ex.wasm_ctx_draw_elements_instanced !== 'function') {
|
|
1539
|
+
throw new Error('wasm_ctx_draw_elements_instanced not found');
|
|
1540
|
+
}
|
|
1541
|
+
const code = ex.wasm_ctx_draw_elements_instanced(this._ctxHandle, mode >>> 0, count | 0, type >>> 0, offset >>> 0, instanceCount | 0);
|
|
1542
|
+
_checkErr(code, this._instance);
|
|
1543
|
+
}
|
|
1544
|
+
drawRangeElements(mode, start, end, count, type, offset) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1545
|
+
drawBuffers(buffers) {
|
|
1546
|
+
this._assertNotDestroyed();
|
|
1547
|
+
const ex = this._instance.exports;
|
|
1548
|
+
if (!ex || typeof ex.wasm_ctx_draw_buffers !== 'function') {
|
|
1549
|
+
throw new Error('wasm_ctx_draw_buffers not found');
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
const count = buffers.length;
|
|
1553
|
+
const bufs = new Uint32Array(count);
|
|
1554
|
+
for (let i = 0; i < count; i++) {
|
|
1555
|
+
bufs[i] = buffers[i];
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
const ptr = ex.wasm_alloc(count * 4);
|
|
1559
|
+
const view = new Uint32Array(ex.memory.buffer, ptr, count);
|
|
1560
|
+
view.set(bufs);
|
|
1561
|
+
|
|
1562
|
+
const code = ex.wasm_ctx_draw_buffers(this._ctxHandle, ptr, count);
|
|
1563
|
+
ex.wasm_free(ptr, count * 4);
|
|
1564
|
+
_checkErr(code, this._instance);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
readBuffer(mode) {
|
|
1568
|
+
this._assertNotDestroyed();
|
|
1569
|
+
const ex = this._instance.exports;
|
|
1570
|
+
if (!ex || typeof ex.wasm_ctx_read_buffer !== 'function') {
|
|
1571
|
+
throw new Error('wasm_ctx_read_buffer not found');
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
const code = ex.wasm_ctx_read_buffer(this._ctxHandle, mode);
|
|
1575
|
+
_checkErr(code, this._instance);
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
createVertexArray() {
|
|
1579
|
+
this._assertNotDestroyed();
|
|
1580
|
+
const ex = this._instance.exports;
|
|
1581
|
+
if (!ex || typeof ex.wasm_ctx_create_vertex_array !== 'function') {
|
|
1582
|
+
throw new Error('wasm_ctx_create_vertex_array not found');
|
|
1583
|
+
}
|
|
1584
|
+
const handle = ex.wasm_ctx_create_vertex_array(this._ctxHandle);
|
|
1585
|
+
if (handle === 0) return null;
|
|
1586
|
+
return new WasmWebGLVertexArrayObject(this, handle);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
bindVertexArray(vao) {
|
|
1590
|
+
this._assertNotDestroyed();
|
|
1591
|
+
const ex = this._instance.exports;
|
|
1592
|
+
if (!ex || typeof ex.wasm_ctx_bind_vertex_array !== 'function') {
|
|
1593
|
+
throw new Error('wasm_ctx_bind_vertex_array not found');
|
|
1594
|
+
}
|
|
1595
|
+
const handle = vao && typeof vao === 'object' && typeof vao._handle === 'number' ? vao._handle : (vao ? (vao >>> 0) : 0);
|
|
1596
|
+
const code = ex.wasm_ctx_bind_vertex_array(this._ctxHandle, handle);
|
|
1597
|
+
_checkErr(code, this._instance);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
deleteVertexArray(vao) {
|
|
1601
|
+
this._assertNotDestroyed();
|
|
1602
|
+
const ex = this._instance.exports;
|
|
1603
|
+
if (!ex || typeof ex.wasm_ctx_delete_vertex_array !== 'function') {
|
|
1604
|
+
throw new Error('wasm_ctx_delete_vertex_array not found');
|
|
1605
|
+
}
|
|
1606
|
+
const handle = vao && typeof vao === 'object' && typeof vao._handle === 'number' ? vao._handle : (vao >>> 0);
|
|
1607
|
+
const code = ex.wasm_ctx_delete_vertex_array(this._ctxHandle, handle);
|
|
1608
|
+
_checkErr(code, this._instance);
|
|
1609
|
+
if (vao && typeof vao === 'object') {
|
|
1610
|
+
try { vao._handle = 0; vao._deleted = true; } catch (e) { /* ignore */ }
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
isVertexArray(vao) {
|
|
1615
|
+
this._assertNotDestroyed();
|
|
1616
|
+
const ex = this._instance.exports;
|
|
1617
|
+
if (!ex || typeof ex.wasm_ctx_is_vertex_array !== 'function') {
|
|
1618
|
+
throw new Error('wasm_ctx_is_vertex_array not found');
|
|
1619
|
+
}
|
|
1620
|
+
const handle = vao && typeof vao === 'object' && typeof vao._handle === 'number' ? vao._handle : (vao >>> 0);
|
|
1621
|
+
const res = ex.wasm_ctx_is_vertex_array(this._ctxHandle, handle);
|
|
1622
|
+
return res !== 0;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
createTransformFeedback() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1626
|
+
bindTransformFeedback(target, tf) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1627
|
+
beginTransformFeedback(primitiveMode) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1628
|
+
pauseTransformFeedback() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1629
|
+
resumeTransformFeedback() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1630
|
+
endTransformFeedback() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1631
|
+
transformFeedbackVaryings(program, varyings, bufferMode) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1632
|
+
getTransformFeedbackVarying(program, index) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1633
|
+
|
|
1634
|
+
createQuery() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1635
|
+
deleteQuery(q) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1636
|
+
beginQuery(target, id) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1637
|
+
endQuery(target) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1638
|
+
getQueryParameter(query, pname) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1639
|
+
|
|
1640
|
+
fenceSync(condition, flags) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1641
|
+
clientWaitSync(sync, flags, timeout) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1642
|
+
waitSync(sync, flags, timeout) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1643
|
+
deleteSync(sync) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1644
|
+
getSyncParameter(sync, pname) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1645
|
+
|
|
1646
|
+
createSampler() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1647
|
+
deleteSampler(s) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1648
|
+
bindSampler(unit, sampler) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1649
|
+
samplerParameteri(sampler, pname, param) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1650
|
+
samplerParameterf(sampler, pname, param) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1651
|
+
|
|
1652
|
+
activeTexture(texture) {
|
|
1653
|
+
this._assertNotDestroyed();
|
|
1654
|
+
const ex = this._instance.exports;
|
|
1655
|
+
if (!ex || typeof ex.wasm_ctx_active_texture !== 'function') {
|
|
1656
|
+
throw new Error('wasm_ctx_active_texture not found');
|
|
1657
|
+
}
|
|
1658
|
+
const code = ex.wasm_ctx_active_texture(this._ctxHandle, texture >>> 0);
|
|
1659
|
+
_checkErr(code, this._instance);
|
|
1660
|
+
// Track active texture unit in JS wrapper (GL_TEXTURE0 = 0x84C0)
|
|
1661
|
+
this._activeTextureUnit = (texture >>> 0) - 0x84C0;
|
|
1662
|
+
this._textureUnits = this._textureUnits || [];
|
|
1663
|
+
}
|
|
1664
|
+
texParameteri(target, pname, param) {
|
|
1665
|
+
this._assertNotDestroyed();
|
|
1666
|
+
const ex = this._instance.exports;
|
|
1667
|
+
if (!ex || typeof ex.wasm_ctx_tex_parameter_i !== 'function') {
|
|
1668
|
+
throw new Error('wasm_ctx_tex_parameter_i not found');
|
|
1669
|
+
}
|
|
1670
|
+
const code = ex.wasm_ctx_tex_parameter_i(this._ctxHandle, target >>> 0, pname >>> 0, param | 0);
|
|
1671
|
+
_checkErr(code, this._instance);
|
|
1672
|
+
}
|
|
1673
|
+
generateMipmap(target) {
|
|
1674
|
+
this._assertNotDestroyed();
|
|
1675
|
+
const ex = this._instance.exports;
|
|
1676
|
+
if (!ex || typeof ex.wasm_ctx_generate_mipmap !== 'function') {
|
|
1677
|
+
throw new Error('wasm_ctx_generate_mipmap not found');
|
|
1678
|
+
}
|
|
1679
|
+
const code = ex.wasm_ctx_generate_mipmap(this._ctxHandle, target >>> 0);
|
|
1680
|
+
_checkErr(code, this._instance);
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
copyTexImage2D(target, level, internalformat, x, y, width, height, border) {
|
|
1684
|
+
this._assertNotDestroyed();
|
|
1685
|
+
const ex = this._instance.exports;
|
|
1686
|
+
if (!ex || typeof ex.wasm_ctx_copy_tex_image_2d !== 'function') {
|
|
1687
|
+
throw new Error('wasm_ctx_copy_tex_image_2d not found');
|
|
1688
|
+
}
|
|
1689
|
+
const code = ex.wasm_ctx_copy_tex_image_2d(
|
|
1690
|
+
this._ctxHandle,
|
|
1691
|
+
target >>> 0,
|
|
1692
|
+
level | 0,
|
|
1693
|
+
internalformat >>> 0,
|
|
1694
|
+
x | 0,
|
|
1695
|
+
y | 0,
|
|
1696
|
+
width | 0,
|
|
1697
|
+
height | 0,
|
|
1698
|
+
border | 0
|
|
1699
|
+
);
|
|
1700
|
+
_checkErr(code, this._instance);
|
|
1701
|
+
}
|
|
1702
|
+
copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1703
|
+
texSubImage2D(target, level, xoffset, yoffset, width, height, format, type_, pixels) {
|
|
1704
|
+
this._assertNotDestroyed();
|
|
1705
|
+
const ex = this._instance.exports;
|
|
1706
|
+
if (!ex || typeof ex.wasm_ctx_tex_sub_image_2d !== 'function') {
|
|
1707
|
+
throw new Error('wasm_ctx_tex_sub_image_2d not found');
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
let data = pixels;
|
|
1711
|
+
if (!data) return; // No-op if no data provided
|
|
1712
|
+
if (!(data instanceof Uint8Array)) {
|
|
1713
|
+
if (ArrayBuffer.isView(data)) {
|
|
1714
|
+
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
1715
|
+
} else {
|
|
1716
|
+
data = new Uint8Array(data);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
const len = data.length;
|
|
1721
|
+
const ptr = ex.wasm_alloc(len);
|
|
1722
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for sub-pixel data');
|
|
1723
|
+
|
|
1724
|
+
try {
|
|
1725
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1726
|
+
mem.set(data, ptr);
|
|
1727
|
+
|
|
1728
|
+
const code = ex.wasm_ctx_tex_sub_image_2d(
|
|
1729
|
+
this._ctxHandle,
|
|
1730
|
+
target >>> 0,
|
|
1731
|
+
level >>> 0,
|
|
1732
|
+
xoffset | 0,
|
|
1733
|
+
yoffset | 0,
|
|
1734
|
+
width >>> 0,
|
|
1735
|
+
height >>> 0,
|
|
1736
|
+
format >>> 0,
|
|
1737
|
+
type_ >>> 0,
|
|
1738
|
+
ptr >>> 0,
|
|
1739
|
+
len >>> 0
|
|
1740
|
+
);
|
|
1741
|
+
_checkErr(code, this._instance);
|
|
1742
|
+
} finally {
|
|
1743
|
+
ex.wasm_free(ptr);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
checkFramebufferStatus(target) {
|
|
1748
|
+
this._assertNotDestroyed();
|
|
1749
|
+
const ex = this._instance.exports;
|
|
1750
|
+
if (!ex || typeof ex.wasm_ctx_check_framebuffer_status !== 'function') {
|
|
1751
|
+
throw new Error('wasm_ctx_check_framebuffer_status not found');
|
|
1752
|
+
}
|
|
1753
|
+
return ex.wasm_ctx_check_framebuffer_status(this._ctxHandle, target);
|
|
1754
|
+
}
|
|
1755
|
+
blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter) {
|
|
1756
|
+
this._assertNotDestroyed();
|
|
1757
|
+
const ex = this._instance.exports;
|
|
1758
|
+
if (!ex || typeof ex.wasm_ctx_blit_framebuffer !== 'function') {
|
|
1759
|
+
throw new Error('wasm_ctx_blit_framebuffer not found');
|
|
1760
|
+
}
|
|
1761
|
+
const code = ex.wasm_ctx_blit_framebuffer(
|
|
1762
|
+
this._ctxHandle,
|
|
1763
|
+
srcX0 | 0, srcY0 | 0, srcX1 | 0, srcY1 | 0,
|
|
1764
|
+
dstX0 | 0, dstY0 | 0, dstX1 | 0, dstY1 | 0,
|
|
1765
|
+
mask >>> 0, filter >>> 0
|
|
1766
|
+
);
|
|
1767
|
+
_checkErr(code, this._instance);
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
pixelStorei(pname, param) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
1771
|
+
getExtension(name) {
|
|
1772
|
+
this._assertNotDestroyed();
|
|
1773
|
+
if (name === 'EXT_color_buffer_float') {
|
|
1774
|
+
return {};
|
|
1775
|
+
}
|
|
1776
|
+
return null;
|
|
1777
|
+
}
|
|
1778
|
+
getSupportedExtensions() {
|
|
1779
|
+
this._assertNotDestroyed();
|
|
1780
|
+
return ['EXT_color_buffer_float'];
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
getUniformLocation(program, name) {
|
|
1784
|
+
this._assertNotDestroyed();
|
|
1785
|
+
const ex = this._instance.exports;
|
|
1786
|
+
if (!ex || typeof ex.wasm_ctx_get_uniform_location !== 'function') {
|
|
1787
|
+
throw new Error('wasm_ctx_get_uniform_location not found');
|
|
1788
|
+
}
|
|
1789
|
+
const programHandle = program && typeof program === 'object' && typeof program._handle === 'number' ? program._handle : (program >>> 0);
|
|
1790
|
+
const nameStr = String(name);
|
|
1791
|
+
const bytes = new TextEncoder().encode(nameStr);
|
|
1792
|
+
const len = bytes.length;
|
|
1793
|
+
const ptr = ex.wasm_alloc(len);
|
|
1794
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for getUniformLocation');
|
|
1795
|
+
|
|
1796
|
+
try {
|
|
1797
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1798
|
+
mem.set(bytes, ptr);
|
|
1799
|
+
const loc = ex.wasm_ctx_get_uniform_location(this._ctxHandle, programHandle, ptr, len);
|
|
1800
|
+
return loc === -1 ? null : new WasmWebGLUniformLocation(this, loc);
|
|
1801
|
+
} finally {
|
|
1802
|
+
ex.wasm_free(ptr);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
uniform1f(loc, x) {
|
|
1807
|
+
this._assertNotDestroyed();
|
|
1808
|
+
const ex = this._instance.exports;
|
|
1809
|
+
if (!ex || typeof ex.wasm_ctx_uniform1f !== 'function') {
|
|
1810
|
+
throw new Error('wasm_ctx_uniform1f not found');
|
|
1811
|
+
}
|
|
1812
|
+
const locHandle = loc === null ? -1 : (typeof loc === 'number' ? loc : (loc._handle >>> 0));
|
|
1813
|
+
const code = ex.wasm_ctx_uniform1f(this._ctxHandle, locHandle, +x);
|
|
1814
|
+
_checkErr(code, this._instance);
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
uniform2f(loc, x, y) {
|
|
1818
|
+
this._assertNotDestroyed();
|
|
1819
|
+
const ex = this._instance.exports;
|
|
1820
|
+
if (!ex || typeof ex.wasm_ctx_uniform2f !== 'function') {
|
|
1821
|
+
throw new Error('wasm_ctx_uniform2f not found');
|
|
1822
|
+
}
|
|
1823
|
+
const locHandle = loc === null ? -1 : (typeof loc === 'number' ? loc : (loc._handle >>> 0));
|
|
1824
|
+
const code = ex.wasm_ctx_uniform2f(this._ctxHandle, locHandle, +x, +y);
|
|
1825
|
+
_checkErr(code, this._instance);
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
uniform3f(loc, x, y, z) {
|
|
1829
|
+
this._assertNotDestroyed();
|
|
1830
|
+
const ex = this._instance.exports;
|
|
1831
|
+
if (!ex || typeof ex.wasm_ctx_uniform3f !== 'function') {
|
|
1832
|
+
throw new Error('wasm_ctx_uniform3f not found');
|
|
1833
|
+
}
|
|
1834
|
+
const locHandle = loc === null ? -1 : (typeof loc === 'number' ? loc : (loc._handle >>> 0));
|
|
1835
|
+
const code = ex.wasm_ctx_uniform3f(this._ctxHandle, locHandle, +x, +y, +z);
|
|
1836
|
+
_checkErr(code, this._instance);
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
uniform4f(loc, x, y, z, w) {
|
|
1840
|
+
this._assertNotDestroyed();
|
|
1841
|
+
const ex = this._instance.exports;
|
|
1842
|
+
if (!ex || typeof ex.wasm_ctx_uniform4f !== 'function') {
|
|
1843
|
+
throw new Error('wasm_ctx_uniform4f not found');
|
|
1844
|
+
}
|
|
1845
|
+
const locHandle = loc === null ? -1 : (typeof loc === 'number' ? loc : (loc._handle >>> 0));
|
|
1846
|
+
const code = ex.wasm_ctx_uniform4f(this._ctxHandle, locHandle, +x, +y, +z, +w);
|
|
1847
|
+
_checkErr(code, this._instance);
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
uniform1i(loc, x) {
|
|
1851
|
+
this._assertNotDestroyed();
|
|
1852
|
+
const ex = this._instance.exports;
|
|
1853
|
+
if (!ex || typeof ex.wasm_ctx_uniform1i !== 'function') {
|
|
1854
|
+
throw new Error('wasm_ctx_uniform1i not found');
|
|
1855
|
+
}
|
|
1856
|
+
const locHandle = loc === null ? -1 : (typeof loc === 'number' ? loc : (loc._handle >>> 0));
|
|
1857
|
+
const code = ex.wasm_ctx_uniform1i(this._ctxHandle, locHandle, x | 0);
|
|
1858
|
+
_checkErr(code, this._instance);
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
uniformMatrix4fv(loc, transpose, value) {
|
|
1862
|
+
this._assertNotDestroyed();
|
|
1863
|
+
const ex = this._instance.exports;
|
|
1864
|
+
if (!ex || typeof ex.wasm_ctx_uniform_matrix_4fv !== 'function') {
|
|
1865
|
+
throw new Error('wasm_ctx_uniform_matrix_4fv not found');
|
|
1866
|
+
}
|
|
1867
|
+
const locHandle = loc === null ? -1 : (typeof loc === 'number' ? loc : (loc._handle >>> 0));
|
|
1868
|
+
|
|
1869
|
+
let bytes;
|
|
1870
|
+
if (value instanceof Float32Array) {
|
|
1871
|
+
bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
1872
|
+
} else {
|
|
1873
|
+
bytes = new Uint8Array(new Float32Array(value).buffer);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
const len = bytes.length;
|
|
1877
|
+
const ptr = ex.wasm_alloc(len);
|
|
1878
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for uniformMatrix4fv');
|
|
1879
|
+
|
|
1880
|
+
try {
|
|
1881
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
1882
|
+
mem.set(bytes, ptr);
|
|
1883
|
+
const count = len / 4;
|
|
1884
|
+
const code = ex.wasm_ctx_uniform_matrix_4fv(this._ctxHandle, locHandle, transpose ? 1 : 0, ptr, count);
|
|
1885
|
+
_checkErr(code, this._instance);
|
|
1886
|
+
} finally {
|
|
1887
|
+
ex.wasm_free(ptr);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
getVertexAttrib(index, pname) {
|
|
1892
|
+
this._assertNotDestroyed();
|
|
1893
|
+
const ex = this._instance.exports;
|
|
1894
|
+
if (!ex || typeof ex.wasm_ctx_get_vertex_attrib !== 'function') {
|
|
1895
|
+
throw new Error('wasm_ctx_get_vertex_attrib not found');
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
// Allocate memory for result.
|
|
1899
|
+
// Most params return 1 int (4 bytes).
|
|
1900
|
+
// CURRENT_VERTEX_ATTRIB returns 4 values (16 bytes) + type (4 bytes) = 20 bytes.
|
|
1901
|
+
const len = 20;
|
|
1902
|
+
const ptr = ex.wasm_alloc(len);
|
|
1903
|
+
if (ptr === 0) throw new Error('Failed to allocate memory for getVertexAttrib');
|
|
1904
|
+
|
|
1905
|
+
try {
|
|
1906
|
+
const code = ex.wasm_ctx_get_vertex_attrib(this._ctxHandle, index >>> 0, pname >>> 0, ptr, len);
|
|
1907
|
+
if (code === 5) { // ERR_GL
|
|
1908
|
+
return undefined;
|
|
1909
|
+
}
|
|
1910
|
+
_checkErr(code, this._instance);
|
|
1911
|
+
|
|
1912
|
+
const mem = new Int32Array(ex.memory.buffer, ptr, 5);
|
|
1913
|
+
const memU = new Uint32Array(ex.memory.buffer, ptr, 5);
|
|
1914
|
+
const memF = new Float32Array(ex.memory.buffer, ptr, 5);
|
|
1915
|
+
|
|
1916
|
+
if (pname === 0x8626 /* CURRENT_VERTEX_ATTRIB */) {
|
|
1917
|
+
// Check type at index 4
|
|
1918
|
+
const type = memU[4];
|
|
1919
|
+
if (type === 0x1404 /* INT */) {
|
|
1920
|
+
return new Int32Array([mem[0], mem[1], mem[2], mem[3]]);
|
|
1921
|
+
} else if (type === 0x1405 /* UNSIGNED_INT */) {
|
|
1922
|
+
return new Uint32Array([memU[0], memU[1], memU[2], memU[3]]);
|
|
1923
|
+
} else {
|
|
1924
|
+
// Default to float
|
|
1925
|
+
return new Float32Array([memF[0], memF[1], memF[2], memF[3]]);
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
// Other params
|
|
1930
|
+
if (pname === 0x8622 /* ENABLED */ ||
|
|
1931
|
+
pname === 0x886A /* NORMALIZED */ ||
|
|
1932
|
+
pname === 0x88FD /* INTEGER */) {
|
|
1933
|
+
return mem[0] !== 0;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
if (pname === 0x889F /* BUFFER_BINDING */) {
|
|
1937
|
+
const handle = memU[0];
|
|
1938
|
+
if (handle === 0) return null;
|
|
1939
|
+
return new WasmWebGLBuffer(this, handle);
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
return mem[0];
|
|
1943
|
+
} finally {
|
|
1944
|
+
ex.wasm_free(ptr, len);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
|
|
1949
|
+
getParameter(pname) {
|
|
1950
|
+
this._assertNotDestroyed();
|
|
1951
|
+
const ex = this._instance.exports;
|
|
1952
|
+
if (!ex || typeof ex.wasm_ctx_get_parameter_v !== 'function') {
|
|
1953
|
+
throw new Error('wasm_ctx_get_parameter_v not found');
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
if (pname === 0x0BA2 /* VIEWPORT */) {
|
|
1957
|
+
const ptr = ex.wasm_alloc(16);
|
|
1958
|
+
try {
|
|
1959
|
+
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 16);
|
|
1960
|
+
_checkErr(code, this._instance);
|
|
1961
|
+
const mem = new Int32Array(ex.memory.buffer, ptr, 4);
|
|
1962
|
+
return new Int32Array(mem);
|
|
1963
|
+
} finally {
|
|
1964
|
+
ex.wasm_free(ptr, 16);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
if (pname === 0x0C22 /* COLOR_CLEAR_VALUE */) {
|
|
1969
|
+
const ptr = ex.wasm_alloc(16);
|
|
1970
|
+
try {
|
|
1971
|
+
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 16);
|
|
1972
|
+
_checkErr(code, this._instance);
|
|
1973
|
+
const mem = new Float32Array(ex.memory.buffer, ptr, 4);
|
|
1974
|
+
return new Float32Array(mem);
|
|
1975
|
+
} finally {
|
|
1976
|
+
ex.wasm_free(ptr, 16);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
if (pname === 0x0C23 /* COLOR_WRITEMASK */) {
|
|
1981
|
+
const ptr = ex.wasm_alloc(4);
|
|
1982
|
+
try {
|
|
1983
|
+
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
1984
|
+
_checkErr(code, this._instance);
|
|
1985
|
+
const mem = new Uint8Array(ex.memory.buffer, ptr, 4);
|
|
1986
|
+
return [mem[0] !== 0, mem[1] !== 0, mem[2] !== 0, mem[3] !== 0];
|
|
1987
|
+
} finally {
|
|
1988
|
+
ex.wasm_free(ptr, 4);
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
if (pname === 0x0B72 /* DEPTH_WRITEMASK */) {
|
|
1993
|
+
const ptr = ex.wasm_alloc(4);
|
|
1994
|
+
try {
|
|
1995
|
+
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
1996
|
+
_checkErr(code, this._instance);
|
|
1997
|
+
const mem = new Uint8Array(ex.memory.buffer, ptr, 1);
|
|
1998
|
+
return mem[0] !== 0;
|
|
1999
|
+
} finally {
|
|
2000
|
+
ex.wasm_free(ptr, 4);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
if (pname === 0x0B98 /* STENCIL_WRITEMASK */ || pname === 0x8CA5 /* STENCIL_BACK_WRITEMASK */) {
|
|
2005
|
+
const ptr = ex.wasm_alloc(4);
|
|
2006
|
+
try {
|
|
2007
|
+
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2008
|
+
_checkErr(code, this._instance);
|
|
2009
|
+
const mem = new Int32Array(ex.memory.buffer, ptr, 1);
|
|
2010
|
+
return mem[0];
|
|
2011
|
+
} finally {
|
|
2012
|
+
ex.wasm_free(ptr, 4);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
const singleIntParams = [
|
|
2017
|
+
0x0B74, // DEPTH_FUNC
|
|
2018
|
+
0x0B92, // STENCIL_FUNC
|
|
2019
|
+
0x0B93, // STENCIL_VALUE_MASK
|
|
2020
|
+
0x0B97, // STENCIL_REF
|
|
2021
|
+
0x8800, // STENCIL_BACK_FUNC
|
|
2022
|
+
0x8CA4, // STENCIL_BACK_VALUE_MASK
|
|
2023
|
+
0x8CA3, // STENCIL_BACK_REF
|
|
2024
|
+
0x0B94, // STENCIL_FAIL
|
|
2025
|
+
0x0B95, // STENCIL_PASS_DEPTH_FAIL
|
|
2026
|
+
0x0B96, // STENCIL_PASS_DEPTH_PASS
|
|
2027
|
+
0x8801, // STENCIL_BACK_FAIL
|
|
2028
|
+
0x8802, // STENCIL_BACK_PASS_DEPTH_FAIL
|
|
2029
|
+
0x8803, // STENCIL_BACK_PASS_DEPTH_PASS
|
|
2030
|
+
];
|
|
2031
|
+
|
|
2032
|
+
if (singleIntParams.includes(pname)) {
|
|
2033
|
+
const ptr = ex.wasm_alloc(4);
|
|
2034
|
+
try {
|
|
2035
|
+
const code = ex.wasm_ctx_get_parameter_v(this._ctxHandle, pname, ptr, 4);
|
|
2036
|
+
_checkErr(code, this._instance);
|
|
2037
|
+
const mem = new Int32Array(ex.memory.buffer, ptr, 1);
|
|
2038
|
+
return mem[0];
|
|
2039
|
+
} finally {
|
|
2040
|
+
ex.wasm_free(ptr, 4);
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
if (pname === 0x8869 /* MAX_VERTEX_ATTRIBS */) {
|
|
2045
|
+
return 16;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
throw new Error(`getParameter for ${pname} not implemented`);
|
|
2049
|
+
}
|
|
2050
|
+
getError() {
|
|
2051
|
+
this._assertNotDestroyed();
|
|
2052
|
+
const ex = this._instance.exports;
|
|
2053
|
+
if (!ex || typeof ex.wasm_ctx_get_error !== 'function') {
|
|
2054
|
+
throw new Error('wasm_ctx_get_error not found');
|
|
2055
|
+
}
|
|
2056
|
+
return ex.wasm_ctx_get_error(this._ctxHandle);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
_setError(error) {
|
|
2060
|
+
const ex = this._instance.exports;
|
|
2061
|
+
if (ex && typeof ex.wasm_ctx_set_gl_error === 'function') {
|
|
2062
|
+
ex.wasm_ctx_set_gl_error(this._ctxHandle, error);
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
finish() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
2067
|
+
flush() { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
2068
|
+
|
|
2069
|
+
isTexture(tex) {
|
|
2070
|
+
this._assertNotDestroyed();
|
|
2071
|
+
if (!tex || typeof tex !== 'object' || !(tex instanceof WasmWebGLTexture)) return false;
|
|
2072
|
+
if (tex._ctx !== this) return false;
|
|
2073
|
+
const ex = this._instance.exports;
|
|
2074
|
+
return ex.wasm_ctx_is_texture(this._ctxHandle, tex._handle) !== 0;
|
|
2075
|
+
}
|
|
2076
|
+
isFramebuffer(fb) {
|
|
2077
|
+
this._assertNotDestroyed();
|
|
2078
|
+
if (!fb || typeof fb !== 'object' || !(fb instanceof WasmWebGLFramebuffer)) return false;
|
|
2079
|
+
if (fb._ctx !== this) return false;
|
|
2080
|
+
const ex = this._instance.exports;
|
|
2081
|
+
return ex.wasm_ctx_is_framebuffer(this._ctxHandle, fb._handle) !== 0;
|
|
2082
|
+
}
|
|
2083
|
+
isProgram(p) {
|
|
2084
|
+
this._assertNotDestroyed();
|
|
2085
|
+
if (!p || typeof p !== 'object' || !(p instanceof WasmWebGLProgram)) return false;
|
|
2086
|
+
if (p._ctx !== this) return false;
|
|
2087
|
+
const ex = this._instance.exports;
|
|
2088
|
+
return ex.wasm_ctx_is_program(this._ctxHandle, p._handle) !== 0;
|
|
2089
|
+
}
|
|
2090
|
+
isShader(s) {
|
|
2091
|
+
this._assertNotDestroyed();
|
|
2092
|
+
if (!s || typeof s !== 'object' || !(s instanceof WasmWebGLShader)) return false;
|
|
2093
|
+
if (s._ctx !== this) return false;
|
|
2094
|
+
const ex = this._instance.exports;
|
|
2095
|
+
return ex.wasm_ctx_is_shader(this._ctxHandle, s._handle) !== 0;
|
|
2096
|
+
}
|
|
2097
|
+
enable(cap) {
|
|
2098
|
+
this._assertNotDestroyed();
|
|
2099
|
+
const ex = this._instance.exports;
|
|
2100
|
+
if (!ex || typeof ex.wasm_ctx_enable !== 'function') {
|
|
2101
|
+
throw new Error('wasm_ctx_enable not found');
|
|
2102
|
+
}
|
|
2103
|
+
const code = ex.wasm_ctx_enable(this._ctxHandle, cap >>> 0);
|
|
2104
|
+
_checkErr(code, this._instance);
|
|
2105
|
+
}
|
|
2106
|
+
disable(cap) {
|
|
2107
|
+
this._assertNotDestroyed();
|
|
2108
|
+
const ex = this._instance.exports;
|
|
2109
|
+
if (!ex || typeof ex.wasm_ctx_disable !== 'function') {
|
|
2110
|
+
throw new Error('wasm_ctx_disable not found');
|
|
2111
|
+
}
|
|
2112
|
+
const code = ex.wasm_ctx_disable(this._ctxHandle, cap >>> 0);
|
|
2113
|
+
_checkErr(code, this._instance);
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
blendFunc(sfactor, dfactor) {
|
|
2117
|
+
this._assertNotDestroyed();
|
|
2118
|
+
const ex = this._instance.exports;
|
|
2119
|
+
if (!ex || typeof ex.wasm_ctx_blend_func !== 'function') {
|
|
2120
|
+
throw new Error('wasm_ctx_blend_func not found');
|
|
2121
|
+
}
|
|
2122
|
+
const code = ex.wasm_ctx_blend_func(this._ctxHandle, sfactor >>> 0, dfactor >>> 0);
|
|
2123
|
+
_checkErr(code, this._instance);
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha) {
|
|
2127
|
+
this._assertNotDestroyed();
|
|
2128
|
+
const ex = this._instance.exports;
|
|
2129
|
+
if (!ex || typeof ex.wasm_ctx_blend_func_separate !== 'function') {
|
|
2130
|
+
throw new Error('wasm_ctx_blend_func_separate not found');
|
|
2131
|
+
}
|
|
2132
|
+
const code = ex.wasm_ctx_blend_func_separate(
|
|
2133
|
+
this._ctxHandle,
|
|
2134
|
+
srcRGB >>> 0,
|
|
2135
|
+
dstRGB >>> 0,
|
|
2136
|
+
srcAlpha >>> 0,
|
|
2137
|
+
dstAlpha >>> 0
|
|
2138
|
+
);
|
|
2139
|
+
_checkErr(code, this._instance);
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
blendEquation(mode) {
|
|
2143
|
+
this._assertNotDestroyed();
|
|
2144
|
+
const ex = this._instance.exports;
|
|
2145
|
+
if (!ex || typeof ex.wasm_ctx_blend_equation !== 'function') {
|
|
2146
|
+
throw new Error('wasm_ctx_blend_equation not found');
|
|
2147
|
+
}
|
|
2148
|
+
const code = ex.wasm_ctx_blend_equation(this._ctxHandle, mode >>> 0);
|
|
2149
|
+
_checkErr(code, this._instance);
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
blendEquationSeparate(modeRGB, modeAlpha) {
|
|
2153
|
+
this._assertNotDestroyed();
|
|
2154
|
+
const ex = this._instance.exports;
|
|
2155
|
+
if (!ex || typeof ex.wasm_ctx_blend_equation_separate !== 'function') {
|
|
2156
|
+
throw new Error('wasm_ctx_blend_equation_separate not found');
|
|
2157
|
+
}
|
|
2158
|
+
const code = ex.wasm_ctx_blend_equation_separate(
|
|
2159
|
+
this._ctxHandle,
|
|
2160
|
+
modeRGB >>> 0,
|
|
2161
|
+
modeAlpha >>> 0
|
|
2162
|
+
);
|
|
2163
|
+
_checkErr(code, this._instance);
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
blendColor(red, green, blue, alpha) {
|
|
2167
|
+
this._assertNotDestroyed();
|
|
2168
|
+
const ex = this._instance.exports;
|
|
2169
|
+
if (!ex || typeof ex.wasm_ctx_blend_color !== 'function') {
|
|
2170
|
+
throw new Error('wasm_ctx_blend_color not found');
|
|
2171
|
+
}
|
|
2172
|
+
const code = ex.wasm_ctx_blend_color(
|
|
2173
|
+
this._ctxHandle,
|
|
2174
|
+
+red,
|
|
2175
|
+
+green,
|
|
2176
|
+
+blue,
|
|
2177
|
+
+alpha
|
|
2178
|
+
);
|
|
2179
|
+
_checkErr(code, this._instance);
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
isEnabled(cap) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
2183
|
+
|
|
2184
|
+
viewport(x, y, width, height) {
|
|
2185
|
+
this._assertNotDestroyed();
|
|
2186
|
+
const ex = this._instance.exports;
|
|
2187
|
+
if (!ex || typeof ex.wasm_ctx_viewport !== 'function') {
|
|
2188
|
+
throw new Error('wasm_ctx_viewport not found');
|
|
2189
|
+
}
|
|
2190
|
+
const code = ex.wasm_ctx_viewport(this._ctxHandle, x >>> 0, y >>> 0, width >>> 0, height >>> 0);
|
|
2191
|
+
_checkErr(code, this._instance);
|
|
2192
|
+
}
|
|
2193
|
+
scissor(x, y, width, height) {
|
|
2194
|
+
this._assertNotDestroyed();
|
|
2195
|
+
const ex = this._instance.exports;
|
|
2196
|
+
if (!ex || typeof ex.wasm_ctx_scissor !== 'function') {
|
|
2197
|
+
throw new Error('wasm_ctx_scissor not found');
|
|
2198
|
+
}
|
|
2199
|
+
const code = ex.wasm_ctx_scissor(this._ctxHandle, x | 0, y | 0, width >>> 0, height >>> 0);
|
|
2200
|
+
_checkErr(code, this._instance);
|
|
2201
|
+
}
|
|
2202
|
+
clear(mask) {
|
|
2203
|
+
this._assertNotDestroyed();
|
|
2204
|
+
const ex = this._instance.exports;
|
|
2205
|
+
if (!ex || typeof ex.wasm_ctx_clear !== 'function') {
|
|
2206
|
+
throw new Error('wasm_ctx_clear not found');
|
|
2207
|
+
}
|
|
2208
|
+
const code = ex.wasm_ctx_clear(this._ctxHandle, mask >>> 0);
|
|
2209
|
+
_checkErr(code, this._instance);
|
|
2210
|
+
}
|
|
2211
|
+
clearColor(r, g, b, a) {
|
|
2212
|
+
this._assertNotDestroyed();
|
|
2213
|
+
const ex = this._instance.exports;
|
|
2214
|
+
if (!ex || typeof ex.wasm_ctx_clear_color !== 'function') {
|
|
2215
|
+
throw new Error('wasm_ctx_clear_color not found');
|
|
2216
|
+
}
|
|
2217
|
+
const code = ex.wasm_ctx_clear_color(this._ctxHandle, +r, +g, +b, +a);
|
|
2218
|
+
_checkErr(code, this._instance);
|
|
2219
|
+
}
|
|
2220
|
+
clearDepth(depth) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
2221
|
+
depthFunc(func) {
|
|
2222
|
+
this._assertNotDestroyed();
|
|
2223
|
+
const ex = this._instance.exports;
|
|
2224
|
+
if (!ex || typeof ex.wasm_ctx_depth_func !== 'function') {
|
|
2225
|
+
throw new Error('wasm_ctx_depth_func not found');
|
|
2226
|
+
}
|
|
2227
|
+
const code = ex.wasm_ctx_depth_func(this._ctxHandle, func >>> 0);
|
|
2228
|
+
_checkErr(code, this._instance);
|
|
2229
|
+
}
|
|
2230
|
+
depthMask(flag) {
|
|
2231
|
+
this._assertNotDestroyed();
|
|
2232
|
+
const ex = this._instance.exports;
|
|
2233
|
+
if (!ex || typeof ex.wasm_ctx_depth_mask !== 'function') {
|
|
2234
|
+
throw new Error('wasm_ctx_depth_mask not found');
|
|
2235
|
+
}
|
|
2236
|
+
const code = ex.wasm_ctx_depth_mask(this._ctxHandle, flag ? 1 : 0);
|
|
2237
|
+
_checkErr(code, this._instance);
|
|
2238
|
+
}
|
|
2239
|
+
colorMask(r, g, b, a) {
|
|
2240
|
+
this._assertNotDestroyed();
|
|
2241
|
+
const ex = this._instance.exports;
|
|
2242
|
+
if (!ex || typeof ex.wasm_ctx_color_mask !== 'function') {
|
|
2243
|
+
throw new Error('wasm_ctx_color_mask not found');
|
|
2244
|
+
}
|
|
2245
|
+
const code = ex.wasm_ctx_color_mask(this._ctxHandle, r ? 1 : 0, g ? 1 : 0, b ? 1 : 0, a ? 1 : 0);
|
|
2246
|
+
_checkErr(code, this._instance);
|
|
2247
|
+
}
|
|
2248
|
+
polygonOffset(factor, units) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
2249
|
+
sampleCoverage(value, invert) { this._assertNotDestroyed(); throw new Error('not implemented'); }
|
|
2250
|
+
stencilFunc(func, ref, mask) {
|
|
2251
|
+
this._assertNotDestroyed();
|
|
2252
|
+
const ex = this._instance.exports;
|
|
2253
|
+
if (!ex || typeof ex.wasm_ctx_stencil_func !== 'function') {
|
|
2254
|
+
throw new Error('wasm_ctx_stencil_func not found');
|
|
2255
|
+
}
|
|
2256
|
+
const code = ex.wasm_ctx_stencil_func(this._ctxHandle, func >>> 0, ref | 0, mask >>> 0);
|
|
2257
|
+
_checkErr(code, this._instance);
|
|
2258
|
+
}
|
|
2259
|
+
stencilFuncSeparate(face, func, ref, mask) {
|
|
2260
|
+
this._assertNotDestroyed();
|
|
2261
|
+
const ex = this._instance.exports;
|
|
2262
|
+
if (!ex || typeof ex.wasm_ctx_stencil_func_separate !== 'function') {
|
|
2263
|
+
throw new Error('wasm_ctx_stencil_func_separate not found');
|
|
2264
|
+
}
|
|
2265
|
+
const code = ex.wasm_ctx_stencil_func_separate(this._ctxHandle, face >>> 0, func >>> 0, ref | 0, mask >>> 0);
|
|
2266
|
+
_checkErr(code, this._instance);
|
|
2267
|
+
}
|
|
2268
|
+
stencilOp(fail, zfail, zpass) {
|
|
2269
|
+
this._assertNotDestroyed();
|
|
2270
|
+
const ex = this._instance.exports;
|
|
2271
|
+
if (!ex || typeof ex.wasm_ctx_stencil_op !== 'function') {
|
|
2272
|
+
throw new Error('wasm_ctx_stencil_op not found');
|
|
2273
|
+
}
|
|
2274
|
+
const code = ex.wasm_ctx_stencil_op(this._ctxHandle, fail >>> 0, zfail >>> 0, zpass >>> 0);
|
|
2275
|
+
_checkErr(code, this._instance);
|
|
2276
|
+
}
|
|
2277
|
+
stencilOpSeparate(face, fail, zfail, zpass) {
|
|
2278
|
+
this._assertNotDestroyed();
|
|
2279
|
+
const ex = this._instance.exports;
|
|
2280
|
+
if (!ex || typeof ex.wasm_ctx_stencil_op_separate !== 'function') {
|
|
2281
|
+
throw new Error('wasm_ctx_stencil_op_separate not found');
|
|
2282
|
+
}
|
|
2283
|
+
const code = ex.wasm_ctx_stencil_op_separate(this._ctxHandle, face >>> 0, fail >>> 0, zfail >>> 0, zpass >>> 0);
|
|
2284
|
+
_checkErr(code, this._instance);
|
|
2285
|
+
}
|
|
2286
|
+
stencilMask(mask) {
|
|
2287
|
+
this._assertNotDestroyed();
|
|
2288
|
+
const ex = this._instance.exports;
|
|
2289
|
+
if (!ex || typeof ex.wasm_ctx_stencil_mask !== 'function') {
|
|
2290
|
+
throw new Error('wasm_ctx_stencil_mask not found');
|
|
2291
|
+
}
|
|
2292
|
+
const code = ex.wasm_ctx_stencil_mask(this._ctxHandle, mask >>> 0);
|
|
2293
|
+
_checkErr(code, this._instance);
|
|
2294
|
+
}
|
|
2295
|
+
stencilMaskSeparate(face, mask) {
|
|
2296
|
+
this._assertNotDestroyed();
|
|
2297
|
+
const ex = this._instance.exports;
|
|
2298
|
+
if (!ex || typeof ex.wasm_ctx_stencil_mask_separate !== 'function') {
|
|
2299
|
+
throw new Error('wasm_ctx_stencil_mask_separate not found');
|
|
2300
|
+
}
|
|
2301
|
+
const code = ex.wasm_ctx_stencil_mask_separate(this._ctxHandle, face >>> 0, mask >>> 0);
|
|
2302
|
+
_checkErr(code, this._instance);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
/**
|
|
2307
|
+
* Thin wrapper for a WebGLTexture handle returned from WASM.
|
|
2308
|
+
* Holds a reference to the originating WasmWebGL2RenderingContext and the numeric handle.
|
|
2309
|
+
*/
|
|
2310
|
+
// WebGLTexture wrapper moved to `src/webgl2_texture.js`.
|
|
2311
|
+
|
|
2312
|
+
/**
|
|
2313
|
+
* Read an error message from WASM memory and return it as string.
|
|
2314
|
+
* Exported so callers outside this module can report errors.
|
|
2315
|
+
* @param {WebAssembly.Instance} instance
|
|
2316
|
+
* @returns {string}
|
|
2317
|
+
*/
|
|
2318
|
+
export function readErrorMessage(instance) {
|
|
2319
|
+
const ex = instance.exports;
|
|
2320
|
+
if (!ex || typeof ex.wasm_last_error_ptr !== 'function' || typeof ex.wasm_last_error_len !== 'function') {
|
|
2321
|
+
return '(no error message available)';
|
|
2322
|
+
}
|
|
2323
|
+
const ptr = ex.wasm_last_error_ptr();
|
|
2324
|
+
const len = ex.wasm_last_error_len();
|
|
2325
|
+
if (ptr === 0 || len === 0) {
|
|
2326
|
+
return '';
|
|
2327
|
+
}
|
|
2328
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
2329
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
2330
|
+
return new TextDecoder('utf-8').decode(bytes);
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
function _checkErr(code, instance) {
|
|
2334
|
+
if (code === ERR_OK) return;
|
|
2335
|
+
const msg = readErrorMessage(instance);
|
|
2336
|
+
throw new Error(`WASM error ${code}: ${msg}`);
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
// ============================================================================
|
|
2340
|
+
// WAT Testing Support (docs/1.9-wat-testing.md)
|
|
2341
|
+
// ============================================================================
|
|
2342
|
+
|
|
2343
|
+
/**
|
|
2344
|
+
* Get the compiled WASM bytes for a shader in a program.
|
|
2345
|
+
*
|
|
2346
|
+
* @param {number} ctxHandle - Context handle
|
|
2347
|
+
* @param {number} programHandle - Program handle
|
|
2348
|
+
* @param {number} shaderType - Shader type (VERTEX_SHADER or FRAGMENT_SHADER)
|
|
2349
|
+
* @returns {Uint8Array | null} WASM bytes or null if not available
|
|
2350
|
+
*/
|
|
2351
|
+
export function getShaderModule(ctxHandle, programHandle, shaderType) {
|
|
2352
|
+
const ctx = WasmWebGL2RenderingContext._contexts.get(ctxHandle);
|
|
2353
|
+
if (!ctx) {
|
|
2354
|
+
throw new Error('Invalid context handle');
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
const ex = ctx._instance.exports;
|
|
2358
|
+
if (!ex || typeof ex.wasm_ctx_get_program_wasm_ref !== 'function') {
|
|
2359
|
+
throw new Error('wasm_ctx_get_program_wasm_ref not found');
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// Call the WASM function - it returns a packed u64 (BigInt or Number)
|
|
2363
|
+
const result = ex.wasm_ctx_get_program_wasm_ref(ctxHandle, programHandle, shaderType);
|
|
2364
|
+
|
|
2365
|
+
// Unpack: low 32 bits = ptr, high 32 bits = len
|
|
2366
|
+
let ptr, len;
|
|
2367
|
+
if (typeof result === 'bigint') {
|
|
2368
|
+
ptr = Number(result & 0xFFFFFFFFn);
|
|
2369
|
+
len = Number((result >> 32n) & 0xFFFFFFFFn);
|
|
2370
|
+
} else {
|
|
2371
|
+
// Fallback for number (may lose precision for very large values)
|
|
2372
|
+
ptr = result >>> 0; // Low 32 bits
|
|
2373
|
+
len = Math.floor(result / 0x100000000); // High 32 bits
|
|
2374
|
+
}
|
|
2375
|
+
|
|
2376
|
+
// Check for failure (0, 0)
|
|
2377
|
+
if (ptr === 0 || len === 0) {
|
|
2378
|
+
return null;
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
// Copy bytes from WASM memory into a new Uint8Array
|
|
2382
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
2383
|
+
const bytes = new Uint8Array(len);
|
|
2384
|
+
bytes.set(mem.subarray(ptr, ptr + len));
|
|
2385
|
+
|
|
2386
|
+
return bytes;
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* Get the WAT (WebAssembly Text) representation for a shader in a program.
|
|
2391
|
+
*
|
|
2392
|
+
* @param {number} ctxHandle - Context handle
|
|
2393
|
+
* @param {number} programHandle - Program handle
|
|
2394
|
+
* @param {number} shaderType - Shader type (VERTEX_SHADER or FRAGMENT_SHADER)
|
|
2395
|
+
* @returns {string | null} WAT text or null if not available
|
|
2396
|
+
*/
|
|
2397
|
+
export function getShaderWat(ctxHandle, programHandle, shaderType) {
|
|
2398
|
+
const ctx = WasmWebGL2RenderingContext._contexts.get(ctxHandle);
|
|
2399
|
+
if (!ctx) {
|
|
2400
|
+
throw new Error('Invalid context handle');
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
const ex = ctx._instance.exports;
|
|
2404
|
+
if (!ex || typeof ex.wasm_ctx_get_program_wat_ref !== 'function') {
|
|
2405
|
+
throw new Error('wasm_ctx_get_program_wat_ref not found');
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
// Call the WASM function - it returns a packed u64 (BigInt or Number)
|
|
2409
|
+
const result = ex.wasm_ctx_get_program_wat_ref(ctxHandle, programHandle, shaderType);
|
|
2410
|
+
|
|
2411
|
+
// Unpack: low 32 bits = ptr, high 32 bits = len
|
|
2412
|
+
let ptr, len;
|
|
2413
|
+
if (typeof result === 'bigint') {
|
|
2414
|
+
ptr = Number(result & 0xFFFFFFFFn);
|
|
2415
|
+
len = Number((result >> 32n) & 0xFFFFFFFFn);
|
|
2416
|
+
} else {
|
|
2417
|
+
// Fallback for number (may lose precision for very large values)
|
|
2418
|
+
ptr = result >>> 0; // Low 32 bits
|
|
2419
|
+
len = Math.floor(result / 0x100000000); // High 32 bits
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
// Check for failure (0, 0)
|
|
2423
|
+
if (ptr === 0 || len === 0) {
|
|
2424
|
+
return null;
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
// Copy bytes from WASM memory and decode as UTF-8
|
|
2428
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
2429
|
+
const bytes = mem.subarray(ptr, ptr + len);
|
|
2430
|
+
const decoder = new TextDecoder('utf-8');
|
|
2431
|
+
const watText = decoder.decode(bytes);
|
|
2432
|
+
|
|
2433
|
+
return watText;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
/**
|
|
2437
|
+
* Decompile WASM bytes to GLSL source code.
|
|
2438
|
+
*
|
|
2439
|
+
* This uses the WASM-to-GLSL decompiler to convert compiled shader WASM
|
|
2440
|
+
* back into readable GLSL-like code.
|
|
2441
|
+
*
|
|
2442
|
+
* @param {number} ctxHandle - Context handle
|
|
2443
|
+
* @param {number} programHandle - Program handle
|
|
2444
|
+
* @param {number} shaderType - Shader type (VERTEX_SHADER or FRAGMENT_SHADER)
|
|
2445
|
+
* @returns {string | null} GLSL source code or null if not available
|
|
2446
|
+
*/
|
|
2447
|
+
export function getShaderGlsl(ctxHandle, programHandle, shaderType) {
|
|
2448
|
+
const ctx = WasmWebGL2RenderingContext._contexts.get(ctxHandle);
|
|
2449
|
+
if (!ctx) {
|
|
2450
|
+
throw new Error('Invalid context handle');
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
// First get the WASM bytes for the shader
|
|
2454
|
+
const wasmBytes = getShaderModule(ctxHandle, programHandle, shaderType);
|
|
2455
|
+
if (!wasmBytes) {
|
|
2456
|
+
return null;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
const ex = ctx._instance.exports;
|
|
2460
|
+
if (!ex || typeof ex.wasm_decompile_to_glsl !== 'function') {
|
|
2461
|
+
throw new Error('wasm_decompile_to_glsl not found');
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
// Allocate memory in WASM for the input bytes
|
|
2465
|
+
const wasmBytesLen = wasmBytes.length;
|
|
2466
|
+
const wasmBytesPtr = ex.wasm_alloc(wasmBytesLen);
|
|
2467
|
+
if (wasmBytesPtr === 0) {
|
|
2468
|
+
throw new Error('Failed to allocate memory for WASM bytes');
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
try {
|
|
2472
|
+
// Copy WASM bytes to linear memory
|
|
2473
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
2474
|
+
mem.set(wasmBytes, wasmBytesPtr);
|
|
2475
|
+
|
|
2476
|
+
// Call the decompiler
|
|
2477
|
+
const resultLen = ex.wasm_decompile_to_glsl(wasmBytesPtr, wasmBytesLen);
|
|
2478
|
+
|
|
2479
|
+
if (resultLen === 0) {
|
|
2480
|
+
return null;
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
// Get the decompiled GLSL
|
|
2484
|
+
const glslPtr = ex.wasm_get_decompiled_glsl_ptr();
|
|
2485
|
+
const glslLen = ex.wasm_get_decompiled_glsl_len();
|
|
2486
|
+
|
|
2487
|
+
if (glslPtr === 0 || glslLen === 0) {
|
|
2488
|
+
return null;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
// Read the GLSL string
|
|
2492
|
+
const glslBytes = new Uint8Array(ex.memory.buffer).subarray(glslPtr, glslPtr + glslLen);
|
|
2493
|
+
const decoder = new TextDecoder('utf-8');
|
|
2494
|
+
return decoder.decode(glslBytes);
|
|
2495
|
+
} finally {
|
|
2496
|
+
// Free the allocated memory
|
|
2497
|
+
ex.wasm_free(wasmBytesPtr);
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/**
|
|
2502
|
+
* Decompile raw WASM bytes to GLSL source code.
|
|
2503
|
+
*
|
|
2504
|
+
* This is a lower-level API that takes raw WASM bytes directly.
|
|
2505
|
+
*
|
|
2506
|
+
* @param {WasmWebGL2RenderingContext} gl - WebGL2 context
|
|
2507
|
+
* @param {Uint8Array} wasmBytes - Raw WASM bytecode to decompile
|
|
2508
|
+
* @returns {string | null} GLSL source code or null on error
|
|
2509
|
+
*/
|
|
2510
|
+
export function decompileWasmToGlsl(gl, wasmBytes) {
|
|
2511
|
+
if (!gl || !gl._instance) {
|
|
2512
|
+
throw new Error('Invalid WebGL2 context');
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
const ex = gl._instance.exports;
|
|
2516
|
+
if (!ex || typeof ex.wasm_decompile_to_glsl !== 'function') {
|
|
2517
|
+
throw new Error('wasm_decompile_to_glsl not found');
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
// Allocate memory in WASM for the input bytes
|
|
2521
|
+
const wasmBytesLen = wasmBytes.length;
|
|
2522
|
+
const wasmBytesPtr = ex.wasm_alloc(wasmBytesLen);
|
|
2523
|
+
if (wasmBytesPtr === 0) {
|
|
2524
|
+
throw new Error('Failed to allocate memory for WASM bytes');
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
try {
|
|
2528
|
+
// Copy WASM bytes to linear memory
|
|
2529
|
+
const mem = new Uint8Array(ex.memory.buffer);
|
|
2530
|
+
mem.set(wasmBytes, wasmBytesPtr);
|
|
2531
|
+
|
|
2532
|
+
// Call the decompiler
|
|
2533
|
+
const resultLen = ex.wasm_decompile_to_glsl(wasmBytesPtr, wasmBytesLen);
|
|
2534
|
+
|
|
2535
|
+
if (resultLen === 0) {
|
|
2536
|
+
return null;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
// Get the decompiled GLSL
|
|
2540
|
+
const glslPtr = ex.wasm_get_decompiled_glsl_ptr();
|
|
2541
|
+
const glslLen = ex.wasm_get_decompiled_glsl_len();
|
|
2542
|
+
|
|
2543
|
+
if (glslPtr === 0 || glslLen === 0) {
|
|
2544
|
+
return null;
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
// Read the GLSL string
|
|
2548
|
+
const glslBytes = new Uint8Array(ex.memory.buffer).subarray(glslPtr, glslPtr + glslLen);
|
|
2549
|
+
const decoder = new TextDecoder('utf-8');
|
|
2550
|
+
return decoder.decode(glslBytes);
|
|
2551
|
+
} finally {
|
|
2552
|
+
// Free the allocated memory
|
|
2553
|
+
ex.wasm_free(wasmBytesPtr);
|
|
2554
|
+
}
|
|
2555
|
+
}
|