-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebgl-lint.js
3545 lines (3244 loc) · 147 KB
/
webgl-lint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* webgl-lint@1.11.3, license MIT */
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}((function () { 'use strict';
function isBuiltIn(name) {
return name.startsWith('gl_') || name.startsWith('webgl_');
}
function isWebGL2(gl) {
// a proxy for if this is webgl
return !!gl.texImage3D;
}
function isTypedArray(v) {
return v && v.buffer && v.buffer instanceof ArrayBuffer;
}
function isArrayThatCanHaveBadValues(v) {
return Array.isArray(v) ||
v instanceof Float32Array ||
v instanceof Float64Array;
}
function quotedStringOrEmpty(s) {
return s ? `"${s}"` : '';
}
/**
* Map of names to numbers.
* @type {Object}
*/
const enumStringToValue = {};
function enumArrayToString(gl, enums) {
const enumStrings = [];
if (enums.length) {
for (let i = 0; i < enums.length; ++i) {
enums.push(glEnumToString(enums[i])); // eslint-disable-line
}
return '[' + enumStrings.join(', ') + ']';
}
return enumStrings.toString();
}
function makeBitFieldToStringFunc(enums) {
return function(gl, value) {
let orResult = 0;
const orEnums = [];
for (let i = 0; i < enums.length; ++i) {
const enumValue = enumStringToValue[enums[i]];
if ((value & enumValue) !== 0) {
orResult |= enumValue;
orEnums.push(glEnumToString(enumValue)); // eslint-disable-line
}
}
if (orResult === value) {
return orEnums.join(' | ');
} else {
return glEnumToString(value); // eslint-disable-line
}
};
}
/** @type Map<int, Set<string>> */
const enumToStringsMap = new Map();
function addEnumsFromAPI(api) {
for (const key in api) {
const value = api[key];
if (typeof value === 'number') {
if (!enumToStringsMap.has(value)) {
enumToStringsMap.set(value, new Set());
}
enumToStringsMap.get(value).add(key);
}
}
}
/**
* Gets an string version of an WebGL enum.
*
* Example:
* var str = WebGLDebugUtil.glEnumToString(ctx.getError());
*
* @param {number} value Value to return an enum for
* @return {string} The string version of the enum.
*/
function glEnumToString(value) {
const matches = enumToStringsMap.get(value);
return matches
? [...matches.keys()].map(v => `${v}`).join(' | ')
: `/*UNKNOWN WebGL ENUM*/ ${typeof value === 'number' ? `0x${value.toString(16)}` : value}`;
}
// ---------------------------------
const FLOAT = 0x1406;
const FLOAT_VEC2 = 0x8B50;
const FLOAT_VEC3 = 0x8B51;
const FLOAT_VEC4 = 0x8B52;
const INT = 0x1404;
const INT_VEC2 = 0x8B53;
const INT_VEC3 = 0x8B54;
const INT_VEC4 = 0x8B55;
const BOOL = 0x8B56;
const BOOL_VEC2 = 0x8B57;
const BOOL_VEC3 = 0x8B58;
const BOOL_VEC4 = 0x8B59;
const FLOAT_MAT2 = 0x8B5A;
const FLOAT_MAT3 = 0x8B5B;
const FLOAT_MAT4 = 0x8B5C;
const SAMPLER_2D = 0x8B5E;
const SAMPLER_CUBE = 0x8B60;
const SAMPLER_3D = 0x8B5F;
const SAMPLER_2D_SHADOW = 0x8B62;
const FLOAT_MAT2x3 = 0x8B65;
const FLOAT_MAT2x4 = 0x8B66;
const FLOAT_MAT3x2 = 0x8B67;
const FLOAT_MAT3x4 = 0x8B68;
const FLOAT_MAT4x2 = 0x8B69;
const FLOAT_MAT4x3 = 0x8B6A;
const SAMPLER_2D_ARRAY = 0x8DC1;
const SAMPLER_2D_ARRAY_SHADOW = 0x8DC4;
const SAMPLER_CUBE_SHADOW = 0x8DC5;
const UNSIGNED_INT = 0x1405;
const UNSIGNED_INT_VEC2 = 0x8DC6;
const UNSIGNED_INT_VEC3 = 0x8DC7;
const UNSIGNED_INT_VEC4 = 0x8DC8;
const INT_SAMPLER_2D = 0x8DCA;
const INT_SAMPLER_3D = 0x8DCB;
const INT_SAMPLER_CUBE = 0x8DCC;
const INT_SAMPLER_2D_ARRAY = 0x8DCF;
const UNSIGNED_INT_SAMPLER_2D = 0x8DD2;
const UNSIGNED_INT_SAMPLER_3D = 0x8DD3;
const UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4;
const UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7;
const uniformTypeMap = new Map([
[FLOAT, { size: 1, name: 'float', }],
[FLOAT_VEC2, { size: 2, name: 'vec2', }],
[FLOAT_VEC3, { size: 3, name: 'vec3', }],
[FLOAT_VEC4, { size: 4, name: 'vec4', }],
[INT, { size: 1, name: 'int', }],
[INT_VEC2, { size: 2, name: 'ivec2', }],
[INT_VEC3, { size: 3, name: 'ivec3', }],
[INT_VEC4, { size: 4, name: 'ivec4', }],
[UNSIGNED_INT, { size: 1, name: 'uint', }],
[UNSIGNED_INT_VEC2, { size: 2, name: 'uvec2', }],
[UNSIGNED_INT_VEC3, { size: 3, name: 'uvec3', }],
[UNSIGNED_INT_VEC4, { size: 4, name: 'uvec4', }],
[BOOL, { size: 1, name: 'bool', }],
[BOOL_VEC2, { size: 2, name: 'bvec2', }],
[BOOL_VEC3, { size: 3, name: 'bvec3', }],
[BOOL_VEC4, { size: 4, name: 'bvec4', }],
[FLOAT_MAT2, { size: 4, name: 'mat2', }],
[FLOAT_MAT3, { size: 9, name: 'mat3', }],
[FLOAT_MAT4, { size: 16, name: 'mat4', }],
[FLOAT_MAT2x3, { size: 6, name: 'mat2x3', }],
[FLOAT_MAT2x4, { size: 8, name: 'mat2x4', }],
[FLOAT_MAT3x2, { size: 6, name: 'mat3x2', }],
[FLOAT_MAT3x4, { size: 12, name: 'mat3x4', }],
[FLOAT_MAT4x2, { size: 8, name: 'mat4x2', }],
[FLOAT_MAT4x3, { size: 12, name: 'mat4x3', }],
[SAMPLER_2D, { size: 1, name: 'sampler2D', }],
[SAMPLER_CUBE, { size: 1, name: 'samplerCube', }],
[SAMPLER_3D, { size: 1, name: 'sampler3D', }],
[SAMPLER_2D_SHADOW, { size: 1, name: 'sampler2DShadow', }],
[SAMPLER_2D_ARRAY, { size: 1, name: 'sampler2DArray', }],
[SAMPLER_2D_ARRAY_SHADOW, { size: 1, name: 'sampler2DArrayShadow', }],
[SAMPLER_CUBE_SHADOW, { size: 1, name: 'samplerCubeShadow', }],
[INT_SAMPLER_2D, { size: 1, name: 'isampler2D', }],
[INT_SAMPLER_3D, { size: 1, name: 'isampler3D', }],
[INT_SAMPLER_CUBE, { size: 1, name: 'isamplerCube', }],
[INT_SAMPLER_2D_ARRAY, { size: 1, name: 'isampler2DArray', }],
[UNSIGNED_INT_SAMPLER_2D, { size: 1, name: 'usampler2D', }],
[UNSIGNED_INT_SAMPLER_3D, { size: 1, name: 'usampler3D', }],
[UNSIGNED_INT_SAMPLER_CUBE, { size: 1, name: 'usamplerCube', }],
[UNSIGNED_INT_SAMPLER_2D_ARRAY, { size: 1, name: 'usampler2DArray', }],
]);
function getUniformTypeInfo(type) {
return uniformTypeMap.get(type);
}
// ---------------------------------
const TEXTURE_BINDING_2D = 0x8069;
const TEXTURE_BINDING_CUBE_MAP = 0x8514;
const TEXTURE_BINDING_3D = 0x806A;
const TEXTURE_BINDING_2D_ARRAY = 0x8C1D;
const ARRAY_BUFFER = 0x8892;
const ELEMENT_ARRAY_BUFFER = 0x8893;
const ARRAY_BUFFER_BINDING = 0x8894;
const ELEMENT_ARRAY_BUFFER_BINDING = 0x8895;
const TEXTURE_2D = 0x0DE1;
const TEXTURE_3D = 0x806F;
const TEXTURE_2D_ARRAY = 0x8C1A;
const TEXTURE_CUBE_MAP = 0x8513;
const FRAMEBUFFER = 0x8D40;
const RENDERBUFFER = 0x8D41;
const FRAMEBUFFER_BINDING = 0x8CA6;
const RENDERBUFFER_BINDING = 0x8CA7;
const TRANSFORM_FEEDBACK_BUFFER = 0x8C8E;
const TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F;
const DRAW_FRAMEBUFFER = 0x8CA9;
const READ_FRAMEBUFFER = 0x8CA8;
const READ_FRAMEBUFFER_BINDING = 0x8CAA;
const UNIFORM_BUFFER = 0x8A11;
const UNIFORM_BUFFER_BINDING = 0x8A28;
const TRANSFORM_FEEDBACK = 0x8E22;
const TRANSFORM_FEEDBACK_BINDING = 0x8E25;
const bindPointMap = new Map([
[ARRAY_BUFFER, ARRAY_BUFFER_BINDING],
[ELEMENT_ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER_BINDING],
[TEXTURE_2D, TEXTURE_BINDING_2D],
[TEXTURE_CUBE_MAP, TEXTURE_BINDING_CUBE_MAP],
[TEXTURE_3D, TEXTURE_BINDING_3D],
[TEXTURE_2D_ARRAY, TEXTURE_BINDING_2D_ARRAY],
[RENDERBUFFER, RENDERBUFFER_BINDING],
[FRAMEBUFFER, FRAMEBUFFER_BINDING],
[DRAW_FRAMEBUFFER, FRAMEBUFFER_BINDING],
[READ_FRAMEBUFFER, READ_FRAMEBUFFER_BINDING],
[UNIFORM_BUFFER, UNIFORM_BUFFER_BINDING],
[TRANSFORM_FEEDBACK_BUFFER, TRANSFORM_FEEDBACK_BUFFER_BINDING],
[TRANSFORM_FEEDBACK, TRANSFORM_FEEDBACK_BINDING],
]);
function getBindingQueryEnumForBindPoint(bindPoint) {
return bindPointMap.get(bindPoint);
}
const BYTE = 0x1400;
const SHORT = 0x1402;
const UNSIGNED_BYTE = 0x1401;
const UNSIGNED_SHORT = 0x1403;
const glTypeToSizeMap = new Map([
[BOOL , 1],
[BYTE , 1],
[UNSIGNED_BYTE , 1],
[SHORT , 2],
[UNSIGNED_SHORT , 2],
[INT , 4],
[UNSIGNED_INT , 4],
[FLOAT , 4],
]);
function getBytesPerValueForGLType(type) {
return glTypeToSizeMap.get(type) || 0;
}
const glTypeToTypedArrayMap = new Map([
[UNSIGNED_BYTE, Uint8Array],
[UNSIGNED_SHORT, Uint16Array],
[UNSIGNED_INT, Uint32Array],
]);
function glTypeToTypedArray(type) {
return glTypeToTypedArrayMap.get(type);
}
const drawFuncsToArgs = {
drawArrays(primType, startOffset, vertCount) {
return {startOffset, vertCount, instances: 1};
},
drawElements(primType, vertCount, indexType, startOffset) {
return {startOffset, vertCount, instances: 1, indexType};
},
drawArraysInstanced(primType, startOffset, vertCount, instances) {
return {startOffset, vertCount, instances};
},
drawElementsInstanced(primType, vertCount, indexType, startOffset, instances) {
return {startOffset, vertCount, instances, indexType};
},
drawArraysInstancedANGLE(primType, startOffset, vertCount, instances) {
return {startOffset, vertCount, instances};
},
drawElementsInstancedANGLE(primType, vertCount, indexType, startOffset, instances) {
return {startOffset, vertCount, instances, indexType};
},
drawRangeElements(primType, start, end, vertCount, indexType, startOffset) {
return {startOffset, vertCount, instances: 1, indexType};
},
};
function getDrawFunctionArgs(funcName, args) {
return drawFuncsToArgs[funcName](...args);
}
function isDrawFunction(funcName) {
return !!drawFuncsToArgs[funcName];
}
const attrTypeMap = new Map([
[FLOAT, { size: 4, }],
[FLOAT_VEC2, { size: 8, }],
[FLOAT_VEC3, { size: 12, }],
[FLOAT_VEC4, { size: 16, }],
[INT, { size: 4, }],
[INT_VEC2, { size: 8, }],
[INT_VEC3, { size: 12, }],
[INT_VEC4, { size: 16, }],
[UNSIGNED_INT, { size: 4, }],
[UNSIGNED_INT_VEC2, { size: 8, }],
[UNSIGNED_INT_VEC3, { size: 12, }],
[UNSIGNED_INT_VEC4, { size: 16, }],
[BOOL, { size: 4, }],
[BOOL_VEC2, { size: 8, }],
[BOOL_VEC3, { size: 12, }],
[BOOL_VEC4, { size: 16, }],
[FLOAT_MAT2, { size: 4, count: 2, }],
[FLOAT_MAT3, { size: 9, count: 3, }],
[FLOAT_MAT4, { size: 16, count: 4, }],
]);
function getAttributeTypeInfo(type) {
return attrTypeMap.get(type);
}
const createWeakRef = obj => obj ? new WeakRef(obj) : null;
const isObjectRefEqual = (ref, obj) => {
const refed = ref?.deref();
// check they both reference something or both don't reference something.
if (!!refed !== !!obj) {
return false;
}
return refed ? refed === obj : true;
};
function getWithDefault(v, defaultValue) {
return v === 'undefined' ? defaultValue : v;
}
const VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE;
function computeLastUseIndexForDrawArrays(startOffset, vertCount/*, instances, errors*/) {
return startOffset + vertCount - 1;
}
function getLastUsedIndexForDrawElements(gl, funcName, startOffset, vertCount, instances, indexType, getWebGLObjectString, getIndicesForBuffer, errors) {
const elementBuffer = gl.getParameter(gl.ELEMENT_ARRAY_BUFFER_BINDING);
if (!elementBuffer) {
errors.push('No ELEMENT_ARRAY_BUFFER bound');
return undefined;
}
const bytesPerIndex = getBytesPerValueForGLType(indexType);
const bufferSize = gl.getBufferParameter(gl.ELEMENT_ARRAY_BUFFER, gl.BUFFER_SIZE);
const sizeNeeded = startOffset + vertCount * bytesPerIndex;
if (sizeNeeded > bufferSize) {
errors.push(`offset: ${startOffset} and count: ${vertCount} with index type: ${glEnumToString(indexType)} passed to ${funcName} are out of range for current ELEMENT_ARRAY_BUFFER.
Those parameters require ${sizeNeeded} bytes but the current ELEMENT_ARRAY_BUFFER ${getWebGLObjectString(elementBuffer)} only has ${bufferSize} bytes`);
return undefined;
}
const buffer = getIndicesForBuffer(elementBuffer);
const Type = glTypeToTypedArray(indexType);
const view = new Type(buffer, startOffset);
let maxIndex = view[0];
for (let i = 1; i < vertCount; ++i) {
maxIndex = Math.max(maxIndex, view[i]);
}
return maxIndex;
}
function checkAttributesForBufferOverflow(gl, funcName, args, getWebGLObjectString, getIndicesForBuffer) {
const {vertCount, startOffset, indexType, instances} = getDrawFunctionArgs(funcName, args);
if (vertCount <= 0 || instances <= 0) {
return [];
}
const program = gl.getParameter(gl.CURRENT_PROGRAM);
const errors = [];
const nonInstancedLastIndex = indexType
? getLastUsedIndexForDrawElements(gl, funcName, startOffset, vertCount, instances, indexType, getWebGLObjectString, getIndicesForBuffer, errors)
: computeLastUseIndexForDrawArrays(startOffset, vertCount);
if (errors.length) {
return errors;
}
const hasDivisor = isWebGL2(gl) || gl.getExtension('ANGLE_instanced_arrays');
// get the attributes used by the current program
const numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
const oldArrayBuffer = gl.getParameter(gl.ARRAY_BUFFER_BINDING);
for (let ii = 0; ii < numAttributes; ++ii) {
const {name, type} = gl.getActiveAttrib(program, ii);
if (isBuiltIn(name)) {
continue;
}
const index = gl.getAttribLocation(program, name);
const {count} = {count: 1, ...getAttributeTypeInfo(type)};
for (let jj = 0; jj < count; ++jj) {
const ndx = index + jj;
const enabled = gl.getVertexAttrib(ndx, gl.VERTEX_ATTRIB_ARRAY_ENABLED);
if (!enabled) {
continue;
}
const buffer = gl.getVertexAttrib(ndx, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
if (!buffer) {
errors.push(`no buffer bound to attribute (${name}) location: ${index}`);
continue;
}
const numComponents = gl.getVertexAttrib(ndx, gl.VERTEX_ATTRIB_ARRAY_SIZE);
const type = gl.getVertexAttrib(ndx, gl.VERTEX_ATTRIB_ARRAY_TYPE);
const bytesPerElement = getBytesPerValueForGLType(type) * numComponents;
const offset = gl.getVertexAttribOffset(ndx, gl.VERTEX_ATTRIB_ARRAY_POINTER);
const specifiedStride = gl.getVertexAttrib(ndx, gl.VERTEX_ATTRIB_ARRAY_STRIDE);
const stride = specifiedStride ? specifiedStride : bytesPerElement;
const divisor = hasDivisor
? gl.getVertexAttrib(ndx, VERTEX_ATTRIB_ARRAY_DIVISOR)
: 0;
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
const bufferSize = gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE);
const effectiveLastIndex = divisor > 0
? ((instances + divisor - 1) / divisor | 0) - 1
: nonInstancedLastIndex;
const sizeNeeded = offset + effectiveLastIndex * stride + bytesPerElement;
if (sizeNeeded > bufferSize) {
errors.push(`${getWebGLObjectString(buffer)} assigned to attribute ${ndx} used as attribute '${name}' in current program is too small for draw parameters.
index of highest vertex accessed: ${effectiveLastIndex}
attribute size: ${numComponents}, type: ${glEnumToString(type)}, stride: ${specifiedStride}, offset: ${offset}, divisor: ${divisor}
needs ${sizeNeeded} bytes for draw but buffer is only ${bufferSize} bytes`);
}
}
}
gl.bindBuffer(gl.ARRAY_BUFFER, oldArrayBuffer);
return errors;
}
const SAMPLER_2D$1 = 0x8B5E;
const SAMPLER_CUBE$1 = 0x8B60;
const SAMPLER_3D$1 = 0x8B5F;
const SAMPLER_2D_SHADOW$1 = 0x8B62;
const SAMPLER_2D_ARRAY$1 = 0x8DC1;
const SAMPLER_2D_ARRAY_SHADOW$1 = 0x8DC4;
const SAMPLER_CUBE_SHADOW$1 = 0x8DC5;
const INT_SAMPLER_2D$1 = 0x8DCA;
const INT_SAMPLER_3D$1 = 0x8DCB;
const INT_SAMPLER_CUBE$1 = 0x8DCC;
const INT_SAMPLER_2D_ARRAY$1 = 0x8DCF;
const UNSIGNED_INT_SAMPLER_2D$1 = 0x8DD2;
const UNSIGNED_INT_SAMPLER_3D$1 = 0x8DD3;
const UNSIGNED_INT_SAMPLER_CUBE$1 = 0x8DD4;
const UNSIGNED_INT_SAMPLER_2D_ARRAY$1 = 0x8DD7;
const samplerTypes = new Map([
[SAMPLER_2D$1, {uniformType: 'sampler2D', numberType: 'float/normalized', bindPoint: '2D'}],
[SAMPLER_CUBE$1, {uniformType: 'samplerCube', numberType: 'float/normalized', bindPoint: 'CUBE'}],
[SAMPLER_3D$1, {uniformType: 'sampler3D', numberType: 'float/normalized', bindPoint: '3D'}],
[SAMPLER_2D_SHADOW$1, {uniformType: 'sampler2D', numberType: 'float/normalized', bindPoint: '2D'}],
[SAMPLER_2D_ARRAY$1, {uniformType: 'sampler2DArray', numberType: 'float/normalized', bindPoint: '2D_ARRAY'}],
[SAMPLER_2D_ARRAY_SHADOW$1, {uniformType: 'sampler2DArray', numberType: 'float/normalized', bindPoint: '2D_ARRAY'}],
[SAMPLER_CUBE_SHADOW$1, {uniformType: 'samplerCube', numberType: 'float/normalized', bindPoint: 'CUBE'}],
[INT_SAMPLER_2D$1, {uniformType: 'isampler2D', numberType: 'int', bindPoint: '2D'}],
[INT_SAMPLER_3D$1, {uniformType: 'isampler3D', numberType: 'int', bindPoint: '3D'}],
[INT_SAMPLER_CUBE$1, {uniformType: 'isamplerCube', numberType: 'int', bindPoint: 'CUBE'}],
[INT_SAMPLER_2D_ARRAY$1, {uniformType: 'isampler2DArray', numberType: 'int', bindPoint: '2D_ARRAY'}],
[UNSIGNED_INT_SAMPLER_2D$1, {uniformType: 'usampler2D', numberType: 'unsigned int', bindPoint: '2D'}],
[UNSIGNED_INT_SAMPLER_3D$1, {uniformType: 'usampler3D', numberType: 'unsigned int', bindPoint: '3D'}],
[UNSIGNED_INT_SAMPLER_CUBE$1, {uniformType: 'usamplerCube', numberType: 'unsigned int', bindPoint: 'CUBE'}],
[UNSIGNED_INT_SAMPLER_2D_ARRAY$1, {uniformType: 'usampler2DArray', numberType: 'unsigned int', bindPoint: '2D_ARRAY'}],
]);
function getBindPointForSampler(type) {
return samplerTypes.get(type).bindPoint;
}
function uniformTypeIsSampler(type) {
return samplerTypes.has(type);
}
function getNumberTypeForUniformSamplerType(type) {
return samplerTypes.get(type).numberType;
}
function getUniformTypeForUniformSamplerType(type) {
return samplerTypes.get(type).uniformType;
}
const TEXTURE_2D$1 = 0x0DE1;
const TEXTURE_3D$1 = 0x806F;
const TEXTURE_2D_ARRAY$1 = 0x8C1A;
const TEXTURE_CUBE_MAP$1 = 0x8513;
const TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
const TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
const TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
const TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
const TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
const TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A;
const targetToBindPointMap = new Map([
[TEXTURE_2D$1, '2D'],
[TEXTURE_3D$1, '3D'],
[TEXTURE_CUBE_MAP$1, 'CUBE'],
[TEXTURE_CUBE_MAP_POSITIVE_X, 'CUBE'],
[TEXTURE_CUBE_MAP_NEGATIVE_X, 'CUBE'],
[TEXTURE_CUBE_MAP_POSITIVE_Y, 'CUBE'],
[TEXTURE_CUBE_MAP_NEGATIVE_Y, 'CUBE'],
[TEXTURE_CUBE_MAP_POSITIVE_Z, 'CUBE'],
[TEXTURE_CUBE_MAP_NEGATIVE_Z, 'CUBE'],
[TEXTURE_2D_ARRAY$1, '2D_ARRAY'],
]);
function getBindPointForTarget(target) {
return targetToBindPointMap.get(target);
}
const TEXTURE_BINDING_2D$1 = 0x8069;
const TEXTURE_BINDING_CUBE_MAP$1 = 0x8514;
const TEXTURE_BINDING_3D$1 = 0x806A;
const TEXTURE_BINDING_2D_ARRAY$1 = 0x8C1D;
const samplerTypeToBinding = new Map([
[SAMPLER_2D$1, TEXTURE_BINDING_2D$1],
[SAMPLER_2D_SHADOW$1, TEXTURE_BINDING_2D$1],
[SAMPLER_3D$1, TEXTURE_BINDING_3D$1],
[SAMPLER_2D_ARRAY$1, TEXTURE_BINDING_2D_ARRAY$1],
[SAMPLER_2D_ARRAY_SHADOW$1, TEXTURE_BINDING_2D_ARRAY$1],
[SAMPLER_CUBE$1, TEXTURE_BINDING_CUBE_MAP$1],
[SAMPLER_CUBE_SHADOW$1, TEXTURE_BINDING_CUBE_MAP$1],
]);
function getTextureForUnit(gl, unit, type) {
gl.activeTexture(gl.TEXTURE0 + unit);
const binding = samplerTypeToBinding.get(type);
return gl.getParameter(binding);
}
/* global WebGLTexture */
const MAX_COLOR_ATTACHMENTS = 0x8CDF;
function getMaxColorAttachments(gl) {
if (!isWebGL2(gl)) {
const ext = gl.getExtension('WEBGL_draw_buffers');
if (!ext) {
return 1;
}
}
return gl.getParameter(MAX_COLOR_ATTACHMENTS);
}
/**
* slow non-cached version
* @param {WebGLRenderingContext} gl
* @param {number} attachment
* @param {Map<WebGLTexture, [number]>} textureAttachments
*/
function addTextureAttachment(gl, attachment, textureAttachments) {
const type = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, attachment, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE);
if (type === gl.NONE) {
return;
}
const obj = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, attachment, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
if (obj instanceof WebGLTexture) {
if (!textureAttachments.has(obj)) {
textureAttachments.set(obj, []);
}
textureAttachments.get(obj).push(attachment);
}
}
/**
* slow non-cached version
* @param {WebGLRenderingContext} gl
*/
function checkFramebufferFeedback(gl, getWebGLObjectString) {
const framebuffer = gl.getParameter(gl.FRAMEBUFFER_BINDING);
if (!framebuffer) {
// drawing to canvas
return [];
}
// get framebuffer texture attachments
const maxColorAttachments = getMaxColorAttachments(gl);
const textureAttachments = new Map();
for (let i = 0; i < maxColorAttachments; ++i) {
addTextureAttachment(gl, gl.COLOR_ATTACHMENT0 + i, textureAttachments);
}
addTextureAttachment(gl, gl.DEPTH_ATTACHMENT, textureAttachments);
addTextureAttachment(gl, gl.STENCIL_ATTACHMENT, textureAttachments);
if (!isWebGL2(gl)) {
addTextureAttachment(gl, gl.DEPTH_STENCIL_ATTACHMENT, textureAttachments);
}
const oldActiveTexture = gl.getParameter(gl.ACTIVE_TEXTURE);
const program = gl.getParameter(gl.CURRENT_PROGRAM);
// get the texture units used by the current program
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
const errors = [];
for (let ii = 0; ii < numUniforms; ++ii) {
const {name, type, size} = gl.getActiveUniform(program, ii);
if (isBuiltIn(name) || !uniformTypeIsSampler(type)) {
continue;
}
if (size > 1) {
const baseName = (name.substr(-3) === '[0]')
? name.substr(0, name.length - 3)
: name;
for (let t = 0; t < size; ++t) {
errors.push(...checkTextureUsage(gl, framebuffer, textureAttachments, program, `${baseName}[${t}]`, type, getWebGLObjectString));
}
} else {
errors.push(...checkTextureUsage(gl, framebuffer, textureAttachments, program, name, type, getWebGLObjectString));
}
}
gl.activeTexture(oldActiveTexture);
return errors;
}
function checkTextureUsage(gl, framebuffer, textureAttachments, program, uniformName, uniformType, getWebGLObjectString) {
const location = gl.getUniformLocation(program, uniformName);
const textureUnit = gl.getUniform(program, location);
const texture = getTextureForUnit(gl, textureUnit, uniformType);
const attachments = textureAttachments.get(texture);
return attachments
? [`${getWebGLObjectString(texture)} on uniform: ${uniformName} bound to texture unit ${textureUnit} is also attached to ${getWebGLObjectString(framebuffer)} on attachment: ${attachments.map(a => glEnumToString(a)).join(', ')}`]
: [];
}
/* global navigator */
// adapted from http://stackoverflow.com/a/2401861/128511
function getBrowser() {
const userAgent = navigator.userAgent;
let m = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(m[1])) {
m = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
return {
name: 'IE',
version: m[1],
};
}
if (m[1] === 'Chrome') {
const temp = userAgent.match(/\b(OPR|Edge)\/(\d+)/);
if (temp) {
return {
name: temp[1].replace('OPR', 'Opera'),
version: temp[2],
};
}
}
m = m[2] ? [m[1], m[2]] : [navigator.appName, navigator.appVersion, '-?'];
const version = userAgent.match(/version\/(\d+)/i);
if (version) {
m.splice(1, 1, version[1]);
}
return {
name: m[0],
version: m[1],
};
}
/**
* @typedef {Object} StackInfo
* @property {string} url Url of line
* @property {number} lineNo line number of error
* @property {number} colNo column number of error
* @property {string} [funcName] name of function
*/
/**
* @parameter {string} stack A stack string as in `(new Error()).stack`
* @returns {StackInfo}
*/
const parseStack = function() {
const browser = getBrowser();
let lineNdx;
let matcher;
if ((/chrome|opera/i).test(browser.name)) {
lineNdx = 3;
matcher = function(line) {
const m = /at ([^(]+)*\(*(.*?):(\d+):(\d+)/.exec(line);
if (m) {
let userFnName = m[1];
let url = m[2];
const lineNo = parseInt(m[3]);
const colNo = parseInt(m[4]);
if (url === '') {
url = userFnName;
userFnName = '';
}
return {
url: url,
lineNo: lineNo,
colNo: colNo,
funcName: userFnName,
};
}
return undefined;
};
} else if ((/firefox|safari/i).test(browser.name)) {
lineNdx = 2;
matcher = function(line) {
const m = /@(.*?):(\d+):(\d+)/.exec(line);
if (m) {
const url = m[1];
const lineNo = parseInt(m[2]);
const colNo = parseInt(m[3]);
return {
url: url,
lineNo: lineNo,
colNo: colNo,
};
}
return undefined;
};
}
return function stackParser(stack) {
if (matcher) {
try {
const lines = stack.split('\n');
// window.fooLines = lines;
// lines.forEach(function(line, ndx) {
// origConsole.log("#", ndx, line);
// });
return matcher(lines[lineNdx]);
} catch (e) {
// do nothing
}
}
return undefined;
};
}();
function createTextureUnits(gl) {
const textureUnits = [];
const numUnits = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
for (let i = 0; i < numUnits; ++i) {
textureUnits.push(new Map());
}
return textureUnits;
}
const TEXTURE0 = 0x84C0;
const TEXTURE_2D$2 = 0x0DE1;
const TEXTURE_3D$2 = 0x806F;
const TEXTURE_CUBE_MAP$2 = 0x8513;
const TEXTURE_CUBE_MAP_POSITIVE_X$1 = 0x8515;
const TEXTURE_CUBE_MAP_NEGATIVE_X$1 = 0x8516;
const TEXTURE_CUBE_MAP_POSITIVE_Y$1 = 0x8517;
const TEXTURE_CUBE_MAP_NEGATIVE_Y$1 = 0x8518;
const TEXTURE_CUBE_MAP_POSITIVE_Z$1 = 0x8519;
const TEXTURE_CUBE_MAP_NEGATIVE_Z$1 = 0x851A;
const TEXTURE_MIN_FILTER = 0x2801;
const TEXTURE_MAG_FILTER = 0x2800;
const TEXTURE_BASE_LEVEL = 0x813c; // int
const TEXTURE_MAX_LEVEL = 0x813d; // int
const TEXTURE_WRAP_S = 0x2802;
const TEXTURE_WRAP_T = 0x2803;
const REPEAT = 0x2901;
const TEXTURE_2D_ARRAY$2 = 0x8C1A;
const CLAMP_TO_EDGE = 0x812F;
const NEAREST = 0x2600;
const LINEAR = 0x2601;
const NEAREST_MIPMAP_LINEAR = 0x2702;
const texImage2DArgParersMap = new Map([
[9, function([target, level, internalFormat, width, height, , format, type]) {
return {target, level, internalFormat, width, height, format, type};
}, ],
[6, function([target, level, internalFormat, format, type, texImageSource]) {
return {target, level, internalFormat, width: texImageSource.width, height: texImageSource.height, format, type};
}, ],
[10, function([target, level, internalFormat, width, height, , format, type]) {
return {target, level, internalFormat, width, height, format, type};
}, ],
]);
const ALPHA = 0x1906;
const RGB = 0x1907;
const RGBA = 0x1908;
const LUMINANCE = 0x1909;
const LUMINANCE_ALPHA = 0x190A;
const DEPTH_COMPONENT = 0x1902;
const DEPTH_STENCIL = 0x84F9;
const unsizedInternalFormats = new Set([
ALPHA,
LUMINANCE,
LUMINANCE_ALPHA,
RGB,
RGBA,
]);
function getInternalFormatStringForInternalFormatType(internalFormat, type) {
return unsizedInternalFormats.has(internalFormat)
? `${glEnumToString(internalFormat)}/${glEnumToString(type)}`
: glEnumToString(internalFormat);
}
const targetToFaceIndex = new Map([
[TEXTURE_2D$2, 0],
[TEXTURE_3D$2, 0],
[TEXTURE_2D_ARRAY$2, 0],
[TEXTURE_CUBE_MAP$2, 0],
[TEXTURE_CUBE_MAP_POSITIVE_X$1, 0],
[TEXTURE_CUBE_MAP_NEGATIVE_X$1, 1],
[TEXTURE_CUBE_MAP_POSITIVE_Y$1, 2],
[TEXTURE_CUBE_MAP_NEGATIVE_Y$1, 3],
[TEXTURE_CUBE_MAP_POSITIVE_Z$1, 4],
[TEXTURE_CUBE_MAP_NEGATIVE_Z$1, 5],
]);
function getFaceTarget(face, type) {
if (type === TEXTURE_CUBE_MAP$2) {
return `(${glEnumToString(TEXTURE_CUBE_MAP_POSITIVE_X$1 + face)})`;
} else {
return '';
}
}
const twoDFaceTargets = [
TEXTURE_2D$2,
];
const cubeMapFaceTargets = [
TEXTURE_CUBE_MAP_POSITIVE_X$1,
TEXTURE_CUBE_MAP_NEGATIVE_X$1,
TEXTURE_CUBE_MAP_POSITIVE_Y$1,
TEXTURE_CUBE_MAP_NEGATIVE_Y$1,
TEXTURE_CUBE_MAP_POSITIVE_Z$1,
TEXTURE_CUBE_MAP_NEGATIVE_Z$1,
];
/*
const targetToBindPointMap = new Map([
[TEXTURE_2D, TEXTURE_2D],
[TEXTURE_3D, TEXTURE_3D],
[TEXTURE_2D_ARRAY, TEXTURE_2D_ARRAY],
[TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP],
[TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP],
[TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP],
[TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP],
[TEXTURE_CUBE_MAP_POSITIVE_Z, TEXTURE_CUBE_MAP],
[TEXTURE_CUBE_MAP_NEGATIVE_Z, TEXTURE_CUBE_MAP],
]);
*/
const R8 = 0x8229;
const R8_SNORM = 0x8F94;
const R16F = 0x822D;
const R32F = 0x822E;
const R8UI = 0x8232;
const R8I = 0x8231;
const RG16UI = 0x823A;
const RG16I = 0x8239;
const RG32UI = 0x823C;
const RG32I = 0x823B;
const RG8 = 0x822B;
const RG8_SNORM = 0x8F95;
const RG16F = 0x822F;
const RG32F = 0x8230;
const RG8UI = 0x8238;
const RG8I = 0x8237;
const R16UI = 0x8234;
const R16I = 0x8233;
const R32UI = 0x8236;
const R32I = 0x8235;
const RGB8 = 0x8051;
const SRGB8 = 0x8C41;
const RGB565 = 0x8D62;
const RGB8_SNORM = 0x8F96;
const R11F_G11F_B10F = 0x8C3A;
const RGB9_E5 = 0x8C3D;
const RGB16F = 0x881B;
const RGB32F = 0x8815;
const RGB8UI = 0x8D7D;
const RGB8I = 0x8D8F;
const RGB16UI = 0x8D77;
const RGB16I = 0x8D89;
const RGB32UI = 0x8D71;
const RGB32I = 0x8D83;
const RGBA8 = 0x8058;
const SRGB8_ALPHA8 = 0x8C43;
const RGBA8_SNORM = 0x8F97;
const RGB5_A1 = 0x8057;
const RGBA4 = 0x8056;
const RGB10_A2 = 0x8059;
const RGBA16F = 0x881A;
const RGBA32F = 0x8814;
const RGBA8UI = 0x8D7C;
const RGBA8I = 0x8D8E;
const RGB10_A2UI = 0x906F;
const RGBA16UI = 0x8D76;
const RGBA16I = 0x8D88;
const RGBA32I = 0x8D82;
const RGBA32UI = 0x8D70;
const DEPTH_COMPONENT16 = 0x81A5;
const DEPTH_COMPONENT24 = 0x81A6;
const DEPTH_COMPONENT32F = 0x8CAC;
const DEPTH32F_STENCIL8 = 0x8CAD;
const DEPTH24_STENCIL8 = 0x88F0;
/* DataType */
const BYTE$1 = 0x1400;
const UNSIGNED_BYTE$1 = 0x1401;
const SHORT$1 = 0x1402;
const UNSIGNED_SHORT$1 = 0x1403;
const INT$1 = 0x1404;
const UNSIGNED_INT$1 = 0x1405;
const FLOAT$1 = 0x1406;
const UNSIGNED_SHORT_4_4_4_4 = 0x8033;
const UNSIGNED_SHORT_5_5_5_1 = 0x8034;
const UNSIGNED_SHORT_5_6_5 = 0x8363;
const HALF_FLOAT = 0x140B;
const HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
const UNSIGNED_INT_2_10_10_10_REV = 0x8368;
const UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
const UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
const FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
const UNSIGNED_INT_24_8 = 0x84FA;
const RG = 0x8227;
const RG_INTEGER = 0x8228;
const RED = 0x1903;
const RED_INTEGER = 0x8D94;
const RGB_INTEGER = 0x8D98;
const RGBA_INTEGER = 0x8D99;
function createTextureInternalFormatInfoMap() {
const textureInternalFormatInfoMap = new Map([
// unsized formats
[ALPHA, { textureFormat: ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$1], }],
[LUMINANCE, { textureFormat: LUMINANCE, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$1], }],
[LUMINANCE_ALPHA, { textureFormat: LUMINANCE_ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [2, 4, 4, 8], type: [UNSIGNED_BYTE$1], }],
[RGB, { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 6, 6, 12, 2], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_5_6_5], }],
[RGBA, { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1], }],
// sized formats
[R8, { textureFormat: RED, colorRenderable: true, textureFilterable: true, bytesPerElement: [1], type: [UNSIGNED_BYTE$1], }],
[R8_SNORM, { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [1], type: [BYTE$1], }],
[R16F, { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [4, 2], type: [FLOAT$1, HALF_FLOAT], }],
[R32F, { textureFormat: RED, colorRenderable: false, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$1], }],
[R8UI, { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [UNSIGNED_BYTE$1], }],
[R8I, { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [BYTE$1], }],
[R16UI, { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_SHORT$1], }],
[R16I, { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [SHORT$1], }],
[R32UI, { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$1], }],
[R32I, { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [INT$1], }],
[RG8, { textureFormat: RG, colorRenderable: true, textureFilterable: true, bytesPerElement: [2], type: [UNSIGNED_BYTE$1], }],
[RG8_SNORM, { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [2], type: [BYTE$1], }],
[RG16F, { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [8, 4], type: [FLOAT$1, HALF_FLOAT], }],
[RG32F, { textureFormat: RG, colorRenderable: false, textureFilterable: false, bytesPerElement: [8], type: [FLOAT$1], }],
[RG8UI, { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_BYTE$1], }],
[RG8I, { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [BYTE$1], }],
[RG16UI, { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_SHORT$1], }],
[RG16I, { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [SHORT$1], }],
[RG32UI, { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_INT$1], }],
[RG32I, { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [INT$1], }],
[RGB8, { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$1], }],
[SRGB8, { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$1], }],
[RGB565, { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 2], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_5_6_5], }],
[RGB8_SNORM, { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [BYTE$1], }],
[R11F_G11F_B10F, { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$1, HALF_FLOAT, UNSIGNED_INT_10F_11F_11F_REV], }],
[RGB9_E5, { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$1, HALF_FLOAT, UNSIGNED_INT_5_9_9_9_REV], }],
[RGB16F, { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6], type: [FLOAT$1, HALF_FLOAT], }],
[RGB32F, { textureFormat: RGB, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [FLOAT$1], }],
[RGB8UI, { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [UNSIGNED_BYTE$1], }],
[RGB8I, { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [BYTE$1], }],
[RGB16UI, { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [UNSIGNED_SHORT$1], }],
[RGB16I, { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [SHORT$1], }],
[RGB32UI, { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [UNSIGNED_INT$1], }],
[RGB32I, { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [INT$1], }],
[RGBA8, { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$1], }],
[SRGB8_ALPHA8, { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$1], }],
[RGBA8_SNORM, { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [4], type: [BYTE$1], }],
[RGB5_A1, { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2, 4], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_5_5_5_1, UNSIGNED_INT_2_10_10_10_REV], }],
[RGBA4, { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_4_4_4_4], }],
[RGB10_A2, { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV], }],
[RGBA16F, { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [16, 8], type: [FLOAT$1, HALF_FLOAT], }],
[RGBA32F, { textureFormat: RGBA, colorRenderable: false, textureFilterable: false, bytesPerElement: [16], type: [FLOAT$1], }],
[RGBA8UI, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_BYTE$1], }],
[RGBA8I, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [BYTE$1], }],
[RGB10_A2UI, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV], }],
[RGBA16UI, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_SHORT$1], }],
[RGBA16I, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [SHORT$1], }],
[RGBA32I, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [INT$1], }],
[RGBA32UI, { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [UNSIGNED_INT$1], }],
// Sized Internal these are marked as not filterable but for some reason they apparently are?
[DEPTH_COMPONENT16, { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: true/*false*/, bytesPerElement: [2, 4], type: [UNSIGNED_SHORT$1, UNSIGNED_INT$1], }],
[DEPTH_COMPONENT24, { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: true/*false*/, bytesPerElement: [4], type: [UNSIGNED_INT$1], }],
[DEPTH_COMPONENT32F, { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: true/*false*/, bytesPerElement: [4], type: [FLOAT$1], }],
[DEPTH24_STENCIL8, { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_24_8], }],
[DEPTH32F_STENCIL8, { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT_32_UNSIGNED_INT_24_8_REV], }],
]);
textureInternalFormatInfoMap.forEach((info) =>{
info.bytesPerElementMap = {};
info.bytesPerElement.forEach(function(bytesPerElement, ndx) {
const type = info.type[ndx];
info.bytesPerElementMap[type] = bytesPerElement;
});