twgl.js 4.22.1 → 4.23.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/4.x/twgl-full.d.ts +9 -0
- package/dist/4.x/twgl-full.js +306 -42
- package/dist/4.x/twgl-full.module.js +224 -44
- package/dist/4.x/twgl.d.ts +8 -0
- package/dist/4.x/twgl.js +295 -42
- package/package.json +1 -1
package/dist/4.x/twgl.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @license twgl.js 4.
|
|
2
|
+
* @license twgl.js 4.23.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
|
*/
|
|
@@ -1592,9 +1592,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
|
|
|
1592
1592
|
exports.__esModule = true;
|
|
1593
1593
|
exports.createAttributeSetters = createAttributeSetters;
|
|
1594
1594
|
exports.createProgram = createProgram;
|
|
1595
|
+
exports.createProgramAsync = createProgramAsync;
|
|
1595
1596
|
exports.createProgramFromScripts = createProgramFromScripts;
|
|
1596
1597
|
exports.createProgramFromSources = createProgramFromSources;
|
|
1597
1598
|
exports.createProgramInfo = createProgramInfo;
|
|
1599
|
+
exports.createProgramInfoAsync = createProgramInfoAsync;
|
|
1598
1600
|
exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
|
|
1599
1601
|
exports.createUniformSetters = createUniformSetters;
|
|
1600
1602
|
exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
|
|
@@ -1619,6 +1621,10 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
|
|
|
1619
1621
|
|
|
1620
1622
|
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; }
|
|
1621
1623
|
|
|
1624
|
+
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); } }
|
|
1625
|
+
|
|
1626
|
+
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); }); }; }
|
|
1627
|
+
|
|
1622
1628
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
1623
1629
|
|
|
1624
1630
|
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."); }
|
|
@@ -2415,56 +2421,91 @@ function addLineNumbersWithError(src) {
|
|
|
2415
2421
|
* @memberOf module:twgl
|
|
2416
2422
|
*/
|
|
2417
2423
|
|
|
2424
|
+
/**
|
|
2425
|
+
* Program Callback
|
|
2426
|
+
* @callback ProgramCallback
|
|
2427
|
+
* @param {string} [err] error message, falsy if no error
|
|
2428
|
+
* @param {WebGLProgram|module:twgl.ProgramInfo} [result] the program or programInfo
|
|
2429
|
+
*/
|
|
2430
|
+
|
|
2418
2431
|
|
|
2419
2432
|
var spaceRE = /^[ \t]*\n/;
|
|
2433
|
+
/**
|
|
2434
|
+
* Remove the first end of line because WebGL 2.0 requires
|
|
2435
|
+
* #version 300 es
|
|
2436
|
+
* as the first line. No whitespace allowed before that line
|
|
2437
|
+
* so
|
|
2438
|
+
*
|
|
2439
|
+
* <script>
|
|
2440
|
+
* #version 300 es
|
|
2441
|
+
* </script>
|
|
2442
|
+
*
|
|
2443
|
+
* Has one line before it which is invalid according to GLSL ES 3.00
|
|
2444
|
+
*
|
|
2445
|
+
* @param {string} shaderSource The source of the shader
|
|
2446
|
+
* @returns {{shaderSource: string, lineOffset: number}}
|
|
2447
|
+
*/
|
|
2448
|
+
|
|
2449
|
+
function prepShaderSource(shaderSource) {
|
|
2450
|
+
var lineOffset = 0;
|
|
2451
|
+
|
|
2452
|
+
if (spaceRE.test(shaderSource)) {
|
|
2453
|
+
lineOffset = 1;
|
|
2454
|
+
shaderSource = shaderSource.replace(spaceRE, '');
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
return {
|
|
2458
|
+
lineOffset: lineOffset,
|
|
2459
|
+
shaderSource: shaderSource
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2420
2462
|
/**
|
|
2421
2463
|
* Loads a shader.
|
|
2422
2464
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2423
2465
|
* @param {string} shaderSource The shader source.
|
|
2424
2466
|
* @param {number} shaderType The type of shader.
|
|
2425
|
-
* @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
|
|
2426
2467
|
* @return {WebGLShader} The created shader.
|
|
2427
2468
|
* @private
|
|
2428
2469
|
*/
|
|
2429
2470
|
|
|
2430
|
-
function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
|
|
2431
|
-
var errFn = opt_errorCallback || error; // Create the shader object
|
|
2432
2471
|
|
|
2433
|
-
|
|
2434
|
-
//
|
|
2435
|
-
|
|
2436
|
-
// so
|
|
2437
|
-
//
|
|
2438
|
-
// <script>
|
|
2439
|
-
// #version 300 es
|
|
2440
|
-
// </script>
|
|
2441
|
-
//
|
|
2442
|
-
// Has one line before it which is invalid according to GLSL ES 3.00
|
|
2443
|
-
//
|
|
2472
|
+
function loadShader(gl, shaderSource, shaderType) {
|
|
2473
|
+
// Create the shader object
|
|
2474
|
+
var shader = gl.createShader(shaderType); // Load the shader source
|
|
2444
2475
|
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
if (spaceRE.test(shaderSource)) {
|
|
2448
|
-
lineOffset = 1;
|
|
2449
|
-
shaderSource = shaderSource.replace(spaceRE, '');
|
|
2450
|
-
} // Load the shader source
|
|
2476
|
+
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
|
|
2451
2477
|
|
|
2478
|
+
gl.compileShader(shader);
|
|
2479
|
+
return shader;
|
|
2480
|
+
}
|
|
2481
|
+
/**
|
|
2482
|
+
* Check Shader status
|
|
2483
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2484
|
+
* @param {WebGLShader} shader The shader
|
|
2485
|
+
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
2486
|
+
* @returns {bool} true if shader is ok.
|
|
2487
|
+
*/
|
|
2452
2488
|
|
|
2453
|
-
gl.shaderSource(shader, shaderSource); // Compile the shader
|
|
2454
2489
|
|
|
2455
|
-
|
|
2490
|
+
function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
2491
|
+
errFn = errFn || error; // Check the compile status
|
|
2456
2492
|
|
|
2457
2493
|
var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
|
|
2458
2494
|
|
|
2459
2495
|
if (!compiled) {
|
|
2460
2496
|
// Something went wrong during compilation; get the error
|
|
2461
2497
|
var lastError = gl.getShaderInfoLog(shader);
|
|
2462
|
-
|
|
2463
|
-
gl.
|
|
2464
|
-
|
|
2498
|
+
|
|
2499
|
+
var _shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
2500
|
+
|
|
2501
|
+
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
2502
|
+
lineOffset = _prepShaderSource.lineOffset,
|
|
2503
|
+
shaderSource = _prepShaderSource.shaderSource;
|
|
2504
|
+
|
|
2505
|
+
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, _shaderType), ": ").concat(lastError));
|
|
2465
2506
|
}
|
|
2466
2507
|
|
|
2467
|
-
return
|
|
2508
|
+
return compiled;
|
|
2468
2509
|
}
|
|
2469
2510
|
/**
|
|
2470
2511
|
* @typedef {Object} ProgramOptions
|
|
@@ -2474,6 +2515,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
|
|
|
2474
2515
|
* a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
|
|
2475
2516
|
* you can pass an array of names.
|
|
2476
2517
|
* @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
|
|
2518
|
+
* @property {ProgramCallback} [callback] callback for async program compilation.
|
|
2477
2519
|
* @memberOf module:twgl
|
|
2478
2520
|
*/
|
|
2479
2521
|
|
|
@@ -2491,6 +2533,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
|
|
|
2491
2533
|
function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
2492
2534
|
var transformFeedbackVaryings;
|
|
2493
2535
|
var transformFeedbackMode;
|
|
2536
|
+
var callback;
|
|
2494
2537
|
|
|
2495
2538
|
if (typeof opt_locations === 'function') {
|
|
2496
2539
|
opt_errorCallback = opt_locations;
|
|
@@ -2512,12 +2555,14 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2512
2555
|
opt_attribs = opt.attribLocations;
|
|
2513
2556
|
transformFeedbackVaryings = opt.transformFeedbackVaryings;
|
|
2514
2557
|
transformFeedbackMode = opt.transformFeedbackMode;
|
|
2558
|
+
callback = opt.callback;
|
|
2515
2559
|
}
|
|
2516
2560
|
|
|
2517
2561
|
var options = {
|
|
2518
2562
|
errorCallback: opt_errorCallback || error,
|
|
2519
2563
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
2520
|
-
transformFeedbackMode: transformFeedbackMode
|
|
2564
|
+
transformFeedbackMode: transformFeedbackMode,
|
|
2565
|
+
callback: callback
|
|
2521
2566
|
};
|
|
2522
2567
|
|
|
2523
2568
|
if (opt_attribs) {
|
|
@@ -2554,6 +2599,13 @@ function deleteShaders(gl, shaders) {
|
|
|
2554
2599
|
gl.deleteShader(shader);
|
|
2555
2600
|
});
|
|
2556
2601
|
}
|
|
2602
|
+
|
|
2603
|
+
var wait = function wait() {
|
|
2604
|
+
var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
2605
|
+
return new Promise(function (resolve) {
|
|
2606
|
+
return setTimeout(resolve, ms);
|
|
2607
|
+
});
|
|
2608
|
+
};
|
|
2557
2609
|
/**
|
|
2558
2610
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
2559
2611
|
* program and calls useProgram.
|
|
@@ -2577,6 +2629,8 @@ function deleteShaders(gl, shaders) {
|
|
|
2577
2629
|
|
|
2578
2630
|
|
|
2579
2631
|
function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
|
|
2632
|
+
// This code is really convoluted, because it may or may not be async
|
|
2633
|
+
// Maybe it would be better to have a separate function
|
|
2580
2634
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
2581
2635
|
var realShaders = [];
|
|
2582
2636
|
var newShaders = [];
|
|
@@ -2593,7 +2647,13 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2593
2647
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
2594
2648
|
}
|
|
2595
2649
|
|
|
2596
|
-
shader = loadShader(gl, src, type
|
|
2650
|
+
shader = loadShader(gl, src, type);
|
|
2651
|
+
|
|
2652
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shader, opt_errorCallback)) {
|
|
2653
|
+
gl.deleteShader(shader);
|
|
2654
|
+
shader = null;
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2597
2657
|
newShaders.push(shader);
|
|
2598
2658
|
}
|
|
2599
2659
|
|
|
@@ -2633,24 +2693,196 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2633
2693
|
gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
|
|
2634
2694
|
}
|
|
2635
2695
|
|
|
2636
|
-
gl.linkProgram(program);
|
|
2696
|
+
gl.linkProgram(program);
|
|
2697
|
+
|
|
2698
|
+
if (progOptions.callback) {
|
|
2699
|
+
checkForProgramLinkCompletionAsync(gl, program, progOptions);
|
|
2700
|
+
return null;
|
|
2701
|
+
} else {
|
|
2702
|
+
if (!checkProgramStatus(gl, program, progOptions.errorCallback)) {
|
|
2703
|
+
gl.deleteProgram(program);
|
|
2704
|
+
deleteShaders(gl, newShaders);
|
|
2705
|
+
return null;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
return program;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
/**
|
|
2712
|
+
* Same as createProgram but returns a promise
|
|
2713
|
+
*
|
|
2714
|
+
* NOTE: There are 4 signatures for this function
|
|
2715
|
+
*
|
|
2716
|
+
* twgl.createProgramAsync(gl, [vs, fs], options);
|
|
2717
|
+
* twgl.createProgramAsync(gl, [vs, fs], opt_errFunc);
|
|
2718
|
+
* twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_errFunc);
|
|
2719
|
+
* twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
|
|
2720
|
+
*
|
|
2721
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2722
|
+
* @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
|
|
2723
|
+
* @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
|
|
2724
|
+
* @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.
|
|
2725
|
+
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2726
|
+
* on error. If you want something else pass an callback. It's passed an error message.
|
|
2727
|
+
* @return {Promise<WebGLProgram>} The created program
|
|
2728
|
+
* @memberOf module:twgl/programs
|
|
2729
|
+
*/
|
|
2730
|
+
|
|
2731
|
+
|
|
2732
|
+
function createProgramAsync(gl, shaders) {
|
|
2733
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
2734
|
+
args[_key - 2] = arguments[_key];
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
return new Promise(function (resolve, reject) {
|
|
2738
|
+
var programOptions = getProgramOptions.apply(void 0, args);
|
|
2739
|
+
|
|
2740
|
+
programOptions.callback = function (err, program) {
|
|
2741
|
+
if (err) {
|
|
2742
|
+
reject(err);
|
|
2743
|
+
} else {
|
|
2744
|
+
resolve(program);
|
|
2745
|
+
}
|
|
2746
|
+
};
|
|
2747
|
+
|
|
2748
|
+
twgl.createProgram(gl, shaders, programOptions);
|
|
2749
|
+
});
|
|
2750
|
+
}
|
|
2751
|
+
/**
|
|
2752
|
+
* Same as createProgramInfo but returns a promise
|
|
2753
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext
|
|
2754
|
+
* to use.
|
|
2755
|
+
* @param {string[]} shaderSources Array of sources for the
|
|
2756
|
+
* shaders or ids. The first is assumed to be the vertex shader,
|
|
2757
|
+
* the second the fragment shader.
|
|
2758
|
+
* @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
|
|
2759
|
+
* @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.
|
|
2760
|
+
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2761
|
+
* on error. If you want something else pass an callback. It's passed an error message.
|
|
2762
|
+
* @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
|
|
2763
|
+
* @memberOf module:twgl/programs
|
|
2764
|
+
*/
|
|
2765
|
+
|
|
2766
|
+
|
|
2767
|
+
function createProgramInfoAsync(gl, shaders) {
|
|
2768
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
2769
|
+
args[_key2 - 2] = arguments[_key2];
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
return new Promise(function (resolve, reject) {
|
|
2773
|
+
var programOptions = getProgramOptions.apply(void 0, args);
|
|
2774
|
+
|
|
2775
|
+
programOptions.callback = function (err, programInfo) {
|
|
2776
|
+
if (err) {
|
|
2777
|
+
reject(err);
|
|
2778
|
+
} else {
|
|
2779
|
+
resolve(programInfo);
|
|
2780
|
+
}
|
|
2781
|
+
};
|
|
2782
|
+
|
|
2783
|
+
twgl.createProgramInfo(gl, shaders, programOptions);
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Asynchronously wait for program to link.
|
|
2788
|
+
* Note: if 'KHR_parallel_shader_compile' extension does not
|
|
2789
|
+
* exist then compilation will not be truly async.
|
|
2790
|
+
* @param {WebGLRenderingContext} gl The context
|
|
2791
|
+
* @param {WebGLProgram} program The program
|
|
2792
|
+
* @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
|
|
2793
|
+
*/
|
|
2794
|
+
|
|
2795
|
+
|
|
2796
|
+
function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
2797
|
+
return _checkForProgramLinkCompletionAsync.apply(this, arguments);
|
|
2798
|
+
}
|
|
2799
|
+
/**
|
|
2800
|
+
* Check a program's link status
|
|
2801
|
+
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2802
|
+
* @param {WebGLProgram} program Program to check
|
|
2803
|
+
* @param {ErrorCallback} [errFn] func for errors
|
|
2804
|
+
* @return {bool} true if program is ok
|
|
2805
|
+
*/
|
|
2806
|
+
|
|
2807
|
+
|
|
2808
|
+
function _checkForProgramLinkCompletionAsync() {
|
|
2809
|
+
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
|
|
2810
|
+
var ext, checkFn, waitTime, errMsgs, success, err, errFn;
|
|
2811
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
2812
|
+
while (1) {
|
|
2813
|
+
switch (_context.prev = _context.next) {
|
|
2814
|
+
case 0:
|
|
2815
|
+
ext = gl.getExtension('KHR_parallel_shader_compile');
|
|
2816
|
+
checkFn = ext ? function (gl, program) {
|
|
2817
|
+
return gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR);
|
|
2818
|
+
} : function () {
|
|
2819
|
+
return true;
|
|
2820
|
+
};
|
|
2821
|
+
waitTime = 0;
|
|
2822
|
+
|
|
2823
|
+
case 3:
|
|
2824
|
+
_context.next = 5;
|
|
2825
|
+
return wait(waitTime);
|
|
2826
|
+
|
|
2827
|
+
case 5:
|
|
2828
|
+
// must wait at least once
|
|
2829
|
+
waitTime = 1000 / 60;
|
|
2830
|
+
|
|
2831
|
+
case 6:
|
|
2832
|
+
if (!checkFn(gl, program)) {
|
|
2833
|
+
_context.next = 3;
|
|
2834
|
+
break;
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
case 7:
|
|
2838
|
+
errMsgs = [];
|
|
2839
|
+
success = checkProgramStatus(gl, program, function (msg) {
|
|
2840
|
+
return errMsgs.push(msg);
|
|
2841
|
+
});
|
|
2842
|
+
err = success ? undefined : errMsgs.join('\n');
|
|
2843
|
+
|
|
2844
|
+
if (!success) {
|
|
2845
|
+
errFn = progOptions.errorCallback || error;
|
|
2846
|
+
errFn(err);
|
|
2847
|
+
gl.deleteProgram(program); // TODO: delete shaders, but only shaders that were created newly for this
|
|
2848
|
+
// program
|
|
2849
|
+
|
|
2850
|
+
program = null;
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
progOptions.callback(err, program);
|
|
2854
|
+
|
|
2855
|
+
case 12:
|
|
2856
|
+
case "end":
|
|
2857
|
+
return _context.stop();
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
}, _callee);
|
|
2861
|
+
}));
|
|
2862
|
+
return _checkForProgramLinkCompletionAsync.apply(this, arguments);
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
function checkProgramStatus(gl, program, errFn) {
|
|
2866
|
+
errFn = errFn || error; // Check the link status
|
|
2637
2867
|
|
|
2638
2868
|
var linked = gl.getProgramParameter(program, LINK_STATUS);
|
|
2639
2869
|
|
|
2640
2870
|
if (!linked) {
|
|
2641
2871
|
// something went wrong with the link
|
|
2642
2872
|
var lastError = gl.getProgramInfoLog(program);
|
|
2643
|
-
|
|
2644
|
-
var
|
|
2873
|
+
errFn("".concat(gl.getAttachedShaders(program).map(function (shader) {
|
|
2874
|
+
var _prepShaderSource2 = prepShaderSource(gl.getShaderSource(shader)),
|
|
2875
|
+
lineOffset = _prepShaderSource2.lineOffset,
|
|
2876
|
+
shaderSource = _prepShaderSource2.shaderSource;
|
|
2877
|
+
|
|
2878
|
+
var shaderError = gl.getShaderInfoLog(shader);
|
|
2879
|
+
var src = addLineNumbersWithError(shaderSource, shaderError, lineOffset);
|
|
2645
2880
|
var type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
2646
2881
|
return "".concat(utils.glEnumToString(gl, type), "\n").concat(src, "}");
|
|
2647
2882
|
}).join('\n'), "\nError in program linking: ").concat(lastError));
|
|
2648
|
-
gl.deleteProgram(program);
|
|
2649
|
-
deleteShaders(gl, newShaders);
|
|
2650
|
-
return null;
|
|
2651
2883
|
}
|
|
2652
2884
|
|
|
2653
|
-
return
|
|
2885
|
+
return linked;
|
|
2654
2886
|
}
|
|
2655
2887
|
/**
|
|
2656
2888
|
* Loads a shader from a script tag.
|
|
@@ -3827,6 +4059,8 @@ function createProgramInfoFromProgram(gl, program) {
|
|
|
3827
4059
|
|
|
3828
4060
|
return programInfo;
|
|
3829
4061
|
}
|
|
4062
|
+
|
|
4063
|
+
var notIdRE = /\s|{|}|;/;
|
|
3830
4064
|
/**
|
|
3831
4065
|
* Creates a ProgramInfo from 2 sources.
|
|
3832
4066
|
*
|
|
@@ -3858,18 +4092,18 @@ function createProgramInfoFromProgram(gl, program) {
|
|
|
3858
4092
|
* @memberOf module:twgl/programs
|
|
3859
4093
|
*/
|
|
3860
4094
|
|
|
3861
|
-
|
|
3862
4095
|
function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
|
|
3863
4096
|
var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
3864
|
-
var
|
|
4097
|
+
var errors = [];
|
|
3865
4098
|
shaderSources = shaderSources.map(function (source) {
|
|
3866
4099
|
// Lets assume if there is no \n it's an id
|
|
3867
|
-
if (
|
|
4100
|
+
if (!notIdRE.test(source)) {
|
|
3868
4101
|
var script = getElementById(source);
|
|
3869
4102
|
|
|
3870
4103
|
if (!script) {
|
|
3871
|
-
|
|
3872
|
-
|
|
4104
|
+
var err = "no element with id: ".concat(source);
|
|
4105
|
+
progOptions.errorCallback(err);
|
|
4106
|
+
errors.push(err);
|
|
3873
4107
|
} else {
|
|
3874
4108
|
source = script.text;
|
|
3875
4109
|
}
|
|
@@ -3878,13 +4112,32 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
3878
4112
|
return source;
|
|
3879
4113
|
});
|
|
3880
4114
|
|
|
3881
|
-
if (
|
|
4115
|
+
if (errors.length) {
|
|
4116
|
+
if (progOptions.callback) {
|
|
4117
|
+
progOptions.callback(errors.join('\n'));
|
|
4118
|
+
}
|
|
4119
|
+
|
|
3882
4120
|
return null;
|
|
3883
4121
|
}
|
|
3884
4122
|
|
|
4123
|
+
var origCallback = progOptions.callback;
|
|
4124
|
+
|
|
4125
|
+
if (origCallback) {
|
|
4126
|
+
progOptions.callback = function (err, program) {
|
|
4127
|
+
var programInfo;
|
|
4128
|
+
|
|
4129
|
+
if (!err) {
|
|
4130
|
+
programInfo = createProgramInfoFromProgram(gl, program);
|
|
4131
|
+
}
|
|
4132
|
+
|
|
4133
|
+
origCallback(err, programInfo);
|
|
4134
|
+
};
|
|
4135
|
+
}
|
|
4136
|
+
|
|
3885
4137
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
3886
4138
|
|
|
3887
4139
|
if (!program) {
|
|
4140
|
+
// we should never get if if we have a callback
|
|
3888
4141
|
return null;
|
|
3889
4142
|
}
|
|
3890
4143
|
|