twgl.js 4.23.0 → 4.24.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/README.md +1 -1
- package/dist/4.x/twgl-full.d.ts +0 -14
- package/dist/4.x/twgl-full.js +114 -62
- package/dist/4.x/twgl-full.module.js +90 -48
- package/dist/4.x/twgl.d.ts +0 -14
- package/dist/4.x/twgl.js +114 -62
- 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.24.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
|
*/
|
|
@@ -651,6 +651,11 @@ function getNumElementsFromNonIndexedArrays(arrays) {
|
|
|
651
651
|
|
|
652
652
|
var array = arrays[key];
|
|
653
653
|
var length = getArray(array).length;
|
|
654
|
+
|
|
655
|
+
if (length === undefined) {
|
|
656
|
+
return 1; // There's no arrays
|
|
657
|
+
}
|
|
658
|
+
|
|
654
659
|
var numComponents = getNumComponents(array, key);
|
|
655
660
|
var numElements = length / numComponents;
|
|
656
661
|
|
|
@@ -684,6 +689,11 @@ function getNumElementsFromAttributes(gl, attribs) {
|
|
|
684
689
|
}
|
|
685
690
|
|
|
686
691
|
var attrib = attribs[key];
|
|
692
|
+
|
|
693
|
+
if (!attrib.buffer) {
|
|
694
|
+
return 1; // There's no buffer
|
|
695
|
+
}
|
|
696
|
+
|
|
687
697
|
gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
|
|
688
698
|
var numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
|
|
689
699
|
gl.bindBuffer(ARRAY_BUFFER, null);
|
|
@@ -1243,6 +1253,12 @@ renderbufferFormats[STENCIL_INDEX8] = true;
|
|
|
1243
1253
|
function isRenderbufferFormat(format) {
|
|
1244
1254
|
return renderbufferFormats[format];
|
|
1245
1255
|
}
|
|
1256
|
+
|
|
1257
|
+
var MAX_COLOR_ATTACHMENT_POINTS = 32; // even an 3090 only supports 8 but WebGL/OpenGL ES define constants for 32
|
|
1258
|
+
|
|
1259
|
+
function isColorAttachmentPoint(attachmentPoint) {
|
|
1260
|
+
return attachmentPoint >= COLOR_ATTACHMENT0 && attachmentPoint < COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENT_POINTS;
|
|
1261
|
+
}
|
|
1246
1262
|
/**
|
|
1247
1263
|
* @typedef {Object} FramebufferInfo
|
|
1248
1264
|
* @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
|
|
@@ -1256,6 +1272,9 @@ function isRenderbufferFormat(format) {
|
|
|
1256
1272
|
* Creates a framebuffer and attachments.
|
|
1257
1273
|
*
|
|
1258
1274
|
* This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
|
|
1275
|
+
* It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
|
|
1276
|
+
* Note: If this is WebGL2 or if you called {@link module:twgl.addExtensionsToContext} then it will set the drawBuffers
|
|
1277
|
+
* to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
|
|
1259
1278
|
*
|
|
1260
1279
|
* The simplest usage
|
|
1261
1280
|
*
|
|
@@ -1297,21 +1316,25 @@ function createFramebufferInfo(gl, attachments, width, height) {
|
|
|
1297
1316
|
width = width || gl.drawingBufferWidth;
|
|
1298
1317
|
height = height || gl.drawingBufferHeight;
|
|
1299
1318
|
attachments = attachments || defaultAttachments;
|
|
1300
|
-
var
|
|
1319
|
+
var usedColorAttachmentsPoints = [];
|
|
1301
1320
|
var framebufferInfo = {
|
|
1302
1321
|
framebuffer: fb,
|
|
1303
1322
|
attachments: [],
|
|
1304
1323
|
width: width,
|
|
1305
1324
|
height: height
|
|
1306
1325
|
};
|
|
1307
|
-
attachments.forEach(function (attachmentOptions) {
|
|
1326
|
+
attachments.forEach(function (attachmentOptions, i) {
|
|
1308
1327
|
var attachment = attachmentOptions.attachment;
|
|
1309
1328
|
var samples = attachmentOptions.samples;
|
|
1310
1329
|
var format = attachmentOptions.format;
|
|
1311
1330
|
var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
|
|
1312
1331
|
|
|
1313
1332
|
if (!attachmentPoint) {
|
|
1314
|
-
attachmentPoint = COLOR_ATTACHMENT0 +
|
|
1333
|
+
attachmentPoint = COLOR_ATTACHMENT0 + i;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
if (isColorAttachmentPoint(attachmentPoint)) {
|
|
1337
|
+
usedColorAttachmentsPoints.push(attachmentPoint);
|
|
1315
1338
|
}
|
|
1316
1339
|
|
|
1317
1340
|
if (!attachment) {
|
|
@@ -1355,6 +1378,11 @@ function createFramebufferInfo(gl, attachments, width, height) {
|
|
|
1355
1378
|
|
|
1356
1379
|
framebufferInfo.attachments.push(attachment);
|
|
1357
1380
|
});
|
|
1381
|
+
|
|
1382
|
+
if (gl.drawBuffers) {
|
|
1383
|
+
gl.drawBuffers(usedColorAttachmentsPoints);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1358
1386
|
return framebufferInfo;
|
|
1359
1387
|
}
|
|
1360
1388
|
/**
|
|
@@ -1725,6 +1753,7 @@ var TEXTURE_2D_ARRAY = 0x8C1A;
|
|
|
1725
1753
|
var typeMap = {};
|
|
1726
1754
|
/**
|
|
1727
1755
|
* Returns the corresponding bind point for a given sampler type
|
|
1756
|
+
* @private
|
|
1728
1757
|
*/
|
|
1729
1758
|
|
|
1730
1759
|
function getBindPointForSamplerType(gl, type) {
|
|
@@ -2444,6 +2473,7 @@ var spaceRE = /^[ \t]*\n/;
|
|
|
2444
2473
|
*
|
|
2445
2474
|
* @param {string} shaderSource The source of the shader
|
|
2446
2475
|
* @returns {{shaderSource: string, lineOffset: number}}
|
|
2476
|
+
* @private
|
|
2447
2477
|
*/
|
|
2448
2478
|
|
|
2449
2479
|
function prepShaderSource(shaderSource) {
|
|
@@ -2459,31 +2489,59 @@ function prepShaderSource(shaderSource) {
|
|
|
2459
2489
|
shaderSource: shaderSource
|
|
2460
2490
|
};
|
|
2461
2491
|
}
|
|
2492
|
+
/**
|
|
2493
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
2494
|
+
* @param {string} msg
|
|
2495
|
+
* @return null
|
|
2496
|
+
* @private
|
|
2497
|
+
*/
|
|
2498
|
+
|
|
2499
|
+
|
|
2500
|
+
function reportError(progOptions, msg) {
|
|
2501
|
+
progOptions.errorCallback(msg);
|
|
2502
|
+
|
|
2503
|
+
if (progOptions.callback) {
|
|
2504
|
+
setTimeout(function () {
|
|
2505
|
+
progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
return null;
|
|
2510
|
+
}
|
|
2462
2511
|
/**
|
|
2463
2512
|
* Loads a shader.
|
|
2464
2513
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2465
2514
|
* @param {string} shaderSource The shader source.
|
|
2466
2515
|
* @param {number} shaderType The type of shader.
|
|
2516
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
2467
2517
|
* @return {WebGLShader} The created shader.
|
|
2468
2518
|
* @private
|
|
2469
2519
|
*/
|
|
2470
2520
|
|
|
2471
2521
|
|
|
2472
|
-
function loadShader(gl, shaderSource, shaderType) {
|
|
2522
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
2473
2523
|
// Create the shader object
|
|
2474
2524
|
var shader = gl.createShader(shaderType); // Load the shader source
|
|
2475
2525
|
|
|
2476
2526
|
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
|
|
2477
2527
|
|
|
2478
2528
|
gl.compileShader(shader);
|
|
2529
|
+
|
|
2530
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
2531
|
+
gl.deleteShader(shader);
|
|
2532
|
+
return null;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2479
2535
|
return shader;
|
|
2480
2536
|
}
|
|
2481
2537
|
/**
|
|
2482
2538
|
* Check Shader status
|
|
2483
2539
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2540
|
+
* @param {number} shaderType The shader type
|
|
2484
2541
|
* @param {WebGLShader} shader The shader
|
|
2485
2542
|
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
2486
|
-
* @
|
|
2543
|
+
* @return {bool} true if shader is ok.
|
|
2544
|
+
* @private
|
|
2487
2545
|
*/
|
|
2488
2546
|
|
|
2489
2547
|
|
|
@@ -2496,13 +2554,11 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
2496
2554
|
// Something went wrong during compilation; get the error
|
|
2497
2555
|
var lastError = gl.getShaderInfoLog(shader);
|
|
2498
2556
|
|
|
2499
|
-
var _shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
2500
|
-
|
|
2501
2557
|
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
2502
2558
|
lineOffset = _prepShaderSource.lineOffset,
|
|
2503
2559
|
shaderSource = _prepShaderSource.shaderSource;
|
|
2504
2560
|
|
|
2505
|
-
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl,
|
|
2561
|
+
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
|
|
2506
2562
|
}
|
|
2507
2563
|
|
|
2508
2564
|
return compiled;
|
|
@@ -2546,7 +2602,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2546
2602
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
2547
2603
|
// If we have an errorCallback we can just return this object
|
|
2548
2604
|
// Otherwise we need to construct one with default errorCallback
|
|
2549
|
-
if (opt_attribs.errorCallback) {
|
|
2605
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
2550
2606
|
return opt_attribs;
|
|
2551
2607
|
}
|
|
2552
2608
|
|
|
@@ -2558,11 +2614,23 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2558
2614
|
callback = opt.callback;
|
|
2559
2615
|
}
|
|
2560
2616
|
|
|
2617
|
+
var _errorCallback = opt_errorCallback || error;
|
|
2618
|
+
|
|
2619
|
+
var errors = [];
|
|
2561
2620
|
var options = {
|
|
2562
|
-
errorCallback:
|
|
2621
|
+
errorCallback: function errorCallback(msg) {
|
|
2622
|
+
errors.push(msg);
|
|
2623
|
+
|
|
2624
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2625
|
+
args[_key - 1] = arguments[_key];
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
_errorCallback.apply(void 0, [msg].concat(args));
|
|
2629
|
+
},
|
|
2563
2630
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
2564
2631
|
transformFeedbackMode: transformFeedbackMode,
|
|
2565
|
-
callback: callback
|
|
2632
|
+
callback: callback,
|
|
2633
|
+
errors: errors
|
|
2566
2634
|
};
|
|
2567
2635
|
|
|
2568
2636
|
if (opt_attribs) {
|
|
@@ -2608,7 +2676,7 @@ var wait = function wait() {
|
|
|
2608
2676
|
};
|
|
2609
2677
|
/**
|
|
2610
2678
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
2611
|
-
* program
|
|
2679
|
+
* program.
|
|
2612
2680
|
*
|
|
2613
2681
|
* NOTE: There are 4 signatures for this function
|
|
2614
2682
|
*
|
|
@@ -2623,7 +2691,7 @@ var wait = function wait() {
|
|
|
2623
2691
|
* @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.
|
|
2624
2692
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2625
2693
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
2626
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
2694
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
2627
2695
|
* @memberOf module:twgl/programs
|
|
2628
2696
|
*/
|
|
2629
2697
|
|
|
@@ -2647,13 +2715,7 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2647
2715
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
2648
2716
|
}
|
|
2649
2717
|
|
|
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
|
-
|
|
2718
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
2657
2719
|
newShaders.push(shader);
|
|
2658
2720
|
}
|
|
2659
2721
|
|
|
@@ -2663,9 +2725,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2663
2725
|
}
|
|
2664
2726
|
|
|
2665
2727
|
if (realShaders.length !== shaders.length) {
|
|
2666
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
2667
2728
|
deleteShaders(gl, newShaders);
|
|
2668
|
-
return
|
|
2729
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
2669
2730
|
}
|
|
2670
2731
|
|
|
2671
2732
|
var program = gl.createProgram();
|
|
@@ -2730,8 +2791,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2730
2791
|
|
|
2731
2792
|
|
|
2732
2793
|
function createProgramAsync(gl, shaders) {
|
|
2733
|
-
for (var
|
|
2734
|
-
args[
|
|
2794
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
2795
|
+
args[_key2 - 2] = arguments[_key2];
|
|
2735
2796
|
}
|
|
2736
2797
|
|
|
2737
2798
|
return new Promise(function (resolve, reject) {
|
|
@@ -2745,7 +2806,7 @@ function createProgramAsync(gl, shaders) {
|
|
|
2745
2806
|
}
|
|
2746
2807
|
};
|
|
2747
2808
|
|
|
2748
|
-
|
|
2809
|
+
createProgram(gl, shaders, programOptions);
|
|
2749
2810
|
});
|
|
2750
2811
|
}
|
|
2751
2812
|
/**
|
|
@@ -2765,8 +2826,8 @@ function createProgramAsync(gl, shaders) {
|
|
|
2765
2826
|
|
|
2766
2827
|
|
|
2767
2828
|
function createProgramInfoAsync(gl, shaders) {
|
|
2768
|
-
for (var
|
|
2769
|
-
args[
|
|
2829
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2830
|
+
args[_key3 - 2] = arguments[_key3];
|
|
2770
2831
|
}
|
|
2771
2832
|
|
|
2772
2833
|
return new Promise(function (resolve, reject) {
|
|
@@ -2780,7 +2841,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
2780
2841
|
}
|
|
2781
2842
|
};
|
|
2782
2843
|
|
|
2783
|
-
|
|
2844
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
2784
2845
|
});
|
|
2785
2846
|
}
|
|
2786
2847
|
/**
|
|
@@ -2790,6 +2851,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
2790
2851
|
* @param {WebGLRenderingContext} gl The context
|
|
2791
2852
|
* @param {WebGLProgram} program The program
|
|
2792
2853
|
* @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
|
|
2854
|
+
* @private
|
|
2793
2855
|
*/
|
|
2794
2856
|
|
|
2795
2857
|
|
|
@@ -2802,12 +2864,13 @@ function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
|
2802
2864
|
* @param {WebGLProgram} program Program to check
|
|
2803
2865
|
* @param {ErrorCallback} [errFn] func for errors
|
|
2804
2866
|
* @return {bool} true if program is ok
|
|
2867
|
+
* @private
|
|
2805
2868
|
*/
|
|
2806
2869
|
|
|
2807
2870
|
|
|
2808
2871
|
function _checkForProgramLinkCompletionAsync() {
|
|
2809
2872
|
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
|
|
2810
|
-
var ext, checkFn, waitTime,
|
|
2873
|
+
var ext, checkFn, waitTime, success, err, errFn;
|
|
2811
2874
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
2812
2875
|
while (1) {
|
|
2813
2876
|
switch (_context.prev = _context.next) {
|
|
@@ -2835,11 +2898,8 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
2835
2898
|
}
|
|
2836
2899
|
|
|
2837
2900
|
case 7:
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
return errMsgs.push(msg);
|
|
2841
|
-
});
|
|
2842
|
-
err = success ? undefined : errMsgs.join('\n');
|
|
2901
|
+
success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
2902
|
+
err = success ? undefined : progOptions.errors.join('\n');
|
|
2843
2903
|
|
|
2844
2904
|
if (!success) {
|
|
2845
2905
|
errFn = progOptions.errorCallback || error;
|
|
@@ -2852,7 +2912,7 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
2852
2912
|
|
|
2853
2913
|
progOptions.callback(err, program);
|
|
2854
2914
|
|
|
2855
|
-
case
|
|
2915
|
+
case 11:
|
|
2856
2916
|
case "end":
|
|
2857
2917
|
return _context.stop();
|
|
2858
2918
|
}
|
|
@@ -2870,16 +2930,7 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
2870
2930
|
if (!linked) {
|
|
2871
2931
|
// something went wrong with the link
|
|
2872
2932
|
var lastError = gl.getProgramInfoLog(program);
|
|
2873
|
-
errFn("".concat(
|
|
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);
|
|
2880
|
-
var type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
2881
|
-
return "".concat(utils.glEnumToString(gl, type), "\n").concat(src, "}");
|
|
2882
|
-
}).join('\n'), "\nError in program linking: ").concat(lastError));
|
|
2933
|
+
errFn("Error in program linking: ".concat(lastError));
|
|
2883
2934
|
}
|
|
2884
2935
|
|
|
2885
2936
|
return linked;
|
|
@@ -2890,28 +2941,28 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
2890
2941
|
* @param {string} scriptId The id of the script tag.
|
|
2891
2942
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
2892
2943
|
* be derived from the type of the script tag.
|
|
2893
|
-
* @param {module:twgl.
|
|
2944
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
2894
2945
|
* @return {WebGLShader?} The created shader or null if error.
|
|
2895
2946
|
* @private
|
|
2896
2947
|
*/
|
|
2897
2948
|
|
|
2898
2949
|
|
|
2899
|
-
function createShaderFromScript(gl, scriptId, opt_shaderType,
|
|
2950
|
+
function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
2900
2951
|
var shaderSource = "";
|
|
2901
2952
|
var shaderScript = getElementById(scriptId);
|
|
2902
2953
|
|
|
2903
2954
|
if (!shaderScript) {
|
|
2904
|
-
|
|
2955
|
+
return reportError(progOptions, "unknown script element: ".concat(scriptId));
|
|
2905
2956
|
}
|
|
2906
2957
|
|
|
2907
2958
|
shaderSource = shaderScript.text;
|
|
2908
2959
|
var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
2909
2960
|
|
|
2910
2961
|
if (!shaderType) {
|
|
2911
|
-
|
|
2962
|
+
return reportError(progOptions, 'unknown shader type');
|
|
2912
2963
|
}
|
|
2913
2964
|
|
|
2914
|
-
return loadShader(gl, shaderSource, shaderType,
|
|
2965
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
2915
2966
|
}
|
|
2916
2967
|
/**
|
|
2917
2968
|
* Creates a program from 2 script tags.
|
|
@@ -2932,7 +2983,7 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback)
|
|
|
2932
2983
|
* @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.
|
|
2933
2984
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2934
2985
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
2935
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
2986
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
2936
2987
|
* @memberOf module:twgl/programs
|
|
2937
2988
|
*/
|
|
2938
2989
|
|
|
@@ -2942,7 +2993,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
2942
2993
|
var shaders = [];
|
|
2943
2994
|
|
|
2944
2995
|
for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
2945
|
-
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
2996
|
+
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
2946
2997
|
|
|
2947
2998
|
if (!shader) {
|
|
2948
2999
|
return null;
|
|
@@ -2972,7 +3023,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
2972
3023
|
* @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.
|
|
2973
3024
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2974
3025
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
2975
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
3026
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
2976
3027
|
* @memberOf module:twgl/programs
|
|
2977
3028
|
*/
|
|
2978
3029
|
|
|
@@ -2982,9 +3033,9 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
|
|
|
2982
3033
|
var shaders = [];
|
|
2983
3034
|
|
|
2984
3035
|
for (var ii = 0; ii < shaderSources.length; ++ii) {
|
|
2985
|
-
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions
|
|
3036
|
+
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
2986
3037
|
|
|
2987
|
-
if (!shader) {
|
|
3038
|
+
if (!progOptions.callback && !shader) {
|
|
2988
3039
|
return null;
|
|
2989
3040
|
}
|
|
2990
3041
|
|
|
@@ -3952,6 +4003,7 @@ function createAttributeSetters(gl, program) {
|
|
|
3952
4003
|
* @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
|
|
3953
4004
|
* @memberOf module:twgl/programs
|
|
3954
4005
|
* @deprecated use {@link module:twgl.setBuffersAndAttributes}
|
|
4006
|
+
* @private
|
|
3955
4007
|
*/
|
|
3956
4008
|
|
|
3957
4009
|
|
|
@@ -4113,11 +4165,7 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4113
4165
|
});
|
|
4114
4166
|
|
|
4115
4167
|
if (errors.length) {
|
|
4116
|
-
|
|
4117
|
-
progOptions.callback(errors.join('\n'));
|
|
4118
|
-
}
|
|
4119
|
-
|
|
4120
|
-
return null;
|
|
4168
|
+
return reportError(progOptions, '');
|
|
4121
4169
|
}
|
|
4122
4170
|
|
|
4123
4171
|
var origCallback = progOptions.callback;
|
|
@@ -4137,7 +4185,6 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4137
4185
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
4138
4186
|
|
|
4139
4187
|
if (!program) {
|
|
4140
|
-
// we should never get if if we have a callback
|
|
4141
4188
|
return null;
|
|
4142
4189
|
}
|
|
4143
4190
|
|
|
@@ -5793,6 +5840,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
|
|
|
5793
5840
|
* @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
|
|
5794
5841
|
* This is often the same options you passed in when you created the texture.
|
|
5795
5842
|
* @memberOf module:twgl/textures
|
|
5843
|
+
* @private
|
|
5796
5844
|
*/
|
|
5797
5845
|
|
|
5798
5846
|
|
|
@@ -5907,6 +5955,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
|
|
|
5907
5955
|
* @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
5908
5956
|
* be non null if there was an error.
|
|
5909
5957
|
* @memberOf module:twgl/textures
|
|
5958
|
+
* @private
|
|
5910
5959
|
*/
|
|
5911
5960
|
|
|
5912
5961
|
|
|
@@ -5995,6 +6044,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
5995
6044
|
* @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
5996
6045
|
* be non null if there was an error.
|
|
5997
6046
|
* @memberOf module:twgl/textures
|
|
6047
|
+
* @private
|
|
5998
6048
|
*/
|
|
5999
6049
|
|
|
6000
6050
|
|
|
@@ -6879,6 +6929,8 @@ function create3DContext(canvas, opt_attribs) {
|
|
|
6879
6929
|
* @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
|
|
6880
6930
|
* @return {WebGLRenderingContext} The created context.
|
|
6881
6931
|
* @memberOf module:twgl
|
|
6932
|
+
* @deprecated
|
|
6933
|
+
* @private
|
|
6882
6934
|
*/
|
|
6883
6935
|
|
|
6884
6936
|
|