twgl.js 5.0.3 → 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-full.d.ts +3 -2
- package/dist/5.x/twgl-full.js +632 -1331
- package/dist/5.x/twgl-full.module.js +439 -411
- package/dist/5.x/twgl.d.ts +3 -2
- package/dist/5.x/twgl.js +346 -923
- package/package.json +20 -21
package/dist/5.x/twgl.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @license twgl.js 5.0
|
|
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";
|
|
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.
|
|
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
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
371
|
-
*
|
|
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
|
|
525
|
-
var type;
|
|
526
|
-
var normalization;
|
|
527
|
-
var numComponents;
|
|
528
|
-
|
|
521
|
+
var fn;
|
|
529
522
|
if (array.buffer && array.buffer instanceof WebGLBuffer) {
|
|
530
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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;
|
|
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
|
-
});
|
|
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";
|
|
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
|
|
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);
|
|
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
|
-
}
|
|
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
|
-
}
|
|
1085
|
-
|
|
1027
|
+
}
|
|
1086
1028
|
|
|
1087
|
-
|
|
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";
|
|
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
|
|
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,13 +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.
|
|
1516
|
-
|
|
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); }
|
|
1517
1436
|
/*
|
|
1518
1437
|
* Copyright 2019 Gregg Tavares
|
|
1519
1438
|
*
|
|
@@ -1549,12 +1468,12 @@ exports.isSampler = isSampler;
|
|
|
1549
1468
|
function copyNamedProperties(names, src, dst) {
|
|
1550
1469
|
names.forEach(function (name) {
|
|
1551
1470
|
var value = src[name];
|
|
1552
|
-
|
|
1553
1471
|
if (value !== undefined) {
|
|
1554
1472
|
dst[name] = value;
|
|
1555
1473
|
}
|
|
1556
1474
|
});
|
|
1557
1475
|
}
|
|
1476
|
+
|
|
1558
1477
|
/**
|
|
1559
1478
|
* Copies properties from source to dest only if a matching key is in dest
|
|
1560
1479
|
*
|
|
@@ -1562,8 +1481,6 @@ function copyNamedProperties(names, src, dst) {
|
|
|
1562
1481
|
* @param {Object.<string, ?>} dst the dest
|
|
1563
1482
|
* @private
|
|
1564
1483
|
*/
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
1484
|
function copyExistingProperties(src, dst) {
|
|
1568
1485
|
Object.keys(dst).forEach(function (key) {
|
|
1569
1486
|
if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
|
|
@@ -1572,60 +1489,44 @@ function copyExistingProperties(src, dst) {
|
|
|
1572
1489
|
}
|
|
1573
1490
|
});
|
|
1574
1491
|
}
|
|
1575
|
-
|
|
1576
1492
|
function error() {
|
|
1577
1493
|
var _console;
|
|
1578
|
-
|
|
1579
1494
|
(_console = console).error.apply(_console, arguments);
|
|
1580
1495
|
}
|
|
1581
|
-
|
|
1582
1496
|
function warn() {
|
|
1583
1497
|
var _console2;
|
|
1584
|
-
|
|
1585
1498
|
(_console2 = console).warn.apply(_console2, arguments);
|
|
1586
1499
|
}
|
|
1587
|
-
|
|
1588
1500
|
var isTypeWeakMaps = new Map();
|
|
1589
|
-
|
|
1590
1501
|
function isType(object, type) {
|
|
1591
|
-
if (!object) {
|
|
1502
|
+
if (!object || _typeof(object) !== 'object') {
|
|
1592
1503
|
return false;
|
|
1593
1504
|
}
|
|
1594
|
-
|
|
1595
1505
|
var weakMap = isTypeWeakMaps.get(type);
|
|
1596
|
-
|
|
1597
1506
|
if (!weakMap) {
|
|
1598
1507
|
weakMap = new WeakMap();
|
|
1599
1508
|
isTypeWeakMaps.set(type, weakMap);
|
|
1600
1509
|
}
|
|
1601
|
-
|
|
1602
1510
|
var isOfType = weakMap.get(object);
|
|
1603
|
-
|
|
1604
1511
|
if (isOfType === undefined) {
|
|
1605
1512
|
var s = Object.prototype.toString.call(object);
|
|
1606
1513
|
isOfType = s.substring(8, s.length - 1) === type;
|
|
1607
1514
|
weakMap.set(object, isOfType);
|
|
1608
1515
|
}
|
|
1609
|
-
|
|
1610
1516
|
return isOfType;
|
|
1611
1517
|
}
|
|
1612
|
-
|
|
1613
1518
|
function isBuffer(gl, t) {
|
|
1614
1519
|
return typeof WebGLBuffer !== 'undefined' && isType(t, 'WebGLBuffer');
|
|
1615
1520
|
}
|
|
1616
|
-
|
|
1617
1521
|
function isRenderbuffer(gl, t) {
|
|
1618
1522
|
return typeof WebGLRenderbuffer !== 'undefined' && isType(t, 'WebGLRenderbuffer');
|
|
1619
1523
|
}
|
|
1620
|
-
|
|
1621
1524
|
function isShader(gl, t) {
|
|
1622
1525
|
return typeof WebGLShader !== 'undefined' && isType(t, 'WebGLShader');
|
|
1623
1526
|
}
|
|
1624
|
-
|
|
1625
1527
|
function isTexture(gl, t) {
|
|
1626
1528
|
return typeof WebGLTexture !== 'undefined' && isType(t, 'WebGLTexture');
|
|
1627
1529
|
}
|
|
1628
|
-
|
|
1629
1530
|
function isSampler(gl, t) {
|
|
1630
1531
|
return typeof WebGLSampler !== 'undefined' && isType(t, 'WebGLSampler');
|
|
1631
1532
|
}
|
|
@@ -1642,9 +1543,10 @@ function isSampler(gl, t) {
|
|
|
1642
1543
|
"use strict";
|
|
1643
1544
|
|
|
1644
1545
|
|
|
1645
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
1646
|
-
|
|
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); }
|
|
1647
1547
|
exports.__esModule = true;
|
|
1548
|
+
exports.bindTransformFeedbackInfo = bindTransformFeedbackInfo;
|
|
1549
|
+
exports.bindUniformBlock = bindUniformBlock;
|
|
1648
1550
|
exports.createAttributeSetters = createAttributeSetters;
|
|
1649
1551
|
exports.createProgram = createProgram;
|
|
1650
1552
|
exports.createProgramAsync = createProgramAsync;
|
|
@@ -1653,45 +1555,31 @@ exports.createProgramFromSources = createProgramFromSources;
|
|
|
1653
1555
|
exports.createProgramInfo = createProgramInfo;
|
|
1654
1556
|
exports.createProgramInfoAsync = createProgramInfoAsync;
|
|
1655
1557
|
exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
|
|
1656
|
-
exports.createUniformSetters = createUniformSetters;
|
|
1657
|
-
exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
|
|
1658
|
-
exports.createUniformBlockInfoFromProgram = createUniformBlockInfoFromProgram;
|
|
1659
|
-
exports.createUniformBlockInfo = createUniformBlockInfo;
|
|
1660
1558
|
exports.createTransformFeedback = createTransformFeedback;
|
|
1661
1559
|
exports.createTransformFeedbackInfo = createTransformFeedbackInfo;
|
|
1662
|
-
exports.
|
|
1560
|
+
exports.createUniformBlockInfo = createUniformBlockInfo;
|
|
1561
|
+
exports.createUniformBlockInfoFromProgram = createUniformBlockInfoFromProgram;
|
|
1562
|
+
exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
|
|
1563
|
+
exports.createUniformSetters = createUniformSetters;
|
|
1663
1564
|
exports.setAttributes = setAttributes;
|
|
1565
|
+
exports.setBlockUniforms = setBlockUniforms;
|
|
1664
1566
|
exports.setBuffersAndAttributes = setBuffersAndAttributes;
|
|
1665
|
-
exports.setUniforms = setUniforms;
|
|
1666
1567
|
exports.setUniformBlock = setUniformBlock;
|
|
1667
|
-
exports.
|
|
1668
|
-
exports.bindUniformBlock = bindUniformBlock;
|
|
1568
|
+
exports.setUniforms = setUniforms;
|
|
1669
1569
|
exports.setUniformsAndBindTextures = void 0;
|
|
1670
|
-
|
|
1671
1570
|
var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
|
|
1672
|
-
|
|
1673
1571
|
var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
|
|
1674
|
-
|
|
1675
|
-
function
|
|
1676
|
-
|
|
1677
|
-
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; }
|
|
1678
|
-
|
|
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; }
|
|
1679
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); } }
|
|
1680
|
-
|
|
1681
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); }); }; }
|
|
1682
|
-
|
|
1683
1577
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
1684
|
-
|
|
1685
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."); }
|
|
1686
|
-
|
|
1687
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); }
|
|
1688
|
-
|
|
1689
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
1690
|
-
|
|
1580
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
1691
1581
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
1692
|
-
|
|
1693
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; }
|
|
1694
|
-
|
|
1695
1583
|
/**
|
|
1696
1584
|
* Low level shader program related functions
|
|
1697
1585
|
*
|
|
@@ -1706,13 +1594,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
1706
1594
|
*
|
|
1707
1595
|
* @module twgl/programs
|
|
1708
1596
|
*/
|
|
1597
|
+
|
|
1709
1598
|
var error = helper.error;
|
|
1710
1599
|
var warn = helper.warn;
|
|
1711
|
-
|
|
1712
1600
|
function getElementById(id) {
|
|
1713
1601
|
return typeof document !== 'undefined' && document.getElementById ? document.getElementById(id) : null;
|
|
1714
1602
|
}
|
|
1715
|
-
|
|
1716
1603
|
var TEXTURE0 = 0x84c0;
|
|
1717
1604
|
var DYNAMIC_DRAW = 0x88e8;
|
|
1718
1605
|
var ARRAY_BUFFER = 0x8892;
|
|
@@ -1778,167 +1665,143 @@ var TEXTURE_CUBE_MAP = 0x8513;
|
|
|
1778
1665
|
var TEXTURE_3D = 0x806F;
|
|
1779
1666
|
var TEXTURE_2D_ARRAY = 0x8C1A;
|
|
1780
1667
|
var typeMap = {};
|
|
1668
|
+
|
|
1781
1669
|
/**
|
|
1782
1670
|
* Returns the corresponding bind point for a given sampler type
|
|
1783
1671
|
* @private
|
|
1784
1672
|
*/
|
|
1785
|
-
|
|
1786
1673
|
function getBindPointForSamplerType(gl, type) {
|
|
1787
1674
|
return typeMap[type].bindPoint;
|
|
1788
|
-
}
|
|
1789
|
-
// this code could be a lot smaller but that is sadly really slow (T_T)
|
|
1675
|
+
}
|
|
1790
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)
|
|
1791
1679
|
|
|
1792
1680
|
function floatSetter(gl, location) {
|
|
1793
1681
|
return function (v) {
|
|
1794
1682
|
gl.uniform1f(location, v);
|
|
1795
1683
|
};
|
|
1796
1684
|
}
|
|
1797
|
-
|
|
1798
1685
|
function floatArraySetter(gl, location) {
|
|
1799
1686
|
return function (v) {
|
|
1800
1687
|
gl.uniform1fv(location, v);
|
|
1801
1688
|
};
|
|
1802
1689
|
}
|
|
1803
|
-
|
|
1804
1690
|
function floatVec2Setter(gl, location) {
|
|
1805
1691
|
return function (v) {
|
|
1806
1692
|
gl.uniform2fv(location, v);
|
|
1807
1693
|
};
|
|
1808
1694
|
}
|
|
1809
|
-
|
|
1810
1695
|
function floatVec3Setter(gl, location) {
|
|
1811
1696
|
return function (v) {
|
|
1812
1697
|
gl.uniform3fv(location, v);
|
|
1813
1698
|
};
|
|
1814
1699
|
}
|
|
1815
|
-
|
|
1816
1700
|
function floatVec4Setter(gl, location) {
|
|
1817
1701
|
return function (v) {
|
|
1818
1702
|
gl.uniform4fv(location, v);
|
|
1819
1703
|
};
|
|
1820
1704
|
}
|
|
1821
|
-
|
|
1822
1705
|
function intSetter(gl, location) {
|
|
1823
1706
|
return function (v) {
|
|
1824
1707
|
gl.uniform1i(location, v);
|
|
1825
1708
|
};
|
|
1826
1709
|
}
|
|
1827
|
-
|
|
1828
1710
|
function intArraySetter(gl, location) {
|
|
1829
1711
|
return function (v) {
|
|
1830
1712
|
gl.uniform1iv(location, v);
|
|
1831
1713
|
};
|
|
1832
1714
|
}
|
|
1833
|
-
|
|
1834
1715
|
function intVec2Setter(gl, location) {
|
|
1835
1716
|
return function (v) {
|
|
1836
1717
|
gl.uniform2iv(location, v);
|
|
1837
1718
|
};
|
|
1838
1719
|
}
|
|
1839
|
-
|
|
1840
1720
|
function intVec3Setter(gl, location) {
|
|
1841
1721
|
return function (v) {
|
|
1842
1722
|
gl.uniform3iv(location, v);
|
|
1843
1723
|
};
|
|
1844
1724
|
}
|
|
1845
|
-
|
|
1846
1725
|
function intVec4Setter(gl, location) {
|
|
1847
1726
|
return function (v) {
|
|
1848
1727
|
gl.uniform4iv(location, v);
|
|
1849
1728
|
};
|
|
1850
1729
|
}
|
|
1851
|
-
|
|
1852
1730
|
function uintSetter(gl, location) {
|
|
1853
1731
|
return function (v) {
|
|
1854
1732
|
gl.uniform1ui(location, v);
|
|
1855
1733
|
};
|
|
1856
1734
|
}
|
|
1857
|
-
|
|
1858
1735
|
function uintArraySetter(gl, location) {
|
|
1859
1736
|
return function (v) {
|
|
1860
1737
|
gl.uniform1uiv(location, v);
|
|
1861
1738
|
};
|
|
1862
1739
|
}
|
|
1863
|
-
|
|
1864
1740
|
function uintVec2Setter(gl, location) {
|
|
1865
1741
|
return function (v) {
|
|
1866
1742
|
gl.uniform2uiv(location, v);
|
|
1867
1743
|
};
|
|
1868
1744
|
}
|
|
1869
|
-
|
|
1870
1745
|
function uintVec3Setter(gl, location) {
|
|
1871
1746
|
return function (v) {
|
|
1872
1747
|
gl.uniform3uiv(location, v);
|
|
1873
1748
|
};
|
|
1874
1749
|
}
|
|
1875
|
-
|
|
1876
1750
|
function uintVec4Setter(gl, location) {
|
|
1877
1751
|
return function (v) {
|
|
1878
1752
|
gl.uniform4uiv(location, v);
|
|
1879
1753
|
};
|
|
1880
1754
|
}
|
|
1881
|
-
|
|
1882
1755
|
function floatMat2Setter(gl, location) {
|
|
1883
1756
|
return function (v) {
|
|
1884
1757
|
gl.uniformMatrix2fv(location, false, v);
|
|
1885
1758
|
};
|
|
1886
1759
|
}
|
|
1887
|
-
|
|
1888
1760
|
function floatMat3Setter(gl, location) {
|
|
1889
1761
|
return function (v) {
|
|
1890
1762
|
gl.uniformMatrix3fv(location, false, v);
|
|
1891
1763
|
};
|
|
1892
1764
|
}
|
|
1893
|
-
|
|
1894
1765
|
function floatMat4Setter(gl, location) {
|
|
1895
1766
|
return function (v) {
|
|
1896
1767
|
gl.uniformMatrix4fv(location, false, v);
|
|
1897
1768
|
};
|
|
1898
1769
|
}
|
|
1899
|
-
|
|
1900
1770
|
function floatMat23Setter(gl, location) {
|
|
1901
1771
|
return function (v) {
|
|
1902
1772
|
gl.uniformMatrix2x3fv(location, false, v);
|
|
1903
1773
|
};
|
|
1904
1774
|
}
|
|
1905
|
-
|
|
1906
1775
|
function floatMat32Setter(gl, location) {
|
|
1907
1776
|
return function (v) {
|
|
1908
1777
|
gl.uniformMatrix3x2fv(location, false, v);
|
|
1909
1778
|
};
|
|
1910
1779
|
}
|
|
1911
|
-
|
|
1912
1780
|
function floatMat24Setter(gl, location) {
|
|
1913
1781
|
return function (v) {
|
|
1914
1782
|
gl.uniformMatrix2x4fv(location, false, v);
|
|
1915
1783
|
};
|
|
1916
1784
|
}
|
|
1917
|
-
|
|
1918
1785
|
function floatMat42Setter(gl, location) {
|
|
1919
1786
|
return function (v) {
|
|
1920
1787
|
gl.uniformMatrix4x2fv(location, false, v);
|
|
1921
1788
|
};
|
|
1922
1789
|
}
|
|
1923
|
-
|
|
1924
1790
|
function floatMat34Setter(gl, location) {
|
|
1925
1791
|
return function (v) {
|
|
1926
1792
|
gl.uniformMatrix3x4fv(location, false, v);
|
|
1927
1793
|
};
|
|
1928
1794
|
}
|
|
1929
|
-
|
|
1930
1795
|
function floatMat43Setter(gl, location) {
|
|
1931
1796
|
return function (v) {
|
|
1932
1797
|
gl.uniformMatrix4x3fv(location, false, v);
|
|
1933
1798
|
};
|
|
1934
1799
|
}
|
|
1935
|
-
|
|
1936
1800
|
function samplerSetter(gl, type, unit, location) {
|
|
1937
1801
|
var bindPoint = getBindPointForSamplerType(gl, type);
|
|
1938
1802
|
return utils.isWebGL2(gl) ? function (textureOrPair) {
|
|
1939
1803
|
var texture;
|
|
1940
1804
|
var sampler;
|
|
1941
|
-
|
|
1942
1805
|
if (helper.isTexture(gl, textureOrPair)) {
|
|
1943
1806
|
texture = textureOrPair;
|
|
1944
1807
|
sampler = null;
|
|
@@ -1946,7 +1809,6 @@ function samplerSetter(gl, type, unit, location) {
|
|
|
1946
1809
|
texture = textureOrPair.texture;
|
|
1947
1810
|
sampler = textureOrPair.sampler;
|
|
1948
1811
|
}
|
|
1949
|
-
|
|
1950
1812
|
gl.uniform1i(location, unit);
|
|
1951
1813
|
gl.activeTexture(TEXTURE0 + unit);
|
|
1952
1814
|
gl.bindTexture(bindPoint, texture);
|
|
@@ -1957,22 +1819,18 @@ function samplerSetter(gl, type, unit, location) {
|
|
|
1957
1819
|
gl.bindTexture(bindPoint, texture);
|
|
1958
1820
|
};
|
|
1959
1821
|
}
|
|
1960
|
-
|
|
1961
1822
|
function samplerArraySetter(gl, type, unit, location, size) {
|
|
1962
1823
|
var bindPoint = getBindPointForSamplerType(gl, type);
|
|
1963
1824
|
var units = new Int32Array(size);
|
|
1964
|
-
|
|
1965
1825
|
for (var ii = 0; ii < size; ++ii) {
|
|
1966
1826
|
units[ii] = unit + ii;
|
|
1967
1827
|
}
|
|
1968
|
-
|
|
1969
1828
|
return utils.isWebGL2(gl) ? function (textures) {
|
|
1970
1829
|
gl.uniform1iv(location, units);
|
|
1971
1830
|
textures.forEach(function (textureOrPair, index) {
|
|
1972
1831
|
gl.activeTexture(TEXTURE0 + units[index]);
|
|
1973
1832
|
var texture;
|
|
1974
1833
|
var sampler;
|
|
1975
|
-
|
|
1976
1834
|
if (helper.isTexture(gl, textureOrPair)) {
|
|
1977
1835
|
texture = textureOrPair;
|
|
1978
1836
|
sampler = null;
|
|
@@ -1980,7 +1838,6 @@ function samplerArraySetter(gl, type, unit, location, size) {
|
|
|
1980
1838
|
texture = textureOrPair.texture;
|
|
1981
1839
|
sampler = textureOrPair.sampler;
|
|
1982
1840
|
}
|
|
1983
|
-
|
|
1984
1841
|
gl.bindSampler(unit, sampler);
|
|
1985
1842
|
gl.bindTexture(bindPoint, texture);
|
|
1986
1843
|
});
|
|
@@ -1992,7 +1849,6 @@ function samplerArraySetter(gl, type, unit, location, size) {
|
|
|
1992
1849
|
});
|
|
1993
1850
|
};
|
|
1994
1851
|
}
|
|
1995
|
-
|
|
1996
1852
|
typeMap[FLOAT] = {
|
|
1997
1853
|
Type: Float32Array,
|
|
1998
1854
|
size: 4,
|
|
@@ -2257,29 +2113,23 @@ typeMap[UNSIGNED_INT_SAMPLER_2D_ARRAY] = {
|
|
|
2257
2113
|
arraySetter: samplerArraySetter,
|
|
2258
2114
|
bindPoint: TEXTURE_2D_ARRAY
|
|
2259
2115
|
};
|
|
2260
|
-
|
|
2261
2116
|
function floatAttribSetter(gl, index) {
|
|
2262
2117
|
return function (b) {
|
|
2263
2118
|
if (b.value) {
|
|
2264
2119
|
gl.disableVertexAttribArray(index);
|
|
2265
|
-
|
|
2266
2120
|
switch (b.value.length) {
|
|
2267
2121
|
case 4:
|
|
2268
2122
|
gl.vertexAttrib4fv(index, b.value);
|
|
2269
2123
|
break;
|
|
2270
|
-
|
|
2271
2124
|
case 3:
|
|
2272
2125
|
gl.vertexAttrib3fv(index, b.value);
|
|
2273
2126
|
break;
|
|
2274
|
-
|
|
2275
2127
|
case 2:
|
|
2276
2128
|
gl.vertexAttrib2fv(index, b.value);
|
|
2277
2129
|
break;
|
|
2278
|
-
|
|
2279
2130
|
case 1:
|
|
2280
2131
|
gl.vertexAttrib1fv(index, b.value);
|
|
2281
2132
|
break;
|
|
2282
|
-
|
|
2283
2133
|
default:
|
|
2284
2134
|
throw new Error('the length of a float constant value must be between 1 and 4!');
|
|
2285
2135
|
}
|
|
@@ -2287,19 +2137,16 @@ function floatAttribSetter(gl, index) {
|
|
|
2287
2137
|
gl.bindBuffer(ARRAY_BUFFER, b.buffer);
|
|
2288
2138
|
gl.enableVertexAttribArray(index);
|
|
2289
2139
|
gl.vertexAttribPointer(index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
|
|
2290
|
-
|
|
2291
2140
|
if (gl.vertexAttribDivisor) {
|
|
2292
2141
|
gl.vertexAttribDivisor(index, b.divisor || 0);
|
|
2293
2142
|
}
|
|
2294
2143
|
}
|
|
2295
2144
|
};
|
|
2296
2145
|
}
|
|
2297
|
-
|
|
2298
2146
|
function intAttribSetter(gl, index) {
|
|
2299
2147
|
return function (b) {
|
|
2300
2148
|
if (b.value) {
|
|
2301
2149
|
gl.disableVertexAttribArray(index);
|
|
2302
|
-
|
|
2303
2150
|
if (b.value.length === 4) {
|
|
2304
2151
|
gl.vertexAttrib4iv(index, b.value);
|
|
2305
2152
|
} else {
|
|
@@ -2309,19 +2156,16 @@ function intAttribSetter(gl, index) {
|
|
|
2309
2156
|
gl.bindBuffer(ARRAY_BUFFER, b.buffer);
|
|
2310
2157
|
gl.enableVertexAttribArray(index);
|
|
2311
2158
|
gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
|
|
2312
|
-
|
|
2313
2159
|
if (gl.vertexAttribDivisor) {
|
|
2314
2160
|
gl.vertexAttribDivisor(index, b.divisor || 0);
|
|
2315
2161
|
}
|
|
2316
2162
|
}
|
|
2317
2163
|
};
|
|
2318
2164
|
}
|
|
2319
|
-
|
|
2320
2165
|
function uintAttribSetter(gl, index) {
|
|
2321
2166
|
return function (b) {
|
|
2322
2167
|
if (b.value) {
|
|
2323
2168
|
gl.disableVertexAttribArray(index);
|
|
2324
|
-
|
|
2325
2169
|
if (b.value.length === 4) {
|
|
2326
2170
|
gl.vertexAttrib4uiv(index, b.value);
|
|
2327
2171
|
} else {
|
|
@@ -2331,14 +2175,12 @@ function uintAttribSetter(gl, index) {
|
|
|
2331
2175
|
gl.bindBuffer(ARRAY_BUFFER, b.buffer);
|
|
2332
2176
|
gl.enableVertexAttribArray(index);
|
|
2333
2177
|
gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
|
|
2334
|
-
|
|
2335
2178
|
if (gl.vertexAttribDivisor) {
|
|
2336
2179
|
gl.vertexAttribDivisor(index, b.divisor || 0);
|
|
2337
2180
|
}
|
|
2338
2181
|
}
|
|
2339
2182
|
};
|
|
2340
2183
|
}
|
|
2341
|
-
|
|
2342
2184
|
function matAttribSetter(gl, index, typeInfo) {
|
|
2343
2185
|
var defaultSize = typeInfo.size;
|
|
2344
2186
|
var count = typeInfo.count;
|
|
@@ -2352,18 +2194,15 @@ function matAttribSetter(gl, index, typeInfo) {
|
|
|
2352
2194
|
var normalize = b.normalize || false;
|
|
2353
2195
|
var offset = b.offset || 0;
|
|
2354
2196
|
var rowOffset = stride / count;
|
|
2355
|
-
|
|
2356
2197
|
for (var i = 0; i < count; ++i) {
|
|
2357
2198
|
gl.enableVertexAttribArray(index + i);
|
|
2358
2199
|
gl.vertexAttribPointer(index + i, size, type, normalize, stride, offset + rowOffset * i);
|
|
2359
|
-
|
|
2360
2200
|
if (gl.vertexAttribDivisor) {
|
|
2361
2201
|
gl.vertexAttribDivisor(index + i, b.divisor || 0);
|
|
2362
2202
|
}
|
|
2363
2203
|
}
|
|
2364
2204
|
};
|
|
2365
2205
|
}
|
|
2366
|
-
|
|
2367
2206
|
var attrTypeMap = {};
|
|
2368
2207
|
attrTypeMap[FLOAT] = {
|
|
2369
2208
|
size: 4,
|
|
@@ -2443,20 +2282,17 @@ attrTypeMap[FLOAT_MAT4] = {
|
|
|
2443
2282
|
size: 16,
|
|
2444
2283
|
setter: matAttribSetter,
|
|
2445
2284
|
count: 4
|
|
2446
|
-
};
|
|
2285
|
+
};
|
|
2447
2286
|
|
|
2448
|
-
|
|
2449
|
-
/* eslint-disable-line */
|
|
2287
|
+
// make sure we don't see a global gl
|
|
2288
|
+
var gl = undefined; /* eslint-disable-line */
|
|
2450
2289
|
|
|
2451
2290
|
var errorRE = /ERROR:\s*\d+:(\d+)/gi;
|
|
2452
|
-
|
|
2453
2291
|
function addLineNumbersWithError(src) {
|
|
2454
2292
|
var log = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
2455
2293
|
var lineOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
2456
|
-
|
|
2457
2294
|
// Note: Error message formats are not defined by any spec so this may or may not work.
|
|
2458
2295
|
var matches = _toConsumableArray(log.matchAll(errorRE));
|
|
2459
|
-
|
|
2460
2296
|
var lineNoToErrorMap = new Map(matches.map(function (m, ndx) {
|
|
2461
2297
|
var lineNo = parseInt(m[1]);
|
|
2462
2298
|
var next = matches[ndx + 1];
|
|
@@ -2469,6 +2305,7 @@ function addLineNumbersWithError(src) {
|
|
|
2469
2305
|
return "".concat(lineNo + 1 + lineOffset, ": ").concat(line).concat(err ? "\n\n^^^ ".concat(err) : '');
|
|
2470
2306
|
}).join('\n');
|
|
2471
2307
|
}
|
|
2308
|
+
|
|
2472
2309
|
/**
|
|
2473
2310
|
* Error Callback
|
|
2474
2311
|
* @callback ErrorCallback
|
|
@@ -2484,8 +2321,8 @@ function addLineNumbersWithError(src) {
|
|
|
2484
2321
|
* @param {WebGLProgram|module:twgl.ProgramInfo} [result] the program or programInfo
|
|
2485
2322
|
*/
|
|
2486
2323
|
|
|
2487
|
-
|
|
2488
2324
|
var spaceRE = /^[ \t]*\n/;
|
|
2325
|
+
|
|
2489
2326
|
/**
|
|
2490
2327
|
* Remove the first end of line because WebGL 2.0 requires
|
|
2491
2328
|
* #version 300 es
|
|
@@ -2502,39 +2339,34 @@ var spaceRE = /^[ \t]*\n/;
|
|
|
2502
2339
|
* @returns {{shaderSource: string, lineOffset: number}}
|
|
2503
2340
|
* @private
|
|
2504
2341
|
*/
|
|
2505
|
-
|
|
2506
2342
|
function prepShaderSource(shaderSource) {
|
|
2507
2343
|
var lineOffset = 0;
|
|
2508
|
-
|
|
2509
2344
|
if (spaceRE.test(shaderSource)) {
|
|
2510
2345
|
lineOffset = 1;
|
|
2511
2346
|
shaderSource = shaderSource.replace(spaceRE, '');
|
|
2512
2347
|
}
|
|
2513
|
-
|
|
2514
2348
|
return {
|
|
2515
2349
|
lineOffset: lineOffset,
|
|
2516
2350
|
shaderSource: shaderSource
|
|
2517
2351
|
};
|
|
2518
2352
|
}
|
|
2353
|
+
|
|
2519
2354
|
/**
|
|
2520
2355
|
* @param {module:twgl.ProgramOptions} progOptions
|
|
2521
2356
|
* @param {string} msg
|
|
2522
2357
|
* @return null
|
|
2523
2358
|
* @private
|
|
2524
2359
|
*/
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
2360
|
function reportError(progOptions, msg) {
|
|
2528
2361
|
progOptions.errorCallback(msg);
|
|
2529
|
-
|
|
2530
2362
|
if (progOptions.callback) {
|
|
2531
2363
|
setTimeout(function () {
|
|
2532
2364
|
progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
|
|
2533
2365
|
});
|
|
2534
2366
|
}
|
|
2535
|
-
|
|
2536
2367
|
return null;
|
|
2537
2368
|
}
|
|
2369
|
+
|
|
2538
2370
|
/**
|
|
2539
2371
|
* Loads a shader.
|
|
2540
2372
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
@@ -2544,23 +2376,22 @@ function reportError(progOptions, msg) {
|
|
|
2544
2376
|
* @return {WebGLShader} The created shader.
|
|
2545
2377
|
* @private
|
|
2546
2378
|
*/
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
2379
|
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
2550
2380
|
// Create the shader object
|
|
2551
|
-
var shader = gl.createShader(shaderType);
|
|
2381
|
+
var shader = gl.createShader(shaderType);
|
|
2552
2382
|
|
|
2553
|
-
|
|
2383
|
+
// Load the shader source
|
|
2384
|
+
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource);
|
|
2554
2385
|
|
|
2386
|
+
// Compile the shader
|
|
2555
2387
|
gl.compileShader(shader);
|
|
2556
|
-
|
|
2557
2388
|
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
2558
2389
|
gl.deleteShader(shader);
|
|
2559
2390
|
return null;
|
|
2560
2391
|
}
|
|
2561
|
-
|
|
2562
2392
|
return shader;
|
|
2563
2393
|
}
|
|
2394
|
+
|
|
2564
2395
|
/**
|
|
2565
2396
|
* Check Shader status
|
|
2566
2397
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
@@ -2570,26 +2401,21 @@ function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
|
2570
2401
|
* @return {bool} true if shader is ok.
|
|
2571
2402
|
* @private
|
|
2572
2403
|
*/
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
2404
|
function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
2576
|
-
errFn = errFn || error;
|
|
2577
|
-
|
|
2405
|
+
errFn = errFn || error;
|
|
2406
|
+
// Check the compile status
|
|
2578
2407
|
var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
|
|
2579
|
-
|
|
2580
2408
|
if (!compiled) {
|
|
2581
2409
|
// Something went wrong during compilation; get the error
|
|
2582
2410
|
var lastError = gl.getShaderInfoLog(shader);
|
|
2583
|
-
|
|
2584
2411
|
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2412
|
+
lineOffset = _prepShaderSource.lineOffset,
|
|
2413
|
+
shaderSource = _prepShaderSource.shaderSource;
|
|
2588
2414
|
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
|
|
2589
2415
|
}
|
|
2590
|
-
|
|
2591
2416
|
return compiled;
|
|
2592
2417
|
}
|
|
2418
|
+
|
|
2593
2419
|
/**
|
|
2594
2420
|
* @typedef {Object} ProgramOptions
|
|
2595
2421
|
* @property {function(string)} [errorCallback] callback for errors
|
|
@@ -2611,18 +2437,14 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
2611
2437
|
* @return {module:twgl.ProgramOptions} an instance of ProgramOptions based on the arguments passed in
|
|
2612
2438
|
* @private
|
|
2613
2439
|
*/
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
2440
|
function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
2617
2441
|
var transformFeedbackVaryings;
|
|
2618
2442
|
var transformFeedbackMode;
|
|
2619
2443
|
var callback;
|
|
2620
|
-
|
|
2621
2444
|
if (typeof opt_locations === 'function') {
|
|
2622
2445
|
opt_errorCallback = opt_locations;
|
|
2623
2446
|
opt_locations = undefined;
|
|
2624
2447
|
}
|
|
2625
|
-
|
|
2626
2448
|
if (typeof opt_attribs === 'function') {
|
|
2627
2449
|
opt_errorCallback = opt_attribs;
|
|
2628
2450
|
opt_attribs = undefined;
|
|
@@ -2632,7 +2454,6 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2632
2454
|
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
2633
2455
|
return opt_attribs;
|
|
2634
2456
|
}
|
|
2635
|
-
|
|
2636
2457
|
var opt = opt_attribs;
|
|
2637
2458
|
opt_errorCallback = opt.errorCallback;
|
|
2638
2459
|
opt_attribs = opt.attribLocations;
|
|
@@ -2640,18 +2461,14 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2640
2461
|
transformFeedbackMode = opt.transformFeedbackMode;
|
|
2641
2462
|
callback = opt.callback;
|
|
2642
2463
|
}
|
|
2643
|
-
|
|
2644
2464
|
var _errorCallback = opt_errorCallback || error;
|
|
2645
|
-
|
|
2646
2465
|
var errors = [];
|
|
2647
2466
|
var options = {
|
|
2648
2467
|
errorCallback: function errorCallback(msg) {
|
|
2649
2468
|
errors.push(msg);
|
|
2650
|
-
|
|
2651
2469
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2652
2470
|
args[_key - 1] = arguments[_key];
|
|
2653
2471
|
}
|
|
2654
|
-
|
|
2655
2472
|
_errorCallback.apply(void 0, [msg].concat(args));
|
|
2656
2473
|
},
|
|
2657
2474
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
@@ -2659,10 +2476,8 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2659
2476
|
callback: callback,
|
|
2660
2477
|
errors: errors
|
|
2661
2478
|
};
|
|
2662
|
-
|
|
2663
2479
|
if (opt_attribs) {
|
|
2664
2480
|
var attribLocations = {};
|
|
2665
|
-
|
|
2666
2481
|
if (Array.isArray(opt_attribs)) {
|
|
2667
2482
|
opt_attribs.forEach(function (attrib, ndx) {
|
|
2668
2483
|
attribLocations[attrib] = opt_locations ? opt_locations[ndx] : ndx;
|
|
@@ -2670,37 +2485,31 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2670
2485
|
} else {
|
|
2671
2486
|
attribLocations = opt_attribs;
|
|
2672
2487
|
}
|
|
2673
|
-
|
|
2674
2488
|
options.attribLocations = attribLocations;
|
|
2675
2489
|
}
|
|
2676
|
-
|
|
2677
2490
|
return options;
|
|
2678
2491
|
}
|
|
2679
|
-
|
|
2680
2492
|
var defaultShaderType = ["VERTEX_SHADER", "FRAGMENT_SHADER"];
|
|
2681
|
-
|
|
2682
2493
|
function getShaderTypeFromScriptType(gl, scriptType) {
|
|
2683
2494
|
if (scriptType.indexOf("frag") >= 0) {
|
|
2684
2495
|
return FRAGMENT_SHADER;
|
|
2685
2496
|
} else if (scriptType.indexOf("vert") >= 0) {
|
|
2686
2497
|
return VERTEX_SHADER;
|
|
2687
2498
|
}
|
|
2688
|
-
|
|
2689
2499
|
return undefined;
|
|
2690
2500
|
}
|
|
2691
|
-
|
|
2692
2501
|
function deleteShaders(gl, shaders) {
|
|
2693
2502
|
shaders.forEach(function (shader) {
|
|
2694
2503
|
gl.deleteShader(shader);
|
|
2695
2504
|
});
|
|
2696
2505
|
}
|
|
2697
|
-
|
|
2698
2506
|
var wait = function wait() {
|
|
2699
2507
|
var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
2700
2508
|
return new Promise(function (resolve) {
|
|
2701
2509
|
return setTimeout(resolve, ms);
|
|
2702
2510
|
});
|
|
2703
2511
|
};
|
|
2512
|
+
|
|
2704
2513
|
/**
|
|
2705
2514
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
2706
2515
|
* program.
|
|
@@ -2721,68 +2530,52 @@ var wait = function wait() {
|
|
|
2721
2530
|
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
2722
2531
|
* @memberOf module:twgl/programs
|
|
2723
2532
|
*/
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
2533
|
function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
|
|
2727
2534
|
// This code is really convoluted, because it may or may not be async
|
|
2728
2535
|
// Maybe it would be better to have a separate function
|
|
2729
2536
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
2730
2537
|
var realShaders = [];
|
|
2731
2538
|
var newShaders = [];
|
|
2732
|
-
|
|
2733
2539
|
for (var ndx = 0; ndx < shaders.length; ++ndx) {
|
|
2734
2540
|
var shader = shaders[ndx];
|
|
2735
|
-
|
|
2736
2541
|
if (typeof shader === 'string') {
|
|
2737
2542
|
var elem = getElementById(shader);
|
|
2738
2543
|
var src = elem ? elem.text : shader;
|
|
2739
2544
|
var type = gl[defaultShaderType[ndx]];
|
|
2740
|
-
|
|
2741
2545
|
if (elem && elem.type) {
|
|
2742
2546
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
2743
2547
|
}
|
|
2744
|
-
|
|
2745
2548
|
shader = loadShader(gl, src, type, progOptions);
|
|
2746
2549
|
newShaders.push(shader);
|
|
2747
2550
|
}
|
|
2748
|
-
|
|
2749
2551
|
if (helper.isShader(gl, shader)) {
|
|
2750
2552
|
realShaders.push(shader);
|
|
2751
2553
|
}
|
|
2752
2554
|
}
|
|
2753
|
-
|
|
2754
2555
|
if (realShaders.length !== shaders.length) {
|
|
2755
2556
|
deleteShaders(gl, newShaders);
|
|
2756
2557
|
return reportError(progOptions, "not enough shaders for program");
|
|
2757
2558
|
}
|
|
2758
|
-
|
|
2759
2559
|
var program = gl.createProgram();
|
|
2760
2560
|
realShaders.forEach(function (shader) {
|
|
2761
2561
|
gl.attachShader(program, shader);
|
|
2762
2562
|
});
|
|
2763
|
-
|
|
2764
2563
|
if (progOptions.attribLocations) {
|
|
2765
2564
|
Object.keys(progOptions.attribLocations).forEach(function (attrib) {
|
|
2766
2565
|
gl.bindAttribLocation(program, progOptions.attribLocations[attrib], attrib);
|
|
2767
2566
|
});
|
|
2768
2567
|
}
|
|
2769
|
-
|
|
2770
2568
|
var varyings = progOptions.transformFeedbackVaryings;
|
|
2771
|
-
|
|
2772
2569
|
if (varyings) {
|
|
2773
2570
|
if (varyings.attribs) {
|
|
2774
2571
|
varyings = varyings.attribs;
|
|
2775
2572
|
}
|
|
2776
|
-
|
|
2777
2573
|
if (!Array.isArray(varyings)) {
|
|
2778
2574
|
varyings = Object.keys(varyings);
|
|
2779
2575
|
}
|
|
2780
|
-
|
|
2781
2576
|
gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
|
|
2782
2577
|
}
|
|
2783
|
-
|
|
2784
2578
|
gl.linkProgram(program);
|
|
2785
|
-
|
|
2786
2579
|
if (progOptions.callback) {
|
|
2787
2580
|
checkForProgramLinkCompletionAsync(gl, program, progOptions);
|
|
2788
2581
|
return null;
|
|
@@ -2792,10 +2585,10 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2792
2585
|
deleteShaders(gl, newShaders);
|
|
2793
2586
|
return null;
|
|
2794
2587
|
}
|
|
2795
|
-
|
|
2796
2588
|
return program;
|
|
2797
2589
|
}
|
|
2798
2590
|
}
|
|
2591
|
+
|
|
2799
2592
|
/**
|
|
2800
2593
|
* Same as createProgram but returns a promise
|
|
2801
2594
|
*
|
|
@@ -2815,16 +2608,12 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2815
2608
|
* @return {Promise<WebGLProgram>} The created program
|
|
2816
2609
|
* @memberOf module:twgl/programs
|
|
2817
2610
|
*/
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
2611
|
function createProgramAsync(gl, shaders) {
|
|
2821
2612
|
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
2822
2613
|
args[_key2 - 2] = arguments[_key2];
|
|
2823
2614
|
}
|
|
2824
|
-
|
|
2825
2615
|
return new Promise(function (resolve, reject) {
|
|
2826
2616
|
var programOptions = getProgramOptions.apply(void 0, args);
|
|
2827
|
-
|
|
2828
2617
|
programOptions.callback = function (err, program) {
|
|
2829
2618
|
if (err) {
|
|
2830
2619
|
reject(err);
|
|
@@ -2832,10 +2621,10 @@ function createProgramAsync(gl, shaders) {
|
|
|
2832
2621
|
resolve(program);
|
|
2833
2622
|
}
|
|
2834
2623
|
};
|
|
2835
|
-
|
|
2836
2624
|
createProgram(gl, shaders, programOptions);
|
|
2837
2625
|
});
|
|
2838
2626
|
}
|
|
2627
|
+
|
|
2839
2628
|
/**
|
|
2840
2629
|
* Same as createProgramInfo but returns a promise
|
|
2841
2630
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext
|
|
@@ -2850,16 +2639,12 @@ function createProgramAsync(gl, shaders) {
|
|
|
2850
2639
|
* @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
|
|
2851
2640
|
* @memberOf module:twgl/programs
|
|
2852
2641
|
*/
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
2642
|
function createProgramInfoAsync(gl, shaders) {
|
|
2856
2643
|
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2857
2644
|
args[_key3 - 2] = arguments[_key3];
|
|
2858
2645
|
}
|
|
2859
|
-
|
|
2860
2646
|
return new Promise(function (resolve, reject) {
|
|
2861
2647
|
var programOptions = getProgramOptions.apply(void 0, args);
|
|
2862
|
-
|
|
2863
2648
|
programOptions.callback = function (err, programInfo) {
|
|
2864
2649
|
if (err) {
|
|
2865
2650
|
reject(err);
|
|
@@ -2867,10 +2652,10 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
2867
2652
|
resolve(programInfo);
|
|
2868
2653
|
}
|
|
2869
2654
|
};
|
|
2870
|
-
|
|
2871
2655
|
createProgramInfo(gl, shaders, programOptions);
|
|
2872
2656
|
});
|
|
2873
2657
|
}
|
|
2658
|
+
|
|
2874
2659
|
/**
|
|
2875
2660
|
* Asynchronously wait for program to link.
|
|
2876
2661
|
* Note: if 'KHR_parallel_shader_compile' extension does not
|
|
@@ -2880,25 +2665,20 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
2880
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
|
|
2881
2666
|
* @private
|
|
2882
2667
|
*/
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
2668
|
function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
2886
2669
|
return _checkForProgramLinkCompletionAsync.apply(this, arguments);
|
|
2887
|
-
}
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
*/
|
|
2896
|
-
|
|
2897
|
-
|
|
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
|
+
*/
|
|
2898
2678
|
function _checkForProgramLinkCompletionAsync() {
|
|
2899
|
-
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/
|
|
2679
|
+
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(gl, program, progOptions) {
|
|
2900
2680
|
var ext, checkFn, waitTime, success, err, errFn;
|
|
2901
|
-
return
|
|
2681
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2902
2682
|
while (1) {
|
|
2903
2683
|
switch (_context.prev = _context.next) {
|
|
2904
2684
|
case 0:
|
|
@@ -2909,36 +2689,29 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
2909
2689
|
return true;
|
|
2910
2690
|
};
|
|
2911
2691
|
waitTime = 0;
|
|
2912
|
-
|
|
2913
2692
|
case 3:
|
|
2914
2693
|
_context.next = 5;
|
|
2915
2694
|
return wait(waitTime);
|
|
2916
|
-
|
|
2917
2695
|
case 5:
|
|
2918
2696
|
// must wait at least once
|
|
2919
2697
|
waitTime = 1000 / 60;
|
|
2920
|
-
|
|
2921
2698
|
case 6:
|
|
2922
2699
|
if (!checkFn(gl, program)) {
|
|
2923
2700
|
_context.next = 3;
|
|
2924
2701
|
break;
|
|
2925
2702
|
}
|
|
2926
|
-
|
|
2927
2703
|
case 7:
|
|
2928
2704
|
success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
2929
2705
|
err = success ? undefined : progOptions.errors.join('\n');
|
|
2930
|
-
|
|
2931
2706
|
if (!success) {
|
|
2932
2707
|
errFn = progOptions.errorCallback || error;
|
|
2933
2708
|
errFn(err);
|
|
2934
|
-
gl.deleteProgram(program);
|
|
2709
|
+
gl.deleteProgram(program);
|
|
2710
|
+
// TODO: delete shaders, but only shaders that were created newly for this
|
|
2935
2711
|
// program
|
|
2936
|
-
|
|
2937
2712
|
program = null;
|
|
2938
2713
|
}
|
|
2939
|
-
|
|
2940
2714
|
progOptions.callback(err, program);
|
|
2941
|
-
|
|
2942
2715
|
case 11:
|
|
2943
2716
|
case "end":
|
|
2944
2717
|
return _context.stop();
|
|
@@ -2948,20 +2721,18 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
2948
2721
|
}));
|
|
2949
2722
|
return _checkForProgramLinkCompletionAsync.apply(this, arguments);
|
|
2950
2723
|
}
|
|
2951
|
-
|
|
2952
2724
|
function checkProgramStatus(gl, program, errFn) {
|
|
2953
|
-
errFn = errFn || error;
|
|
2954
|
-
|
|
2725
|
+
errFn = errFn || error;
|
|
2726
|
+
// Check the link status
|
|
2955
2727
|
var linked = gl.getProgramParameter(program, LINK_STATUS);
|
|
2956
|
-
|
|
2957
2728
|
if (!linked) {
|
|
2958
2729
|
// something went wrong with the link
|
|
2959
2730
|
var lastError = gl.getProgramInfoLog(program);
|
|
2960
2731
|
errFn("Error in program linking: ".concat(lastError));
|
|
2961
2732
|
}
|
|
2962
|
-
|
|
2963
2733
|
return linked;
|
|
2964
2734
|
}
|
|
2735
|
+
|
|
2965
2736
|
/**
|
|
2966
2737
|
* Loads a shader from a script tag.
|
|
2967
2738
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
@@ -2972,25 +2743,20 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
2972
2743
|
* @return {WebGLShader?} The created shader or null if error.
|
|
2973
2744
|
* @private
|
|
2974
2745
|
*/
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
2746
|
function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
2978
2747
|
var shaderSource = "";
|
|
2979
2748
|
var shaderScript = getElementById(scriptId);
|
|
2980
|
-
|
|
2981
2749
|
if (!shaderScript) {
|
|
2982
2750
|
return reportError(progOptions, "unknown script element: ".concat(scriptId));
|
|
2983
2751
|
}
|
|
2984
|
-
|
|
2985
2752
|
shaderSource = shaderScript.text;
|
|
2986
2753
|
var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
2987
|
-
|
|
2988
2754
|
if (!shaderType) {
|
|
2989
2755
|
return reportError(progOptions, 'unknown shader type');
|
|
2990
2756
|
}
|
|
2991
|
-
|
|
2992
2757
|
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
2993
2758
|
}
|
|
2759
|
+
|
|
2994
2760
|
/**
|
|
2995
2761
|
* Creates a program from 2 script tags.
|
|
2996
2762
|
*
|
|
@@ -3013,24 +2779,19 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
|
3013
2779
|
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
3014
2780
|
* @memberOf module:twgl/programs
|
|
3015
2781
|
*/
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
2782
|
function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_locations, opt_errorCallback) {
|
|
3019
2783
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
3020
2784
|
var shaders = [];
|
|
3021
|
-
|
|
3022
2785
|
for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
3023
2786
|
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
3024
|
-
|
|
3025
2787
|
if (!shader) {
|
|
3026
2788
|
return null;
|
|
3027
2789
|
}
|
|
3028
|
-
|
|
3029
2790
|
shaders.push(shader);
|
|
3030
2791
|
}
|
|
3031
|
-
|
|
3032
2792
|
return createProgram(gl, shaders, progOptions);
|
|
3033
2793
|
}
|
|
2794
|
+
|
|
3034
2795
|
/**
|
|
3035
2796
|
* Creates a program from 2 sources.
|
|
3036
2797
|
*
|
|
@@ -3053,24 +2814,19 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
3053
2814
|
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
3054
2815
|
* @memberOf module:twgl/programs
|
|
3055
2816
|
*/
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
2817
|
function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
|
|
3059
2818
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
3060
2819
|
var shaders = [];
|
|
3061
|
-
|
|
3062
2820
|
for (var ii = 0; ii < shaderSources.length; ++ii) {
|
|
3063
2821
|
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
3064
|
-
|
|
3065
2822
|
if (!progOptions.callback && !shader) {
|
|
3066
2823
|
return null;
|
|
3067
2824
|
}
|
|
3068
|
-
|
|
3069
2825
|
shaders.push(shader);
|
|
3070
2826
|
}
|
|
3071
|
-
|
|
3072
2827
|
return createProgram(gl, shaders, progOptions);
|
|
3073
2828
|
}
|
|
2829
|
+
|
|
3074
2830
|
/**
|
|
3075
2831
|
* Returns true if attribute/uniform is a reserved/built in
|
|
3076
2832
|
*
|
|
@@ -3088,60 +2844,49 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
|
|
|
3088
2844
|
* @return {bool} true if it's reserved
|
|
3089
2845
|
* @private
|
|
3090
2846
|
*/
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
2847
|
function isBuiltIn(info) {
|
|
3094
2848
|
var name = info.name;
|
|
3095
2849
|
return name.startsWith("gl_") || name.startsWith("webgl_");
|
|
3096
2850
|
}
|
|
3097
|
-
|
|
3098
2851
|
var tokenRE = /(\.|\[|]|\w+)/g;
|
|
3099
|
-
|
|
3100
2852
|
var isDigit = function isDigit(s) {
|
|
3101
2853
|
return s >= '0' && s <= '9';
|
|
3102
2854
|
};
|
|
3103
|
-
|
|
3104
2855
|
function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
|
|
3105
2856
|
var tokens = fullPath.split(tokenRE).filter(function (s) {
|
|
3106
2857
|
return s !== '';
|
|
3107
2858
|
});
|
|
3108
2859
|
var tokenNdx = 0;
|
|
3109
2860
|
var path = '';
|
|
3110
|
-
|
|
3111
2861
|
for (;;) {
|
|
3112
2862
|
var token = tokens[tokenNdx++]; // has to be name or number
|
|
3113
|
-
|
|
3114
2863
|
path += token;
|
|
3115
2864
|
var isArrayIndex = isDigit(token[0]);
|
|
3116
2865
|
var accessor = isArrayIndex ? parseInt(token) : token;
|
|
3117
|
-
|
|
3118
2866
|
if (isArrayIndex) {
|
|
3119
2867
|
path += tokens[tokenNdx++]; // skip ']'
|
|
3120
2868
|
}
|
|
3121
2869
|
|
|
3122
2870
|
var isLastToken = tokenNdx === tokens.length;
|
|
3123
|
-
|
|
3124
2871
|
if (isLastToken) {
|
|
3125
2872
|
node[accessor] = setter;
|
|
3126
2873
|
break;
|
|
3127
2874
|
} else {
|
|
3128
2875
|
var _token = tokens[tokenNdx++]; // has to be . or [
|
|
3129
|
-
|
|
3130
2876
|
var isArray = _token === '[';
|
|
3131
2877
|
var child = node[accessor] || (isArray ? [] : {});
|
|
3132
2878
|
node[accessor] = child;
|
|
3133
2879
|
node = child;
|
|
3134
|
-
|
|
3135
2880
|
uniformSetters[path] = uniformSetters[path] || function (node) {
|
|
3136
2881
|
return function (value) {
|
|
3137
2882
|
setUniformTree(node, value);
|
|
3138
2883
|
};
|
|
3139
2884
|
}(child);
|
|
3140
|
-
|
|
3141
2885
|
path += _token;
|
|
3142
2886
|
}
|
|
3143
2887
|
}
|
|
3144
2888
|
}
|
|
2889
|
+
|
|
3145
2890
|
/**
|
|
3146
2891
|
* Creates setter functions for all uniforms of a shader
|
|
3147
2892
|
* program.
|
|
@@ -3153,10 +2898,9 @@ function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
|
|
|
3153
2898
|
* @returns {Object.<string, function>} an object with a setter by name for each uniform
|
|
3154
2899
|
* @memberOf module:twgl/programs
|
|
3155
2900
|
*/
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
2901
|
function createUniformSetters(gl, program) {
|
|
3159
2902
|
var textureUnit = 0;
|
|
2903
|
+
|
|
3160
2904
|
/**
|
|
3161
2905
|
* Creates a setter for a uniform of the given program with it's
|
|
3162
2906
|
* location embedded in the setter.
|
|
@@ -3164,23 +2908,19 @@ function createUniformSetters(gl, program) {
|
|
|
3164
2908
|
* @param {WebGLUniformInfo} uniformInfo
|
|
3165
2909
|
* @returns {function} the created setter.
|
|
3166
2910
|
*/
|
|
3167
|
-
|
|
3168
2911
|
function createUniformSetter(program, uniformInfo, location) {
|
|
3169
2912
|
var isArray = uniformInfo.name.endsWith("[0]");
|
|
3170
2913
|
var type = uniformInfo.type;
|
|
3171
2914
|
var typeInfo = typeMap[type];
|
|
3172
|
-
|
|
3173
2915
|
if (!typeInfo) {
|
|
3174
2916
|
throw new Error("unknown type: 0x".concat(type.toString(16))); // we should never get here.
|
|
3175
2917
|
}
|
|
3176
2918
|
|
|
3177
2919
|
var setter;
|
|
3178
|
-
|
|
3179
2920
|
if (typeInfo.bindPoint) {
|
|
3180
2921
|
// it's a sampler
|
|
3181
2922
|
var unit = textureUnit;
|
|
3182
2923
|
textureUnit += uniformInfo.size;
|
|
3183
|
-
|
|
3184
2924
|
if (isArray) {
|
|
3185
2925
|
setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
|
|
3186
2926
|
} else {
|
|
@@ -3193,39 +2933,33 @@ function createUniformSetters(gl, program) {
|
|
|
3193
2933
|
setter = typeInfo.setter(gl, location);
|
|
3194
2934
|
}
|
|
3195
2935
|
}
|
|
3196
|
-
|
|
3197
2936
|
setter.location = location;
|
|
3198
2937
|
return setter;
|
|
3199
2938
|
}
|
|
3200
|
-
|
|
3201
2939
|
var uniformSetters = {};
|
|
3202
2940
|
var uniformTree = {};
|
|
3203
2941
|
var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
|
|
3204
|
-
|
|
3205
2942
|
for (var ii = 0; ii < numUniforms; ++ii) {
|
|
3206
2943
|
var uniformInfo = gl.getActiveUniform(program, ii);
|
|
3207
|
-
|
|
3208
2944
|
if (isBuiltIn(uniformInfo)) {
|
|
3209
2945
|
continue;
|
|
3210
2946
|
}
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
2947
|
+
var name = uniformInfo.name;
|
|
2948
|
+
// remove the array suffix.
|
|
3214
2949
|
if (name.endsWith("[0]")) {
|
|
3215
2950
|
name = name.substr(0, name.length - 3);
|
|
3216
2951
|
}
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
2952
|
+
var location = gl.getUniformLocation(program, uniformInfo.name);
|
|
2953
|
+
// the uniform will have no location if it's in a uniform block
|
|
3220
2954
|
if (location) {
|
|
3221
2955
|
var setter = createUniformSetter(program, uniformInfo, location);
|
|
3222
2956
|
uniformSetters[name] = setter;
|
|
3223
2957
|
addSetterToUniformTree(name, setter, uniformTree, uniformSetters);
|
|
3224
2958
|
}
|
|
3225
2959
|
}
|
|
3226
|
-
|
|
3227
2960
|
return uniformSetters;
|
|
3228
2961
|
}
|
|
2962
|
+
|
|
3229
2963
|
/**
|
|
3230
2964
|
* @typedef {Object} TransformFeedbackInfo
|
|
3231
2965
|
* @property {number} index index of transform feedback
|
|
@@ -3241,12 +2975,9 @@ function createUniformSetters(gl, program) {
|
|
|
3241
2975
|
* @return {Object<string, module:twgl.TransformFeedbackInfo>}
|
|
3242
2976
|
* @memberOf module:twgl
|
|
3243
2977
|
*/
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
2978
|
function createTransformFeedbackInfo(gl, program) {
|
|
3247
2979
|
var info = {};
|
|
3248
2980
|
var numVaryings = gl.getProgramParameter(program, TRANSFORM_FEEDBACK_VARYINGS);
|
|
3249
|
-
|
|
3250
2981
|
for (var ii = 0; ii < numVaryings; ++ii) {
|
|
3251
2982
|
var varying = gl.getTransformFeedbackVarying(program, ii);
|
|
3252
2983
|
info[varying.name] = {
|
|
@@ -3255,9 +2986,9 @@ function createTransformFeedbackInfo(gl, program) {
|
|
|
3255
2986
|
size: varying.size
|
|
3256
2987
|
};
|
|
3257
2988
|
}
|
|
3258
|
-
|
|
3259
2989
|
return info;
|
|
3260
2990
|
}
|
|
2991
|
+
|
|
3261
2992
|
/**
|
|
3262
2993
|
* Binds buffers for transform feedback.
|
|
3263
2994
|
*
|
|
@@ -3266,23 +2997,17 @@ function createTransformFeedbackInfo(gl, program) {
|
|
|
3266
2997
|
* @param {(module:twgl.BufferInfo|Object<string, module:twgl.AttribInfo>)} [bufferInfo] A BufferInfo or set of AttribInfos.
|
|
3267
2998
|
* @memberOf module:twgl
|
|
3268
2999
|
*/
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
3000
|
function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
|
|
3272
3001
|
if (transformFeedbackInfo.transformFeedbackInfo) {
|
|
3273
3002
|
transformFeedbackInfo = transformFeedbackInfo.transformFeedbackInfo;
|
|
3274
3003
|
}
|
|
3275
|
-
|
|
3276
3004
|
if (bufferInfo.attribs) {
|
|
3277
3005
|
bufferInfo = bufferInfo.attribs;
|
|
3278
3006
|
}
|
|
3279
|
-
|
|
3280
3007
|
for (var name in bufferInfo) {
|
|
3281
3008
|
var varying = transformFeedbackInfo[name];
|
|
3282
|
-
|
|
3283
3009
|
if (varying) {
|
|
3284
3010
|
var buf = bufferInfo[name];
|
|
3285
|
-
|
|
3286
3011
|
if (buf.offset) {
|
|
3287
3012
|
gl.bindBufferRange(TRANSFORM_FEEDBACK_BUFFER, varying.index, buf.buffer, buf.offset, buf.size);
|
|
3288
3013
|
} else {
|
|
@@ -3291,6 +3016,7 @@ function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
|
|
|
3291
3016
|
}
|
|
3292
3017
|
}
|
|
3293
3018
|
}
|
|
3019
|
+
|
|
3294
3020
|
/**
|
|
3295
3021
|
* Creates a transform feedback and sets the buffers
|
|
3296
3022
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
@@ -3299,8 +3025,6 @@ function bindTransformFeedbackInfo(gl, transformFeedbackInfo, bufferInfo) {
|
|
|
3299
3025
|
* @return {WebGLTransformFeedback} the created transform feedback
|
|
3300
3026
|
* @memberOf module:twgl
|
|
3301
3027
|
*/
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
3028
|
function createTransformFeedback(gl, programInfo, bufferInfo) {
|
|
3305
3029
|
var tf = gl.createTransformFeedback();
|
|
3306
3030
|
gl.bindTransformFeedback(TRANSFORM_FEEDBACK, tf);
|
|
@@ -3309,6 +3033,7 @@ function createTransformFeedback(gl, programInfo, bufferInfo) {
|
|
|
3309
3033
|
gl.bindTransformFeedback(TRANSFORM_FEEDBACK, null);
|
|
3310
3034
|
return tf;
|
|
3311
3035
|
}
|
|
3036
|
+
|
|
3312
3037
|
/**
|
|
3313
3038
|
* @typedef {Object} UniformData
|
|
3314
3039
|
* @property {string} name The name of the uniform
|
|
@@ -3354,21 +3079,18 @@ function createTransformFeedback(gl, programInfo, bufferInfo) {
|
|
|
3354
3079
|
* @return {module:twgl.UniformBlockSpec} The created UniformBlockSpec
|
|
3355
3080
|
* @memberOf module:twgl/programs
|
|
3356
3081
|
*/
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
3082
|
function createUniformBlockSpecFromProgram(gl, program) {
|
|
3360
3083
|
var numUniforms = gl.getProgramParameter(program, ACTIVE_UNIFORMS);
|
|
3361
3084
|
var uniformData = [];
|
|
3362
3085
|
var uniformIndices = [];
|
|
3363
|
-
|
|
3364
3086
|
for (var ii = 0; ii < numUniforms; ++ii) {
|
|
3365
3087
|
uniformIndices.push(ii);
|
|
3366
3088
|
uniformData.push({});
|
|
3367
3089
|
var uniformInfo = gl.getActiveUniform(program, ii);
|
|
3368
3090
|
uniformData[ii].name = uniformInfo.name;
|
|
3369
3091
|
}
|
|
3370
|
-
|
|
3371
|
-
|
|
3092
|
+
[["UNIFORM_TYPE", "type"], ["UNIFORM_SIZE", "size"],
|
|
3093
|
+
// num elements
|
|
3372
3094
|
["UNIFORM_BLOCK_INDEX", "blockNdx"], ["UNIFORM_OFFSET", "offset"]].forEach(function (pair) {
|
|
3373
3095
|
var pname = pair[0];
|
|
3374
3096
|
var key = pair[1];
|
|
@@ -3378,7 +3100,6 @@ function createUniformBlockSpecFromProgram(gl, program) {
|
|
|
3378
3100
|
});
|
|
3379
3101
|
var blockSpecs = {};
|
|
3380
3102
|
var numUniformBlocks = gl.getProgramParameter(program, ACTIVE_UNIFORM_BLOCKS);
|
|
3381
|
-
|
|
3382
3103
|
for (var _ii = 0; _ii < numUniformBlocks; ++_ii) {
|
|
3383
3104
|
var name = gl.getActiveUniformBlockName(program, _ii);
|
|
3384
3105
|
var blockSpec = {
|
|
@@ -3391,19 +3112,16 @@ function createUniformBlockSpecFromProgram(gl, program) {
|
|
|
3391
3112
|
blockSpec.used = blockSpec.usedByVertexShader || blockSpec.usedByFragmentShader;
|
|
3392
3113
|
blockSpecs[name] = blockSpec;
|
|
3393
3114
|
}
|
|
3394
|
-
|
|
3395
3115
|
return {
|
|
3396
3116
|
blockSpecs: blockSpecs,
|
|
3397
3117
|
uniformData: uniformData
|
|
3398
3118
|
};
|
|
3399
3119
|
}
|
|
3400
|
-
|
|
3401
3120
|
var arraySuffixRE = /\[\d+\]\.$/; // better way to check?
|
|
3402
3121
|
|
|
3403
3122
|
var pad = function pad(v, padding) {
|
|
3404
3123
|
return ((v + (padding - 1)) / padding | 0) * padding;
|
|
3405
3124
|
};
|
|
3406
|
-
|
|
3407
3125
|
function createUniformBlockUniformSetter(view, isArray, rows, cols) {
|
|
3408
3126
|
if (isArray || rows) {
|
|
3409
3127
|
cols = cols || 1;
|
|
@@ -3412,12 +3130,10 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
|
|
|
3412
3130
|
return function (value) {
|
|
3413
3131
|
var dst = 0;
|
|
3414
3132
|
var src = 0;
|
|
3415
|
-
|
|
3416
3133
|
for (var row = 0; row < totalRows; ++row) {
|
|
3417
3134
|
for (var col = 0; col < cols; ++col) {
|
|
3418
3135
|
view[dst++] = value[src++];
|
|
3419
3136
|
}
|
|
3420
|
-
|
|
3421
3137
|
dst += 4 - cols;
|
|
3422
3138
|
}
|
|
3423
3139
|
};
|
|
@@ -3431,6 +3147,7 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
|
|
|
3431
3147
|
};
|
|
3432
3148
|
}
|
|
3433
3149
|
}
|
|
3150
|
+
|
|
3434
3151
|
/**
|
|
3435
3152
|
* Represents a UniformBlockObject including an ArrayBuffer with all the uniform values
|
|
3436
3153
|
* and a corresponding WebGLBuffer to hold those values on the GPU
|
|
@@ -3475,13 +3192,10 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
|
|
|
3475
3192
|
* @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
|
|
3476
3193
|
* @memberOf module:twgl/programs
|
|
3477
3194
|
*/
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
3195
|
function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
|
|
3481
3196
|
var blockSpecs = uniformBlockSpec.blockSpecs;
|
|
3482
3197
|
var uniformData = uniformBlockSpec.uniformData;
|
|
3483
3198
|
var blockSpec = blockSpecs[blockName];
|
|
3484
|
-
|
|
3485
3199
|
if (!blockSpec) {
|
|
3486
3200
|
warn("no uniform block object named:", blockName);
|
|
3487
3201
|
return {
|
|
@@ -3489,40 +3203,34 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
|
|
|
3489
3203
|
uniforms: {}
|
|
3490
3204
|
};
|
|
3491
3205
|
}
|
|
3492
|
-
|
|
3493
3206
|
var array = new ArrayBuffer(blockSpec.size);
|
|
3494
3207
|
var buffer = gl.createBuffer();
|
|
3495
3208
|
var uniformBufferIndex = blockSpec.index;
|
|
3496
3209
|
gl.bindBuffer(UNIFORM_BUFFER, buffer);
|
|
3497
3210
|
gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
|
|
3498
3211
|
var prefix = blockName + ".";
|
|
3499
|
-
|
|
3500
3212
|
if (arraySuffixRE.test(prefix)) {
|
|
3501
3213
|
prefix = prefix.replace(arraySuffixRE, ".");
|
|
3502
3214
|
}
|
|
3503
|
-
|
|
3504
3215
|
var uniforms = {};
|
|
3505
3216
|
var setters = {};
|
|
3506
3217
|
var setterTree = {};
|
|
3507
3218
|
blockSpec.uniformIndices.forEach(function (uniformNdx) {
|
|
3508
3219
|
var data = uniformData[uniformNdx];
|
|
3509
3220
|
var name = data.name;
|
|
3510
|
-
|
|
3511
3221
|
if (name.startsWith(prefix)) {
|
|
3512
3222
|
name = name.substr(prefix.length);
|
|
3513
3223
|
}
|
|
3514
|
-
|
|
3515
3224
|
var isArray = name.endsWith('[0]');
|
|
3516
|
-
|
|
3517
3225
|
if (isArray) {
|
|
3518
3226
|
name = name.substr(0, name.length - 3);
|
|
3519
3227
|
}
|
|
3520
|
-
|
|
3521
3228
|
var typeInfo = typeMap[data.type];
|
|
3522
3229
|
var Type = typeInfo.Type;
|
|
3523
3230
|
var byteLength = isArray ? pad(typeInfo.size, 16) * data.size : typeInfo.size * data.size;
|
|
3524
3231
|
var uniformView = new Type(array, data.offset, byteLength / Type.BYTES_PER_ELEMENT);
|
|
3525
|
-
uniforms[name] = uniformView;
|
|
3232
|
+
uniforms[name] = uniformView;
|
|
3233
|
+
// Note: I'm not sure what to do here. The original
|
|
3526
3234
|
// idea was to create TypedArray views into each part
|
|
3527
3235
|
// of the block. This is useful, for example if you have
|
|
3528
3236
|
// a block with { mat4: model; mat4 view; mat4 projection; }
|
|
@@ -3547,7 +3255,6 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
|
|
|
3547
3255
|
// then you should probably roll your own solution. TWGL's goal
|
|
3548
3256
|
// here is ease of use as AFAICT there is no simple generic efficient
|
|
3549
3257
|
// solution.
|
|
3550
|
-
|
|
3551
3258
|
var setter = createUniformBlockUniformSetter(uniformView, isArray, typeInfo.rows, typeInfo.cols);
|
|
3552
3259
|
setters[name] = setter;
|
|
3553
3260
|
addSetterToUniformTree(name, setter, setterTree, setters);
|
|
@@ -3562,6 +3269,7 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
|
|
|
3562
3269
|
setters: setters
|
|
3563
3270
|
};
|
|
3564
3271
|
}
|
|
3272
|
+
|
|
3565
3273
|
/**
|
|
3566
3274
|
* Creates a `UniformBlockInfo` for the specified block
|
|
3567
3275
|
*
|
|
@@ -3578,11 +3286,10 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
|
|
|
3578
3286
|
* @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
|
|
3579
3287
|
* @memberOf module:twgl/programs
|
|
3580
3288
|
*/
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
3289
|
function createUniformBlockInfo(gl, programInfo, blockName) {
|
|
3584
3290
|
return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
|
|
3585
3291
|
}
|
|
3292
|
+
|
|
3586
3293
|
/**
|
|
3587
3294
|
* Binds a uniform block to the matching uniform block point.
|
|
3588
3295
|
* Matches by blocks by name so blocks must have the same name not just the same
|
|
@@ -3601,20 +3308,17 @@ function createUniformBlockInfo(gl, programInfo, blockName) {
|
|
|
3601
3308
|
* no buffer is bound.
|
|
3602
3309
|
* @memberOf module:twgl/programs
|
|
3603
3310
|
*/
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
3311
|
function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
|
|
3607
3312
|
var uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
|
|
3608
3313
|
var blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
|
|
3609
|
-
|
|
3610
3314
|
if (blockSpec) {
|
|
3611
3315
|
var bufferBindIndex = blockSpec.index;
|
|
3612
3316
|
gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
|
|
3613
3317
|
return true;
|
|
3614
3318
|
}
|
|
3615
|
-
|
|
3616
3319
|
return false;
|
|
3617
3320
|
}
|
|
3321
|
+
|
|
3618
3322
|
/**
|
|
3619
3323
|
* Uploads the current uniform values to the corresponding WebGLBuffer
|
|
3620
3324
|
* and binds that buffer to the program's corresponding bind point for the uniform block object.
|
|
@@ -3630,13 +3334,12 @@ function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
|
|
|
3630
3334
|
* {@link module:twgl.createUniformBlockInfo}.
|
|
3631
3335
|
* @memberOf module:twgl/programs
|
|
3632
3336
|
*/
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
3337
|
function setUniformBlock(gl, programInfo, uniformBlockInfo) {
|
|
3636
3338
|
if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
|
|
3637
3339
|
gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);
|
|
3638
3340
|
}
|
|
3639
3341
|
}
|
|
3342
|
+
|
|
3640
3343
|
/**
|
|
3641
3344
|
* Sets values of a uniform block object
|
|
3642
3345
|
*
|
|
@@ -3722,25 +3425,19 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
|
|
|
3722
3425
|
* Any name that doesn't match will be ignored
|
|
3723
3426
|
* @memberOf module:twgl/programs
|
|
3724
3427
|
*/
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
3428
|
function setBlockUniforms(uniformBlockInfo, values) {
|
|
3728
3429
|
var setters = uniformBlockInfo.setters;
|
|
3729
|
-
|
|
3730
3430
|
for (var name in values) {
|
|
3731
3431
|
var setter = setters[name];
|
|
3732
|
-
|
|
3733
3432
|
if (setter) {
|
|
3734
3433
|
var value = values[name];
|
|
3735
3434
|
setter(value);
|
|
3736
3435
|
}
|
|
3737
3436
|
}
|
|
3738
3437
|
}
|
|
3739
|
-
|
|
3740
3438
|
function setUniformTree(tree, values) {
|
|
3741
3439
|
for (var name in values) {
|
|
3742
3440
|
var prop = tree[name];
|
|
3743
|
-
|
|
3744
3441
|
if (typeof prop === 'function') {
|
|
3745
3442
|
prop(values[name]);
|
|
3746
3443
|
} else {
|
|
@@ -3748,6 +3445,7 @@ function setUniformTree(tree, values) {
|
|
|
3748
3445
|
}
|
|
3749
3446
|
}
|
|
3750
3447
|
}
|
|
3448
|
+
|
|
3751
3449
|
/**
|
|
3752
3450
|
* Set uniforms and binds related textures.
|
|
3753
3451
|
*
|
|
@@ -3906,26 +3604,20 @@ function setUniformTree(tree, values) {
|
|
|
3906
3604
|
*
|
|
3907
3605
|
* @memberOf module:twgl/programs
|
|
3908
3606
|
*/
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
3607
|
function setUniforms(setters) {
|
|
3912
3608
|
// eslint-disable-line
|
|
3913
3609
|
var actualSetters = setters.uniformSetters || setters;
|
|
3914
3610
|
var numArgs = arguments.length <= 1 ? 0 : arguments.length - 1;
|
|
3915
|
-
|
|
3916
3611
|
for (var aNdx = 0; aNdx < numArgs; ++aNdx) {
|
|
3917
3612
|
var values = aNdx + 1 < 1 || arguments.length <= aNdx + 1 ? undefined : arguments[aNdx + 1];
|
|
3918
|
-
|
|
3919
3613
|
if (Array.isArray(values)) {
|
|
3920
3614
|
var numValues = values.length;
|
|
3921
|
-
|
|
3922
3615
|
for (var ii = 0; ii < numValues; ++ii) {
|
|
3923
3616
|
setUniforms(actualSetters, values[ii]);
|
|
3924
3617
|
}
|
|
3925
3618
|
} else {
|
|
3926
3619
|
for (var name in values) {
|
|
3927
3620
|
var setter = actualSetters[name];
|
|
3928
|
-
|
|
3929
3621
|
if (setter) {
|
|
3930
3622
|
setter(values[name]);
|
|
3931
3623
|
}
|
|
@@ -3933,6 +3625,7 @@ function setUniforms(setters) {
|
|
|
3933
3625
|
}
|
|
3934
3626
|
}
|
|
3935
3627
|
}
|
|
3628
|
+
|
|
3936
3629
|
/**
|
|
3937
3630
|
* Alias for `setUniforms`
|
|
3938
3631
|
* @function
|
|
@@ -3941,9 +3634,8 @@ function setUniforms(setters) {
|
|
|
3941
3634
|
* @param {Object.<string, ?>} values an object with values for the
|
|
3942
3635
|
* @memberOf module:twgl/programs
|
|
3943
3636
|
*/
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
3637
|
var setUniformsAndBindTextures = setUniforms;
|
|
3638
|
+
|
|
3947
3639
|
/**
|
|
3948
3640
|
* Creates setter functions for all attributes of a shader
|
|
3949
3641
|
* program. You can pass this to {@link module:twgl.setBuffersAndAttributes} to set all your buffers and attributes.
|
|
@@ -3954,29 +3646,24 @@ var setUniformsAndBindTextures = setUniforms;
|
|
|
3954
3646
|
* @return {Object.<string, function>} an object with a setter for each attribute by name.
|
|
3955
3647
|
* @memberOf module:twgl/programs
|
|
3956
3648
|
*/
|
|
3957
|
-
|
|
3958
3649
|
exports.setUniformsAndBindTextures = setUniformsAndBindTextures;
|
|
3959
|
-
|
|
3960
3650
|
function createAttributeSetters(gl, program) {
|
|
3961
3651
|
var attribSetters = {};
|
|
3962
3652
|
var numAttribs = gl.getProgramParameter(program, ACTIVE_ATTRIBUTES);
|
|
3963
|
-
|
|
3964
3653
|
for (var ii = 0; ii < numAttribs; ++ii) {
|
|
3965
3654
|
var attribInfo = gl.getActiveAttrib(program, ii);
|
|
3966
|
-
|
|
3967
3655
|
if (isBuiltIn(attribInfo)) {
|
|
3968
3656
|
continue;
|
|
3969
3657
|
}
|
|
3970
|
-
|
|
3971
3658
|
var index = gl.getAttribLocation(program, attribInfo.name);
|
|
3972
3659
|
var typeInfo = attrTypeMap[attribInfo.type];
|
|
3973
3660
|
var setter = typeInfo.setter(gl, index, typeInfo);
|
|
3974
3661
|
setter.location = index;
|
|
3975
3662
|
attribSetters[attribInfo.name] = setter;
|
|
3976
3663
|
}
|
|
3977
|
-
|
|
3978
3664
|
return attribSetters;
|
|
3979
3665
|
}
|
|
3666
|
+
|
|
3980
3667
|
/**
|
|
3981
3668
|
* Sets attributes and binds buffers (deprecated... use {@link module:twgl.setBuffersAndAttributes})
|
|
3982
3669
|
*
|
|
@@ -4032,17 +3719,15 @@ function createAttributeSetters(gl, program) {
|
|
|
4032
3719
|
* @deprecated use {@link module:twgl.setBuffersAndAttributes}
|
|
4033
3720
|
* @private
|
|
4034
3721
|
*/
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
3722
|
function setAttributes(setters, buffers) {
|
|
4038
3723
|
for (var name in buffers) {
|
|
4039
3724
|
var setter = setters[name];
|
|
4040
|
-
|
|
4041
3725
|
if (setter) {
|
|
4042
3726
|
setter(buffers[name]);
|
|
4043
3727
|
}
|
|
4044
3728
|
}
|
|
4045
3729
|
}
|
|
3730
|
+
|
|
4046
3731
|
/**
|
|
4047
3732
|
* Sets attributes and buffers including the `ELEMENT_ARRAY_BUFFER` if appropriate
|
|
4048
3733
|
*
|
|
@@ -4080,19 +3765,17 @@ function setAttributes(setters, buffers) {
|
|
|
4080
3765
|
* or a `VertexArrayInfo` as returned from {@link module:twgl.createVertexArrayInfo}
|
|
4081
3766
|
* @memberOf module:twgl/programs
|
|
4082
3767
|
*/
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
3768
|
function setBuffersAndAttributes(gl, programInfo, buffers) {
|
|
4086
3769
|
if (buffers.vertexArrayObject) {
|
|
4087
3770
|
gl.bindVertexArray(buffers.vertexArrayObject);
|
|
4088
3771
|
} else {
|
|
4089
3772
|
setAttributes(programInfo.attribSetters || programInfo, buffers.attribs);
|
|
4090
|
-
|
|
4091
3773
|
if (buffers.indices) {
|
|
4092
3774
|
gl.bindBuffer(ELEMENT_ARRAY_BUFFER, buffers.indices);
|
|
4093
3775
|
}
|
|
4094
3776
|
}
|
|
4095
3777
|
}
|
|
3778
|
+
|
|
4096
3779
|
/**
|
|
4097
3780
|
* @typedef {Object} ProgramInfo
|
|
4098
3781
|
* @property {WebGLProgram} program A shader program
|
|
@@ -4120,8 +3803,6 @@ function setBuffersAndAttributes(gl, programInfo, buffers) {
|
|
|
4120
3803
|
* @return {module:twgl.ProgramInfo} The created ProgramInfo.
|
|
4121
3804
|
* @memberOf module:twgl/programs
|
|
4122
3805
|
*/
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
3806
|
function createProgramInfoFromProgram(gl, program) {
|
|
4126
3807
|
var uniformSetters = createUniformSetters(gl, program);
|
|
4127
3808
|
var attribSetters = createAttributeSetters(gl, program);
|
|
@@ -4130,16 +3811,14 @@ function createProgramInfoFromProgram(gl, program) {
|
|
|
4130
3811
|
uniformSetters: uniformSetters,
|
|
4131
3812
|
attribSetters: attribSetters
|
|
4132
3813
|
};
|
|
4133
|
-
|
|
4134
3814
|
if (utils.isWebGL2(gl)) {
|
|
4135
3815
|
programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);
|
|
4136
3816
|
programInfo.transformFeedbackInfo = createTransformFeedbackInfo(gl, program);
|
|
4137
3817
|
}
|
|
4138
|
-
|
|
4139
3818
|
return programInfo;
|
|
4140
3819
|
}
|
|
4141
|
-
|
|
4142
3820
|
var notIdRE = /\s|{|}|;/;
|
|
3821
|
+
|
|
4143
3822
|
/**
|
|
4144
3823
|
* Creates a ProgramInfo from 2 sources.
|
|
4145
3824
|
*
|
|
@@ -4170,7 +3849,6 @@ var notIdRE = /\s|{|}|;/;
|
|
|
4170
3849
|
* @return {module:twgl.ProgramInfo?} The created ProgramInfo or null if it failed to link or compile
|
|
4171
3850
|
* @memberOf module:twgl/programs
|
|
4172
3851
|
*/
|
|
4173
|
-
|
|
4174
3852
|
function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
|
|
4175
3853
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
4176
3854
|
var errors = [];
|
|
@@ -4178,7 +3856,6 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4178
3856
|
// Lets assume if there is no \n it's an id
|
|
4179
3857
|
if (!notIdRE.test(source)) {
|
|
4180
3858
|
var script = getElementById(source);
|
|
4181
|
-
|
|
4182
3859
|
if (!script) {
|
|
4183
3860
|
var err = "no element with id: ".concat(source);
|
|
4184
3861
|
progOptions.errorCallback(err);
|
|
@@ -4187,34 +3864,25 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4187
3864
|
source = script.text;
|
|
4188
3865
|
}
|
|
4189
3866
|
}
|
|
4190
|
-
|
|
4191
3867
|
return source;
|
|
4192
3868
|
});
|
|
4193
|
-
|
|
4194
3869
|
if (errors.length) {
|
|
4195
3870
|
return reportError(progOptions, '');
|
|
4196
3871
|
}
|
|
4197
|
-
|
|
4198
3872
|
var origCallback = progOptions.callback;
|
|
4199
|
-
|
|
4200
3873
|
if (origCallback) {
|
|
4201
3874
|
progOptions.callback = function (err, program) {
|
|
4202
3875
|
var programInfo;
|
|
4203
|
-
|
|
4204
3876
|
if (!err) {
|
|
4205
3877
|
programInfo = createProgramInfoFromProgram(gl, program);
|
|
4206
3878
|
}
|
|
4207
|
-
|
|
4208
3879
|
origCallback(err, programInfo);
|
|
4209
3880
|
};
|
|
4210
3881
|
}
|
|
4211
|
-
|
|
4212
3882
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
4213
|
-
|
|
4214
3883
|
if (!program) {
|
|
4215
3884
|
return null;
|
|
4216
3885
|
}
|
|
4217
|
-
|
|
4218
3886
|
return createProgramInfoFromProgram(gl, program);
|
|
4219
3887
|
}
|
|
4220
3888
|
|
|
@@ -4230,39 +3898,32 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4230
3898
|
"use strict";
|
|
4231
3899
|
|
|
4232
3900
|
|
|
4233
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
4234
|
-
|
|
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); }
|
|
4235
3902
|
exports.__esModule = true;
|
|
4236
|
-
exports.
|
|
3903
|
+
exports.canFilter = canFilter;
|
|
3904
|
+
exports.canGenerateMipmap = canGenerateMipmap;
|
|
4237
3905
|
exports.createSampler = createSampler;
|
|
4238
3906
|
exports.createSamplers = createSamplers;
|
|
4239
|
-
exports.setSamplerParameters = setSamplerParameters;
|
|
4240
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;
|
|
4241
3915
|
exports.setEmptyTexture = setEmptyTexture;
|
|
3916
|
+
exports.setSamplerParameters = setSamplerParameters;
|
|
3917
|
+
exports.setTextureDefaults_ = setDefaults;
|
|
3918
|
+
exports.setTextureFilteringForSize = setTextureFilteringForSize;
|
|
4242
3919
|
exports.setTextureFromArray = setTextureFromArray;
|
|
4243
|
-
exports.loadTextureFromUrl = loadTextureFromUrl;
|
|
4244
3920
|
exports.setTextureFromElement = setTextureFromElement;
|
|
4245
|
-
exports.setTextureFilteringForSize = setTextureFilteringForSize;
|
|
4246
3921
|
exports.setTextureParameters = setTextureParameters;
|
|
4247
|
-
exports.setDefaultTextureColor = setDefaultTextureColor;
|
|
4248
|
-
exports.createTextures = createTextures;
|
|
4249
|
-
exports.resizeTexture = resizeTexture;
|
|
4250
|
-
exports.canGenerateMipmap = canGenerateMipmap;
|
|
4251
|
-
exports.canFilter = canFilter;
|
|
4252
|
-
exports.getNumComponentsForFormat = getNumComponentsForFormat;
|
|
4253
|
-
exports.getBytesPerElementForInternalFormat = getBytesPerElementForInternalFormat;
|
|
4254
|
-
exports.getFormatAndTypeForInternalFormat = getFormatAndTypeForInternalFormat;
|
|
4255
|
-
|
|
4256
3922
|
var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
|
|
4257
|
-
|
|
4258
3923
|
var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
|
|
4259
|
-
|
|
4260
3924
|
var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
|
|
4261
|
-
|
|
4262
|
-
function
|
|
4263
|
-
|
|
4264
|
-
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; }
|
|
4265
|
-
|
|
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; }
|
|
4266
3927
|
/*
|
|
4267
3928
|
* Copyright 2019 Gregg Tavares
|
|
4268
3929
|
*
|
|
@@ -4299,27 +3960,30 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
4299
3960
|
*
|
|
4300
3961
|
* @module twgl/textures
|
|
4301
3962
|
*/
|
|
4302
|
-
// make sure we don't see a global gl
|
|
4303
|
-
var gl = undefined;
|
|
4304
|
-
/* eslint-disable-line */
|
|
4305
3963
|
|
|
3964
|
+
// make sure we don't see a global gl
|
|
3965
|
+
var gl = undefined; /* eslint-disable-line */
|
|
4306
3966
|
var defaults = {
|
|
4307
3967
|
textureColor: new Uint8Array([128, 192, 255, 255]),
|
|
4308
3968
|
textureOptions: {},
|
|
4309
3969
|
crossOrigin: undefined
|
|
4310
3970
|
};
|
|
4311
|
-
var isArrayBuffer = typedArrays.isArrayBuffer;
|
|
3971
|
+
var isArrayBuffer = typedArrays.isArrayBuffer;
|
|
4312
3972
|
|
|
3973
|
+
// Should we make this on demand?
|
|
4313
3974
|
var getShared2DContext = function () {
|
|
4314
3975
|
var s_ctx;
|
|
4315
3976
|
return function getShared2DContext() {
|
|
4316
3977
|
s_ctx = s_ctx || (typeof document !== 'undefined' && document.createElement ? document.createElement("canvas").getContext("2d") : null);
|
|
4317
3978
|
return s_ctx;
|
|
4318
3979
|
};
|
|
4319
|
-
}();
|
|
3980
|
+
}();
|
|
3981
|
+
|
|
3982
|
+
// NOTE: Chrome supports 2D canvas in a Worker (behind flag as of v64 but
|
|
4320
3983
|
// not only does Firefox NOT support it but Firefox freezes immediately
|
|
4321
3984
|
// if you try to create one instead of just returning null and continuing.
|
|
4322
3985
|
// : (global.OffscreenCanvas && (new global.OffscreenCanvas(1, 1)).getContext("2d")); // OffscreenCanvas may not support 2d
|
|
3986
|
+
|
|
4323
3987
|
// NOTE: We can maybe remove some of the need for the 2d canvas. In WebGL2
|
|
4324
3988
|
// we can use the various unpack settings. Otherwise we could try using
|
|
4325
3989
|
// the ability of an ImageBitmap to be cut. Unfortunately cutting an ImageBitmap
|
|
@@ -4328,8 +3992,6 @@ var getShared2DContext = function () {
|
|
|
4328
3992
|
// as of 2018-01-02
|
|
4329
3993
|
|
|
4330
3994
|
/* PixelFormat */
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
3995
|
var ALPHA = 0x1906;
|
|
4334
3996
|
var RGB = 0x1907;
|
|
4335
3997
|
var RGBA = 0x1908;
|
|
@@ -4337,15 +3999,16 @@ var LUMINANCE = 0x1909;
|
|
|
4337
3999
|
var LUMINANCE_ALPHA = 0x190A;
|
|
4338
4000
|
var DEPTH_COMPONENT = 0x1902;
|
|
4339
4001
|
var DEPTH_STENCIL = 0x84F9;
|
|
4002
|
+
|
|
4340
4003
|
/* TextureWrapMode */
|
|
4341
4004
|
// const REPEAT = 0x2901;
|
|
4342
4005
|
// const MIRRORED_REPEAT = 0x8370;
|
|
4343
|
-
|
|
4344
4006
|
var CLAMP_TO_EDGE = 0x812f;
|
|
4345
|
-
/* TextureMagFilter */
|
|
4346
4007
|
|
|
4008
|
+
/* TextureMagFilter */
|
|
4347
4009
|
var NEAREST = 0x2600;
|
|
4348
4010
|
var LINEAR = 0x2601;
|
|
4011
|
+
|
|
4349
4012
|
/* TextureMinFilter */
|
|
4350
4013
|
// const NEAREST_MIPMAP_NEAREST = 0x2700;
|
|
4351
4014
|
// const LINEAR_MIPMAP_NEAREST = 0x2701;
|
|
@@ -4353,21 +4016,20 @@ var LINEAR = 0x2601;
|
|
|
4353
4016
|
// const LINEAR_MIPMAP_LINEAR = 0x2703;
|
|
4354
4017
|
|
|
4355
4018
|
/* Texture Target */
|
|
4356
|
-
|
|
4357
4019
|
var TEXTURE_2D = 0x0de1;
|
|
4358
4020
|
var TEXTURE_CUBE_MAP = 0x8513;
|
|
4359
4021
|
var TEXTURE_3D = 0x806f;
|
|
4360
4022
|
var TEXTURE_2D_ARRAY = 0x8c1a;
|
|
4361
|
-
/* Cubemap Targets */
|
|
4362
4023
|
|
|
4024
|
+
/* Cubemap Targets */
|
|
4363
4025
|
var TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
|
|
4364
4026
|
var TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
|
|
4365
4027
|
var TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
|
|
4366
4028
|
var TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
|
|
4367
4029
|
var TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
|
|
4368
4030
|
var TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
|
|
4369
|
-
/* Texture Parameters */
|
|
4370
4031
|
|
|
4032
|
+
/* Texture Parameters */
|
|
4371
4033
|
var TEXTURE_MIN_FILTER = 0x2801;
|
|
4372
4034
|
var TEXTURE_MAG_FILTER = 0x2800;
|
|
4373
4035
|
var TEXTURE_WRAP_S = 0x2802;
|
|
@@ -4377,8 +4039,8 @@ var TEXTURE_MIN_LOD = 0x813a;
|
|
|
4377
4039
|
var TEXTURE_MAX_LOD = 0x813b;
|
|
4378
4040
|
var TEXTURE_BASE_LEVEL = 0x813c;
|
|
4379
4041
|
var TEXTURE_MAX_LEVEL = 0x813d;
|
|
4380
|
-
/* Pixel store */
|
|
4381
4042
|
|
|
4043
|
+
/* Pixel store */
|
|
4382
4044
|
var UNPACK_ALIGNMENT = 0x0cf5;
|
|
4383
4045
|
var UNPACK_ROW_LENGTH = 0x0cf2;
|
|
4384
4046
|
var UNPACK_IMAGE_HEIGHT = 0x806e;
|
|
@@ -4442,8 +4104,8 @@ var DEPTH_COMPONENT24 = 0x81A6;
|
|
|
4442
4104
|
var DEPTH_COMPONENT32F = 0x8CAC;
|
|
4443
4105
|
var DEPTH32F_STENCIL8 = 0x8CAD;
|
|
4444
4106
|
var DEPTH24_STENCIL8 = 0x88F0;
|
|
4445
|
-
/* DataType */
|
|
4446
4107
|
|
|
4108
|
+
/* DataType */
|
|
4447
4109
|
var BYTE = 0x1400;
|
|
4448
4110
|
var UNSIGNED_BYTE = 0x1401;
|
|
4449
4111
|
var SHORT = 0x1402;
|
|
@@ -4456,7 +4118,6 @@ var UNSIGNED_SHORT_5_5_5_1 = 0x8034;
|
|
|
4456
4118
|
var UNSIGNED_SHORT_5_6_5 = 0x8363;
|
|
4457
4119
|
var HALF_FLOAT = 0x140B;
|
|
4458
4120
|
var HALF_FLOAT_OES = 0x8D61; // Thanks Khronos for making this different >:(
|
|
4459
|
-
|
|
4460
4121
|
var UNSIGNED_INT_2_10_10_10_REV = 0x8368;
|
|
4461
4122
|
var UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B;
|
|
4462
4123
|
var UNSIGNED_INT_5_9_9_9_REV = 0x8C3E;
|
|
@@ -4519,6 +4180,7 @@ var formatInfo = {};
|
|
|
4519
4180
|
numColorComponents: 2
|
|
4520
4181
|
};
|
|
4521
4182
|
}
|
|
4183
|
+
|
|
4522
4184
|
/**
|
|
4523
4185
|
* @typedef {Object} TextureFormatDetails
|
|
4524
4186
|
* @property {number} textureFormat format to pass texImage2D and similar functions.
|
|
@@ -4530,12 +4192,11 @@ var formatInfo = {};
|
|
|
4530
4192
|
*/
|
|
4531
4193
|
|
|
4532
4194
|
var s_textureInternalFormatInfo;
|
|
4533
|
-
|
|
4534
4195
|
function getTextureInternalFormatInfo(internalFormat) {
|
|
4535
4196
|
if (!s_textureInternalFormatInfo) {
|
|
4536
4197
|
// NOTE: these properties need unique names so we can let Uglify mangle the name.
|
|
4537
|
-
var t = {};
|
|
4538
|
-
|
|
4198
|
+
var t = {};
|
|
4199
|
+
// unsized formats
|
|
4539
4200
|
t[ALPHA] = {
|
|
4540
4201
|
textureFormat: ALPHA,
|
|
4541
4202
|
colorRenderable: true,
|
|
@@ -4577,8 +4238,9 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
4577
4238
|
textureFilterable: false,
|
|
4578
4239
|
bytesPerElement: [2, 4],
|
|
4579
4240
|
type: [UNSIGNED_INT, UNSIGNED_SHORT]
|
|
4580
|
-
};
|
|
4241
|
+
};
|
|
4581
4242
|
|
|
4243
|
+
// sized formats
|
|
4582
4244
|
t[R8] = {
|
|
4583
4245
|
textureFormat: RED,
|
|
4584
4246
|
colorRenderable: true,
|
|
@@ -4921,8 +4583,8 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
4921
4583
|
textureFilterable: false,
|
|
4922
4584
|
bytesPerElement: [16],
|
|
4923
4585
|
type: [UNSIGNED_INT]
|
|
4924
|
-
};
|
|
4925
|
-
|
|
4586
|
+
};
|
|
4587
|
+
// Sized Internal
|
|
4926
4588
|
t[DEPTH_COMPONENT16] = {
|
|
4927
4589
|
textureFormat: DEPTH_COMPONENT,
|
|
4928
4590
|
colorRenderable: true,
|
|
@@ -4968,9 +4630,9 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
4968
4630
|
});
|
|
4969
4631
|
s_textureInternalFormatInfo = t;
|
|
4970
4632
|
}
|
|
4971
|
-
|
|
4972
4633
|
return s_textureInternalFormatInfo[internalFormat];
|
|
4973
4634
|
}
|
|
4635
|
+
|
|
4974
4636
|
/**
|
|
4975
4637
|
* Gets the number of bytes per element for a given internalFormat / type
|
|
4976
4638
|
* @param {number} internalFormat The internalFormat parameter from texImage2D etc..
|
|
@@ -4978,23 +4640,18 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
4978
4640
|
* @return {number} the number of bytes per element for the given internalFormat, type combo
|
|
4979
4641
|
* @memberOf module:twgl/textures
|
|
4980
4642
|
*/
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
4643
|
function getBytesPerElementForInternalFormat(internalFormat, type) {
|
|
4984
4644
|
var info = getTextureInternalFormatInfo(internalFormat);
|
|
4985
|
-
|
|
4986
4645
|
if (!info) {
|
|
4987
4646
|
throw "unknown internal format";
|
|
4988
4647
|
}
|
|
4989
|
-
|
|
4990
4648
|
var bytesPerElement = info.bytesPerElementMap[type];
|
|
4991
|
-
|
|
4992
4649
|
if (bytesPerElement === undefined) {
|
|
4993
4650
|
throw "unknown internal format";
|
|
4994
4651
|
}
|
|
4995
|
-
|
|
4996
4652
|
return bytesPerElement;
|
|
4997
4653
|
}
|
|
4654
|
+
|
|
4998
4655
|
/**
|
|
4999
4656
|
* Info related to a specific texture internalFormat as returned
|
|
5000
4657
|
* from {@link module:twgl/textures.getFormatAndTypeForInternalFormat}.
|
|
@@ -5012,31 +4669,27 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
|
|
|
5012
4669
|
* @return {module:twgl/textures.TextureFormatInfo} the corresponding format and type,
|
|
5013
4670
|
* @memberOf module:twgl/textures
|
|
5014
4671
|
*/
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
4672
|
function getFormatAndTypeForInternalFormat(internalFormat) {
|
|
5018
4673
|
var info = getTextureInternalFormatInfo(internalFormat);
|
|
5019
|
-
|
|
5020
4674
|
if (!info) {
|
|
5021
4675
|
throw "unknown internal format";
|
|
5022
4676
|
}
|
|
5023
|
-
|
|
5024
4677
|
return {
|
|
5025
4678
|
format: info.textureFormat,
|
|
5026
4679
|
type: info.type[0]
|
|
5027
4680
|
};
|
|
5028
4681
|
}
|
|
4682
|
+
|
|
5029
4683
|
/**
|
|
5030
4684
|
* Returns true if value is power of 2
|
|
5031
4685
|
* @param {number} value number to check.
|
|
5032
4686
|
* @return true if value is power of 2
|
|
5033
4687
|
* @private
|
|
5034
4688
|
*/
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
4689
|
function isPowerOf2(value) {
|
|
5038
4690
|
return (value & value - 1) === 0;
|
|
5039
4691
|
}
|
|
4692
|
+
|
|
5040
4693
|
/**
|
|
5041
4694
|
* Gets whether or not we can generate mips for the given
|
|
5042
4695
|
* internal format.
|
|
@@ -5048,79 +4701,63 @@ function isPowerOf2(value) {
|
|
|
5048
4701
|
* @return {boolean} true if we can generate mips
|
|
5049
4702
|
* @memberOf module:twgl/textures
|
|
5050
4703
|
*/
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
4704
|
function canGenerateMipmap(gl, width, height, internalFormat) {
|
|
5054
4705
|
if (!utils.isWebGL2(gl)) {
|
|
5055
4706
|
return isPowerOf2(width) && isPowerOf2(height);
|
|
5056
4707
|
}
|
|
5057
|
-
|
|
5058
4708
|
var info = getTextureInternalFormatInfo(internalFormat);
|
|
5059
|
-
|
|
5060
4709
|
if (!info) {
|
|
5061
4710
|
throw "unknown internal format";
|
|
5062
4711
|
}
|
|
5063
|
-
|
|
5064
4712
|
return info.colorRenderable && info.textureFilterable;
|
|
5065
4713
|
}
|
|
4714
|
+
|
|
5066
4715
|
/**
|
|
5067
4716
|
* Gets whether or not we can generate mips for the given format
|
|
5068
4717
|
* @param {number} internalFormat The internalFormat parameter from texImage2D etc..
|
|
5069
4718
|
* @return {boolean} true if we can generate mips
|
|
5070
4719
|
* @memberOf module:twgl/textures
|
|
5071
4720
|
*/
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
4721
|
function canFilter(internalFormat) {
|
|
5075
4722
|
var info = getTextureInternalFormatInfo(internalFormat);
|
|
5076
|
-
|
|
5077
4723
|
if (!info) {
|
|
5078
4724
|
throw "unknown internal format";
|
|
5079
4725
|
}
|
|
5080
|
-
|
|
5081
4726
|
return info.textureFilterable;
|
|
5082
4727
|
}
|
|
4728
|
+
|
|
5083
4729
|
/**
|
|
5084
4730
|
* Gets the number of components for a given image format.
|
|
5085
4731
|
* @param {number} format the format.
|
|
5086
4732
|
* @return {number} the number of components for the format.
|
|
5087
4733
|
* @memberOf module:twgl/textures
|
|
5088
4734
|
*/
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
4735
|
function getNumComponentsForFormat(format) {
|
|
5092
4736
|
var info = formatInfo[format];
|
|
5093
|
-
|
|
5094
4737
|
if (!info) {
|
|
5095
4738
|
throw "unknown format: " + format;
|
|
5096
4739
|
}
|
|
5097
|
-
|
|
5098
4740
|
return info.numColorComponents;
|
|
5099
4741
|
}
|
|
4742
|
+
|
|
5100
4743
|
/**
|
|
5101
4744
|
* Gets the texture type for a given array type.
|
|
5102
4745
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
5103
4746
|
* @return {number} the gl texture type
|
|
5104
4747
|
* @private
|
|
5105
4748
|
*/
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
4749
|
function getTextureTypeForArrayType(gl, src, defaultType) {
|
|
5109
4750
|
if (isArrayBuffer(src)) {
|
|
5110
4751
|
return typedArrays.getGLTypeForTypedArray(src);
|
|
5111
4752
|
}
|
|
5112
|
-
|
|
5113
4753
|
return defaultType || UNSIGNED_BYTE;
|
|
5114
4754
|
}
|
|
5115
|
-
|
|
5116
4755
|
function guessDimensions(gl, target, width, height, numElements) {
|
|
5117
4756
|
if (numElements % 1 !== 0) {
|
|
5118
4757
|
throw "can't guess dimensions";
|
|
5119
4758
|
}
|
|
5120
|
-
|
|
5121
4759
|
if (!width && !height) {
|
|
5122
4760
|
var size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
|
|
5123
|
-
|
|
5124
4761
|
if (size % 1 === 0) {
|
|
5125
4762
|
width = size;
|
|
5126
4763
|
height = size;
|
|
@@ -5130,23 +4767,21 @@ function guessDimensions(gl, target, width, height, numElements) {
|
|
|
5130
4767
|
}
|
|
5131
4768
|
} else if (!height) {
|
|
5132
4769
|
height = numElements / width;
|
|
5133
|
-
|
|
5134
4770
|
if (height % 1) {
|
|
5135
4771
|
throw "can't guess dimensions";
|
|
5136
4772
|
}
|
|
5137
4773
|
} else if (!width) {
|
|
5138
4774
|
width = numElements / height;
|
|
5139
|
-
|
|
5140
4775
|
if (width % 1) {
|
|
5141
4776
|
throw "can't guess dimensions";
|
|
5142
4777
|
}
|
|
5143
4778
|
}
|
|
5144
|
-
|
|
5145
4779
|
return {
|
|
5146
4780
|
width: width,
|
|
5147
4781
|
height: height
|
|
5148
4782
|
};
|
|
5149
4783
|
}
|
|
4784
|
+
|
|
5150
4785
|
/**
|
|
5151
4786
|
* Sets the default texture color.
|
|
5152
4787
|
*
|
|
@@ -5160,19 +4795,16 @@ function guessDimensions(gl, target, width, height, numElements) {
|
|
|
5160
4795
|
* @deprecated see {@link module:twgl.setDefaults}
|
|
5161
4796
|
* @memberOf module:twgl/textures
|
|
5162
4797
|
*/
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
4798
|
function setDefaultTextureColor(color) {
|
|
5166
4799
|
defaults.textureColor = new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
|
|
5167
4800
|
}
|
|
5168
|
-
|
|
5169
4801
|
function setDefaults(newDefaults) {
|
|
5170
4802
|
helper.copyExistingProperties(newDefaults, defaults);
|
|
5171
|
-
|
|
5172
4803
|
if (newDefaults.textureColor) {
|
|
5173
4804
|
setDefaultTextureColor(newDefaults.textureColor);
|
|
5174
4805
|
}
|
|
5175
4806
|
}
|
|
4807
|
+
|
|
5176
4808
|
/**
|
|
5177
4809
|
* A function to generate the source for a texture.
|
|
5178
4810
|
* @callback TextureFunc
|
|
@@ -5281,31 +4913,25 @@ function setDefaults(newDefaults) {
|
|
|
5281
4913
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
5282
4914
|
* @private
|
|
5283
4915
|
*/
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
4916
|
function setPackState(gl, options) {
|
|
5287
4917
|
if (options.colorspaceConversion !== undefined) {
|
|
5288
4918
|
gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
|
|
5289
4919
|
}
|
|
5290
|
-
|
|
5291
4920
|
if (options.premultiplyAlpha !== undefined) {
|
|
5292
4921
|
gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
|
|
5293
4922
|
}
|
|
5294
|
-
|
|
5295
4923
|
if (options.flipY !== undefined) {
|
|
5296
4924
|
gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);
|
|
5297
4925
|
}
|
|
5298
4926
|
}
|
|
4927
|
+
|
|
5299
4928
|
/**
|
|
5300
4929
|
* Set skip state to defaults
|
|
5301
4930
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
5302
4931
|
* @private
|
|
5303
4932
|
*/
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
4933
|
function setSkipStateToDefault(gl) {
|
|
5307
4934
|
gl.pixelStorei(UNPACK_ALIGNMENT, 4);
|
|
5308
|
-
|
|
5309
4935
|
if (utils.isWebGL2(gl)) {
|
|
5310
4936
|
gl.pixelStorei(UNPACK_ROW_LENGTH, 0);
|
|
5311
4937
|
gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
|
|
@@ -5314,6 +4940,7 @@ function setSkipStateToDefault(gl) {
|
|
|
5314
4940
|
gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
|
|
5315
4941
|
}
|
|
5316
4942
|
}
|
|
4943
|
+
|
|
5317
4944
|
/**
|
|
5318
4945
|
* Sets the parameters of a texture or sampler
|
|
5319
4946
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
@@ -5324,59 +4951,47 @@ function setSkipStateToDefault(gl) {
|
|
|
5324
4951
|
* This is often the same options you passed in when you created the texture.
|
|
5325
4952
|
* @private
|
|
5326
4953
|
*/
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
4954
|
function setTextureSamplerParameters(gl, target, parameteriFn, options) {
|
|
5330
4955
|
if (options.minMag) {
|
|
5331
4956
|
parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.minMag);
|
|
5332
4957
|
parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.minMag);
|
|
5333
4958
|
}
|
|
5334
|
-
|
|
5335
4959
|
if (options.min) {
|
|
5336
4960
|
parameteriFn.call(gl, target, TEXTURE_MIN_FILTER, options.min);
|
|
5337
4961
|
}
|
|
5338
|
-
|
|
5339
4962
|
if (options.mag) {
|
|
5340
4963
|
parameteriFn.call(gl, target, TEXTURE_MAG_FILTER, options.mag);
|
|
5341
4964
|
}
|
|
5342
|
-
|
|
5343
4965
|
if (options.wrap) {
|
|
5344
4966
|
parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrap);
|
|
5345
4967
|
parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrap);
|
|
5346
|
-
|
|
5347
4968
|
if (target === TEXTURE_3D || helper.isSampler(gl, target)) {
|
|
5348
4969
|
parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrap);
|
|
5349
4970
|
}
|
|
5350
4971
|
}
|
|
5351
|
-
|
|
5352
4972
|
if (options.wrapR) {
|
|
5353
4973
|
parameteriFn.call(gl, target, TEXTURE_WRAP_R, options.wrapR);
|
|
5354
4974
|
}
|
|
5355
|
-
|
|
5356
4975
|
if (options.wrapS) {
|
|
5357
4976
|
parameteriFn.call(gl, target, TEXTURE_WRAP_S, options.wrapS);
|
|
5358
4977
|
}
|
|
5359
|
-
|
|
5360
4978
|
if (options.wrapT) {
|
|
5361
4979
|
parameteriFn.call(gl, target, TEXTURE_WRAP_T, options.wrapT);
|
|
5362
4980
|
}
|
|
5363
|
-
|
|
5364
4981
|
if (options.minLod) {
|
|
5365
4982
|
parameteriFn.call(gl, target, TEXTURE_MIN_LOD, options.minLod);
|
|
5366
4983
|
}
|
|
5367
|
-
|
|
5368
4984
|
if (options.maxLod) {
|
|
5369
4985
|
parameteriFn.call(gl, target, TEXTURE_MAX_LOD, options.maxLod);
|
|
5370
4986
|
}
|
|
5371
|
-
|
|
5372
4987
|
if (options.baseLevel) {
|
|
5373
4988
|
parameteriFn.call(gl, target, TEXTURE_BASE_LEVEL, options.baseLevel);
|
|
5374
4989
|
}
|
|
5375
|
-
|
|
5376
4990
|
if (options.maxLevel) {
|
|
5377
4991
|
parameteriFn.call(gl, target, TEXTURE_MAX_LEVEL, options.maxLevel);
|
|
5378
4992
|
}
|
|
5379
4993
|
}
|
|
4994
|
+
|
|
5380
4995
|
/**
|
|
5381
4996
|
* Sets the texture parameters of a texture.
|
|
5382
4997
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
@@ -5385,13 +5000,12 @@ function setTextureSamplerParameters(gl, target, parameteriFn, options) {
|
|
|
5385
5000
|
* This is often the same options you passed in when you created the texture.
|
|
5386
5001
|
* @memberOf module:twgl/textures
|
|
5387
5002
|
*/
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
5003
|
function setTextureParameters(gl, tex, options) {
|
|
5391
5004
|
var target = options.target || TEXTURE_2D;
|
|
5392
5005
|
gl.bindTexture(target, tex);
|
|
5393
5006
|
setTextureSamplerParameters(gl, target, gl.texParameteri, options);
|
|
5394
5007
|
}
|
|
5008
|
+
|
|
5395
5009
|
/**
|
|
5396
5010
|
* Sets the sampler parameters of a sampler.
|
|
5397
5011
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
@@ -5399,11 +5013,10 @@ function setTextureParameters(gl, tex, options) {
|
|
|
5399
5013
|
* @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
|
|
5400
5014
|
* @memberOf module:twgl/textures
|
|
5401
5015
|
*/
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
5016
|
function setSamplerParameters(gl, sampler, options) {
|
|
5405
5017
|
setTextureSamplerParameters(gl, sampler, gl.samplerParameteri, options);
|
|
5406
5018
|
}
|
|
5019
|
+
|
|
5407
5020
|
/**
|
|
5408
5021
|
* Creates a new sampler object and sets parameters.
|
|
5409
5022
|
*
|
|
@@ -5419,13 +5032,12 @@ function setSamplerParameters(gl, sampler, options) {
|
|
|
5419
5032
|
* @return {Object.<string,WebGLSampler>} the created samplers by name
|
|
5420
5033
|
* @private
|
|
5421
5034
|
*/
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
5035
|
function createSampler(gl, options) {
|
|
5425
5036
|
var sampler = gl.createSampler();
|
|
5426
5037
|
setSamplerParameters(gl, sampler, options);
|
|
5427
5038
|
return sampler;
|
|
5428
5039
|
}
|
|
5040
|
+
|
|
5429
5041
|
/**
|
|
5430
5042
|
* Creates a multiple sampler objects and sets parameters on each.
|
|
5431
5043
|
*
|
|
@@ -5460,8 +5072,6 @@ function createSampler(gl, options) {
|
|
|
5460
5072
|
* @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set on the sampler
|
|
5461
5073
|
* @private
|
|
5462
5074
|
*/
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
5075
|
function createSamplers(gl, samplerOptions) {
|
|
5466
5076
|
var samplers = {};
|
|
5467
5077
|
Object.keys(samplerOptions).forEach(function (name) {
|
|
@@ -5469,6 +5079,7 @@ function createSamplers(gl, samplerOptions) {
|
|
|
5469
5079
|
});
|
|
5470
5080
|
return samplers;
|
|
5471
5081
|
}
|
|
5082
|
+
|
|
5472
5083
|
/**
|
|
5473
5084
|
* Makes a 1x1 pixel
|
|
5474
5085
|
* If no color is passed in uses the default color which can be set by calling `setDefaultTextureColor`.
|
|
@@ -5476,17 +5087,14 @@ function createSamplers(gl, samplerOptions) {
|
|
|
5476
5087
|
* @return {Uint8Array} Unit8Array with color.
|
|
5477
5088
|
* @private
|
|
5478
5089
|
*/
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
5090
|
function make1Pixel(color) {
|
|
5482
5091
|
color = color || defaults.textureColor;
|
|
5483
|
-
|
|
5484
5092
|
if (isArrayBuffer(color)) {
|
|
5485
5093
|
return color;
|
|
5486
5094
|
}
|
|
5487
|
-
|
|
5488
5095
|
return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
|
|
5489
5096
|
}
|
|
5097
|
+
|
|
5490
5098
|
/**
|
|
5491
5099
|
* Sets filtering or generates mips for texture based on width or height
|
|
5492
5100
|
* If width or height is not passed in uses `options.width` and//or `options.height`
|
|
@@ -5500,8 +5108,6 @@ function make1Pixel(color) {
|
|
|
5500
5108
|
* @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
|
|
5501
5109
|
* @memberOf module:twgl/textures
|
|
5502
5110
|
*/
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
5111
|
function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
|
|
5506
5112
|
options = options || defaults.textureOptions;
|
|
5507
5113
|
internalFormat = internalFormat || RGBA;
|
|
@@ -5509,7 +5115,6 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
|
|
|
5509
5115
|
width = width || options.width;
|
|
5510
5116
|
height = height || options.height;
|
|
5511
5117
|
gl.bindTexture(target, tex);
|
|
5512
|
-
|
|
5513
5118
|
if (canGenerateMipmap(gl, width, height, internalFormat)) {
|
|
5514
5119
|
gl.generateMipmap(target);
|
|
5515
5120
|
} else {
|
|
@@ -5520,10 +5125,10 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
|
|
|
5520
5125
|
gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
|
|
5521
5126
|
}
|
|
5522
5127
|
}
|
|
5523
|
-
|
|
5524
5128
|
function shouldAutomaticallySetTextureFilteringForSize(options) {
|
|
5525
5129
|
return options.auto === true || options.auto === undefined && options.level === undefined;
|
|
5526
5130
|
}
|
|
5131
|
+
|
|
5527
5132
|
/**
|
|
5528
5133
|
* Gets an array of cubemap face enums
|
|
5529
5134
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
@@ -5532,12 +5137,11 @@ function shouldAutomaticallySetTextureFilteringForSize(options) {
|
|
|
5532
5137
|
* @return {number[]} cubemap face enums
|
|
5533
5138
|
* @private
|
|
5534
5139
|
*/
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
5140
|
function getCubeFaceOrder(gl, options) {
|
|
5538
5141
|
options = options || {};
|
|
5539
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];
|
|
5540
5143
|
}
|
|
5144
|
+
|
|
5541
5145
|
/**
|
|
5542
5146
|
* @typedef {Object} FaceInfo
|
|
5543
5147
|
* @property {number} face gl enum for texImage2D
|
|
@@ -5558,11 +5162,9 @@ function getCubeFaceOrder(gl, options) {
|
|
|
5558
5162
|
* it's needed internally to sort the array of `ndx` properties by `face`.
|
|
5559
5163
|
* @private
|
|
5560
5164
|
*/
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
5165
|
function getCubeFacesWithNdx(gl, options) {
|
|
5564
|
-
var faces = getCubeFaceOrder(gl, options);
|
|
5565
|
-
|
|
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 :(
|
|
5566
5168
|
var facesWithNdx = faces.map(function (face, ndx) {
|
|
5567
5169
|
return {
|
|
5568
5170
|
face: face,
|
|
@@ -5574,6 +5176,7 @@ function getCubeFacesWithNdx(gl, options) {
|
|
|
5574
5176
|
});
|
|
5575
5177
|
return facesWithNdx;
|
|
5576
5178
|
}
|
|
5179
|
+
|
|
5577
5180
|
/**
|
|
5578
5181
|
* Set a texture from the contents of an element. Will also set
|
|
5579
5182
|
* texture filtering or generate mips based on the dimensions of the element
|
|
@@ -5587,8 +5190,6 @@ function getCubeFacesWithNdx(gl, options) {
|
|
|
5587
5190
|
* @memberOf module:twgl/textures
|
|
5588
5191
|
* @kind function
|
|
5589
5192
|
*/
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
5193
|
function setTextureFromElement(gl, tex, element, options) {
|
|
5593
5194
|
options = options || defaults.textureOptions;
|
|
5594
5195
|
var target = options.target || TEXTURE_2D;
|
|
@@ -5601,14 +5202,12 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5601
5202
|
var type = options.type || formatType.type;
|
|
5602
5203
|
setPackState(gl, options);
|
|
5603
5204
|
gl.bindTexture(target, tex);
|
|
5604
|
-
|
|
5605
5205
|
if (target === TEXTURE_CUBE_MAP) {
|
|
5606
5206
|
// guess the parts
|
|
5607
5207
|
var imgWidth = element.width;
|
|
5608
5208
|
var imgHeight = element.height;
|
|
5609
5209
|
var size;
|
|
5610
5210
|
var slices;
|
|
5611
|
-
|
|
5612
5211
|
if (imgWidth / 6 === imgHeight) {
|
|
5613
5212
|
// It's 6x1
|
|
5614
5213
|
size = imgHeight;
|
|
@@ -5628,9 +5227,7 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5628
5227
|
} else {
|
|
5629
5228
|
throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
|
|
5630
5229
|
}
|
|
5631
|
-
|
|
5632
5230
|
var ctx = getShared2DContext();
|
|
5633
|
-
|
|
5634
5231
|
if (ctx) {
|
|
5635
5232
|
ctx.canvas.width = size;
|
|
5636
5233
|
ctx.canvas.height = size;
|
|
@@ -5641,8 +5238,8 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5641
5238
|
var yOffset = slices[f.ndx * 2 + 1] * size;
|
|
5642
5239
|
ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
|
|
5643
5240
|
gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
|
|
5644
|
-
});
|
|
5645
|
-
|
|
5241
|
+
});
|
|
5242
|
+
// Free up the canvas memory
|
|
5646
5243
|
ctx.canvas.width = 1;
|
|
5647
5244
|
ctx.canvas.height = 1;
|
|
5648
5245
|
} else if (typeof createImageBitmap !== 'undefined') {
|
|
@@ -5652,12 +5249,12 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5652
5249
|
height = size;
|
|
5653
5250
|
getCubeFacesWithNdx(gl, options).forEach(function (f) {
|
|
5654
5251
|
var xOffset = slices[f.ndx * 2 + 0] * size;
|
|
5655
|
-
var yOffset = slices[f.ndx * 2 + 1] * size;
|
|
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
|
|
5656
5254
|
// the type across all faces where as with a 2D one there's only one face
|
|
5657
5255
|
// so we're replacing everything all at once. It also has to be the correct size.
|
|
5658
5256
|
// On the other hand we need all faces to be the same size so as one face loads
|
|
5659
5257
|
// the rest match else the texture will be un-renderable.
|
|
5660
|
-
|
|
5661
5258
|
gl.texImage2D(f.face, level, internalFormat, size, size, 0, format, type, null);
|
|
5662
5259
|
createImageBitmap(element, xOffset, yOffset, size, size, {
|
|
5663
5260
|
premultiplyAlpha: 'none',
|
|
@@ -5666,7 +5263,6 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5666
5263
|
setPackState(gl, options);
|
|
5667
5264
|
gl.bindTexture(target, tex);
|
|
5668
5265
|
gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
|
|
5669
|
-
|
|
5670
5266
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
5671
5267
|
setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
|
|
5672
5268
|
}
|
|
@@ -5677,11 +5273,9 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5677
5273
|
var smallest = Math.min(element.width, element.height);
|
|
5678
5274
|
var largest = Math.max(element.width, element.height);
|
|
5679
5275
|
var depth = largest / smallest;
|
|
5680
|
-
|
|
5681
5276
|
if (depth % 1 !== 0) {
|
|
5682
5277
|
throw "can not compute 3D dimensions of element";
|
|
5683
5278
|
}
|
|
5684
|
-
|
|
5685
5279
|
var xMult = element.width === largest ? 1 : 0;
|
|
5686
5280
|
var yMult = element.height === largest ? 1 : 0;
|
|
5687
5281
|
gl.pixelStorei(UNPACK_ALIGNMENT, 1);
|
|
@@ -5689,7 +5283,6 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5689
5283
|
gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
|
|
5690
5284
|
gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
|
|
5691
5285
|
gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
|
|
5692
|
-
|
|
5693
5286
|
for (var d = 0; d < depth; ++d) {
|
|
5694
5287
|
var srcX = d * smallest * xMult;
|
|
5695
5288
|
var srcY = d * smallest * yMult;
|
|
@@ -5697,28 +5290,23 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5697
5290
|
gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
|
|
5698
5291
|
gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
|
|
5699
5292
|
}
|
|
5700
|
-
|
|
5701
5293
|
setSkipStateToDefault(gl);
|
|
5702
5294
|
} else {
|
|
5703
5295
|
gl.texImage2D(target, level, internalFormat, format, type, element);
|
|
5704
5296
|
}
|
|
5705
|
-
|
|
5706
5297
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
5707
5298
|
setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
|
|
5708
5299
|
}
|
|
5709
|
-
|
|
5710
5300
|
setTextureParameters(gl, tex, options);
|
|
5711
5301
|
}
|
|
5712
|
-
|
|
5713
5302
|
function noop() {}
|
|
5303
|
+
|
|
5714
5304
|
/**
|
|
5715
5305
|
* Checks whether the url's origin is the same so that we can set the `crossOrigin`
|
|
5716
5306
|
* @param {string} url url to image
|
|
5717
5307
|
* @returns {boolean} true if the window's origin is the same as image's url
|
|
5718
5308
|
* @private
|
|
5719
5309
|
*/
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
5310
|
function urlIsSameOrigin(url) {
|
|
5723
5311
|
if (typeof document !== 'undefined') {
|
|
5724
5312
|
// for IE really
|
|
@@ -5731,10 +5319,10 @@ function urlIsSameOrigin(url) {
|
|
|
5731
5319
|
return urlOrigin === localOrigin;
|
|
5732
5320
|
}
|
|
5733
5321
|
}
|
|
5734
|
-
|
|
5735
5322
|
function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
|
|
5736
5323
|
return crossOrigin === undefined && !urlIsSameOrigin(url) ? 'anonymous' : crossOrigin;
|
|
5737
5324
|
}
|
|
5325
|
+
|
|
5738
5326
|
/**
|
|
5739
5327
|
* Loads an image
|
|
5740
5328
|
* @param {string} url url to image
|
|
@@ -5744,41 +5332,31 @@ function setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin) {
|
|
|
5744
5332
|
* @return {HTMLImageElement} the image being loaded.
|
|
5745
5333
|
* @private
|
|
5746
5334
|
*/
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
5335
|
function loadImage(url, crossOrigin, callback) {
|
|
5750
5336
|
callback = callback || noop;
|
|
5751
5337
|
var img;
|
|
5752
5338
|
crossOrigin = crossOrigin !== undefined ? crossOrigin : defaults.crossOrigin;
|
|
5753
5339
|
crossOrigin = setToAnonymousIfUndefinedAndURLIsNotSameOrigin(url, crossOrigin);
|
|
5754
|
-
|
|
5755
5340
|
if (typeof Image !== 'undefined') {
|
|
5756
5341
|
img = new Image();
|
|
5757
|
-
|
|
5758
5342
|
if (crossOrigin !== undefined) {
|
|
5759
5343
|
img.crossOrigin = crossOrigin;
|
|
5760
5344
|
}
|
|
5761
|
-
|
|
5762
5345
|
var clearEventHandlers = function clearEventHandlers() {
|
|
5763
5346
|
img.removeEventListener('error', onError); // eslint-disable-line
|
|
5764
|
-
|
|
5765
5347
|
img.removeEventListener('load', onLoad); // eslint-disable-line
|
|
5766
|
-
|
|
5767
5348
|
img = null;
|
|
5768
5349
|
};
|
|
5769
|
-
|
|
5770
5350
|
var onError = function onError() {
|
|
5771
5351
|
var msg = "couldn't load image: " + url;
|
|
5772
5352
|
helper.error(msg);
|
|
5773
5353
|
callback(msg, img);
|
|
5774
5354
|
clearEventHandlers();
|
|
5775
5355
|
};
|
|
5776
|
-
|
|
5777
5356
|
var onLoad = function onLoad() {
|
|
5778
5357
|
callback(null, img);
|
|
5779
5358
|
clearEventHandlers();
|
|
5780
5359
|
};
|
|
5781
|
-
|
|
5782
5360
|
img.addEventListener('error', onError);
|
|
5783
5361
|
img.addEventListener('load', onLoad);
|
|
5784
5362
|
img.src = url;
|
|
@@ -5786,13 +5364,10 @@ function loadImage(url, crossOrigin, callback) {
|
|
|
5786
5364
|
} else if (typeof ImageBitmap !== 'undefined') {
|
|
5787
5365
|
var err;
|
|
5788
5366
|
var bm;
|
|
5789
|
-
|
|
5790
5367
|
var cb = function cb() {
|
|
5791
5368
|
callback(err, bm);
|
|
5792
5369
|
};
|
|
5793
|
-
|
|
5794
5370
|
var options = {};
|
|
5795
|
-
|
|
5796
5371
|
if (crossOrigin) {
|
|
5797
5372
|
options.mode = 'cors'; // TODO: not sure how to translate image.crossOrigin
|
|
5798
5373
|
}
|
|
@@ -5801,7 +5376,6 @@ function loadImage(url, crossOrigin, callback) {
|
|
|
5801
5376
|
if (!response.ok) {
|
|
5802
5377
|
throw response;
|
|
5803
5378
|
}
|
|
5804
|
-
|
|
5805
5379
|
return response.blob();
|
|
5806
5380
|
}).then(function (blob) {
|
|
5807
5381
|
return createImageBitmap(blob, {
|
|
@@ -5821,9 +5395,9 @@ function loadImage(url, crossOrigin, callback) {
|
|
|
5821
5395
|
});
|
|
5822
5396
|
img = null;
|
|
5823
5397
|
}
|
|
5824
|
-
|
|
5825
5398
|
return img;
|
|
5826
5399
|
}
|
|
5400
|
+
|
|
5827
5401
|
/**
|
|
5828
5402
|
* check if object is a TexImageSource
|
|
5829
5403
|
*
|
|
@@ -5831,11 +5405,10 @@ function loadImage(url, crossOrigin, callback) {
|
|
|
5831
5405
|
* @return {boolean} true if object is a TexImageSource
|
|
5832
5406
|
* @private
|
|
5833
5407
|
*/
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
5408
|
function isTexImageSource(obj) {
|
|
5837
5409
|
return typeof ImageBitmap !== 'undefined' && obj instanceof ImageBitmap || typeof ImageData !== 'undefined' && obj instanceof ImageData || typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement;
|
|
5838
5410
|
}
|
|
5411
|
+
|
|
5839
5412
|
/**
|
|
5840
5413
|
* if obj is an TexImageSource then just
|
|
5841
5414
|
* uses it otherwise if obj is a string
|
|
@@ -5847,8 +5420,6 @@ function isTexImageSource(obj) {
|
|
|
5847
5420
|
* if there was an error
|
|
5848
5421
|
* @private
|
|
5849
5422
|
*/
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
5423
|
function loadAndUseImage(obj, crossOrigin, callback) {
|
|
5853
5424
|
if (isTexImageSource(obj)) {
|
|
5854
5425
|
setTimeout(function () {
|
|
@@ -5856,9 +5427,9 @@ function loadAndUseImage(obj, crossOrigin, callback) {
|
|
|
5856
5427
|
});
|
|
5857
5428
|
return obj;
|
|
5858
5429
|
}
|
|
5859
|
-
|
|
5860
5430
|
return loadImage(obj, crossOrigin, callback);
|
|
5861
5431
|
}
|
|
5432
|
+
|
|
5862
5433
|
/**
|
|
5863
5434
|
* Sets a texture to a 1x1 pixel color. If `options.color === false` is nothing happens. If it's not set
|
|
5864
5435
|
* the default texture color is used which can be set by calling `setDefaultTextureColor`.
|
|
@@ -5869,21 +5440,16 @@ function loadAndUseImage(obj, crossOrigin, callback) {
|
|
|
5869
5440
|
* @memberOf module:twgl/textures
|
|
5870
5441
|
* @private
|
|
5871
5442
|
*/
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
5443
|
function setTextureTo1PixelColor(gl, tex, options) {
|
|
5875
5444
|
options = options || defaults.textureOptions;
|
|
5876
5445
|
var target = options.target || TEXTURE_2D;
|
|
5877
5446
|
gl.bindTexture(target, tex);
|
|
5878
|
-
|
|
5879
5447
|
if (options.color === false) {
|
|
5880
5448
|
return;
|
|
5881
|
-
}
|
|
5449
|
+
}
|
|
5450
|
+
// Assume it's a URL
|
|
5882
5451
|
// Put 1x1 pixels in texture. That makes it renderable immediately regardless of filtering.
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
5452
|
var color = make1Pixel(options.color);
|
|
5886
|
-
|
|
5887
5453
|
if (target === TEXTURE_CUBE_MAP) {
|
|
5888
5454
|
for (var ii = 0; ii < 6; ++ii) {
|
|
5889
5455
|
gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
|
|
@@ -5894,6 +5460,7 @@ function setTextureTo1PixelColor(gl, tex, options) {
|
|
|
5894
5460
|
gl.texImage2D(target, 0, RGBA, 1, 1, 0, RGBA, UNSIGNED_BYTE, color);
|
|
5895
5461
|
}
|
|
5896
5462
|
}
|
|
5463
|
+
|
|
5897
5464
|
/**
|
|
5898
5465
|
* The src image(s) used to create a texture.
|
|
5899
5466
|
*
|
|
@@ -5955,13 +5522,11 @@ function setTextureTo1PixelColor(gl, tex, options) {
|
|
|
5955
5522
|
* @return {HTMLImageElement} the image being downloaded.
|
|
5956
5523
|
* @memberOf module:twgl/textures
|
|
5957
5524
|
*/
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
5525
|
function loadTextureFromUrl(gl, tex, options, callback) {
|
|
5961
5526
|
callback = callback || noop;
|
|
5962
5527
|
options = options || defaults.textureOptions;
|
|
5963
|
-
setTextureTo1PixelColor(gl, tex, options);
|
|
5964
|
-
|
|
5528
|
+
setTextureTo1PixelColor(gl, tex, options);
|
|
5529
|
+
// Because it's async we need to copy the options.
|
|
5965
5530
|
options = Object.assign({}, options);
|
|
5966
5531
|
var img = loadAndUseImage(options.src, options.crossOrigin, function (err, img) {
|
|
5967
5532
|
if (err) {
|
|
@@ -5973,6 +5538,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
|
|
|
5973
5538
|
});
|
|
5974
5539
|
return img;
|
|
5975
5540
|
}
|
|
5541
|
+
|
|
5976
5542
|
/**
|
|
5977
5543
|
* Loads a cubemap from 6 urls or TexImageSources as specified in `options.src`. Will set the cubemap to a 1x1 pixel color
|
|
5978
5544
|
* so that it is usable immediately unless `option.color === false`.
|
|
@@ -5984,29 +5550,23 @@ function loadTextureFromUrl(gl, tex, options, callback) {
|
|
|
5984
5550
|
* @memberOf module:twgl/textures
|
|
5985
5551
|
* @private
|
|
5986
5552
|
*/
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
5553
|
function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
5990
5554
|
callback = callback || noop;
|
|
5991
5555
|
var urls = options.src;
|
|
5992
|
-
|
|
5993
5556
|
if (urls.length !== 6) {
|
|
5994
5557
|
throw "there must be 6 urls for a cubemap";
|
|
5995
5558
|
}
|
|
5996
|
-
|
|
5997
5559
|
var level = options.level || 0;
|
|
5998
5560
|
var internalFormat = options.internalFormat || options.format || RGBA;
|
|
5999
5561
|
var formatType = getFormatAndTypeForInternalFormat(internalFormat);
|
|
6000
5562
|
var format = options.format || formatType.format;
|
|
6001
5563
|
var type = options.type || UNSIGNED_BYTE;
|
|
6002
5564
|
var target = options.target || TEXTURE_2D;
|
|
6003
|
-
|
|
6004
5565
|
if (target !== TEXTURE_CUBE_MAP) {
|
|
6005
5566
|
throw "target must be TEXTURE_CUBE_MAP";
|
|
6006
5567
|
}
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
5568
|
+
setTextureTo1PixelColor(gl, tex, options);
|
|
5569
|
+
// Because it's async we need to copy the options.
|
|
6010
5570
|
options = Object.assign({}, options);
|
|
6011
5571
|
var numToLoad = 6;
|
|
6012
5572
|
var errors = [];
|
|
@@ -6016,7 +5576,6 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6016
5576
|
function uploadImg(faceTarget) {
|
|
6017
5577
|
return function (err, img) {
|
|
6018
5578
|
--numToLoad;
|
|
6019
|
-
|
|
6020
5579
|
if (err) {
|
|
6021
5580
|
errors.push(err);
|
|
6022
5581
|
} else {
|
|
@@ -6024,9 +5583,10 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6024
5583
|
errors.push("cubemap face img is not a square: " + img.src);
|
|
6025
5584
|
} else {
|
|
6026
5585
|
setPackState(gl, options);
|
|
6027
|
-
gl.bindTexture(target, tex);
|
|
6028
|
-
// and 5 faces that are 1x1 pixel so size the other faces
|
|
5586
|
+
gl.bindTexture(target, tex);
|
|
6029
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
|
|
6030
5590
|
if (numToLoad === 5) {
|
|
6031
5591
|
// use the default order
|
|
6032
5592
|
getCubeFaceOrder(gl).forEach(function (otherTarget) {
|
|
@@ -6036,23 +5596,21 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6036
5596
|
} else {
|
|
6037
5597
|
gl.texImage2D(faceTarget, level, internalFormat, format, type, img);
|
|
6038
5598
|
}
|
|
6039
|
-
|
|
6040
5599
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
6041
5600
|
gl.generateMipmap(target);
|
|
6042
5601
|
}
|
|
6043
5602
|
}
|
|
6044
5603
|
}
|
|
6045
|
-
|
|
6046
5604
|
if (numToLoad === 0) {
|
|
6047
5605
|
callback(errors.length ? errors : undefined, tex, imgs);
|
|
6048
5606
|
}
|
|
6049
5607
|
};
|
|
6050
5608
|
}
|
|
6051
|
-
|
|
6052
5609
|
imgs = urls.map(function (url, ndx) {
|
|
6053
5610
|
return loadAndUseImage(url, options.crossOrigin, uploadImg(faces[ndx]));
|
|
6054
5611
|
});
|
|
6055
5612
|
}
|
|
5613
|
+
|
|
6056
5614
|
/**
|
|
6057
5615
|
* Loads a 2d array or 3d texture from urls OR TexImageSources as specified in `options.src`.
|
|
6058
5616
|
* Will set the texture to a 1x1 pixel color
|
|
@@ -6073,8 +5631,6 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6073
5631
|
* @memberOf module:twgl/textures
|
|
6074
5632
|
* @private
|
|
6075
5633
|
*/
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
5634
|
function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
6079
5635
|
callback = callback || noop;
|
|
6080
5636
|
var urls = options.src;
|
|
@@ -6083,47 +5639,41 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
|
6083
5639
|
var format = options.format || formatType.format;
|
|
6084
5640
|
var type = options.type || UNSIGNED_BYTE;
|
|
6085
5641
|
var target = options.target || TEXTURE_2D_ARRAY;
|
|
6086
|
-
|
|
6087
5642
|
if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
|
|
6088
5643
|
throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
|
|
6089
5644
|
}
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
5645
|
+
setTextureTo1PixelColor(gl, tex, options);
|
|
5646
|
+
// Because it's async we need to copy the options.
|
|
6093
5647
|
options = Object.assign({}, options);
|
|
6094
5648
|
var numToLoad = urls.length;
|
|
6095
5649
|
var errors = [];
|
|
6096
5650
|
var imgs; // eslint-disable-line
|
|
6097
|
-
|
|
6098
5651
|
var level = options.level || 0;
|
|
6099
5652
|
var width = options.width;
|
|
6100
5653
|
var height = options.height;
|
|
6101
5654
|
var depth = urls.length;
|
|
6102
5655
|
var firstImage = true;
|
|
6103
|
-
|
|
6104
5656
|
function uploadImg(slice) {
|
|
6105
5657
|
return function (err, img) {
|
|
6106
5658
|
--numToLoad;
|
|
6107
|
-
|
|
6108
5659
|
if (err) {
|
|
6109
5660
|
errors.push(err);
|
|
6110
5661
|
} else {
|
|
6111
5662
|
setPackState(gl, options);
|
|
6112
5663
|
gl.bindTexture(target, tex);
|
|
6113
|
-
|
|
6114
5664
|
if (firstImage) {
|
|
6115
5665
|
firstImage = false;
|
|
6116
5666
|
width = options.width || img.width;
|
|
6117
5667
|
height = options.height || img.height;
|
|
6118
|
-
gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
|
|
5668
|
+
gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
|
|
6119
5669
|
|
|
5670
|
+
// put it in every slice otherwise some slices will be 0,0,0,0
|
|
6120
5671
|
for (var s = 0; s < depth; ++s) {
|
|
6121
5672
|
gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);
|
|
6122
5673
|
}
|
|
6123
5674
|
} else {
|
|
6124
5675
|
var src = img;
|
|
6125
5676
|
var ctx;
|
|
6126
|
-
|
|
6127
5677
|
if (img.width !== width || img.height !== height) {
|
|
6128
5678
|
// Size the image to fix
|
|
6129
5679
|
ctx = getShared2DContext();
|
|
@@ -6132,30 +5682,28 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
|
6132
5682
|
ctx.canvas.height = height;
|
|
6133
5683
|
ctx.drawImage(img, 0, 0, width, height);
|
|
6134
5684
|
}
|
|
5685
|
+
gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src);
|
|
6135
5686
|
|
|
6136
|
-
|
|
6137
|
-
|
|
5687
|
+
// free the canvas memory
|
|
6138
5688
|
if (ctx && src === ctx.canvas) {
|
|
6139
5689
|
ctx.canvas.width = 0;
|
|
6140
5690
|
ctx.canvas.height = 0;
|
|
6141
5691
|
}
|
|
6142
5692
|
}
|
|
6143
|
-
|
|
6144
5693
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
6145
5694
|
gl.generateMipmap(target);
|
|
6146
5695
|
}
|
|
6147
5696
|
}
|
|
6148
|
-
|
|
6149
5697
|
if (numToLoad === 0) {
|
|
6150
5698
|
callback(errors.length ? errors : undefined, tex, imgs);
|
|
6151
5699
|
}
|
|
6152
5700
|
};
|
|
6153
5701
|
}
|
|
6154
|
-
|
|
6155
5702
|
imgs = urls.map(function (url, ndx) {
|
|
6156
5703
|
return loadAndUseImage(url, options.crossOrigin, uploadImg(ndx));
|
|
6157
5704
|
});
|
|
6158
5705
|
}
|
|
5706
|
+
|
|
6159
5707
|
/**
|
|
6160
5708
|
* Sets a texture from an array or typed array. If the width or height is not provided will attempt to
|
|
6161
5709
|
* guess the size. See {@link module:twgl.TextureOptions}.
|
|
@@ -6166,8 +5714,6 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
|
6166
5714
|
* This is often the same options you passed in when you created the texture.
|
|
6167
5715
|
* @memberOf module:twgl/textures
|
|
6168
5716
|
*/
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
5717
|
function setTextureFromArray(gl, tex, src, options) {
|
|
6172
5718
|
options = options || defaults.textureOptions;
|
|
6173
5719
|
var target = options.target || TEXTURE_2D;
|
|
@@ -6180,31 +5726,24 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6180
5726
|
var formatType = getFormatAndTypeForInternalFormat(internalFormat);
|
|
6181
5727
|
var format = options.format || formatType.format;
|
|
6182
5728
|
var type = options.type || getTextureTypeForArrayType(gl, src, formatType.type);
|
|
6183
|
-
|
|
6184
5729
|
if (!isArrayBuffer(src)) {
|
|
6185
5730
|
var Type = typedArrays.getTypedArrayTypeForGLType(type);
|
|
6186
5731
|
src = new Type(src);
|
|
6187
5732
|
} else if (src instanceof Uint8ClampedArray) {
|
|
6188
5733
|
src = new Uint8Array(src.buffer);
|
|
6189
5734
|
}
|
|
6190
|
-
|
|
6191
5735
|
var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
|
|
6192
5736
|
var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
|
|
6193
|
-
|
|
6194
5737
|
if (numElements % 1) {
|
|
6195
5738
|
throw "length wrong size for format: " + utils.glEnumToString(gl, format);
|
|
6196
5739
|
}
|
|
6197
|
-
|
|
6198
5740
|
var dimensions;
|
|
6199
|
-
|
|
6200
5741
|
if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
|
|
6201
5742
|
if (!width && !height && !depth) {
|
|
6202
5743
|
var size = Math.cbrt(numElements);
|
|
6203
|
-
|
|
6204
5744
|
if (size % 1 !== 0) {
|
|
6205
5745
|
throw "can't guess cube size of array of numElements: " + numElements;
|
|
6206
5746
|
}
|
|
6207
|
-
|
|
6208
5747
|
width = size;
|
|
6209
5748
|
height = size;
|
|
6210
5749
|
depth = size;
|
|
@@ -6226,11 +5765,9 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6226
5765
|
width = dimensions.width;
|
|
6227
5766
|
height = dimensions.height;
|
|
6228
5767
|
}
|
|
6229
|
-
|
|
6230
5768
|
setSkipStateToDefault(gl);
|
|
6231
5769
|
gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
|
|
6232
5770
|
setPackState(gl, options);
|
|
6233
|
-
|
|
6234
5771
|
if (target === TEXTURE_CUBE_MAP) {
|
|
6235
5772
|
var elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
|
|
6236
5773
|
var faceSize = numElements / 6 * elementsPerElement;
|
|
@@ -6244,7 +5781,6 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6244
5781
|
} else {
|
|
6245
5782
|
gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
|
|
6246
5783
|
}
|
|
6247
|
-
|
|
6248
5784
|
return {
|
|
6249
5785
|
width: width,
|
|
6250
5786
|
height: height,
|
|
@@ -6252,6 +5788,7 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6252
5788
|
type: type
|
|
6253
5789
|
};
|
|
6254
5790
|
}
|
|
5791
|
+
|
|
6255
5792
|
/**
|
|
6256
5793
|
* Sets a texture with no contents of a certain size. In other words calls `gl.texImage2D` with `null`.
|
|
6257
5794
|
* You must set `options.width` and `options.height`.
|
|
@@ -6260,8 +5797,6 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6260
5797
|
* @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
|
|
6261
5798
|
* @memberOf module:twgl/textures
|
|
6262
5799
|
*/
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
5800
|
function setEmptyTexture(gl, tex, options) {
|
|
6266
5801
|
var target = options.target || TEXTURE_2D;
|
|
6267
5802
|
gl.bindTexture(target, tex);
|
|
@@ -6271,7 +5806,6 @@ function setEmptyTexture(gl, tex, options) {
|
|
|
6271
5806
|
var format = options.format || formatType.format;
|
|
6272
5807
|
var type = options.type || formatType.type;
|
|
6273
5808
|
setPackState(gl, options);
|
|
6274
|
-
|
|
6275
5809
|
if (target === TEXTURE_CUBE_MAP) {
|
|
6276
5810
|
for (var ii = 0; ii < 6; ++ii) {
|
|
6277
5811
|
gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
|
|
@@ -6282,6 +5816,7 @@ function setEmptyTexture(gl, tex, options) {
|
|
|
6282
5816
|
gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
|
|
6283
5817
|
}
|
|
6284
5818
|
}
|
|
5819
|
+
|
|
6285
5820
|
/**
|
|
6286
5821
|
* Creates a texture based on the options passed in.
|
|
6287
5822
|
*
|
|
@@ -6294,8 +5829,6 @@ function setEmptyTexture(gl, tex, options) {
|
|
|
6294
5829
|
* @return {WebGLTexture} the created texture.
|
|
6295
5830
|
* @memberOf module:twgl/textures
|
|
6296
5831
|
*/
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
5832
|
function createTexture(gl, options, callback) {
|
|
6300
5833
|
callback = callback || noop;
|
|
6301
5834
|
options = options || defaults.textureOptions;
|
|
@@ -6305,20 +5838,16 @@ function createTexture(gl, options, callback) {
|
|
|
6305
5838
|
var height = options.height || 1;
|
|
6306
5839
|
var internalFormat = options.internalFormat || RGBA;
|
|
6307
5840
|
gl.bindTexture(target, tex);
|
|
6308
|
-
|
|
6309
5841
|
if (target === TEXTURE_CUBE_MAP) {
|
|
6310
5842
|
// this should have been the default for cubemaps :(
|
|
6311
5843
|
gl.texParameteri(target, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
|
|
6312
5844
|
gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
|
|
6313
5845
|
}
|
|
6314
|
-
|
|
6315
5846
|
var src = options.src;
|
|
6316
|
-
|
|
6317
5847
|
if (src) {
|
|
6318
5848
|
if (typeof src === "function") {
|
|
6319
5849
|
src = src(gl, options);
|
|
6320
5850
|
}
|
|
6321
|
-
|
|
6322
5851
|
if (typeof src === "string") {
|
|
6323
5852
|
loadTextureFromUrl(gl, tex, options, callback);
|
|
6324
5853
|
} else if (isArrayBuffer(src) || Array.isArray(src) && (typeof src[0] === 'number' || Array.isArray(src[0]) || isArrayBuffer(src[0]))) {
|
|
@@ -6340,14 +5869,13 @@ function createTexture(gl, options, callback) {
|
|
|
6340
5869
|
} else {
|
|
6341
5870
|
setEmptyTexture(gl, tex, options);
|
|
6342
5871
|
}
|
|
6343
|
-
|
|
6344
5872
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
6345
5873
|
setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
|
|
6346
5874
|
}
|
|
6347
|
-
|
|
6348
5875
|
setTextureParameters(gl, tex, options);
|
|
6349
5876
|
return tex;
|
|
6350
5877
|
}
|
|
5878
|
+
|
|
6351
5879
|
/**
|
|
6352
5880
|
* Resizes a texture based on the options passed in.
|
|
6353
5881
|
*
|
|
@@ -6365,8 +5893,6 @@ function createTexture(gl, options, callback) {
|
|
|
6365
5893
|
* @param {number} [depth] the new depth. If not passed in will use `options.depth`
|
|
6366
5894
|
* @memberOf module:twgl/textures
|
|
6367
5895
|
*/
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
5896
|
function resizeTexture(gl, tex, options, width, height, depth) {
|
|
6371
5897
|
width = width || options.width;
|
|
6372
5898
|
height = height || options.height;
|
|
@@ -6379,7 +5905,6 @@ function resizeTexture(gl, tex, options, width, height, depth) {
|
|
|
6379
5905
|
var format = options.format || formatType.format;
|
|
6380
5906
|
var type;
|
|
6381
5907
|
var src = options.src;
|
|
6382
|
-
|
|
6383
5908
|
if (!src) {
|
|
6384
5909
|
type = options.type || formatType.type;
|
|
6385
5910
|
} else if (isArrayBuffer(src) || Array.isArray(src) && typeof src[0] === 'number') {
|
|
@@ -6387,7 +5912,6 @@ function resizeTexture(gl, tex, options, width, height, depth) {
|
|
|
6387
5912
|
} else {
|
|
6388
5913
|
type = options.type || formatType.type;
|
|
6389
5914
|
}
|
|
6390
|
-
|
|
6391
5915
|
if (target === TEXTURE_CUBE_MAP) {
|
|
6392
5916
|
for (var ii = 0; ii < 6; ++ii) {
|
|
6393
5917
|
gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, width, height, 0, format, type, null);
|
|
@@ -6398,6 +5922,7 @@ function resizeTexture(gl, tex, options, width, height, depth) {
|
|
|
6398
5922
|
gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, null);
|
|
6399
5923
|
}
|
|
6400
5924
|
}
|
|
5925
|
+
|
|
6401
5926
|
/**
|
|
6402
5927
|
* Check if a src is an async request.
|
|
6403
5928
|
* if src is a string we're going to download an image
|
|
@@ -6406,11 +5931,10 @@ function resizeTexture(gl, tex, options, width, height, depth) {
|
|
|
6406
5931
|
* @returns {bool} true if src is async.
|
|
6407
5932
|
* @private
|
|
6408
5933
|
*/
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
5934
|
function isAsyncSrc(src) {
|
|
6412
5935
|
return typeof src === 'string' || Array.isArray(src) && typeof src[0] === 'string';
|
|
6413
5936
|
}
|
|
5937
|
+
|
|
6414
5938
|
/**
|
|
6415
5939
|
* Creates a bunch of textures based on the passed in options.
|
|
6416
5940
|
*
|
|
@@ -6486,15 +6010,12 @@ function isAsyncSrc(src) {
|
|
|
6486
6010
|
* @return {Object.<string,WebGLTexture>} the created textures by name
|
|
6487
6011
|
* @memberOf module:twgl/textures
|
|
6488
6012
|
*/
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
6013
|
function createTextures(gl, textureOptions, callback) {
|
|
6492
6014
|
callback = callback || noop;
|
|
6493
6015
|
var numDownloading = 0;
|
|
6494
6016
|
var errors = [];
|
|
6495
6017
|
var textures = {};
|
|
6496
6018
|
var images = {};
|
|
6497
|
-
|
|
6498
6019
|
function callCallbackIfReady() {
|
|
6499
6020
|
if (numDownloading === 0) {
|
|
6500
6021
|
setTimeout(function () {
|
|
@@ -6502,32 +6023,27 @@ function createTextures(gl, textureOptions, callback) {
|
|
|
6502
6023
|
}, 0);
|
|
6503
6024
|
}
|
|
6504
6025
|
}
|
|
6505
|
-
|
|
6506
6026
|
Object.keys(textureOptions).forEach(function (name) {
|
|
6507
6027
|
var options = textureOptions[name];
|
|
6508
6028
|
var onLoadFn;
|
|
6509
|
-
|
|
6510
6029
|
if (isAsyncSrc(options.src)) {
|
|
6511
6030
|
onLoadFn = function onLoadFn(err, tex, img) {
|
|
6512
6031
|
images[name] = img;
|
|
6513
6032
|
--numDownloading;
|
|
6514
|
-
|
|
6515
6033
|
if (err) {
|
|
6516
6034
|
errors.push(err);
|
|
6517
6035
|
}
|
|
6518
|
-
|
|
6519
6036
|
callCallbackIfReady();
|
|
6520
6037
|
};
|
|
6521
|
-
|
|
6522
6038
|
++numDownloading;
|
|
6523
6039
|
}
|
|
6524
|
-
|
|
6525
6040
|
textures[name] = createTexture(gl, options, onLoadFn);
|
|
6526
|
-
});
|
|
6041
|
+
});
|
|
6042
|
+
|
|
6043
|
+
// queue the callback if there are no images to download.
|
|
6527
6044
|
// We do this because if your code is structured to wait for
|
|
6528
6045
|
// images to download but then you comment out all the async
|
|
6529
6046
|
// images your code would break.
|
|
6530
|
-
|
|
6531
6047
|
callCallbackIfReady();
|
|
6532
6048
|
return textures;
|
|
6533
6049
|
}
|
|
@@ -6545,11 +6061,10 @@ function createTextures(gl, textureOptions, callback) {
|
|
|
6545
6061
|
|
|
6546
6062
|
|
|
6547
6063
|
exports.__esModule = true;
|
|
6548
|
-
|
|
6549
6064
|
var _twgl = __webpack_require__(/*! ./twgl.js */ "./src/twgl.js");
|
|
6550
|
-
|
|
6551
6065
|
Object.keys(_twgl).forEach(function (key) {
|
|
6552
6066
|
if (key === "default" || key === "__esModule") return;
|
|
6067
|
+
if (key in exports && exports[key] === _twgl[key]) return;
|
|
6553
6068
|
exports[key] = _twgl[key];
|
|
6554
6069
|
});
|
|
6555
6070
|
|
|
@@ -6565,8 +6080,7 @@ Object.keys(_twgl).forEach(function (key) {
|
|
|
6565
6080
|
"use strict";
|
|
6566
6081
|
|
|
6567
6082
|
|
|
6568
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
6569
|
-
|
|
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); }
|
|
6570
6084
|
exports.__esModule = true;
|
|
6571
6085
|
var _exportNames = {
|
|
6572
6086
|
addExtensionsToContext: true,
|
|
@@ -6584,90 +6098,80 @@ var _exportNames = {
|
|
|
6584
6098
|
vertexArrays: true
|
|
6585
6099
|
};
|
|
6586
6100
|
exports.addExtensionsToContext = addExtensionsToContext;
|
|
6101
|
+
exports.framebuffers = exports.draw = exports.attributes = void 0;
|
|
6587
6102
|
exports.getContext = getContext;
|
|
6588
6103
|
exports.getWebGLContext = getWebGLContext;
|
|
6104
|
+
exports.programs = void 0;
|
|
6589
6105
|
exports.resizeCanvasToDisplaySize = resizeCanvasToDisplaySize;
|
|
6590
6106
|
exports.setDefaults = setDefaults;
|
|
6591
|
-
exports.vertexArrays = exports.
|
|
6592
|
-
|
|
6107
|
+
exports.vertexArrays = exports.utils = exports.typedarrays = exports.textures = void 0;
|
|
6593
6108
|
var attributes = _interopRequireWildcard(__webpack_require__(/*! ./attributes.js */ "./src/attributes.js"));
|
|
6594
|
-
|
|
6595
6109
|
exports.attributes = attributes;
|
|
6596
6110
|
Object.keys(attributes).forEach(function (key) {
|
|
6597
6111
|
if (key === "default" || key === "__esModule") return;
|
|
6598
6112
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6113
|
+
if (key in exports && exports[key] === attributes[key]) return;
|
|
6599
6114
|
exports[key] = attributes[key];
|
|
6600
6115
|
});
|
|
6601
|
-
|
|
6602
6116
|
var textures = _interopRequireWildcard(__webpack_require__(/*! ./textures.js */ "./src/textures.js"));
|
|
6603
|
-
|
|
6604
6117
|
exports.textures = textures;
|
|
6605
6118
|
Object.keys(textures).forEach(function (key) {
|
|
6606
6119
|
if (key === "default" || key === "__esModule") return;
|
|
6607
6120
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6121
|
+
if (key in exports && exports[key] === textures[key]) return;
|
|
6608
6122
|
exports[key] = textures[key];
|
|
6609
6123
|
});
|
|
6610
|
-
|
|
6611
6124
|
var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
|
|
6612
|
-
|
|
6613
6125
|
var utils = _interopRequireWildcard(__webpack_require__(/*! ./utils.js */ "./src/utils.js"));
|
|
6614
|
-
|
|
6615
6126
|
exports.utils = utils;
|
|
6616
6127
|
Object.keys(utils).forEach(function (key) {
|
|
6617
6128
|
if (key === "default" || key === "__esModule") return;
|
|
6618
6129
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6130
|
+
if (key in exports && exports[key] === utils[key]) return;
|
|
6619
6131
|
exports[key] = utils[key];
|
|
6620
6132
|
});
|
|
6621
|
-
|
|
6622
6133
|
var draw = _interopRequireWildcard(__webpack_require__(/*! ./draw.js */ "./src/draw.js"));
|
|
6623
|
-
|
|
6624
6134
|
exports.draw = draw;
|
|
6625
6135
|
Object.keys(draw).forEach(function (key) {
|
|
6626
6136
|
if (key === "default" || key === "__esModule") return;
|
|
6627
6137
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6138
|
+
if (key in exports && exports[key] === draw[key]) return;
|
|
6628
6139
|
exports[key] = draw[key];
|
|
6629
6140
|
});
|
|
6630
|
-
|
|
6631
6141
|
var framebuffers = _interopRequireWildcard(__webpack_require__(/*! ./framebuffers.js */ "./src/framebuffers.js"));
|
|
6632
|
-
|
|
6633
6142
|
exports.framebuffers = framebuffers;
|
|
6634
6143
|
Object.keys(framebuffers).forEach(function (key) {
|
|
6635
6144
|
if (key === "default" || key === "__esModule") return;
|
|
6636
6145
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6146
|
+
if (key in exports && exports[key] === framebuffers[key]) return;
|
|
6637
6147
|
exports[key] = framebuffers[key];
|
|
6638
6148
|
});
|
|
6639
|
-
|
|
6640
6149
|
var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
|
|
6641
|
-
|
|
6642
6150
|
exports.programs = programs;
|
|
6643
6151
|
Object.keys(programs).forEach(function (key) {
|
|
6644
6152
|
if (key === "default" || key === "__esModule") return;
|
|
6645
6153
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6154
|
+
if (key in exports && exports[key] === programs[key]) return;
|
|
6646
6155
|
exports[key] = programs[key];
|
|
6647
6156
|
});
|
|
6648
|
-
|
|
6649
6157
|
var typedarrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.js */ "./src/typedarrays.js"));
|
|
6650
|
-
|
|
6651
6158
|
exports.typedarrays = typedarrays;
|
|
6652
6159
|
Object.keys(typedarrays).forEach(function (key) {
|
|
6653
6160
|
if (key === "default" || key === "__esModule") return;
|
|
6654
6161
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6162
|
+
if (key in exports && exports[key] === typedarrays[key]) return;
|
|
6655
6163
|
exports[key] = typedarrays[key];
|
|
6656
6164
|
});
|
|
6657
|
-
|
|
6658
6165
|
var vertexArrays = _interopRequireWildcard(__webpack_require__(/*! ./vertex-arrays.js */ "./src/vertex-arrays.js"));
|
|
6659
|
-
|
|
6660
6166
|
exports.vertexArrays = vertexArrays;
|
|
6661
6167
|
Object.keys(vertexArrays).forEach(function (key) {
|
|
6662
6168
|
if (key === "default" || key === "__esModule") return;
|
|
6663
6169
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
6170
|
+
if (key in exports && exports[key] === vertexArrays[key]) return;
|
|
6664
6171
|
exports[key] = vertexArrays[key];
|
|
6665
6172
|
});
|
|
6666
|
-
|
|
6667
|
-
function
|
|
6668
|
-
|
|
6669
|
-
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; }
|
|
6670
|
-
|
|
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; }
|
|
6671
6175
|
/*
|
|
6672
6176
|
* Copyright 2019 Gregg Tavares
|
|
6673
6177
|
*
|
|
@@ -6717,13 +6221,13 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
6717
6221
|
* @borrows module:twgl/textures.resizeTexture as resizeTexture
|
|
6718
6222
|
* @borrows module:twgl/textures.createTextures as createTextures
|
|
6719
6223
|
*/
|
|
6720
|
-
// make sure we don't see a global gl
|
|
6721
|
-
var gl = undefined;
|
|
6722
|
-
/* eslint-disable-line */
|
|
6723
6224
|
|
|
6225
|
+
// make sure we don't see a global gl
|
|
6226
|
+
var gl = undefined; /* eslint-disable-line */
|
|
6724
6227
|
var defaults = {
|
|
6725
6228
|
addExtensionsToContext: true
|
|
6726
6229
|
};
|
|
6230
|
+
|
|
6727
6231
|
/**
|
|
6728
6232
|
* Various default settings for twgl.
|
|
6729
6233
|
*
|
|
@@ -6795,36 +6299,30 @@ var defaults = {
|
|
|
6795
6299
|
* @param {module:twgl.Defaults} newDefaults The default settings.
|
|
6796
6300
|
* @memberOf module:twgl
|
|
6797
6301
|
*/
|
|
6798
|
-
|
|
6799
6302
|
function setDefaults(newDefaults) {
|
|
6800
6303
|
helper.copyExistingProperties(newDefaults, defaults);
|
|
6801
6304
|
attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line
|
|
6802
|
-
|
|
6803
6305
|
textures.setTextureDefaults_(newDefaults); // eslint-disable-line
|
|
6804
6306
|
}
|
|
6805
6307
|
|
|
6806
6308
|
var prefixRE = /^(.*?)_/;
|
|
6807
|
-
|
|
6808
6309
|
function addExtensionToContext(gl, extensionName) {
|
|
6809
6310
|
utils.glEnumToString(gl, 0);
|
|
6810
6311
|
var ext = gl.getExtension(extensionName);
|
|
6811
|
-
|
|
6812
6312
|
if (ext) {
|
|
6813
6313
|
var enums = {};
|
|
6814
6314
|
var fnSuffix = prefixRE.exec(extensionName)[1];
|
|
6815
6315
|
var enumSuffix = '_' + fnSuffix;
|
|
6816
|
-
|
|
6817
6316
|
for (var key in ext) {
|
|
6818
6317
|
var value = ext[key];
|
|
6819
6318
|
var isFunc = typeof value === 'function';
|
|
6820
6319
|
var suffix = isFunc ? fnSuffix : enumSuffix;
|
|
6821
|
-
var name = key;
|
|
6320
|
+
var name = key;
|
|
6321
|
+
// examples of where this is not true are WEBGL_compressed_texture_s3tc
|
|
6822
6322
|
// and WEBGL_compressed_texture_pvrtc
|
|
6823
|
-
|
|
6824
6323
|
if (key.endsWith(suffix)) {
|
|
6825
6324
|
name = key.substring(0, key.length - suffix.length);
|
|
6826
6325
|
}
|
|
6827
|
-
|
|
6828
6326
|
if (gl[name] !== undefined) {
|
|
6829
6327
|
if (!isFunc && gl[name] !== value) {
|
|
6830
6328
|
helper.warn(name, gl[name], value, key);
|
|
@@ -6841,17 +6339,16 @@ function addExtensionToContext(gl, extensionName) {
|
|
|
6841
6339
|
enums[name] = value;
|
|
6842
6340
|
}
|
|
6843
6341
|
}
|
|
6844
|
-
}
|
|
6845
|
-
|
|
6846
|
-
|
|
6342
|
+
}
|
|
6343
|
+
// pass the modified enums to glEnumToString
|
|
6847
6344
|
enums.constructor = {
|
|
6848
6345
|
name: ext.constructor.name
|
|
6849
6346
|
};
|
|
6850
6347
|
utils.glEnumToString(enums, 0);
|
|
6851
6348
|
}
|
|
6852
|
-
|
|
6853
6349
|
return ext;
|
|
6854
6350
|
}
|
|
6351
|
+
|
|
6855
6352
|
/*
|
|
6856
6353
|
* If you're wondering why the code doesn't just iterate
|
|
6857
6354
|
* over all extensions using `gl.getExtensions` is that it's possible
|
|
@@ -6860,9 +6357,8 @@ function addExtensionToContext(gl, extensionName) {
|
|
|
6860
6357
|
* list.
|
|
6861
6358
|
*
|
|
6862
6359
|
*/
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
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
|
+
|
|
6866
6362
|
/**
|
|
6867
6363
|
* Attempts to enable all of the following extensions
|
|
6868
6364
|
* and add their functions and constants to the
|
|
@@ -6911,12 +6407,12 @@ var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_co
|
|
|
6911
6407
|
* @param {WebGLRenderingContext} gl A WebGLRenderingContext
|
|
6912
6408
|
* @memberOf module:twgl
|
|
6913
6409
|
*/
|
|
6914
|
-
|
|
6915
6410
|
function addExtensionsToContext(gl) {
|
|
6916
6411
|
for (var ii = 0; ii < supportedExtensions.length; ++ii) {
|
|
6917
6412
|
addExtensionToContext(gl, supportedExtensions[ii]);
|
|
6918
6413
|
}
|
|
6919
6414
|
}
|
|
6415
|
+
|
|
6920
6416
|
/**
|
|
6921
6417
|
* Creates a webgl context.
|
|
6922
6418
|
* @param {HTMLCanvasElement} canvas The canvas tag to get
|
|
@@ -6925,26 +6421,21 @@ function addExtensionsToContext(gl) {
|
|
|
6925
6421
|
* @return {WebGLRenderingContext} The created context.
|
|
6926
6422
|
* @private
|
|
6927
6423
|
*/
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
6424
|
function create3DContext(canvas, opt_attribs) {
|
|
6931
6425
|
var names = ["webgl", "experimental-webgl"];
|
|
6932
6426
|
var context = null;
|
|
6933
|
-
|
|
6934
6427
|
for (var ii = 0; ii < names.length; ++ii) {
|
|
6935
6428
|
context = canvas.getContext(names[ii], opt_attribs);
|
|
6936
|
-
|
|
6937
6429
|
if (context) {
|
|
6938
6430
|
if (defaults.addExtensionsToContext) {
|
|
6939
6431
|
addExtensionsToContext(context);
|
|
6940
6432
|
}
|
|
6941
|
-
|
|
6942
6433
|
break;
|
|
6943
6434
|
}
|
|
6944
6435
|
}
|
|
6945
|
-
|
|
6946
6436
|
return context;
|
|
6947
6437
|
}
|
|
6438
|
+
|
|
6948
6439
|
/**
|
|
6949
6440
|
* Gets a WebGL1 context.
|
|
6950
6441
|
*
|
|
@@ -6959,12 +6450,11 @@ function create3DContext(canvas, opt_attribs) {
|
|
|
6959
6450
|
* @deprecated
|
|
6960
6451
|
* @private
|
|
6961
6452
|
*/
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
6453
|
function getWebGLContext(canvas, opt_attribs) {
|
|
6965
6454
|
var gl = create3DContext(canvas, opt_attribs);
|
|
6966
6455
|
return gl;
|
|
6967
6456
|
}
|
|
6457
|
+
|
|
6968
6458
|
/**
|
|
6969
6459
|
* Creates a webgl context.
|
|
6970
6460
|
*
|
|
@@ -6979,26 +6469,21 @@ function getWebGLContext(canvas, opt_attribs) {
|
|
|
6979
6469
|
* created.
|
|
6980
6470
|
* @return {WebGLRenderingContext} The created context.
|
|
6981
6471
|
*/
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
6472
|
function createContext(canvas, opt_attribs) {
|
|
6985
6473
|
var names = ["webgl2", "webgl", "experimental-webgl"];
|
|
6986
6474
|
var context = null;
|
|
6987
|
-
|
|
6988
6475
|
for (var ii = 0; ii < names.length; ++ii) {
|
|
6989
6476
|
context = canvas.getContext(names[ii], opt_attribs);
|
|
6990
|
-
|
|
6991
6477
|
if (context) {
|
|
6992
6478
|
if (defaults.addExtensionsToContext) {
|
|
6993
6479
|
addExtensionsToContext(context);
|
|
6994
6480
|
}
|
|
6995
|
-
|
|
6996
6481
|
break;
|
|
6997
6482
|
}
|
|
6998
6483
|
}
|
|
6999
|
-
|
|
7000
6484
|
return context;
|
|
7001
6485
|
}
|
|
6486
|
+
|
|
7002
6487
|
/**
|
|
7003
6488
|
* Gets a WebGL context. Will create a WebGL2 context if possible.
|
|
7004
6489
|
*
|
|
@@ -7017,12 +6502,11 @@ function createContext(canvas, opt_attribs) {
|
|
|
7017
6502
|
* @return {WebGLRenderingContext} The created context.
|
|
7018
6503
|
* @memberOf module:twgl
|
|
7019
6504
|
*/
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
6505
|
function getContext(canvas, opt_attribs) {
|
|
7023
6506
|
var gl = createContext(canvas, opt_attribs);
|
|
7024
6507
|
return gl;
|
|
7025
6508
|
}
|
|
6509
|
+
|
|
7026
6510
|
/**
|
|
7027
6511
|
* Resize a canvas to match the size it's displayed.
|
|
7028
6512
|
* @param {HTMLCanvasElement} canvas The canvas to resize.
|
|
@@ -7030,20 +6514,16 @@ function getContext(canvas, opt_attribs) {
|
|
|
7030
6514
|
* @return {boolean} true if the canvas was resized.
|
|
7031
6515
|
* @memberOf module:twgl
|
|
7032
6516
|
*/
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
6517
|
function resizeCanvasToDisplaySize(canvas, multiplier) {
|
|
7036
6518
|
multiplier = multiplier || 1;
|
|
7037
6519
|
multiplier = Math.max(0, multiplier);
|
|
7038
6520
|
var width = canvas.clientWidth * multiplier | 0;
|
|
7039
6521
|
var height = canvas.clientHeight * multiplier | 0;
|
|
7040
|
-
|
|
7041
6522
|
if (canvas.width !== width || canvas.height !== height) {
|
|
7042
6523
|
canvas.width = width;
|
|
7043
6524
|
canvas.height = height;
|
|
7044
6525
|
return true;
|
|
7045
6526
|
}
|
|
7046
|
-
|
|
7047
6527
|
return false;
|
|
7048
6528
|
}
|
|
7049
6529
|
|
|
@@ -7064,7 +6544,6 @@ exports.getGLTypeForTypedArray = getGLTypeForTypedArray;
|
|
|
7064
6544
|
exports.getGLTypeForTypedArrayType = getGLTypeForTypedArrayType;
|
|
7065
6545
|
exports.getTypedArrayTypeForGLType = getTypedArrayTypeForGLType;
|
|
7066
6546
|
exports.isArrayBuffer = void 0;
|
|
7067
|
-
|
|
7068
6547
|
/*
|
|
7069
6548
|
* Copyright 2019 Gregg Tavares
|
|
7070
6549
|
*
|
|
@@ -7101,12 +6580,11 @@ exports.isArrayBuffer = void 0;
|
|
|
7101
6580
|
*
|
|
7102
6581
|
* @module twgl/typedArray
|
|
7103
6582
|
*/
|
|
6583
|
+
|
|
7104
6584
|
// make sure we don't see a global gl
|
|
7105
|
-
var gl = undefined;
|
|
7106
|
-
/* eslint-disable-line */
|
|
6585
|
+
var gl = undefined; /* eslint-disable-line */
|
|
7107
6586
|
|
|
7108
6587
|
/* DataType */
|
|
7109
|
-
|
|
7110
6588
|
var BYTE = 0x1400;
|
|
7111
6589
|
var UNSIGNED_BYTE = 0x1401;
|
|
7112
6590
|
var SHORT = 0x1402;
|
|
@@ -7143,6 +6621,7 @@ var glTypeToTypedArray = {};
|
|
|
7143
6621
|
tt[FLOAT_32_UNSIGNED_INT_24_8_REV] = Uint32Array;
|
|
7144
6622
|
tt[UNSIGNED_INT_24_8] = Uint32Array;
|
|
7145
6623
|
}
|
|
6624
|
+
|
|
7146
6625
|
/**
|
|
7147
6626
|
* Get the GL type for a typedArray
|
|
7148
6627
|
* @param {ArrayBufferView} typedArray a typedArray
|
|
@@ -7150,50 +6629,34 @@ var glTypeToTypedArray = {};
|
|
|
7150
6629
|
* be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned
|
|
7151
6630
|
* @memberOf module:twgl/typedArray
|
|
7152
6631
|
*/
|
|
7153
|
-
|
|
7154
6632
|
function getGLTypeForTypedArray(typedArray) {
|
|
7155
6633
|
if (typedArray instanceof Int8Array) {
|
|
7156
6634
|
return BYTE;
|
|
7157
6635
|
} // eslint-disable-line
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
6636
|
if (typedArray instanceof Uint8Array) {
|
|
7161
6637
|
return UNSIGNED_BYTE;
|
|
7162
6638
|
} // eslint-disable-line
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
6639
|
if (typedArray instanceof Uint8ClampedArray) {
|
|
7166
6640
|
return UNSIGNED_BYTE;
|
|
7167
6641
|
} // eslint-disable-line
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
6642
|
if (typedArray instanceof Int16Array) {
|
|
7171
6643
|
return SHORT;
|
|
7172
6644
|
} // eslint-disable-line
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
6645
|
if (typedArray instanceof Uint16Array) {
|
|
7176
6646
|
return UNSIGNED_SHORT;
|
|
7177
6647
|
} // eslint-disable-line
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
6648
|
if (typedArray instanceof Int32Array) {
|
|
7181
6649
|
return INT;
|
|
7182
6650
|
} // eslint-disable-line
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
6651
|
if (typedArray instanceof Uint32Array) {
|
|
7186
6652
|
return UNSIGNED_INT;
|
|
7187
6653
|
} // eslint-disable-line
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
6654
|
if (typedArray instanceof Float32Array) {
|
|
7191
6655
|
return FLOAT;
|
|
7192
6656
|
} // eslint-disable-line
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
6657
|
throw new Error('unsupported typed array type');
|
|
7196
6658
|
}
|
|
6659
|
+
|
|
7197
6660
|
/**
|
|
7198
6661
|
* Get the GL type for a typedArray type
|
|
7199
6662
|
* @param {ArrayBufferView} typedArrayType a typedArray constructor
|
|
@@ -7201,69 +6664,47 @@ function getGLTypeForTypedArray(typedArray) {
|
|
|
7201
6664
|
* be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned
|
|
7202
6665
|
* @memberOf module:twgl/typedArray
|
|
7203
6666
|
*/
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
6667
|
function getGLTypeForTypedArrayType(typedArrayType) {
|
|
7207
6668
|
if (typedArrayType === Int8Array) {
|
|
7208
6669
|
return BYTE;
|
|
7209
6670
|
} // eslint-disable-line
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
6671
|
if (typedArrayType === Uint8Array) {
|
|
7213
6672
|
return UNSIGNED_BYTE;
|
|
7214
6673
|
} // eslint-disable-line
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
6674
|
if (typedArrayType === Uint8ClampedArray) {
|
|
7218
6675
|
return UNSIGNED_BYTE;
|
|
7219
6676
|
} // eslint-disable-line
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
6677
|
if (typedArrayType === Int16Array) {
|
|
7223
6678
|
return SHORT;
|
|
7224
6679
|
} // eslint-disable-line
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
6680
|
if (typedArrayType === Uint16Array) {
|
|
7228
6681
|
return UNSIGNED_SHORT;
|
|
7229
6682
|
} // eslint-disable-line
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
6683
|
if (typedArrayType === Int32Array) {
|
|
7233
6684
|
return INT;
|
|
7234
6685
|
} // eslint-disable-line
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
6686
|
if (typedArrayType === Uint32Array) {
|
|
7238
6687
|
return UNSIGNED_INT;
|
|
7239
6688
|
} // eslint-disable-line
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
6689
|
if (typedArrayType === Float32Array) {
|
|
7243
6690
|
return FLOAT;
|
|
7244
6691
|
} // eslint-disable-line
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
6692
|
throw new Error('unsupported typed array type');
|
|
7248
6693
|
}
|
|
6694
|
+
|
|
7249
6695
|
/**
|
|
7250
6696
|
* Get the typed array constructor for a given GL type
|
|
7251
6697
|
* @param {number} type the GL type. (eg: `gl.UNSIGNED_INT`)
|
|
7252
6698
|
* @return {function} the constructor for a the corresponding typed array. (eg. `Uint32Array`).
|
|
7253
6699
|
* @memberOf module:twgl/typedArray
|
|
7254
6700
|
*/
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
6701
|
function getTypedArrayTypeForGLType(type) {
|
|
7258
6702
|
var CTOR = glTypeToTypedArray[type];
|
|
7259
|
-
|
|
7260
6703
|
if (!CTOR) {
|
|
7261
6704
|
throw new Error('unknown gl type');
|
|
7262
6705
|
}
|
|
7263
|
-
|
|
7264
6706
|
return CTOR;
|
|
7265
6707
|
}
|
|
7266
|
-
|
|
7267
6708
|
var isArrayBuffer = typeof SharedArrayBuffer !== 'undefined' ? function isArrayBufferOrSharedArrayBuffer(a) {
|
|
7268
6709
|
return a && a.buffer && (a.buffer instanceof ArrayBuffer || a.buffer instanceof SharedArrayBuffer);
|
|
7269
6710
|
} : function isArrayBuffer(a) {
|
|
@@ -7284,10 +6725,9 @@ exports.isArrayBuffer = isArrayBuffer;
|
|
|
7284
6725
|
|
|
7285
6726
|
|
|
7286
6727
|
exports.__esModule = true;
|
|
6728
|
+
exports.glEnumToString = void 0;
|
|
7287
6729
|
exports.isWebGL1 = isWebGL1;
|
|
7288
6730
|
exports.isWebGL2 = isWebGL2;
|
|
7289
|
-
exports.glEnumToString = void 0;
|
|
7290
|
-
|
|
7291
6731
|
/*
|
|
7292
6732
|
* Copyright 2019 Gregg Tavares
|
|
7293
6733
|
*
|
|
@@ -7333,14 +6773,13 @@ function isWebGL2(gl) {
|
|
|
7333
6773
|
// return gl instanceof WebGL2RenderingContext;
|
|
7334
6774
|
return !!gl.texStorage2D;
|
|
7335
6775
|
}
|
|
6776
|
+
|
|
7336
6777
|
/**
|
|
7337
6778
|
* Check if context is WebGL 1.0
|
|
7338
6779
|
* @param {WebGLRenderingContext} gl A WebGLRenderingContext
|
|
7339
6780
|
* @return {bool} true if it's WebGL 1.0
|
|
7340
6781
|
* @memberOf module:twgl
|
|
7341
6782
|
*/
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
6783
|
function isWebGL1(gl) {
|
|
7345
6784
|
// This is the correct check but it's slow
|
|
7346
6785
|
// const version = getVersionAsNumber(gl);
|
|
@@ -7349,6 +6788,7 @@ function isWebGL1(gl) {
|
|
|
7349
6788
|
// return gl instanceof WebGLRenderingContext;
|
|
7350
6789
|
return !gl.texStorage2D;
|
|
7351
6790
|
}
|
|
6791
|
+
|
|
7352
6792
|
/**
|
|
7353
6793
|
* Gets a string for WebGL enum
|
|
7354
6794
|
*
|
|
@@ -7397,15 +6837,11 @@ function isWebGL1(gl) {
|
|
|
7397
6837
|
* @memberOf module:twgl
|
|
7398
6838
|
* @function glEnumToString
|
|
7399
6839
|
*/
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
6840
|
var glEnumToString = function () {
|
|
7403
6841
|
var haveEnumsForType = {};
|
|
7404
6842
|
var enums = {};
|
|
7405
|
-
|
|
7406
6843
|
function addEnums(gl) {
|
|
7407
6844
|
var type = gl.constructor.name;
|
|
7408
|
-
|
|
7409
6845
|
if (!haveEnumsForType[type]) {
|
|
7410
6846
|
for (var key in gl) {
|
|
7411
6847
|
if (typeof gl[key] === 'number') {
|
|
@@ -7413,17 +6849,14 @@ var glEnumToString = function () {
|
|
|
7413
6849
|
enums[gl[key]] = existing ? "".concat(existing, " | ").concat(key) : key;
|
|
7414
6850
|
}
|
|
7415
6851
|
}
|
|
7416
|
-
|
|
7417
6852
|
haveEnumsForType[type] = true;
|
|
7418
6853
|
}
|
|
7419
6854
|
}
|
|
7420
|
-
|
|
7421
6855
|
return function glEnumToString(gl, value) {
|
|
7422
6856
|
addEnums(gl);
|
|
7423
6857
|
return enums[value] || (typeof value === 'number' ? "0x".concat(value.toString(16)) : value);
|
|
7424
6858
|
};
|
|
7425
6859
|
}();
|
|
7426
|
-
|
|
7427
6860
|
exports.glEnumToString = glEnumToString;
|
|
7428
6861
|
|
|
7429
6862
|
/***/ }),
|
|
@@ -7438,19 +6871,14 @@ exports.glEnumToString = glEnumToString;
|
|
|
7438
6871
|
"use strict";
|
|
7439
6872
|
|
|
7440
6873
|
|
|
7441
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
7442
|
-
|
|
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); }
|
|
7443
6875
|
exports.__esModule = true;
|
|
7444
|
-
exports.createVertexArrayInfo = createVertexArrayInfo;
|
|
7445
6876
|
exports.createVAOAndSetAttributes = createVAOAndSetAttributes;
|
|
7446
6877
|
exports.createVAOFromBufferInfo = createVAOFromBufferInfo;
|
|
7447
|
-
|
|
6878
|
+
exports.createVertexArrayInfo = createVertexArrayInfo;
|
|
7448
6879
|
var programs = _interopRequireWildcard(__webpack_require__(/*! ./programs.js */ "./src/programs.js"));
|
|
7449
|
-
|
|
7450
|
-
function
|
|
7451
|
-
|
|
7452
|
-
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; }
|
|
7453
|
-
|
|
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; }
|
|
7454
6882
|
/*
|
|
7455
6883
|
* Copyright 2019 Gregg Tavares
|
|
7456
6884
|
*
|
|
@@ -7487,7 +6915,9 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
7487
6915
|
*
|
|
7488
6916
|
* @module twgl/vertexArrays
|
|
7489
6917
|
*/
|
|
6918
|
+
|
|
7490
6919
|
var ELEMENT_ARRAY_BUFFER = 0x8893;
|
|
6920
|
+
|
|
7491
6921
|
/**
|
|
7492
6922
|
* @typedef {Object} VertexArrayInfo
|
|
7493
6923
|
* @property {number} numElements The number of elements to pass to `gl.drawArrays` or `gl.drawElements`.
|
|
@@ -7532,15 +6962,12 @@ var ELEMENT_ARRAY_BUFFER = 0x8893;
|
|
|
7532
6962
|
*
|
|
7533
6963
|
* @memberOf module:twgl/vertexArrays
|
|
7534
6964
|
*/
|
|
7535
|
-
|
|
7536
6965
|
function createVertexArrayInfo(gl, programInfos, bufferInfo) {
|
|
7537
6966
|
var vao = gl.createVertexArray();
|
|
7538
6967
|
gl.bindVertexArray(vao);
|
|
7539
|
-
|
|
7540
6968
|
if (!programInfos.length) {
|
|
7541
6969
|
programInfos = [programInfos];
|
|
7542
6970
|
}
|
|
7543
|
-
|
|
7544
6971
|
programInfos.forEach(function (programInfo) {
|
|
7545
6972
|
programs.setBuffersAndAttributes(gl, programInfo, bufferInfo);
|
|
7546
6973
|
});
|
|
@@ -7551,6 +6978,7 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
|
|
|
7551
6978
|
vertexArrayObject: vao
|
|
7552
6979
|
};
|
|
7553
6980
|
}
|
|
6981
|
+
|
|
7554
6982
|
/**
|
|
7555
6983
|
* Creates a vertex array object and then sets the attributes on it
|
|
7556
6984
|
*
|
|
@@ -7563,22 +6991,19 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
|
|
|
7563
6991
|
*
|
|
7564
6992
|
* @memberOf module:twgl/vertexArrays
|
|
7565
6993
|
*/
|
|
7566
|
-
|
|
7567
|
-
|
|
7568
6994
|
function createVAOAndSetAttributes(gl, setters, attribs, indices) {
|
|
7569
6995
|
var vao = gl.createVertexArray();
|
|
7570
6996
|
gl.bindVertexArray(vao);
|
|
7571
6997
|
programs.setAttributes(setters, attribs);
|
|
7572
|
-
|
|
7573
6998
|
if (indices) {
|
|
7574
6999
|
gl.bindBuffer(ELEMENT_ARRAY_BUFFER, indices);
|
|
7575
|
-
}
|
|
7000
|
+
}
|
|
7001
|
+
// We unbind this because otherwise any change to ELEMENT_ARRAY_BUFFER
|
|
7576
7002
|
// like when creating buffers for other stuff will mess up this VAO's binding
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
7003
|
gl.bindVertexArray(null);
|
|
7580
7004
|
return vao;
|
|
7581
7005
|
}
|
|
7006
|
+
|
|
7582
7007
|
/**
|
|
7583
7008
|
* Creates a vertex array object and then sets the attributes
|
|
7584
7009
|
* on it
|
|
@@ -7593,8 +7018,6 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
|
|
|
7593
7018
|
*
|
|
7594
7019
|
* @memberOf module:twgl/vertexArrays
|
|
7595
7020
|
*/
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
7021
|
function createVAOFromBufferInfo(gl, programInfo, bufferInfo) {
|
|
7599
7022
|
return createVAOAndSetAttributes(gl, programInfo.attribSetters || programInfo, bufferInfo.attribs, bufferInfo.indices);
|
|
7600
7023
|
}
|