twgl.js 4.22.0 → 4.23.1

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,4 +1,4 @@
1
- /* @license twgl.js 4.22.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
1
+ /* @license twgl.js 4.23.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
2
  Available via the MIT license.
3
3
  see: http://github.com/greggman/twgl.js for details */
4
4
  /*
@@ -548,6 +548,15 @@ function negate$1(m, dst) {
548
548
  return dst;
549
549
  }
550
550
 
551
+ /**
552
+ * Creates a matrix.
553
+ * @return {module:twgl/m4.Mat4} A new matrix.
554
+ * @memberOf module:twgl/m4
555
+ */
556
+ function create$1() {
557
+ return new MatType(16).fill(0);
558
+ }
559
+
551
560
  /**
552
561
  * Copies a matrix.
553
562
  * @param {module:twgl/m4.Mat4} m The matrix.
@@ -1717,6 +1726,7 @@ var m4 = /*#__PURE__*/Object.freeze({
1717
1726
  axisRotate: axisRotate,
1718
1727
  axisRotation: axisRotation,
1719
1728
  copy: copy$1,
1729
+ create: create$1,
1720
1730
  frustum: frustum,
1721
1731
  getAxis: getAxis,
1722
1732
  getTranslation: getTranslation,
@@ -7243,56 +7253,102 @@ function addLineNumbersWithError(src, log = '', lineOffset = 0) {
7243
7253
  * @memberOf module:twgl
7244
7254
  */
7245
7255
 
7256
+ /**
7257
+ * Program Callback
7258
+ * @callback ProgramCallback
7259
+ * @param {string} [err] error message, falsy if no error
7260
+ * @param {WebGLProgram|module:twgl.ProgramInfo} [result] the program or programInfo
7261
+ */
7262
+
7246
7263
  const spaceRE = /^[ \t]*\n/;
7247
7264
 
7265
+ /**
7266
+ * Remove the first end of line because WebGL 2.0 requires
7267
+ * #version 300 es
7268
+ * as the first line. No whitespace allowed before that line
7269
+ * so
7270
+ *
7271
+ * <script>
7272
+ * #version 300 es
7273
+ * </script>
7274
+ *
7275
+ * Has one line before it which is invalid according to GLSL ES 3.00
7276
+ *
7277
+ * @param {string} shaderSource The source of the shader
7278
+ * @returns {{shaderSource: string, lineOffset: number}}
7279
+ */
7280
+ function prepShaderSource(shaderSource) {
7281
+ let lineOffset = 0;
7282
+ if (spaceRE.test(shaderSource)) {
7283
+ lineOffset = 1;
7284
+ shaderSource = shaderSource.replace(spaceRE, '');
7285
+ }
7286
+ return {lineOffset, shaderSource};
7287
+ }
7288
+
7289
+ /**
7290
+ * @param {module:twgl.ProgramOptions} progOptions
7291
+ * @param {string} msg
7292
+ * @return null
7293
+ * @private
7294
+ */
7295
+ function reportError(progOptions, msg) {
7296
+ progOptions.errorCallback(msg);
7297
+ if (progOptions.callback) {
7298
+ setTimeout(() => {
7299
+ progOptions.callback(`${msg}\n${progOptions.errors.join('\n')}`);
7300
+ });
7301
+ }
7302
+ return null;
7303
+ }
7304
+
7248
7305
  /**
7249
7306
  * Loads a shader.
7250
7307
  * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7251
7308
  * @param {string} shaderSource The shader source.
7252
7309
  * @param {number} shaderType The type of shader.
7253
- * @param {module:twgl.ErrorCallback} opt_errorCallback callback for errors.
7310
+ * @param {module:twgl.ProgramOptions} progOptions
7254
7311
  * @return {WebGLShader} The created shader.
7255
7312
  * @private
7256
7313
  */
7257
- function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
7258
- const errFn = opt_errorCallback || error$1;
7314
+ function loadShader(gl, shaderSource, shaderType, progOptions) {
7259
7315
  // Create the shader object
7260
7316
  const shader = gl.createShader(shaderType);
7261
7317
 
7262
- // Remove the first end of line because WebGL 2.0 requires
7263
- // #version 300 es
7264
- // as the first line. No whitespace allowed before that line
7265
- // so
7266
- //
7267
- // <script>
7268
- // #version 300 es
7269
- // </script>
7270
- //
7271
- // Has one line before it which is invalid according to GLSL ES 3.00
7272
- //
7273
- let lineOffset = 0;
7274
- if (spaceRE.test(shaderSource)) {
7275
- lineOffset = 1;
7276
- shaderSource = shaderSource.replace(spaceRE, '');
7277
- }
7278
-
7279
7318
  // Load the shader source
7280
- gl.shaderSource(shader, shaderSource);
7319
+ gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource);
7281
7320
 
7282
7321
  // Compile the shader
7283
7322
  gl.compileShader(shader);
7284
7323
 
7324
+ if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
7325
+ gl.deleteShader(shader);
7326
+ return null;
7327
+ }
7328
+
7329
+ return shader;
7330
+ }
7331
+
7332
+ /**
7333
+ * Check Shader status
7334
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7335
+ * @param {number} shaderType The shader type
7336
+ * @param {WebGLShader} shader The shader
7337
+ * @param {ErrorCallback} [errFn] function to receive error message.
7338
+ * @return {bool} true if shader is ok.
7339
+ * @private
7340
+ */
7341
+ function checkShaderStatus(gl, shaderType, shader, errFn) {
7342
+ errFn = errFn || error$1;
7285
7343
  // Check the compile status
7286
7344
  const compiled = gl.getShaderParameter(shader, COMPILE_STATUS);
7287
7345
  if (!compiled) {
7288
7346
  // Something went wrong during compilation; get the error
7289
7347
  const lastError = gl.getShaderInfoLog(shader);
7348
+ const {lineOffset, shaderSource} = prepShaderSource(gl.getShaderSource(shader));
7290
7349
  errFn(`${addLineNumbersWithError(shaderSource, lastError, lineOffset)}\nError compiling ${glEnumToString(gl, shaderType)}: ${lastError}`);
7291
- gl.deleteShader(shader);
7292
- return null;
7293
7350
  }
7294
-
7295
- return shader;
7351
+ return compiled;
7296
7352
  }
7297
7353
 
7298
7354
  /**
@@ -7303,6 +7359,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
7303
7359
  * a BufferInfo will use the attribs names inside. If passed an object of AttribInfos will use the names from that object. Otherwise
7304
7360
  * you can pass an array of names.
7305
7361
  * @property {number} [transformFeedbackMode] the mode to pass `gl.transformFeedbackVaryings`. Defaults to `SEPARATE_ATTRIBS`.
7362
+ * @property {ProgramCallback} [callback] callback for async program compilation.
7306
7363
  * @memberOf module:twgl
7307
7364
  */
7308
7365
 
@@ -7318,6 +7375,7 @@ function loadShader(gl, shaderSource, shaderType, opt_errorCallback) {
7318
7375
  function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
7319
7376
  let transformFeedbackVaryings;
7320
7377
  let transformFeedbackMode;
7378
+ let callback;
7321
7379
  if (typeof opt_locations === 'function') {
7322
7380
  opt_errorCallback = opt_locations;
7323
7381
  opt_locations = undefined;
@@ -7328,7 +7386,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
7328
7386
  } else if (opt_attribs && !Array.isArray(opt_attribs)) {
7329
7387
  // If we have an errorCallback we can just return this object
7330
7388
  // Otherwise we need to construct one with default errorCallback
7331
- if (opt_attribs.errorCallback) {
7389
+ if (opt_attribs.errorCallback && opt_attribs.errors) {
7332
7390
  return opt_attribs;
7333
7391
  }
7334
7392
  const opt = opt_attribs;
@@ -7336,12 +7394,20 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
7336
7394
  opt_attribs = opt.attribLocations;
7337
7395
  transformFeedbackVaryings = opt.transformFeedbackVaryings;
7338
7396
  transformFeedbackMode = opt.transformFeedbackMode;
7397
+ callback = opt.callback;
7339
7398
  }
7340
7399
 
7400
+ const errorCallback = opt_errorCallback || error$1;
7401
+ const errors = [];
7341
7402
  const options = {
7342
- errorCallback: opt_errorCallback || error$1,
7343
- transformFeedbackVaryings: transformFeedbackVaryings,
7344
- transformFeedbackMode: transformFeedbackMode,
7403
+ errorCallback(msg, ...args) {
7404
+ errors.push(msg);
7405
+ errorCallback(msg, ...args);
7406
+ },
7407
+ transformFeedbackVaryings,
7408
+ transformFeedbackMode,
7409
+ callback,
7410
+ errors,
7345
7411
  };
7346
7412
 
7347
7413
  if (opt_attribs) {
@@ -7379,9 +7445,11 @@ function deleteShaders(gl, shaders) {
7379
7445
  });
7380
7446
  }
7381
7447
 
7448
+ const wait = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
7449
+
7382
7450
  /**
7383
7451
  * Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
7384
- * program and calls useProgram.
7452
+ * program.
7385
7453
  *
7386
7454
  * NOTE: There are 4 signatures for this function
7387
7455
  *
@@ -7396,11 +7464,13 @@ function deleteShaders(gl, shaders) {
7396
7464
  * @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.
7397
7465
  * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
7398
7466
  * on error. If you want something else pass an callback. It's passed an error message.
7399
- * @return {WebGLProgram?} the created program or null if error.
7467
+ * @return {WebGLProgram?} the created program or null if error of a callback was provided.
7400
7468
  * @memberOf module:twgl/programs
7401
7469
  */
7402
7470
  function createProgram(
7403
7471
  gl, shaders, opt_attribs, opt_locations, opt_errorCallback) {
7472
+ // This code is really convoluted, because it may or may not be async
7473
+ // Maybe it would be better to have a separate function
7404
7474
  const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
7405
7475
  const realShaders = [];
7406
7476
  const newShaders = [];
@@ -7413,7 +7483,7 @@ function createProgram(
7413
7483
  if (elem && elem.type) {
7414
7484
  type = getShaderTypeFromScriptType(gl, elem.type) || type;
7415
7485
  }
7416
- shader = loadShader(gl, src, type, progOptions.errorCallback);
7486
+ shader = loadShader(gl, src, type, progOptions);
7417
7487
  newShaders.push(shader);
7418
7488
  }
7419
7489
  if (isShader(gl, shader)) {
@@ -7422,9 +7492,8 @@ function createProgram(
7422
7492
  }
7423
7493
 
7424
7494
  if (realShaders.length !== shaders.length) {
7425
- progOptions.errorCallback("not enough shaders for program");
7426
7495
  deleteShaders(gl, newShaders);
7427
- return null;
7496
+ return reportError(progOptions, "not enough shaders for program");
7428
7497
  }
7429
7498
 
7430
7499
  const program = gl.createProgram();
@@ -7446,26 +7515,135 @@ function createProgram(
7446
7515
  }
7447
7516
  gl.transformFeedbackVaryings(program, varyings, progOptions.transformFeedbackMode || SEPARATE_ATTRIBS);
7448
7517
  }
7518
+
7449
7519
  gl.linkProgram(program);
7520
+ if (progOptions.callback) {
7521
+ checkForProgramLinkCompletionAsync(gl, program, progOptions);
7522
+ return null;
7523
+ } else {
7524
+ if (!checkProgramStatus(gl, program, progOptions.errorCallback)) {
7525
+ gl.deleteProgram(program);
7526
+ deleteShaders(gl, newShaders);
7527
+ return null;
7528
+ }
7529
+ return program;
7530
+ }
7531
+ }
7532
+
7533
+ /**
7534
+ * Same as createProgram but returns a promise
7535
+ *
7536
+ * NOTE: There are 4 signatures for this function
7537
+ *
7538
+ * twgl.createProgramAsync(gl, [vs, fs], options);
7539
+ * twgl.createProgramAsync(gl, [vs, fs], opt_errFunc);
7540
+ * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_errFunc);
7541
+ * twgl.createProgramAsync(gl, [vs, fs], opt_attribs, opt_locations, opt_errFunc);
7542
+ *
7543
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7544
+ * @param {WebGLShader[]|string[]} shaders The shaders to attach, or element ids for their source, or strings that contain their source
7545
+ * @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
7546
+ * @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.
7547
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
7548
+ * on error. If you want something else pass an callback. It's passed an error message.
7549
+ * @return {Promise<WebGLProgram>} The created program
7550
+ * @memberOf module:twgl/programs
7551
+ */
7552
+ function createProgramAsync(gl, shaders, ...args) {
7553
+ return new Promise((resolve, reject) => {
7554
+ const programOptions = getProgramOptions(...args);
7555
+ programOptions.callback = (err, program) => {
7556
+ if (err) {
7557
+ reject(err);
7558
+ } else {
7559
+ resolve(program);
7560
+ }
7561
+ };
7562
+ createProgram(gl, shaders, programOptions);
7563
+ });
7564
+ }
7450
7565
 
7566
+ /**
7567
+ * Same as createProgramInfo but returns a promise
7568
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext
7569
+ * to use.
7570
+ * @param {string[]} shaderSources Array of sources for the
7571
+ * shaders or ids. The first is assumed to be the vertex shader,
7572
+ * the second the fragment shader.
7573
+ * @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
7574
+ * @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.
7575
+ * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
7576
+ * on error. If you want something else pass an callback. It's passed an error message.
7577
+ * @return {Promise<module:twgl.ProgramInfo>} The created ProgramInfo
7578
+ * @memberOf module:twgl/programs
7579
+ */
7580
+ function createProgramInfoAsync(gl, shaders, ...args) {
7581
+ return new Promise((resolve, reject) => {
7582
+ const programOptions = getProgramOptions(...args);
7583
+ programOptions.callback = (err, programInfo) => {
7584
+ if (err) {
7585
+ reject(err);
7586
+ } else {
7587
+ resolve(programInfo);
7588
+ }
7589
+ };
7590
+ createProgramInfo(gl, shaders, programOptions);
7591
+ });
7592
+ }
7593
+
7594
+
7595
+ /**
7596
+ * Asynchronously wait for program to link.
7597
+ * Note: if 'KHR_parallel_shader_compile' extension does not
7598
+ * exist then compilation will not be truly async.
7599
+ * @param {WebGLRenderingContext} gl The context
7600
+ * @param {WebGLProgram} program The program
7601
+ * @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
7602
+ * @private
7603
+ */
7604
+ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
7605
+ const ext = gl.getExtension('KHR_parallel_shader_compile');
7606
+ const checkFn = ext
7607
+ ? (gl, program) => gl.getProgramParameter(program, ext.COMPLETION_STATUS_KHR)
7608
+ : () => true;
7609
+
7610
+ let waitTime = 0;
7611
+ do {
7612
+ await wait(waitTime); // must wait at least once
7613
+ waitTime = 1000 / 60;
7614
+ } while (!checkFn(gl, program));
7615
+
7616
+ const success = checkProgramStatus(gl, program, progOptions.errorCallback);
7617
+ const err = success ? undefined : progOptions.errors.join('\n');
7618
+ if (!success) {
7619
+ const errFn = progOptions.errorCallback || error$1;
7620
+ errFn(err);
7621
+ gl.deleteProgram(program);
7622
+ // TODO: delete shaders, but only shaders that were created newly for this
7623
+ // program
7624
+ program = null;
7625
+ }
7626
+ progOptions.callback(err, program);
7627
+ }
7628
+
7629
+ /**
7630
+ * Check a program's link status
7631
+ * @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
7632
+ * @param {WebGLProgram} program Program to check
7633
+ * @param {ErrorCallback} [errFn] func for errors
7634
+ * @return {bool} true if program is ok
7635
+ * @private
7636
+ */
7637
+ function checkProgramStatus(gl, program, errFn) {
7638
+ errFn = errFn || error$1;
7451
7639
  // Check the link status
7452
7640
  const linked = gl.getProgramParameter(program, LINK_STATUS);
7453
7641
  if (!linked) {
7454
7642
  // something went wrong with the link
7455
7643
  const lastError = gl.getProgramInfoLog(program);
7456
- progOptions.errorCallback(`${
7457
- realShaders.map(shader => {
7458
- const src = addLineNumbersWithError(gl.getShaderSource(shader), '', 0);
7459
- const type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
7460
- return `${glEnumToString(gl, type)}\n${src}}`;
7461
- }).join('\n')
7462
- }\nError in program linking: ${lastError}`);
7463
-
7464
- gl.deleteProgram(program);
7465
- deleteShaders(gl, newShaders);
7466
- return null;
7644
+ errFn(`Error in program linking: ${lastError}`);
7467
7645
  }
7468
- return program;
7646
+ return linked;
7469
7647
  }
