twgl.js 5.0.4 → 5.2.0

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.
@@ -1,4 +1,4 @@
1
- /* @license twgl.js 5.0.4 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
1
+ /* @license twgl.js 5.2.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
2
  Available via the MIT license.
3
3
  see: http://github.com/greggman/twgl.js for details */
4
4
  /*
@@ -63,7 +63,7 @@ let VecType = Float32Array;
63
63
  * @return {constructor} previous constructor for Vec3
64
64
  * @memberOf module:twgl/v3
65
65
  */
66
- function setDefaultType(ctor) {
66
+ function setDefaultType$1(ctor) {
67
67
  const oldType = VecType;
68
68
  VecType = ctor;
69
69
  return oldType;
@@ -77,7 +77,7 @@ function setDefaultType(ctor) {
77
77
  * @return {module:twgl/v3.Vec3} the created vector
78
78
  * @memberOf module:twgl/v3
79
79
  */
80
- function create(x, y, z) {
80
+ function create$1(x, y, z) {
81
81
  const dst = new VecType(3);
82
82
  if (x) {
83
83
  dst[0] = x;
@@ -358,7 +358,7 @@ function normalize(a, dst) {
358
358
  * @return {module:twgl/v3.Vec3} -v.
359
359
  * @memberOf module:twgl/v3
360
360
  */
361
- function negate(v, dst) {
361
+ function negate$1(v, dst) {
362
362
  dst = dst || new VecType(3);
363
363
 
364
364
  dst[0] = -v[0];
@@ -375,7 +375,7 @@ function negate(v, dst) {
375
375
  * @return {module:twgl/v3.Vec3} A copy of v.
376
376
  * @memberOf module:twgl/v3
377
377
  */
378
- function copy(v, dst) {
378
+ function copy$1(v, dst) {
379
379
  dst = dst || new VecType(3);
380
380
 
381
381
  dst[0] = v[0];
@@ -395,7 +395,7 @@ function copy(v, dst) {
395
395
  * b.
396
396
  * @memberOf module:twgl/v3
397
397
  */
398
- function multiply(a, b, dst) {
398
+ function multiply$1(a, b, dst) {
399
399
  dst = dst || new VecType(3);
400
400
 
401
401
  dst[0] = a[0] * b[0];
@@ -428,8 +428,8 @@ function divide(a, b, dst) {
428
428
  var v3 = /*#__PURE__*/Object.freeze({
429
429
  __proto__: null,
430
430
  add: add,
431
- copy: copy,
432
- create: create,
431
+ copy: copy$1,
432
+ create: create$1,
433
433
  cross: cross,
434
434
  distance: distance,
435
435
  distanceSq: distanceSq,
@@ -443,10 +443,10 @@ var v3 = /*#__PURE__*/Object.freeze({
443
443
  max: max,
444
444
  min: min,
445
445
  mulScalar: mulScalar,
446
- multiply: multiply,
447
- negate: negate,
446
+ multiply: multiply$1,
447
+ negate: negate$1,
448
448
  normalize: normalize,
449
- setDefaultType: setDefaultType,
449
+ setDefaultType: setDefaultType$1,
450
450
  subtract: subtract
451
451
  });
452
452
 
@@ -512,7 +512,7 @@ let MatType = Float32Array;
512
512
  * @return {constructor} previous constructor for Mat4
513
513
  * @memberOf module:twgl/m4
514
514
  */
515
- function setDefaultType$1(ctor) {
515
+ function setDefaultType(ctor) {
516
516
  const oldType = MatType;
517
517
  MatType = ctor;
518
518
  return oldType;
@@ -525,7 +525,7 @@ function setDefaultType$1(ctor) {
525
525
  * @return {module:twgl/m4.Mat4} -m.
526
526
  * @memberOf module:twgl/m4
527
527
  */
528
- function negate$1(m, dst) {
528
+ function negate(m, dst) {
529
529
  dst = dst || new MatType(16);
530
530
 
531
531
  dst[ 0] = -m[ 0];
@@ -553,7 +553,7 @@ function negate$1(m, dst) {
553
553
  * @return {module:twgl/m4.Mat4} A new matrix.
554
554
  * @memberOf module:twgl/m4
555
555
  */
556
- function create$1() {
556
+ function create() {
557
557
  return new MatType(16).fill(0);
558
558
  }
559
559
 
@@ -564,7 +564,7 @@ function create$1() {
564
564
  * @return {module:twgl/m4.Mat4} A copy of m.
565
565
  * @memberOf module:twgl/m4
566
566
  */
567
- function copy$1(m, dst) {
567
+ function copy(m, dst) {
568
568
  dst = dst || new MatType(16);
569
569
 
570
570
  dst[ 0] = m[ 0];
@@ -794,7 +794,7 @@ function inverse(m, dst) {
794
794
  * @return {module:twgl/m4.Mat4} The matrix product of a and b.
795
795
  * @memberOf module:twgl/m4
796
796
  */
797
- function multiply$1(a, b, dst) {
797
+ function multiply(a, b, dst) {
798
798
  dst = dst || new MatType(16);
799
799
 
800
800
  const a00 = a[0];
@@ -891,7 +891,7 @@ function setTranslation(a, v, dst) {
891
891
  * @memberOf module:twgl/m4
892
892
  */
893
893
  function getTranslation(m, dst) {
894
- dst = dst || create();
894
+ dst = dst || create$1();
895
895
  dst[0] = m[12];
896
896
  dst[1] = m[13];
897
897
  dst[2] = m[14];
@@ -907,7 +907,7 @@ function getTranslation(m, dst) {
907
907
  * @memberOf module:twgl/m4
908
908
  */
909
909
  function getAxis(m, axis, dst) {
910
- dst = dst || create();
910
+ dst = dst || create$1();
911
911
  const off = axis * 4;
912
912
  dst[0] = m[off + 0];
913
913
  dst[1] = m[off + 1];
@@ -926,7 +926,7 @@ function getAxis(m, axis, dst) {
926
926
  */
927
927
  function setAxis(a, v, axis, dst) {
928
928
  if (dst !== a) {
929
- dst = copy$1(a, dst);
929
+ dst = copy(a, dst);
930
930
  }
931
931
  const off = axis * 4;
932
932
  dst[off + 0] = v[0];
@@ -1094,9 +1094,9 @@ let zAxis;
1094
1094
  function lookAt(eye, target, up, dst) {
1095
1095
  dst = dst || new MatType(16);
1096
1096
 
1097
- xAxis = xAxis || create();
1098
- yAxis = yAxis || create();
1099
- zAxis = zAxis || create();
1097
+ xAxis = xAxis || create$1();
1098
+ yAxis = yAxis || create$1();
1099
+ zAxis = zAxis || create$1();
1100
1100
 
1101
1101
  normalize(
1102
1102
  subtract(eye, target, zAxis), zAxis);
@@ -1652,7 +1652,7 @@ function scale(m, v, dst) {
1652
1652
  * @memberOf module:twgl/m4
1653
1653
  */
1654
1654
  function transformPoint(m, v, dst) {
1655
- dst = dst || create();
1655
+ dst = dst || create$1();
1656
1656
  const v0 = v[0];
1657
1657
  const v1 = v[1];
1658
1658
  const v2 = v[2];
@@ -1679,7 +1679,7 @@ function transformPoint(m, v, dst) {
1679
1679
  * @memberOf module:twgl/m4
1680
1680
  */
1681
1681
  function transformDirection(m, v, dst) {
1682
- dst = dst || create();
1682
+ dst = dst || create$1();
1683
1683
 
1684
1684
  const v0 = v[0];
1685
1685
  const v1 = v[1];
@@ -1707,8 +1707,8 @@ function transformDirection(m, v, dst) {
1707
1707
  * @return {module:twgl/v3.Vec3} The transformed normal.
1708
1708
  * @memberOf module:twgl/m4
1709
1709
  */
1710
- function transformNormal(m, v, dst) {
1711
- dst = dst || create();
1710
+ function transformNormal$1(m, v, dst) {
1711
+ dst = dst || create$1();
1712
1712
  const mi = inverse(m);
1713
1713
  const v0 = v[0];
1714
1714
  const v1 = v[1];
@@ -1725,16 +1725,16 @@ var m4 = /*#__PURE__*/Object.freeze({
1725
1725
  __proto__: null,
1726
1726
  axisRotate: axisRotate,
1727
1727
  axisRotation: axisRotation,
1728
- copy: copy$1,
1729
- create: create$1,
1728
+ copy: copy,
1729
+ create: create,
1730
1730
  frustum: frustum,
1731
1731
  getAxis: getAxis,
1732
1732
  getTranslation: getTranslation,
1733
1733
  identity: identity,
1734
1734
  inverse: inverse,
1735
1735
  lookAt: lookAt,
1736
- multiply: multiply$1,
1737
- negate: negate$1,
1736
+ multiply: multiply,
1737
+ negate: negate,
1738
1738
  ortho: ortho,
1739
1739
  perspective: perspective,
1740
1740
  rotateX: rotateX,
@@ -1746,10 +1746,10 @@ var m4 = /*#__PURE__*/Object.freeze({
1746
1746
  scale: scale,
1747
1747
  scaling: scaling,
1748
1748
  setAxis: setAxis,
1749
- setDefaultType: setDefaultType$1,
1749
+ setDefaultType: setDefaultType,
1750
1750
  setTranslation: setTranslation,
1751
1751
  transformDirection: transformDirection,
1752
- transformNormal: transformNormal,
1752
+ transformNormal: transformNormal$1,
1753
1753
  transformPoint: transformPoint,
1754
1754
  translate: translate,
1755
1755
  translation: translation,
@@ -1779,42 +1779,42 @@ var m4 = /*#__PURE__*/Object.freeze({
1779
1779
  */
1780
1780
 
1781
1781
  /* DataType */
1782
- const BYTE = 0x1400;
1783
- const UNSIGNED_BYTE = 0x1401;
1784
- const SHORT = 0x1402;
1785
- const UNSIGNED_SHORT = 0x1403;
1786
- const INT = 0x1404;
1787
- const UNSIGNED_INT = 0x1405;
1788
- const FLOAT = 0x1406;
1789
- const UNSIGNED_SHORT_4_4_4_4 = 0x8033;
1790
- const UNSIGNED_SHORT_5_5_5_1 = 0x8034;
1791
- const UNSIGNED_SHORT_5_6_5 = 0x8363;
1792
- const HALF_FLOAT = 0x140B;
1793
- const UNSIGNED_INT_2_10_10_10_REV = 0x8368;
1794
- const UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
1795
- const UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
1796
- const FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
1797
- const UNSIGNED_INT_24_8 = 0x84FA;
1782
+ const BYTE$2 = 0x1400;
1783
+ const UNSIGNED_BYTE$3 = 0x1401;
1784
+ const SHORT$2 = 0x1402;
1785
+ const UNSIGNED_SHORT$3 = 0x1403;
1786
+ const INT$3 = 0x1404;
1787
+ const UNSIGNED_INT$3 = 0x1405;
1788
+ const FLOAT$3 = 0x1406;
1789
+ const UNSIGNED_SHORT_4_4_4_4$1 = 0x8033;
1790
+ const UNSIGNED_SHORT_5_5_5_1$1 = 0x8034;
1791
+ const UNSIGNED_SHORT_5_6_5$1 = 0x8363;
1792
+ const HALF_FLOAT$1 = 0x140B;
1793
+ const UNSIGNED_INT_2_10_10_10_REV$1 = 0x8368;
1794
+ const UNSIGNED_INT_10F_11F_11F_REV$1 = 0x8C3B;
1795
+ const UNSIGNED_INT_5_9_9_9_REV$1 = 0x8C3E;
1796
+ const FLOAT_32_UNSIGNED_INT_24_8_REV$1 = 0x8DAD;
1797
+ const UNSIGNED_INT_24_8$1 = 0x84FA;
1798
1798
 
1799
1799
  const glTypeToTypedArray = {};
1800
1800
  {
1801
1801
  const tt = glTypeToTypedArray;
1802
- tt[BYTE] = Int8Array;
1803
- tt[UNSIGNED_BYTE] = Uint8Array;
1804
- tt[SHORT] = Int16Array;
1805
- tt[UNSIGNED_SHORT] = Uint16Array;
1806
- tt[INT] = Int32Array;
1807
- tt[UNSIGNED_INT] = Uint32Array;
1808
- tt[FLOAT] = Float32Array;
1809
- tt[UNSIGNED_SHORT_4_4_4_4] = Uint16Array;
1810
- tt[UNSIGNED_SHORT_5_5_5_1] = Uint16Array;
1811
- tt[UNSIGNED_SHORT_5_6_5] = Uint16Array;
1812
- tt[HALF_FLOAT] = Uint16Array;
1813
- tt[UNSIGNED_INT_2_10_10_10_REV] = Uint32Array;
1814
- tt[UNSIGNED_INT_10F_11F_11F_REV] = Uint32Array;
1815
- tt[UNSIGNED_INT_5_9_9_9_REV] = Uint32Array;
1816
- tt[FLOAT_32_UNSIGNED_INT_24_8_REV] = Uint32Array;
1817
- tt[UNSIGNED_INT_24_8] = Uint32Array;
1802
+ tt[BYTE$2] = Int8Array;
1803
+ tt[UNSIGNED_BYTE$3] = Uint8Array;
1804
+ tt[SHORT$2] = Int16Array;
1805
+ tt[UNSIGNED_SHORT$3] = Uint16Array;
1806
+ tt[INT$3] = Int32Array;
1807
+ tt[UNSIGNED_INT$3] = Uint32Array;
1808
+ tt[FLOAT$3] = Float32Array;
1809
+ tt[UNSIGNED_SHORT_4_4_4_4$1] = Uint16Array;
1810
+ tt[UNSIGNED_SHORT_5_5_5_1$1] = Uint16Array;
1811
+ tt[UNSIGNED_SHORT_5_6_5$1] = Uint16Array;
1812
+ tt[HALF_FLOAT$1] = Uint16Array;
1813
+ tt[UNSIGNED_INT_2_10_10_10_REV$1] = Uint32Array;
1814
+ tt[UNSIGNED_INT_10F_11F_11F_REV$1] = Uint32Array;
1815
+ tt[UNSIGNED_INT_5_9_9_9_REV$1] = Uint32Array;
1816
+ tt[FLOAT_32_UNSIGNED_INT_24_8_REV$1] = Uint32Array;
1817
+ tt[UNSIGNED_INT_24_8$1] = Uint32Array;
1818
1818
  }
1819
1819
 
1820
1820
  /**
@@ -1825,14 +1825,14 @@ const glTypeToTypedArray = {};
1825
1825
  * @memberOf module:twgl/typedArray
1826
1826
  */
1827
1827
  function getGLTypeForTypedArray(typedArray) {
1828
- if (typedArray instanceof Int8Array) { return BYTE; } // eslint-disable-line
1829
- if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
1830
- if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
1831
- if (typedArray instanceof Int16Array) { return SHORT; } // eslint-disable-line
1832
- if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
1833
- if (typedArray instanceof Int32Array) { return INT; } // eslint-disable-line
1834
- if (typedArray instanceof Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
1835
- if (typedArray instanceof Float32Array) { return FLOAT; } // eslint-disable-line
1828
+ if (typedArray instanceof Int8Array) { return BYTE$2; } // eslint-disable-line
1829
+ if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE$3; } // eslint-disable-line
1830
+ if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE$3; } // eslint-disable-line
1831
+ if (typedArray instanceof Int16Array) { return SHORT$2; } // eslint-disable-line
1832
+ if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT$3; } // eslint-disable-line
1833
+ if (typedArray instanceof Int32Array) { return INT$3; } // eslint-disable-line
1834
+ if (typedArray instanceof Uint32Array) { return UNSIGNED_INT$3; } // eslint-disable-line
1835
+ if (typedArray instanceof Float32Array) { return FLOAT$3; } // eslint-disable-line
1836
1836
  throw new Error('unsupported typed array type');
1837
1837
  }
1838
1838
 
@@ -1844,14 +1844,14 @@ function getGLTypeForTypedArray(typedArray) {
1844
1844
  * @memberOf module:twgl/typedArray
1845
1845
  */
1846
1846
  function getGLTypeForTypedArrayType(typedArrayType) {
1847
- if (typedArrayType === Int8Array) { return BYTE; } // eslint-disable-line
1848
- if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
1849
- if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
1850
- if (typedArrayType === Int16Array) { return SHORT; } // eslint-disable-line
1851
- if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
1852
- if (typedArrayType === Int32Array) { return INT; } // eslint-disable-line
1853
- if (typedArrayType === Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
1854
- if (typedArrayType === Float32Array) { return FLOAT; } // eslint-disable-line
1847
+ if (typedArrayType === Int8Array) { return BYTE$2; } // eslint-disable-line
1848
+ if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE$3; } // eslint-disable-line
1849
+ if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE$3; } // eslint-disable-line
1850
+ if (typedArrayType === Int16Array) { return SHORT$2; } // eslint-disable-line
1851
+ if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT$3; } // eslint-disable-line
1852
+ if (typedArrayType === Int32Array) { return INT$3; } // eslint-disable-line
1853
+ if (typedArrayType === Uint32Array) { return UNSIGNED_INT$3; } // eslint-disable-line
1854
+ if (typedArrayType === Float32Array) { return FLOAT$3; } // eslint-disable-line
1855
1855
  throw new Error('unsupported typed array type');
1856
1856
  }
1857
1857
 
@@ -1869,7 +1869,7 @@ function getTypedArrayTypeForGLType(type) {
1869
1869
  return CTOR;
1870
1870
  }
1871
1871
 
1872
- const isArrayBuffer = typeof SharedArrayBuffer !== 'undefined'
1872
+ const isArrayBuffer$1 = typeof SharedArrayBuffer !== 'undefined'
1873
1873
  ? function isArrayBufferOrSharedArrayBuffer(a) {
1874
1874
  return a && a.buffer && (a.buffer instanceof ArrayBuffer || a.buffer instanceof SharedArrayBuffer);
1875
1875
  }
@@ -1882,7 +1882,7 @@ var typedarrays = /*#__PURE__*/Object.freeze({
1882
1882
  getGLTypeForTypedArray: getGLTypeForTypedArray,
1883
1883
  getGLTypeForTypedArrayType: getGLTypeForTypedArrayType,
1884
1884
  getTypedArrayTypeForGLType: getTypedArrayTypeForGLType,
1885
- isArrayBuffer: isArrayBuffer
1885
+ isArrayBuffer: isArrayBuffer$1
1886
1886
  });
1887
1887
 
1888
1888
  /*
@@ -1941,11 +1941,11 @@ function copyExistingProperties(src, dst) {
1941
1941
  });
1942
1942
  }
1943
1943
 
1944
- function error(...args) {
1944
+ function error$1(...args) {
1945
1945
  console.error(...args);
1946
1946
  }
1947
1947
 
1948
- function warn(...args) {
1948
+ function warn$1(...args) {
1949
1949
  console.warn(...args);
1950
1950
  }
1951
1951
 
@@ -1977,10 +1977,6 @@ function isRenderbuffer(gl, t) {
1977
1977
  return typeof WebGLRenderbuffer !== 'undefined' && isType(t, 'WebGLRenderbuffer');
1978
1978
  }
1979
1979
 
1980
- function isShader(gl, t) {
1981
- return typeof WebGLShader !== 'undefined' && isType(t, 'WebGLShader');
1982
- }
1983
-
1984
1980
  function isTexture(gl, t) {
1985
1981
  return typeof WebGLTexture !== 'undefined' && isType(t, 'WebGLTexture');
1986
1982
  }
@@ -2012,18 +2008,18 @@ function isSampler(gl, t) {
2012
2008
  */
2013
2009
 
2014
2010
  const STATIC_DRAW = 0x88e4;
2015
- const ARRAY_BUFFER = 0x8892;
2016
- const ELEMENT_ARRAY_BUFFER = 0x8893;
2011
+ const ARRAY_BUFFER$1 = 0x8892;
2012
+ const ELEMENT_ARRAY_BUFFER$2 = 0x8893;
2017
2013
  const BUFFER_SIZE = 0x8764;
2018
2014
 
2019
2015
  const BYTE$1 = 0x1400;
2020
- const UNSIGNED_BYTE$1 = 0x1401;
2016
+ const UNSIGNED_BYTE$2 = 0x1401;
2021
2017
  const SHORT$1 = 0x1402;
2022
- const UNSIGNED_SHORT$1 = 0x1403;
2023
- const INT$1 = 0x1404;
2024
- const UNSIGNED_INT$1 = 0x1405;
2025
- const FLOAT$1 = 0x1406;
2026
- const defaults = {
2018
+ const UNSIGNED_SHORT$2 = 0x1403;
2019
+ const INT$2 = 0x1404;
2020
+ const UNSIGNED_INT$2 = 0x1405;
2021
+ const FLOAT$2 = 0x1406;
2022
+ const defaults$2 = {
2027
2023
  attribPrefix: "",
2028
2024
  };
2029
2025
 
@@ -2048,11 +2044,11 @@ const defaults = {
2048
2044
  * @memberOf module:twgl/attributes
2049
2045
  */
2050
2046
  function setAttributePrefix(prefix) {
2051
- defaults.attribPrefix = prefix;
2047
+ defaults$2.attribPrefix = prefix;
2052
2048
  }
2053
2049
 
2054
- function setDefaults(newDefaults) {
2055
- copyExistingProperties(newDefaults, defaults);
2050
+ function setDefaults$2(newDefaults) {
2051
+ copyExistingProperties(newDefaults, defaults$2);
2056
2052
  }
2057
2053
 
2058
2054
  function setBufferFromTypedArray(gl, type, buffer, array, drawType) {
@@ -2075,7 +2071,7 @@ function createBufferFromTypedArray(gl, typedArray, type, drawType) {
2075
2071
  if (isBuffer(gl, typedArray)) {
2076
2072
  return typedArray;
2077
2073
  }
2078
- type = type || ARRAY_BUFFER;
2074
+ type = type || ARRAY_BUFFER$1;
2079
2075
  const buffer = gl.createBuffer();
2080
2076
  setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
2081
2077
  return buffer;
@@ -2085,14 +2081,6 @@ function isIndices(name) {
2085
2081
  return name === "indices";
2086
2082
  }
2087
2083
 
2088
- // This is really just a guess. Though I can't really imagine using
2089
- // anything else? Maybe for some compression?
2090
- function getNormalizationForTypedArray(typedArray) {
2091
- if (typedArray instanceof Int8Array) { return true; } // eslint-disable-line
2092
- if (typedArray instanceof Uint8Array) { return true; } // eslint-disable-line
2093
- return false;
2094
- }
2095
-
2096
2084
  // This is really just a guess. Though I can't really imagine using
2097
2085
  // anything else? Maybe for some compression?
2098
2086
  function getNormalizationForTypedArrayType(typedArrayType) {
@@ -2101,7 +2089,7 @@ function getNormalizationForTypedArrayType(typedArrayType) {
2101
2089
  return false;
2102
2090
  }
2103
2091
 
2104
- function getArray(array) {
2092
+ function getArray$1(array) {
2105
2093
  return array.length ? array : array.data;
2106
2094
  }
2107
2095
 
@@ -2125,16 +2113,16 @@ function guessNumComponentsFromName(name, length) {
2125
2113
  return numComponents;
2126
2114
  }
2127
2115
 
2128
- function getNumComponents(array, arrayName) {
2129
- return array.numComponents || array.size || guessNumComponentsFromName(arrayName, getArray(array).length);
2116
+ function getNumComponents$1(array, arrayName, numValues) {
2117
+ return array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues || getArray$1(array).length);
2130
2118
  }
2131
2119
 
2132
2120
  function makeTypedArray(array, name) {
2133
- if (isArrayBuffer(array)) {
2121
+ if (isArrayBuffer$1(array)) {
2134
2122
  return array;
2135
2123
  }
2136
2124
 
2137
- if (isArrayBuffer(array.data)) {
2125
+ if (isArrayBuffer$1(array.data)) {
2138
2126
  return array.data;
2139
2127
  }
2140
2128
 
@@ -2144,7 +2132,7 @@ function makeTypedArray(array, name) {
2144
2132
  };
2145
2133
  }
2146
2134
 
2147
- let Type = array.type;
2135
+ let Type = array.type ? typedArrayTypeFromGLTypeOrTypedArrayCtor(array.type) : undefined;
2148
2136
  if (!Type) {
2149
2137
  if (isIndices(name)) {
2150
2138
  Type = Uint16Array;
@@ -2155,6 +2143,52 @@ function makeTypedArray(array, name) {
2155
2143
  return new Type(array.data);
2156
2144
  }
2157
2145
 
2146
+ function glTypeFromGLTypeOrTypedArrayType(glTypeOrTypedArrayCtor) {
2147
+ return typeof glTypeOrTypedArrayCtor === 'number'
2148
+ ? glTypeOrTypedArrayCtor
2149
+ : glTypeOrTypedArrayCtor ? getGLTypeForTypedArrayType(glTypeOrTypedArrayCtor) : FLOAT$2;
2150
+ }
2151
+
2152
+ function typedArrayTypeFromGLTypeOrTypedArrayCtor(glTypeOrTypedArrayCtor) {
2153
+ return typeof glTypeOrTypedArrayCtor === 'number'
2154
+ ? getTypedArrayTypeForGLType(glTypeOrTypedArrayCtor)
2155
+ : glTypeOrTypedArrayCtor || Float32Array;
2156
+ }
2157
+
2158
+ function attribBufferFromBuffer(gl, array/*, arrayName */) {
2159
+ return {
2160
+ buffer: array.buffer,
2161
+ numValues: 2 * 3 * 4, // safely divided by 2, 3, 4
2162
+ type: glTypeFromGLTypeOrTypedArrayType(array.type),
2163
+ arrayType: typedArrayTypeFromGLTypeOrTypedArrayCtor(array.type),
2164
+ };
2165
+ }
2166
+
2167
+ function attribBufferFromSize(gl, array/*, arrayName*/) {
2168
+ const numValues = array.data || array;
2169
+ const arrayType = typedArrayTypeFromGLTypeOrTypedArrayCtor(array.type);
2170
+ const numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
2171
+ const buffer = gl.createBuffer();
2172
+ gl.bindBuffer(ARRAY_BUFFER$1, buffer);
2173
+ gl.bufferData(ARRAY_BUFFER$1, numBytes, array.drawType || STATIC_DRAW);
2174
+ return {
2175
+ buffer,
2176
+ numValues,
2177
+ type: getGLTypeForTypedArrayType(arrayType),
2178
+ arrayType,
2179
+ };
2180
+ }
2181
+
2182
+ function attribBufferFromArrayLike(gl, array, arrayName) {
2183
+ const typedArray = makeTypedArray(array, arrayName);
2184
+ return {
2185
+ arrayType: typedArray.constructor,
2186
+ buffer: createBufferFromTypedArray(gl, typedArray, undefined, array.drawType),
2187
+ type: getGLTypeForTypedArray(typedArray),
2188
+ numValues: 0,
2189
+ };
2190
+ }
2191
+
2158
2192
  /**
2159
2193
  * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer
2160
2194
  * for the attribute.
@@ -2170,24 +2204,29 @@ function makeTypedArray(array, name) {
2170
2204
  * @property {number} [stride] the stride in bytes per element. Default = 0
2171
2205
  * @property {number} [divisor] the divisor in instances. Default = 0.
2172
2206
  * Requires WebGL2 or the ANGLE_instanced_arrays extension.
2173
- * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
2207
+ * and, if you're using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
2174
2208
  * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
2175
2209
  * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
2176
2210
  * @memberOf module:twgl
2177
2211
  */
2178
2212
 
2213
+ /**
2214
+ * @typedef {(Int8ArrayConstructor|Uint8ArrayConstructor|Int16ArrayConstructor|Uint16ArrayConstructor|Int32ArrayConstructor|Uint32ArrayConstructor|Float32ArrayConstructor)} TypedArrayConstructor
2215
+ */
2216
+
2179
2217
  /**
2180
2218
  * Use this type of array spec when TWGL can't guess the type or number of components of an array
2181
2219
  * @typedef {Object} FullArraySpec
2182
2220
  * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
2183
2221
  * disabled and set to this constant value and all other values will be ignored.
2184
- * @property {(number|number[]|ArrayBufferView)} data The data of the array. A number alone becomes the number of elements of type.
2222
+ * @property {(number|number[]|ArrayBufferView)} [data] The data of the array. A number alone becomes the number of elements of type.
2185
2223
  * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.
2186
2224
  * If `coord` is in the name assumes `numComponents = 2`.
2187
2225
  * If `color` is in the name assumes `numComponents = 4`.
2188
2226
  * otherwise assumes `numComponents = 3`
2189
- * @property {constructor} [type] type. This is only used if `data` is a JavaScript array. It is the constructor for the typedarray. (eg. `Uint8Array`).
2190
- * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: Uint8Array, data: [255,0,255,255, ...], }`.
2227
+ * @property {number|TypedArrayConstructor} [type] type. This is used if `data` is a JavaScript array, or `buffer` is passed in, or `data` is a number.
2228
+ * It can either be the constructor for a typedarray. (eg. `Uint8Array`) OR a WebGL type, (eg `gl.UNSIGNED_BYTE`).
2229
+ * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: gl.UNSIGNED_BYTE, data: [255,0,255,255, ...], }`.
2191
2230
  * @property {number} [size] synonym for `numComponents`.
2192
2231
  * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
2193
2232
  * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
@@ -2328,41 +2367,26 @@ function createAttribsFromArrays(gl, arrays) {
2328
2367
  Object.keys(arrays).forEach(function(arrayName) {
2329
2368
  if (!isIndices(arrayName)) {
2330
2369
  const array = arrays[arrayName];
2331
- const attribName = array.attrib || array.name || array.attribName || (defaults.attribPrefix + arrayName);
2370
+ const attribName = array.attrib || array.name || array.attribName || (defaults$2.attribPrefix + arrayName);
2332
2371
  if (array.value) {
2333
- if (!Array.isArray(array.value) && !isArrayBuffer(array.value)) {
2372
+ if (!Array.isArray(array.value) && !isArrayBuffer$1(array.value)) {
2334
2373
  throw new Error('array.value is not array or typedarray');
2335
2374
  }
2336
2375
  attribs[attribName] = {
2337
2376
  value: array.value,
2338
2377
  };
2339
2378
  } else {
2340
- let buffer;
2341
- let type;
2342
- let normalization;
2343
- let numComponents;
2379
+ let fn;
2344
2380
  if (array.buffer && array.buffer instanceof WebGLBuffer) {
2345
- buffer = array.buffer;
2346
- numComponents = array.numComponents || array.size;
2347
- type = array.type;
2348
- normalization = array.normalize;
2381
+ fn = attribBufferFromBuffer;
2349
2382
  } else if (typeof array === "number" || typeof array.data === "number") {
2350
- const numValues = array.data || array;
2351
- const arrayType = array.type || Float32Array;
2352
- const numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
2353
- type = getGLTypeForTypedArrayType(arrayType);
2354
- normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
2355
- numComponents = array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues);
2356
- buffer = gl.createBuffer();
2357
- gl.bindBuffer(ARRAY_BUFFER, buffer);
2358
- gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);
2383
+ fn = attribBufferFromSize;
2359
2384
  } else {
2360
- const typedArray = makeTypedArray(array, arrayName);
2361
- buffer = createBufferFromTypedArray(gl, typedArray, undefined, array.drawType);
2362
- type = getGLTypeForTypedArray(typedArray);
2363
- normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArray(typedArray);
2364
- numComponents = getNumComponents(array, arrayName);
2385
+ fn = attribBufferFromArrayLike;
2365
2386
  }
2387
+ const {buffer, type, numValues, arrayType} = fn(gl, array, arrayName);
2388
+ const normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
2389
+ const numComponents = getNumComponents$1(array, arrayName, numValues);
2366
2390
  attribs[attribName] = {
2367
2391
  buffer: buffer,
2368
2392
  numComponents: numComponents,
@@ -2376,7 +2400,7 @@ function createAttribsFromArrays(gl, arrays) {
2376
2400
  }
2377
2401
  }
2378
2402
  });
2379
- gl.bindBuffer(ARRAY_BUFFER, null);
2403
+ gl.bindBuffer(ARRAY_BUFFER$1, null);
2380
2404
  return attribs;
2381
2405
  }
2382
2406
 
@@ -2419,21 +2443,21 @@ function createAttribsFromArrays(gl, arrays) {
2419
2443
  function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
2420
2444
  array = makeTypedArray(array);
2421
2445
  if (offset !== undefined) {
2422
- gl.bindBuffer(ARRAY_BUFFER, attribInfo.buffer);
2423
- gl.bufferSubData(ARRAY_BUFFER, offset, array);
2446
+ gl.bindBuffer(ARRAY_BUFFER$1, attribInfo.buffer);
2447
+ gl.bufferSubData(ARRAY_BUFFER$1, offset, array);
2424
2448
  } else {
2425
- setBufferFromTypedArray(gl, ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
2449
+ setBufferFromTypedArray(gl, ARRAY_BUFFER$1, attribInfo.buffer, array, attribInfo.drawType);
2426
2450
  }
2427
2451
  }
2428
2452
 
2429
2453
  function getBytesPerValueForGLType(gl, type) {
2430
2454
  if (type === BYTE$1) return 1; // eslint-disable-line
2431
- if (type === UNSIGNED_BYTE$1) return 1; // eslint-disable-line
2455
+ if (type === UNSIGNED_BYTE$2) return 1; // eslint-disable-line
2432
2456
  if (type === SHORT$1) return 2; // eslint-disable-line
2433
- if (type === UNSIGNED_SHORT$1) return 2; // eslint-disable-line
2434
- if (type === INT$1) return 4; // eslint-disable-line
2435
- if (type === UNSIGNED_INT$1) return 4; // eslint-disable-line
2436
- if (type === FLOAT$1) return 4; // eslint-disable-line
2457
+ if (type === UNSIGNED_SHORT$2) return 2; // eslint-disable-line
2458
+ if (type === INT$2) return 4; // eslint-disable-line
2459
+ if (type === UNSIGNED_INT$2) return 4; // eslint-disable-line
2460
+ if (type === FLOAT$2) return 4; // eslint-disable-line
2437
2461
  return 0;
2438
2462
  }
2439
2463
 
@@ -2452,11 +2476,11 @@ function getNumElementsFromNonIndexedArrays(arrays) {
2452
2476
  key = Object.keys(arrays)[0];
2453
2477
  }
2454
2478
  const array = arrays[key];
2455
- const length = getArray(array).length;
2479
+ const length = getArray$1(array).length;
2456
2480
  if (length === undefined) {
2457
2481
  return 1; // There's no arrays
2458
2482
  }
2459
- const numComponents = getNumComponents(array, key);
2483
+ const numComponents = getNumComponents$1(array, key);
2460
2484
  const numElements = length / numComponents;
2461
2485
  if (length % numComponents > 0) {
2462
2486
  throw new Error(`numComponents ${numComponents} not correct for length ${length}`);
@@ -2472,7 +2496,7 @@ function getNumElementsFromAttributes(gl, attribs) {
2472
2496
  if (key in attribs) {
2473
2497
  break;
2474
2498
  }
2475
- key = defaults.attribPrefix + key;
2499
+ key = defaults$2.attribPrefix + key;
2476
2500
  if (key in attribs) {
2477
2501
  break;
2478
2502
  }
@@ -2484,9 +2508,9 @@ function getNumElementsFromAttributes(gl, attribs) {
2484
2508
  if (!attrib.buffer) {
2485
2509
  return 1; // There's no buffer
2486
2510
  }
2487
- gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
2488
- const numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
2489
- gl.bindBuffer(ARRAY_BUFFER, null);
2511
+ gl.bindBuffer(ARRAY_BUFFER$1, attrib.buffer);
2512
+ const numBytes = gl.getBufferParameter(ARRAY_BUFFER$1, BUFFER_SIZE);
2513
+ gl.bindBuffer(ARRAY_BUFFER$1, null);
2490
2514
 
2491
2515
  const bytesPerValue = getBytesPerValueForGLType(gl, attrib.type);
2492
2516
  const totalElements = numBytes / bytesPerValue;
@@ -2611,7 +2635,7 @@ function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
2611
2635
  const indices = arrays.indices;
2612
2636
  if (indices) {
2613
2637
  const newIndices = makeTypedArray(indices, "indices");
2614
- bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER);
2638
+ bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER$2);
2615
2639
  bufferInfo.numElements = newIndices.length;
2616
2640
  bufferInfo.elementType = getGLTypeForTypedArray(newIndices);
2617
2641
  } else if (!bufferInfo.numElements) {
@@ -2648,7 +2672,7 @@ function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
2648
2672
  * @memberOf module:twgl/attributes
2649
2673
  */
2650
2674
  function createBufferFromArray(gl, array, arrayName) {
2651
- const type = arrayName === "indices" ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER;
2675
+ const type = arrayName === "indices" ? ELEMENT_ARRAY_BUFFER$2 : ARRAY_BUFFER$1;
2652
2676
  const typedArray = makeTypedArray(array, arrayName);
2653
2677
  return createBufferFromTypedArray(gl, typedArray, type);
2654
2678
  }
@@ -2703,9 +2727,9 @@ var attributes = /*#__PURE__*/Object.freeze({
2703
2727
  createBufferInfoFromArrays: createBufferInfoFromArrays,
2704
2728
  setAttribInfoBufferFromArray: setAttribInfoBufferFromArray,
2705
2729
  setAttributePrefix: setAttributePrefix,
2706
- setAttributeDefaults_: setDefaults,
2707
- getNumComponents_: getNumComponents,
2708
- getArray_: getArray
2730
+ setAttributeDefaults_: setDefaults$2,
2731
+ getNumComponents_: getNumComponents$1,
2732
+ getArray_: getArray$1
2709
2733
  });
2710
2734
 
2711
2735
  /*
@@ -2730,8 +2754,8 @@ var attributes = /*#__PURE__*/Object.freeze({
2730
2754
  * DEALINGS IN THE SOFTWARE.
2731
2755
  */
2732
2756
 
2733
- const getArray$1 = getArray; // eslint-disable-line
2734
- const getNumComponents$1 = getNumComponents; // eslint-disable-line
2757
+ const getArray = getArray$1; // eslint-disable-line
2758
+ const getNumComponents = getNumComponents$1; // eslint-disable-line
2735
2759
 
2736
2760
  /**
2737
2761
  * @typedef {(Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array)} TypedArray
@@ -2750,7 +2774,7 @@ function augmentTypedArray(typedArray, numComponents) {
2750
2774
  typedArray.push = function() {
2751
2775
  for (let ii = 0; ii < arguments.length; ++ii) {
2752
2776
  const value = arguments[ii];
2753
- if (value instanceof Array || isArrayBuffer(value)) {
2777
+ if (value instanceof Array || isArrayBuffer$1(value)) {
2754
2778
  for (let jj = 0; jj < value.length; ++jj) {
2755
2779
  typedArray[cursor++] = value[jj];
2756
2780
  }
@@ -2899,8 +2923,8 @@ function applyFuncToV3Array(array, matrix, fn) {
2899
2923
  }
2900
2924
  }
2901
2925
 
2902
- function transformNormal$1(mi, v, dst) {
2903
- dst = dst || create();
2926
+ function transformNormal(mi, v, dst) {
2927
+ dst = dst || create$1();
2904
2928
  const v0 = v[0];
2905
2929
  const v1 = v[1];
2906
2930
  const v2 = v[2];
@@ -2933,7 +2957,7 @@ function reorientDirections(array, matrix) {
2933
2957
  * @memberOf module:twgl/primitives
2934
2958
  */
2935
2959
  function reorientNormals(array, matrix) {
2936
- applyFuncToV3Array(array, inverse(matrix), transformNormal$1);
2960
+ applyFuncToV3Array(array, inverse(matrix), transformNormal);
2937
2961
  return array;
2938
2962
  }
2939
2963
 
@@ -4134,7 +4158,7 @@ function create3DFVertices() {
4134
4158
  const py = c * verticalRadius;
4135
4159
  const pz = s * radius;
4136
4160
  positions.push(px, py, pz);
4137
- const n = add(multiply([0, s, c], normalMult), normalAdd);
4161
+ const n = add(multiply$1([0, s, c], normalMult), normalAdd);
4138
4162
  normals.push(n);
4139
4163
  texcoords.push(uBack * uMult + uAdd, v);
4140
4164
  }
@@ -4632,7 +4656,7 @@ function copyElements(src, dst, dstNdx, offset) {
4632
4656
  * @private
4633
4657
  */
4634
4658
  function createArrayOfSameType(srcArray, length) {
4635
- const arraySrc = getArray$1(srcArray);
4659
+ const arraySrc = getArray(srcArray);
4636
4660
  const newArray = new arraySrc.constructor(length);
4637
4661
  let newArraySpec = newArray;
4638
4662
  // If it appears to have been augmented make new one augmented
@@ -4689,8 +4713,8 @@ function concatVertices(arrayOfArrays) {
4689
4713
  baseName = name;
4690
4714
  }
4691
4715
  const arrayInfo = arrays[name];
4692
- const numComponents = getNumComponents$1(arrayInfo, name);
4693
- const array = getArray$1(arrayInfo);
4716
+ const numComponents = getNumComponents(arrayInfo, name);
4717
+ const array = getArray(arrayInfo);
4694
4718
  const numElements = array.length / numComponents;
4695
4719
  names[name].push(numElements);
4696
4720
  });
@@ -4704,7 +4728,7 @@ function concatVertices(arrayOfArrays) {
4704
4728
  for (let ii = 0; ii < arrayOfArrays.length; ++ii) {
4705
4729
  const arrays = arrayOfArrays[ii];
4706
4730
  const arrayInfo = arrays[name];
4707
- const array = getArray$1(arrayInfo);
4731
+ const array = getArray(arrayInfo);
4708
4732
  length += array.length;
4709
4733
  if (!arraySpec || arrayInfo.data) {
4710
4734
  arraySpec = arrayInfo;
@@ -4722,7 +4746,7 @@ function concatVertices(arrayOfArrays) {
4722
4746
  for (let ii = 0; ii < arrayOfArrays.length; ++ii) {
4723
4747
  const arrays = arrayOfArrays[ii];
4724
4748
  const arrayInfo = arrays[name];
4725
- const array = getArray$1(arrayInfo);
4749
+ const array = getArray(arrayInfo);
4726
4750
  if (name === 'indices') {
4727
4751
  copyElements(array, newArray, offset, baseIndex);
4728
4752
  baseIndex += base[ii];
@@ -4739,7 +4763,7 @@ function concatVertices(arrayOfArrays) {
4739
4763
  Object.keys(names).forEach(function(name) {
4740
4764
  const info = getLengthOfCombinedArrays(name);
4741
4765
  const newArraySpec = createArrayOfSameType(info.spec, info.length);
4742
- copyArraysToNewArray(name, base, getArray$1(newArraySpec));
4766
+ copyArraysToNewArray(name, base, getArray(newArraySpec));
4743
4767
  newArrays[name] = newArraySpec;
4744
4768
  });
4745
4769
  return newArrays;
@@ -4759,9 +4783,9 @@ function duplicateVertices(arrays) {
4759
4783
  const newArrays = {};
4760
4784
  Object.keys(arrays).forEach(function(name) {
4761
4785
  const arraySpec = arrays[name];
4762
- const srcArray = getArray$1(arraySpec);
4786
+ const srcArray = getArray(arraySpec);
4763
4787
  const newArraySpec = createArrayOfSameType(arraySpec, srcArray.length);
4764
- copyElements(srcArray, getArray$1(newArraySpec), 0);
4788
+ copyElements(srcArray, getArray(newArraySpec), 0);
4765
4789
  newArrays[name] = newArraySpec;
4766
4790
  });
4767
4791
  return newArrays;
@@ -5005,7 +5029,7 @@ const defaults$1 = {
5005
5029
  textureOptions: {},
5006
5030
  crossOrigin: undefined,
5007
5031
  };
5008
- const isArrayBuffer$1 = isArrayBuffer;
5032
+ const isArrayBuffer = isArrayBuffer$1;
5009
5033
 
5010
5034
  // Should we make this on demand?
5011
5035
  const getShared2DContext = function() {
@@ -5034,20 +5058,20 @@ const getShared2DContext = function() {
5034
5058
  /* PixelFormat */
5035
5059
  const ALPHA = 0x1906;
5036
5060
  const RGB = 0x1907;
5037
- const RGBA = 0x1908;
5061
+ const RGBA$1 = 0x1908;
5038
5062
  const LUMINANCE = 0x1909;
5039
5063
  const LUMINANCE_ALPHA = 0x190A;
5040
- const DEPTH_COMPONENT = 0x1902;
5041
- const DEPTH_STENCIL = 0x84F9;
5064
+ const DEPTH_COMPONENT$1 = 0x1902;
5065
+ const DEPTH_STENCIL$1 = 0x84F9;
5042
5066
 
5043
5067
  /* TextureWrapMode */
5044
5068
  // const REPEAT = 0x2901;
5045
5069
  // const MIRRORED_REPEAT = 0x8370;
5046
- const CLAMP_TO_EDGE = 0x812f;
5070
+ const CLAMP_TO_EDGE$1 = 0x812f;
5047
5071
 
5048
5072
  /* TextureMagFilter */
5049
5073
  const NEAREST = 0x2600;
5050
- const LINEAR = 0x2601;
5074
+ const LINEAR$1 = 0x2601;
5051
5075
 
5052
5076
  /* TextureMinFilter */
5053
5077
  // const NEAREST_MIPMAP_NEAREST = 0x2700;
@@ -5056,10 +5080,10 @@ const LINEAR = 0x2601;
5056
5080
  // const LINEAR_MIPMAP_LINEAR = 0x2703;
5057
5081
 
5058
5082
  /* Texture Target */
5059
- const TEXTURE_2D = 0x0de1;
5060
- const TEXTURE_CUBE_MAP = 0x8513;
5061
- const TEXTURE_3D = 0x806f;
5062
- const TEXTURE_2D_ARRAY = 0x8c1a;
5083
+ const TEXTURE_2D$2 = 0x0de1;
5084
+ const TEXTURE_CUBE_MAP$1 = 0x8513;
5085
+ const TEXTURE_3D$1 = 0x806f;
5086
+ const TEXTURE_2D_ARRAY$1 = 0x8c1a;
5063
5087
 
5064
5088
  /* Cubemap Targets */
5065
5089
  const TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
@@ -5114,7 +5138,7 @@ const R32UI = 0x8236;
5114
5138
  const R32I = 0x8235;
5115
5139
  const RGB8 = 0x8051;
5116
5140
  const SRGB8 = 0x8C41;
5117
- const RGB565 = 0x8D62;
5141
+ const RGB565$1 = 0x8D62;
5118
5142
  const RGB8_SNORM = 0x8F96;
5119
5143
  const R11F_G11F_B10F = 0x8C3A;
5120
5144
  const RGB9_E5 = 0x8C3D;
@@ -5129,8 +5153,8 @@ const RGB32I = 0x8D83;
5129
5153
  const RGBA8 = 0x8058;
5130
5154
  const SRGB8_ALPHA8 = 0x8C43;
5131
5155
  const RGBA8_SNORM = 0x8F97;
5132
- const RGB5_A1 = 0x8057;
5133
- const RGBA4 = 0x8056;
5156
+ const RGB5_A1$1 = 0x8057;
5157
+ const RGBA4$1 = 0x8056;
5134
5158
  const RGB10_A2 = 0x8059;
5135
5159
  const RGBA16F = 0x881A;
5136
5160
  const RGBA32F = 0x8814;
@@ -5142,30 +5166,30 @@ const RGBA16I = 0x8D88;
5142
5166
  const RGBA32I = 0x8D82;
5143
5167
  const RGBA32UI = 0x8D70;
5144
5168
 
5145
- const DEPTH_COMPONENT16 = 0x81A5;
5146
- const DEPTH_COMPONENT24 = 0x81A6;
5147
- const DEPTH_COMPONENT32F = 0x8CAC;
5148
- const DEPTH32F_STENCIL8 = 0x8CAD;
5149
- const DEPTH24_STENCIL8 = 0x88F0;
5169
+ const DEPTH_COMPONENT16$1 = 0x81A5;
5170
+ const DEPTH_COMPONENT24$1 = 0x81A6;
5171
+ const DEPTH_COMPONENT32F$1 = 0x8CAC;
5172
+ const DEPTH32F_STENCIL8$1 = 0x8CAD;
5173
+ const DEPTH24_STENCIL8$1 = 0x88F0;
5150
5174
 
5151
5175
  /* DataType */
5152
- const BYTE$2 = 0x1400;
5153
- const UNSIGNED_BYTE$2 = 0x1401;
5154
- const SHORT$2 = 0x1402;
5155
- const UNSIGNED_SHORT$2 = 0x1403;
5156
- const INT$2 = 0x1404;
5157
- const UNSIGNED_INT$2 = 0x1405;
5158
- const FLOAT$2 = 0x1406;
5159
- const UNSIGNED_SHORT_4_4_4_4$1 = 0x8033;
5160
- const UNSIGNED_SHORT_5_5_5_1$1 = 0x8034;
5161
- const UNSIGNED_SHORT_5_6_5$1 = 0x8363;
5162
- const HALF_FLOAT$1 = 0x140B;
5176
+ const BYTE = 0x1400;
5177
+ const UNSIGNED_BYTE$1 = 0x1401;
5178
+ const SHORT = 0x1402;
5179
+ const UNSIGNED_SHORT$1 = 0x1403;
5180
+ const INT$1 = 0x1404;
5181
+ const UNSIGNED_INT$1 = 0x1405;
5182
+ const FLOAT$1 = 0x1406;
5183
+ const UNSIGNED_SHORT_4_4_4_4 = 0x8033;
5184
+ const UNSIGNED_SHORT_5_5_5_1 = 0x8034;
5185
+ const UNSIGNED_SHORT_5_6_5 = 0x8363;
5186
+ const HALF_FLOAT = 0x140B;
5163
5187
  const HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
5164
- const UNSIGNED_INT_2_10_10_10_REV$1 = 0x8368;
5165
- const UNSIGNED_INT_10F_11F_11F_REV$1 = 0x8C3B;
5166
- const UNSIGNED_INT_5_9_9_9_REV$1 = 0x8C3E;
5167
- const FLOAT_32_UNSIGNED_INT_24_8_REV$1 = 0x8DAD;
5168
- const UNSIGNED_INT_24_8$1 = 0x84FA;
5188
+ const UNSIGNED_INT_2_10_10_10_REV = 0x8368;
5189
+ const UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
5190
+ const UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
5191
+ const FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD;
5192
+ const UNSIGNED_INT_24_8 = 0x84FA;
5169
5193
 
5170
5194
  const RG = 0x8227;
5171
5195
  const RG_INTEGER = 0x8228;
@@ -5183,17 +5207,17 @@ const formatInfo = {};
5183
5207
  f[LUMINANCE] = { numColorComponents: 1, };
5184
5208
  f[LUMINANCE_ALPHA] = { numColorComponents: 2, };
5185
5209
  f[RGB] = { numColorComponents: 3, };
5186
- f[RGBA] = { numColorComponents: 4, };
5210
+ f[RGBA$1] = { numColorComponents: 4, };
5187
5211
  f[RED] = { numColorComponents: 1, };
5188
5212
  f[RED_INTEGER] = { numColorComponents: 1, };
5189
5213
  f[RG] = { numColorComponents: 2, };
5190
5214
  f[RG_INTEGER] = { numColorComponents: 2, };
5191
5215
  f[RGB] = { numColorComponents: 3, };
5192
5216
  f[RGB_INTEGER] = { numColorComponents: 3, };
5193
- f[RGBA] = { numColorComponents: 4, };
5217
+ f[RGBA$1] = { numColorComponents: 4, };
5194
5218
  f[RGBA_INTEGER] = { numColorComponents: 4, };
5195
- f[DEPTH_COMPONENT] = { numColorComponents: 1, };
5196
- f[DEPTH_STENCIL] = { numColorComponents: 2, };
5219
+ f[DEPTH_COMPONENT$1] = { numColorComponents: 1, };
5220
+ f[DEPTH_STENCIL$1] = { numColorComponents: 2, };
5197
5221
  }
5198
5222
 
5199
5223
  /**
@@ -5212,69 +5236,69 @@ function getTextureInternalFormatInfo(internalFormat) {
5212
5236
  // NOTE: these properties need unique names so we can let Uglify mangle the name.
5213
5237
  const t = {};
5214
5238
  // unsized formats
5215
- t[ALPHA] = { textureFormat: ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2], };
5216
- t[LUMINANCE] = { textureFormat: LUMINANCE, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2], };
5217
- t[LUMINANCE_ALPHA] = { textureFormat: LUMINANCE_ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [2, 4, 4, 8], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2], };
5218
- t[RGB] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 6, 6, 12, 2], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2, UNSIGNED_SHORT_5_6_5$1], };
5219
- t[RGBA] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [UNSIGNED_BYTE$2, HALF_FLOAT$1, HALF_FLOAT_OES, FLOAT$2, UNSIGNED_SHORT_4_4_4_4$1, UNSIGNED_SHORT_5_5_5_1$1], };
5220
- t[DEPTH_COMPONENT] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [2, 4], type: [UNSIGNED_INT$2, UNSIGNED_SHORT$2], };
5239
+ t[ALPHA] = { textureFormat: ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$1, HALF_FLOAT, HALF_FLOAT_OES, FLOAT$1], };
5240
+ t[LUMINANCE] = { textureFormat: LUMINANCE, colorRenderable: true, textureFilterable: true, bytesPerElement: [1, 2, 2, 4], type: [UNSIGNED_BYTE$1, HALF_FLOAT, HALF_FLOAT_OES, FLOAT$1], };
5241
+ t[LUMINANCE_ALPHA] = { textureFormat: LUMINANCE_ALPHA, colorRenderable: true, textureFilterable: true, bytesPerElement: [2, 4, 4, 8], type: [UNSIGNED_BYTE$1, HALF_FLOAT, HALF_FLOAT_OES, FLOAT$1], };
5242
+ t[RGB] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 6, 6, 12, 2], type: [UNSIGNED_BYTE$1, HALF_FLOAT, HALF_FLOAT_OES, FLOAT$1, UNSIGNED_SHORT_5_6_5], };
5243
+ t[RGBA$1] = { textureFormat: RGBA$1, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [UNSIGNED_BYTE$1, HALF_FLOAT, HALF_FLOAT_OES, FLOAT$1, UNSIGNED_SHORT_4_4_4_4, UNSIGNED_SHORT_5_5_5_1], };
5244
+ t[DEPTH_COMPONENT$1] = { textureFormat: DEPTH_COMPONENT$1, colorRenderable: true, textureFilterable: false, bytesPerElement: [2, 4], type: [UNSIGNED_INT$1, UNSIGNED_SHORT$1], };
5221
5245
 
5222
5246
  // sized formats
5223
- t[R8] = { textureFormat: RED, colorRenderable: true, textureFilterable: true, bytesPerElement: [1], type: [UNSIGNED_BYTE$2], };
5224
- t[R8_SNORM] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [1], type: [BYTE$2], };
5225
- t[R16F] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [4, 2], type: [FLOAT$2, HALF_FLOAT$1], };
5226
- t[R32F] = { textureFormat: RED, colorRenderable: false, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$2], };
5227
- t[R8UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [UNSIGNED_BYTE$2], };
5228
- t[R8I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [BYTE$2], };
5229
- t[R16UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_SHORT$2], };
5230
- t[R16I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [SHORT$2], };
5231
- t[R32UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$2], };
5232
- t[R32I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [INT$2], };
5233
- t[RG8] = { textureFormat: RG, colorRenderable: true, textureFilterable: true, bytesPerElement: [2], type: [UNSIGNED_BYTE$2], };
5234
- t[RG8_SNORM] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [2], type: [BYTE$2], };
5235
- t[RG16F] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [8, 4], type: [FLOAT$2, HALF_FLOAT$1], };
5236
- t[RG32F] = { textureFormat: RG, colorRenderable: false, textureFilterable: false, bytesPerElement: [8], type: [FLOAT$2], };
5237
- t[RG8UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_BYTE$2], };
5238
- t[RG8I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [BYTE$2], };
5239
- t[RG16UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_SHORT$2], };
5240
- t[RG16I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [SHORT$2], };
5241
- t[RG32UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_INT$2], };
5242
- t[RG32I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [INT$2], };
5243
- t[RGB8] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$2], };
5244
- t[SRGB8] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$2], };
5245
- t[RGB565] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 2], type: [UNSIGNED_BYTE$2, UNSIGNED_SHORT_5_6_5$1], };
5246
- t[RGB8_SNORM] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [BYTE$2], };
5247
- t[R11F_G11F_B10F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$2, HALF_FLOAT$1, UNSIGNED_INT_10F_11F_11F_REV$1], };
5248
- t[RGB9_E5] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$2, HALF_FLOAT$1, UNSIGNED_INT_5_9_9_9_REV$1], };
5249
- t[RGB16F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6], type: [FLOAT$2, HALF_FLOAT$1], };
5250
- t[RGB32F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [FLOAT$2], };
5251
- t[RGB8UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [UNSIGNED_BYTE$2], };
5252
- t[RGB8I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [BYTE$2], };
5253
- t[RGB16UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [UNSIGNED_SHORT$2], };
5254
- t[RGB16I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [SHORT$2], };
5255
- t[RGB32UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [UNSIGNED_INT$2], };
5256
- t[RGB32I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [INT$2], };
5257
- t[RGBA8] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$2], };
5258
- t[SRGB8_ALPHA8] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$2], };
5259
- t[RGBA8_SNORM] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [4], type: [BYTE$2], };
5260
- t[RGB5_A1] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2, 4], type: [UNSIGNED_BYTE$2, UNSIGNED_SHORT_5_5_5_1$1, UNSIGNED_INT_2_10_10_10_REV$1], };
5261
- t[RGBA4] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2], type: [UNSIGNED_BYTE$2, UNSIGNED_SHORT_4_4_4_4$1], };
5262
- t[RGB10_A2] = { textureFormat: RGBA, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV$1], };
5263
- t[RGBA16F] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: true, bytesPerElement: [16, 8], type: [FLOAT$2, HALF_FLOAT$1], };
5264
- t[RGBA32F] = { textureFormat: RGBA, colorRenderable: false, textureFilterable: false, bytesPerElement: [16], type: [FLOAT$2], };
5265
- t[RGBA8UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_BYTE$2], };
5266
- t[RGBA8I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [BYTE$2], };
5267
- t[RGB10_A2UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV$1], };
5268
- t[RGBA16UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_SHORT$2], };
5269
- t[RGBA16I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [SHORT$2], };
5270
- t[RGBA32I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [INT$2], };
5271
- t[RGBA32UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [UNSIGNED_INT$2], };
5247
+ t[R8] = { textureFormat: RED, colorRenderable: true, textureFilterable: true, bytesPerElement: [1], type: [UNSIGNED_BYTE$1], };
5248
+ t[R8_SNORM] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [1], type: [BYTE], };
5249
+ t[R16F] = { textureFormat: RED, colorRenderable: false, textureFilterable: true, bytesPerElement: [4, 2], type: [FLOAT$1, HALF_FLOAT], };
5250
+ t[R32F] = { textureFormat: RED, colorRenderable: false, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$1], };
5251
+ t[R8UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [UNSIGNED_BYTE$1], };
5252
+ t[R8I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [1], type: [BYTE], };
5253
+ t[R16UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_SHORT$1], };
5254
+ t[R16I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [SHORT], };
5255
+ t[R32UI] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$1], };
5256
+ t[R32I] = { textureFormat: RED_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [INT$1], };
5257
+ t[RG8] = { textureFormat: RG, colorRenderable: true, textureFilterable: true, bytesPerElement: [2], type: [UNSIGNED_BYTE$1], };
5258
+ t[RG8_SNORM] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [2], type: [BYTE], };
5259
+ t[RG16F] = { textureFormat: RG, colorRenderable: false, textureFilterable: true, bytesPerElement: [8, 4], type: [FLOAT$1, HALF_FLOAT], };
5260
+ t[RG32F] = { textureFormat: RG, colorRenderable: false, textureFilterable: false, bytesPerElement: [8], type: [FLOAT$1], };
5261
+ t[RG8UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [UNSIGNED_BYTE$1], };
5262
+ t[RG8I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [2], type: [BYTE], };
5263
+ t[RG16UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_SHORT$1], };
5264
+ t[RG16I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [SHORT], };
5265
+ t[RG32UI] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_INT$1], };
5266
+ t[RG32I] = { textureFormat: RG_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [INT$1], };
5267
+ t[RGB8] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$1], };
5268
+ t[SRGB8] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [UNSIGNED_BYTE$1], };
5269
+ t[RGB565$1] = { textureFormat: RGB, colorRenderable: true, textureFilterable: true, bytesPerElement: [3, 2], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_5_6_5], };
5270
+ t[RGB8_SNORM] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [3], type: [BYTE], };
5271
+ t[R11F_G11F_B10F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$1, HALF_FLOAT, UNSIGNED_INT_10F_11F_11F_REV], };
5272
+ t[RGB9_E5] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6, 4], type: [FLOAT$1, HALF_FLOAT, UNSIGNED_INT_5_9_9_9_REV], };
5273
+ t[RGB16F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: true, bytesPerElement: [12, 6], type: [FLOAT$1, HALF_FLOAT], };
5274
+ t[RGB32F] = { textureFormat: RGB, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [FLOAT$1], };
5275
+ t[RGB8UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [UNSIGNED_BYTE$1], };
5276
+ t[RGB8I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [3], type: [BYTE], };
5277
+ t[RGB16UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [UNSIGNED_SHORT$1], };
5278
+ t[RGB16I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [6], type: [SHORT], };
5279
+ t[RGB32UI] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [UNSIGNED_INT$1], };
5280
+ t[RGB32I] = { textureFormat: RGB_INTEGER, colorRenderable: false, textureFilterable: false, bytesPerElement: [12], type: [INT$1], };
5281
+ t[RGBA8] = { textureFormat: RGBA$1, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$1], };
5282
+ t[SRGB8_ALPHA8] = { textureFormat: RGBA$1, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_BYTE$1], };
5283
+ t[RGBA8_SNORM] = { textureFormat: RGBA$1, colorRenderable: false, textureFilterable: true, bytesPerElement: [4], type: [BYTE], };
5284
+ t[RGB5_A1$1] = { textureFormat: RGBA$1, 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], };
5285
+ t[RGBA4$1] = { textureFormat: RGBA$1, colorRenderable: true, textureFilterable: true, bytesPerElement: [4, 2], type: [UNSIGNED_BYTE$1, UNSIGNED_SHORT_4_4_4_4], };
5286
+ t[RGB10_A2] = { textureFormat: RGBA$1, colorRenderable: true, textureFilterable: true, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV], };
5287
+ t[RGBA16F] = { textureFormat: RGBA$1, colorRenderable: false, textureFilterable: true, bytesPerElement: [16, 8], type: [FLOAT$1, HALF_FLOAT], };
5288
+ t[RGBA32F] = { textureFormat: RGBA$1, colorRenderable: false, textureFilterable: false, bytesPerElement: [16], type: [FLOAT$1], };
5289
+ t[RGBA8UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_BYTE$1], };
5290
+ t[RGBA8I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [BYTE], };
5291
+ t[RGB10_A2UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_2_10_10_10_REV], };
5292
+ t[RGBA16UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [UNSIGNED_SHORT$1], };
5293
+ t[RGBA16I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [8], type: [SHORT], };
5294
+ t[RGBA32I] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [INT$1], };
5295
+ t[RGBA32UI] = { textureFormat: RGBA_INTEGER, colorRenderable: true, textureFilterable: false, bytesPerElement: [16], type: [UNSIGNED_INT$1], };
5272
5296
  // Sized Internal
5273
- t[DEPTH_COMPONENT16] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [2, 4], type: [UNSIGNED_SHORT$2, UNSIGNED_INT$2], };
5274
- t[DEPTH_COMPONENT24] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$2], };
5275
- t[DEPTH_COMPONENT32F] = { textureFormat: DEPTH_COMPONENT, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$2], };
5276
- t[DEPTH24_STENCIL8] = { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_24_8$1], };
5277
- t[DEPTH32F_STENCIL8] = { textureFormat: DEPTH_STENCIL, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT_32_UNSIGNED_INT_24_8_REV$1], };
5297
+ t[DEPTH_COMPONENT16$1] = { textureFormat: DEPTH_COMPONENT$1, colorRenderable: true, textureFilterable: false, bytesPerElement: [2, 4], type: [UNSIGNED_SHORT$1, UNSIGNED_INT$1], };
5298
+ t[DEPTH_COMPONENT24$1] = { textureFormat: DEPTH_COMPONENT$1, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT$1], };
5299
+ t[DEPTH_COMPONENT32F$1] = { textureFormat: DEPTH_COMPONENT$1, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT$1], };
5300
+ t[DEPTH24_STENCIL8$1] = { textureFormat: DEPTH_STENCIL$1, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [UNSIGNED_INT_24_8], };
5301
+ t[DEPTH32F_STENCIL8$1] = { textureFormat: DEPTH_STENCIL$1, colorRenderable: true, textureFilterable: false, bytesPerElement: [4], type: [FLOAT_32_UNSIGNED_INT_24_8_REV], };
5278
5302
 
5279
5303
  Object.keys(t).forEach(function(internalFormat) {
5280
5304
  const info = t[internalFormat];
@@ -5403,10 +5427,10 @@ function getNumComponentsForFormat(format) {
5403
5427
  * @private
5404
5428
  */
5405
5429
  function getTextureTypeForArrayType(gl, src, defaultType) {
5406
- if (isArrayBuffer$1(src)) {
5430
+ if (isArrayBuffer(src)) {
5407
5431
  return getGLTypeForTypedArray(src);
5408
5432
  }
5409
- return defaultType || UNSIGNED_BYTE$2;
5433
+ return defaultType || UNSIGNED_BYTE$1;
5410
5434
  }
5411
5435
 
5412
5436
  function guessDimensions(gl, target, width, height, numElements) {
@@ -5414,7 +5438,7 @@ function guessDimensions(gl, target, width, height, numElements) {
5414
5438
  throw "can't guess dimensions";
5415
5439
  }
5416
5440
  if (!width && !height) {
5417
- const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
5441
+ const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP$1 ? 6 : 1));
5418
5442
  if (size % 1 === 0) {
5419
5443
  width = size;
5420
5444
  height = size;
@@ -5623,7 +5647,7 @@ function setTextureSamplerParameters(gl, target, parameteriFn, options) {
5623
5647
  if (options.wrap) {
5624
5648
  parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);
5625
5649
  parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);
5626
- if (target === TEXTURE_3D || isSampler(gl, target)) {
5650
+ if (target === TEXTURE_3D$1 || isSampler(gl, target)) {
5627
5651
  parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);
5628
5652
  }
5629
5653
  }
@@ -5659,7 +5683,7 @@ function setTextureSamplerParameters(gl, target, parameteriFn, options) {
5659
5683
  * @memberOf module:twgl/textures
5660
5684
  */
5661
5685
  function setTextureParameters(gl, tex, options) {
5662
- const target = options.target || TEXTURE_2D;
5686
+ const target = options.target || TEXTURE_2D$2;
5663
5687
  gl.bindTexture(target, tex);
5664
5688
  setTextureSamplerParameters(gl, target, gl.texParameteri, options);
5665
5689
  }
@@ -5747,7 +5771,7 @@ function createSamplers(gl, samplerOptions) {
5747
5771
  */
5748
5772
  function make1Pixel(color) {
5749
5773
  color = color || defaults$1.textureColor;
5750
- if (isArrayBuffer$1(color)) {
5774
+ if (isArrayBuffer(color)) {
5751
5775
  return color;
5752
5776
  }
5753
5777
  return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
@@ -5768,19 +5792,19 @@ function make1Pixel(color) {
5768
5792
  */
5769
5793
  function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
5770
5794
  options = options || defaults$1.textureOptions;
5771
- internalFormat = internalFormat || RGBA;
5772
- const target = options.target || TEXTURE_2D;
5795
+ internalFormat = internalFormat || RGBA$1;
5796
+ const target = options.target || TEXTURE_2D$2;
5773
5797
  width = width || options.width;
5774
5798
  height = height || options.height;
5775
5799
  gl.bindTexture(target, tex);
5776
5800
  if (canGenerateMipmap(gl, width, height, internalFormat)) {
5777
5801
  gl.generateMipmap(target);
5778
5802
  } else {
5779
- const filtering = canFilter(internalFormat) ? LINEAR : NEAREST;
5803
+ const filtering = canFilter(internalFormat) ? LINEAR$1 : NEAREST;
5780
5804
  gl.texParameteri(target, TEXTURE_MIN_FILTER, filtering);
5781
5805
  gl.texParameteri(target, TEXTURE_MAG_FILTER, filtering);
5782
- gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
5783
- gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
5806
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE$1);
5807
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE$1);
5784
5808
  }
5785
5809
  }
5786
5810
 
@@ -5855,17 +5879,17 @@ function getCubeFacesWithNdx(gl, options) {
5855
5879
  */
5856
5880
  function setTextureFromElement(gl, tex, element, options) {
5857
5881
  options = options || defaults$1.textureOptions;
5858
- const target = options.target || TEXTURE_2D;
5882
+ const target = options.target || TEXTURE_2D$2;
5859
5883
  const level = options.level || 0;
5860
5884
  let width = element.width;
5861
5885
  let height = element.height;
5862
- const internalFormat = options.internalFormat || options.format || RGBA;
5886
+ const internalFormat = options.internalFormat || options.format || RGBA$1;
5863
5887
  const formatType = getFormatAndTypeForInternalFormat(internalFormat);
5864
5888
  const format = options.format || formatType.format;
5865
5889
  const type = options.type || formatType.type;
5866
5890
  setPackState(gl, options);
5867
5891
  gl.bindTexture(target, tex);
5868
- if (target === TEXTURE_CUBE_MAP) {
5892
+ if (target === TEXTURE_CUBE_MAP$1) {
5869
5893
  // guess the parts
5870
5894
  const imgWidth = element.width;
5871
5895
  const imgHeight = element.height;
@@ -5933,7 +5957,7 @@ function setTextureFromElement(gl, tex, element, options) {
5933
5957
  });
5934
5958
  });
5935
5959
  }
5936
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
5960
+ } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
5937
5961
  const smallest = Math.min(element.width, element.height);
5938
5962
  const largest = Math.max(element.width, element.height);
5939
5963
  const depth = largest / smallest;
@@ -6022,7 +6046,7 @@ function loadImage(url, crossOrigin, callback) {
6022
6046
 
6023
6047
  const onError = function onError() {
6024
6048
  const msg = "couldn't load image: " + url;
6025
- error(msg);
6049
+ error$1(msg);
6026
6050
  callback(msg, img);
6027
6051
  clearEventHandlers();
6028
6052
  };
@@ -6120,7 +6144,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
6120
6144
  */
6121
6145
  function setTextureTo1PixelColor(gl, tex, options) {
6122
6146
  options = options || defaults$1.textureOptions;
6123
- const target = options.target || TEXTURE_2D;
6147
+ const target = options.target || TEXTURE_2D$2;
6124
6148
  gl.bindTexture(target, tex);
6125
6149
  if (options.color === false) {
6126
6150
  return;
@@ -6128,14 +6152,14 @@ function setTextureTo1PixelColor(gl, tex, options) {
6128
6152
  // Assume it's a URL
6129
6153
  // Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.
6130
6154
  const color = make1Pixel(options.color);
6131
- if (target === TEXTURE_CUBE_MAP) {
6155
+ if (target === TEXTURE_CUBE_MAP$1) {
6132
6156
  for (let ii = 0; ii < 6; ++ii) {
6133
- gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE$2, color);
6157
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA$1, 1, 1, 0, RGBA$1, UNSIGNED_BYTE$1, color);
6134
6158
  }
6135
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6136
- gl.texImage3D(target, 0, RGBA, 1, 1, 1, 0, RGBA, UNSIGNED_BYTE$2, color);
6159
+ } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6160
+ gl.texImage3D(target, 0, RGBA$1, 1, 1, 1, 0, RGBA$1, UNSIGNED_BYTE$1, color);
6137
6161
  } else {
6138
- gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE$2, color);
6162
+ gl.texImage2D(target, 0, RGBA$1, 1, 1, 0, RGBA$1, UNSIGNED_BYTE$1, color);
6139
6163
  }
6140
6164
  }
6141
6165
 
@@ -6235,12 +6259,12 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6235
6259
  throw "there must be 6 urls for a cubemap";
6236
6260
  }
6237
6261
  const level = options.level || 0;
6238
- const internalFormat = options.internalFormat || options.format || RGBA;
6262
+ const internalFormat = options.internalFormat || options.format || RGBA$1;
6239
6263
  const formatType = getFormatAndTypeForInternalFormat(internalFormat);
6240
6264
  const format = options.format || formatType.format;
6241
- const type = options.type || UNSIGNED_BYTE$2;
6242
- const target = options.target || TEXTURE_2D;
6243
- if (target !== TEXTURE_CUBE_MAP) {
6265
+ const type = options.type || UNSIGNED_BYTE$1;
6266
+ const target = options.target || TEXTURE_2D$2;
6267
+ if (target !== TEXTURE_CUBE_MAP$1) {
6244
6268
  throw "target must be TEXTURE_CUBE_MAP";
6245
6269
  }
6246
6270
  setTextureTo1PixelColor(gl, tex, options);
@@ -6315,12 +6339,12 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6315
6339
  function loadSlicesFromUrls(gl, tex, options, callback) {
6316
6340
  callback = callback || noop;
6317
6341
  const urls = options.src;
6318
- const internalFormat = options.internalFormat || options.format || RGBA;
6342
+ const internalFormat = options.internalFormat || options.format || RGBA$1;
6319
6343
  const formatType = getFormatAndTypeForInternalFormat(internalFormat);
6320
6344
  const format = options.format || formatType.format;
6321
- const type = options.type || UNSIGNED_BYTE$2;
6322
- const target = options.target || TEXTURE_2D_ARRAY;
6323
- if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
6345
+ const type = options.type || UNSIGNED_BYTE$1;
6346
+ const target = options.target || TEXTURE_2D_ARRAY$1;
6347
+ if (target !== TEXTURE_3D$1 && target !== TEXTURE_2D_ARRAY$1) {
6324
6348
  throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
6325
6349
  }
6326
6350
  setTextureTo1PixelColor(gl, tex, options);
@@ -6403,17 +6427,17 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
6403
6427
  */
6404
6428
  function setTextureFromArray(gl, tex, src, options) {
6405
6429
  options = options || defaults$1.textureOptions;
6406
- const target = options.target || TEXTURE_2D;
6430
+ const target = options.target || TEXTURE_2D$2;
6407
6431
  gl.bindTexture(target, tex);
6408
6432
  let width = options.width;
6409
6433
  let height = options.height;
6410
6434
  let depth = options.depth;
6411
6435
  const level = options.level || 0;
6412
- const internalFormat = options.internalFormat || options.format || RGBA;
6436
+ const internalFormat = options.internalFormat || options.format || RGBA$1;
6413
6437
  const formatType = getFormatAndTypeForInternalFormat(internalFormat);
6414
6438
  const format = options.format || formatType.format;
6415
6439
  const type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
6416
- if (!isArrayBuffer$1(src)) {
6440
+ if (!isArrayBuffer(src)) {
6417
6441
  const Type = getTypedArrayTypeForGLType(type);
6418
6442
  src = new Type(src);
6419
6443
  } else if (src instanceof Uint8ClampedArray) {
@@ -6426,7 +6450,7 @@ function setTextureFromArray(gl, tex, src, options) {
6426
6450
  throw "length wrong size for format: " + glEnumToString(gl, format);
6427
6451
  }
6428
6452
  let dimensions;
6429
- if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6453
+ if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6430
6454
  if (!width && !height && !depth) {
6431
6455
  const size = Math.cbrt(numElements);
6432
6456
  if (size % 1 !== 0) {
@@ -6456,7 +6480,7 @@ function setTextureFromArray(gl, tex, src, options) {
6456
6480
  setSkipStateToDefault(gl);
6457
6481
  gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
6458
6482
  setPackState(gl, options);
6459
- if (target === TEXTURE_CUBE_MAP) {
6483
+ if (target === TEXTURE_CUBE_MAP$1) {
6460
6484
  const elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
6461
6485
  const faceSize = numElements / 6 * elementsPerElement;
6462
6486
 
@@ -6465,7 +6489,7 @@ function setTextureFromArray(gl, tex, src, options) {
6465
6489
  const data = src.subarray(offset, offset + faceSize);
6466
6490
  gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
6467
6491
  });
6468
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6492
+ } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6469
6493
  gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
6470
6494
  } else {
6471
6495
  gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
@@ -6487,19 +6511,19 @@ function setTextureFromArray(gl, tex, src, options) {
6487
6511
  * @memberOf module:twgl/textures
6488
6512
  */
6489
6513
  function setEmptyTexture(gl, tex, options) {
6490
- const target = options.target || TEXTURE_2D;
6514
+ const target = options.target || TEXTURE_2D$2;
6491
6515
  gl.bindTexture(target, tex);
6492
6516
  const level = options.level || 0;
6493
- const internalFormat = options.internalFormat || options.format || RGBA;
6517
+ const internalFormat = options.internalFormat || options.format || RGBA$1;
6494
6518
  const formatType = getFormatAndTypeForInternalFormat(internalFormat);
6495
6519
  const format = options.format || formatType.format;
6496
6520
  const type = options.type || formatType.type;
6497
6521
  setPackState(gl, options);
6498
- if (target === TEXTURE_CUBE_MAP) {
6522
+ if (target === TEXTURE_CUBE_MAP$1) {
6499
6523
  for (let ii = 0; ii < 6; ++ii) {
6500
6524
  gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
6501
6525
  }
6502
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6526
+ } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6503
6527
  gl.texImage3D(target, level, internalFormat, options.width, options.height, options.depth, 0, format, type, null);
6504
6528
  } else {
6505
6529
  gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
@@ -6522,15 +6546,15 @@ function createTexture(gl, options, callback) {
6522
6546
  callback = callback || noop;
6523
6547
  options = options || defaults$1.textureOptions;
6524
6548
  const tex = gl.createTexture();
6525
- const target = options.target || TEXTURE_2D;
6549
+ const target = options.target || TEXTURE_2D$2;
6526
6550
  let width = options.width || 1;
6527
6551
  let height = options.height || 1;
6528
- const internalFormat = options.internalFormat || RGBA;
6552
+ const internalFormat = options.internalFormat || RGBA$1;
6529
6553
  gl.bindTexture(target, tex);
6530
- if (target === TEXTURE_CUBE_MAP) {
6554
+ if (target === TEXTURE_CUBE_MAP$1) {
6531
6555
  // this should have been the default for cubemaps :(
6532
- gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
6533
- gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
6556
+ gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE$1);
6557
+ gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE$1);
6534
6558
  }
6535
6559
  let src = options.src;
6536
6560
  if (src) {
@@ -6539,18 +6563,18 @@ function createTexture(gl, options, callback) {
6539
6563
  }
6540
6564
  if (typeof (src) === "string") {
6541
6565
  loadTextureFromUrl(gl, tex, options, callback);
6542
- } else if (isArrayBuffer$1(src) ||
6566
+ } else if (isArrayBuffer(src) ||
6543
6567
  (Array.isArray(src) && (
6544
6568
  typeof src[0] === 'number' ||
6545
6569
  Array.isArray(src[0]) ||
6546
- isArrayBuffer$1(src[0]))
6570
+ isArrayBuffer(src[0]))
6547
6571
  )
6548
6572
  ) {
6549
6573
  const dimensions = setTextureFromArray(gl, tex, src, options);
6550
6574
  width = dimensions.width;
6551
6575
  height = dimensions.height;
6552
6576
  } else if (Array.isArray(src) && (typeof (src[0]) === 'string' || isTexImageSource(src[0]))) {
6553
- if (target === TEXTURE_CUBE_MAP) {
6577
+ if (target === TEXTURE_CUBE_MAP$1) {
6554
6578
  loadCubemapFromUrls(gl, tex, options, callback);
6555
6579
  } else {
6556
6580
  loadSlicesFromUrls(gl, tex, options, callback);
@@ -6591,26 +6615,26 @@ function resizeTexture(gl, tex, options, width, height, depth) {
6591
6615
  width = width || options.width;
6592
6616
  height = height || options.height;
6593
6617
  depth = depth || options.depth;
6594
- const target = options.target || TEXTURE_2D;
6618
+ const target = options.target || TEXTURE_2D$2;
6595
6619
  gl.bindTexture(target, tex);
6596
6620
  const level = options.level || 0;
6597
- const internalFormat = options.internalFormat || options.format || RGBA;
6621
+ const internalFormat = options.internalFormat || options.format || RGBA$1;
6598
6622
  const formatType = getFormatAndTypeForInternalFormat(internalFormat);
6599
6623
  const format = options.format || formatType.format;
6600
6624
  let type;
6601
6625
  const src = options.src;
6602
6626
  if (!src) {
6603
6627
  type = options.type || formatType.type;
6604
- } else if (isArrayBuffer$1(src) || (Array.isArray(src) && typeof (src[0]) === 'number')) {
6628
+ } else if (isArrayBuffer(src) || (Array.isArray(src) && typeof (src[0]) === 'number')) {
6605
6629
  type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
6606
6630
  } else {
6607
6631
  type = options.type || formatType.type;
6608
6632
  }
6609
- if (target === TEXTURE_CUBE_MAP) {
6633
+ if (target === TEXTURE_CUBE_MAP$1) {
6610
6634
  for (let ii = 0; ii < 6; ++ii) {
6611
6635
  gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, width, height, 0, format, type, null);
6612
6636
  }
6613
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6637
+ } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6614
6638
  gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
6615
6639
  } else {
6616
6640
  gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, null);
@@ -6806,8 +6830,8 @@ var textures = /*#__PURE__*/Object.freeze({
6806
6830
  * @module twgl/programs
6807
6831
  */
6808
6832
 
6809
- const error$1 = error;
6810
- const warn$1 = warn;
6833
+ const error = error$1;
6834
+ const warn = warn$1;
6811
6835
  function getElementById(id) {
6812
6836
  return (typeof document !== 'undefined' && document.getElementById)
6813
6837
  ? document.getElementById(id)
@@ -6817,7 +6841,7 @@ function getElementById(id) {
6817
6841
  const TEXTURE0 = 0x84c0;
6818
6842
  const DYNAMIC_DRAW = 0x88e8;
6819
6843
 
6820
- const ARRAY_BUFFER$1 = 0x8892;
6844
+ const ARRAY_BUFFER = 0x8892;
6821
6845
  const ELEMENT_ARRAY_BUFFER$1 = 0x8893;
6822
6846
  const UNIFORM_BUFFER = 0x8a11;
6823
6847
  const TRANSFORM_FEEDBACK_BUFFER = 0x8c8e;
@@ -6839,11 +6863,11 @@ const UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8a46;
6839
6863
  const UNIFORM_BLOCK_DATA_SIZE = 0x8a40;
6840
6864
  const UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8a43;
6841
6865
 
6842
- const FLOAT$3 = 0x1406;
6866
+ const FLOAT = 0x1406;
6843
6867
  const FLOAT_VEC2 = 0x8B50;
6844
6868
  const FLOAT_VEC3 = 0x8B51;
6845
6869
  const FLOAT_VEC4 = 0x8B52;
6846
- const INT$3 = 0x1404;
6870
+ const INT = 0x1404;
6847
6871
  const INT_VEC2 = 0x8B53;
6848
6872
  const INT_VEC3 = 0x8B54;
6849
6873
  const INT_VEC4 = 0x8B55;
@@ -6867,7 +6891,7 @@ const FLOAT_MAT4x3 = 0x8B6A;
6867
6891
  const SAMPLER_2D_ARRAY = 0x8DC1;
6868
6892
  const SAMPLER_2D_ARRAY_SHADOW = 0x8DC4;
6869
6893
  const SAMPLER_CUBE_SHADOW = 0x8DC5;
6870
- const UNSIGNED_INT$3 = 0x1405;
6894
+ const UNSIGNED_INT = 0x1405;
6871
6895
  const UNSIGNED_INT_VEC2 = 0x8DC6;
6872
6896
  const UNSIGNED_INT_VEC3 = 0x8DC7;
6873
6897
  const UNSIGNED_INT_VEC4 = 0x8DC8;
@@ -6881,9 +6905,9 @@ const UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4;
6881
6905
  const UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7;
6882
6906
 
6883
6907
  const TEXTURE_2D$1 = 0x0DE1;
6884
- const TEXTURE_CUBE_MAP$1 = 0x8513;
6885
- const TEXTURE_3D$1 = 0x806F;
6886
- const TEXTURE_2D_ARRAY$1 = 0x8C1A;
6908
+ const TEXTURE_CUBE_MAP = 0x8513;
6909
+ const TEXTURE_3D = 0x806F;
6910
+ const TEXTURE_2D_ARRAY = 0x8C1A;
6887
6911
 
6888
6912
  const typeMap = {};
6889
6913
 
@@ -7097,15 +7121,15 @@ function samplerArraySetter(gl, type, unit, location, size) {
7097
7121
  };
7098
7122
  }
7099
7123
 
7100
- typeMap[FLOAT$3] = { Type: Float32Array, size: 4, setter: floatSetter, arraySetter: floatArraySetter, };
7124
+ typeMap[FLOAT] = { Type: Float32Array, size: 4, setter: floatSetter, arraySetter: floatArraySetter, };
7101
7125
  typeMap[FLOAT_VEC2] = { Type: Float32Array, size: 8, setter: floatVec2Setter, cols: 2, };
7102
7126
  typeMap[FLOAT_VEC3] = { Type: Float32Array, size: 12, setter: floatVec3Setter, cols: 3, };
7103
7127
  typeMap[FLOAT_VEC4] = { Type: Float32Array, size: 16, setter: floatVec4Setter, cols: 4, };
7104
- typeMap[INT$3] = { Type: Int32Array, size: 4, setter: intSetter, arraySetter: intArraySetter, };
7128
+ typeMap[INT] = { Type: Int32Array, size: 4, setter: intSetter, arraySetter: intArraySetter, };
7105
7129
  typeMap[INT_VEC2] = { Type: Int32Array, size: 8, setter: intVec2Setter, cols: 2, };
7106
7130
  typeMap[INT_VEC3] = { Type: Int32Array, size: 12, setter: intVec3Setter, cols: 3, };
7107
7131
  typeMap[INT_VEC4] = { Type: Int32Array, size: 16, setter: intVec4Setter, cols: 4, };
7108
- typeMap[UNSIGNED_INT$3] = { Type: Uint32Array, size: 4, setter: uintSetter, arraySetter: uintArraySetter, };
7132
+ typeMap[UNSIGNED_INT] = { Type: Uint32Array, size: 4, setter: uintSetter, arraySetter: uintArraySetter, };
7109
7133
  typeMap[UNSIGNED_INT_VEC2] = { Type: Uint32Array, size: 8, setter: uintVec2Setter, cols: 2, };
7110
7134
  typeMap[UNSIGNED_INT_VEC3] = { Type: Uint32Array, size: 12, setter: uintVec3Setter, cols: 3, };
7111
7135
  typeMap[UNSIGNED_INT_VEC4] = { Type: Uint32Array, size: 16, setter: uintVec4Setter, cols: 4, };
@@ -7123,20 +7147,20 @@ typeMap[FLOAT_MAT3x4] = { Type: Float32Array, size: 48, setter:
7123
7147
  typeMap[FLOAT_MAT4x2] = { Type: Float32Array, size: 64, setter: floatMat42Setter, rows: 4, cols: 2, };
7124
7148
  typeMap[FLOAT_MAT4x3] = { Type: Float32Array, size: 64, setter: floatMat43Setter, rows: 4, cols: 3, };
7125
7149
  typeMap[SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
7126
- typeMap[SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
7127
- typeMap[SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D$1, };
7150
+ typeMap[SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };
7151
+ typeMap[SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D, };
7128
7152
  typeMap[SAMPLER_2D_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
7129
- typeMap[SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
7130
- typeMap[SAMPLER_2D_ARRAY_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
7131
- typeMap[SAMPLER_CUBE_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
7153
+ typeMap[SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };
7154
+ typeMap[SAMPLER_2D_ARRAY_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };
7155
+ typeMap[SAMPLER_CUBE_SHADOW] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };
7132
7156
  typeMap[INT_SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
7133
- typeMap[INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D$1, };
7134
- typeMap[INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
7135
- typeMap[INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
7157
+ typeMap[INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D, };
7158
+ typeMap[INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };
7159
+ typeMap[INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };
7136
7160
  typeMap[UNSIGNED_INT_SAMPLER_2D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D$1, };
7137
- typeMap[UNSIGNED_INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D$1, };
7138
- typeMap[UNSIGNED_INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP$1, };
7139
- typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY$1, };
7161
+ typeMap[UNSIGNED_INT_SAMPLER_3D] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_3D, };
7162
+ typeMap[UNSIGNED_INT_SAMPLER_CUBE] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_CUBE_MAP, };
7163
+ typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = { Type: null, size: 0, setter: samplerSetter, arraySetter: samplerArraySetter, bindPoint: TEXTURE_2D_ARRAY, };
7140
7164
 
7141
7165
  function floatAttribSetter(gl, index) {
7142
7166
  return function(b) {
@@ -7159,10 +7183,10 @@ function floatAttribSetter(gl, index) {
7159
7183
  throw new Error('the length of a float constant value must be between 1 and 4!');
7160
7184
  }
7161
7185
  } else {
7162
- gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
7186
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
7163
7187
  gl.enableVertexAttribArray(index);
7164
7188
  gl.vertexAttribPointer(
7165
- index, b.numComponents || b.size, b.type || FLOAT$3, b.normalize || false, b.stride || 0, b.offset || 0);
7189
+ index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
7166
7190
  if (gl.vertexAttribDivisor) {
7167
7191
  gl.vertexAttribDivisor(index, b.divisor || 0);
7168
7192
  }
@@ -7180,10 +7204,10 @@ function intAttribSetter(gl, index) {
7180
7204
  throw new Error('The length of an integer constant value must be 4!');
7181
7205
  }
7182
7206
  } else {
7183
- gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
7207
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
7184
7208
  gl.enableVertexAttribArray(index);
7185
7209
  gl.vertexAttribIPointer(
7186
- index, b.numComponents || b.size, b.type || INT$3, b.stride || 0, b.offset || 0);
7210
+ index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
7187
7211
  if (gl.vertexAttribDivisor) {
7188
7212
  gl.vertexAttribDivisor(index, b.divisor || 0);
7189
7213
  }
@@ -7201,10 +7225,10 @@ function uintAttribSetter(gl, index) {
7201
7225
  throw new Error('The length of an unsigned integer constant value must be 4!');
7202
7226
  }
7203
7227
  } else {
7204
- gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
7228
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
7205
7229
  gl.enableVertexAttribArray(index);
7206
7230
  gl.vertexAttribIPointer(
7207
- index, b.numComponents || b.size, b.type || UNSIGNED_INT$3, b.stride || 0, b.offset || 0);
7231
+ index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
7208
7232
  if (gl.vertexAttribDivisor) {
7209
7233
  gl.vertexAttribDivisor(index, b.divisor || 0);
7210
7234
  }
@@ -7217,10 +7241,10 @@ function matAttribSetter(gl, index, typeInfo) {
7217
7241
  const count = typeInfo.count;
7218
7242
 
7219
7243
  return function(b) {
7220
- gl.bindBuffer(ARRAY_BUFFER$1, b.buffer);
7244
+ gl.bindBuffer(ARRAY_BUFFER, b.buffer);
7221
7245
  const numComponents = b.size || b.numComponents || defaultSize;
7222
7246
  const size = numComponents / count;
7223
- const type = b.type || FLOAT$3;
7247
+ const type = b.type || FLOAT;
7224
7248
  const typeInfo = typeMap[type];
7225
7249
  const stride = typeInfo.size * numComponents;
7226
7250
  const normalize = b.normalize || false;
@@ -7240,15 +7264,15 @@ function matAttribSetter(gl, index, typeInfo) {
7240
7264
 
7241
7265
 
7242
7266
  const attrTypeMap = {};
7243
- attrTypeMap[FLOAT$3] = { size: 4, setter: floatAttribSetter, };
7267
+ attrTypeMap[FLOAT] = { size: 4, setter: floatAttribSetter, };
7244
7268
  attrTypeMap[FLOAT_VEC2] = { size: 8, setter: floatAttribSetter, };
7245
7269
  attrTypeMap[FLOAT_VEC3] = { size: 12, setter: floatAttribSetter, };
7246
7270
  attrTypeMap[FLOAT_VEC4] = { size: 16, setter: floatAttribSetter, };
7247
- attrTypeMap[INT$3] = { size: 4, setter: intAttribSetter, };
7271
+ attrTypeMap[INT] = { size: 4, setter: intAttribSetter, };
7248
7272
  attrTypeMap[INT_VEC2] = { size: 8, setter: intAttribSetter, };
7249
7273
  attrTypeMap[INT_VEC3] = { size: 12, setter: intAttribSetter, };
7250
7274
  attrTypeMap[INT_VEC4] = { size: 16, setter: intAttribSetter, };
7251
- attrTypeMap[UNSIGNED_INT$3] = { size: 4, setter: uintAttribSetter, };
7275
+ attrTypeMap[UNSIGNED_INT] = { size: 4, setter: uintAttribSetter, };
7252
7276
  attrTypeMap[UNSIGNED_INT_VEC2] = { size: 8, setter: uintAttribSetter, };
7253
7277
  attrTypeMap[UNSIGNED_INT_VEC3] = { size: 12, setter: uintAttribSetter, };
7254
7278
  attrTypeMap[UNSIGNED_INT_VEC4] = { size: 16, setter: uintAttribSetter, };
@@ -7335,59 +7359,52 @@ function reportError(progOptions, msg) {
7335
7359
  return null;
7336
7360
  }
7337
7361
 
7338
- /**
7339
- * Loads a shader.
7340
- * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7341
- * @param {string} shaderSource The shader source.
7342
- * @param {number} shaderType The type of shader.
7343
- * @param {module:twgl.ProgramOptions} progOptions
7344
- * @return {WebGLShader} The created shader.
7345
- * @private
7346
- */
7347
- function loadShader(gl, shaderSource, shaderType, progOptions) {
7348
- // Create the shader object
7349
- const shader = gl.createShader(shaderType);
7350
-
7351
- // Load the shader source
7352
- gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource);
7353
-
7354
- // Compile the shader
7355
- gl.compileShader(shader);
7356
-
7357
- if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
7358
- gl.deleteShader(shader);
7359
- return null;
7360
- }
7361
-
7362
- return shader;
7363
- }
7364
-
7365
7362
  /**
7366
7363
  * Check Shader status
7367
7364
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7368
7365
  * @param {number} shaderType The shader type
7369
7366
  * @param {WebGLShader} shader The shader
7370
7367
  * @param {ErrorCallback} [errFn] function to receive error message.
7371
- * @return {bool} true if shader is ok.
7368
+ * @return {string} errors or empty string
7372
7369
  * @private
7373
7370
  */
7374
7371
  function checkShaderStatus(gl, shaderType, shader, errFn) {
7375
- errFn = errFn || error$1;
7372
+ errFn = errFn || error;
7376
7373
  // Check the compile status
7377
7374
  const compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
7378
7375
  if (!compiled) {
7379
7376
  // Something went wrong during compilation; get the error
7380
7377
  const lastError = gl.getShaderInfoLog(shader);
7381
7378
  const {lineOffset, shaderSource} = prepShaderSource(gl.getShaderSource(shader));
7382
- errFn(`${addLineNumbersWithError(shaderSource, lastError, lineOffset)}\nError compiling ${glEnumToString(gl, shaderType)}: ${lastError}`);
7379
+ const error = `${addLineNumbersWithError(shaderSource, lastError, lineOffset)}\nError compiling ${glEnumToString(gl, shaderType)}: ${lastError}`;
7380
+ errFn(error);
7381
+ return error;
7383
7382
  }
7384
- return compiled;
7383
+ return '';
7385
7384
  }
7386
7385
 
7386
+ /**
7387
+ * @typedef {Object} FullProgramSpec
7388
+ * @property {string[]} shaders the shader source or element ids.
7389
+ * @property {function(string)} [errorCallback] callback for errors
7390
+ * @property {Object.<string,number>|string[]} [attribLocations] a attribute name to location map, or array of attribute names where index = location.
7391
+ * @property {(module:twgl.BufferInfo|Object.<string,module:twgl.AttribInfo>|string[])} [transformFeedbackVaryings] If passed
7392
+ * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
7393
+ * you can pass an array of names.
7394
+ * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
7395
+ * @property {ProgramCallback} [callback] callback for async program compilation.
7396
+ * @memberOf module:twgl
7397
+ */
7398
+
7399
+ /**
7400
+ * @typedef {string[]|module:twgl.FullProgramSpec} ProgramSpec
7401
+ * @memberOf module:twgl
7402
+ */
7403
+
7387
7404
  /**
7388
7405
  * @typedef {Object} ProgramOptions
7389
7406
  * @property {function(string)} [errorCallback] callback for errors
7390
- * @property {Object.<string,number>} [attribLocations] a attribute name to location map
7407
+ * @property {Object.<string,number>|string[]} [attribLocations] a attribute name to location map, or array of attribute names where index = location.
7391
7408
  * @property {(module:twgl.BufferInfo|Object.<string,module:twgl.AttribInfo>|string[])} [transformFeedbackVaryings] If passed
7392
7409
  * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
7393
7410
  * you can pass an array of names.
@@ -7417,11 +7434,6 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
7417
7434
  opt_errorCallback = opt_attribs;
7418
7435
  opt_attribs = undefined;
7419
7436
  } else if (opt_attribs && !Array.isArray(opt_attribs)) {
7420
- // If we have an errorCallback we can just return this object
7421
- // Otherwise we need to construct one with default errorCallback
7422
- if (opt_attribs.errorCallback && opt_attribs.errors) {
7423
- return opt_attribs;
7424
- }
7425
7437
  const opt = opt_attribs;
7426
7438
  opt_errorCallback = opt.errorCallback;
7427
7439
  opt_attribs = opt.attribLocations;
@@ -7430,7 +7442,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
7430
7442
  callback = opt.callback;
7431
7443
  }
7432
7444
 
7433
- const errorCallback = opt_errorCallback || error$1;
7445
+ const errorCallback = opt_errorCallback || error;
7434
7446
  const errors = [];
7435
7447
  const options = {
7436
7448
  errorCallback(msg, ...args) {
@@ -7443,14 +7455,14 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
7443
7455
  errors,
7444
7456
  };
7445
7457
 
7446
- if (opt_attribs) {
7458
+ {
7447
7459
  let attribLocations = {};
7448
7460
  if (Array.isArray(opt_attribs)) {
7449
7461
  opt_attribs.forEach(function(attrib, ndx) {
7450
7462
  attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;
7451
7463
  });
7452
7464
  } else {
7453
- attribLocations = opt_attribs;
7465
+ attribLocations = opt_attribs || {};
7454
7466
  }
7455
7467
  options.attribLocations = attribLocations;
7456
7468
  }
@@ -7472,14 +7484,61 @@ function getShaderTypeFromScriptType(gl, scriptType) {
7472
7484
  return undefined;
7473
7485
  }
7474
7486
 
7475
- function deleteShaders(gl, shaders) {
7476
- shaders.forEach(function(shader) {
7477
- gl.deleteShader(shader);
7478
- });
7487
+ function deleteProgramAndShaders(gl, program, notThese) {
7488
+ const shaders = gl.getAttachedShaders(program);
7489
+ for (const shader of shaders) {
7490
+ if (notThese.has(shader)) {
7491
+ gl.deleteShader(shader);
7492
+ }
7493
+ }
7494
+ gl.deleteProgram(program);
7479
7495
  }
7480
7496
 
7481
7497
  const wait = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
7482
7498
 
7499
+ function createProgramNoCheck(gl, shaders, programOptions) {
7500
+ const program = gl.createProgram();
7501
+ const {
7502
+ attribLocations,
7503
+ transformFeedbackVaryings,
7504
+ transformFeedbackMode,
7505
+ } = getProgramOptions(programOptions);
7506
+
7507
+ for (let ndx = 0; ndx < shaders.length; ++ndx) {
7508
+ let shader = shaders[ndx];
7509
+ if (typeof shader === 'string') {
7510
+ const elem = getElementById(shader);
7511
+ const src = elem ? elem.text : shader;
7512
+ let type = gl[defaultShaderType[ndx]];
7513
+ if (elem && elem.type) {
7514
+ type = getShaderTypeFromScriptType(gl, elem.type) || type;
7515
+ }
7516
+ shader = gl.createShader(type);
7517
+ gl.shaderSource(shader, prepShaderSource(src).shaderSource);
7518
+ gl.compileShader(shader);
7519
+ gl.attachShader(program, shader);
7520
+ }
7521
+ }
7522
+
7523
+ Object.entries(attribLocations).forEach(([attrib, loc]) => gl.bindAttribLocation(program, loc, attrib));
7524
+
7525
+ {
7526
+ let varyings = transformFeedbackVaryings;
7527
+ if (varyings) {
7528
+ if (varyings.attribs) {
7529
+ varyings = varyings.attribs;
7530
+ }
7531
+ if (!Array.isArray(varyings)) {
7532
+ varyings = Object.keys(varyings);
7533
+ }
7534
+ gl.transformFeedbackVaryings(program, varyings, transformFeedbackMode || SEPARATE_ATTRIBS);
7535
+ }
7536
+ }
7537
+
7538
+ gl.linkProgram(program);
7539
+ return program;
7540
+ }
7541
+
7483
7542
  /**
7484
7543
  * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
7485
7544
  * program.
@@ -7505,62 +7564,47 @@ function createProgram(
7505
7564
  // This code is really convoluted, because it may or may not be async
7506
7565
  // Maybe it would be better to have a separate function
7507
7566
  const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
7508
- const realShaders = [];
7509
- const newShaders = [];
7510
- for (let ndx = 0; ndx < shaders.length; ++ndx) {
7511
- let shader = shaders[ndx];
7512
- if (typeof (shader) === 'string') {
7513
- const elem = getElementById(shader);
7514
- const src = elem ? elem.text : shader;
7515
- let type = gl[defaultShaderType[ndx]];
7516
- if (elem && elem.type) {
7517
- type = getShaderTypeFromScriptType(gl, elem.type) || type;
7518
- }
7519
- shader = loadShader(gl, src, type, progOptions);
7520
- newShaders.push(shader);
7521
- }
7522
- if (isShader(gl, shader)) {
7523
- realShaders.push(shader);
7524
- }
7525
- }
7567
+ const shaderSet = new Set(shaders);
7568
+ const program = createProgramNoCheck(gl, shaders, progOptions);
7526
7569
 
7527
- if (realShaders.length !== shaders.length) {
7528
- deleteShaders(gl, newShaders);
7529
- return reportError(progOptions, "not enough shaders for program");
7530
- }
7531
-
7532
- const program = gl.createProgram();
7533
- realShaders.forEach(function(shader) {
7534
- gl.attachShader(program, shader);
7535
- });
7536
- if (progOptions.attribLocations) {
7537
- Object.keys(progOptions.attribLocations).forEach(function(attrib) {
7538
- gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);
7539
- });
7540
- }
7541
- let varyings = progOptions.transformFeedbackVaryings;
7542
- if (varyings) {
7543
- if (varyings.attribs) {
7544
- varyings = varyings.attribs;
7545
- }
7546
- if (!Array.isArray(varyings)) {
7547
- varyings = Object.keys(varyings);
7570
+ function hasErrors(gl, program) {
7571
+ const errors = getProgramErrors(gl, program, progOptions.errorCallback);
7572
+ if (errors) {
7573
+ deleteProgramAndShaders(gl, program, shaderSet);
7548
7574
  }
7549
- gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
7575
+ return errors;
7550
7576
  }
7551
7577
 
7552
- gl.linkProgram(program);
7553
7578
  if (progOptions.callback) {
7554
- checkForProgramLinkCompletionAsync(gl, program, progOptions);
7555
- return null;
7556
- } else {
7557
- if (!checkProgramStatus(gl, program, progOptions.errorCallback)) {
7558
- gl.deleteProgram(program);
7559
- deleteShaders(gl, newShaders);
7560
- return null;
7561
- }
7562
- return program;
7579
+ waitForProgramLinkCompletionAsync(gl, program).then(() => {
7580
+ const errors = hasErrors(gl, program);
7581
+ progOptions.callback(errors, errors ? undefined : program);
7582
+ });
7583
+ return undefined;
7563
7584
  }
7585
+
7586
+ return hasErrors(gl, program) ? undefined : program;
7587
+ }
7588
+
7589
+ /**
7590
+ * This only works because the functions it wraps the first 2 arguments
7591
+ * are gl and any, followed by things that become programOptions
7592
+ * @private
7593
+ */
7594
+ function wrapCallbackFnToAsyncFn(fn) {
7595
+ return function(gl, arg1, ...args) {
7596
+ return new Promise((resolve, reject) => {
7597
+ const programOptions = getProgramOptions(...args);
7598
+ programOptions.callback = (err, program) => {
7599
+ if (err) {
7600
+ reject(err);
7601
+ } else {
7602
+ resolve(program);
7603
+ }
7604
+ };
7605
+ fn(gl, arg1, programOptions);
7606
+ });
7607
+ };
7564
7608
  }
7565
7609
 
7566
7610
  /**
@@ -7573,6 +7617,7 @@ function createProgram(
7573
7617
  * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_errFunc);
7574
7618
  * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
7575
7619
  *
7620
+ * @function
7576
7621
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7577
7622
  * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
7578
7623
  * @param {module:twgl.ProgramOptions|string[]|module:twgl.ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
@@ -7582,22 +7627,11 @@ function createProgram(
7582
7627
  * @return {Promise<WebGLProgram>} The created program
7583
7628
  * @memberOf module:twgl/programs
7584
7629
  */
7585
- function createProgramAsync(gl, shaders, ...args) {
7586
- return new Promise((resolve, reject) => {
7587
- const programOptions = getProgramOptions(...args);
7588
- programOptions.callback = (err, program) => {
7589
- if (err) {
7590
- reject(err);
7591
- } else {
7592
- resolve(program);
7593
- }
7594
- };
7595
- createProgram(gl, shaders, programOptions);
7596
- });
7597
- }
7630
+ const createProgramAsync = wrapCallbackFnToAsyncFn(createProgram);
7598
7631
 
7599
7632
  /**
7600
7633
  * Same as createProgramInfo but returns a promise
7634
+ * @function
7601
7635
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext
7602
7636
  * to use.
7603
7637
  * @param {string[]} shaderSources Array of sources for the
@@ -7610,31 +7644,9 @@ function createProgramAsync(gl, shaders, ...args) {
7610
7644
  * @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
7611
7645
  * @memberOf module:twgl/programs
7612
7646
  */
7613
- function createProgramInfoAsync(gl, shaders, ...args) {
7614
- return new Promise((resolve, reject) => {
7615
- const programOptions = getProgramOptions(...args);
7616
- programOptions.callback = (err, programInfo) => {
7617
- if (err) {
7618
- reject(err);
7619
- } else {
7620
- resolve(programInfo);
7621
- }
7622
- };
7623
- createProgramInfo(gl, shaders, programOptions);
7624
- });
7625
- }
7626
-
7647
+ const createProgramInfoAsync = wrapCallbackFnToAsyncFn(createProgramInfo);
7627
7648
 
7628
- /**
7629
- * Asynchronously wait for program to link.
7630
- * Note: if 'KHR_parallel_shader_compile' extension does not
7631
- * exist then compilation will not be truly async.
7632
- * @param {WebGLRenderingContext} gl The context
7633
- * @param {WebGLProgram} program The program
7634
- * @param {module:twgl.ProgramOptions} progOptions Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
7635
- * @private
7636
- */
7637
- async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
7649
+ async function waitForProgramLinkCompletionAsync(gl, program) {
7638
7650
  const ext = gl.getExtension('KHR_parallel_shader_compile');
7639
7651
  const checkFn = ext
7640
7652
  ? (gl, program) => gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR)
@@ -7645,18 +7657,12 @@ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
7645
7657
  await wait(waitTime); // must wait at least once
7646
7658
  waitTime = 1000 / 60;
7647
7659
  } while (!checkFn(gl, program));
7660
+ }
7648
7661
 
7649
- const success = checkProgramStatus(gl, program, progOptions.errorCallback);
7650
- const err = success ? undefined : progOptions.errors.join('\n');
7651
- if (!success) {
7652
- const errFn = progOptions.errorCallback || error$1;
7653
- errFn(err);
7654
- gl.deleteProgram(program);
7655
- // TODO: delete shaders, but only shaders that were created newly for this
7656
- // program
7657
- program = null;
7662
+ async function waitForAllProgramsLinkCompletionAsync(gl, programs) {
7663
+ for (const program of Object.values(programs)) {
7664
+ await waitForProgramLinkCompletionAsync(gl, program);
7658
7665
  }
7659
- progOptions.callback(err, program);
7660
7666
  }
7661
7667
 
7662
7668
  /**
@@ -7664,46 +7670,23 @@ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
7664
7670
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7665
7671
  * @param {WebGLProgram} program Program to check
7666
7672
  * @param {ErrorCallback} [errFn] func for errors
7667
- * @return {bool} true if program is ok
7673
+ * @return {string?} errors if program is failed, else undefined
7668
7674
  * @private
7669
7675
  */
7670
- function checkProgramStatus(gl, program, errFn) {
7671
- errFn = errFn || error$1;
7676
+ function getProgramErrors(gl, program, errFn) {
7677
+ errFn = errFn || error;
7672
7678
  // Check the link status
7673
7679
  const linked = gl.getProgramParameter(program, LINK_STATUS);
7674
7680
  if (!linked) {
7675
7681
  // something went wrong with the link
7676
7682
  const lastError = gl.getProgramInfoLog(program);
7677
7683
  errFn(`Error in program linking: ${lastError}`);
7684
+ // print any errors from these shaders
7685
+ const shaders = gl.getAttachedShaders(program);
7686
+ const errors = shaders.map(shader => checkShaderStatus(gl, gl.getShaderParameter(shader, gl.SHADER_TYPE), shader, errFn));
7687
+ return `${lastError}\n${errors.filter(_ => _).join('\n')}`;
7678
7688
  }
7679
- return linked;
7680
- }
7681
-
7682
- /**
7683
- * Loads a shader from a script tag.
7684
- * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7685
- * @param {string} scriptId The id of the script tag.
7686
- * @param {number} [opt_shaderType] The type of shader. If not passed in it will
7687
- * be derived from the type of the script tag.
7688
- * @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
7689
- * @return {WebGLShader?} The created shader or null if error.
7690
- * @private
7691
- */
7692
- function createShaderFromScript(
7693
- gl, scriptId, opt_shaderType, progOptions) {
7694
- let shaderSource = "";
7695
- const shaderScript = getElementById(scriptId);
7696
- if (!shaderScript) {
7697
- return reportError(progOptions, `unknown script element: ${scriptId}`);
7698
- }
7699
- shaderSource = shaderScript.text;
7700
-
7701
- const shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
7702
- if (!shaderType) {
7703
- return reportError(progOptions, 'unknown shader type');
7704
- }
7705
-
7706
- return loadShader(gl, shaderSource, shaderType, progOptions);
7689
+ return undefined;
7707
7690
  }
7708
7691
 
7709
7692
  /**
@@ -7732,13 +7715,12 @@ function createProgramFromScripts(
7732
7715
  gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {
7733
7716
  const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
7734
7717
  const shaders = [];
7735
- for (let ii = 0; ii < shaderScriptIds.length; ++ii) {
7736
- const shader = createShaderFromScript(
7737
- gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
7738
- if (!shader) {
7739
- return null;
7718
+ for (const scriptId of shaderScriptIds) {
7719
+ const shaderScript = getElementById(scriptId);
7720
+ if (!shaderScript) {
7721
+ return reportError(progOptions, `unknown script element: ${scriptId}`);
7740
7722
  }
7741
- shaders.push(shader);
7723
+ shaders.push(shaderScript.text);
7742
7724
  }
7743
7725
  return createProgram(gl, shaders, progOptions);
7744
7726
  }
@@ -7767,16 +7749,7 @@ function createProgramFromScripts(
7767
7749
  */
7768
7750
  function createProgramFromSources(
7769
7751
  gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
7770
- const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
7771
- const shaders = [];
7772
- for (let ii = 0; ii < shaderSources.length; ++ii) {
7773
- const shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
7774
- if (!progOptions.callback && !shader) {
7775
- return null;
7776
- }
7777
- shaders.push(shader);
7778
- }
7779
- return createProgram(gl, shaders, progOptions);
7752
+ return createProgram(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback);
7780
7753
  }
7781
7754
 
7782
7755
  /**
@@ -8158,7 +8131,7 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
8158
8131
  const uniformData = uniformBlockSpec.uniformData;
8159
8132
  const blockSpec = blockSpecs[blockName];
8160
8133
  if (!blockSpec) {
8161
- warn$1("no uniform block object named:", blockName);
8134
+ warn("no uniform block object named:", blockName);
8162
8135
  return {
8163
8136
  name: blockName,
8164
8137
  uniforms: {},
@@ -8835,35 +8808,228 @@ function createProgramInfo(
8835
8808
  }
8836
8809
  return source;
8837
8810
  });
8811
+
8838
8812
  if (errors.length) {
8839
8813
  return reportError(progOptions, '');
8840
8814
  }
8815
+
8841
8816
  const origCallback = progOptions.callback;
8842
8817
  if (origCallback) {
8843
8818
  progOptions.callback = (err, program) => {
8844
- let programInfo;
8845
- if (!err) {
8846
- programInfo = createProgramInfoFromProgram(gl, program);
8847
- }
8848
- origCallback(err, programInfo);
8819
+ origCallback(err, err ? undefined : createProgramInfoFromProgram(gl, program));
8849
8820
  };
8850
8821
  }
8822
+
8851
8823
  const program = createProgramFromSources(gl, shaderSources, progOptions);
8852
8824
  if (!program) {
8853
8825
  return null;
8854
8826
  }
8827
+
8855
8828
  return createProgramInfoFromProgram(gl, program);
8856
8829
  }
8857
8830
 
8831
+ function checkAllPrograms(gl, programs, programSpecs, noDeleteShadersSet, programOptions) {
8832
+ // check errors for everything.
8833
+ for (const [name, program] of Object.entries(programs)) {
8834
+ const options = {...programOptions};
8835
+ const spec = programSpecs[name];
8836
+ if (!Array.isArray(spec)) {
8837
+ Object.assign(options, spec);
8838
+ }
8839
+ const errors = getProgramErrors(gl, program, options.errorCallback);
8840
+ if (errors) {
8841
+ // delete everything we created
8842
+ for (const program of Object.values(programs)) {
8843
+ const shaders = gl.getAttachedShaders(program);
8844
+ gl.deleteProgram(program);
8845
+ for (const shader of shaders) {
8846
+ // Don't delete it if we didn't create it.
8847
+ if (!noDeleteShadersSet.has(shader)) {
8848
+ gl.deleteShader(shader);
8849
+ }
8850
+ }
8851
+ }
8852
+ return errors;
8853
+ }
8854
+ }
8855
+
8856
+ return undefined;
8857
+ }
8858
+
8859
+ /**
8860
+ * Creates multiple programs
8861
+ *
8862
+ * Note: the reason this function exists is because the fastest way to create multiple
8863
+ * programs in WebGL is to create and compile all shaders and link all programs and only
8864
+ * afterwards check if they succeeded. In that way, giving all your shaders
8865
+ *
8866
+ * @see {@link module:twgl.createProgram}
8867
+ *
8868
+ * Example:
8869
+ *
8870
+ * const programs = twgl.createPrograms(gl, {
8871
+ * lambert: [lambertVS, lambertFS],
8872
+ * phong: [phongVS, phoneFS],
8873
+ * particles: {
8874
+ * shaders: [particlesVS, particlesFS],
8875
+ * transformFeedbackVaryings: ['position', 'velocity'],
8876
+ * },
8877
+ * });
8878
+ *
8879
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8880
+ * @param {Object.<string, module:twgl.ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
8881
+ * @param {module:twgl.ProgramOptions} [programOptions] options to apply to all programs
8882
+ * @return {Object.<string, WebGLProgram>?} the created programInfos by name
8883
+ */
8884
+ function createPrograms(gl, programSpecs, programOptions = {}) {
8885
+ // Remember existing shaders so that if there is an error we don't delete them
8886
+ const noDeleteShadersSet = new Set();
8887
+
8888
+ // compile and link everything
8889
+ const programs = Object.fromEntries(Object.entries(programSpecs).map(([name, spec]) => {
8890
+ const options = {...programOptions};
8891
+ const shaders = Array.isArray(spec) ? spec : spec.shaders;
8892
+ if (!Array.isArray(spec)) {
8893
+ Object.assign(options, spec);
8894
+ }
8895
+ shaders.forEach(noDeleteShadersSet.add, noDeleteShadersSet);
8896
+ return [name, createProgramNoCheck(gl, shaders, options)];
8897
+ }));
8898
+
8899
+ if (programOptions.callback) {
8900
+ waitForAllProgramsLinkCompletionAsync(gl, programs).then(() => {
8901
+ const errors = checkAllPrograms(gl, programs, programSpecs, noDeleteShadersSet, programOptions);
8902
+ programOptions.callback(errors, errors ? undefined : programs);
8903
+ });
8904
+ return undefined;
8905
+ }
8906
+
8907
+ const errors = checkAllPrograms(gl, programs, programSpecs, noDeleteShadersSet, programOptions);
8908
+ return errors ? undefined : programs;
8909
+ }
8910
+
8911
+ /**
8912
+ * Creates multiple programInfos
8913
+ *
8914
+ * Note: the reason this function exists is because the fastest way to create multiple
8915
+ * programs in WebGL is to create and compile all shaders and link all programs and only
8916
+ * afterwards check if they succeeded. In that way, giving all your shaders
8917
+ *
8918
+ * @see {@link module:twgl.createProgramInfo}
8919
+ *
8920
+ * Examples:
8921
+ *
8922
+ * const programInfos = twgl.createProgramInfos(gl, {
8923
+ * lambert: [lambertVS, lambertFS],
8924
+ * phong: [phongVS, phoneFS],
8925
+ * particles: {
8926
+ * shaders: [particlesVS, particlesFS],
8927
+ * transformFeedbackVaryings: ['position', 'velocity'],
8928
+ * },
8929
+ * });
8930
+ *
8931
+ * or
8932
+ *
8933
+ * const {lambert, phong, particles} = twgl.createProgramInfos(gl, {
8934
+ * lambert: [lambertVS, lambertFS],
8935
+ * phong: [phongVS, phoneFS],
8936
+ * particles: {
8937
+ * shaders: [particlesVS, particlesFS],
8938
+ * transformFeedbackVaryings: ['position', 'velocity'],
8939
+ * },
8940
+ * });
8941
+ *
8942
+ *
8943
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8944
+ * @param {Object.<string, module:twgl.ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
8945
+ * @param {module:twgl.ProgramOptions} [programOptions] options to apply to all programs
8946
+ * @return {Object.<string, module:twgl.ProgramInfo>?} the created programInfos by name
8947
+ */
8948
+ function createProgramInfos(gl, programSpecs, programOptions) {
8949
+ programOptions = getProgramOptions(programOptions);
8950
+
8951
+ function createProgramInfosForPrograms(gl, programs) {
8952
+ return Object.fromEntries(Object.entries(programs).map(([name, program]) =>
8953
+ [name, createProgramInfoFromProgram(gl, program)]
8954
+ ));
8955
+ }
8956
+
8957
+ const origCallback = programOptions.callback;
8958
+ if (origCallback) {
8959
+ programOptions.callback = (err, programs) => {
8960
+ origCallback(err, err ? undefined : createProgramInfosForPrograms(gl, programs));
8961
+ };
8962
+ }
8963
+
8964
+ const programs = createPrograms(gl, programSpecs, programOptions);
8965
+ if (origCallback || !programs) {
8966
+ return undefined;
8967
+ }
8968
+
8969
+ return createProgramInfosForPrograms(gl, programs);
8970
+ }
8971
+
8972
+ /**
8973
+ * Creates multiple programs asynchronously
8974
+ *
8975
+ * @see {@link module:twgl.createProgramAsync}
8976
+ *
8977
+ * Example:
8978
+ *
8979
+ * const programs = await twgl.createProgramsAsync(gl, {
8980
+ * lambert: [lambertVS, lambertFS],
8981
+ * phong: [phongVS, phoneFS],
8982
+ * particles: {
8983
+ * shaders: [particlesVS, particlesFS],
8984
+ * transformFeedbackVaryings: ['position', 'velocity'],
8985
+ * },
8986
+ * });
8987
+ *
8988
+ * @function
8989
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8990
+ * @param {Object.<string, module:twgl.ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
8991
+ * @param {module:twgl.ProgramOptions} [programOptions] options to apply to all programs
8992
+ * @return {Object.<string, WebGLProgram>?} the created programInfos by name
8993
+ */
8994
+ const createProgramsAsync = wrapCallbackFnToAsyncFn(createPrograms);
8995
+
8996
+ /**
8997
+ * Creates multiple programInfos asynchronously
8998
+ *
8999
+ * @see {@link module:twgl.createProgramInfoAsync}
9000
+ *
9001
+ * Example:
9002
+ *
9003
+ * const programInfos = await twgl.createProgramInfosAsync(gl, {
9004
+ * lambert: [lambertVS, lambertFS],
9005
+ * phong: [phongVS, phoneFS],
9006
+ * particles: {
9007
+ * shaders: [particlesVS, particlesFS],
9008
+ * transformFeedbackVaryings: ['position', 'velocity'],
9009
+ * },
9010
+ * });
9011
+ *
9012
+ * @function
9013
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
9014
+ * @param {Object.<string, module:twgl.ProgramSpec>} programSpecs An object of ProgramSpecs, one per program.
9015
+ * @param {module:twgl.ProgramOptions} [programOptions] options to apply to all programs
9016
+ * @return {Promise<Object.<string, module:twgl.ProgramInfo>>} the created programInfos by name
9017
+ */
9018
+ const createProgramInfosAsync = wrapCallbackFnToAsyncFn(createProgramInfos);
9019
+
8858
9020
  var programs = /*#__PURE__*/Object.freeze({
8859
9021
  __proto__: null,
8860
9022
  createAttributeSetters: createAttributeSetters,
8861
9023
  createProgram: createProgram,
8862
9024
  createProgramAsync: createProgramAsync,
9025
+ createPrograms: createPrograms,
9026
+ createProgramsAsync: createProgramsAsync,
8863
9027
  createProgramFromScripts: createProgramFromScripts,
8864
9028
  createProgramFromSources: createProgramFromSources,
8865
9029
  createProgramInfo: createProgramInfo,
8866
9030
  createProgramInfoAsync: createProgramInfoAsync,
9031
+ createProgramInfos: createProgramInfos,
9032
+ createProgramInfosAsync: createProgramInfosAsync,
8867
9033
  createProgramInfoFromProgram: createProgramInfoFromProgram,
8868
9034
  createUniformSetters: createUniformSetters,
8869
9035
  createUniformBlockSpecFromProgram: createUniformBlockSpecFromProgram,
@@ -8904,7 +9070,7 @@ var programs = /*#__PURE__*/Object.freeze({
8904
9070
  */
8905
9071
 
8906
9072
  const TRIANGLES = 0x0004;
8907
- const UNSIGNED_SHORT$3 = 0x1403;
9073
+ const UNSIGNED_SHORT = 0x1403;
8908
9074
 
8909
9075
  /**
8910
9076
  * Drawing related functions
@@ -8941,9 +9107,9 @@ function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
8941
9107
  offset = offset === undefined ? 0 : offset;
8942
9108
  if (elementType || indices) {
8943
9109
  if (instanceCount !== undefined) {
8944
- gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT$3 : bufferInfo.elementType, offset, instanceCount);
9110
+ gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
8945
9111
  } else {
8946
- gl.drawElements(type, numElements, elementType === undefined ? UNSIGNED_SHORT$3 : bufferInfo.elementType, offset);
9112
+ gl.drawElements(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset);
8947
9113
  }
8948
9114
  } else {
8949
9115
  if (instanceCount !== undefined) {
@@ -9072,36 +9238,36 @@ var draw = /*#__PURE__*/Object.freeze({
9072
9238
 
9073
9239
  const FRAMEBUFFER = 0x8d40;
9074
9240
  const RENDERBUFFER = 0x8d41;
9075
- const TEXTURE_2D$2 = 0x0de1;
9241
+ const TEXTURE_2D = 0x0de1;
9076
9242
 
9077
- const UNSIGNED_BYTE$3 = 0x1401;
9243
+ const UNSIGNED_BYTE = 0x1401;
9078
9244
 
9079
9245
  /* PixelFormat */
9080
- const DEPTH_COMPONENT$1 = 0x1902;
9081
- const RGBA$1 = 0x1908;
9082
- const DEPTH_COMPONENT24$1 = 0x81a6;
9083
- const DEPTH_COMPONENT32F$1 = 0x8cac;
9084
- const DEPTH24_STENCIL8$1 = 0x88f0;
9085
- const DEPTH32F_STENCIL8$1 = 0x8cad;
9246
+ const DEPTH_COMPONENT = 0x1902;
9247
+ const RGBA = 0x1908;
9248
+ const DEPTH_COMPONENT24 = 0x81a6;
9249
+ const DEPTH_COMPONENT32F = 0x8cac;
9250
+ const DEPTH24_STENCIL8 = 0x88f0;
9251
+ const DEPTH32F_STENCIL8 = 0x8cad;
9086
9252
 
9087
9253
  /* Framebuffer Object. */
9088
- const RGBA4$1 = 0x8056;
9089
- const RGB5_A1$1 = 0x8057;
9090
- const RGB565$1 = 0x8D62;
9091
- const DEPTH_COMPONENT16$1 = 0x81A5;
9254
+ const RGBA4 = 0x8056;
9255
+ const RGB5_A1 = 0x8057;
9256
+ const RGB565 = 0x8D62;
9257
+ const DEPTH_COMPONENT16 = 0x81A5;
9092
9258
  const STENCIL_INDEX = 0x1901;
9093
9259
  const STENCIL_INDEX8 = 0x8D48;
9094
- const DEPTH_STENCIL$1 = 0x84F9;
9260
+ const DEPTH_STENCIL = 0x84F9;
9095
9261
  const COLOR_ATTACHMENT0 = 0x8CE0;
9096
9262
  const DEPTH_ATTACHMENT = 0x8D00;
9097
9263
  const STENCIL_ATTACHMENT = 0x8D20;
9098
9264
  const DEPTH_STENCIL_ATTACHMENT = 0x821A;
9099
9265
 
9100
9266
  /* TextureWrapMode */
9101
- const CLAMP_TO_EDGE$1 = 0x812F;
9267
+ const CLAMP_TO_EDGE = 0x812F;
9102
9268
 
9103
9269
  /* TextureMagFilter */
9104
- const LINEAR$1 = 0x2601;
9270
+ const LINEAR = 0x2601;
9105
9271
 
9106
9272
  /**
9107
9273
  * The options for a framebuffer attachment.
@@ -9136,31 +9302,31 @@ const LINEAR$1 = 0x2601;
9136
9302
  */
9137
9303
 
9138
9304
  const defaultAttachments = [
9139
- { format: RGBA$1, type: UNSIGNED_BYTE$3, min: LINEAR$1, wrap: CLAMP_TO_EDGE$1, },
9140
- { format: DEPTH_STENCIL$1, },
9305
+ { format: RGBA, type: UNSIGNED_BYTE, min: LINEAR, wrap: CLAMP_TO_EDGE, },
9306
+ { format: DEPTH_STENCIL, },
9141
9307
  ];
9142
9308
 
9143
9309
  const attachmentsByFormat = {};
9144
- attachmentsByFormat[DEPTH_STENCIL$1] = DEPTH_STENCIL_ATTACHMENT;
9310
+ attachmentsByFormat[DEPTH_STENCIL] = DEPTH_STENCIL_ATTACHMENT;
9145
9311
  attachmentsByFormat[STENCIL_INDEX] = STENCIL_ATTACHMENT;
9146
9312
  attachmentsByFormat[STENCIL_INDEX8] = STENCIL_ATTACHMENT;
9147
- attachmentsByFormat[DEPTH_COMPONENT$1] = DEPTH_ATTACHMENT;
9148
- attachmentsByFormat[DEPTH_COMPONENT16$1] = DEPTH_ATTACHMENT;
9149
- attachmentsByFormat[DEPTH_COMPONENT24$1] = DEPTH_ATTACHMENT;
9150
- attachmentsByFormat[DEPTH_COMPONENT32F$1] = DEPTH_ATTACHMENT;
9151
- attachmentsByFormat[DEPTH24_STENCIL8$1] = DEPTH_STENCIL_ATTACHMENT;
9152
- attachmentsByFormat[DEPTH32F_STENCIL8$1] = DEPTH_STENCIL_ATTACHMENT;
9313
+ attachmentsByFormat[DEPTH_COMPONENT] = DEPTH_ATTACHMENT;
9314
+ attachmentsByFormat[DEPTH_COMPONENT16] = DEPTH_ATTACHMENT;
9315
+ attachmentsByFormat[DEPTH_COMPONENT24] = DEPTH_ATTACHMENT;
9316
+ attachmentsByFormat[DEPTH_COMPONENT32F] = DEPTH_ATTACHMENT;
9317
+ attachmentsByFormat[DEPTH24_STENCIL8] = DEPTH_STENCIL_ATTACHMENT;
9318
+ attachmentsByFormat[DEPTH32F_STENCIL8] = DEPTH_STENCIL_ATTACHMENT;
9153
9319
 
9154
9320
  function getAttachmentPointForFormat(format, internalFormat) {
9155
9321
  return attachmentsByFormat[format] || attachmentsByFormat[internalFormat];
9156
9322
  }
9157
9323
 
9158
9324
  const renderbufferFormats = {};
9159
- renderbufferFormats[RGBA4$1] = true;
9160
- renderbufferFormats[RGB5_A1$1] = true;
9161
- renderbufferFormats[RGB565$1] = true;
9162
- renderbufferFormats[DEPTH_STENCIL$1] = true;
9163
- renderbufferFormats[DEPTH_COMPONENT16$1] = true;
9325
+ renderbufferFormats[RGBA4] = true;
9326
+ renderbufferFormats[RGB5_A1] = true;
9327
+ renderbufferFormats[RGB565] = true;
9328
+ renderbufferFormats[DEPTH_STENCIL] = true;
9329
+ renderbufferFormats[DEPTH_COMPONENT16] = true;
9164
9330
  renderbufferFormats[STENCIL_INDEX] = true;
9165
9331
  renderbufferFormats[STENCIL_INDEX8] = true;
9166
9332
 
@@ -9263,10 +9429,10 @@ function createFramebufferInfo(gl, attachments, width, height) {
9263
9429
  textureOptions.height = height;
9264
9430
  if (textureOptions.auto === undefined) {
9265
9431
  textureOptions.auto = false;
9266
- textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR$1;
9267
- textureOptions.mag = textureOptions.mag || textureOptions.minMag || LINEAR$1;
9268
- textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE$1;
9269
- textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE$1;
9432
+ textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR;
9433
+ textureOptions.mag = textureOptions.mag || textureOptions.minMag || LINEAR;
9434
+ textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE;
9435
+ textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE;
9270
9436
  }
9271
9437
  attachment = createTexture(gl, textureOptions);
9272
9438
  }
@@ -9285,7 +9451,7 @@ function createFramebufferInfo(gl, attachments, width, height) {
9285
9451
  gl.framebufferTexture2D(
9286
9452
  target,
9287
9453
  attachmentPoint,
9288
- attachmentOptions.target || TEXTURE_2D$2,
9454
+ attachmentOptions.target || TEXTURE_2D,
9289
9455
  attachment,
9290
9456
  attachmentOptions.level || 0);
9291
9457
  }
@@ -9443,7 +9609,7 @@ var framebuffers = /*#__PURE__*/Object.freeze({
9443
9609
  * @module twgl/vertexArrays
9444
9610
  */
9445
9611
 
9446
- const ELEMENT_ARRAY_BUFFER$2 = 0x8893;
9612
+ const ELEMENT_ARRAY_BUFFER = 0x8893;
9447
9613
 
9448
9614
  /**
9449
9615
  * @typedef {Object} VertexArrayInfo
@@ -9523,7 +9689,7 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
9523
9689
  gl.bindVertexArray(vao);
9524
9690
  setAttributes(setters, attribs);
9525
9691
  if (indices) {
9526
- gl.bindBuffer(ELEMENT_ARRAY_BUFFER$2, indices);
9692
+ gl.bindBuffer(ELEMENT_ARRAY_BUFFER, indices);
9527
9693
  }
9528
9694
  // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
9529
9695
  // like when creating buffers for other stuff will mess up this VAO's binding
@@ -9577,7 +9743,7 @@ var vertexArrays = /*#__PURE__*/Object.freeze({
9577
9743
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
9578
9744
  * DEALINGS IN THE SOFTWARE.
9579
9745
  */
9580
- const defaults$2 = {
9746
+ const defaults = {
9581
9747
  addExtensionsToContext: true,
9582
9748
  };
9583
9749
 
@@ -9652,9 +9818,9 @@ const defaults$2 = {
9652
9818
  * @param {module:twgl.Defaults} newDefaults The default settings.
9653
9819
  * @memberOf module:twgl
9654
9820
  */
9655
- function setDefaults$2(newDefaults) {
9656
- copyExistingProperties(newDefaults, defaults$2);
9657
- setDefaults(newDefaults); // eslint-disable-line
9821
+ function setDefaults(newDefaults) {
9822
+ copyExistingProperties(newDefaults, defaults);
9823
+ setDefaults$2(newDefaults); // eslint-disable-line
9658
9824
  setDefaults$1(newDefaults); // eslint-disable-line
9659
9825
  }
9660
9826
 
@@ -9678,7 +9844,7 @@ function addExtensionToContext(gl, extensionName) {
9678
9844
  }
9679
9845
  if (gl[name] !== undefined) {
9680
9846
  if (!isFunc && gl[name] !== value) {
9681
- warn(name, gl[name], value, key);
9847
+ warn$1(name, gl[name], value, key);
9682
9848
  }
9683
9849
  } else {
9684
9850
  if (isFunc) {
@@ -9806,7 +9972,7 @@ function create3DContext(canvas, opt_attribs) {
9806
9972
  for (let ii = 0; ii < names.length; ++ii) {
9807
9973
  context = canvas.getContext(names[ii], opt_attribs);
9808
9974
  if (context) {
9809
- if (defaults$2.addExtensionsToContext) {
9975
+ if (defaults.addExtensionsToContext) {
9810
9976
  addExtensionsToContext(context);
9811
9977
  }
9812
9978
  break;
@@ -9854,7 +10020,7 @@ function createContext(canvas, opt_attribs) {
9854
10020
  for (let ii = 0; ii < names.length; ++ii) {
9855
10021
  context = canvas.getContext(names[ii], opt_attribs);
9856
10022
  if (context) {
9857
- if (defaults$2.addExtensionsToContext) {
10023
+ if (defaults.addExtensionsToContext) {
9858
10024
  addExtensionsToContext(context);
9859
10025
  }
9860
10026
  break;
@@ -9906,4 +10072,4 @@ function resizeCanvasToDisplaySize(canvas, multiplier) {
9906
10072
  return false;
9907
10073
  }
9908
10074
 
9909
- export { addExtensionsToContext, attributes, bindFramebufferInfo, bindTransformFeedbackInfo, bindUniformBlock, canFilter, canGenerateMipmap, createAttribsFromArrays, createAttributeSetters, createBufferFromArray, createBufferFromTypedArray, createBufferInfoFromArrays, createBuffersFromArrays, createFramebufferInfo, createProgram, createProgramAsync, createProgramFromScripts, createProgramFromSources, createProgramInfo, createProgramInfoAsync, createProgramInfoFromProgram, createSampler, createSamplers, createTexture, createTextures, createTransformFeedback, createTransformFeedbackInfo, createUniformBlockInfo, createUniformBlockInfoFromProgram, createUniformBlockSpecFromProgram, createUniformSetters, createVAOAndSetAttributes, createVAOFromBufferInfo, createVertexArrayInfo, draw, drawBufferInfo, drawObjectList, framebuffers, getArray as getArray_, getBytesPerElementForInternalFormat, getContext, getFormatAndTypeForInternalFormat, getGLTypeForTypedArray, getGLTypeForTypedArrayType, getNumComponentsForFormat, getNumComponents as getNumComponents_, getTypedArrayTypeForGLType, getWebGLContext, glEnumToString, isArrayBuffer, isWebGL1, isWebGL2, loadTextureFromUrl, m4, primitives, programs, resizeCanvasToDisplaySize, resizeFramebufferInfo, resizeTexture, setAttribInfoBufferFromArray, setDefaults as setAttributeDefaults_, setAttributePrefix, setAttributes, setBlockUniforms, setBuffersAndAttributes, setDefaultTextureColor, setDefaults$2 as setDefaults, setEmptyTexture, setSamplerParameters, setDefaults$1 as setTextureDefaults_, setTextureFilteringForSize, setTextureFromArray, setTextureFromElement, setTextureParameters, setUniformBlock, setUniforms, setUniformsAndBindTextures, textures, typedarrays, utils, v3, vertexArrays };
10075
+ export { addExtensionsToContext, attributes, bindFramebufferInfo, bindTransformFeedbackInfo, bindUniformBlock, canFilter, canGenerateMipmap, createAttribsFromArrays, createAttributeSetters, createBufferFromArray, createBufferFromTypedArray, createBufferInfoFromArrays, createBuffersFromArrays, createFramebufferInfo, createProgram, createProgramAsync, createProgramFromScripts, createProgramFromSources, createProgramInfo, createProgramInfoAsync, createProgramInfoFromProgram, createProgramInfos, createProgramInfosAsync, createPrograms, createProgramsAsync, createSampler, createSamplers, createTexture, createTextures, createTransformFeedback, createTransformFeedbackInfo, createUniformBlockInfo, createUniformBlockInfoFromProgram, createUniformBlockSpecFromProgram, createUniformSetters, createVAOAndSetAttributes, createVAOFromBufferInfo, createVertexArrayInfo, draw, drawBufferInfo, drawObjectList, framebuffers, getArray$1 as getArray_, getBytesPerElementForInternalFormat, getContext, getFormatAndTypeForInternalFormat, getGLTypeForTypedArray, getGLTypeForTypedArrayType, getNumComponentsForFormat, getNumComponents$1 as getNumComponents_, getTypedArrayTypeForGLType, getWebGLContext, glEnumToString, isArrayBuffer$1 as isArrayBuffer, isWebGL1, isWebGL2, loadTextureFromUrl, m4, primitives, programs, resizeCanvasToDisplaySize, resizeFramebufferInfo, resizeTexture, setAttribInfoBufferFromArray, setDefaults$2 as setAttributeDefaults_, setAttributePrefix, setAttributes, setBlockUniforms, setBuffersAndAttributes, setDefaultTextureColor, setDefaults, setEmptyTexture, setSamplerParameters, setDefaults$1 as setTextureDefaults_, setTextureFilteringForSize, setTextureFromArray, setTextureFromElement, setTextureParameters, setUniformBlock, setUniforms, setUniformsAndBindTextures, textures, typedarrays, utils, v3, vertexArrays };