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.
@@ -89,6 +89,7 @@ export type ProgramOptions = {
89
89
  [key: string]: AttribInfo;
90
90
  } | string[];
91
91
  transformFeedbackMode?: number;
92
+ callback?: ProgramCallback;
92
93
  };
93
94
  export type TransformFeedbackInfo = {
94
95
  index: number;
@@ -256,7 +257,14 @@ export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?:
256
257
 
257
258
 
258
259
  export function getBindPointForSamplerType(): void;
260
+ export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo) => void;
261
+ export function prepShaderSource(shaderSource: string): any;
262
+ export function checkShaderStatus(gl: WebGLRenderingContext, shader: WebGLShader, errFn?: ErrorCallback): boolean;
259
263
  export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
264
+ export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
265
+ export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
266
+ export function checkForProgramLinkCompletionAsync(gl: WebGLRenderingContext, program: WebGLProgram, progOptions: ProgramOptions): void;
267
+ export function checkProgramStatus(gl: WebGLRenderingContext, program: WebGLProgram, errFn?: ErrorCallback): boolean;
260
268
  export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
261
269
  export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
262
270
  export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
@@ -367,6 +375,7 @@ declare module m4 {
367
375
  export type Mat4 = number[] | Float32Array;
368
376
  export function setDefaultType(ctor: Function): Function;
369
377
  export function negate(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
378
+ export function create(): m4.Mat4;
370
379
  export function copy(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
371
380
  export function identity(dst?: m4.Mat4): m4.Mat4;
372
381
  export function transpose(m: m4.Mat4, dst?: m4.Mat4): m4.Mat4;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.22.1 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
  */
@@ -1593,6 +1593,7 @@ exports.__esModule = true;
1593
1593
  exports.axisRotate = axisRotate;
1594
1594
  exports.axisRotation = axisRotation;
1595
1595
  exports.copy = copy;
1596
+ exports.create = create;
1596
1597
  exports.frustum = frustum;
1597
1598
  exports.getAxis = getAxis;
1598
1599
  exports.getTranslation = getTranslation;
@@ -1723,6 +1724,16 @@ function negate(m, dst) {
1723
1724
  dst[15] = -m[15];
1724
1725
  return dst;
1725
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
+ }
1726
1737
  /**
1727
1738
  * Copies a matrix.
1728
1739
  * @param {module:twgl/m4.Mat4} m The matrix.
@@ -4670,9 +4681,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
4670
4681
  exports.__esModule = true;
4671
4682
  exports.createAttributeSetters = createAttributeSetters;
4672
4683
  exports.createProgram = createProgram;
4684
+ exports.createProgramAsync = createProgramAsync;
4673
4685
  exports.createProgramFromScripts = createProgramFromScripts;
4674
4686
  exports.createProgramFromSources = createProgramFromSources;
4675
4687
  exports.createProgramInfo = createProgramInfo;
4688
+ exports.createProgramInfoAsync = createProgramInfoAsync;
4676
4689
  exports.createProgramInfoFromProgram = createProgramInfoFromProgram;
4677
4690
  exports.createUniformSetters = createUniformSetters;
4678
4691
  exports.createUniformBlockSpecFromProgram = createUniformBlockSpecFromProgram;
@@ -4697,6 +4710,10 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
4697
4710
 
4698
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; }
4699
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
+
4700
4717
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4701
4718
 
4702
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."); }
@@ -5493,56 +5510,91 @@ function addLineNumbersWithError(src) {
5493
5510
  * @memberOf module:twgl
5494
5511
  */
5495
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
+
5496
5520
 
5497
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
+ }
5498
5551
  /**
5499
5552
  * Loads a shader.
5500
5553
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
5501
5554
  * @param {string} shaderSource The shader source.
5502
5555
  * @param {number} shaderType The type of shader.
5503
- * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
5504
5556
  * @return {WebGLShader} The created shader.
5505
5557
  * @private
5506
5558
  */
5507
5559
 
5508
- function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
5509
- var errFn = opt_errorCallback || error; // Create the shader object
5510
5560
 
5511
- var shader = gl.createShader(shaderType); // Remove the first end of line because WebGL 2.0 requires
5512
- // #version 300 es
5513
- // as the first line. No whitespace allowed before that line
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
- //
5561
+ function loadShader(gl, shaderSource, shaderType) {
5562
+ // Create the shader object
5563
+ var shader = gl.createShader(shaderType); // Load the shader source
5522
5564
 
5523
- var lineOffset = 0;
5524
-
5525
- if (spaceRE.test(shaderSource)) {
5526
- lineOffset = 1;
5527
- shaderSource = shaderSource.replace(spaceRE, '');
5528
- } // Load the shader source
5565
+ gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
5529
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
+ */
5530
5577
 
5531
- gl.shaderSource(shader, shaderSource); // Compile the shader
5532
5578
 
5533
- gl.compileShader(shader); // Check the compile status
5579
+ function checkShaderStatus(gl, shaderType, shader, errFn) {
5580
+ errFn = errFn || error; // Check the compile status
5534
5581
 
5535
5582
  var compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
5536
5583
 
5537
5584
  if (!compiled) {
5538
5585
  // Something went wrong during compilation; get the error
5539
5586
  var lastError = gl.getShaderInfoLog(shader);
5540
- errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
5541
- gl.deleteShader(shader);
5542
- 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));
5543
5595
  }
5544
5596
 
5545
- return shader;
5597
+ return compiled;
5546
5598
  }
5547
5599
  /**
5548
5600
  * @typedef {Object} ProgramOptions
@@ -5552,6 +5604,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
5552
5604
  * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
5553
5605
  * you can pass an array of names.
5554
5606
  * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
5607
+ * @property {ProgramCallback} [callback] callback for async program compilation.
5555
5608
  * @memberOf module:twgl
5556
5609
  */
5557
5610
 
@@ -5569,6 +5622,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
5569
5622
  function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
5570
5623
  var transformFeedbackVaryings;
5571
5624
  var transformFeedbackMode;
5625
+ var callback;
5572
5626
 
5573
5627
  if (typeof opt_locations === 'function') {
5574
5628
  opt_errorCallback = opt_locations;
@@ -5590,12 +5644,14 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
5590
5644
  opt_attribs = opt.attribLocations;
5591
5645
  transformFeedbackVaryings = opt.transformFeedbackVaryings;
5592
5646
  transformFeedbackMode = opt.transformFeedbackMode;
5647
+ callback = opt.callback;
5593
5648
  }
5594
5649
 
5595
5650
  var options = {
5596
5651
  errorCallback: opt_errorCallback || error,
5597
5652
  transformFeedbackVaryings: transformFeedbackVaryings,
5598
- transformFeedbackMode: transformFeedbackMode
5653
+ transformFeedbackMode: transformFeedbackMode,
5654
+ callback: callback
5599
5655
  };
5600
5656
 
5601
5657
  if (opt_attribs) {
@@ -5632,6 +5688,13 @@ function deleteShaders(gl, shaders) {
5632
5688
  gl.deleteShader(shader);
5633
5689
  });
5634
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
+ };
5635
5698
  /**
5636
5699
  * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
5637
5700
  * program and calls useProgram.
@@ -5655,6 +5718,8 @@ function deleteShaders(gl, shaders) {
5655
5718
 
5656
5719
 
5657
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
5658
5723
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
5659
5724
  var realShaders = [];
5660
5725
  var newShaders = [];
@@ -5671,7 +5736,13 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
5671
5736
  type = getShaderTypeFromScriptType(gl, elem.type) || type;
5672
5737
  }
5673
5738
 
5674
- 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
+
5675
5746
  newShaders.push(shader);
5676
5747
  }
5677
5748
 
@@ -5711,24 +5782,196 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
5711
5782
  gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
5712
5783
  }
5713
5784
 
5714
- 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
5715
5956
 
5716
5957
  var linked = gl.getProgramParameter(program, LINK_STATUS);
5717
5958
 
5718
5959
  if (!linked) {
5719
5960
  // something went wrong with the link
5720
5961
  var lastError = gl.getProgramInfoLog(program);
5721
- progOptions.errorCallback("".concat(realShaders.map(function (shader) {
5722
- 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);
5723
5969
  var type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
5724
5970
  return "".concat(utils.glEnumToString(gl, type), "\n").concat(src, "}");
5725
5971
  }).join('\n'), "\nError in program linking: ").concat(lastError));
5726
- gl.deleteProgram(program);
5727
- deleteShaders(gl, newShaders);
5728
- return null;
5729
5972
  }
5730
5973
 
5731
- return program;
5974
+ return linked;
5732
5975
  }
5733
5976
  /**
5734
5977
  * Loads a shader from a script tag.
@@ -6905,6 +7148,8 @@ function createProgramInfoFromProgram(gl, program) {
6905
7148
 
6906
7149
  return programInfo;
6907
7150
  }
7151
+
7152
+ var notIdRE = /\s|{|}|;/;
6908
7153
  /**
6909
7154
  * Creates a ProgramInfo from 2 sources.
6910
7155
  *
@@ -6936,18 +7181,18 @@ function createProgramInfoFromProgram(gl, program) {
6936
7181
  * @memberOf module:twgl/programs
6937
7182
  */