7470
7648
 
7471
7649
  /**
@@ -7474,25 +7652,25 @@ function createProgram(
7474
7652
  * @param {string} scriptId The id of the script tag.
7475
7653
  * @param {number} [opt_shaderType] The type of shader. If not passed in it will
7476
7654
  * be derived from the type of the script tag.
7477
- * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors.
7655
+ * @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
7478
7656
  * @return {WebGLShader?} The created shader or null if error.
7479
7657
  * @private
7480
7658
  */
7481
7659
  function createShaderFromScript(
7482
- gl, scriptId, opt_shaderType, opt_errorCallback) {
7660
+ gl, scriptId, opt_shaderType, progOptions) {
7483
7661
  let shaderSource = "";
7484
7662
  const shaderScript = getElementById(scriptId);
7485
7663
  if (!shaderScript) {
7486
- throw new Error(`unknown script element: ${scriptId}`);
7664
+ return reportError(progOptions, `unknown script element: ${scriptId}`);
7487
7665
  }
7488
7666
  shaderSource = shaderScript.text;
7489
7667
 
7490
7668
  const shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
7491
7669
  if (!shaderType) {
7492
- throw new Error('unknown shader type');
7670
+ return reportError(progOptions, 'unknown shader type');
7493
7671
  }
7494
7672
 
7495
- return loadShader(gl, shaderSource, shaderType, opt_errorCallback);
7673
+ return loadShader(gl, shaderSource, shaderType, progOptions);
7496
7674
  }
