twgl.js 4.21.2 → 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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.21.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
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
  */
@@ -1197,6 +1197,7 @@ var LINEAR = 0x2601;
1197
1197
  * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
1198
1198
  * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
1199
1199
  * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
1200
+ * @property {number} [samples] The number of samples. Default = 1
1200
1201
  * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
1201
1202
  * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
1202
1203
  * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
@@ -1305,6 +1306,7 @@ function createFramebufferInfo(gl, attachments, width, height) {
1305
1306
  };
1306
1307
  attachments.forEach(function (attachmentOptions) {
1307
1308
  var attachment = attachmentOptions.attachment;
1309
+ var samples = attachmentOptions.samples;
1308
1310
  var format = attachmentOptions.format;
1309
1311
  var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
1310
1312
 
@@ -1313,10 +1315,15 @@ function createFramebufferInfo(gl, attachments, width, height) {
1313
1315
  }
1314
1316
 
1315
1317
  if (!attachment) {
1316
- if (isRenderbufferFormat(format)) {
1318
+ if (samples !== undefined || isRenderbufferFormat(format)) {
1317
1319
  attachment = gl.createRenderbuffer();
1318
1320
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1319
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1321
+
1322
+ if (samples > 1) {
1323
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1324
+ } else {
1325
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1326
+ }
1320
1327
  } else {
1321
1328
  var textureOptions = Object.assign({}, attachmentOptions);
1322
1329
  textureOptions.width = width;
@@ -1404,10 +1411,16 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
1404
1411
  attachments.forEach(function (attachmentOptions, ndx) {
1405
1412
  var attachment = framebufferInfo.attachments[ndx];
1406
1413
  var format = attachmentOptions.format;
1414
+ var samples = attachmentOptions.samples;
1407
1415
 
1408
- if (helper.isRenderbuffer(gl, attachment)) {
1416
+ if (samples !== undefined || helper.isRenderbuffer(gl, attachment)) {
1409
1417
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1410
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1418
+
1419
+ if (samples > 1) {
1420
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1421
+ } else {
1422
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1423
+ }
1411
1424
  } else if (helper.isTexture(gl, attachment)) {
1412
1425
  textures.resizeTexture(gl, attachment, attachmentOptions, width, height);
1413
1426
  } else {
@@ -1580,6 +1593,7 @@ exports.__esModule = true;
1580
1593
  exports.axisRotate = axisRotate;
1581
1594
  exports.axisRotation = axisRotation;
1582
1595
  exports.copy = copy;
1596
+ exports.create = create;
1583
1597
  exports.frustum = frustum;
1584
1598
  exports.getAxis = getAxis;
1585
1599
  exports.getTranslation = getTranslation;
@@ -1710,6 +1724,16 @@ function negate(m, dst) {
1710
1724
  dst[15] = -m[15];
1711
1725
  return dst;
1712
1726
  }
1727
+ /**
1728
+ * Creates a matrix.
1729
+ * @return {module:twgl/m4.Mat4} A new matrix.
1730
+ * @memberOf module:twgl/m4
1731
+ */
1732
+
1733
+
1734
+ function create() {
1735
+ return new MatType(16).fill(0);
1736
+ }
1713
1737
  /**
1714
1738
  * Copies a matrix.
1715
1739
  * @param {module:twgl/m4.Mat4} m The matrix.
@@ -4657,9 +4681,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
4657
4681
  exports.__esModule = true;
4658
4682
  exports.createAttributeSetters = createAttributeSetters;
4659
4683
  exports.createProgram = createProgram;
4684
+ exports.createProgramAsync = createProgramAsync;
4660
4685
  exports.createProgramFromScripts = createProgramFromScripts;
4661
4686
  exports.createProgramFromSources = createProgramFromSources;
4662
4687
  exports.createProgramInfo = createProgramInfo;
4688
+ exports.createProgramInfoAsync = createProgramInfoAsync;
4663
4689
  exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
4664
4690
  exports.createUniformSetters = createUniformSetters;
4665
4691
  exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
@@ -4684,6 +4710,10 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
4684
4710
 
4685
4711
  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; }
4686
4712
 
4713
+ 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); } }
4714
+
4715
+ 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); }); }; }
4716
+
4687
4717
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4688
4718
 
4689
4719
  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."); }
@@ -5480,56 +5510,91 @@ function addLineNumbersWithError(src) {
5480
5510
  * @memberOf module:twgl
5481
5511
  */
5482
5512
 
5513
+ /**
5514
+ * Program Callback
5515
+ * @callback ProgramCallback
5516
+ * @param {string} [err] error message, falsy if no error
5517
+ * @param {WebGLProgram|module:twgl.ProgramInfo} [result] the program or programInfo
5518
+ */
5519
+
5483
5520
 
5484
5521
  var spaceRE = /^[ \t]*\n/;
5522
+ /**
5523
+ * Remove the first end of line because WebGL 2.0 requires
5524
+ * #version 300 es
5525
+ * as the first line. No whitespace allowed before that line
5526
+ * so
5527
+ *
5528
+ * <script>
5529
+ * #version 300 es
5530
+ * </script>
5531
+ *
5532
+ * Has one line before it which is invalid according to GLSL ES 3.00
5533
+ *
5534
+ * @param {string} shaderSource The source of the shader
5535
+ * @returns {{shaderSource: string, lineOffset: number}}
5536
+ */
5537
+
5538
+ function prepShaderSource(shaderSource) {
5539
+ var lineOffset = 0;
5540
+
5541
+ if (spaceRE.test(shaderSource)) {
5542
+ lineOffset = 1;
5543
+ shaderSource = shaderSource.replace(spaceRE, '');
5544
+ }
5545
+
5546
+ return {
5547
+ lineOffset: lineOffset,
5548
+ shaderSource: shaderSource
5549
+ };
5550
+ }
5485
5551
  /**
5486
5552
  * Loads a shader.
5487
5553
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
5488
5554
  * @param {string} shaderSource The shader source.
5489
5555
  * @param {number} shaderType The type of shader.
5490
- * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
5491
5556
  * @return {WebGLShader} The created shader.
5492
5557
  * @private
5493
5558
  */
5494
5559
 
5495
- function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
5496
- var errFn = opt_errorCallback || error; // Create the shader object
5497
5560
 
5498
- var shader = gl.createShader(shaderType); // Remove the first end of line because WebGL 2.0 requires
5499
- // #version 300 es
5500
- // as the first line. No whitespace allowed before that line
5501
- // so
5502
- //
5503
- // <script>
5504
- // #version 300 es
5505
- // </script>
5506
- //
5507
- // Has one line before it which is invalid according to GLSL ES 3.00
5508
- //
5561
+ function loadShader(gl, shaderSource, shaderType) {
5562
+ // Create the shader object
5563
+ var shader = gl.createShader(shaderType); // Load the shader source
5509
5564
 
5510
- var lineOffset = 0;
5511
-
5512
- if (spaceRE.test(shaderSource)) {
5513
- lineOffset = 1;
5514
- shaderSource = shaderSource.replace(spaceRE, '');
5515
- } // Load the shader source
5565
+ gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
5516
5566
 
5567
+ gl.compileShader(shader);
5568
+ return shader;
5569
+ }
5570
+ /**
5571
+ * Check Shader status
5572
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
5573
+ * @param {WebGLShader} shader The shader
5574
+ * @param {ErrorCallback} [errFn] function to receive error message.
5575
+ * @returns {bool} true if shader is ok.
5576
+ */
5517
5577
 
5518
- gl.shaderSource(shader, shaderSource); // Compile the shader
5519
5578
 
5520
- gl.compileShader(shader); // Check the compile status
5579
+ function checkShaderStatus(gl, shaderType, shader, errFn) {
5580
+ errFn = errFn || error; // Check the compile status
5521
5581
 
5522
5582
  var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
5523
5583
 
5524
5584
  if (!compiled) {
5525
5585
  // Something went wrong during compilation; get the error
5526
5586
  var lastError = gl.getShaderInfoLog(shader);
5527
- errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
5528
- gl.deleteShader(shader);
5529
- return null;
5587
+
5588
+ var _shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
5589
+
5590
+ var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
5591
+ lineOffset = _prepShaderSource.lineOffset,
5592
+ shaderSource = _prepShaderSource.shaderSource;
5593
+
5594
+ errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, _shaderType), ": ").concat(lastError));
5530
5595
  }
5531
5596
 
5532
- return shader;
5597
+ return compiled;
5533
5598
  }
5534
5599
  /**
5535
5600
  * @typedef {Object} ProgramOptions
@@ -5539,6 +5604,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
5539
5604
  * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
5540
5605
  * you can pass an array of names.
5541
5606
  * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
5607
+ * @property {ProgramCallback} [callback] callback for async program compilation.
5542
5608
  * @memberOf module:twgl
5543
5609
  */
5544
5610
 
@@ -5556,6 +5622,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
5556
5622
  function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
5557
5623
  var transformFeedbackVaryings;
5558
5624
  var transformFeedbackMode;
5625
+ var callback;
5559
5626
 
5560
5627
  if (typeof opt_locations === 'function') {
5561
5628
  opt_errorCallback = opt_locations;
@@ -5577,12 +5644,14 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
5577
5644
  opt_attribs = opt.attribLocations;
5578
5645
  transformFeedbackVaryings = opt.transformFeedbackVaryings;
5579
5646
  transformFeedbackMode = opt.transformFeedbackMode;
5647
+ callback = opt.callback;
5580
5648
  }
5581
5649
 
5582
5650
  var options = {
5583
5651
  errorCallback: opt_errorCallback || error,
5584
5652
  transformFeedbackVaryings: transformFeedbackVaryings,
5585
- transformFeedbackMode: transformFeedbackMode
5653
+ transformFeedbackMode: transformFeedbackMode,
5654
+ callback: callback
5586
5655
  };
5587
5656
 
5588
5657
  if (opt_attribs) {
@@ -5619,6 +5688,13 @@ function deleteShaders(gl, shaders) {
5619
5688
  gl.deleteShader(shader);
5620
5689
  });
5621
5690
  }
5691
+
5692
+ var wait = function wait() {
5693
+ var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
5694
+ return new Promise(function (resolve) {
5695
+ return setTimeout(resolve, ms);
5696
+ });
5697
+ };
5622
5698
  /**
5623
5699
  * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
5624
5700
  * program and calls useProgram.
@@ -5642,6 +5718,8 @@ function deleteShaders(gl, shaders) {
5642
5718
 
5643
5719
 
5644
5720
  function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
5721
+ // This code is really convoluted, because it may or may not be async
5722
+ // Maybe it would be better to have a separate function
5645
5723
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
5646
5724
  var realShaders = [];
5647
5725
  var newShaders = [];
@@ -5658,7 +5736,13 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
5658
5736
  type = getShaderTypeFromScriptType(gl, elem.type) || type;
5659
5737
  }
5660
5738
 
5661
- shader = loadShader(gl, src, type, progOptions.errorCallback);
5739
+ shader = loadShader(gl, src, type);
5740
+
5741
+ if (!progOptions.callback && !checkShaderStatus(gl, shader, opt_errorCallback)) {
5742
+ gl.deleteShader(shader);
5743
+ shader = null;
5744
+ }
5745
+
5662
5746
  newShaders.push(shader);
5663
5747
  }
5664
5748
 
@@ -5698,24 +5782,196 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
5698
5782
  gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
5699
5783
  }
5700
5784
 
5701
- gl.linkProgram(program); // Check the link status
5785
+ gl.linkProgram(program);
5786
+
5787
+ if (progOptions.callback) {
5788
+ checkForProgramLinkCompletionAsync(gl, program, progOptions);
5789
+ return null;
5790
+ } else {
5791
+ if (!checkProgramStatus(gl, program, progOptions.errorCallback)) {
5792
+ gl.deleteProgram(program);
5793
+ deleteShaders(gl, newShaders);
5794
+ return null;
5795
+ }
5796
+
5797
+ return program;
5798
+ }
5799
+ }
5800
+ /**
5801
+ * Same as createProgram but returns a promise
5802
+ *
5803
+ * NOTE: There are 4 signatures for this function
5804
+ *
5805
+ * twgl.createProgramAsync(gl, [vs, fs], options);
5806
+ * twgl.createProgramAsync(gl, [vs, fs], opt_errFunc);
5807
+ * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_errFunc);
5808
+ * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
5809
+ *
5810
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
5811
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
5812
+ * @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
5813
+ * @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.
5814
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
5815
+ * on error. If you want something else pass an callback. It's passed an error message.
5816
+ * @return {Promise<WebGLProgram>} The created program
5817
+ * @memberOf module:twgl/programs
5818
+ */
5819
+
5820
+
5821
+ function createProgramAsync(gl, shaders) {
5822
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
5823
+ args[_key - 2] = arguments[_key];
5824
+ }
5825
+
5826
+ return new Promise(function (resolve, reject) {
5827
+ var programOptions = getProgramOptions.apply(void 0, args);
5828
+
5829
+ programOptions.callback = function (err, program) {
5830
+ if (err) {
5831
+ reject(err);
5832
+ } else {
5833
+ resolve(program);
5834
+ }
5835
+ };
5836
+
5837
+ twgl.createProgram(gl, shaders, programOptions);
5838
+ });
5839
+ }
5840
+ /**
5841
+ * Same as createProgramInfo but returns a promise
5842
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
5843
+ * to use.
5844
+ * @param {string[]} shaderSources Array of sources for the
5845
+ * shaders or ids. The first is assumed to be the vertex shader,
5846
+ * the second the fragment shader.
5847
+ * @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
5848
+ * @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.
5849
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
5850
+ * on error. If you want something else pass an callback. It's passed an error message.
5851
+ * @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
5852
+ * @memberOf module:twgl/programs
5853
+ */
5854
+
5855
+
5856
+ function createProgramInfoAsync(gl, shaders) {
5857
+ for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
5858
+ args[_key2 - 2] = arguments[_key2];
5859
+ }
5860
+
5861
+ return new Promise(function (resolve, reject) {
5862
+ var programOptions = getProgramOptions.apply(void 0, args);
5863
+
5864
+ programOptions.callback = function (err, programInfo) {
5865
+ if (err) {
5866
+ reject(err);
5867
+ } else {
5868
+ resolve(programInfo);
5869
+ }
5870
+ };
5871
+
5872
+ twgl.createProgramInfo(gl, shaders, programOptions);
5873
+ });
5874
+ }
5875
+ /**
5876
+ * Asynchronously wait for program to link.
5877
+ * Note: if 'KHR_parallel_shader_compile' extension does not
5878
+ * exist then compilation will not be truly async.
5879
+ * @param {WebGLRenderingContext} gl The context
5880
+ * @param {WebGLProgram} program The program
5881
+ * @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
5882
+ */
5883
+
5884
+
5885
+ function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
5886
+ return _checkForProgramLinkCompletionAsync.apply(this, arguments);
5887
+ }
5888
+ /**
5889
+ * Check a program's link status
5890
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
5891
+ * @param {WebGLProgram} program Program to check
5892
+ * @param {ErrorCallback} [errFn] func for errors
5893
+ * @return {bool} true if program is ok
5894
+ */
5895
+
5896
+
5897
+ function _checkForProgramLinkCompletionAsync() {
5898
+ _checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
5899
+ var ext, checkFn, waitTime, errMsgs, success, err, errFn;
5900
+ return regeneratorRuntime.wrap(function _callee$(_context) {
5901
+ while (1) {
5902
+ switch (_context.prev = _context.next) {
5903
+ case 0:
5904
+ ext = gl.getExtension('KHR_parallel_shader_compile');
5905
+ checkFn = ext ? function (gl, program) {
5906
+ return gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR);
5907
+ } : function () {
5908
+ return true;
5909
+ };
5910
+ waitTime = 0;
5911
+
5912
+ case 3:
5913
+ _context.next = 5;
5914
+ return wait(waitTime);
5915
+
5916
+ case 5:
5917
+ // must wait at least once
5918
+ waitTime = 1000 / 60;
5919
+
5920
+ case 6:
5921
+ if (!checkFn(gl, program)) {
5922
+ _context.next = 3;
5923
+ break;
5924
+ }
5925
+
5926
+ case 7:
5927
+ errMsgs = [];
5928
+ success = checkProgramStatus(gl, program, function (msg) {
5929
+ return errMsgs.push(msg);
5930
+ });
5931
+ err = success ? undefined : errMsgs.join('\n');
5932
+
5933
+ if (!success) {
5934
+ errFn = progOptions.errorCallback || error;
5935
+ errFn(err);
5936
+ gl.deleteProgram(program); // TODO: delete shaders, but only shaders that were created newly for this
5937
+ // program
5938
+
5939
+ program = null;
5940
+ }
5941
+
5942
+ progOptions.callback(err, program);
5943
+
5944
+ case 12:
5945
+ case "end":
5946
+ return _context.stop();
5947
+ }
5948
+ }
5949
+ }, _callee);
5950
+ }));
5951
+ return _checkForProgramLinkCompletionAsync.apply(this, arguments);
5952
+ }
5953
+
5954
+ function checkProgramStatus(gl, program, errFn) {
5955
+ errFn = errFn || error; // Check the link status
5702
5956
 
5703
5957
  var linked = gl.getProgramParameter(program, LINK_STATUS);
5704
5958
 
5705
5959
  if (!linked) {
5706
5960
  // something went wrong with the link
5707
5961
  var lastError = gl.getProgramInfoLog(program);
5708
- progOptions.errorCallback("".concat(realShaders.map(function (shader) {
5709
- var src = addLineNumbersWithError(gl.getShaderSource(shader), '', 0);
5962
+ errFn("".concat(gl.getAttachedShaders(program).map(function (shader) {
5963
+ var _prepShaderSource2 = prepShaderSource(gl.getShaderSource(shader)),
5964
+ lineOffset = _prepShaderSource2.lineOffset,
5965
+ shaderSource = _prepShaderSource2.shaderSource;
5966
+
5967
+ var shaderError = gl.getShaderInfoLog(shader);
5968
+ var src = addLineNumbersWithError(shaderSource, shaderError, lineOffset);
5710
5969
  var type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
5711
5970
  return "".concat(utils.glEnumToString(gl, type), "\n").concat(src, "}");
5712
5971
  }).join('\n'), "\nError in program linking: ").concat(lastError));
5713
- gl.deleteProgram(program);
5714
- deleteShaders(gl, newShaders);
5715
- return null;
5716
5972
  }
5717
5973
 
5718
- return program;
5974
+ return linked;
5719
5975
  }
5720
5976
  /**
5721
5977
  * Loads a shader from a script tag.
@@ -6424,6 +6680,7 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
6424
6680
  * struct Light {
6425
6681
  * float intensity;
6426
6682
  * vec4 color;
6683
+ * float nearFar[2];
6427
6684
  * };
6428
6685
  * uniform Lights {
6429
6686
  * Light lights[2];
@@ -6433,28 +6690,35 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
6433
6690
  *
6434
6691
  * twgl.setBlockUniforms(someBlockInfo, {
6435
6692
  * lights: [
6436
- * { intensity: 5.0, color: [1, 0, 0, 1] },
6437
- * { intensity: 2.0, color: [0, 0, 1, 1] },
6693
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
6694
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
6438
6695
  * ],
6439
6696
  * });
6440
6697
  *
6441
- * // or the more traditional way
6698
+ * or the more traditional way
6442
6699
  *
6443
6700
  * twgl.setBlockUniforms(someBlockInfo, {
6444
6701
  * "lights[0].intensity": 5.0,
6445
6702
  * "lights[0].color": [1, 0, 0, 1],
6703
+ * "lights[0].nearFar": [0.1, 10],
6446
6704
  * "lights[1].intensity": 2.0,
6447
6705
  * "lights[1].color": [0, 0, 1, 1],
6706
+ * "lights[1].nearFar": [0.2, 15],
6448
6707
  * });
6449
6708
  *
6450
6709
  * You can also specify partial paths
6451
6710
  *
6452
6711
  * twgl.setBlockUniforms(someBlockInfo, {
6453
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
6712
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
6454
6713
  * });
6455
6714
  *
6456
6715
  * But you can not specify leaf array indices.
6457
6716
  *
6717
+ * twgl.setBlockUniforms(someBlockInfo, {
6718
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
6719
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
6720
+ * });
6721
+ *
6458
6722
  * **IMPORTANT!**, packing in a UniformBlock is unintuitive.
6459
6723
  * For example the actual layout of `someVec3Array` above in memory
6460
6724
  * is `1, 2, 3, unused, 4, 5, 6, unused`. twgl takes in 6 values
@@ -6614,6 +6878,7 @@ function setUniformTree(tree, values) {
6614
6878
  * struct Light {
6615
6879
  * float intensity;
6616
6880
  * vec4 color;
6881
+ * float nearFar[2];
6617
6882
  * };
6618
6883
  * uniform Light lights[2];
6619
6884
  *
@@ -6621,8 +6886,8 @@ function setUniformTree(tree, values) {
6621
6886
  *
6622
6887
  * twgl.setUniforms(programInfo, {
6623
6888
  * lights: [
6624
- * { intensity: 5.0, color: [1, 0, 0, 1] },
6625
- * { intensity: 2.0, color: [0, 0, 1, 1] },
6889
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
6890
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
6626
6891
  * ],
6627
6892
  * });
6628
6893
  *
@@ -6631,18 +6896,25 @@ function setUniformTree(tree, values) {
6631
6896
  * twgl.setUniforms(programInfo, {
6632
6897
  * "lights[0].intensity": 5.0,
6633
6898
  * "lights[0].color": [1, 0, 0, 1],
6899
+ * "lights[0].nearFar": [0.1, 10],
6634
6900
  * "lights[1].intensity": 2.0,
6635
6901
  * "lights[1].color": [0, 0, 1, 1],
6902
+ * "lights[1].nearFar": [0.2, 15],
6636
6903
  * });
6637
6904
  *
6638
6905
  * You can also specify partial paths
6639
6906
  *
6640
6907
  * twgl.setUniforms(programInfo, {
6641
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
6908
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
6642
6909
  * });
6643
6910
  *
6644
6911
  * But you can not specify leaf array indices
6645
6912
  *
6913
+ * twgl.setUniforms(programInfo, {
6914
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
6915
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
6916
+ * });
6917
+ *
6646
6918
  * @memberOf module:twgl/programs
6647
6919
  */
6648
6920
 
@@ -6876,6 +7148,8 @@ function createProgramInfoFromProgram(gl, program) {
6876
7148
 
6877
7149
  return programInfo;
6878
7150
  }
7151
+
7152
+ var notIdRE = /\s|{|}|;/;
6879
7153
  /**
6880
7154
  * Creates a ProgramInfo from 2 sources.
6881
7155
  *
@@ -6907,18 +7181,18 @@ function createProgramInfoFromProgram(gl, program) {
6907
7181
  * @memberOf module:twgl/programs
6908
7182
  */
6909
7183
 
6910
-
6911
7184
  function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
6912
7185
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
6913
- var good = true;
7186
+ var errors = [];
6914
7187
  shaderSources = shaderSources.map(function (source) {
6915
7188
  // Lets assume if there is no \n it's an id
6916
- if (source.indexOf("\n") < 0) {
7189
+ if (!notIdRE.test(source)) {
6917
7190
  var script = getElementById(source);
6918
7191
 
6919
7192
  if (!script) {
6920
- progOptions.errorCallback("no element with id: " + source);
6921
- good = false;
7193
+ var err = "no element with id: ".concat(source);
7194
+ progOptions.errorCallback(err);
7195
+ errors.push(err);
6922
7196
  } else {
6923
7197
  source = script.text;
6924
7198
  }
@@ -6927,13 +7201,32 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
6927
7201
  return source;
6928
7202
  });
6929
7203
 
6930
- if (!good) {
7204
+ if (errors.length) {
7205
+ if (progOptions.callback) {
7206
+ progOptions.callback(errors.join('\n'));
7207
+ }
7208
+
6931
7209
  return null;
6932
7210
  }
6933
7211
 
7212
+ var origCallback = progOptions.callback;
7213
+
7214
+ if (origCallback) {
7215
+ progOptions.callback = function (err, program) {
7216
+ var programInfo;
7217
+
7218
+ if (!err) {
7219
+ programInfo = createProgramInfoFromProgram(gl, program);
7220
+ }
7221
+
7222
+ origCallback(err, programInfo);
7223
+ };
7224
+ }
7225
+
6934
7226
  var program = createProgramFromSources(gl, shaderSources, progOptions);
6935
7227
 
6936
7228
  if (!program) {
7229
+ // we should never get if if we have a callback
6937
7230
  return null;
6938
7231
  }
6939
7232
 
@@ -10756,6 +11049,9 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
10756
11049
  * @param {Object.<string, function>} setters Attribute setters as returned from createAttributeSetters
10757
11050
  * @param {Object.<string, module:twgl.AttribInfo>} attribs AttribInfos mapped by attribute name.
10758
11051
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
11052
+ *
11053
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
11054
+ *
10759
11055
  * @memberOf module:twgl/vertexArrays
10760
11056
  */
10761
11057
 
@@ -10783,6 +11079,9 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
10783
11079
  * @param {Object.<string, function>| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
10784
11080
  * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
10785
11081
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
11082
+ *
11083
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
11084
+ *
10786
11085
  * @memberOf module:twgl/vertexArrays
10787
11086
  */
10788
11087