twgl.js 5.0.4 → 5.1.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.
package/dist/5.x/twgl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 5.0.4 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 5.1.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
3
3
  * Available via the MIT license.
4
4
  * see: http://github.com/greggman/twgl.js for details
5
5
  */
@@ -111,28 +111,22 @@ return /******/ (function(modules) { // webpackBootstrap
111
111
  "use strict";
112
112
 
113
113
 
114
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
115
-
114
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
116
115
  exports.__esModule = true;
117
116
  exports.createAttribsFromArrays = createAttribsFromArrays;
118
- exports.createBuffersFromArrays = createBuffersFromArrays;
119
117
  exports.createBufferFromArray = createBufferFromArray;
120
118
  exports.createBufferFromTypedArray = createBufferFromTypedArray;
121
119
  exports.createBufferInfoFromArrays = createBufferInfoFromArrays;
120
+ exports.createBuffersFromArrays = createBuffersFromArrays;
121
+ exports.getArray_ = getArray;
122
+ exports.getNumComponents_ = getNumComponents;
122
123
  exports.setAttribInfoBufferFromArray = setAttribInfoBufferFromArray;
123
- exports.setAttributePrefix = setAttributePrefix;
124
124
  exports.setAttributeDefaults_ = setDefaults;
125
- exports.getNumComponents_ = getNumComponents;
126
- exports.getArray_ = getArray;
127
-
125
+ exports.setAttributePrefix = setAttributePrefix;
128
126
  var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
129
-
130
127
  var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
131
-
132
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
133
-
134
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
135
-
128
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
129
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
136
130
  /*
137
131
  * Copyright 2019 Gregg Tavares
138
132
  *
@@ -154,6 +148,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
154
148
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
155
149
  * DEALINGS IN THE SOFTWARE.
156
150
  */
151
+
157
152
  var STATIC_DRAW = 0x88e4;
158
153
  var ARRAY_BUFFER = 0x8892;
159
154
  var ELEMENT_ARRAY_BUFFER = 0x8893;
@@ -165,6 +160,7 @@ var UNSIGNED_SHORT = 0x1403;
165
160
  var INT = 0x1404;
166
161
  var UNSIGNED_INT = 0x1405;
167
162
  var FLOAT = 0x1406;
163
+
168
164
  /**
169
165
  * Low level attribute and buffer related functions
170
166
  *
@@ -179,14 +175,13 @@ var FLOAT = 0x1406;
179
175
  *
180
176
  * @module twgl/attributes
181
177
  */
182
- // make sure we don't see a global gl
183
-
184
- var gl = undefined;
185
- /* eslint-disable-line */
186
178
 
179
+ // make sure we don't see a global gl
180
+ var gl = undefined; /* eslint-disable-line */
187
181
  var defaults = {
188
182
  attribPrefix: ""
189
183
  };
184
+
190
185
  /**
191
186
  * Sets the default attrib prefix
192
187
  *
@@ -207,19 +202,17 @@ var defaults = {
207
202
  * @param {string} prefix prefix for attribs
208
203
  * @memberOf module:twgl/attributes
209
204
  */
210
-
211
205
  function setAttributePrefix(prefix) {
212
206
  defaults.attribPrefix = prefix;
213
207
  }
214
-
215
208
  function setDefaults(newDefaults) {
216
209
  helper.copyExistingProperties(newDefaults, defaults);
217
210
  }
218
-
219
211
  function setBufferFromTypedArray(gl, type, buffer, array, drawType) {
220
212
  gl.bindBuffer(type, buffer);
221
213
  gl.bufferData(type, array, drawType || STATIC_DRAW);
222
214
  }
215
+
223
216
  /**
224
217
  * Given typed array creates a WebGLBuffer and copies the typed array
225
218
  * into it.
@@ -231,65 +224,37 @@ function setBufferFromTypedArray(gl, type, buffer, array, drawType) {
231
224
  * @return {WebGLBuffer} the created WebGLBuffer
232
225
  * @memberOf module:twgl/attributes
233
226
  */
234
-
235
-
236
227
  function createBufferFromTypedArray(gl, typedArray, type, drawType) {
237
228
  if (helper.isBuffer(gl, typedArray)) {
238
229
  return typedArray;
239
230
  }
240
-
241
231
  type = type || ARRAY_BUFFER;
242
232
  var buffer = gl.createBuffer();
243
233
  setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
244
234
  return buffer;
245
235
  }
246
-
247
236
  function isIndices(name) {
248
237
  return name === "indices";
249
- } // This is really just a guess. Though I can't really imagine using
250
- // anything else? Maybe for some compression?
251
-
252
-
253
- function getNormalizationForTypedArray(typedArray) {
254
- if (typedArray instanceof Int8Array) {
255
- return true;
256
- } // eslint-disable-line
257
-
258
-
259
- if (typedArray instanceof Uint8Array) {
260
- return true;
261
- } // eslint-disable-line
262
-
238
+ }
263
239
 
264
- return false;
265
- } // This is really just a guess. Though I can't really imagine using
240
+ // This is really just a guess. Though I can't really imagine using
266
241
  // anything else? Maybe for some compression?
267
-
268
-
269
242
  function getNormalizationForTypedArrayType(typedArrayType) {
270
243
  if (typedArrayType === Int8Array) {
271
244
  return true;
272
245
  } // eslint-disable-line
273
-
274
-
275
246
  if (typedArrayType === Uint8Array) {
276
247
  return true;
277
248
  } // eslint-disable-line
278
-
279
-
280
249
  return false;
281
250
  }
282
-
283
251
  function getArray(array) {
284
252
  return array.length ? array : array.data;
285
253
  }
286
-
287
254
  var texcoordRE = /coord|texture/i;
288
255
  var colorRE = /color|colour/i;
289
-
290
256
  function guessNumComponentsFromName(name, length) {
291
257
  var numComponents;
292
-
293
258
  if (texcoordRE.test(name)) {
294
259
  numComponents = 2;
295
260
  } else if (colorRE.test(name)) {
@@ -301,31 +266,24 @@ function guessNumComponentsFromName(name, length) {
301
266
  if (length % numComponents > 0) {
302
267
  throw new Error("Can not guess numComponents for attribute '".concat(name, "'. Tried ").concat(numComponents, " but ").concat(length, " values is not evenly divisible by ").concat(numComponents, ". You should specify it."));
303
268
  }
304
-
305
269
  return numComponents;
306
270
  }
307
-
308
- function getNumComponents(array, arrayName) {
309
- return array.numComponents || array.size || guessNumComponentsFromName(arrayName, getArray(array).length);
271
+ function getNumComponents(array, arrayName, numValues) {
272
+ return array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues || getArray(array).length);
310
273
  }
311
-
312
274
  function makeTypedArray(array, name) {
313
275
  if (typedArrays.isArrayBuffer(array)) {
314
276
  return array;
315
277
  }
316
-
317
278
  if (typedArrays.isArrayBuffer(array.data)) {
318
279
  return array.data;
319
280
  }
320
-
321
281
  if (Array.isArray(array)) {
322
282
  array = {
323
283
  data: array
324
284
  };
325
285
  }
326
-
327
- var Type = array.type;
328
-
286
+ var Type = array.type ? typedArrayTypeFromGLTypeOrTypedArrayCtor(array.type) : undefined;
329
287
  if (!Type) {
330
288
  if (isIndices(name)) {
331
289
  Type = Uint16Array;
@@ -333,9 +291,47 @@ function makeTypedArray(array, name) {
333
291
  Type = Float32Array;
334
292
  }
335
293
  }
336
-
337
294
  return new Type(array.data);
338
295
  }
296
+ function glTypeFromGLTypeOrTypedArrayType(glTypeOrTypedArrayCtor) {
297
+ return typeof glTypeOrTypedArrayCtor === 'number' ? glTypeOrTypedArrayCtor : glTypeOrTypedArrayCtor ? typedArrays.getGLTypeForTypedArrayType(glTypeOrTypedArrayCtor) : FLOAT;
298
+ }
299
+ function typedArrayTypeFromGLTypeOrTypedArrayCtor(glTypeOrTypedArrayCtor) {
300
+ return typeof glTypeOrTypedArrayCtor === 'number' ? typedArrays.getTypedArrayTypeForGLType(glTypeOrTypedArrayCtor) : glTypeOrTypedArrayCtor || Float32Array;
301
+ }
302
+ function attribBufferFromBuffer(gl, array /*, arrayName */) {
303
+ return {
304
+ buffer: array.buffer,
305
+ numValues: 2 * 3 * 4,
306
+ // safely divided by 2, 3, 4
307
+ type: glTypeFromGLTypeOrTypedArrayType(array.type),
308
+ arrayType: typedArrayTypeFromGLTypeOrTypedArrayCtor(array.type)
309
+ };
310
+ }
311
+ function attribBufferFromSize(gl, array /*, arrayName*/) {
312
+ var numValues = array.data || array;
313
+ var arrayType = typedArrayTypeFromGLTypeOrTypedArrayCtor(array.type);
314
+ var numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
315
+ var buffer = gl.createBuffer();
316
+ gl.bindBuffer(ARRAY_BUFFER, buffer);
317
+ gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);
318
+ return {
319
+ buffer: buffer,
320
+ numValues: numValues,
321
+ type: typedArrays.getGLTypeForTypedArrayType(arrayType),
322
+ arrayType: arrayType
323
+ };
324
+ }
325
+ function attribBufferFromArrayLike(gl, array, arrayName) {
326
+ var typedArray = makeTypedArray(array, arrayName);
327
+ return {
328
+ arrayType: typedArray.constructor,
329
+ buffer: createBufferFromTypedArray(gl, typedArray, undefined, array.drawType),
330
+ type: typedArrays.getGLTypeForTypedArray(typedArray),
331
+ numValues: 0
332
+ };
333
+ }
334
+
339
335
  /**
340
336
  * The info for an attribute. This is effectively just the arguments to `gl.vertexAttribPointer` plus the WebGLBuffer
341
337
  * for the attribute.
@@ -351,24 +347,29 @@ function makeTypedArray(array, name) {
351
347
  * @property {number} [stride] the stride in bytes per element. Default = 0
352
348
  * @property {number} [divisor] the divisor in instances. Default = 0.
353
349
  * Requires WebGL2 or the ANGLE_instanced_arrays extension.
354
- * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
350
+ * and, if you're using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
355
351
  * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
356
352
  * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
357
353
  * @memberOf module:twgl
358
354
  */
359
355
 
356
+ /**
357
+ * @typedef {(Int8ArrayConstructor|Uint8ArrayConstructor|Int16ArrayConstructor|Uint16ArrayConstructor|Int32ArrayConstructor|Uint32ArrayConstructor|Float32ArrayConstructor)} TypedArrayConstructor
358
+ */
359
+
360
360
  /**
361
361
  * Use this type of array spec when TWGL can't guess the type or number of components of an array
362
362
  * @typedef {Object} FullArraySpec
363
363
  * @property {number[]|ArrayBufferView} [value] a constant value for the attribute. Note: if this is set the attribute will be
364
364
  * disabled and set to this constant value and all other values will be ignored.
365
- * @property {(number|number[]|ArrayBufferView)} data The data of the array. A number alone becomes the number of elements of type.
365
+ * @property {(number|number[]|ArrayBufferView)} [data] The data of the array. A number alone becomes the number of elements of type.
366
366
  * @property {number} [numComponents] number of components for `vertexAttribPointer`. Default is based on the name of the array.
367
367
  * If `coord` is in the name assumes `numComponents = 2`.
368
368
  * If `color` is in the name assumes `numComponents = 4`.
369
369
  * otherwise assumes `numComponents = 3`
370
- * @property {constructor} [type] type. This is only used if `data` is a JavaScript array. It is the constructor for the typedarray. (eg. `Uint8Array`).
371
- * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: Uint8Array, data: [255,0,255,255, ...], }`.
370
+ * @property {number|TypedArrayConstructor} [type] type. This is used if `data` is a JavaScript array, or `buffer` is passed in, or `data` is a number.
371
+ * It can either be the constructor for a typedarray. (eg. `Uint8Array`) OR a WebGL type, (eg `gl.UNSIGNED_BYTE`).
372
+ * For example if you want colors in a `Uint8Array` you might have a `FullArraySpec` like `{ type: gl.UNSIGNED_BYTE, data: [255,0,255,255, ...], }`.
372
373
  * @property {number} [size] synonym for `numComponents`.
373
374
  * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
374
375
  * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
@@ -503,52 +504,35 @@ function makeTypedArray(array, name) {
503
504
  * @return {Object.<string, module:twgl.AttribInfo>} the attribs
504
505
  * @memberOf module:twgl/attributes
505
506
  */
506
-
507
-
508
507
  function createAttribsFromArrays(gl, arrays) {
509
508
  var attribs = {};
510
509
  Object.keys(arrays).forEach(function (arrayName) {
511
510
  if (!isIndices(arrayName)) {
512
511
  var array = arrays[arrayName];
513
512
  var attribName = array.attrib || array.name || array.attribName || defaults.attribPrefix + arrayName;
514
-
515
513
  if (array.value) {
516
514
  if (!Array.isArray(array.value) && !typedArrays.isArrayBuffer(array.value)) {
517
515
  throw new Error('array.value is not array or typedarray');
518
516
  }
519
-
520
517
  attribs[attribName] = {
521
518
  value: array.value
522
519
  };
523
520
  } else {
524
- var buffer;
525
- var type;
526
- var normalization;
527
- var numComponents;
528
-
521
+ var fn;
529
522
  if (array.buffer && array.buffer instanceof WebGLBuffer) {
530
- buffer = array.buffer;
531
- numComponents = array.numComponents || array.size;
532
- type = array.type;
533
- normalization = array.normalize;
523
+ fn = attribBufferFromBuffer;
534
524
  } else if (typeof array === "number" || typeof array.data === "number") {
535
- var numValues = array.data || array;
536
- var arrayType = array.type || Float32Array;
537
- var numBytes = numValues * arrayType.BYTES_PER_ELEMENT;
538
- type = typedArrays.getGLTypeForTypedArrayType(arrayType);
539
- normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
540
- numComponents = array.numComponents || array.size || guessNumComponentsFromName(arrayName, numValues);
541
- buffer = gl.createBuffer();
542
- gl.bindBuffer(ARRAY_BUFFER, buffer);
543
- gl.bufferData(ARRAY_BUFFER, numBytes, array.drawType || STATIC_DRAW);
525
+ fn = attribBufferFromSize;
544
526
  } else {
545
- var typedArray = makeTypedArray(array, arrayName);
546
- buffer = createBufferFromTypedArray(gl, typedArray, undefined, array.drawType);
547
- type = typedArrays.getGLTypeForTypedArray(typedArray);
548
- normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArray(typedArray);
549
- numComponents = getNumComponents(array, arrayName);
527
+ fn = attribBufferFromArrayLike;
550
528
  }
551
-
529
+ var _fn = fn(gl, array, arrayName),
530
+ buffer = _fn.buffer,
531
+ type = _fn.type,
532
+ numValues = _fn.numValues,
533
+ arrayType = _fn.arrayType;
534
+ var normalization = array.normalize !== undefined ? array.normalize : getNormalizationForTypedArrayType(arrayType);
535
+ var numComponents = getNumComponents(array, arrayName, numValues);
552
536
  attribs[attribName] = {
553
537
  buffer: buffer,
554
538
  numComponents: numComponents,
@@ -565,6 +549,7 @@ function createAttribsFromArrays(gl, arrays) {
565
549
  gl.bindBuffer(ARRAY_BUFFER, null);
566
550
  return attribs;
567
551
  }
552
+
568
553
  /**
569
554
  * Sets the contents of a buffer attached to an attribInfo
570
555
  *
@@ -601,11 +586,8 @@ function createAttribsFromArrays(gl, arrays) {
601
586
  * Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
602
587
  * @memberOf module:twgl/attributes
603
588
  */
604
-
605
-
606
589
  function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
607
590
  array = makeTypedArray(array);
608
-
609
591
  if (offset !== undefined) {
610
592
  gl.bindBuffer(ARRAY_BUFFER, attribInfo.buffer);
611
593
  gl.bufferSubData(ARRAY_BUFFER, offset, array);
@@ -613,85 +595,61 @@ function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
613
595
  setBufferFromTypedArray(gl, ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
614
596
  }
615
597
  }
616
-
617
598
  function getBytesPerValueForGLType(gl, type) {
618
599
  if (type === BYTE) return 1; // eslint-disable-line
619
-
620
600
  if (type === UNSIGNED_BYTE) return 1; // eslint-disable-line
621
-
622
601
  if (type === SHORT) return 2; // eslint-disable-line
623
-
624
602
  if (type === UNSIGNED_SHORT) return 2; // eslint-disable-line
625
-
626
603
  if (type === INT) return 4; // eslint-disable-line
627
-
628
604
  if (type === UNSIGNED_INT) return 4; // eslint-disable-line
629
-
630
605
  if (type === FLOAT) return 4; // eslint-disable-line
631
-
632
606
  return 0;
633
- } // Tries to get the number of elements from a set of arrays.
634
-
607
+ }
635
608
 
609
+ // Tries to get the number of elements from a set of arrays.
636
610
  var positionKeys = ['position', 'positions', 'a_position'];
637
-
638
611
  function getNumElementsFromNonIndexedArrays(arrays) {
639
612
  var key;
640
613
  var ii;
641
-
642
614
  for (ii = 0; ii < positionKeys.length; ++ii) {
643
615
  key = positionKeys[ii];
644
-
645
616
  if (key in arrays) {
646
617
  break;
647
618
  }
648
619
  }
649
-
650
620
  if (ii === positionKeys.length) {
651
621
  key = Object.keys(arrays)[0];
652
622
  }
653
-
654
623
  var array = arrays[key];
655
624
  var length = getArray(array).length;
656
-
657
625
  if (length === undefined) {
658
626
  return 1; // There's no arrays
659
627
  }
660
628
 
661
629
  var numComponents = getNumComponents(array, key);
662
630
  var numElements = length / numComponents;
663
-
664
631
  if (length % numComponents > 0) {
665
632
  throw new Error("numComponents ".concat(numComponents, " not correct for length ").concat(length));
666
633
  }
667
-
668
634
  return numElements;
669
635
  }
670
-
671
636
  function getNumElementsFromAttributes(gl, attribs) {
672
637
  var key;
673
638
  var ii;
674
-
675
639
  for (ii = 0; ii < positionKeys.length; ++ii) {
676
640
  key = positionKeys[ii];
677
-
678
641
  if (key in attribs) {
679
642
  break;
680
643
  }
681
-
682
644
  key = defaults.attribPrefix + key;
683
-
684
645
  if (key in attribs) {
685
646
  break;
686
647
  }
687
648
  }
688
-
689
649
  if (ii === positionKeys.length) {
690
650
  key = Object.keys(attribs)[0];
691
651
  }
692
-
693
652
  var attrib = attribs[key];
694
-
695
653
  if (!attrib.buffer) {
696
654
  return 1; // There's no buffer
697
655
  }
@@ -701,16 +659,15 @@ function getNumElementsFromAttributes(gl, attribs) {
701
659
  gl.bindBuffer(ARRAY_BUFFER, null);
702
660
  var bytesPerValue = getBytesPerValueForGLType(gl, attrib.type);
703
661
  var totalElements = numBytes / bytesPerValue;
704
- var numComponents = attrib.numComponents || attrib.size; // TODO: check stride
705
-
662
+ var numComponents = attrib.numComponents || attrib.size;
663
+ // TODO: check stride
706
664
  var numElements = totalElements / numComponents;
707
-
708
665
  if (numElements % 1 !== 0) {
709
666
  throw new Error("numComponents ".concat(numComponents, " not correct for length ").concat(length));
710
667
  }
711
-
712
668
  return numElements;
713
669
  }
670
+
714
671
  /**
715
672
  * @typedef {Object} BufferInfo
716
673
  * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
@@ -816,14 +773,11 @@ function getNumElementsFromAttributes(gl, attribs) {
816
773
  * @return {module:twgl.BufferInfo} A BufferInfo
817
774
  * @memberOf module:twgl/attributes
818
775
  */
819
-
820
-
821
776
  function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
822
777
  var newAttribs = createAttribsFromArrays(gl, arrays);
823
778
  var bufferInfo = Object.assign({}, srcBufferInfo ? srcBufferInfo : {});
824
779
  bufferInfo.attribs = Object.assign({}, srcBufferInfo ? srcBufferInfo.attribs : {}, newAttribs);
825
780
  var indices = arrays.indices;
826
-
827
781
  if (indices) {
828
782
  var newIndices = makeTypedArray(indices, "indices");
829
783
  bufferInfo.indices = createBufferFromTypedArray(gl, newIndices, ELEMENT_ARRAY_BUFFER);
@@ -832,9 +786,9 @@ function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
832
786
  } else if (!bufferInfo.numElements) {
833
787
  bufferInfo.numElements = getNumElementsFromAttributes(gl, bufferInfo.attribs);
834
788
  }
835
-
836
789
  return bufferInfo;
837
790
  }
791
+
838
792
  /**
839
793
  * Creates a buffer from an array, typed array, or array spec
840
794
  *
@@ -861,13 +815,12 @@ function createBufferInfoFromArrays(gl, arrays, srcBufferInfo) {
861
815
  * @return {WebGLBuffer} a WebGLBuffer containing the data in array.
862
816
  * @memberOf module:twgl/attributes
863
817
  */
864
-
865
-
866
818
  function createBufferFromArray(gl, array, arrayName) {
867
819
  var type = arrayName === "indices" ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER;
868
820
  var typedArray = makeTypedArray(array, arrayName);
869
821
  return createBufferFromTypedArray(gl, typedArray, type);
870
822
  }
823
+
871
824
  /**
872
825
  * Creates buffers from arrays or typed arrays
873
826
  *
@@ -892,21 +845,19 @@ function createBufferFromArray(gl, array, arrayName) {
892
845
  * @return {Object<string, WebGLBuffer>} returns an object with one WebGLBuffer per array
893
846
  * @memberOf module:twgl/attributes
894
847
  */
895
-
896
-
897
848
  function createBuffersFromArrays(gl, arrays) {
898
849
  var buffers = {};
899
850
  Object.keys(arrays).forEach(function (key) {
900
851
  buffers[key] = createBufferFromArray(gl, arrays[key], key);
901
- }); // Ugh!
852
+ });
902
853
 
854
+ // Ugh!
903
855
  if (arrays.indices) {
904
856
  buffers.numElements = arrays.indices.length;
905
857
  buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');
906
858
  } else {
907
859
  buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
908
860
  }
909
-
910
861
  return buffers;
911
862
  }
912
863
 
@@ -922,18 +873,13 @@ function createBuffersFromArrays(gl, arrays) {
922
873
  "use strict";
923
874
 
924
875
 
925
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
926
-
876
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
927
877
  exports.__esModule = true;
928
878
  exports.drawBufferInfo = drawBufferInfo;
929
879
  exports.drawObjectList = drawObjectList;
930
-
931
880
  var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
932
-
933
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
934
-
935
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
936
-
881
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
882
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
937
883
  /*
938
884
  * Copyright 2019 Gregg Tavares
939
885
  *
@@ -955,8 +901,10 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
955
901
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
956
902
  * DEALINGS IN THE SOFTWARE.
957
903
  */
904
+
958
905
  var TRIANGLES = 0x0004;
959
906
  var UNSIGNED_SHORT = 0x1403;
907
+
960
908
  /**
961
909
  * Drawing related functions
962
910
  *
@@ -984,14 +932,12 @@ var UNSIGNED_SHORT = 0x1403;
984
932
  * @param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
985
933
  * @memberOf module:twgl/draw
986
934
  */
987
-
988
935
  function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
989
936
  type = type === undefined ? TRIANGLES : type;
990
937
  var indices = bufferInfo.indices;
991
938
  var elementType = bufferInfo.elementType;
992
939
  var numElements = count === undefined ? bufferInfo.numElements : count;
993
940
  offset = offset === undefined ? 0 : offset;
994
-
995
941
  if (elementType || indices) {
996
942
  if (instanceCount !== undefined) {
997
943
  gl.drawElementsInstanced(type, numElements, elementType === undefined ? UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
@@ -1006,6 +952,7 @@ function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
1006
952
  }
1007
953
  }
1008
954
  }
955
+
1009
956
  /**
1010
957
  * A DrawObject is useful for putting objects in to an array and passing them to {@link module:twgl.drawObjectList}.
1011
958
  *
@@ -1048,8 +995,6 @@ function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
1048
995
  * @param {DrawObject[]} objectsToDraw an array of objects to draw.
1049
996
  * @memberOf module:twgl/draw
1050
997
  */
1051
-
1052
-
1053
998
  function drawObjectList(gl, objectsToDraw) {
1054
999
  var lastUsedProgramInfo = null;
1055
1000
  var lastUsedBufferInfo = null;
@@ -1057,38 +1002,36 @@ function drawObjectList(gl, objectsToDraw) {
1057
1002
  if (object.active === false) {
1058
1003
  return;
1059
1004
  }
1060
-
1061
1005
  var programInfo = object.programInfo;
1062
1006
  var bufferInfo = object.vertexArrayInfo || object.bufferInfo;
1063
1007
  var bindBuffers = false;
1064
1008
  var type = object.type === undefined ? TRIANGLES : object.type;
1065
-
1066
1009
  if (programInfo !== lastUsedProgramInfo) {
1067
1010
  lastUsedProgramInfo = programInfo;
1068
- gl.useProgram(programInfo.program); // We have to rebind buffers when changing programs because we
1011
+ gl.useProgram(programInfo.program);
1012
+
1013
+ // We have to rebind buffers when changing programs because we
1069
1014
  // only bind buffers the program uses. So if 2 programs use the same
1070
1015
  // bufferInfo but the 1st one uses only positions the when the
1071
1016
  // we switch to the 2nd one some of the attributes will not be on.
1072
-
1073
1017
  bindBuffers = true;
1074
- } // Setup all the needed attributes.
1075
-
1018
+ }
1076
1019
 
1020
+ // Setup all the needed attributes.
1077
1021
  if (bindBuffers || bufferInfo !== lastUsedBufferInfo) {
1078
1022
  if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject && !bufferInfo.vertexArrayObject) {
1079
1023
  gl.bindVertexArray(null);
1080
1024
  }
1081
-
1082
1025
  lastUsedBufferInfo = bufferInfo;
1083
1026
  programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);
1084
- } // Set the uniforms.
1085
-
1027
+ }
1086
1028
 
1087
- programs.setUniforms(programInfo, object.uniforms); // Draw
1029
+ // Set the uniforms.
1030
+ programs.setUniforms(programInfo, object.uniforms);
1088
1031
 
1032
+ // Draw
1089
1033
  drawBufferInfo(gl, bufferInfo, type, object.count, object.offset, object.instanceCount);
1090
1034
  });
1091
-
1092
1035
  if (lastUsedBufferInfo && lastUsedBufferInfo.vertexArrayObject) {
1093
1036
  gl.bindVertexArray(null);
1094
1037
  }
@@ -1106,21 +1049,15 @@ function drawObjectList(gl, objectsToDraw) {
1106
1049
  "use strict";
1107
1050
 
1108
1051
 
1109
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
1110
-
1052
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1111
1053
  exports.__esModule = true;
1112
1054
  exports.bindFramebufferInfo = bindFramebufferInfo;
1113
1055
  exports.createFramebufferInfo = createFramebufferInfo;
1114
1056
  exports.resizeFramebufferInfo = resizeFramebufferInfo;
1115
-
1116
1057
  var textures = _interopRequireWildcard(__webpack_require__(/*! ./textures.js */ "./src/textures.js"));
1117
-
1118
1058
  var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
1119
-
1120
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
1121
-
1122
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1123
-
1059
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1060
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1124
1061
  /*
1125
1062
  * Copyright 2019 Gregg Tavares
1126
1063
  *
@@ -1153,24 +1090,24 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
1153
1090
  *
1154
1091
  * @module twgl/framebuffers
1155
1092
  */
1093
+
1156
1094
  // make sure we don't see a global gl
1157
- var gl = undefined;
1158
- /* eslint-disable-line */
1095
+ var gl = undefined; /* eslint-disable-line */
1159
1096
 
1160
1097
  var FRAMEBUFFER = 0x8d40;
1161
1098
  var RENDERBUFFER = 0x8d41;
1162
1099
  var TEXTURE_2D = 0x0de1;
1163
1100
  var UNSIGNED_BYTE = 0x1401;
1164
- /* PixelFormat */
1165
1101
 
1102
+ /* PixelFormat */
1166
1103
  var DEPTH_COMPONENT = 0x1902;
1167
1104
  var RGBA = 0x1908;
1168
1105
  var DEPTH_COMPONENT24 = 0x81a6;
1169
1106
  var DEPTH_COMPONENT32F = 0x8cac;
1170
1107
  var DEPTH24_STENCIL8 = 0x88f0;
1171
1108
  var DEPTH32F_STENCIL8 = 0x8cad;
1172
- /* Framebuffer Object. */
1173
1109
 
1110
+ /* Framebuffer Object. */
1174
1111
  var RGBA4 = 0x8056;
1175
1112
  var RGB5_A1 = 0x8057;
1176
1113
  var RGB565 = 0x8D62;
@@ -1182,12 +1119,13 @@ var COLOR_ATTACHMENT0 = 0x8CE0;
1182
1119
  var DEPTH_ATTACHMENT = 0x8D00;
1183
1120
  var STENCIL_ATTACHMENT = 0x8D20;
1184
1121
  var DEPTH_STENCIL_ATTACHMENT = 0x821A;
1185
- /* TextureWrapMode */
1186
1122
 
1123
+ /* TextureWrapMode */
1187
1124
  var CLAMP_TO_EDGE = 0x812F;
1188
- /* TextureMagFilter */
1189
1125
 
1126
+ /* TextureMagFilter */
1190
1127
  var LINEAR = 0x2601;
1128
+
1191
1129
  /**
1192
1130
  * The options for a framebuffer attachment.
1193
1131
  *
@@ -1238,11 +1176,9 @@ attachmentsByFormat[DEPTH_COMPONENT24] = DEPTH_ATTACHMENT;
1238
1176
  attachmentsByFormat[DEPTH_COMPONENT32F] = DEPTH_ATTACHMENT;
1239
1177
  attachmentsByFormat[DEPTH24_STENCIL8] = DEPTH_STENCIL_ATTACHMENT;
1240
1178
  attachmentsByFormat[DEPTH32F_STENCIL8] = DEPTH_STENCIL_ATTACHMENT;
1241
-
1242
1179
  function getAttachmentPointForFormat(format, internalFormat) {
1243
1180
  return attachmentsByFormat[format] || attachmentsByFormat[internalFormat];
1244
1181
  }
1245
-
1246
1182
  var renderbufferFormats = {};
1247
1183
  renderbufferFormats[RGBA4] = true;
1248
1184
  renderbufferFormats[RGB5_A1] = true;
@@ -1251,16 +1187,15 @@ renderbufferFormats[DEPTH_STENCIL] = true;
1251
1187
  renderbufferFormats[DEPTH_COMPONENT16] = true;
1252
1188
  renderbufferFormats[STENCIL_INDEX] = true;
1253
1189
  renderbufferFormats[STENCIL_INDEX8] = true;
1254
-
1255
1190
  function isRenderbufferFormat(format) {
1256
1191
  return renderbufferFormats[format];
1257
1192
  }
1258
-
1259
1193
  var MAX_COLOR_ATTACHMENT_POINTS = 32; // even an 3090 only supports 8 but WebGL/OpenGL ES define constants for 32
1260
1194
 
1261
1195
  function isColorAttachmentPoint(attachmentPoint) {
1262
1196
  return attachmentPoint >= COLOR_ATTACHMENT0 && attachmentPoint < COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENT_POINTS;
1263
1197
  }
1198
+
1264
1199
  /**
1265
1200
  * @typedef {Object} FramebufferInfo
1266
1201
  * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
@@ -1309,8 +1244,6 @@ function isColorAttachmentPoint(attachmentPoint) {
1309
1244
  * @return {module:twgl.FramebufferInfo} the framebuffer and attachments.
1310
1245
  * @memberOf module:twgl/framebuffers
1311
1246
  */
1312
-
1313
-
1314
1247
  function createFramebufferInfo(gl, attachments, width, height) {
1315
1248
  var target = FRAMEBUFFER;
1316
1249
  var fb = gl.createFramebuffer();
@@ -1330,20 +1263,16 @@ function createFramebufferInfo(gl, attachments, width, height) {
1330
1263
  var samples = attachmentOptions.samples;
1331
1264
  var format = attachmentOptions.format;
1332
1265
  var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
1333
-
1334
1266
  if (!attachmentPoint) {
1335
1267
  attachmentPoint = COLOR_ATTACHMENT0 + i;
1336
1268
  }
1337
-
1338
1269
  if (isColorAttachmentPoint(attachmentPoint)) {
1339
1270
  usedColorAttachmentsPoints.push(attachmentPoint);
1340
1271
  }
1341
-
1342
1272
  if (!attachment) {
1343
1273
  if (samples !== undefined || isRenderbufferFormat(format)) {
1344
1274
  attachment = gl.createRenderbuffer();
1345
1275
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1346
-
1347
1276
  if (samples > 1) {
1348
1277
  gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1349
1278
  } else {
@@ -1353,7 +1282,6 @@ function createFramebufferInfo(gl, attachments, width, height) {
1353
1282
  var textureOptions = Object.assign({}, attachmentOptions);
1354
1283
  textureOptions.width = width;
1355
1284
  textureOptions.height = height;
1356
-
1357
1285
  if (textureOptions.auto === undefined) {
1358
1286
  textureOptions.auto = false;
1359
1287
  textureOptions.min = textureOptions.min || textureOptions.minMag || LINEAR;
@@ -1361,11 +1289,9 @@ function createFramebufferInfo(gl, attachments, width, height) {
1361
1289
  textureOptions.wrapS = textureOptions.wrapS || textureOptions.wrap || CLAMP_TO_EDGE;
1362
1290
  textureOptions.wrapT = textureOptions.wrapT || textureOptions.wrap || CLAMP_TO_EDGE;
1363
1291
  }
1364
-
1365
1292
  attachment = textures.createTexture(gl, textureOptions);
1366
1293
  }
1367
1294
  }
1368
-
1369
1295
  if (helper.isRenderbuffer(gl, attachment)) {
1370
1296
  gl.framebufferRenderbuffer(target, attachmentPoint, RENDERBUFFER, attachment);
1371
1297
  } else if (helper.isTexture(gl, attachment)) {
@@ -1377,16 +1303,14 @@ function createFramebufferInfo(gl, attachments, width, height) {
1377
1303
  } else {
1378
1304
  throw new Error('unknown attachment type');
1379
1305
  }
1380
-
1381
1306
  framebufferInfo.attachments.push(attachment);
1382
1307
  });
1383
-
1384
1308
  if (gl.drawBuffers) {
1385
1309
  gl.drawBuffers(usedColorAttachmentsPoints);
1386
1310
  }
1387
-
1388
1311
  return framebufferInfo;
1389
1312
  }
1313
+
1390
1314
  /**
1391
1315
  * Resizes the attachments of a framebuffer.
1392
1316
  *
@@ -1430,8 +1354,6 @@ function createFramebufferInfo(gl, attachments, width, height) {
1430
1354
  * @param {number} [height] the height for the attachments. Default = size of drawingBuffer
1431
1355
  * @memberOf module:twgl/framebuffers
1432
1356
  */
1433
-
1434
-
1435
1357
  function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height) {
1436
1358
  width = width || gl.drawingBufferWidth;
1437
1359
  height = height || gl.drawingBufferHeight;
@@ -1442,10 +1364,8 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
1442
1364
  var attachment = framebufferInfo.attachments[ndx];
1443
1365
  var format = attachmentOptions.format;
1444
1366
  var samples = attachmentOptions.samples;
1445
-
1446
1367
  if (samples !== undefined || helper.isRenderbuffer(gl, attachment)) {
1447
1368
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1448
-
1449
1369
  if (samples > 1) {
1450
1370
  gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1451
1371
  } else {
@@ -1458,6 +1378,7 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
1458
1378
  }
1459
1379
  });
1460
1380
  }
1381
+
1461
1382
  /**
1462
1383
  * Binds a framebuffer
1463
1384
  *
@@ -1478,10 +1399,8 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
1478
1399
  * @memberOf module:twgl/framebuffers
1479
1400
  */
1480
1401
 
1481
-
1482
1402
  function bindFramebufferInfo(gl, framebufferInfo, target) {
1483
1403
  target = target || FRAMEBUFFER;
1484
-
1485
1404
  if (framebufferInfo) {
1486
1405
  gl.bindFramebuffer(target, framebufferInfo.framebuffer);
1487
1406
  gl.viewport(0, 0, framebufferInfo.width, framebufferInfo.height);
@@ -1507,15 +1426,13 @@ exports.__esModule = true;
1507
1426
  exports.copyExistingProperties = copyExistingProperties;
1508
1427
  exports.copyNamedProperties = copyNamedProperties;
1509
1428
  exports.error = error;
1510
- exports.warn = warn;
1511
1429
  exports.isBuffer = isBuffer;
1512
1430
  exports.isRenderbuffer = isRenderbuffer;
1431
+ exports.isSampler = isSampler;
1513
1432
  exports.isShader = isShader;
1514
1433
  exports.isTexture = isTexture;
1515
- exports.isSampler = isSampler;
1516
-
1517
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
1518
-
1434
+ exports.warn = warn;
1435
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1519
1436
  /*
1520
1437
  * Copyright 2019 Gregg Tavares
1521
1438
  *
@@ -1551,12 +1468,12 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
1551
1468
  function copyNamedProperties(names, src, dst) {
1552
1469
  names.forEach(function (name) {
1553
1470
  var value = src[name];
1554
-
1555
1471
  if (value !== undefined) {
1556
1472
  dst[name] = value;
1557
1473
  }
1558
1474
  });
1559
1475
  }
1476
+
1560
1477
  /**
1561
1478
  * Copies properties from source to dest only if a matching key is in dest
1562
1479
  *
@@ -1564,8 +1481,6 @@ function copyNamedProperties(names, src, dst) {
1564
1481
  * @param {Object.<string, ?>} dst the dest
1565
1482
  * @private
1566
1483
  */
1567
-
1568
-
1569
1484
  function copyExistingProperties(src, dst) {
1570
1485
  Object.keys(dst).forEach(function (key) {
1571
1486
  if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
@@ -1574,60 +1489,44 @@ function copyExistingProperties(src, dst) {
1574
1489
  }
1575
1490
  });
1576
1491
  }
1577
-
1578
1492
  function error() {
1579
1493
  var _console;
1580
-
1581
1494
  (_console = console).error.apply(_console, arguments);
1582
1495
  }
1583
-
1584
1496
  function warn() {
1585
1497
  var _console2;
1586
-
1587
1498
  (_console2 = console).warn.apply(_console2, arguments);
1588
1499
  }
1589
-
1590
1500
  var isTypeWeakMaps = new Map();
1591
-
1592
1501
  function isType(object, type) {
1593
1502
  if (!object || _typeof(object) !== 'object') {
1594
1503
  return false;
1595
1504
  }
1596
-
1597
1505
  var weakMap = isTypeWeakMaps.get(type);
1598
-
1599
1506
  if (!weakMap) {
1600
1507
  weakMap = new WeakMap();
1601
1508
  isTypeWeakMaps.set(type, weakMap);
1602
1509
  }
1603
-
1604
1510
  var isOfType = weakMap.get(object);
1605
-
1606
1511
  if (isOfType === undefined) {
1607
1512
  var s = Object.prototype.toString.call(object);
1608
1513
  isOfType = s.substring(8, s.length - 1) === type;
1609
1514
  weakMap.set(object, isOfType);
1610
1515
  }
1611
-
1612
1516
  return isOfType;
1613
1517
  }
1614
-
1615
1518
  function isBuffer(gl, t) {
1616
1519
  return typeof WebGLBuffer !== 'undefined' && isType(t, 'WebGLBuffer');
1617
1520
  }
1618
-
1619
1521
  function isRenderbuffer(gl, t) {
1620
1522
  return typeof WebGLRenderbuffer !== 'undefined' && isType(t, 'WebGLRenderbuffer');
1621
1523
  }
1622
-
1623
1524
  function isShader(gl, t) {
1624
1525
  return typeof WebGLShader !== 'undefined' && isType(t, 'WebGLShader');
1625
1526
  }
1626
-
1627
1527
  function isTexture(gl, t) {
1628
1528
  return typeof WebGLTexture !== 'undefined' && isType(t, 'WebGLTexture');
1629
1529
  }
1630
-
1631
1530
  function isSampler(gl, t) {
1632
1531
  return typeof WebGLSampler !== 'undefined' && isType(t, 'WebGLSampler');
1633
1532
  }
@@ -1644,9 +1543,10 @@ function isSampler(gl, t) {
1644
1543
  "use strict";
1645
1544
 
1646
1545
 
1647
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
1648
-
1546
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1649
1547
  exports.__esModule = true;
1548
+ exports.bindTransformFeedbackInfo = bindTransformFeedbackInfo;
1549
+ exports.bindUniformBlock = bindUniformBlock;
1650
1550
  exports.createAttributeSetters = createAttributeSetters;
1651
1551
  exports.createProgram = createProgram;
1652
1552
  exports.createProgramAsync = createProgramAsync;
@@ -1655,45 +1555,31 @@ exports.createProgramFromSources = createProgramFromSources;
1655
1555
  exports.createProgramInfo = createProgramInfo;
1656
1556
  exports.createProgramInfoAsync = createProgramInfoAsync;
1657
1557
  exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
1658
- exports.createUniformSetters = createUniformSetters;
1659
- exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
1660
- exports.createUniformBlockInfoFromProgram = createUniformBlockInfoFromProgram;
1661
- exports.createUniformBlockInfo = createUniformBlockInfo;
1662
1558
  exports.createTransformFeedback = createTransformFeedback;
1663
1559
  exports.createTransformFeedbackInfo = createTransformFeedbackInfo;
1664
- exports.bindTransformFeedbackInfo = bindTransformFeedbackInfo;
1560
+ exports.createUniformBlockInfo = createUniformBlockInfo;
1561
+ exports.createUniformBlockInfoFromProgram = createUniformBlockInfoFromProgram;
1562
+ exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
1563
+ exports.createUniformSetters = createUniformSetters;
1665
1564
  exports.setAttributes = setAttributes;
1565
+ exports.setBlockUniforms = setBlockUniforms;
1666
1566
  exports.setBuffersAndAttributes = setBuffersAndAttributes;
1667
- exports.setUniforms = setUniforms;
1668
1567
  exports.setUniformBlock = setUniformBlock;
1669
- exports.setBlockUniforms = setBlockUniforms;
1670
- exports.bindUniformBlock = bindUniformBlock;
1568
+ exports.setUniforms = setUniforms;
1671
1569
  exports.setUniformsAndBindTextures = void 0;
1672
-
1673
1570
  var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
1674
-
1675
1571
  var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
1676
-
1677
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
1678
-
1679
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1680
-
1572
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
1573
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
1574
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
1681
1575
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
1682
-
1683
1576
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
1684
-
1685
1577
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
1686
-
1687
1578
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1688
-
1689
1579
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
1690
-
1691
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
1692
-
1580
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
1693
1581
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
1694
-
1695
1582
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1696
-
1697
1583
  /**
1698
1584
  * Low level shader program related functions
1699
1585
  *
@@ -1708,13 +1594,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
1708
1594
  *
1709
1595
  * @module twgl/programs
1710
1596
  */
1597
+
1711
1598
  var error = helper.error;
1712
1599
  var warn = helper.warn;
1713
-
1714
1600
  function getElementById(id) {
1715
1601
  return typeof document !== 'undefined' && document.getElementById ? document.getElementById(id) : null;
1716
1602
  }
1717
-
1718
1603
  var TEXTURE0 = 0x84c0;
1719
1604
  var DYNAMIC_DRAW = 0x88e8;
1720
1605
  var ARRAY_BUFFER = 0x8892;
@@ -1780,167 +1665,143 @@ var TEXTURE_CUBE_MAP = 0x8513;
1780
1665
  var TEXTURE_3D = 0x806F;
1781
1666
  var TEXTURE_2D_ARRAY = 0x8C1A;
1782
1667
  var typeMap = {};
1668
+
1783
1669
  /**
1784
1670
  * Returns the corresponding bind point for a given sampler type
1785
1671
  * @private
1786
1672
  */
1787
-
1788
1673
  function getBindPointForSamplerType(gl, type) {
1789
1674
  return typeMap[type].bindPoint;
1790
- } // This kind of sucks! If you could compose functions as in `var fn = gl[name];`
1791
- // this code could be a lot smaller but that is sadly really slow (T_T)
1675
+ }
1792
1676
 
1677
+ // This kind of sucks! If you could compose functions as in `var fn = gl[name];`
1678
+ // this code could be a lot smaller but that is sadly really slow (T_T)
1793
1679
 
1794
1680
  function floatSetter(gl, location) {
1795
1681
  return function (v) {
1796
1682
  gl.uniform1f(location, v);
1797
1683
  };
1798
1684
  }
1799
-
1800
1685
  function floatArraySetter(gl, location) {
1801
1686
  return function (v) {
1802
1687
  gl.uniform1fv(location, v);
1803
1688
  };
1804
1689
  }
1805
-
1806
1690
  function floatVec2Setter(gl, location) {
1807
1691
  return function (v) {
1808
1692
  gl.uniform2fv(location, v);
1809
1693
  };
1810
1694
  }
1811
-
1812
1695
  function floatVec3Setter(gl, location) {
1813
1696
  return function (v) {
1814
1697
  gl.uniform3fv(location, v);
1815
1698
  };
1816
1699
  }
1817
-
1818
1700
  function floatVec4Setter(gl, location) {
1819
1701
  return function (v) {
1820
1702
  gl.uniform4fv(location, v);
1821
1703
  };
1822
1704
  }
1823
-
1824
1705
  function intSetter(gl, location) {
1825
1706
  return function (v) {
1826
1707
  gl.uniform1i(location, v);
1827
1708
  };
1828
1709
  }
1829
-
1830
1710
  function intArraySetter(gl, location) {
1831
1711
  return function (v) {
1832
1712
  gl.uniform1iv(location, v);
1833
1713
  };
1834
1714
  }
1835
-
1836
1715
  function intVec2Setter(gl, location) {
1837
1716
  return function (v) {
1838
1717
  gl.uniform2iv(location, v);
1839
1718
  };
1840
1719
  }
1841
-
1842
1720
  function intVec3Setter(gl, location) {
1843
1721
  return function (v) {
1844
1722
  gl.uniform3iv(location, v);
1845
1723
  };
1846
1724
  }
1847
-
1848
1725
  function intVec4Setter(gl, location) {
1849
1726
  return function (v) {
1850
1727
  gl.uniform4iv(location, v);
1851
1728
  };
1852
1729
  }
1853
-
1854
1730
  function uintSetter(gl, location) {
1855
1731
  return function (v) {
1856
1732
  gl.uniform1ui(location, v);
1857
1733
  };
1858
1734
  }
1859
-
1860
1735
  function uintArraySetter(gl, location) {
1861
1736
  return function (v) {
1862
1737
  gl.uniform1uiv(location, v);
1863
1738
  };
1864
1739
  }
1865
-
1866
1740
  function uintVec2Setter(gl, location) {
1867
1741
  return function (v) {
1868
1742
  gl.uniform2uiv(location, v);
1869
1743
  };
1870
1744
  }
1871
-
1872
1745
  function uintVec3Setter(gl, location) {
1873
1746
  return function (v) {
1874
1747
  gl.uniform3uiv(location, v);
1875
1748
  };
1876
1749
  }
1877
-
1878
1750
  function uintVec4Setter(gl, location) {
1879
1751
  return function (v) {
1880
1752
  gl.uniform4uiv(location, v);
1881
1753
  };
1882
1754
  }
1883
-
1884
1755
  function floatMat2Setter(gl, location) {
1885
1756
  return function (v) {
1886
1757
  gl.uniformMatrix2fv(location, false, v);
1887
1758
  };
1888
1759
  }
1889
-
1890
1760
  function floatMat3Setter(gl, location) {
1891
1761
  return function (v) {
1892
1762
  gl.uniformMatrix3fv(location, false, v);
1893
1763
  };
1894
1764
  }
1895
-
1896
1765
  function floatMat4Setter(gl, location) {
1897
1766
  return function (v) {
1898
1767
  gl.uniformMatrix4fv(location, false, v);
1899
1768
  };
1900
1769
  }
1901
-
1902
1770
  function floatMat23Setter(gl, location) {
1903
1771
  return function (v) {
1904
1772
  gl.uniformMatrix2x3fv(location, false, v);
1905
1773
  };
1906
1774
  }
1907
-
1908
1775
  function floatMat32Setter(gl, location) {
1909
1776
  return function (v) {
1910
1777
  gl.uniformMatrix3x2fv(location, false, v);
1911
1778
  };
1912
1779
  }
1913
-
1914
1780
  function floatMat24Setter(gl, location) {
1915
1781
  return function (v) {
1916
1782
  gl.uniformMatrix2x4fv(location, false, v);
1917
1783
  };
1918
1784
  }
1919
-
1920
1785
  function floatMat42Setter(gl, location) {
1921
1786
  return function (v) {
1922
1787
  gl.uniformMatrix4x2fv(location, false, v);
1923
1788
  };
1924
1789
  }
1925
-
1926
1790
  function floatMat34Setter(gl, location) {
1927
1791
  return function (v) {
1928
1792
  gl.uniformMatrix3x4fv(location, false, v);
1929
1793
  };
1930
1794
  }
1931
-
1932
1795
  function floatMat43Setter(gl, location) {
1933
1796
  return function (v) {
1934
1797
  gl.uniformMatrix4x3fv(location, false, v);
1935
1798
  };
1936
1799
  }
1937
-
1938
1800
  function samplerSetter(gl, type, unit, location) {
1939
1801
  var bindPoint = getBindPointForSamplerType(gl, type);
1940
1802
  return utils.isWebGL2(gl) ? function (textureOrPair) {
1941
1803
  var texture;
1942
1804
  var sampler;
1943
-
1944
1805
  if (helper.isTexture(gl, textureOrPair)) {
1945
1806
  texture = textureOrPair;
1946
1807
  sampler = null;
@@ -1948,7 +1809,6 @@ function samplerSetter(gl, type, unit, location) {
1948
1809
  texture = textureOrPair.texture;
1949
1810
  sampler = textureOrPair.sampler;
1950
1811
  }
1951
-
1952
1812
  gl.uniform1i(location, unit);
1953
1813
  gl.activeTexture(TEXTURE0 + unit);
1954
1814
  gl.bindTexture(bindPoint, texture);
@@ -1959,22 +1819,18 @@ function samplerSetter(gl, type, unit, location) {
1959
1819
  gl.bindTexture(bindPoint, texture);
1960
1820
  };
1961
1821
  }
1962
-
1963
1822
  function samplerArraySetter(gl, type, unit, location, size) {
1964
1823
  var bindPoint = getBindPointForSamplerType(gl, type);
1965
1824
  var units = new Int32Array(size);
1966
-
1967
1825
  for (var ii = 0; ii < size; ++ii) {
1968
1826
  units[ii] = unit + ii;
1969
1827
  }
1970
-
1971
1828
  return utils.isWebGL2(gl) ? function (textures) {
1972
1829
  gl.uniform1iv(location, units);
1973
1830
  textures.forEach(function (textureOrPair, index) {
1974
1831
  gl.activeTexture(TEXTURE0 + units[index]);
1975
1832
  var texture;
1976
1833
  var sampler;
1977
-
1978
1834
  if (helper.isTexture(gl, textureOrPair)) {
1979
1835
  texture = textureOrPair;
1980
1836
  sampler = null;
@@ -1982,7 +1838,6 @@ function samplerArraySetter(gl, type, unit, location, size) {
1982
1838
  texture = textureOrPair.texture;
1983
1839
  sampler = textureOrPair.sampler;
1984
1840
  }
1985
-
1986
1841
  gl.bindSampler(unit, sampler);
1987
1842
  gl.bindTexture(bindPoint, texture);
1988
1843
  });
@@ -1994,7 +1849,6 @@ function samplerArraySetter(gl, type, unit, location, size) {
1994
1849
  });
1995
1850
  };
1996
1851
  }
1997
-
1998
1852
  typeMap[FLOAT] = {
1999
1853
  Type: Float32Array,
2000
1854
  size: 4,
@@ -2259,29 +2113,23 @@ typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = {
2259
2113
  arraySetter: samplerArraySetter,
2260
2114
  bindPoint: TEXTURE_2D_ARRAY
2261
2115
  };
2262
-
2263
2116
  function floatAttribSetter(gl, index) {
2264
2117
  return function (b) {
2265
2118
  if (b.value) {
2266
2119
  gl.disableVertexAttribArray(index);
2267
-
2268
2120
  switch (b.value.length) {
2269
2121
  case 4:
2270
2122
  gl.vertexAttrib4fv(index, b.value);
2271
2123
  break;
2272
-
2273
2124
  case 3:
2274
2125
  gl.vertexAttrib3fv(index, b.value);
2275
2126
  break;
2276
-
2277
2127
  case 2:
2278
2128
  gl.vertexAttrib2fv(index, b.value);
2279
2129
  break;
2280
-
2281
2130
  case 1:
2282
2131
  gl.vertexAttrib1fv(index, b.value);
2283
2132
  break;
2284
-
2285
2133
  default:
2286
2134
  throw new Error('the length of a float constant value must be between 1 and 4!');
2287
2135
  }
@@ -2289,19 +2137,16 @@ function floatAttribSetter(gl, index) {
2289
2137
  gl.bindBuffer(ARRAY_BUFFER, b.buffer);
2290
2138
  gl.enableVertexAttribArray(index);
2291
2139
  gl.vertexAttribPointer(index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
2292
-
2293
2140
  if (gl.vertexAttribDivisor) {
2294
2141
  gl.vertexAttribDivisor(index, b.divisor || 0);
2295
2142
  }
2296
2143
  }
2297
2144
  };
2298
2145
  }
2299
-
2300
2146
  function intAttribSetter(gl, index) {
2301
2147
  return function (b) {
2302
2148
  if (b.value) {
2303
2149
  gl.disableVertexAttribArray(index);
2304
-
2305
2150
  if (b.value.length === 4) {
2306
2151
  gl.vertexAttrib4iv(index, b.value);
2307
2152
  } else {
@@ -2311,19 +2156,16 @@ function intAttribSetter(gl, index) {
2311
2156
  gl.bindBuffer(ARRAY_BUFFER, b.buffer);
2312
2157
  gl.enableVertexAttribArray(index);
2313
2158
  gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
2314
-
2315
2159
  if (gl.vertexAttribDivisor) {
2316
2160
  gl.vertexAttribDivisor(index, b.divisor || 0);
2317
2161
  }
2318
2162
  }
2319
2163
  };
2320
2164
  }
2321
-
2322
2165
  function uintAttribSetter(gl, index) {
2323
2166
  return function (b) {
2324
2167
  if (b.value) {
2325
2168
  gl.disableVertexAttribArray(index);
2326
-
2327
2169
  if (b.value.length === 4) {
2328
2170
  gl.vertexAttrib4uiv(index, b.value);
2329
2171
  } else {
@@ -2333,14 +2175,12 @@ function uintAttribSetter(gl, index) {
2333
2175
  gl.bindBuffer(ARRAY_BUFFER, b.buffer);
2334
2176
  gl.enableVertexAttribArray(index);
2335
2177
  gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
2336
-
2337
2178
  if (gl.vertexAttribDivisor) {
2338
2179
  gl.vertexAttribDivisor(index, b.divisor || 0);
2339
2180
  }
2340
2181
  }
2341
2182
  };
2342
2183
  }
2343
-
2344
2184
  function matAttribSetter(gl, index, typeInfo) {
2345
2185
  var defaultSize = typeInfo.size;
2346
2186
  var count = typeInfo.count;
@@ -2354,18 +2194,15 @@ function matAttribSetter(gl, index, typeInfo) {
2354
2194
  var normalize = b.normalize || false;
2355
2195
  var offset = b.offset || 0;
2356
2196
  var rowOffset = stride / count;
2357
-
2358
2197
  for (var i = 0; i < count; ++i) {
2359
2198
  gl.enableVertexAttribArray(index + i);
2360
2199
  gl.vertexAttribPointer(index + i, size, type, normalize, stride, offset + rowOffset * i);
2361
-
2362
2200
  if (gl.vertexAttribDivisor) {
2363
2201
  gl.vertexAttribDivisor(index + i, b.divisor || 0);
2364
2202
  }
2365
2203
  }
2366
2204
  };
2367
2205
  }
2368
-
2369
2206
  var attrTypeMap = {};
2370
2207
  attrTypeMap[FLOAT] = {
2371
2208
  size: 4,
@@ -2445,20 +2282,17 @@ attrTypeMap[FLOAT_MAT4] = {
2445
2282
  size: 16,
2446
2283
  setter: matAttribSetter,
2447
2284
  count: 4
2448
- }; // make sure we don't see a global gl
2285
+ };
2449
2286
 
2450
- var gl = undefined;
2451
- /* eslint-disable-line */
2287
+ // make sure we don't see a global gl
2288
+ var gl = undefined; /* eslint-disable-line */
2452
2289
 
2453
2290
  var errorRE = /ERROR:\s*\d+:(\d+)/gi;
2454
-
2455
2291
  function addLineNumbersWithError(src) {
2456
2292
  var log = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2457
2293
  var lineOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
2458
-
2459
2294
  // Note: Error message formats are not defined by any spec so this may or may not work.
2460
2295
  var matches = _toConsumableArray(log.matchAll(errorRE));
2461
-
2462
2296
  var lineNoToErrorMap = new Map(matches.map(function (m, ndx) {
2463
2297
  var lineNo = parseInt(m[1]);
2464
2298
  var next = matches[ndx + 1];
@@ -2471,6 +2305,7 @@ function addLineNumbersWithError(src) {
2471
2305
  return "".concat(lineNo + 1 + lineOffset, ": ").concat(line).concat(err ? "\n\n^^^ ".concat(err) : '');
2472
2306
  }).join('\n');
2473
2307
  }
2308
+
2474
2309
  /**
2475
2310
  * Error Callback
2476
2311
  * @callback ErrorCallback
@@ -2486,8 +2321,8 @@ function addLineNumbersWithError(src) {
2486
2321
  * @param {WebGLProgram|module:twgl.ProgramInfo} [result] the program or programInfo
2487
2322
  */
2488
2323
 
2489
-
2490
2324
  var spaceRE = /^[ \t]*\n/;
2325
+
2491
2326
  /**
2492
2327
  * Remove the first end of line because WebGL 2.0 requires
2493
2328
  * #version 300 es
@@ -2504,39 +2339,34 @@ var spaceRE = /^[ \t]*\n/;
2504
2339
  * @returns {{shaderSource: string, lineOffset: number}}
2505
2340
  * @private
2506
2341
  */
2507
-
2508
2342
  function prepShaderSource(shaderSource) {
2509
2343
  var lineOffset = 0;
2510
-
2511
2344
  if (spaceRE.test(shaderSource)) {
2512
2345
  lineOffset = 1;
2513
2346
  shaderSource = shaderSource.replace(spaceRE, '');
2514
2347
  }
2515
-
2516
2348
  return {
2517
2349
  lineOffset: lineOffset,
2518
2350
  shaderSource: shaderSource
2519
2351
  };
2520
2352
  }
2353
+
2521
2354
  /**
2522
2355
  * @param {module:twgl.ProgramOptions} progOptions
2523
2356
  * @param {string} msg
2524
2357
  * @return null
2525
2358
  * @private
2526
2359
  */
2527
-
2528
-
2529
2360
  function reportError(progOptions, msg) {
2530
2361
  progOptions.errorCallback(msg);
2531
-
2532
2362
  if (progOptions.callback) {
2533
2363
  setTimeout(function () {
2534
2364
  progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
2535
2365
  });
2536
2366
  }
2537
-
2538
2367
  return null;
2539
2368
  }
2369
+
2540
2370
  /**
2541
2371
  * Loads a shader.
2542
2372
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
@@ -2546,23 +2376,22 @@ function reportError(progOptions, msg) {
2546
2376
  * @return {WebGLShader} The created shader.
2547
2377
  * @private
2548
2378
  */
2549
-
2550
-
2551
2379
  function loadShader(gl, shaderSource, shaderType, progOptions) {
2552
2380
  // Create the shader object
2553
- var shader = gl.createShader(shaderType); // Load the shader source
2381
+ var shader = gl.createShader(shaderType);
2554
2382
 
2555
- gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
2383
+ // Load the shader source
2384
+ gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource);
2556
2385
 
2386
+ // Compile the shader
2557
2387
  gl.compileShader(shader);
2558
-
2559
2388
  if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
2560
2389
  gl.deleteShader(shader);
2561
2390
  return null;
2562
2391
  }
2563
-
2564
2392
  return shader;
2565
2393
  }
2394
+
2566
2395
  /**
2567
2396
  * Check Shader status
2568
2397
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
@@ -2572,26 +2401,21 @@ function loadShader(gl, shaderSource, shaderType, progOptions) {
2572
2401
  * @return {bool} true if shader is ok.
2573
2402
  * @private
2574
2403
  */
2575
-
2576
-
2577
2404
  function checkShaderStatus(gl, shaderType, shader, errFn) {
2578
- errFn = errFn || error; // Check the compile status
2579
-
2405
+ errFn = errFn || error;
2406
+ // Check the compile status
2580
2407
  var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
2581
-
2582
2408
  if (!compiled) {
2583
2409
  // Something went wrong during compilation; get the error
2584
2410
  var lastError = gl.getShaderInfoLog(shader);
2585
-
2586
2411
  var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
2587
- lineOffset = _prepShaderSource.lineOffset,
2588
- shaderSource = _prepShaderSource.shaderSource;
2589
-
2412
+ lineOffset = _prepShaderSource.lineOffset,
2413
+ shaderSource = _prepShaderSource.shaderSource;
2590
2414
  errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
2591
2415
  }
2592
-
2593
2416
  return compiled;
2594
2417
  }
2418
+
2595
2419
  /**
2596
2420
  * @typedef {Object} ProgramOptions
2597
2421
  * @property {function(string)} [errorCallback] callback for errors
@@ -2613,18 +2437,14 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
2613
2437
  * @return {module:twgl.ProgramOptions} an instance of ProgramOptions based on the arguments passed in
2614
2438
  * @private
2615
2439
  */
2616
-
2617
-
2618
2440
  function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
2619
2441
  var transformFeedbackVaryings;
2620
2442
  var transformFeedbackMode;
2621
2443
  var callback;
2622
-
2623
2444
  if (typeof opt_locations === 'function') {
2624
2445
  opt_errorCallback = opt_locations;
2625
2446
  opt_locations = undefined;
2626
2447
  }
2627
-
2628
2448
  if (typeof opt_attribs === 'function') {
2629
2449
  opt_errorCallback = opt_attribs;
2630
2450
  opt_attribs = undefined;
@@ -2634,7 +2454,6 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
2634
2454
  if (opt_attribs.errorCallback && opt_attribs.errors) {
2635
2455
  return opt_attribs;
2636
2456
  }
2637
-
2638
2457
  var opt = opt_attribs;
2639
2458
  opt_errorCallback = opt.errorCallback;
2640
2459
  opt_attribs = opt.attribLocations;
@@ -2642,18 +2461,14 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
2642
2461
  transformFeedbackMode = opt.transformFeedbackMode;
2643
2462
  callback = opt.callback;
2644
2463
  }
2645
-
2646
2464
  var _errorCallback = opt_errorCallback || error;
2647
-
2648
2465
  var errors = [];
2649
2466
  var options = {
2650
2467
  errorCallback: function errorCallback(msg) {
2651
2468
  errors.push(msg);
2652
-
2653
2469
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2654
2470
  args[_key - 1] = arguments[_key];
2655
2471
  }
2656
-
2657
2472
  _errorCallback.apply(void 0, [msg].concat(args));
2658
2473
  },
2659
2474
  transformFeedbackVaryings: transformFeedbackVaryings,
@@ -2661,10 +2476,8 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
2661
2476
  callback: callback,
2662
2477
  errors: errors
2663
2478
  };
2664
-
2665
2479
  if (opt_attribs) {
2666
2480
  var attribLocations = {};
2667
-
2668
2481
  if (Array.isArray(opt_attribs)) {
2669
2482
  opt_attribs.forEach(function (attrib, ndx) {
2670
2483
  attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;
@@ -2672,37 +2485,31 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
2672
2485
  } else {
2673
2486
  attribLocations = opt_attribs;
2674
2487
  }
2675
-
2676
2488
  options.attribLocations = attribLocations;
2677
2489
  }
2678
-
2679
2490
  return options;
2680
2491
  }
2681
-
2682
2492
  var defaultShaderType = ["VERTEX_SHADER", "FRAGMENT_SHADER"];
2683
-
2684
2493
  function getShaderTypeFromScriptType(gl, scriptType) {
2685
2494
  if (scriptType.indexOf("frag") >= 0) {
2686
2495
  return FRAGMENT_SHADER;
2687
2496
  } else if (scriptType.indexOf("vert") >= 0) {
2688
2497
  return VERTEX_SHADER;
2689
2498
  }
2690
-
2691
2499
  return undefined;
2692
2500
  }
2693
-
2694
2501
  function deleteShaders(gl, shaders) {
2695
2502
  shaders.forEach(function (shader) {
2696
2503
  gl.deleteShader(shader);
2697
2504
  });
2698
2505
  }
2699
-
2700
2506
  var wait = function wait() {
2701
2507
  var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
2702
2508
  return new Promise(function (resolve) {
2703
2509
  return setTimeout(resolve, ms);
2704
2510
  });
2705
2511
  };
2512
+
2706
2513
  /**
2707
2514
  * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
2708
2515
  * program.
@@ -2723,68 +2530,52 @@ var wait = function wait() {
2723
2530
  * @return {WebGLProgram?} the created program or null if error of a callback was provided.
2724
2531
  * @memberOf module:twgl/programs
2725
2532
  */
2726
-
2727
-
2728
2533
  function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
2729
2534
  // This code is really convoluted, because it may or may not be async
2730
2535
  // Maybe it would be better to have a separate function
2731
2536
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
2732
2537
  var realShaders = [];
2733
2538
  var newShaders = [];
2734
-
2735
2539
  for (var ndx = 0; ndx < shaders.length; ++ndx) {
2736
2540
  var shader = shaders[ndx];
2737
-
2738
2541
  if (typeof shader === 'string') {
2739
2542
  var elem = getElementById(shader);
2740
2543
  var src = elem ? elem.text : shader;
2741
2544
  var type = gl[defaultShaderType[ndx]];
2742
-
2743
2545
  if (elem && elem.type) {
2744
2546
  type = getShaderTypeFromScriptType(gl, elem.type) || type;
2745
2547
  }
2746
-
2747
2548
  shader = loadShader(gl, src, type, progOptions);
2748
2549
  newShaders.push(shader);
2749
2550
  }
2750
-
2751
2551
  if (helper.isShader(gl, shader)) {
2752
2552
  realShaders.push(shader);
2753
2553
  }
2754
2554
  }
2755
-
2756
2555
  if (realShaders.length !== shaders.length) {
2757
2556
  deleteShaders(gl, newShaders);
2758
2557
  return reportError(progOptions, "not enough shaders for program");
2759
2558
  }
2760
-
2761
2559
  var program = gl.createProgram();
2762
2560
  realShaders.forEach(function (shader) {
2763
2561
  gl.attachShader(program, shader);
2764
2562
  });
2765
-
2766
2563
  if (progOptions.attribLocations) {
2767
2564
  Object.keys(progOptions.attribLocations).forEach(function (attrib) {
2768
2565
  gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);
2769
2566
  });
2770
2567
  }
2771
-
2772
2568
  var varyings = progOptions.transformFeedbackVaryings;
2773
-
2774
2569
  if (varyings) {
2775
2570
  if (varyings.attribs) {
2776
2571
  varyings = varyings.attribs;
2777
2572
  }
2778
-
2779
2573
  if (!Array.isArray(varyings)) {
2780
2574
  varyings = Object.keys(varyings);
2781
2575
  }
2782
-
2783
2576
  gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
2784
2577
  }
2785
-
2786
2578
  gl.linkProgram(program);
2787
-
2788
2579
  if (progOptions.callback) {
2789
2580
  checkForProgramLinkCompletionAsync(gl, program, progOptions);
2790
2581
  return null;
@@ -2794,10 +2585,10 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
2794
2585
  deleteShaders(gl, newShaders);
2795
2586
  return null;
2796
2587
  }
2797
-
2798
2588
  return program;
2799
2589
  }
2800
2590
  }
2591
+
2801
2592
  /**
2802
2593
  * Same as createProgram but returns a promise
2803
2594
  *
@@ -2817,16 +2608,12 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
2817
2608
  * @return {Promise<WebGLProgram>} The created program
2818
2609
  * @memberOf module:twgl/programs
2819
2610
  */
2820
-
2821
-
2822
2611
  function createProgramAsync(gl, shaders) {
2823
2612
  for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2824
2613
  args[_key2 - 2] = arguments[_key2];
2825
2614
  }
2826
-
2827
2615
  return new Promise(function (resolve, reject) {
2828
2616
  var programOptions = getProgramOptions.apply(void 0, args);
2829
-
2830
2617
  programOptions.callback = function (err, program) {
2831
2618
  if (err) {
2832
2619
  reject(err);
@@ -2834,10 +2621,10 @@ function createProgramAsync(gl, shaders) {
2834
2621
  resolve(program);
2835
2622
  }
2836
2623
  };
2837
-
2838
2624
  createProgram(gl, shaders, programOptions);
2839
2625
  });
2840
2626
  }
2627
+
2841
2628
  /**
2842
2629
  * Same as createProgramInfo but returns a promise
2843
2630
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext
@@ -2852,16 +2639,12 @@ function createProgramAsync(gl, shaders) {
2852
2639
  * @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
2853
2640
  * @memberOf module:twgl/programs
2854
2641
  */
2855
-
2856
-
2857
2642
  function createProgramInfoAsync(gl, shaders) {
2858
2643
  for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2859
2644
  args[_key3 - 2] = arguments[_key3];
2860
2645
  }
2861
-
2862
2646
  return new Promise(function (resolve, reject) {
2863
2647
  var programOptions = getProgramOptions.apply(void 0, args);
2864
-
2865
2648
  programOptions.callback = function (err, programInfo) {
2866
2649
  if (err) {
2867
2650
  reject(err);
@@ -2869,10 +2652,10 @@ function createProgramInfoAsync(gl, shaders) {
2869
2652
  resolve(programInfo);
2870
2653
  }
2871
2654
  };
2872
-
2873
2655
  createProgramInfo(gl, shaders, programOptions);
2874
2656
  });
2875
2657
  }
2658
+
2876
2659
  /**
2877
2660
  * Asynchronously wait for program to link.
2878
2661
  * Note: if 'KHR_parallel_shader_compile' extension does not
@@ -2882,25 +2665,20 @@ function createProgramInfoAsync(gl, shaders) {
2882
2665
  * @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
2883
2666
  * @private
2884
2667
  */
2885
-
2886
-
2887
2668
  function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
2888
2669
  return _checkForProgramLinkCompletionAsync.apply(this, arguments);
2889
- }
2890
- /**
2891
- * Check a program's link status
2892
- * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2893
- * @param {WebGLProgram} program Program to check
2894
- * @param {ErrorCallback} [errFn] func for errors
2895
- * @return {bool} true if program is ok
2896
- * @private
2897
- */
2898
-
2899
-
2670
+ } /**
2671
+ * Check a program's link status
2672
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
2673
+ * @param {WebGLProgram} program Program to check
2674
+ * @param {ErrorCallback} [errFn] func for errors
2675
+ * @return {bool} true if program is ok
2676
+ * @private
2677
+ */
2900
2678
  function _checkForProgramLinkCompletionAsync() {
2901
- _checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
2679
+ _checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(gl, program, progOptions) {
2902
2680
  var ext, checkFn, waitTime, success, err, errFn;
2903
- return regeneratorRuntime.wrap(function _callee$(_context) {
2681
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2904
2682
  while (1) {
2905
2683
  switch (_context.prev = _context.next) {
2906
2684
  case 0:
@@ -2911,36 +2689,29 @@ function _checkForProgramLinkCompletionAsync() {
2911
2689
  return true;
2912
2690
  };
2913
2691
  waitTime = 0;
2914
-
2915
2692
  case 3:
2916
2693
  _context.next = 5;
2917
2694
  return wait(waitTime);
2918
-
2919
2695
  case 5:
2920
2696
  // must wait at least once
2921
2697
  waitTime = 1000 / 60;
2922
-
2923
2698
  case 6:
2924
2699
  if (!checkFn(gl, program)) {
2925
2700
  _context.next = 3;
2926
2701
  break;
2927
2702
  }
2928
-
2929
2703
  case 7:
2930
2704
  success = checkProgramStatus(gl, program, progOptions.errorCallback);
2931
2705
  err = success ? undefined : progOptions.errors.join('\n');
2932
-
2933
2706
  if (!success) {
2934
2707
  errFn = progOptions.errorCallback || error;
2935
2708
  errFn(err);
2936
- gl.deleteProgram(program); // TODO: delete shaders, but only shaders that were created newly for this
2709
+ gl.deleteProgram(program);
2710
+ // TODO: delete shaders, but only shaders that were created newly for this
2937
2711
  // program
2938
-
2939
2712
  program = null;
2940
2713
  }
2941
-
2942
2714
  progOptions.callback(err, program);
2943
-
2944
2715
  case 11:
2945
2716
  case "end":
2946
2717
  return _context.stop();
@@ -2950,20 +2721,18 @@ function _checkForProgramLinkCompletionAsync() {
2950
2721
  }));
2951
2722
  return _checkForProgramLinkCompletionAsync.apply(this, arguments);
2952
2723
  }
2953
-
2954
2724
  function checkProgramStatus(gl, program, errFn) {
2955
- errFn = errFn || error; // Check the link status
2956
-
2725
+ errFn = errFn || error;
2726
+ // Check the link status
2957
2727
  var linked = gl.getProgramParameter(program, LINK_STATUS);
2958
-
2959
2728
  if (!linked) {
2960
2729
  // something went wrong with the link
2961
2730
  var lastError = gl.getProgramInfoLog(program);
2962
2731
  errFn("Error in program linking: ".concat(lastError));
2963
2732
  }
2964
-
2965
2733
  return linked;
2966
2734
  }
2735
+
2967
2736
  /**
2968
2737
  * Loads a shader from a script tag.
2969
2738
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
@@ -2974,25 +2743,20 @@ function checkProgramStatus(gl, program, errFn) {
2974
2743
  * @return {WebGLShader?} The created shader or null if error.
2975
2744
  * @private
2976
2745
  */
2977
-
2978
-
2979
2746
  function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
2980
2747
  var shaderSource = "";
2981
2748
  var shaderScript = getElementById(scriptId);
2982
-
2983
2749
  if (!shaderScript) {
2984
2750
  return reportError(progOptions, "unknown script element: ".concat(scriptId));
2985
2751
  }
2986
-
2987
2752
  shaderSource = shaderScript.text;
2988
2753
  var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
2989
-
2990
2754
  if (!shaderType) {
2991
2755
  return reportError(progOptions, 'unknown shader type');
2992
2756
  }
2993
-
2994
2757
  return loadShader(gl, shaderSource, shaderType, progOptions);
2995
2758
  }
2759
+
2996
2760
  /**
2997
2761
  * Creates a program from 2 script tags.
2998
2762
  *
@@ -3015,24 +2779,19 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
3015
2779
  * @return {WebGLProgram?} the created program or null if error or a callback was provided.
3016
2780
  * @memberOf module:twgl/programs
3017
2781
  */
3018
-
3019
-
3020
2782
  function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {
3021
2783
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
3022
2784
  var shaders = [];
3023
-
3024
2785
  for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
3025
2786
  var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
3026
-
3027
2787
  if (!shader) {
3028
2788
  return null;
3029
2789
  }
3030
-
3031
2790
  shaders.push(shader);
3032
2791
  }
3033
-
3034
2792
  return createProgram(gl, shaders, progOptions);
3035
2793
  }
2794
+
3036
2795
  /**
3037
2796
  * Creates a program from 2 sources.
3038
2797
  *
@@ -3055,24 +2814,19 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
3055
2814
  * @return {WebGLProgram?} the created program or null if error or a callback was provided.
3056
2815
  * @memberOf module:twgl/programs
3057
2816
  */
3058
-
3059
-
3060
2817
  function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
3061
2818
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
3062
2819
  var shaders = [];
3063
-
3064
2820
  for (var ii = 0; ii < shaderSources.length; ++ii) {
3065
2821
  var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
3066
-
3067
2822
  if (!progOptions.callback && !shader) {
3068
2823
  return null;
3069
2824
  }
3070
-
3071
2825
  shaders.push(shader);
3072
2826
  }
3073
-
3074
2827
  return createProgram(gl, shaders, progOptions);
3075
2828
  }
2829
+
3076
2830
  /**
3077
2831
  * Returns true if attribute/uniform is a reserved/built in
3078
2832
  *
@@ -3090,60 +2844,49 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
3090
2844
  * @return {bool} true if it's reserved
3091
2845
  * @private
3092
2846
  */
3093
-
3094
-
3095
2847
  function isBuiltIn(info) {
3096
2848
  var name = info.name;
3097
2849
  return name.startsWith("gl_") || name.startsWith("webgl_");
3098
2850
  }
3099
-
3100
2851
  var tokenRE = /(\.|\[|]|\w+)/g;
3101
-
3102
2852
  var isDigit = function isDigit(s) {
3103
2853
  return s >= '0' && s <= '9';
3104
2854
  };
3105
-
3106
2855
  function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
3107
2856
  var tokens = fullPath.split(tokenRE).filter(function (s) {
3108
2857
  return s !== '';
3109
2858
  });
3110
2859
  var tokenNdx = 0;
3111
2860
  var path = '';
3112
-
3113
2861
  for (;;) {
3114
2862
  var token = tokens[tokenNdx++]; // has to be name or number
3115
-
3116
2863
  path += token;
3117
2864
  var isArrayIndex = isDigit(token[0]);
3118
2865
  var accessor = isArrayIndex ? parseInt(token) : token;
3119
-
3120
2866
  if (isArrayIndex) {
3121
2867
  path += tokens[tokenNdx++]; // skip ']'
3122
2868
  }
3123
2869
 
3124
2870
  var isLastToken = tokenNdx === tokens.length;
3125
-
3126
2871
  if (isLastToken) {
3127
2872
  node[accessor] = setter;
3128
2873
  break;
3129
2874
  } else {
3130
2875
  var _token = tokens[tokenNdx++]; // has to be . or [
3131
-
3132
2876
  var isArray = _token === '[';
3133
2877
  var child = node[accessor] || (isArray ? [] : {});
3134
2878
  node[accessor] = child;
3135
2879
  node = child;
3136
-
3137
2880
  uniformSetters[path] = uniformSetters[path] || function (node) {
3138
2881
  return function (value) {
3139
2882
  setUniformTree(node, value);
3140
2883
  };
3141
2884
  }(child);
3142
-
3143
2885
  path += _token;
3144
2886
  }
3145
2887
  }
3146
2888
  }
2889
+
3147
2890
  /**
3148
2891
  * Creates setter functions for all uniforms of a shader
3149
2892
  * program.
@@ -3155,10 +2898,9 @@ function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
3155
2898
  * @returns {Object.<string, function>} an object with a setter by name for each uniform
3156
2899
  * @memberOf module:twgl/programs
3157
2900
  */
3158
-
3159
-
3160
2901
  function createUniformSetters(gl, program) {
3161
2902
  var textureUnit = 0;
2903
+
3162
2904
  /**
3163
2905
  * Creates a setter for a uniform of the given program with it's
3164
2906
  * location embedded in the setter.
@@ -3166,23 +2908,19 @@ function createUniformSetters(gl, program) {
3166
2908
  * @param {WebGLUniformInfo} uniformInfo
3167
2909
  * @returns {function} the created setter.
3168
2910
  */
3169
-
3170
2911
  function createUniformSetter(program, uniformInfo, location) {
3171
2912
  var isArray = uniformInfo.name.endsWith("[0]");
3172
2913
  var type = uniformInfo.type;
3173
2914
  var typeInfo = typeMap[type];
3174
-
3175
2915
  if (!typeInfo) {
3176
2916
  throw new Error("unknown type: 0x".concat(type.toString(16))); // we should never get here.
3177
2917
  }
3178
2918
 
3179
2919
  var setter;
3180
-
3181
2920
  if (typeInfo.bindPoint) {
3182
2921
  // it's a sampler
3183
2922
  var unit = textureUnit;
3184
2923
  textureUnit += uniformInfo.size;
3185
-
3186
2924
  if (isArray) {
3187
2925
  setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
3188
2926
  } else {
@@ -3195,39 +2933,33 @@ function createUniformSetters(gl, program) {
3195
2933
  setter = typeInfo.setter(gl, location);
3196
2934
  }
3197
2935
  }
3198
-
3199
2936
  setter.location = location;
3200
2937
  return setter;
3201
2938
  }
3202
-
3203
2939
  var uniformSetters = {};
3204
2940
  var uniformTree = {};
3205
2941
  var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
3206
-
3207
2942
  for (var ii = 0; ii < numUniforms; ++ii) {
3208
2943
  var uniformInfo = gl.getActiveUniform(program, ii);
3209
-
3210
2944
  if (isBuiltIn(uniformInfo)) {
3211
2945
  continue;
3212
2946
  }
3213
-
3214
- var name = uniformInfo.name; // remove the array suffix.
3215
-
2947
+ var name = uniformInfo.name;
2948
+ // remove the array suffix.
3216
2949
  if (name.endsWith("[0]")) {
3217
2950
  name = name.substr(0, name.length - 3);
3218
2951
  }
3219
-
3220
- var location = gl.getUniformLocation(program, uniformInfo.name); // the uniform will have no location if it's in a uniform block
3221
-
2952
+ var location = gl.getUniformLocation(program, uniformInfo.name);
2953
+ // the uniform will have no location if it's in a uniform block
3222
2954
  if (location) {
3223
2955
  var setter = createUniformSetter(program, uniformInfo, location);
3224
2956
  uniformSetters[name] = setter;
3225
2957
  addSetterToUniformTree(name, setter, uniformTree, uniformSetters);
3226
2958
  }
3227
2959
  }
3228
-
3229
2960
  return uniformSetters;
3230
2961
  }
2962
+
3231
2963
  /**
3232
2964
  * @typedef {Object} TransformFeedbackInfo
3233
2965
  * @property {number} index index of transform feedback
@@ -3243,12 +2975,9 @@ function createUniformSetters(gl, program) {
3243
2975
  * @return {Object<string, module:twgl.TransformFeedbackInfo>}
3244
2976
  * @memberOf module:twgl
3245
2977
  */
3246
-
3247
-
3248
2978
  function createTransformFeedbackInfo(gl, program) {
3249
2979
  var info = {};
3250
2980
  var numVaryings = gl.getProgramParameter(program, TRANSFORM_FEEDBACK_VARYINGS);
3251
-
3252
2981
  for (var ii = 0; ii < numVaryings; ++ii) {
3253
2982
  var varying = gl.getTransformFeedbackVarying(program, ii);
3254
2983
  info[varying.name] = {
@@ -3257,9 +2986,9 @@ function createTransformFeedbackInfo(gl, program) {
3257
2986
  size: varying.size
3258
2987
  };
3259
2988
  }
3260
-
3261
2989
  return info;
3262
2990
  }
2991
+
3263
2992
  /**
3264
2993
  * Binds buffers for transform feedback.
3265
2994
  *
@@ -3268,23 +2997,17 @@ function createTransformFeedbackInfo(gl, program) {
3268
2997
  * @param {(module:twgl.BufferInfo|Object<string, module:twgl.AttribInfo>)} [bufferInfo] A BufferInfo or set of AttribInfos.
3269
2998
  * @memberOf module:twgl
3270
2999
  */
3271
-
3272
-
3273
3000
  function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
3274
3001
  if (transformFeedbackInfo.transformFeedbackInfo) {
3275
3002
  transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;
3276
3003
  }
3277
-
3278
3004
  if (bufferInfo.attribs) {
3279
3005
  bufferInfo = bufferInfo.attribs;
3280
3006
  }
3281
-
3282
3007
  for (var name in bufferInfo) {
3283
3008
  var varying = transformFeedbackInfo[name];
3284
-
3285
3009
  if (varying) {
3286
3010
  var buf = bufferInfo[name];
3287
-
3288
3011
  if (buf.offset) {
3289
3012
  gl.bindBufferRange(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);
3290
3013
  } else {
@@ -3293,6 +3016,7 @@ function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
3293
3016
  }
3294
3017
  }
3295
3018
  }
3019
+
3296
3020
  /**
3297
3021
  * Creates a transform feedback and sets the buffers
3298
3022
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
@@ -3301,8 +3025,6 @@ function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
3301
3025
  * @return {WebGLTransformFeedback} the created transform feedback
3302
3026
  * @memberOf module:twgl
3303
3027
  */
3304
-
3305
-
3306
3028
  function createTransformFeedback(gl, programInfo, bufferInfo) {
3307
3029
  var tf = gl.createTransformFeedback();
3308
3030
  gl.bindTransformFeedback(TRANSFORM_FEEDBACK, tf);
@@ -3311,6 +3033,7 @@ function createTransformFeedback(gl, programInfo, bufferInfo) {
3311
3033
  gl.bindTransformFeedback(TRANSFORM_FEEDBACK, null);
3312
3034
  return tf;
3313
3035
  }
3036
+
3314
3037
  /**
3315
3038
  * @typedef {Object} UniformData
3316
3039
  * @property {string} name The name of the uniform
@@ -3356,21 +3079,18 @@ function createTransformFeedback(gl, programInfo, bufferInfo) {
3356
3079
  * @return {module:twgl.UniformBlockSpec} The created UniformBlockSpec
3357
3080
  * @memberOf module:twgl/programs
3358
3081
  */
3359
-
3360
-
3361
3082
  function createUniformBlockSpecFromProgram(gl, program) {
3362
3083
  var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
3363
3084
  var uniformData = [];
3364
3085
  var uniformIndices = [];
3365
-
3366
3086
  for (var ii = 0; ii < numUniforms; ++ii) {
3367
3087
  uniformIndices.push(ii);
3368
3088
  uniformData.push({});
3369
3089
  var uniformInfo = gl.getActiveUniform(program, ii);
3370
3090
  uniformData[ii].name = uniformInfo.name;
3371
3091
  }
3372
-
3373
- [["UNIFORM_TYPE", "type"], ["UNIFORM_SIZE", "size"], // num elements
3092
+ [["UNIFORM_TYPE", "type"], ["UNIFORM_SIZE", "size"],
3093
+ // num elements
3374
3094
  ["UNIFORM_BLOCK_INDEX", "blockNdx"], ["UNIFORM_OFFSET", "offset"]].forEach(function (pair) {
3375
3095
  var pname = pair[0];
3376
3096
  var key = pair[1];
@@ -3380,7 +3100,6 @@ function createUniformBlockSpecFromProgram(gl, program) {
3380
3100
  });
3381
3101
  var blockSpecs = {};
3382
3102
  var numUniformBlocks = gl.getProgramParameter(program, ACTIVE_UNIFORM_BLOCKS);
3383
-
3384
3103
  for (var _ii = 0; _ii < numUniformBlocks; ++_ii) {
3385
3104
  var name = gl.getActiveUniformBlockName(program, _ii);
3386
3105
  var blockSpec = {
@@ -3393,19 +3112,16 @@ function createUniformBlockSpecFromProgram(gl, program) {
3393
3112
  blockSpec.used = blockSpec.usedByVertexShader || blockSpec.usedByFragmentShader;
3394
3113
  blockSpecs[name] = blockSpec;
3395
3114
  }
3396
-
3397
3115
  return {
3398
3116
  blockSpecs: blockSpecs,
3399
3117
  uniformData: uniformData
3400
3118
  };
3401
3119
  }
3402
-
3403
3120
  var arraySuffixRE = /\[\d+\]\.$/; // better way to check?
3404
3121
 
3405
3122
  var pad = function pad(v, padding) {
3406
3123
  return ((v + (padding - 1)) / padding | 0) * padding;
3407
3124
  };
3408
-
3409
3125
  function createUniformBlockUniformSetter(view, isArray, rows, cols) {
3410
3126
  if (isArray || rows) {
3411
3127
  cols = cols || 1;
@@ -3414,12 +3130,10 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
3414
3130
  return function (value) {
3415
3131
  var dst = 0;
3416
3132
  var src = 0;
3417
-
3418
3133
  for (var row = 0; row < totalRows; ++row) {
3419
3134
  for (var col = 0; col < cols; ++col) {
3420
3135
  view[dst++] = value[src++];
3421
3136
  }
3422
-
3423
3137
  dst += 4 - cols;
3424
3138
  }
3425
3139
  };
@@ -3433,6 +3147,7 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
3433
3147
  };
3434
3148
  }
3435
3149
  }
3150
+
3436
3151
  /**
3437
3152
  * Represents a UniformBlockObject including an ArrayBuffer with all the uniform values
3438
3153
  * and a corresponding WebGLBuffer to hold those values on the GPU
@@ -3477,13 +3192,10 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
3477
3192
  * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
3478
3193
  * @memberOf module:twgl/programs
3479
3194
  */
3480
-
3481
-
3482
3195
  function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
3483
3196
  var blockSpecs = uniformBlockSpec.blockSpecs;
3484
3197
  var uniformData = uniformBlockSpec.uniformData;
3485
3198
  var blockSpec = blockSpecs[blockName];
3486
-
3487
3199
  if (!blockSpec) {
3488
3200
  warn("no uniform block object named:", blockName);
3489
3201
  return {
@@ -3491,40 +3203,34 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
3491
3203
  uniforms: {}
3492
3204
  };
3493
3205
  }
3494
-
3495
3206
  var array = new ArrayBuffer(blockSpec.size);
3496
3207
  var buffer = gl.createBuffer();
3497
3208
  var uniformBufferIndex = blockSpec.index;
3498
3209
  gl.bindBuffer(UNIFORM_BUFFER, buffer);
3499
3210
  gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
3500
3211
  var prefix = blockName + ".";
3501
-
3502
3212
  if (arraySuffixRE.test(prefix)) {
3503
3213
  prefix = prefix.replace(arraySuffixRE, ".");
3504
3214
  }
3505
-
3506
3215
  var uniforms = {};
3507
3216
  var setters = {};
3508
3217
  var setterTree = {};
3509
3218
  blockSpec.uniformIndices.forEach(function (uniformNdx) {
3510
3219
  var data = uniformData[uniformNdx];
3511
3220
  var name = data.name;
3512
-
3513
3221
  if (name.startsWith(prefix)) {
3514
3222
  name = name.substr(prefix.length);
3515
3223
  }
3516
-
3517
3224
  var isArray = name.endsWith('[0]');
3518
-
3519
3225
  if (isArray) {
3520
3226
  name = name.substr(0, name.length - 3);
3521
3227
  }
3522
-
3523
3228
  var typeInfo = typeMap[data.type];
3524
3229
  var Type = typeInfo.Type;
3525
3230
  var byteLength = isArray ? pad(typeInfo.size, 16) * data.size : typeInfo.size * data.size;
3526
3231
  var uniformView = new Type(array, data.offset, byteLength / Type.BYTES_PER_ELEMENT);
3527
- uniforms[name] = uniformView; // Note: I'm not sure what to do here. The original
3232
+ uniforms[name] = uniformView;
3233
+ // Note: I'm not sure what to do here. The original
3528
3234
  // idea was to create TypedArray views into each part
3529
3235
  // of the block. This is useful, for example if you have
3530
3236
  // a block with { mat4: model; mat4 view; mat4 projection; }
@@ -3549,7 +3255,6 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
3549
3255
  // then you should probably roll your own solution. TWGL's goal
3550
3256
  // here is ease of use as AFAICT there is no simple generic efficient
3551
3257
  // solution.
3552
-
3553
3258
  var setter = createUniformBlockUniformSetter(uniformView, isArray, typeInfo.rows, typeInfo.cols);
3554
3259
  setters[name] = setter;
3555
3260
  addSetterToUniformTree(name, setter, setterTree, setters);
@@ -3564,6 +3269,7 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
3564
3269
  setters: setters
3565
3270
  };
3566
3271
  }
3272
+
3567
3273
  /**
3568
3274
  * Creates a `UniformBlockInfo` for the specified block
3569
3275
  *
@@ -3580,11 +3286,10 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
3580
3286
  * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
3581
3287
  * @memberOf module:twgl/programs
3582
3288
  */
3583
-
3584
-
3585
3289
  function createUniformBlockInfo(gl, programInfo, blockName) {
3586
3290
  return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
3587
3291
  }
3292
+
3588
3293
  /**
3589
3294
  * Binds a uniform block to the matching uniform block point.
3590
3295
  * Matches by blocks by name so blocks must have the same name not just the same
@@ -3603,20 +3308,17 @@ function createUniformBlockInfo(gl, programInfo, blockName) {
3603
3308
  * no buffer is bound.
3604
3309
  * @memberOf module:twgl/programs
3605
3310
  */
3606
-
3607
-
3608
3311
  function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
3609
3312
  var uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
3610
3313
  var blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
3611
-
3612
3314
  if (blockSpec) {
3613
3315
  var bufferBindIndex = blockSpec.index;
3614
3316
  gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
3615
3317
  return true;
3616
3318
  }
3617
-
3618
3319
  return false;
3619
3320
  }
3321
+
3620
3322
  /**
3621
3323
  * Uploads the current uniform values to the corresponding WebGLBuffer
3622
3324
  * and binds that buffer to the program's corresponding bind point for the uniform block object.
@@ -3632,13 +3334,12 @@ function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
3632
3334
  * {@link module:twgl.createUniformBlockInfo}.
3633
3335
  * @memberOf module:twgl/programs
3634
3336
  */
3635
-
3636
-
3637
3337
  function setUniformBlock(gl, programInfo, uniformBlockInfo) {
3638
3338
  if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
3639
3339
  gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);
3640
3340
  }
3641
3341
  }
3342
+
3642
3343
  /**
3643
3344
  * Sets values of a uniform block object
3644
3345
  *
@@ -3724,25 +3425,19 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
3724
3425
  * Any name that doesn't match will be ignored
3725
3426
  * @memberOf module:twgl/programs
3726
3427
  */
3727
-
3728
-
3729
3428
  function setBlockUniforms(uniformBlockInfo, values) {
3730
3429
  var setters = uniformBlockInfo.setters;
3731
-
3732
3430
  for (var name in values) {
3733
3431
  var setter = setters[name];
3734
-
3735
3432
  if (setter) {
3736
3433
  var value = values[name];
3737
3434
  setter(value);
3738
3435
  }
3739
3436
  }
3740
3437
  }
3741
-
3742
3438
  function setUniformTree(tree, values) {
3743
3439
  for (var name in values) {
3744
3440
  var prop = tree[name];
3745
-
3746
3441
  if (typeof prop === 'function') {
3747
3442
  prop(values[name]);
3748
3443
  } else {
@@ -3750,6 +3445,7 @@ function setUniformTree(tree, values) {
3750
3445
  }
3751
3446
  }
3752
3447
  }
3448
+
3753
3449
  /**
3754
3450
  * Set uniforms and binds related textures.
3755
3451
  *
@@ -3908,26 +3604,20 @@ function setUniformTree(tree, values) {
3908
3604
  *
3909
3605
  * @memberOf module:twgl/programs
3910
3606
  */
3911
-
3912
-
3913
3607
  function setUniforms(setters) {
3914
3608
  // eslint-disable-line
3915
3609
  var actualSetters = setters.uniformSetters || setters;
3916
3610
  var numArgs = arguments.length <= 1 ? 0 : arguments.length - 1;
3917
-
3918
3611
  for (var aNdx = 0; aNdx < numArgs; ++aNdx) {
3919
3612
  var values = aNdx + 1 < 1 || arguments.length <= aNdx + 1 ? undefined : arguments[aNdx + 1];
3920
-
3921
3613
  if (Array.isArray(values)) {
3922
3614
  var numValues = values.length;
3923
-
3924
3615
  for (var ii = 0; ii < numValues; ++ii) {
3925
3616
  setUniforms(actualSetters, values[ii]);
3926
3617
  }
3927
3618
  } else {
3928
3619
  for (var name in values) {
3929
3620
  var setter = actualSetters[name];
3930
-
3931
3621
  if (setter) {
3932
3622
  setter(values[name]);
3933
3623
  }
@@ -3935,6 +3625,7 @@ function setUniforms(setters) {
3935
3625
  }
3936
3626
  }
3937
3627
  }
3628
+
3938
3629
  /**
3939
3630
  * Alias for `setUniforms`
3940
3631
  * @function
@@ -3943,9 +3634,8 @@ function setUniforms(setters) {
3943
3634
  * @param {Object.<string, ?>} values an object with values for the
3944
3635
  * @memberOf module:twgl/programs
3945
3636
  */
3946
-
3947
-
3948
3637
  var setUniformsAndBindTextures = setUniforms;
3638
+
3949
3639
  /**
3950
3640
  * Creates setter functions for all attributes of a shader
3951
3641
  * program. You can pass this to {@link module:twgl.setBuffersAndAttributes} to set all your buffers and attributes.
@@ -3956,29 +3646,24 @@ var setUniformsAndBindTextures = setUniforms;
3956
3646
  * @return {Object.<string, function>} an object with a setter for each attribute by name.
3957
3647
  * @memberOf module:twgl/programs
3958
3648
  */
3959
-
3960
3649
  exports.setUniformsAndBindTextures = setUniformsAndBindTextures;
3961
-
3962
3650
  function createAttributeSetters(gl, program) {
3963
3651
  var attribSetters = {};
3964
3652
  var numAttribs = gl.getProgramParameter(program, ACTIVE_ATTRIBUTES);
3965
-
3966
3653
  for (var ii = 0; ii < numAttribs; ++ii) {
3967
3654
  var attribInfo = gl.getActiveAttrib(program, ii);
3968
-
3969
3655
  if (isBuiltIn(attribInfo)) {
3970
3656
  continue;
3971
3657
  }
3972
-
3973
3658
  var index = gl.getAttribLocation(program, attribInfo.name);
3974
3659
  var typeInfo = attrTypeMap[attribInfo.type];
3975
3660
  var setter = typeInfo.setter(gl, index, typeInfo);
3976
3661
  setter.location = index;
3977
3662
  attribSetters[attribInfo.name] = setter;
3978
3663
  }
3979
-
3980
3664
  return attribSetters;
3981
3665
  }
3666
+
3982
3667
  /**
3983
3668
  * Sets attributes and binds buffers (deprecated... use {@link module:twgl.setBuffersAndAttributes})
3984
3669
  *
@@ -4034,17 +3719,15 @@ function createAttributeSetters(gl, program) {
4034
3719
  * @deprecated use {@link module:twgl.setBuffersAndAttributes}
4035
3720
  * @private
4036
3721
  */
4037
-
4038
-
4039
3722
  function setAttributes(setters, buffers) {
4040
3723
  for (var name in buffers) {
4041
3724
  var setter = setters[name];
4042
-
4043
3725
  if (setter) {
4044
3726
  setter(buffers[name]);
4045
3727
  }
4046
3728
  }
4047
3729
  }
3730
+
4048
3731
  /**
4049
3732
  * Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
4050
3733
  *
@@ -4082,19 +3765,17 @@ function setAttributes(setters, buffers) {
4082
3765
  * or a `VertexArrayInfo` as returned from {@link module:twgl.createVertexArrayInfo}
4083
3766
  * @memberOf module:twgl/programs
4084
3767
  */
4085
-
4086
-
4087
3768
  function setBuffersAndAttributes(gl, programInfo, buffers) {
4088
3769
  if (buffers.vertexArrayObject) {
4089
3770
  gl.bindVertexArray(buffers.vertexArrayObject);
4090
3771
  } else {
4091
3772
  setAttributes(programInfo.attribSetters || programInfo, buffers.attribs);
4092
-
4093
3773
  if (buffers.indices) {
4094
3774
  gl.bindBuffer(ELEMENT_ARRAY_BUFFER, buffers.indices);
4095
3775
  }
4096
3776
  }
4097
3777
  }
3778
+
4098
3779
  /**
4099
3780
  * @typedef {Object} ProgramInfo
4100
3781
  * @property {WebGLProgram} program A shader program
@@ -4122,8 +3803,6 @@ function setBuffersAndAttributes(gl, programInfo, buffers) {
4122
3803
  * @return {module:twgl.ProgramInfo} The created ProgramInfo.
4123
3804
  * @memberOf module:twgl/programs
4124
3805
  */
4125
-
4126
-
4127
3806
  function createProgramInfoFromProgram(gl, program) {
4128
3807
  var uniformSetters = createUniformSetters(gl, program);
4129
3808
  var attribSetters = createAttributeSetters(gl, program);
@@ -4132,16 +3811,14 @@ function createProgramInfoFromProgram(gl, program) {
4132
3811
  uniformSetters: uniformSetters,
4133
3812
  attribSetters: attribSetters
4134
3813
  };
4135
-
4136
3814
  if (utils.isWebGL2(gl)) {
4137
3815
  programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);
4138
3816
  programInfo.transformFeedbackInfo = createTransformFeedbackInfo(gl, program);
4139
3817
  }
4140
-
4141
3818
  return programInfo;
4142
3819
  }
4143
-
4144
3820
  var notIdRE = /\s|{|}|;/;
3821
+
4145
3822
  /**
4146
3823
  * Creates a ProgramInfo from 2 sources.
4147
3824
  *
@@ -4172,7 +3849,6 @@ var notIdRE = /\s|{|}|;/;
4172
3849
  * @return {module:twgl.ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
4173
3850
  * @memberOf module:twgl/programs
4174
3851
  */
4175
-
4176
3852
  function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
4177
3853
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
4178
3854
  var errors = [];
@@ -4180,7 +3856,6 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
4180
3856
  // Lets assume if there is no \n it's an id
4181
3857
  if (!notIdRE.test(source)) {
4182
3858
  var script = getElementById(source);
4183
-
4184
3859
  if (!script) {
4185
3860
  var err = "no element with id: ".concat(source);
4186
3861
  progOptions.errorCallback(err);
@@ -4189,34 +3864,25 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
4189
3864
  source = script.text;
4190
3865
  }
4191
3866
  }
4192
-
4193
3867
  return source;
4194
3868
  });
4195
-
4196
3869
  if (errors.length) {
4197
3870
  return reportError(progOptions, '');
4198
3871
  }
4199
-
4200
3872
  var origCallback = progOptions.callback;
4201
-
4202
3873
  if (origCallback) {
4203
3874
  progOptions.callback = function (err, program) {
4204
3875
  var programInfo;
4205
-
4206
3876
  if (!err) {
4207
3877
  programInfo = createProgramInfoFromProgram(gl, program);
4208
3878
  }
4209
-
4210
3879
  origCallback(err, programInfo);
4211
3880
  };
4212
3881
  }
4213
-
4214
3882
  var program = createProgramFromSources(gl, shaderSources, progOptions);
4215
-
4216
3883
  if (!program) {
4217
3884
  return null;
4218
3885
  }
4219
-
4220
3886
  return createProgramInfoFromProgram(gl, program);
4221
3887
  }
4222
3888
 
@@ -4232,39 +3898,32 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
4232
3898
  "use strict";
4233
3899
 
4234
3900
 
4235
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4236
-
3901
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4237
3902
  exports.__esModule = true;
4238
- exports.setTextureDefaults_ = setDefaults;
3903
+ exports.canFilter = canFilter;
3904
+ exports.canGenerateMipmap = canGenerateMipmap;
4239
3905
  exports.createSampler = createSampler;
4240
3906
  exports.createSamplers = createSamplers;
4241
- exports.setSamplerParameters = setSamplerParameters;
4242
3907
  exports.createTexture = createTexture;
3908
+ exports.createTextures = createTextures;
3909
+ exports.getBytesPerElementForInternalFormat = getBytesPerElementForInternalFormat;
3910
+ exports.getFormatAndTypeForInternalFormat = getFormatAndTypeForInternalFormat;
3911
+ exports.getNumComponentsForFormat = getNumComponentsForFormat;
3912
+ exports.loadTextureFromUrl = loadTextureFromUrl;
3913
+ exports.resizeTexture = resizeTexture;
3914
+ exports.setDefaultTextureColor = setDefaultTextureColor;
4243
3915
  exports.setEmptyTexture = setEmptyTexture;
3916
+ exports.setSamplerParameters = setSamplerParameters;
3917
+ exports.setTextureDefaults_ = setDefaults;
3918
+ exports.setTextureFilteringForSize = setTextureFilteringForSize;
4244
3919
  exports.setTextureFromArray = setTextureFromArray;
4245
- exports.loadTextureFromUrl = loadTextureFromUrl;
4246
3920
  exports.setTextureFromElement = setTextureFromElement;
4247
- exports.setTextureFilteringForSize = setTextureFilteringForSize;
4248
3921
  exports.setTextureParameters = setTextureParameters;
4249
- exports.setDefaultTextureColor = setDefaultTextureColor;
4250
- exports.createTextures = createTextures;
4251
- exports.resizeTexture = resizeTexture;
4252
- exports.canGenerateMipmap = canGenerateMipmap;
4253
- exports.canFilter = canFilter;
4254
- exports.getNumComponentsForFormat = getNumComponentsForFormat;
4255
- exports.getBytesPerElementForInternalFormat = getBytesPerElementForInternalFormat;
4256
- exports.getFormatAndTypeForInternalFormat = getFormatAndTypeForInternalFormat;
4257
-
4258
3922
  var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
4259
-
4260
3923
  var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
4261
-
4262
3924
  var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
4263
-
4264
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
4265
-
4266
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
4267
-
3925
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
3926
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
4268
3927
  /*
4269
3928
  * Copyright 2019 Gregg Tavares
4270
3929
  *
@@ -4301,27 +3960,30 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
4301
3960
  *
4302
3961
  * @module twgl/textures
4303
3962
  */
4304
- // make sure we don't see a global gl
4305
- var gl = undefined;
4306
- /* eslint-disable-line */
4307
3963
 
3964
+ // make sure we don't see a global gl
3965
+ var gl = undefined; /* eslint-disable-line */
4308
3966
  var defaults = {
4309
3967
  textureColor: new Uint8Array([128, 192, 255, 255]),
4310
3968
  textureOptions: {},
4311
3969
  crossOrigin: undefined
4312
3970
  };
4313
- var isArrayBuffer = typedArrays.isArrayBuffer; // Should we make this on demand?
3971
+ var isArrayBuffer = typedArrays.isArrayBuffer;
4314
3972
 
3973
+ // Should we make this on demand?
4315
3974
  var getShared2DContext = function () {
4316
3975
  var s_ctx;
4317
3976
  return function getShared2DContext() {
4318
3977
  s_ctx = s_ctx || (typeof document !== 'undefined' && document.createElement ? document.createElement("canvas").getContext("2d") : null);
4319
3978
  return s_ctx;
4320
3979
  };
4321
- }(); // NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but
3980
+ }();
3981
+
3982
+ // NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but
4322
3983
  // not only does Firefox NOT support it but Firefox freezes immediately
4323
3984
  // if you try to create one instead of just returning null and continuing.
4324
3985
  // : (global.OffscreenCanvas && (new global.OffscreenCanvas(1, 1)).getContext("2d")); // OffscreenCanvas may not support 2d
3986
+
4325
3987
  // NOTE: We can maybe remove some of the need for the 2d canvas. In WebGL2
4326
3988
  // we can use the various unpack settings. Otherwise we could try using
4327
3989
  // the ability of an ImageBitmap to be cut. Unfortunately cutting an ImageBitmap
@@ -4330,8 +3992,6 @@ var getShared2DContext = function () {
4330
3992
  // as of 2018-01-02
4331
3993
 
4332
3994
  /* PixelFormat */
4333
-
4334
-
4335
3995
  var ALPHA = 0x1906;
4336
3996
  var RGB = 0x1907;
4337
3997
  var RGBA = 0x1908;
@@ -4339,15 +3999,16 @@ var LUMINANCE = 0x1909;
4339
3999
  var LUMINANCE_ALPHA = 0x190A;
4340
4000
  var DEPTH_COMPONENT = 0x1902;
4341
4001
  var DEPTH_STENCIL = 0x84F9;
4002
+
4342
4003
  /* TextureWrapMode */
4343
4004
  // const REPEAT = 0x2901;
4344
4005
  // const MIRRORED_REPEAT = 0x8370;
4345
-
4346
4006
  var CLAMP_TO_EDGE = 0x812f;
4347
- /* TextureMagFilter */
4348
4007
 
4008
+ /* TextureMagFilter */
4349
4009
  var NEAREST = 0x2600;
4350
4010
  var LINEAR = 0x2601;
4011
+
4351
4012
  /* TextureMinFilter */
4352
4013
  // const NEAREST_MIPMAP_NEAREST = 0x2700;
4353
4014
  // const LINEAR_MIPMAP_NEAREST = 0x2701;
@@ -4355,21 +4016,20 @@ var LINEAR = 0x2601;
4355
4016
  // const LINEAR_MIPMAP_LINEAR = 0x2703;
4356
4017
 
4357
4018
  /* Texture Target */
4358
-
4359
4019
  var TEXTURE_2D = 0x0de1;
4360
4020
  var TEXTURE_CUBE_MAP = 0x8513;
4361
4021
  var TEXTURE_3D = 0x806f;
4362
4022
  var TEXTURE_2D_ARRAY = 0x8c1a;
4363
- /* Cubemap Targets */
4364
4023
 
4024
+ /* Cubemap Targets */
4365
4025
  var TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
4366
4026
  var TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
4367
4027
  var TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
4368
4028
  var TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
4369
4029
  var TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
4370
4030
  var TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
4371
- /* Texture Parameters */
4372
4031
 
4032
+ /* Texture Parameters */
4373
4033
  var TEXTURE_MIN_FILTER = 0x2801;
4374
4034
  var TEXTURE_MAG_FILTER = 0x2800;
4375
4035
  var TEXTURE_WRAP_S = 0x2802;
@@ -4379,8 +4039,8 @@ var TEXTURE_MIN_LOD = 0x813a;
4379
4039
  var TEXTURE_MAX_LOD = 0x813b;
4380
4040
  var TEXTURE_BASE_LEVEL = 0x813c;
4381
4041
  var TEXTURE_MAX_LEVEL = 0x813d;
4382
- /* Pixel store */
4383
4042
 
4043
+ /* Pixel store */
4384
4044
  var UNPACK_ALIGNMENT = 0x0cf5;
4385
4045
  var UNPACK_ROW_LENGTH = 0x0cf2;
4386
4046
  var UNPACK_IMAGE_HEIGHT = 0x806e;
@@ -4444,8 +4104,8 @@ var DEPTH_COMPONENT24 = 0x81A6;
4444
4104
  var DEPTH_COMPONENT32F = 0x8CAC;
4445
4105
  var DEPTH32F_STENCIL8 = 0x8CAD;
4446
4106
  var DEPTH24_STENCIL8 = 0x88F0;
4447
- /* DataType */
4448
4107
 
4108
+ /* DataType */
4449
4109
  var BYTE = 0x1400;
4450
4110
  var UNSIGNED_BYTE = 0x1401;
4451
4111
  var SHORT = 0x1402;
@@ -4458,7 +4118,6 @@ var UNSIGNED_SHORT_5_5_5_1 = 0x8034;
4458
4118
  var UNSIGNED_SHORT_5_6_5 = 0x8363;
4459
4119
  var HALF_FLOAT = 0x140B;
4460
4120
  var HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
4461
-
4462
4121
  var UNSIGNED_INT_2_10_10_10_REV = 0x8368;
4463
4122
  var UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
4464
4123
  var UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
@@ -4521,6 +4180,7 @@ var formatInfo = {};
4521
4180
  numColorComponents: 2
4522
4181
  };
4523
4182
  }
4183
+
4524
4184
  /**
4525
4185
  * @typedef {Object} TextureFormatDetails
4526
4186
  * @property {number} textureFormat format to pass texImage2D and similar functions.
@@ -4532,12 +4192,11 @@ var formatInfo = {};
4532
4192
  */
4533
4193
 
4534
4194
  var s_textureInternalFormatInfo;
4535
-
4536
4195
  function getTextureInternalFormatInfo(internalFormat) {
4537
4196
  if (!s_textureInternalFormatInfo) {
4538
4197
  // NOTE: these properties need unique names so we can let Uglify mangle the name.
4539
- var t = {}; // unsized formats
4540
-
4198
+ var t = {};
4199
+ // unsized formats
4541
4200
  t[ALPHA] = {
4542
4201
  textureFormat: ALPHA,
4543
4202
  colorRenderable: true,
@@ -4579,8 +4238,9 @@ function getTextureInternalFormatInfo(internalFormat) {
4579
4238
  textureFilterable: false,
4580
4239
  bytesPerElement: [2, 4],
4581
4240
  type: [UNSIGNED_INT, UNSIGNED_SHORT]
4582
- }; // sized formats
4241
+ };
4583
4242
 
4243
+ // sized formats
4584
4244
  t[R8] = {
4585
4245
  textureFormat: RED,
4586
4246
  colorRenderable: true,
@@ -4923,8 +4583,8 @@ function getTextureInternalFormatInfo(internalFormat) {
4923
4583
  textureFilterable: false,
4924
4584
  bytesPerElement: [16],
4925
4585
  type: [UNSIGNED_INT]
4926
- }; // Sized Internal
4927
-
4586
+ };
4587
+ // Sized Internal
4928
4588
  t[DEPTH_COMPONENT16] = {
4929
4589
  textureFormat: DEPTH_COMPONENT,
4930
4590
  colorRenderable: true,
@@ -4970,9 +4630,9 @@ function getTextureInternalFormatInfo(internalFormat) {
4970
4630
  });
4971
4631
  s_textureInternalFormatInfo = t;
4972
4632
  }
4973
-
4974
4633
  return s_textureInternalFormatInfo[internalFormat];
4975
4634
  }
4635
+
4976
4636
  /**
4977
4637
  * Gets the number of bytes per element for a given internalFormat / type
4978
4638
  * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
@@ -4980,23 +4640,18 @@ function getTextureInternalFormatInfo(internalFormat) {
4980
4640
  * @return {number} the number of bytes per element for the given internalFormat, type combo
4981
4641
  * @memberOf module:twgl/textures
4982
4642
  */
4983
-
4984
-
4985
4643
  function getBytesPerElementForInternalFormat(internalFormat, type) {
4986
4644
  var info = getTextureInternalFormatInfo(internalFormat);
4987
-
4988
4645
  if (!info) {
4989
4646
  throw "unknown internal format";
4990
4647
  }
4991
-
4992
4648
  var bytesPerElement = info.bytesPerElementMap[type];
4993
-
4994
4649
  if (bytesPerElement === undefined) {
4995
4650
  throw "unknown internal format";
4996
4651
  }
4997
-
4998
4652
  return bytesPerElement;
4999
4653
  }
4654
+
5000
4655
  /**
5001
4656
  * Info related to a specific texture internalFormat as returned
5002
4657
  * from {@link module:twgl/textures.getFormatAndTypeForInternalFormat}.
@@ -5014,31 +4669,27 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
5014
4669
  * @return {module:twgl/textures.TextureFormatInfo} the corresponding format and type,
5015
4670
  * @memberOf module:twgl/textures
5016
4671
  */
5017
-
5018
-
5019
4672
  function getFormatAndTypeForInternalFormat(internalFormat) {
5020
4673
  var info = getTextureInternalFormatInfo(internalFormat);
5021
-
5022
4674
  if (!info) {
5023
4675
  throw "unknown internal format";
5024
4676
  }
5025
-
5026
4677
  return {
5027
4678
  format: info.textureFormat,
5028
4679
  type: info.type[0]
5029
4680
  };
5030
4681
  }
4682
+
5031
4683
  /**
5032
4684
  * Returns true if value is power of 2
5033
4685
  * @param {number} value number to check.
5034
4686
  * @return true if value is power of 2
5035
4687
  * @private
5036
4688
  */
5037
-
5038
-
5039
4689
  function isPowerOf2(value) {
5040
4690
  return (value & value - 1) === 0;
5041
4691
  }
4692
+
5042
4693
  /**
5043
4694
  * Gets whether or not we can generate mips for the given
5044
4695
  * internal format.
@@ -5050,79 +4701,63 @@ function isPowerOf2(value) {
5050
4701
  * @return {boolean} true if we can generate mips
5051
4702
  * @memberOf module:twgl/textures
5052
4703
  */
5053
-
5054
-
5055
4704
  function canGenerateMipmap(gl, width, height, internalFormat) {
5056
4705
  if (!utils.isWebGL2(gl)) {
5057
4706
  return isPowerOf2(width) && isPowerOf2(height);
5058
4707
  }
5059
-
5060
4708
  var info = getTextureInternalFormatInfo(internalFormat);
5061
-
5062
4709
  if (!info) {
5063
4710
  throw "unknown internal format";
5064
4711
  }
5065
-
5066
4712
  return info.colorRenderable && info.textureFilterable;
5067
4713
  }
4714
+
5068
4715
  /**
5069
4716
  * Gets whether or not we can generate mips for the given format
5070
4717
  * @param {number} internalFormat The internalFormat parameter from texImage2D etc..
5071
4718
  * @return {boolean} true if we can generate mips
5072
4719
  * @memberOf module:twgl/textures
5073
4720
  */
5074
-
5075
-
5076
4721
  function canFilter(internalFormat) {
5077
4722
  var info = getTextureInternalFormatInfo(internalFormat);
5078
-
5079
4723
  if (!info) {
5080
4724
  throw "unknown internal format";
5081
4725
  }
5082
-
5083
4726
  return info.textureFilterable;
5084
4727
  }
4728
+
5085
4729
  /**
5086
4730
  * Gets the number of components for a given image format.
5087
4731
  * @param {number} format the format.
5088
4732
  * @return {number} the number of components for the format.
5089
4733
  * @memberOf module:twgl/textures
5090
4734
  */
5091
-
5092
-
5093
4735
  function getNumComponentsForFormat(format) {
5094
4736
  var info = formatInfo[format];
5095
-
5096
4737
  if (!info) {
5097
4738
  throw "unknown format: " + format;
5098
4739
  }
5099
-
5100
4740
  return info.numColorComponents;
5101
4741
  }
4742
+
5102
4743
  /**
5103
4744
  * Gets the texture type for a given array type.
5104
4745
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
5105
4746
  * @return {number} the gl texture type
5106
4747
  * @private
5107
4748
  */
5108
-
5109
-
5110
4749
  function getTextureTypeForArrayType(gl, src, defaultType) {
5111
4750
  if (isArrayBuffer(src)) {
5112
4751
  return typedArrays.getGLTypeForTypedArray(src);
5113
4752
  }
5114
-
5115
4753
  return defaultType || UNSIGNED_BYTE;
5116
4754
  }
5117
-
5118
4755
  function guessDimensions(gl, target, width, height, numElements) {
5119
4756
  if (numElements % 1 !== 0) {
5120
4757
  throw "can't guess dimensions";
5121
4758
  }
5122
-
5123
4759
  if (!width && !height) {
5124
4760
  var size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
5125
-
5126
4761
  if (size % 1 === 0) {
5127
4762
  width = size;
5128
4763
  height = size;
@@ -5132,23 +4767,21 @@ function guessDimensions(gl, target, width, height, numElements) {
5132
4767
  }
5133
4768
  } else if (!height) {
5134
4769
  height = numElements / width;
5135
-
5136
4770
  if (height % 1) {
5137
4771
  throw "can't guess dimensions";
5138
4772
  }
5139
4773
  } else if (!width) {
5140
4774
  width = numElements / height;
5141
-
5142
4775
  if (width % 1) {
5143
4776
  throw "can't guess dimensions";
5144
4777
  }
5145
4778
  }
5146
-
5147
4779
  return {
5148
4780
  width: width,
5149
4781
  height: height
5150
4782
  };
5151
4783
  }
4784
+
5152
4785
  /**
5153
4786
  * Sets the default texture color.
5154
4787
  *
@@ -5162,19 +4795,16 @@ function guessDimensions(gl, target, width, height, numElements) {
5162
4795
  * @deprecated see {@link module:twgl.setDefaults}
5163
4796
  * @memberOf module:twgl/textures
5164
4797
  */
5165
-
5166
-
5167
4798
  function setDefaultTextureColor(color) {
5168
4799
  defaults.textureColor = new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
5169
4800
  }
5170
-
5171
4801
  function setDefaults(newDefaults) {
5172
4802
  helper.copyExistingProperties(newDefaults, defaults);
5173
-
5174
4803
  if (newDefaults.textureColor) {
5175
4804
  setDefaultTextureColor(newDefaults.textureColor);
5176
4805
  }
5177
4806
  }
4807
+
5178
4808
  /**
5179
4809
  * A function to generate the source for a texture.
5180
4810
  * @callback TextureFunc
@@ -5283,31 +4913,25 @@ function setDefaults(newDefaults) {
5283
4913
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
5284
4914
  * @private
5285
4915
  */
5286
-
5287
-
5288
4916
  function setPackState(gl, options) {
5289
4917
  if (options.colorspaceConversion !== undefined) {
5290
4918
  gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
5291
4919
  }
5292
-
5293
4920
  if (options.premultiplyAlpha !== undefined) {
5294
4921
  gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
5295
4922
  }
5296
-
5297
4923
  if (options.flipY !== undefined) {
5298
4924
  gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);
5299
4925
  }
5300
4926
  }
4927
+
5301
4928
  /**
5302
4929
  * Set skip state to defaults
5303
4930
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
5304
4931
  * @private
5305
4932
  */
5306
-
5307
-
5308
4933
  function setSkipStateToDefault(gl) {
5309
4934
  gl.pixelStorei(UNPACK_ALIGNMENT, 4);
5310
-
5311
4935
  if (utils.isWebGL2(gl)) {
5312
4936
  gl.pixelStorei(UNPACK_ROW_LENGTH, 0);
5313
4937
  gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
@@ -5316,6 +4940,7 @@ function setSkipStateToDefault(gl) {
5316
4940
  gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
5317
4941
  }
5318
4942
  }
4943
+
5319
4944
  /**
5320
4945
  * Sets the parameters of a texture or sampler
5321
4946
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
@@ -5326,59 +4951,47 @@ function setSkipStateToDefault(gl) {
5326
4951
  * This is often the same options you passed in when you created the texture.
5327
4952
  * @private
5328
4953
  */
5329
-
5330
-
5331
4954
  function setTextureSamplerParameters(gl, target, parameteriFn, options) {
5332
4955
  if (options.minMag) {
5333
4956
  parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.minMag);
5334
4957
  parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.minMag);
5335
4958
  }
5336
-
5337
4959
  if (options.min) {
5338
4960
  parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.min);
5339
4961
  }
5340
-
5341
4962
  if (options.mag) {
5342
4963
  parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.mag);
5343
4964
  }
5344
-
5345
4965
  if (options.wrap) {
5346
4966
  parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);
5347
4967
  parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);
5348
-
5349
4968
  if (target === TEXTURE_3D || helper.isSampler(gl, target)) {
5350
4969
  parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);
5351
4970
  }
5352
4971
  }
5353
-
5354
4972
  if (options.wrapR) {
5355
4973
  parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrapR);
5356
4974
  }
5357
-
5358
4975
  if (options.wrapS) {
5359
4976
  parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrapS);
5360
4977
  }
5361
-
5362
4978
  if (options.wrapT) {
5363
4979
  parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrapT);
5364
4980
  }
5365
-
5366
4981
  if (options.minLod) {
5367
4982
  parameteriFn.call(gl, target, TEXTURE_MIN_LOD, options.minLod);
5368
4983
  }
5369
-
5370
4984
  if (options.maxLod) {
5371
4985
  parameteriFn.call(gl, target, TEXTURE_MAX_LOD, options.maxLod);
5372
4986
  }
5373
-
5374
4987
  if (options.baseLevel) {
5375
4988
  parameteriFn.call(gl, target, TEXTURE_BASE_LEVEL, options.baseLevel);
5376
4989
  }
5377
-
5378
4990
  if (options.maxLevel) {
5379
4991
  parameteriFn.call(gl, target, TEXTURE_MAX_LEVEL, options.maxLevel);
5380
4992
  }
5381
4993
  }
4994
+
5382
4995
  /**
5383
4996
  * Sets the texture parameters of a texture.
5384
4997
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
@@ -5387,13 +5000,12 @@ function setTextureSamplerParameters(gl, target, parameteriFn, options) {
5387
5000
  * This is often the same options you passed in when you created the texture.
5388
5001
  * @memberOf module:twgl/textures
5389
5002
  */
5390
-
5391
-
5392
5003
  function setTextureParameters(gl, tex, options) {
5393
5004
  var target = options.target || TEXTURE_2D;
5394
5005
  gl.bindTexture(target, tex);
5395
5006
  setTextureSamplerParameters(gl, target, gl.texParameteri, options);
5396
5007
  }
5008
+
5397
5009
  /**
5398
5010
  * Sets the sampler parameters of a sampler.
5399
5011
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
@@ -5401,11 +5013,10 @@ function setTextureParameters(gl, tex, options) {
5401
5013
  * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
5402
5014
  * @memberOf module:twgl/textures
5403
5015
  */
5404
-
5405
-
5406
5016
  function setSamplerParameters(gl, sampler, options) {
5407
5017
  setTextureSamplerParameters(gl, sampler, gl.samplerParameteri, options);
5408
5018
  }
5019
+
5409
5020
  /**
5410
5021
  * Creates a new sampler object and sets parameters.
5411
5022
  *
@@ -5421,13 +5032,12 @@ function setSamplerParameters(gl, sampler, options) {
5421
5032
  * @return {Object.<string,WebGLSampler>} the created samplers by name
5422
5033
  * @private
5423
5034
  */
5424
-
5425
-
5426
5035
  function createSampler(gl, options) {
5427
5036
  var sampler = gl.createSampler();
5428
5037
  setSamplerParameters(gl, sampler, options);
5429
5038
  return sampler;
5430
5039
  }
5040
+
5431
5041
  /**
5432
5042
  * Creates a multiple sampler objects and sets parameters on each.
5433
5043
  *
@@ -5462,8 +5072,6 @@ function createSampler(gl, options) {
5462
5072
  * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set on the sampler
5463
5073
  * @private
5464
5074
  */
5465
-
5466
-
5467
5075
  function createSamplers(gl, samplerOptions) {
5468
5076
  var samplers = {};
5469
5077
  Object.keys(samplerOptions).forEach(function (name) {
@@ -5471,6 +5079,7 @@ function createSamplers(gl, samplerOptions) {
5471
5079
  });
5472
5080
  return samplers;
5473
5081
  }
5082
+
5474
5083
  /**
5475
5084
  * Makes a 1x1 pixel
5476
5085
  * If no color is passed in uses the default color which can be set by calling `setDefaultTextureColor`.
@@ -5478,17 +5087,14 @@ function createSamplers(gl, samplerOptions) {
5478
5087
  * @return {Uint8Array} Unit8Array with color.
5479
5088
  * @private
5480
5089
  */
5481
-
5482
-
5483
5090
  function make1Pixel(color) {
5484
5091
  color = color || defaults.textureColor;
5485
-
5486
5092
  if (isArrayBuffer(color)) {
5487
5093
  return color;
5488
5094
  }
5489
-
5490
5095
  return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
5491
5096
  }
5097
+
5492
5098
  /**
5493
5099
  * Sets filtering or generates mips for texture based on width or height
5494
5100
  * If width or height is not passed in uses `options.width` and//or `options.height`
@@ -5502,8 +5108,6 @@ function make1Pixel(color) {
5502
5108
  * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
5503
5109
  * @memberOf module:twgl/textures
5504
5110
  */
5505
-
5506
-
5507
5111
  function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
5508
5112
  options = options || defaults.textureOptions;
5509
5113
  internalFormat = internalFormat || RGBA;
@@ -5511,7 +5115,6 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
5511
5115
  width = width || options.width;
5512
5116
  height = height || options.height;
5513
5117
  gl.bindTexture(target, tex);
5514
-
5515
5118
  if (canGenerateMipmap(gl, width, height, internalFormat)) {
5516
5119
  gl.generateMipmap(target);
5517
5120
  } else {
@@ -5522,10 +5125,10 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
5522
5125
  gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
5523
5126
  }
5524
5127
  }
5525
-
5526
5128
  function shouldAutomaticallySetTextureFilteringForSize(options) {
5527
5129
  return options.auto === true || options.auto === undefined && options.level === undefined;
5528
5130
  }
5131
+
5529
5132
  /**
5530
5133
  * Gets an array of cubemap face enums
5531
5134
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
@@ -5534,12 +5137,11 @@ function shouldAutomaticallySetTextureFilteringForSize(options) {
5534
5137
  * @return {number[]} cubemap face enums
5535
5138
  * @private
5536
5139
  */
5537
-
5538
-
5539
5140
  function getCubeFaceOrder(gl, options) {
5540
5141
  options = options || {};
5541
5142
  return options.cubeFaceOrder || [TEXTURE_CUBE_MAP_POSITIVE_X, TEXTURE_CUBE_MAP_NEGATIVE_X, TEXTURE_CUBE_MAP_POSITIVE_Y, TEXTURE_CUBE_MAP_NEGATIVE_Y, TEXTURE_CUBE_MAP_POSITIVE_Z, TEXTURE_CUBE_MAP_NEGATIVE_Z];
5542
5143
  }
5144
+
5543
5145
  /**
5544
5146
  * @typedef {Object} FaceInfo
5545
5147
  * @property {number} face gl enum for texImage2D
@@ -5560,11 +5162,9 @@ function getCubeFaceOrder(gl, options) {
5560
5162
  * it's needed internally to sort the array of `ndx` properties by `face`.
5561
5163
  * @private
5562
5164
  */
5563
-
5564
-
5565
5165
  function getCubeFacesWithNdx(gl, options) {
5566
- var faces = getCubeFaceOrder(gl, options); // work around bug in NVidia drivers. We have to upload the first face first else the driver crashes :(
5567
-
5166
+ var faces = getCubeFaceOrder(gl, options);
5167
+ // work around bug in NVidia drivers. We have to upload the first face first else the driver crashes :(
5568
5168
  var facesWithNdx = faces.map(function (face, ndx) {
5569
5169
  return {
5570
5170
  face: face,
@@ -5576,6 +5176,7 @@ function getCubeFacesWithNdx(gl, options) {
5576
5176
  });
5577
5177
  return facesWithNdx;
5578
5178
  }
5179
+
5579
5180
  /**
5580
5181
  * Set a texture from the contents of an element. Will also set
5581
5182
  * texture filtering or generate mips based on the dimensions of the element
@@ -5589,8 +5190,6 @@ function getCubeFacesWithNdx(gl, options) {
5589
5190
  * @memberOf module:twgl/textures
5590
5191
  * @kind function
5591
5192
  */
5592
-
5593
-
5594
5193
  function setTextureFromElement(gl, tex, element, options) {
5595
5194
  options = options || defaults.textureOptions;
5596
5195
  var target = options.target || TEXTURE_2D;
@@ -5603,14 +5202,12 @@ function setTextureFromElement(gl, tex, element, options) {
5603
5202
  var type = options.type || formatType.type;
5604
5203
  setPackState(gl, options);
5605
5204
  gl.bindTexture(target, tex);
5606
-
5607
5205
  if (target === TEXTURE_CUBE_MAP) {
5608
5206
  // guess the parts
5609
5207
  var imgWidth = element.width;
5610
5208
  var imgHeight = element.height;
5611
5209
  var size;
5612
5210
  var slices;
5613
-
5614
5211
  if (imgWidth / 6 === imgHeight) {
5615
5212
  // It's 6x1
5616
5213
  size = imgHeight;
@@ -5630,9 +5227,7 @@ function setTextureFromElement(gl, tex, element, options) {
5630
5227
  } else {
5631
5228
  throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
5632
5229
  }
5633
-
5634
5230
  var ctx = getShared2DContext();
5635
-
5636
5231
  if (ctx) {
5637
5232
  ctx.canvas.width = size;
5638
5233
  ctx.canvas.height = size;
@@ -5643,8 +5238,8 @@ function setTextureFromElement(gl, tex, element, options) {
5643
5238
  var yOffset = slices[f.ndx * 2 + 1] * size;
5644
5239
  ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
5645
5240
  gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
5646
- }); // Free up the canvas memory
5647
-
5241
+ });
5242
+ // Free up the canvas memory
5648
5243
  ctx.canvas.width = 1;
5649
5244
  ctx.canvas.height = 1;
5650
5245
  } else if (typeof createImageBitmap !== 'undefined') {
@@ -5654,12 +5249,12 @@ function setTextureFromElement(gl, tex, element, options) {
5654
5249
  height = size;
5655
5250
  getCubeFacesWithNdx(gl, options).forEach(function (f) {
5656
5251
  var xOffset = slices[f.ndx * 2 + 0] * size;
5657
- var yOffset = slices[f.ndx * 2 + 1] * size; // We can't easily use a default texture color here as it would have to match
5252
+ var yOffset = slices[f.ndx * 2 + 1] * size;
5253
+ // We can't easily use a default texture color here as it would have to match
5658
5254
  // the type across all faces where as with a 2D one there's only one face
5659
5255
  // so we're replacing everything all at once. It also has to be the correct size.
5660
5256
  // On the other hand we need all faces to be the same size so as one face loads
5661
5257
  // the rest match else the texture will be un-renderable.
5662
-
5663
5258
  gl.texImage2D(f.face, level, internalFormat, size, size, 0, format, type, null);
5664
5259
  createImageBitmap(element, xOffset, yOffset, size, size, {
5665
5260
  premultiplyAlpha: 'none',
@@ -5668,7 +5263,6 @@ function setTextureFromElement(gl, tex, element, options) {
5668
5263
  setPackState(gl, options);
5669
5264
  gl.bindTexture(target, tex);
5670
5265
  gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
5671
-
5672
5266
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
5673
5267
  setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
5674
5268
  }
@@ -5679,11 +5273,9 @@ function setTextureFromElement(gl, tex, element, options) {
5679
5273
  var smallest = Math.min(element.width, element.height);
5680
5274
  var largest = Math.max(element.width, element.height);
5681
5275
  var depth = largest / smallest;
5682
-
5683
5276
  if (depth % 1 !== 0) {
5684
5277
  throw "can not compute 3D dimensions of element";
5685
5278
  }
5686
-
5687
5279
  var xMult = element.width === largest ? 1 : 0;
5688
5280
  var yMult = element.height === largest ? 1 : 0;
5689
5281
  gl.pixelStorei(UNPACK_ALIGNMENT, 1);
@@ -5691,7 +5283,6 @@ function setTextureFromElement(gl, tex, element, options) {
5691
5283
  gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
5692
5284
  gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
5693
5285
  gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
5694
-
5695
5286
  for (var d = 0; d < depth; ++d) {
5696
5287
  var srcX = d * smallest * xMult;
5697
5288
  var srcY = d * smallest * yMult;
@@ -5699,28 +5290,23 @@ function setTextureFromElement(gl, tex, element, options) {
5699
5290
  gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
5700
5291
  gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
5701
5292
  }
5702
-
5703
5293
  setSkipStateToDefault(gl);
5704
5294
  } else {
5705
5295
  gl.texImage2D(target, level, internalFormat, format, type, element);
5706
5296
  }
5707
-
5708
5297
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
5709
5298
  setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
5710
5299
  }
5711
-
5712
5300
  setTextureParameters(gl, tex, options);
5713
5301
  }
5714
-
5715
5302
  function noop() {}
5303
+
5716
5304
  /**
5717
5305
  * Checks whether the url's origin is the same so that we can set the `crossOrigin`
5718
5306
  * @param {string} url url to image
5719
5307
  * @returns {boolean} true if the window's origin is the same as image's url
5720
5308
  * @private
5721
5309
  */
5722
-
5723
-
5724
5310
  function urlIsSameOrigin(url) {
5725
5311
  if (typeof document !== 'undefined') {
5726
5312
  // for IE really
@@ -5733,10 +5319,10 @@ function urlIsSameOrigin(url) {
5733
5319
  return urlOrigin === localOrigin;
5734
5320
  }
5735
5321
  }
5736
-
5737
5322
  function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
5738
5323
  return crossOrigin === undefined && !urlIsSameOrigin(url) ? 'anonymous' : crossOrigin;
5739
5324
  }
5325
+
5740
5326
  /**
5741
5327
  * Loads an image
5742
5328
  * @param {string} url url to image
@@ -5746,41 +5332,31 @@ function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
5746
5332
  * @return {HTMLImageElement} the image being loaded.
5747
5333
  * @private
5748
5334
  */
5749
-
5750
-
5751
5335
  function loadImage(url, crossOrigin, callback) {
5752
5336
  callback = callback || noop;
5753
5337
  var img;
5754
5338
  crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults.crossOrigin;
5755
5339
  crossOrigin = setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin);
5756
-
5757
5340
  if (typeof Image !== 'undefined') {
5758
5341
  img = new Image();
5759
-
5760
5342
  if (crossOrigin !== undefined) {
5761
5343
  img.crossOrigin = crossOrigin;
5762
5344
  }
5763
-
5764
5345
  var clearEventHandlers = function clearEventHandlers() {
5765
5346
  img.removeEventListener('error', onError); // eslint-disable-line
5766
-
5767
5347
  img.removeEventListener('load', onLoad); // eslint-disable-line
5768
-
5769
5348
  img = null;
5770
5349
  };
5771
-
5772
5350
  var onError = function onError() {
5773
5351
  var msg = "couldn't load image: " + url;
5774
5352
  helper.error(msg);
5775
5353
  callback(msg, img);
5776
5354
  clearEventHandlers();
5777
5355
  };
5778
-
5779
5356
  var onLoad = function onLoad() {
5780
5357
  callback(null, img);
5781
5358
  clearEventHandlers();
5782
5359
  };
5783
-
5784
5360
  img.addEventListener('error', onError);
5785
5361
  img.addEventListener('load', onLoad);
5786
5362
  img.src = url;
@@ -5788,13 +5364,10 @@ function loadImage(url, crossOrigin, callback) {
5788
5364
  } else if (typeof ImageBitmap !== 'undefined') {
5789
5365
  var err;
5790
5366
  var bm;
5791
-
5792
5367
  var cb = function cb() {
5793
5368
  callback(err, bm);
5794
5369
  };
5795
-
5796
5370
  var options = {};
5797
-
5798
5371
  if (crossOrigin) {
5799
5372
  options.mode = 'cors'; // TODO: not sure how to translate image.crossOrigin
5800
5373
  }
@@ -5803,7 +5376,6 @@ function loadImage(url, crossOrigin, callback) {
5803
5376
  if (!response.ok) {
5804
5377
  throw response;
5805
5378
  }
5806
-
5807
5379
  return response.blob();
5808
5380
  }).then(function (blob) {
5809
5381
  return createImageBitmap(blob, {
@@ -5823,9 +5395,9 @@ function loadImage(url, crossOrigin, callback) {
5823
5395
  });
5824
5396
  img = null;
5825
5397
  }
5826
-
5827
5398
  return img;
5828
5399
  }
5400
+
5829
5401
  /**
5830
5402
  * check if object is a TexImageSource
5831
5403
  *
@@ -5833,11 +5405,10 @@ function loadImage(url, crossOrigin, callback) {
5833
5405
  * @return {boolean} true if object is a TexImageSource
5834
5406
  * @private
5835
5407
  */
5836
-
5837
-
5838
5408
  function isTexImageSource(obj) {
5839
5409
  return typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap || typeof ImageData !== 'undefined' && obj instanceof ImageData || typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement;
5840
5410
  }
5411
+
5841
5412
  /**
5842
5413
  * if obj is an TexImageSource then just
5843
5414
  * uses it otherwise if obj is a string
@@ -5849,8 +5420,6 @@ function isTexImageSource(obj) {
5849
5420
  * if there was an error
5850
5421
  * @private
5851
5422
  */
5852
-
5853
-
5854
5423
  function loadAndUseImage(obj, crossOrigin, callback) {
5855
5424
  if (isTexImageSource(obj)) {
5856
5425
  setTimeout(function () {
@@ -5858,9 +5427,9 @@ function loadAndUseImage(obj, crossOrigin, callback) {
5858
5427
  });
5859
5428
  return obj;
5860
5429
  }
5861
-
5862
5430
  return loadImage(obj, crossOrigin, callback);
5863
5431
  }
5432
+
5864
5433
  /**
5865
5434
  * Sets a texture to a 1x1 pixel color. If `options.color === false` is nothing happens. If it's not set
5866
5435
  * the default texture color is used which can be set by calling `setDefaultTextureColor`.
@@ -5871,21 +5440,16 @@ function loadAndUseImage(obj, crossOrigin, callback) {
5871
5440
  * @memberOf module:twgl/textures
5872
5441
  * @private
5873
5442
  */
5874
-
5875
-
5876
5443
  function setTextureTo1PixelColor(gl, tex, options) {
5877
5444
  options = options || defaults.textureOptions;
5878
5445
  var target = options.target || TEXTURE_2D;
5879
5446
  gl.bindTexture(target, tex);
5880
-
5881
5447
  if (options.color === false) {
5882
5448
  return;
5883
- } // Assume it's a URL
5449
+ }
5450
+ // Assume it's a URL
5884
5451
  // Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.
5885
-
5886
-
5887
5452
  var color = make1Pixel(options.color);
5888
-
5889
5453
  if (target === TEXTURE_CUBE_MAP) {
5890
5454
  for (var ii = 0; ii < 6; ++ii) {
5891
5455
  gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
@@ -5896,6 +5460,7 @@ function setTextureTo1PixelColor(gl, tex, options) {
5896
5460
  gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
5897
5461
  }
5898
5462
  }
5463
+
5899
5464
  /**
5900
5465
  * The src image(s) used to create a texture.
5901
5466
  *
@@ -5957,13 +5522,11 @@ function setTextureTo1PixelColor(gl, tex, options) {
5957
5522
  * @return {HTMLImageElement} the image being downloaded.
5958
5523
  * @memberOf module:twgl/textures
5959
5524
  */
5960
-
5961
-
5962
5525
  function loadTextureFromUrl(gl, tex, options, callback) {
5963
5526
  callback = callback || noop;
5964
5527
  options = options || defaults.textureOptions;
5965
- setTextureTo1PixelColor(gl, tex, options); // Because it's async we need to copy the options.
5966
-
5528
+ setTextureTo1PixelColor(gl, tex, options);
5529
+ // Because it's async we need to copy the options.
5967
5530
  options = Object.assign({}, options);
5968
5531
  var img = loadAndUseImage(options.src, options.crossOrigin, function (err, img) {
5969
5532
  if (err) {
@@ -5975,6 +5538,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
5975
5538
  });
5976
5539
  return img;
5977
5540
  }
5541
+
5978
5542
  /**
5979
5543
  * Loads a cubemap from 6 urls or TexImageSources as specified in `options.src`. Will set the cubemap to a 1x1 pixel color
5980
5544
  * so that it is usable immediately unless `option.color === false`.
@@ -5986,29 +5550,23 @@ function loadTextureFromUrl(gl, tex, options, callback) {
5986
5550
  * @memberOf module:twgl/textures
5987
5551
  * @private
5988
5552
  */
5989
-
5990
-
5991
5553
  function loadCubemapFromUrls(gl, tex, options, callback) {
5992
5554
  callback = callback || noop;
5993
5555
  var urls = options.src;
5994
-
5995
5556
  if (urls.length !== 6) {
5996
5557
  throw "there must be 6 urls for a cubemap";
5997
5558
  }
5998
-
5999
5559
  var level = options.level || 0;
6000
5560
  var internalFormat = options.internalFormat || options.format || RGBA;
6001
5561
  var formatType = getFormatAndTypeForInternalFormat(internalFormat);
6002
5562
  var format = options.format || formatType.format;
6003
5563
  var type = options.type || UNSIGNED_BYTE;
6004
5564
  var target = options.target || TEXTURE_2D;
6005
-
6006
5565
  if (target !== TEXTURE_CUBE_MAP) {
6007
5566
  throw "target must be TEXTURE_CUBE_MAP";
6008
5567
  }
6009
-
6010
- setTextureTo1PixelColor(gl, tex, options); // Because it's async we need to copy the options.
6011
-
5568
+ setTextureTo1PixelColor(gl, tex, options);
5569
+ // Because it's async we need to copy the options.
6012
5570
  options = Object.assign({}, options);
6013
5571
  var numToLoad = 6;
6014
5572
  var errors = [];
@@ -6018,7 +5576,6 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6018
5576
  function uploadImg(faceTarget) {
6019
5577
  return function (err, img) {
6020
5578
  --numToLoad;
6021
-
6022
5579
  if (err) {
6023
5580
  errors.push(err);
6024
5581
  } else {
@@ -6026,9 +5583,10 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6026
5583
  errors.push("cubemap face img is not a square: " + img.src);
6027
5584
  } else {
6028
5585
  setPackState(gl, options);
6029
- gl.bindTexture(target, tex); // So assuming this is the first image we now have one face that's img sized
6030
- // and 5 faces that are 1x1 pixel so size the other faces
5586
+ gl.bindTexture(target, tex);
6031
5587
 
5588
+ // So assuming this is the first image we now have one face that's img sized
5589
+ // and 5 faces that are 1x1 pixel so size the other faces
6032
5590
  if (numToLoad === 5) {
6033
5591
  // use the default order
6034
5592
  getCubeFaceOrder(gl).forEach(function (otherTarget) {
@@ -6038,23 +5596,21 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6038
5596
  } else {
6039
5597
  gl.texImage2D(faceTarget, level, internalFormat, format, type, img);
6040
5598
  }
6041
-
6042
5599
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
6043
5600
  gl.generateMipmap(target);
6044
5601
  }
6045
5602
  }
6046
5603
  }
6047
-
6048
5604
  if (numToLoad === 0) {
6049
5605
  callback(errors.length ? errors : undefined, tex, imgs);
6050
5606
  }
6051
5607
  };
6052
5608
  }
6053
-
6054
5609
  imgs = urls.map(function (url, ndx) {
6055
5610
  return loadAndUseImage(url, options.crossOrigin, uploadImg(faces[ndx]));
6056
5611
  });
6057
5612
  }
5613
+
6058
5614
  /**
6059
5615
  * Loads a 2d array or 3d texture from urls OR TexImageSources as specified in `options.src`.
6060
5616
  * Will set the texture to a 1x1 pixel color
@@ -6075,8 +5631,6 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6075
5631
  * @memberOf module:twgl/textures
6076
5632
  * @private
6077
5633
  */
6078
-
6079
-
6080
5634
  function loadSlicesFromUrls(gl, tex, options, callback) {
6081
5635
  callback = callback || noop;
6082
5636
  var urls = options.src;
@@ -6085,47 +5639,41 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
6085
5639
  var format = options.format || formatType.format;
6086
5640
  var type = options.type || UNSIGNED_BYTE;
6087
5641
  var target = options.target || TEXTURE_2D_ARRAY;
6088
-
6089
5642
  if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
6090
5643
  throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
6091
5644
  }
6092
-
6093
- setTextureTo1PixelColor(gl, tex, options); // Because it's async we need to copy the options.
6094
-
5645
+ setTextureTo1PixelColor(gl, tex, options);
5646
+ // Because it's async we need to copy the options.
6095
5647
  options = Object.assign({}, options);
6096
5648
  var numToLoad = urls.length;
6097
5649
  var errors = [];
6098
5650
  var imgs; // eslint-disable-line
6099
-
6100
5651
  var level = options.level || 0;
6101
5652
  var width = options.width;
6102
5653
  var height = options.height;
6103
5654
  var depth = urls.length;
6104
5655
  var firstImage = true;
6105
-
6106
5656
  function uploadImg(slice) {
6107
5657
  return function (err, img) {
6108
5658
  --numToLoad;
6109
-
6110
5659
  if (err) {
6111
5660
  errors.push(err);
6112
5661
  } else {
6113
5662
  setPackState(gl, options);
6114
5663
  gl.bindTexture(target, tex);
6115
-
6116
5664
  if (firstImage) {
6117
5665
  firstImage = false;
6118
5666
  width = options.width || img.width;
6119
5667
  height = options.height || img.height;
6120
- gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null); // put it in every slice otherwise some slices will be 0,0,0,0
5668
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
6121
5669
 
5670
+ // put it in every slice otherwise some slices will be 0,0,0,0
6122
5671
  for (var s = 0; s < depth; ++s) {
6123
5672
  gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);
6124
5673
  }
6125
5674
  } else {
6126
5675
  var src = img;
6127
5676
  var ctx;
6128
-
6129
5677
  if (img.width !== width || img.height !== height) {
6130
5678
  // Size the image to fix
6131
5679
  ctx = getShared2DContext();
@@ -6134,30 +5682,28 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
6134
5682
  ctx.canvas.height = height;
6135
5683
  ctx.drawImage(img, 0, 0, width, height);
6136
5684
  }
5685
+ gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src);
6137
5686
 
6138
- gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src); // free the canvas memory
6139
-
5687
+ // free the canvas memory
6140
5688
  if (ctx && src === ctx.canvas) {
6141
5689
  ctx.canvas.width = 0;
6142
5690
  ctx.canvas.height = 0;
6143
5691
  }
6144
5692
  }
6145
-
6146
5693
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
6147
5694
  gl.generateMipmap(target);
6148
5695
  }
6149
5696
  }
6150
-
6151
5697
  if (numToLoad === 0) {
6152
5698
  callback(errors.length ? errors : undefined, tex, imgs);
6153
5699
  }
6154
5700
  };
6155
5701
  }
6156
-
6157
5702
  imgs = urls.map(function (url, ndx) {
6158
5703
  return loadAndUseImage(url, options.crossOrigin, uploadImg(ndx));
6159
5704
  });
6160
5705
  }
5706
+
6161
5707
  /**
6162
5708
  * Sets a texture from an array or typed array. If the width or height is not provided will attempt to
6163
5709
  * guess the size. See {@link module:twgl.TextureOptions}.
@@ -6168,8 +5714,6 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
6168
5714
  * This is often the same options you passed in when you created the texture.
6169
5715
  * @memberOf module:twgl/textures
6170
5716
  */
6171
-
6172
-
6173
5717
  function setTextureFromArray(gl, tex, src, options) {
6174
5718
  options = options || defaults.textureOptions;
6175
5719
  var target = options.target || TEXTURE_2D;
@@ -6182,31 +5726,24 @@ function setTextureFromArray(gl, tex, src, options) {
6182
5726
  var formatType = getFormatAndTypeForInternalFormat(internalFormat);
6183
5727
  var format = options.format || formatType.format;
6184
5728
  var type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
6185
-
6186
5729
  if (!isArrayBuffer(src)) {
6187
5730
  var Type = typedArrays.getTypedArrayTypeForGLType(type);
6188
5731
  src = new Type(src);
6189
5732
  } else if (src instanceof Uint8ClampedArray) {
6190
5733
  src = new Uint8Array(src.buffer);
6191
5734
  }
6192
-
6193
5735
  var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
6194
5736
  var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
6195
-
6196
5737
  if (numElements % 1) {
6197
5738
  throw "length wrong size for format: " + utils.glEnumToString(gl, format);
6198
5739
  }
6199
-
6200
5740
  var dimensions;
6201
-
6202
5741
  if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6203
5742
  if (!width && !height && !depth) {
6204
5743
  var size = Math.cbrt(numElements);
6205
-
6206
5744
  if (size % 1 !== 0) {
6207
5745
  throw "can't guess cube size of array of numElements: " + numElements;
6208
5746
  }
6209
-
6210
5747
  width = size;
6211
5748
  height = size;
6212
5749
  depth = size;
@@ -6228,11 +5765,9 @@ function setTextureFromArray(gl, tex, src, options) {
6228
5765
  width = dimensions.width;
6229
5766
  height = dimensions.height;
6230
5767
  }
6231
-
6232
5768
  setSkipStateToDefault(gl);
6233
5769
  gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
6234
5770
  setPackState(gl, options);
6235
-
6236
5771
  if (target === TEXTURE_CUBE_MAP) {
6237
5772
  var elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
6238
5773
  var faceSize = numElements / 6 * elementsPerElement;
@@ -6246,7 +5781,6 @@ function setTextureFromArray(gl, tex, src, options) {
6246
5781
  } else {
6247
5782
  gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
6248
5783
  }
6249
-
6250
5784
  return {
6251
5785
  width: width,
6252
5786
  height: height,
@@ -6254,6 +5788,7 @@ function setTextureFromArray(gl, tex, src, options) {
6254
5788
  type: type
6255
5789
  };
6256
5790
  }
5791
+
6257
5792
  /**
6258
5793
  * Sets a texture with no contents of a certain size. In other words calls `gl.texImage2D` with `null`.
6259
5794
  * You must set `options.width` and `options.height`.
@@ -6262,8 +5797,6 @@ function setTextureFromArray(gl, tex, src, options) {
6262
5797
  * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
6263
5798
  * @memberOf module:twgl/textures
6264
5799
  */
6265
-
6266
-
6267
5800
  function setEmptyTexture(gl, tex, options) {
6268
5801
  var target = options.target || TEXTURE_2D;
6269
5802
  gl.bindTexture(target, tex);
@@ -6273,7 +5806,6 @@ function setEmptyTexture(gl, tex, options) {
6273
5806
  var format = options.format || formatType.format;
6274
5807
  var type = options.type || formatType.type;
6275
5808
  setPackState(gl, options);
6276
-
6277
5809
  if (target === TEXTURE_CUBE_MAP) {
6278
5810
  for (var ii = 0; ii < 6; ++ii) {
6279
5811
  gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
@@ -6284,6 +5816,7 @@ function setEmptyTexture(gl, tex, options) {
6284
5816
  gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
6285
5817
  }
6286
5818
  }
5819
+
6287
5820
  /**
6288
5821
  * Creates a texture based on the options passed in.
6289
5822
  *
@@ -6296,8 +5829,6 @@ function setEmptyTexture(gl, tex, options) {
6296
5829
  * @return {WebGLTexture} the created texture.
6297
5830
  * @memberOf module:twgl/textures
6298
5831
  */
6299
-
6300
-
6301
5832
  function createTexture(gl, options, callback) {
6302
5833
  callback = callback || noop;
6303
5834
  options = options || defaults.textureOptions;
@@ -6307,20 +5838,16 @@ function createTexture(gl, options, callback) {
6307
5838
  var height = options.height || 1;
6308
5839
  var internalFormat = options.internalFormat || RGBA;
6309
5840
  gl.bindTexture(target, tex);
6310
-
6311
5841
  if (target === TEXTURE_CUBE_MAP) {
6312
5842
  // this should have been the default for cubemaps :(
6313
5843
  gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
6314
5844
  gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
6315
5845
  }
6316
-
6317
5846
  var src = options.src;
6318
-
6319
5847
  if (src) {
6320
5848
  if (typeof src === "function") {
6321
5849
  src = src(gl, options);
6322
5850
  }
6323
-
6324
5851
  if (typeof src === "string") {
6325
5852
  loadTextureFromUrl(gl, tex, options, callback);
6326
5853
  } else if (isArrayBuffer(src) || Array.isArray(src) && (typeof src[0] === 'number' || Array.isArray(src[0]) || isArrayBuffer(src[0]))) {
@@ -6342,14 +5869,13 @@ function createTexture(gl, options, callback) {
6342
5869
  } else {
6343
5870
  setEmptyTexture(gl, tex, options);
6344
5871
  }
6345
-
6346
5872
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
6347
5873
  setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
6348
5874
  }
6349
-
6350
5875
  setTextureParameters(gl, tex, options);
6351
5876
  return tex;
6352
5877
  }
5878
+
6353
5879
  /**
6354
5880
  * Resizes a texture based on the options passed in.
6355
5881
  *
@@ -6367,8 +5893,6 @@ function createTexture(gl, options, callback) {
6367
5893
  * @param {number} [depth] the new depth. If not passed in will use `options.depth`
6368
5894
  * @memberOf module:twgl/textures
6369
5895
  */
6370
-
6371
-
6372
5896
  function resizeTexture(gl, tex, options, width, height, depth) {
6373
5897
  width = width || options.width;
6374
5898
  height = height || options.height;
@@ -6381,7 +5905,6 @@ function resizeTexture(gl, tex, options, width, height, depth) {
6381
5905
  var format = options.format || formatType.format;
6382
5906
  var type;
6383
5907
  var src = options.src;
6384
-
6385
5908
  if (!src) {
6386
5909
  type = options.type || formatType.type;
6387
5910
  } else if (isArrayBuffer(src) || Array.isArray(src) && typeof src[0] === 'number') {
@@ -6389,7 +5912,6 @@ function resizeTexture(gl, tex, options, width, height, depth) {
6389
5912
  } else {
6390
5913
  type = options.type || formatType.type;
6391
5914
  }
6392
-
6393
5915
  if (target === TEXTURE_CUBE_MAP) {
6394
5916
  for (var ii = 0; ii < 6; ++ii) {
6395
5917
  gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, width, height, 0, format, type, null);
@@ -6400,6 +5922,7 @@ function resizeTexture(gl, tex, options, width, height, depth) {
6400
5922
  gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, null);
6401
5923
  }
6402
5924
  }
5925
+
6403
5926
  /**
6404
5927
  * Check if a src is an async request.
6405
5928
  * if src is a string we're going to download an image
@@ -6408,11 +5931,10 @@ function resizeTexture(gl, tex, options, width, height, depth) {
6408
5931
  * @returns {bool} true if src is async.
6409
5932
  * @private
6410
5933
  */
6411
-
6412
-
6413
5934
  function isAsyncSrc(src) {
6414
5935
  return typeof src === 'string' || Array.isArray(src) && typeof src[0] === 'string';
6415
5936
  }
5937
+
6416
5938
  /**
6417
5939
  * Creates a bunch of textures based on the passed in options.
6418
5940
  *
@@ -6488,15 +6010,12 @@ function isAsyncSrc(src) {
6488
6010
  * @return {Object.<string,WebGLTexture>} the created textures by name
6489
6011
  * @memberOf module:twgl/textures
6490
6012
  */
6491
-
6492
-
6493
6013
  function createTextures(gl, textureOptions, callback) {
6494
6014
  callback = callback || noop;
6495
6015
  var numDownloading = 0;
6496
6016
  var errors = [];
6497
6017
  var textures = {};
6498
6018
  var images = {};
6499
-
6500
6019
  function callCallbackIfReady() {
6501
6020
  if (numDownloading === 0) {
6502
6021
  setTimeout(function () {
@@ -6504,32 +6023,27 @@ function createTextures(gl, textureOptions, callback) {
6504
6023
  }, 0);
6505
6024
  }
6506
6025
  }
6507
-
6508
6026
  Object.keys(textureOptions).forEach(function (name) {
6509
6027
  var options = textureOptions[name];
6510
6028
  var onLoadFn;
6511
-
6512
6029
  if (isAsyncSrc(options.src)) {
6513
6030
  onLoadFn = function onLoadFn(err, tex, img) {
6514
6031
  images[name] = img;
6515
6032
  --numDownloading;
6516
-
6517
6033
  if (err) {
6518
6034
  errors.push(err);
6519
6035
  }
6520
-
6521
6036
  callCallbackIfReady();
6522
6037
  };
6523
-
6524
6038
  ++numDownloading;
6525
6039
  }
6526
-
6527
6040
  textures[name] = createTexture(gl, options, onLoadFn);
6528
- }); // queue the callback if there are no images to download.
6041
+ });
6042
+
6043
+ // queue the callback if there are no images to download.
6529
6044
  // We do this because if your code is structured to wait for
6530
6045
  // images to download but then you comment out all the async
6531
6046
  // images your code would break.
6532
-
6533
6047
  callCallbackIfReady();
6534
6048
  return textures;
6535
6049
  }
@@ -6547,11 +6061,10 @@ function createTextures(gl, textureOptions, callback) {
6547
6061
 
6548
6062
 
6549
6063
  exports.__esModule = true;
6550
-
6551
6064
  var _twgl = __webpack_require__(/*! ./twgl.js */ "./src/twgl.js");
6552
-
6553
6065
  Object.keys(_twgl).forEach(function (key) {
6554
6066
  if (key === "default" || key === "__esModule") return;
6067
+ if (key in exports && exports[key] === _twgl[key]) return;
6555
6068
  exports[key] = _twgl[key];
6556
6069
  });
6557
6070
 
@@ -6567,8 +6080,7 @@ Object.keys(_twgl).forEach(function (key) {
6567
6080
  "use strict";
6568
6081
 
6569
6082
 
6570
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
6571
-
6083
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
6572
6084
  exports.__esModule = true;
6573
6085
  var _exportNames = {
6574
6086
  addExtensionsToContext: true,
@@ -6586,90 +6098,80 @@ var _exportNames = {
6586
6098
  vertexArrays: true
6587
6099
  };
6588
6100
  exports.addExtensionsToContext = addExtensionsToContext;
6101
+ exports.framebuffers = exports.draw = exports.attributes = void 0;
6589
6102
  exports.getContext = getContext;
6590
6103
  exports.getWebGLContext = getWebGLContext;
6104
+ exports.programs = void 0;
6591
6105
  exports.resizeCanvasToDisplaySize = resizeCanvasToDisplaySize;
6592
6106
  exports.setDefaults = setDefaults;
6593
- exports.vertexArrays = exports.typedarrays = exports.programs = exports.framebuffers = exports.draw = exports.utils = exports.textures = exports.attributes = void 0;
6594
-
6107
+ exports.vertexArrays = exports.utils = exports.typedarrays = exports.textures = void 0;
6595
6108
  var attributes = _interopRequireWildcard(__webpack_require__(/*! ./attributes.js */ "./src/attributes.js"));
6596
-
6597
6109
  exports.attributes = attributes;
6598
6110
  Object.keys(attributes).forEach(function (key) {
6599
6111
  if (key === "default" || key === "__esModule") return;
6600
6112
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6113
+ if (key in exports && exports[key] === attributes[key]) return;
6601
6114
  exports[key] = attributes[key];
6602
6115
  });
6603
-
6604
6116
  var textures = _interopRequireWildcard(__webpack_require__(/*! ./textures.js */ "./src/textures.js"));
6605
-
6606
6117
  exports.textures = textures;
6607
6118
  Object.keys(textures).forEach(function (key) {
6608
6119
  if (key === "default" || key === "__esModule") return;
6609
6120
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6121
+ if (key in exports && exports[key] === textures[key]) return;
6610
6122
  exports[key] = textures[key];
6611
6123
  });
6612
-
6613
6124
  var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
6614
-
6615
6125
  var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
6616
-
6617
6126
  exports.utils = utils;
6618
6127
  Object.keys(utils).forEach(function (key) {
6619
6128
  if (key === "default" || key === "__esModule") return;
6620
6129
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6130
+ if (key in exports && exports[key] === utils[key]) return;
6621
6131
  exports[key] = utils[key];
6622
6132
  });
6623
-
6624
6133
  var draw = _interopRequireWildcard(__webpack_require__(/*! ./draw.js */ "./src/draw.js"));
6625
-
6626
6134
  exports.draw = draw;
6627
6135
  Object.keys(draw).forEach(function (key) {
6628
6136
  if (key === "default" || key === "__esModule") return;
6629
6137
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6138
+ if (key in exports && exports[key] === draw[key]) return;
6630
6139
  exports[key] = draw[key];
6631
6140
  });
6632
-
6633
6141
  var framebuffers = _interopRequireWildcard(__webpack_require__(/*! ./framebuffers.js */ "./src/framebuffers.js"));
6634
-
6635
6142
  exports.framebuffers = framebuffers;
6636
6143
  Object.keys(framebuffers).forEach(function (key) {
6637
6144
  if (key === "default" || key === "__esModule") return;
6638
6145
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6146
+ if (key in exports && exports[key] === framebuffers[key]) return;
6639
6147
  exports[key] = framebuffers[key];
6640
6148
  });
6641
-
6642
6149
  var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
6643
-
6644
6150
  exports.programs = programs;
6645
6151
  Object.keys(programs).forEach(function (key) {
6646
6152
  if (key === "default" || key === "__esModule") return;
6647
6153
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6154
+ if (key in exports && exports[key] === programs[key]) return;
6648
6155
  exports[key] = programs[key];
6649
6156
  });
6650
-
6651
6157
  var typedarrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
6652
-
6653
6158
  exports.typedarrays = typedarrays;
6654
6159
  Object.keys(typedarrays).forEach(function (key) {
6655
6160
  if (key === "default" || key === "__esModule") return;
6656
6161
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6162
+ if (key in exports && exports[key] === typedarrays[key]) return;
6657
6163
  exports[key] = typedarrays[key];
6658
6164
  });
6659
-
6660
6165
  var vertexArrays = _interopRequireWildcard(__webpack_require__(/*! ./vertex-arrays.js */ "./src/vertex-arrays.js"));
6661
-
6662
6166
  exports.vertexArrays = vertexArrays;
6663
6167
  Object.keys(vertexArrays).forEach(function (key) {
6664
6168
  if (key === "default" || key === "__esModule") return;
6665
6169
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
6170
+ if (key in exports && exports[key] === vertexArrays[key]) return;
6666
6171
  exports[key] = vertexArrays[key];
6667
6172
  });
6668
-
6669
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
6670
-
6671
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
6672
-
6173
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
6174
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
6673
6175
  /*
6674
6176
  * Copyright 2019 Gregg Tavares
6675
6177
  *
@@ -6719,13 +6221,13 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
6719
6221
  * @borrows module:twgl/textures.resizeTexture as resizeTexture
6720
6222
  * @borrows module:twgl/textures.createTextures as createTextures
6721
6223
  */
6722
- // make sure we don't see a global gl
6723
- var gl = undefined;
6724
- /* eslint-disable-line */
6725
6224
 
6225
+ // make sure we don't see a global gl
6226
+ var gl = undefined; /* eslint-disable-line */
6726
6227
  var defaults = {
6727
6228
  addExtensionsToContext: true
6728
6229
  };
6230
+
6729
6231
  /**
6730
6232
  * Various default settings for twgl.
6731
6233
  *
@@ -6797,36 +6299,30 @@ var defaults = {
6797
6299
  * @param {module:twgl.Defaults} newDefaults The default settings.
6798
6300
  * @memberOf module:twgl
6799
6301
  */
6800
-
6801
6302
  function setDefaults(newDefaults) {
6802
6303
  helper.copyExistingProperties(newDefaults, defaults);
6803
6304
  attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line
6804
-
6805
6305
  textures.setTextureDefaults_(newDefaults); // eslint-disable-line
6806
6306
  }
6807
6307
 
6808
6308
  var prefixRE = /^(.*?)_/;
6809
-
6810
6309
  function addExtensionToContext(gl, extensionName) {
6811
6310
  utils.glEnumToString(gl, 0);
6812
6311
  var ext = gl.getExtension(extensionName);
6813
-
6814
6312
  if (ext) {
6815
6313
  var enums = {};
6816
6314
  var fnSuffix = prefixRE.exec(extensionName)[1];
6817
6315
  var enumSuffix = '_' + fnSuffix;
6818
-
6819
6316
  for (var key in ext) {
6820
6317
  var value = ext[key];
6821
6318
  var isFunc = typeof value === 'function';
6822
6319
  var suffix = isFunc ? fnSuffix : enumSuffix;
6823
- var name = key; // examples of where this is not true are WEBGL_compressed_texture_s3tc
6320
+ var name = key;
6321
+ // examples of where this is not true are WEBGL_compressed_texture_s3tc
6824
6322
  // and WEBGL_compressed_texture_pvrtc
6825
-
6826
6323
  if (key.endsWith(suffix)) {
6827
6324
  name = key.substring(0, key.length - suffix.length);
6828
6325
  }
6829
-
6830
6326
  if (gl[name] !== undefined) {
6831
6327
  if (!isFunc && gl[name] !== value) {
6832
6328
  helper.warn(name, gl[name], value, key);
@@ -6843,17 +6339,16 @@ function addExtensionToContext(gl, extensionName) {
6843
6339
  enums[name] = value;
6844
6340
  }
6845
6341
  }
6846
- } // pass the modified enums to glEnumToString
6847
-
6848
-
6342
+ }
6343
+ // pass the modified enums to glEnumToString
6849
6344
  enums.constructor = {
6850
6345
  name: ext.constructor.name
6851
6346
  };
6852
6347
  utils.glEnumToString(enums, 0);
6853
6348
  }
6854
-
6855
6349
  return ext;
6856
6350
  }
6351
+
6857
6352
  /*
6858
6353
  * If you're wondering why the code doesn't just iterate
6859
6354
  * over all extensions using `gl.getExtensions` is that it's possible
@@ -6862,9 +6357,8 @@ function addExtensionToContext(gl, extensionName) {
6862
6357
  * list.
6863
6358
  *
6864
6359
  */
6865
-
6866
-
6867
6360
  var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_float', 'EXT_color_buffer_half_float', 'EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2', 'EXT_frag_depth', 'EXT_sRGB', 'EXT_shader_texture_lod', 'EXT_texture_filter_anisotropic', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_atc', 'WEBGL_compressed_texture_etc1', 'WEBGL_compressed_texture_pvrtc', 'WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_depth_texture', 'WEBGL_draw_buffers'];
6361
+
6868
6362
  /**
6869
6363
  * Attempts to enable all of the following extensions
6870
6364
  * and add their functions and constants to the
@@ -6913,12 +6407,12 @@ var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_co
6913
6407
  * @param {WebGLRenderingContext} gl A WebGLRenderingContext
6914
6408
  * @memberOf module:twgl
6915
6409
  */
6916
-
6917
6410
  function addExtensionsToContext(gl) {
6918
6411
  for (var ii = 0; ii < supportedExtensions.length; ++ii) {
6919
6412
  addExtensionToContext(gl, supportedExtensions[ii]);
6920
6413
  }
6921
6414
  }
6415
+
6922
6416
  /**
6923
6417
  * Creates a webgl context.
6924
6418
  * @param {HTMLCanvasElement} canvas The canvas tag to get
@@ -6927,26 +6421,21 @@ function addExtensionsToContext(gl) {
6927
6421
  * @return {WebGLRenderingContext} The created context.
6928
6422
  * @private
6929
6423
  */
6930
-
6931
-
6932
6424
  function create3DContext(canvas, opt_attribs) {
6933
6425
  var names = ["webgl", "experimental-webgl"];
6934
6426
  var context = null;
6935
-
6936
6427
  for (var ii = 0; ii < names.length; ++ii) {
6937
6428
  context = canvas.getContext(names[ii], opt_attribs);
6938
-
6939
6429
  if (context) {
6940
6430
  if (defaults.addExtensionsToContext) {
6941
6431
  addExtensionsToContext(context);
6942
6432
  }
6943
-
6944
6433
  break;
6945
6434
  }
6946
6435
  }
6947
-
6948
6436
  return context;
6949
6437
  }
6438
+
6950
6439
  /**
6951
6440
  * Gets a WebGL1 context.
6952
6441
  *
@@ -6961,12 +6450,11 @@ function create3DContext(canvas, opt_attribs) {
6961
6450
  * @deprecated
6962
6451
  * @private
6963
6452
  */
6964
-
6965
-
6966
6453
  function getWebGLContext(canvas, opt_attribs) {
6967
6454
  var gl = create3DContext(canvas, opt_attribs);
6968
6455
  return gl;
6969
6456
  }
6457
+
6970
6458
  /**
6971
6459
  * Creates a webgl context.
6972
6460
  *
@@ -6981,26 +6469,21 @@ function getWebGLContext(canvas, opt_attribs) {
6981
6469
  * created.
6982
6470
  * @return {WebGLRenderingContext} The created context.
6983
6471
  */
6984
-
6985
-
6986
6472
  function createContext(canvas, opt_attribs) {
6987
6473
  var names = ["webgl2", "webgl", "experimental-webgl"];
6988
6474
  var context = null;
6989
-
6990
6475
  for (var ii = 0; ii < names.length; ++ii) {
6991
6476
  context = canvas.getContext(names[ii], opt_attribs);
6992
-
6993
6477
  if (context) {
6994
6478
  if (defaults.addExtensionsToContext) {
6995
6479
  addExtensionsToContext(context);
6996
6480
  }
6997
-
6998
6481
  break;
6999
6482
  }
7000
6483
  }
7001
-
7002
6484
  return context;
7003
6485
  }
6486
+
7004
6487
  /**
7005
6488
  * Gets a WebGL context. Will create a WebGL2 context if possible.
7006
6489
  *
@@ -7019,12 +6502,11 @@ function createContext(canvas, opt_attribs) {
7019
6502
  * @return {WebGLRenderingContext} The created context.
7020
6503
  * @memberOf module:twgl
7021
6504
  */
7022
-
7023
-
7024
6505
  function getContext(canvas, opt_attribs) {
7025
6506
  var gl = createContext(canvas, opt_attribs);
7026
6507
  return gl;
7027
6508
  }
6509
+
7028
6510
  /**
7029
6511
  * Resize a canvas to match the size it's displayed.
7030
6512
  * @param {HTMLCanvasElement} canvas The canvas to resize.
@@ -7032,20 +6514,16 @@ function getContext(canvas, opt_attribs) {
7032
6514
  * @return {boolean} true if the canvas was resized.
7033
6515
  * @memberOf module:twgl
7034
6516
  */
7035
-
7036
-
7037
6517
  function resizeCanvasToDisplaySize(canvas, multiplier) {
7038
6518
  multiplier = multiplier || 1;
7039
6519
  multiplier = Math.max(0, multiplier);
7040
6520
  var width = canvas.clientWidth * multiplier | 0;
7041
6521
  var height = canvas.clientHeight * multiplier | 0;
7042
-
7043
6522
  if (canvas.width !== width || canvas.height !== height) {
7044
6523
  canvas.width = width;
7045
6524
  canvas.height = height;
7046
6525
  return true;
7047
6526
  }
7048
-
7049
6527
  return false;
7050
6528
  }
7051
6529
 
@@ -7066,7 +6544,6 @@ exports.getGLTypeForTypedArray = getGLTypeForTypedArray;
7066
6544
  exports.getGLTypeForTypedArrayType = getGLTypeForTypedArrayType;
7067
6545
  exports.getTypedArrayTypeForGLType = getTypedArrayTypeForGLType;
7068
6546
  exports.isArrayBuffer = void 0;
7069
-
7070
6547
  /*
7071
6548
  * Copyright 2019 Gregg Tavares
7072
6549
  *
@@ -7103,12 +6580,11 @@ exports.isArrayBuffer = void 0;
7103
6580
  *
7104
6581
  * @module twgl/typedArray
7105
6582
  */
6583
+
7106
6584
  // make sure we don't see a global gl
7107
- var gl = undefined;
7108
- /* eslint-disable-line */
6585
+ var gl = undefined; /* eslint-disable-line */
7109
6586
 
7110
6587
  /* DataType */
7111
-
7112
6588
  var BYTE = 0x1400;
7113
6589
  var UNSIGNED_BYTE = 0x1401;
7114
6590
  var SHORT = 0x1402;
@@ -7145,6 +6621,7 @@ var glTypeToTypedArray = {};
7145
6621
  tt[FLOAT_32_UNSIGNED_INT_24_8_REV] = Uint32Array;
7146
6622
  tt[UNSIGNED_INT_24_8] = Uint32Array;
7147
6623
  }
6624
+
7148
6625
  /**
7149
6626
  * Get the GL type for a typedArray
7150
6627
  * @param {ArrayBufferView} typedArray a typedArray
@@ -7152,50 +6629,34 @@ var glTypeToTypedArray = {};
7152
6629
  * be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned
7153
6630
  * @memberOf module:twgl/typedArray
7154
6631
  */
7155
-
7156
6632
  function getGLTypeForTypedArray(typedArray) {
7157
6633
  if (typedArray instanceof Int8Array) {
7158
6634
  return BYTE;
7159
6635
  } // eslint-disable-line
7160
-
7161
-
7162
6636
  if (typedArray instanceof Uint8Array) {
7163
6637
  return UNSIGNED_BYTE;
7164
6638
  } // eslint-disable-line
7165
-
7166
-
7167
6639
  if (typedArray instanceof Uint8ClampedArray) {
7168
6640
  return UNSIGNED_BYTE;
7169
6641
  } // eslint-disable-line
7170
-
7171
-
7172
6642
  if (typedArray instanceof Int16Array) {
7173
6643
  return SHORT;
7174
6644
  } // eslint-disable-line
7175
-
7176
-
7177
6645
  if (typedArray instanceof Uint16Array) {
7178
6646
  return UNSIGNED_SHORT;
7179
6647
  } // eslint-disable-line
7180
-
7181
-
7182
6648
  if (typedArray instanceof Int32Array) {
7183
6649
  return INT;
7184
6650
  } // eslint-disable-line
7185
-
7186
-
7187
6651
  if (typedArray instanceof Uint32Array) {
7188
6652
  return UNSIGNED_INT;
7189
6653
  } // eslint-disable-line
7190
-
7191
-
7192
6654
  if (typedArray instanceof Float32Array) {
7193
6655
  return FLOAT;
7194
6656
  } // eslint-disable-line
7195
-
7196
-
7197
6657
  throw new Error('unsupported typed array type');
7198
6658
  }
6659
+
7199
6660
  /**
7200
6661
  * Get the GL type for a typedArray type
7201
6662
  * @param {ArrayBufferView} typedArrayType a typedArray constructor
@@ -7203,69 +6664,47 @@ function getGLTypeForTypedArray(typedArray) {
7203
6664
  * be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned
7204
6665
  * @memberOf module:twgl/typedArray
7205
6666
  */
7206
-
7207
-
7208
6667
  function getGLTypeForTypedArrayType(typedArrayType) {
7209
6668
  if (typedArrayType === Int8Array) {
7210
6669
  return BYTE;
7211
6670
  } // eslint-disable-line
7212
-
7213
-
7214
6671
  if (typedArrayType === Uint8Array) {
7215
6672
  return UNSIGNED_BYTE;
7216
6673
  } // eslint-disable-line
7217
-
7218
-
7219
6674
  if (typedArrayType === Uint8ClampedArray) {
7220
6675
  return UNSIGNED_BYTE;
7221
6676
  } // eslint-disable-line
7222
-
7223
-
7224
6677
  if (typedArrayType === Int16Array) {
7225
6678
  return SHORT;
7226
6679
  } // eslint-disable-line
7227
-
7228
-
7229
6680
  if (typedArrayType === Uint16Array) {
7230
6681
  return UNSIGNED_SHORT;
7231
6682
  } // eslint-disable-line
7232
-
7233
-
7234
6683
  if (typedArrayType === Int32Array) {
7235
6684
  return INT;
7236
6685
  } // eslint-disable-line
7237
-
7238
-
7239
6686
  if (typedArrayType === Uint32Array) {
7240
6687
  return UNSIGNED_INT;
7241
6688
  } // eslint-disable-line
7242
-
7243
-
7244
6689
  if (typedArrayType === Float32Array) {
7245
6690
  return FLOAT;
7246
6691
  } // eslint-disable-line
7247
-
7248
-
7249
6692
  throw new Error('unsupported typed array type');
7250
6693
  }
6694
+
7251
6695
  /**
7252
6696
  * Get the typed array constructor for a given GL type
7253
6697
  * @param {number} type the GL type. (eg: `gl.UNSIGNED_INT`)
7254
6698
  * @return {function} the constructor for a the corresponding typed array. (eg. `Uint32Array`).
7255
6699
  * @memberOf module:twgl/typedArray
7256
6700
  */
7257
-
7258
-
7259
6701
  function getTypedArrayTypeForGLType(type) {
7260
6702
  var CTOR = glTypeToTypedArray[type];
7261
-
7262
6703
  if (!CTOR) {
7263
6704
  throw new Error('unknown gl type');
7264
6705
  }
7265
-
7266
6706
  return CTOR;
7267
6707
  }
7268
-
7269
6708
  var isArrayBuffer = typeof SharedArrayBuffer !== 'undefined' ? function isArrayBufferOrSharedArrayBuffer(a) {
7270
6709
  return a && a.buffer && (a.buffer instanceof ArrayBuffer || a.buffer instanceof SharedArrayBuffer);
7271
6710
  } : function isArrayBuffer(a) {
@@ -7286,10 +6725,9 @@ exports.isArrayBuffer = isArrayBuffer;
7286
6725
 
7287
6726
 
7288
6727
  exports.__esModule = true;
6728
+ exports.glEnumToString = void 0;
7289
6729
  exports.isWebGL1 = isWebGL1;
7290
6730
  exports.isWebGL2 = isWebGL2;
7291
- exports.glEnumToString = void 0;
7292
-
7293
6731
  /*
7294
6732
  * Copyright 2019 Gregg Tavares
7295
6733
  *
@@ -7335,14 +6773,13 @@ function isWebGL2(gl) {
7335
6773
  // return gl instanceof WebGL2RenderingContext;
7336
6774
  return !!gl.texStorage2D;
7337
6775
  }
6776
+
7338
6777
  /**
7339
6778
  * Check if context is WebGL 1.0
7340
6779
  * @param {WebGLRenderingContext} gl A WebGLRenderingContext
7341
6780
  * @return {bool} true if it's WebGL 1.0
7342
6781
  * @memberOf module:twgl
7343
6782
  */
7344
-
7345
-
7346
6783
  function isWebGL1(gl) {
7347
6784
  // This is the correct check but it's slow
7348
6785
  // const version = getVersionAsNumber(gl);
@@ -7351,6 +6788,7 @@ function isWebGL1(gl) {
7351
6788
  // return gl instanceof WebGLRenderingContext;
7352
6789
  return !gl.texStorage2D;
7353
6790
  }
6791
+
7354
6792
  /**
7355
6793
  * Gets a string for WebGL enum
7356
6794
  *
@@ -7399,15 +6837,11 @@ function isWebGL1(gl) {
7399
6837
  * @memberOf module:twgl
7400
6838
  * @function glEnumToString
7401
6839
  */
7402
-
7403
-
7404
6840
  var glEnumToString = function () {
7405
6841
  var haveEnumsForType = {};
7406
6842
  var enums = {};
7407
-
7408
6843
  function addEnums(gl) {
7409
6844
  var type = gl.constructor.name;
7410
-
7411
6845
  if (!haveEnumsForType[type]) {
7412
6846
  for (var key in gl) {
7413
6847
  if (typeof gl[key] === 'number') {
@@ -7415,17 +6849,14 @@ var glEnumToString = function () {
7415
6849
  enums[gl[key]] = existing ? "".concat(existing, " | ").concat(key) : key;
7416
6850
  }
7417
6851
  }
7418
-
7419
6852
  haveEnumsForType[type] = true;
7420
6853
  }
7421
6854
  }
7422
-
7423
6855
  return function glEnumToString(gl, value) {
7424
6856
  addEnums(gl);
7425
6857
  return enums[value] || (typeof value === 'number' ? "0x".concat(value.toString(16)) : value);
7426
6858
  };
7427
6859
  }();
7428
-
7429
6860
  exports.glEnumToString = glEnumToString;
7430
6861
 
7431
6862
  /***/ }),
@@ -7440,19 +6871,14 @@ exports.glEnumToString = glEnumToString;
7440
6871
  "use strict";
7441
6872
 
7442
6873
 
7443
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
7444
-
6874
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
7445
6875
  exports.__esModule = true;
7446
- exports.createVertexArrayInfo = createVertexArrayInfo;
7447
6876
  exports.createVAOAndSetAttributes = createVAOAndSetAttributes;
7448
6877
  exports.createVAOFromBufferInfo = createVAOFromBufferInfo;
7449
-
6878
+ exports.createVertexArrayInfo = createVertexArrayInfo;
7450
6879
  var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
7451
-
7452
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
7453
-
7454
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
7455
-
6880
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
6881
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
7456
6882
  /*
7457
6883
  * Copyright 2019 Gregg Tavares
7458
6884
  *
@@ -7489,7 +6915,9 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
7489
6915
  *
7490
6916
  * @module twgl/vertexArrays
7491
6917
  */
6918
+
7492
6919
  var ELEMENT_ARRAY_BUFFER = 0x8893;
6920
+
7493
6921
  /**
7494
6922
  * @typedef {Object} VertexArrayInfo
7495
6923
  * @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
@@ -7534,15 +6962,12 @@ var ELEMENT_ARRAY_BUFFER = 0x8893;
7534
6962
  *
7535
6963
  * @memberOf module:twgl/vertexArrays
7536
6964
  */
7537
-
7538
6965
  function createVertexArrayInfo(gl, programInfos, bufferInfo) {
7539
6966
  var vao = gl.createVertexArray();
7540
6967
  gl.bindVertexArray(vao);
7541
-
7542
6968
  if (!programInfos.length) {
7543
6969
  programInfos = [programInfos];
7544
6970
  }
7545
-
7546
6971
  programInfos.forEach(function (programInfo) {
7547
6972
  programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);
7548
6973
  });
@@ -7553,6 +6978,7 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
7553
6978
  vertexArrayObject: vao
7554
6979
  };
7555
6980
  }
6981
+
7556
6982
  /**
7557
6983
  * Creates a vertex array object and then sets the attributes on it
7558
6984
  *
@@ -7565,22 +6991,19 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
7565
6991
  *
7566
6992
  * @memberOf module:twgl/vertexArrays
7567
6993
  */
7568
-
7569
-
7570
6994
  function createVAOAndSetAttributes(gl, setters, attribs, indices) {
7571
6995
  var vao = gl.createVertexArray();
7572
6996
  gl.bindVertexArray(vao);
7573
6997
  programs.setAttributes(setters, attribs);
7574
-
7575
6998
  if (indices) {
7576
6999
  gl.bindBuffer(ELEMENT_ARRAY_BUFFER, indices);
7577
- } // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
7000
+ }
7001
+ // We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
7578
7002
  // like when creating buffers for other stuff will mess up this VAO's binding
7579
-
7580
-
7581
7003
  gl.bindVertexArray(null);
7582
7004
  return vao;
7583
7005
  }
7006
+
7584
7007
  /**
7585
7008
  * Creates a vertex array object and then sets the attributes
7586
7009
  * on it
@@ -7595,8 +7018,6 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
7595
7018
  *
7596
7019
  * @memberOf module:twgl/vertexArrays
7597
7020
  */
7598
-
7599
-
7600
7021
  function createVAOFromBufferInfo(gl, programInfo, bufferInfo) {
7601
7022
  return createVAOAndSetAttributes(gl, programInfo.attribSetters || programInfo, bufferInfo.attribs, bufferInfo.indices);
7602
7023
  }