6938
7183
 
6939
-
6940
7184
  function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
6941
7185
  var progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
6942
- var good = true;
7186
+ var errors = [];
6943
7187
  shaderSources = shaderSources.map(function (source) {
6944
7188
  // Lets assume if there is no \n it's an id
6945
- if (source.indexOf("\n") < 0) {
7189
+ if (!notIdRE.test(source)) {
6946
7190
  var script = getElementById(source);
6947
7191
 
6948
7192
  if (!script) {
6949
- progOptions.errorCallback("no element with id: " + source);
6950
- good = false;
7193
+ var err = "no element with id: ".concat(source);
7194
+ progOptions.errorCallback(err);
7195
+ errors.push(err);
6951
7196
  } else {
6952
7197
  source = script.text;
6953
7198
  }
@@ -6956,13 +7201,32 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
6956
7201
  return source;
6957
7202
  });
6958
7203
 
6959
- if (!good) {
7204
+ if (errors.length) {
7205
+ if (progOptions.callback) {
7206
+ progOptions.callback(errors.join('\n'));
7207
+ }
7208
+
6960
7209
  return null;
6961
7210
  }
6962
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
+
6963
7226
  var program = createProgramFromSources(gl, shaderSources, progOptions);
6964
7227
 
6965
7228
  if (!program) {
7229
+ // we should never get if if we have a callback
6966
7230
  return null;
6967
7231
  }
6968
7232