7497
7675
 
7498
7676
  /**
@@ -7514,7 +7692,7 @@ function createShaderFromScript(
7514
7692
  * @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.
7515
7693
  * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
7516
7694
  * on error. If you want something else pass an callback. It's passed an error message.
7517
- * @return {WebGLProgram?} the created program or null if error.
7695
+ * @return {WebGLProgram?} the created program or null if error or a callback was provided.
7518
7696
  * @memberOf module:twgl/programs
7519
7697
  */
7520
7698
  function createProgramFromScripts(
@@ -7523,7 +7701,7 @@ function createProgramFromScripts(
7523
7701
  const shaders = [];
7524
7702
  for (let ii = 0; ii < shaderScriptIds.length; ++ii) {
7525
7703
  const shader = createShaderFromScript(
7526
- gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
7704
+ gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
7527
7705
  if (!shader) {
7528
7706
  return null;
7529
7707
  }
@@ -7551,7 +7729,7 @@ function createProgramFromScripts(
7551
7729
  * @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.
7552
7730
  * @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
7553
7731
  * on error. If you want something else pass an callback. It's passed an error message.
7554
- * @return {WebGLProgram?} the created program or null if error.
7732
+ * @return {WebGLProgram?} the created program or null if error or a callback was provided.
7555
7733
  * @memberOf module:twgl/programs
7556
7734
  */
7557
7735
  function createProgramFromSources(
@@ -7559,9 +7737,8 @@ function createProgramFromSources(
7559
7737
  const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
7560
7738
  const shaders = [];
7561
7739
  for (let ii = 0; ii < shaderSources.length; ++ii) {
7562
- const shader = loadShader(
7563
- gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions.errorCallback);
7564
- if (!shader) {
7740
+ const shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
7741
+ if (!progOptions.callback && !shader) {
7565
7742
  return null;
7566
7743
  }
7567
7744
  shaders.push(shader);
@@ -8574,6 +8751,8 @@ function createProgramInfoFromProgram(gl, program) {
8574
8751
  return programInfo;
8575
8752
  }
8576
8753
 
8754
+ const notIdRE = /\s|{|}|;/;
8755
+
8577
8756
  /**
8578
8757
  * Creates a ProgramInfo from 2 sources.
8579
8758
  *
@@ -8607,22 +8786,33 @@ function createProgramInfoFromProgram(gl, program) {
8607
8786
  function createProgramInfo(
8608
8787
  gl, shaderSources, opt_attribs, opt_locations, opt_errorCallback) {
8609
8788
  const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
8610
- let good = true;
8789
+ const errors = [];
8611
8790
  shaderSources = shaderSources.map(function(source) {
8612
8791
  // Lets assume if there is no \n it's an id
8613
- if (source.indexOf("\n") < 0) {
8792
+ if (!notIdRE.test(source)) {
8614
8793
  const script = getElementById(source);
8615
8794
  if (!script) {
8616
- progOptions.errorCallback("no element with id: " + source);
8617
- good = false;
8795
+ const err = `no element with id: ${source}`;
8796
+ progOptions.errorCallback(err);
8797
+ errors.push(err);
8618
8798
  } else {
8619
8799
  source = script.text;
8620
8800
  }
8621
8801
  }
8622
8802
  return source;
8623
8803
  });
8624
- if (!good) {
8625
- return null;
8804
+ if (errors.length) {
8805
+ return reportError(progOptions, '');
8806
+ }
8807
+ const origCallback = progOptions.callback;
8808
+ if (origCallback) {
8809
+ progOptions.callback = (err, program) => {
8810
+ let programInfo;
8811
+ if (!err) {
8812
+ programInfo = createProgramInfoFromProgram(gl, program);
8813
+ }
8814
+ origCallback(err, programInfo);
8815
+ };
8626
8816
  }
8627
8817
  const program = createProgramFromSources(gl, shaderSources, progOptions);
8628
8818
  if (!program) {
@@ -8635,9 +8825,11 @@ var programs = /*#__PURE__*/Object.freeze({
8635
8825
  __proto__: null,
8636
8826
  createAttributeSetters: createAttributeSetters,
8637
8827
  createProgram: createProgram,
8828
+ createProgramAsync: createProgramAsync,
8638
8829
  createProgramFromScripts: createProgramFromScripts,
8639
8830
  createProgramFromSources: createProgramFromSources,
8640
8831
  createProgramInfo: createProgramInfo,
8832
+ createProgramInfoAsync: createProgramInfoAsync,
8641
8833
  createProgramInfoFromProgram: createProgramInfoFromProgram,
8642
8834
  createUniformSetters: createUniformSetters,
8643
8835
  createUniformBlockSpecFromProgram: createUniformBlockSpecFromProgram,
@@ -9271,6 +9463,9 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
9271
9463
  * @param {Object.<string, function>} setters Attribute setters as returned from createAttributeSetters
9272
9464
  * @param {Object.<string, module:twgl.AttribInfo>} attribs AttribInfos mapped by attribute name.
9273
9465
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
9466
+ *
9467
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
9468
+ *
9274
9469
  * @memberOf module:twgl/vertexArrays
9275
9470
  */
9276
9471
  function createVAOAndSetAttributes(gl, setters, attribs, indices) {
@@ -9295,6 +9490,9 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
9295
9490
  * @param {Object.<string, function>| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
9296
9491
  * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
9297
9492
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
9493
+ *
9494
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
9495
+ *
9298
9496
  * @memberOf module:twgl/vertexArrays
9299
9497
  */
9300
9498
  function createVAOFromBufferInfo(gl, programInfo, bufferInfo) {
@@ -9656,4 +9854,4 @@ function resizeCanvasToDisplaySize(canvas, multiplier) {
9656
9854
  return false;
9657
9855
  }
9658
9856
 
9659
- export { addExtensionsToContext, attributes, bindFramebufferInfo, bindTransformFeedbackInfo, bindUniformBlock, canFilter, canGenerateMipmap, createAttribsFromArrays, createAttributeSetters, createBufferFromArray, createBufferFromTypedArray, createBufferInfoFromArrays, createBuffersFromArrays, createFramebufferInfo, createProgram, createProgramFromScripts, createProgramFromSources, createProgramInfo, createProgramInfoFromProgram, createSampler, createSamplers, createTexture, createTextures, createTransformFeedback, createTransformFeedbackInfo, createUniformBlockInfo, createUniformBlockInfoFromProgram, createUniformBlockSpecFromProgram, createUniformSetters, createVAOAndSetAttributes, createVAOFromBufferInfo, createVertexArrayInfo, draw, drawBufferInfo, drawObjectList, framebuffers, getArray as getArray_, getBytesPerElementForInternalFormat, getContext, getFormatAndTypeForInternalFormat, getGLTypeForTypedArray, getGLTypeForTypedArrayType, getNumComponentsForFormat, getNumComponents as getNumComponents_, getTypedArrayTypeForGLType, getWebGLContext, glEnumToString, isArrayBuffer, isWebGL1, isWebGL2, loadTextureFromUrl, m4, primitives, programs, resizeCanvasToDisplaySize, resizeFramebufferInfo, resizeTexture, setAttribInfoBufferFromArray, setDefaults as setAttributeDefaults_, setAttributePrefix, setAttributes, setBlockUniforms, setBuffersAndAttributes, setDefaultTextureColor, setDefaults$2 as setDefaults, setEmptyTexture, setSamplerParameters, setDefaults$1 as setTextureDefaults_, setTextureFilteringForSize, setTextureFromArray, setTextureFromElement, setTextureParameters, setUniformBlock, setUniforms, setUniformsAndBindTextures, textures, typedarrays, utils, v3, vertexArrays };
9857
+ export { addExtensionsToContext, attributes, bindFramebufferInfo, bindTransformFeedbackInfo, bindUniformBlock, canFilter, canGenerateMipmap, createAttribsFromArrays, createAttributeSetters, createBufferFromArray, createBufferFromTypedArray, createBufferInfoFromArrays, createBuffersFromArrays, createFramebufferInfo, createProgram, createProgramAsync, createProgramFromScripts, createProgramFromSources, createProgramInfo, createProgramInfoAsync, createProgramInfoFromProgram, createSampler, createSamplers, createTexture, createTextures, createTransformFeedback, createTransformFeedbackInfo, createUniformBlockInfo, createUniformBlockInfoFromProgram, createUniformBlockSpecFromProgram, createUniformSetters, createVAOAndSetAttributes, createVAOFromBufferInfo, createVertexArrayInfo, draw, drawBufferInfo, drawObjectList, framebuffers, getArray as getArray_, getBytesPerElementForInternalFormat, getContext, getFormatAndTypeForInternalFormat, getGLTypeForTypedArray, getGLTypeForTypedArrayType, getNumComponentsForFormat, getNumComponents as getNumComponents_, getTypedArrayTypeForGLType, getWebGLContext, glEnumToString, isArrayBuffer, isWebGL1, isWebGL2, loadTextureFromUrl, m4, primitives, programs, resizeCanvasToDisplaySize, resizeFramebufferInfo, resizeTexture, setAttribInfoBufferFromArray, setDefaults as setAttributeDefaults_, setAttributePrefix, setAttributes, setBlockUniforms, setBuffersAndAttributes, setDefaultTextureColor, setDefaults$2 as setDefaults, setEmptyTexture, setSamplerParameters, setDefaults$1 as setTextureDefaults_, setTextureFilteringForSize, setTextureFromArray, setTextureFromElement, setTextureParameters, setUniformBlock, setUniforms, setUniformsAndBindTextures, textures, typedarrays, utils, v3, vertexArrays };
@@ -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,11 @@ 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;
259
262
  export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
263
+ export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
264
+ export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
260
265
  export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
261
266
  export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
262
267
  export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
@@ -334,7 +339,7 @@ export function createVAOAndSetAttributes(gl: WebGLRenderingContext, setters: {
334
339
  [key: string]: (...params: any[]) => any;
335
340
  }, attribs: {
336
341
  [key: string]: AttribInfo;
337
- }, indices?: WebGLBuffer): void;
342
+ }, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
338
343
  export function createVAOFromBufferInfo(gl: WebGLRenderingContext, programInfo: {
339
344
  [key: string]: (...params: any[]) => any;
340
- } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): void;
345
+ } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): WebGLVertexArrayObject | null;