twgl.js 4.22.1 → 4.23.2
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/README.md +1 -1
- package/dist/4.x/twgl-full.d.ts +5 -10
- package/dist/4.x/twgl-full.js +358 -60
- package/dist/4.x/twgl-full.module.js +271 -65
- package/dist/4.x/twgl.d.ts +4 -10
- package/dist/4.x/twgl.js +347 -60
- package/package.json +1 -1
package/dist/4.x/twgl-full.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @license twgl.js 4.
|
|
2
|
+
* @license twgl.js 4.23.2 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
|
*/
|
|
@@ -651,6 +651,11 @@ function getNumElementsFromNonIndexedArrays(arrays) {
|
|
|
651
651
|
|
|
652
652
|
var array = arrays[key];
|
|
653
653
|
var length = getArray(array).length;
|
|
654
|
+
|
|
655
|
+
if (length === undefined) {
|
|
656
|
+
return 1; // There's no arrays
|
|
657
|
+
}
|
|
658
|
+
|
|
654
659
|
var numComponents = getNumComponents(array, key);
|
|
655
660
|
var numElements = length / numComponents;
|
|
656
661
|
|
|
@@ -684,6 +689,11 @@ function getNumElementsFromAttributes(gl, attribs) {
|
|
|
684
689
|
}
|
|
685
690
|
|
|
686
691
|
var attrib = attribs[key];
|
|
692
|
+
|
|
693
|
+
if (!attrib.buffer) {
|
|
694
|
+
return 1; // There's no buffer
|
|
695
|
+
}
|
|
696
|
+
|
|
687
697
|
gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
|
|
688
698
|
var numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
|
|
689
699
|
gl.bindBuffer(ARRAY_BUFFER, null);
|
|
@@ -1593,6 +1603,7 @@ exports.__esModule = true;
|
|
|
1593
1603
|
exports.axisRotate = axisRotate;
|
|
1594
1604
|
exports.axisRotation = axisRotation;
|
|
1595
1605
|
exports.copy = copy;
|
|
1606
|
+
exports.create = create;
|
|
1596
1607
|
exports.frustum = frustum;
|
|
1597
1608
|
exports.getAxis = getAxis;
|
|
1598
1609
|
exports.getTranslation = getTranslation;
|
|
@@ -1723,6 +1734,16 @@ function negate(m, dst) {
|
|
|
1723
1734
|
dst[15] = -m[15];
|
|
1724
1735
|
return dst;
|
|
1725
1736
|
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Creates a matrix.
|
|
1739
|
+
* @return {module:twgl/m4.Mat4} A new matrix.
|
|
1740
|
+
* @memberOf module:twgl/m4
|
|
1741
|
+
*/
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
function create() {
|
|
1745
|
+
return new MatType(16).fill(0);
|
|
1746
|
+
}
|
|
1726
1747
|
/**
|
|
1727
1748
|
* Copies a matrix.
|
|
1728
1749
|
* @param {module:twgl/m4.Mat4} m The matrix.
|
|
@@ -4670,9 +4691,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
|
|
|
4670
4691
|
exports.__esModule = true;
|
|
4671
4692
|
exports.createAttributeSetters = createAttributeSetters;
|
|
4672
4693
|
exports.createProgram = createProgram;
|
|
4694
|
+
exports.createProgramAsync = createProgramAsync;
|
|
4673
4695
|
exports.createProgramFromScripts = createProgramFromScripts;
|
|
4674
4696
|
exports.createProgramFromSources = createProgramFromSources;
|
|
4675
4697
|
exports.createProgramInfo = createProgramInfo;
|
|
4698
|
+
exports.createProgramInfoAsync = createProgramInfoAsync;
|
|
4676
4699
|
exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
|
|
4677
4700
|
exports.createUniformSetters = createUniformSetters;
|
|
4678
4701
|
exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
|
|
@@ -4697,6 +4720,10 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
|
|
|
4697
4720
|
|
|
4698
4721
|
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; }
|
|
4699
4722
|
|
|
4723
|
+
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); } }
|
|
4724
|
+
|
|
4725
|
+
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); }); }; }
|
|
4726
|
+
|
|
4700
4727
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4701
4728
|
|
|
4702
4729
|
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."); }
|
|
@@ -4797,6 +4824,7 @@ var TEXTURE_2D_ARRAY = 0x8C1A;
|
|
|
4797
4824
|
var typeMap = {};
|
|
4798
4825
|
/**
|
|
4799
4826
|
* Returns the corresponding bind point for a given sampler type
|
|
4827
|
+
* @private
|
|
4800
4828
|
*/
|
|
4801
4829
|
|
|
4802
4830
|
function getBindPointForSamplerType(gl, type) {
|
|
@@ -5493,56 +5521,118 @@ function addLineNumbersWithError(src) {
|
|
|
5493
5521
|
* @memberOf module:twgl
|
|
5494
5522
|
*/
|
|
5495
5523
|
|
|
5524
|
+
/**
|
|
5525
|
+
* Program Callback
|
|
5526
|
+
* @callback ProgramCallback
|
|
5527
|
+
* @param {string} [err] error message, falsy if no error
|
|
5528
|
+
* @param {WebGLProgram|module:twgl.ProgramInfo} [result] the program or programInfo
|
|
5529
|
+
*/
|
|
5530
|
+
|
|
5496
5531
|
|
|
5497
5532
|
var spaceRE = /^[ \t]*\n/;
|
|
5533
|
+
/**
|
|
5534
|
+
* Remove the first end of line because WebGL 2.0 requires
|
|
5535
|
+
* #version 300 es
|
|
5536
|
+
* as the first line. No whitespace allowed before that line
|
|
5537
|
+
* so
|
|
5538
|
+
*
|
|
5539
|
+
* <script>
|
|
5540
|
+
* #version 300 es
|
|
5541
|
+
* </script>
|
|
5542
|
+
*
|
|
5543
|
+
* Has one line before it which is invalid according to GLSL ES 3.00
|
|
5544
|
+
*
|
|
5545
|
+
* @param {string} shaderSource The source of the shader
|
|
5546
|
+
* @returns {{shaderSource: string, lineOffset: number}}
|
|
5547
|
+
* @private
|
|
5548
|
+
*/
|
|
5549
|
+
|
|
5550
|
+
function prepShaderSource(shaderSource) {
|
|
5551
|
+
var lineOffset = 0;
|
|
5552
|
+
|
|
5553
|
+
if (spaceRE.test(shaderSource)) {
|
|
5554
|
+
lineOffset = 1;
|
|
5555
|
+
shaderSource = shaderSource.replace(spaceRE, '');
|
|
5556
|
+
}
|
|
5557
|
+
|
|
5558
|
+
return {
|
|
5559
|
+
lineOffset: lineOffset,
|
|
5560
|
+
shaderSource: shaderSource
|
|
5561
|
+
};
|
|
5562
|
+
}
|
|
5563
|
+
/**
|
|
5564
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
5565
|
+
* @param {string} msg
|
|
5566
|
+
* @return null
|
|
5567
|
+
* @private
|
|
5568
|
+
*/
|
|
5569
|
+
|
|
5570
|
+
|
|
5571
|
+
function reportError(progOptions, msg) {
|
|
5572
|
+
progOptions.errorCallback(msg);
|
|
5573
|
+
|
|
5574
|
+
if (progOptions.callback) {
|
|
5575
|
+
setTimeout(function () {
|
|
5576
|
+
progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
|
|
5577
|
+
});
|
|
5578
|
+
}
|
|
5579
|
+
|
|
5580
|
+
return null;
|
|
5581
|
+
}
|
|
5498
5582
|
/**
|
|
5499
5583
|
* Loads a shader.
|
|
5500
5584
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5501
5585
|
* @param {string} shaderSource The shader source.
|
|
5502
5586
|
* @param {number} shaderType The type of shader.
|
|
5503
|
-
* @param {module:twgl.
|
|
5587
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
5504
5588
|
* @return {WebGLShader} The created shader.
|
|
5505
5589
|
* @private
|
|
5506
5590
|
*/
|
|
5507
5591
|
|
|
5508
|
-
function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
|
|
5509
|
-
var errFn = opt_errorCallback || error; // Create the shader object
|
|
5510
5592
|
|
|
5511
|
-
|
|
5512
|
-
//
|
|
5513
|
-
|
|
5514
|
-
// so
|
|
5515
|
-
//
|
|
5516
|
-
// <script>
|
|
5517
|
-
// #version 300 es
|
|
5518
|
-
// </script>
|
|
5519
|
-
//
|
|
5520
|
-
// Has one line before it which is invalid according to GLSL ES 3.00
|
|
5521
|
-
//
|
|
5593
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
5594
|
+
// Create the shader object
|
|
5595
|
+
var shader = gl.createShader(shaderType); // Load the shader source
|
|
5522
5596
|
|
|
5523
|
-
|
|
5597
|
+
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
|
|
5524
5598
|
|
|
5525
|
-
|
|
5526
|
-
lineOffset = 1;
|
|
5527
|
-
shaderSource = shaderSource.replace(spaceRE, '');
|
|
5528
|
-
} // Load the shader source
|
|
5599
|
+
gl.compileShader(shader);
|
|
5529
5600
|
|
|
5601
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
5602
|
+
gl.deleteShader(shader);
|
|
5603
|
+
return null;
|
|
5604
|
+
}
|
|
5530
5605
|
|
|
5531
|
-
|
|
5606
|
+
return shader;
|
|
5607
|
+
}
|
|
5608
|
+
/**
|
|
5609
|
+
* Check Shader status
|
|
5610
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5611
|
+
* @param {number} shaderType The shader type
|
|
5612
|
+
* @param {WebGLShader} shader The shader
|
|
5613
|
+
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
5614
|
+
* @return {bool} true if shader is ok.
|
|
5615
|
+
* @private
|
|
5616
|
+
*/
|
|
5532
5617
|
|
|
5533
|
-
|
|
5618
|
+
|
|
5619
|
+
function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
5620
|
+
errFn = errFn || error; // Check the compile status
|
|
5534
5621
|
|
|
5535
5622
|
var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
|
|
5536
5623
|
|
|
5537
5624
|
if (!compiled) {
|
|
5538
5625
|
// Something went wrong during compilation; get the error
|
|
5539
5626
|
var lastError = gl.getShaderInfoLog(shader);
|
|
5627
|
+
|
|
5628
|
+
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
5629
|
+
lineOffset = _prepShaderSource.lineOffset,
|
|
5630
|
+
shaderSource = _prepShaderSource.shaderSource;
|
|
5631
|
+
|
|
5540
5632
|
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
|
|
5541
|
-
gl.deleteShader(shader);
|
|
5542
|
-
return null;
|
|
5543
5633
|
}
|
|
5544
5634
|
|
|
5545
|
-
return
|
|
5635
|
+
return compiled;
|
|
5546
5636
|
}
|
|
5547
5637
|
/**
|
|
5548
5638
|
* @typedef {Object} ProgramOptions
|
|
@@ -5552,6 +5642,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
|
|
|
5552
5642
|
* a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
|
|
5553
5643
|
* you can pass an array of names.
|
|
5554
5644
|
* @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
|
|
5645
|
+
* @property {ProgramCallback} [callback] callback for async program compilation.
|
|
5555
5646
|
* @memberOf module:twgl
|
|
5556
5647
|
*/
|
|
5557
5648
|
|
|
@@ -5569,6 +5660,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
|
|
|
5569
5660
|
function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
5570
5661
|
var transformFeedbackVaryings;
|
|
5571
5662
|
var transformFeedbackMode;
|
|
5663
|
+
var callback;
|
|
5572
5664
|
|
|
5573
5665
|
if (typeof opt_locations === 'function') {
|
|
5574
5666
|
opt_errorCallback = opt_locations;
|
|
@@ -5581,7 +5673,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
5581
5673
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
5582
5674
|
// If we have an errorCallback we can just return this object
|
|
5583
5675
|
// Otherwise we need to construct one with default errorCallback
|
|
5584
|
-
if (opt_attribs.errorCallback) {
|
|
5676
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
5585
5677
|
return opt_attribs;
|
|
5586
5678
|
}
|
|
5587
5679
|
|
|
@@ -5590,12 +5682,26 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
5590
5682
|
opt_attribs = opt.attribLocations;
|
|
5591
5683
|
transformFeedbackVaryings = opt.transformFeedbackVaryings;
|
|
5592
5684
|
transformFeedbackMode = opt.transformFeedbackMode;
|
|
5685
|
+
callback = opt.callback;
|
|
5593
5686
|
}
|
|
5594
5687
|
|
|
5688
|
+
var _errorCallback = opt_errorCallback || error;
|
|
5689
|
+
|
|
5690
|
+
var errors = [];
|
|
5595
5691
|
var options = {
|
|
5596
|
-
errorCallback:
|
|
5692
|
+
errorCallback: function errorCallback(msg) {
|
|
5693
|
+
errors.push(msg);
|
|
5694
|
+
|
|
5695
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
5696
|
+
args[_key - 1] = arguments[_key];
|
|
5697
|
+
}
|
|
5698
|
+
|
|
5699
|
+
_errorCallback.apply(void 0, [msg].concat(args));
|
|
5700
|
+
},
|
|
5597
5701
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
5598
|
-
transformFeedbackMode: transformFeedbackMode
|
|
5702
|
+
transformFeedbackMode: transformFeedbackMode,
|
|
5703
|
+
callback: callback,
|
|
5704
|
+
errors: errors
|
|
5599
5705
|
};
|
|
5600
5706
|
|
|
5601
5707
|
if (opt_attribs) {
|
|
@@ -5632,9 +5738,16 @@ function deleteShaders(gl, shaders) {
|
|
|
5632
5738
|
gl.deleteShader(shader);
|
|
5633
5739
|
});
|
|
5634
5740
|
}
|
|
5741
|
+
|
|
5742
|
+
var wait = function wait() {
|
|
5743
|
+
var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
5744
|
+
return new Promise(function (resolve) {
|
|
5745
|
+
return setTimeout(resolve, ms);
|
|
5746
|
+
});
|
|
5747
|
+
};
|
|
5635
5748
|
/**
|
|
5636
5749
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
5637
|
-
* program
|
|
5750
|
+
* program.
|
|
5638
5751
|
*
|
|
5639
5752
|
* NOTE: There are 4 signatures for this function
|
|
5640
5753
|
*
|
|
@@ -5649,12 +5762,14 @@ function deleteShaders(gl, shaders) {
|
|
|
5649
5762
|
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
5650
5763
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5651
5764
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
5652
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
5765
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
5653
5766
|
* @memberOf module:twgl/programs
|
|
5654
5767
|
*/
|
|
5655
5768
|
|
|
5656
5769
|
|
|
5657
5770
|
function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
|
|
5771
|
+
// This code is really convoluted, because it may or may not be async
|
|
5772
|
+
// Maybe it would be better to have a separate function
|
|
5658
5773
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
5659
5774
|
var realShaders = [];
|
|
5660
5775
|
var newShaders = [];
|
|
@@ -5671,7 +5786,7 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5671
5786
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
5672
5787
|
}
|
|
5673
5788
|
|
|
5674
|
-
shader = loadShader(gl, src, type, progOptions
|
|
5789
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
5675
5790
|
newShaders.push(shader);
|
|
5676
5791
|
}
|
|
5677
5792
|
|
|
@@ -5681,9 +5796,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5681
5796
|
}
|
|
5682
5797
|
|
|
5683
5798
|
if (realShaders.length !== shaders.length) {
|
|
5684
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
5685
5799
|
deleteShaders(gl, newShaders);
|
|
5686
|
-
return
|
|
5800
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
5687
5801
|
}
|
|
5688
5802
|
|
|
5689
5803
|
var program = gl.createProgram();
|
|
@@ -5711,24 +5825,186 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5711
5825
|
gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
|
|
5712
5826
|
}
|
|
5713
5827
|
|
|
5714
|
-
gl.linkProgram(program);
|
|
5828
|
+
gl.linkProgram(program);
|
|
5829
|
+
|
|
5830
|
+
if (progOptions.callback) {
|
|
5831
|
+
checkForProgramLinkCompletionAsync(gl, program, progOptions);
|
|
5832
|
+
return null;
|
|
5833
|
+
} else {
|
|
5834
|
+
if (!checkProgramStatus(gl, program, progOptions.errorCallback)) {
|
|
5835
|
+
gl.deleteProgram(program);
|
|
5836
|
+
deleteShaders(gl, newShaders);
|
|
5837
|
+
return null;
|
|
5838
|
+
}
|
|
5839
|
+
|
|
5840
|
+
return program;
|
|
5841
|
+
}
|
|
5842
|
+
}
|
|
5843
|
+
/**
|
|
5844
|
+
* Same as createProgram but returns a promise
|
|
5845
|
+
*
|
|
5846
|
+
* NOTE: There are 4 signatures for this function
|
|
5847
|
+
*
|
|
5848
|
+
* twgl.createProgramAsync(gl, [vs, fs], options);
|
|
5849
|
+
* twgl.createProgramAsync(gl, [vs, fs], opt_errFunc);
|
|
5850
|
+
* twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_errFunc);
|
|
5851
|
+
* twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
|
|
5852
|
+
*
|
|
5853
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5854
|
+
* @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
|
|
5855
|
+
* @param {module:twgl.ProgramOptions|string[]|module:twgl.ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
|
|
5856
|
+
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
5857
|
+
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5858
|
+
* on error. If you want something else pass an callback. It's passed an error message.
|
|
5859
|
+
* @return {Promise<WebGLProgram>} The created program
|
|
5860
|
+
* @memberOf module:twgl/programs
|
|
5861
|
+
*/
|
|
5862
|
+
|
|
5863
|
+
|
|
5864
|
+
function createProgramAsync(gl, shaders) {
|
|
5865
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
5866
|
+
args[_key2 - 2] = arguments[_key2];
|
|
5867
|
+
}
|
|
5868
|
+
|
|
5869
|
+
return new Promise(function (resolve, reject) {
|
|
5870
|
+
var programOptions = getProgramOptions.apply(void 0, args);
|
|
5871
|
+
|
|
5872
|
+
programOptions.callback = function (err, program) {
|
|
5873
|
+
if (err) {
|
|
5874
|
+
reject(err);
|
|
5875
|
+
} else {
|
|
5876
|
+
resolve(program);
|
|
5877
|
+
}
|
|
5878
|
+
};
|
|
5879
|
+
|
|
5880
|
+
createProgram(gl, shaders, programOptions);
|
|
5881
|
+
});
|
|
5882
|
+
}
|
|
5883
|
+
/**
|
|
5884
|
+
* Same as createProgramInfo but returns a promise
|
|
5885
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext
|
|
5886
|
+
* to use.
|
|
5887
|
+
* @param {string[]} shaderSources Array of sources for the
|
|
5888
|
+
* shaders or ids. The first is assumed to be the vertex shader,
|
|
5889
|
+
* the second the fragment shader.
|
|
5890
|
+
* @param {module:twgl.ProgramOptions|string[]|module:twgl.ErrorCallback} [opt_attribs] Options for the program or an array of attribs names or an error callback. Locations will be assigned by index if not passed in
|
|
5891
|
+
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
5892
|
+
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5893
|
+
* on error. If you want something else pass an callback. It's passed an error message.
|
|
5894
|
+
* @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
|
|
5895
|
+
* @memberOf module:twgl/programs
|
|
5896
|
+
*/
|
|
5897
|
+
|
|
5898
|
+
|
|
5899
|
+
function createProgramInfoAsync(gl, shaders) {
|
|
5900
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
5901
|
+
args[_key3 - 2] = arguments[_key3];
|
|
5902
|
+
}
|
|
5903
|
+
|
|
5904
|
+
return new Promise(function (resolve, reject) {
|
|
5905
|
+
var programOptions = getProgramOptions.apply(void 0, args);
|
|
5906
|
+
|
|
5907
|
+
programOptions.callback = function (err, programInfo) {
|
|
5908
|
+
if (err) {
|
|
5909
|
+
reject(err);
|
|
5910
|
+
} else {
|
|
5911
|
+
resolve(programInfo);
|
|
5912
|
+
}
|
|
5913
|
+
};
|
|
5914
|
+
|
|
5915
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
5916
|
+
});
|
|
5917
|
+
}
|
|
5918
|
+
/**
|
|
5919
|
+
* Asynchronously wait for program to link.
|
|
5920
|
+
* Note: if 'KHR_parallel_shader_compile' extension does not
|
|
5921
|
+
* exist then compilation will not be truly async.
|
|
5922
|
+
* @param {WebGLRenderingContext} gl The context
|
|
5923
|
+
* @param {WebGLProgram} program The program
|
|
5924
|
+
* @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
|
|
5925
|
+
* @private
|
|
5926
|
+
*/
|
|
5927
|
+
|
|
5928
|
+
|
|
5929
|
+
function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
5930
|
+
return _checkForProgramLinkCompletionAsync.apply(this, arguments);
|
|
5931
|
+
}
|
|
5932
|
+
/**
|
|
5933
|
+
* Check a program's link status
|
|
5934
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5935
|
+
* @param {WebGLProgram} program Program to check
|
|
5936
|
+
* @param {ErrorCallback} [errFn] func for errors
|
|
5937
|
+
* @return {bool} true if program is ok
|
|
5938
|
+
* @private
|
|
5939
|
+
*/
|
|
5940
|
+
|
|
5941
|
+
|
|
5942
|
+
function _checkForProgramLinkCompletionAsync() {
|
|
5943
|
+
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
|
|
5944
|
+
var ext, checkFn, waitTime, success, err, errFn;
|
|
5945
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
5946
|
+
while (1) {
|
|
5947
|
+
switch (_context.prev = _context.next) {
|
|
5948
|
+
case 0:
|
|
5949
|
+
ext = gl.getExtension('KHR_parallel_shader_compile');
|
|
5950
|
+
checkFn = ext ? function (gl, program) {
|
|
5951
|
+
return gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR);
|
|
5952
|
+
} : function () {
|
|
5953
|
+
return true;
|
|
5954
|
+
};
|
|
5955
|
+
waitTime = 0;
|
|
5956
|
+
|
|
5957
|
+
case 3:
|
|
5958
|
+
_context.next = 5;
|
|
5959
|
+
return wait(waitTime);
|
|
5960
|
+
|
|
5961
|
+
case 5:
|
|
5962
|
+
// must wait at least once
|
|
5963
|
+
waitTime = 1000 / 60;
|
|
5964
|
+
|
|
5965
|
+
case 6:
|
|
5966
|
+
if (!checkFn(gl, program)) {
|
|
5967
|
+
_context.next = 3;
|
|
5968
|
+
break;
|
|
5969
|
+
}
|
|
5970
|
+
|
|
5971
|
+
case 7:
|
|
5972
|
+
success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
5973
|
+
err = success ? undefined : progOptions.errors.join('\n');
|
|
5974
|
+
|
|
5975
|
+
if (!success) {
|
|
5976
|
+
errFn = progOptions.errorCallback || error;
|
|
5977
|
+
errFn(err);
|
|
5978
|
+
gl.deleteProgram(program); // TODO: delete shaders, but only shaders that were created newly for this
|
|
5979
|
+
// program
|
|
5980
|
+
|
|
5981
|
+
program = null;
|
|
5982
|
+
}
|
|
5983
|
+
|
|
5984
|
+
progOptions.callback(err, program);
|
|
5985
|
+
|
|
5986
|
+
case 11:
|
|
5987
|
+
case "end":
|
|
5988
|
+
return _context.stop();
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
}, _callee);
|
|
5992
|
+
}));
|
|
5993
|
+
return _checkForProgramLinkCompletionAsync.apply(this, arguments);
|
|
5994
|
+
}
|
|
5995
|
+
|
|
5996
|
+
function checkProgramStatus(gl, program, errFn) {
|
|
5997
|
+
errFn = errFn || error; // Check the link status
|
|
5715
5998
|
|
|
5716
5999
|
var linked = gl.getProgramParameter(program, LINK_STATUS);
|
|
5717
6000
|
|
|
5718
6001
|
if (!linked) {
|
|
5719
6002
|
// something went wrong with the link
|
|
5720
6003
|
var lastError = gl.getProgramInfoLog(program);
|
|
5721
|
-
|
|
5722
|
-
var src = addLineNumbersWithError(gl.getShaderSource(shader), '', 0);
|
|
5723
|
-
var type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
5724
|
-
return "".concat(utils.glEnumToString(gl, type), "\n").concat(src, "}");
|
|
5725
|
-
}).join('\n'), "\nError in program linking: ").concat(lastError));
|
|
5726
|
-
gl.deleteProgram(program);
|
|
5727
|
-
deleteShaders(gl, newShaders);
|
|
5728
|
-
return null;
|
|
6004
|
+
errFn("Error in program linking: ".concat(lastError));
|
|
5729
6005
|
}
|
|
5730
6006
|
|
|
5731
|
-
return
|
|
6007
|
+
return linked;
|
|
5732
6008
|
}
|
|
5733
6009
|
/**
|
|
5734
6010
|
* Loads a shader from a script tag.
|
|
@@ -5736,28 +6012,28 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5736
6012
|
* @param {string} scriptId The id of the script tag.
|
|
5737
6013
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
5738
6014
|
* be derived from the type of the script tag.
|
|
5739
|
-
* @param {module:twgl.
|
|
6015
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
5740
6016
|
* @return {WebGLShader?} The created shader or null if error.
|
|
5741
6017
|
* @private
|
|
5742
6018
|
*/
|
|
5743
6019
|
|
|
5744
6020
|
|
|
5745
|
-
function createShaderFromScript(gl, scriptId, opt_shaderType,
|
|
6021
|
+
function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
5746
6022
|
var shaderSource = "";
|
|
5747
6023
|
var shaderScript = getElementById(scriptId);
|
|
5748
6024
|
|
|
5749
6025
|
if (!shaderScript) {
|
|
5750
|
-
|
|
6026
|
+
return reportError(progOptions, "unknown script element: ".concat(scriptId));
|
|
5751
6027
|
}
|
|
5752
6028
|
|
|
5753
6029
|
shaderSource = shaderScript.text;
|
|
5754
6030
|
var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
5755
6031
|
|
|
5756
6032
|
if (!shaderType) {
|
|
5757
|
-
|
|
6033
|
+
return reportError(progOptions, 'unknown shader type');
|
|
5758
6034
|
}
|
|
5759
6035
|
|
|
5760
|
-
return loadShader(gl, shaderSource, shaderType,
|
|
6036
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
5761
6037
|
}
|
|
5762
6038
|
/**
|
|
5763
6039
|
* Creates a program from 2 script tags.
|
|
@@ -5778,7 +6054,7 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback)
|
|
|
5778
6054
|
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
5779
6055
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5780
6056
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
5781
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
6057
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
5782
6058
|
* @memberOf module:twgl/programs
|
|
5783
6059
|
*/
|
|
5784
6060
|
|
|
@@ -5788,7 +6064,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
5788
6064
|
var shaders = [];
|
|
5789
6065
|
|
|
5790
6066
|
for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
5791
|
-
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
6067
|
+
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
5792
6068
|
|
|
5793
6069
|
if (!shader) {
|
|
5794
6070
|
return null;
|
|
@@ -5818,7 +6094,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
5818
6094
|
* @param {number[]} [opt_locations|module:twgl.ErrorCallback] The locations for the. A parallel array to opt_attribs letting you assign locations or an error callback.
|
|
5819
6095
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5820
6096
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
5821
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
6097
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
5822
6098
|
* @memberOf module:twgl/programs
|
|
5823
6099
|
*/
|
|
5824
6100
|
|
|
@@ -5828,9 +6104,9 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
|
|
|
5828
6104
|
var shaders = [];
|
|
5829
6105
|
|
|
5830
6106
|
for (var ii = 0; ii < shaderSources.length; ++ii) {
|
|
5831
|
-
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions
|
|
6107
|
+
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
5832
6108
|
|
|
5833
|
-
if (!shader) {
|
|
6109
|
+
if (!progOptions.callback && !shader) {
|
|
5834
6110
|
return null;
|
|
5835
6111
|
}
|
|
5836
6112
|
|
|
@@ -6798,6 +7074,7 @@ function createAttributeSetters(gl, program) {
|
|
|
6798
7074
|
* @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
|
|
6799
7075
|
* @memberOf module:twgl/programs
|
|
6800
7076
|
* @deprecated use {@link module:twgl.setBuffersAndAttributes}
|
|
7077
|
+
* @private
|
|
6801
7078
|
*/
|
|
6802
7079
|
|
|
6803
7080
|
|
|
@@ -6905,6 +7182,8 @@ function createProgramInfoFromProgram(gl, program) {
|
|
|
6905
7182
|
|
|
6906
7183
|
return programInfo;
|
|
6907
7184
|
}
|
|
7185
|
+
|
|
7186
|
+
var notIdRE = /\s|{|}|;/;
|
|
6908
7187
|
/**
|
|
6909
7188
|
* Creates a ProgramInfo from 2 sources.
|
|
6910
7189
|
*
|
|
@@ -6936,18 +7215,18 @@ function createProgramInfoFromProgram(gl, program) {
|
|
|
6936
7215
|
* @memberOf module:twgl/programs
|
|
6937
7216
|
*/
|
|
6938
7217
|
|
|
6939
|
-
|
|
6940
7218
|
function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
|
|
6941
7219
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
6942
|
-
var
|
|
7220
|
+
var errors = [];
|
|
6943
7221
|
shaderSources = shaderSources.map(function (source) {
|
|
6944
7222
|
// Lets assume if there is no \n it's an id
|
|
6945
|
-
if (
|
|
7223
|
+
if (!notIdRE.test(source)) {
|
|
6946
7224
|
var script = getElementById(source);
|
|
6947
7225
|
|
|
6948
7226
|
if (!script) {
|
|
6949
|
-
|
|
6950
|
-
|
|
7227
|
+
var err = "no element with id: ".concat(source);
|
|
7228
|
+
progOptions.errorCallback(err);
|
|
7229
|
+
errors.push(err);
|
|
6951
7230
|
} else {
|
|
6952
7231
|
source = script.text;
|
|
6953
7232
|
}
|
|
@@ -6956,8 +7235,22 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
6956
7235
|
return source;
|
|
6957
7236
|
});
|
|
6958
7237
|
|
|
6959
|
-
if (
|
|
6960
|
-
return
|
|
7238
|
+
if (errors.length) {
|
|
7239
|
+
return reportError(progOptions, '');
|
|
7240
|
+
}
|
|
7241
|
+
|
|
7242
|
+
var origCallback = progOptions.callback;
|
|
7243
|
+
|
|
7244
|
+
if (origCallback) {
|
|
7245
|
+
progOptions.callback = function (err, program) {
|
|
7246
|
+
var programInfo;
|
|
7247
|
+
|
|
7248
|
+
if (!err) {
|
|
7249
|
+
programInfo = createProgramInfoFromProgram(gl, program);
|
|
7250
|
+
}
|
|
7251
|
+
|
|
7252
|
+
origCallback(err, programInfo);
|
|
7253
|
+
};
|
|
6961
7254
|
}
|
|
6962
7255
|
|
|
6963
7256
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
@@ -8618,6 +8911,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
|
|
|
8618
8911
|
* @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
|
|
8619
8912
|
* This is often the same options you passed in when you created the texture.
|
|
8620
8913
|
* @memberOf module:twgl/textures
|
|
8914
|
+
* @private
|
|
8621
8915
|
*/
|
|
8622
8916
|
|
|
8623
8917
|
|
|
@@ -8732,6 +9026,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
|
|
|
8732
9026
|
* @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
8733
9027
|
* be non null if there was an error.
|
|
8734
9028
|
* @memberOf module:twgl/textures
|
|
9029
|
+
* @private
|
|
8735
9030
|
*/
|
|
8736
9031
|
|
|
8737
9032
|
|
|
@@ -8820,6 +9115,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
8820
9115
|
* @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
8821
9116
|
* be non null if there was an error.
|
|
8822
9117
|
* @memberOf module:twgl/textures
|
|
9118
|
+
* @private
|
|
8823
9119
|
*/
|
|
8824
9120
|
|
|
8825
9121
|
|
|
@@ -9729,6 +10025,8 @@ function create3DContext(canvas, opt_attribs) {
|
|
|
9729
10025
|
* @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
|
|
9730
10026
|
* @return {WebGLRenderingContext} The created context.
|
|
9731
10027
|
* @memberOf module:twgl
|
|
10028
|
+
* @deprecated
|
|
10029
|
+
* @private
|
|
9732
10030
|
*/
|
|
9733
10031
|
|
|
9734
10032
|
|