twgl.js 4.23.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.
- package/dist/4.x/twgl-full.d.ts +0 -3
- package/dist/4.x/twgl-full.js +75 -59
- package/dist/4.x/twgl-full.module.js +57 -45
- package/dist/4.x/twgl.d.ts +0 -3
- package/dist/4.x/twgl.js +75 -59
- package/package.json +1 -1
package/dist/4.x/twgl-full.d.ts
CHANGED
|
@@ -259,12 +259,9 @@ export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?:
|
|
|
259
259
|
export function getBindPointForSamplerType(): void;
|
|
260
260
|
export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo) => void;
|
|
261
261
|
export function prepShaderSource(shaderSource: string): any;
|
|
262
|
-
export function checkShaderStatus(gl: WebGLRenderingContext, shader: WebGLShader, errFn?: ErrorCallback): boolean;
|
|
263
262
|
export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
264
263
|
export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
|
|
265
264
|
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;
|
|
268
265
|
export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
269
266
|
export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
270
267
|
export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
|
package/dist/4.x/twgl-full.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @license twgl.js 4.23.
|
|
2
|
+
* @license twgl.js 4.23.1 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
|
*/
|
|
@@ -5548,31 +5548,59 @@ function prepShaderSource(shaderSource) {
|
|
|
5548
5548
|
shaderSource: shaderSource
|
|
5549
5549
|
};
|
|
5550
5550
|
}
|
|
5551
|
+
/**
|
|
5552
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
5553
|
+
* @param {string} msg
|
|
5554
|
+
* @return null
|
|
5555
|
+
* @private
|
|
5556
|
+
*/
|
|
5557
|
+
|
|
5558
|
+
|
|
5559
|
+
function reportError(progOptions, msg) {
|
|
5560
|
+
progOptions.errorCallback(msg);
|
|
5561
|
+
|
|
5562
|
+
if (progOptions.callback) {
|
|
5563
|
+
setTimeout(function () {
|
|
5564
|
+
progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
|
|
5565
|
+
});
|
|
5566
|
+
}
|
|
5567
|
+
|
|
5568
|
+
return null;
|
|
5569
|
+
}
|
|
5551
5570
|
/**
|
|
5552
5571
|
* Loads a shader.
|
|
5553
5572
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5554
5573
|
* @param {string} shaderSource The shader source.
|
|
5555
5574
|
* @param {number} shaderType The type of shader.
|
|
5575
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
5556
5576
|
* @return {WebGLShader} The created shader.
|
|
5557
5577
|
* @private
|
|
5558
5578
|
*/
|
|
5559
5579
|
|
|
5560
5580
|
|
|
5561
|
-
function loadShader(gl, shaderSource, shaderType) {
|
|
5581
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
5562
5582
|
// Create the shader object
|
|
5563
5583
|
var shader = gl.createShader(shaderType); // Load the shader source
|
|
5564
5584
|
|
|
5565
5585
|
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
|
|
5566
5586
|
|
|
5567
5587
|
gl.compileShader(shader);
|
|
5588
|
+
|
|
5589
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
5590
|
+
gl.deleteShader(shader);
|
|
5591
|
+
return null;
|
|
5592
|
+
}
|
|
5593
|
+
|
|
5568
5594
|
return shader;
|
|
5569
5595
|
}
|
|
5570
5596
|
/**
|
|
5571
5597
|
* Check Shader status
|
|
5572
5598
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5599
|
+
* @param {number} shaderType The shader type
|
|
5573
5600
|
* @param {WebGLShader} shader The shader
|
|
5574
5601
|
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
5575
|
-
* @
|
|
5602
|
+
* @return {bool} true if shader is ok.
|
|
5603
|
+
* @private
|
|
5576
5604
|
*/
|
|
5577
5605
|
|
|
5578
5606
|
|
|
@@ -5585,13 +5613,11 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
5585
5613
|
// Something went wrong during compilation; get the error
|
|
5586
5614
|
var lastError = gl.getShaderInfoLog(shader);
|
|
5587
5615
|
|
|
5588
|
-
var _shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
5589
|
-
|
|
5590
5616
|
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
5591
5617
|
lineOffset = _prepShaderSource.lineOffset,
|
|
5592
5618
|
shaderSource = _prepShaderSource.shaderSource;
|
|
5593
5619
|
|
|
5594
|
-
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl,
|
|
5620
|
+
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
|
|
5595
5621
|
}
|
|
5596
5622
|
|
|
5597
5623
|
return compiled;
|
|
@@ -5635,7 +5661,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
5635
5661
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
5636
5662
|
// If we have an errorCallback we can just return this object
|
|
5637
5663
|
// Otherwise we need to construct one with default errorCallback
|
|
5638
|
-
if (opt_attribs.errorCallback) {
|
|
5664
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
5639
5665
|
return opt_attribs;
|
|
5640
5666
|
}
|
|
5641
5667
|
|
|
@@ -5647,11 +5673,23 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
5647
5673
|
callback = opt.callback;
|
|
5648
5674
|
}
|
|
5649
5675
|
|
|
5676
|
+
var _errorCallback = opt_errorCallback || error;
|
|
5677
|
+
|
|
5678
|
+
var errors = [];
|
|
5650
5679
|
var options = {
|
|
5651
|
-
errorCallback:
|
|
5680
|
+
errorCallback: function errorCallback(msg) {
|
|
5681
|
+
errors.push(msg);
|
|
5682
|
+
|
|
5683
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
5684
|
+
args[_key - 1] = arguments[_key];
|
|
5685
|
+
}
|
|
5686
|
+
|
|
5687
|
+
_errorCallback.apply(void 0, [msg].concat(args));
|
|
5688
|
+
},
|
|
5652
5689
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
5653
5690
|
transformFeedbackMode: transformFeedbackMode,
|
|
5654
|
-
callback: callback
|
|
5691
|
+
callback: callback,
|
|
5692
|
+
errors: errors
|
|
5655
5693
|
};
|
|
5656
5694
|
|
|
5657
5695
|
if (opt_attribs) {
|
|
@@ -5697,7 +5735,7 @@ var wait = function wait() {
|
|
|
5697
5735
|
};
|
|
5698
5736
|
/**
|
|
5699
5737
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
5700
|
-
* program
|
|
5738
|
+
* program.
|
|
5701
5739
|
*
|
|
5702
5740
|
* NOTE: There are 4 signatures for this function
|
|
5703
5741
|
*
|
|
@@ -5712,7 +5750,7 @@ var wait = function wait() {
|
|
|
5712
5750
|
* @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.
|
|
5713
5751
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5714
5752
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
5715
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
5753
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
5716
5754
|
* @memberOf module:twgl/programs
|
|
5717
5755
|
*/
|
|
5718
5756
|
|
|
@@ -5736,13 +5774,7 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5736
5774
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
5737
5775
|
}
|
|
5738
5776
|
|
|
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
|
-
|
|
5777
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
5746
5778
|
newShaders.push(shader);
|
|
5747
5779
|
}
|
|
5748
5780
|
|
|
@@ -5752,9 +5784,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5752
5784
|
}
|
|
5753
5785
|
|
|
5754
5786
|
if (realShaders.length !== shaders.length) {
|
|
5755
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
5756
5787
|
deleteShaders(gl, newShaders);
|
|
5757
|
-
return
|
|
5788
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
5758
5789
|
}
|
|
5759
5790
|
|
|
5760
5791
|
var program = gl.createProgram();
|
|
@@ -5819,8 +5850,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5819
5850
|
|
|
5820
5851
|
|
|
5821
5852
|
function createProgramAsync(gl, shaders) {
|
|
5822
|
-
for (var
|
|
5823
|
-
args[
|
|
5853
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
5854
|
+
args[_key2 - 2] = arguments[_key2];
|
|
5824
5855
|
}
|
|
5825
5856
|
|
|
5826
5857
|
return new Promise(function (resolve, reject) {
|
|
@@ -5834,7 +5865,7 @@ function createProgramAsync(gl, shaders) {
|
|
|
5834
5865
|
}
|
|
5835
5866
|
};
|
|
5836
5867
|
|
|
5837
|
-
|
|
5868
|
+
createProgram(gl, shaders, programOptions);
|
|
5838
5869
|
});
|
|
5839
5870
|
}
|
|
5840
5871
|
/**
|
|
@@ -5854,8 +5885,8 @@ function createProgramAsync(gl, shaders) {
|
|
|
5854
5885
|
|
|
5855
5886
|
|
|
5856
5887
|
function createProgramInfoAsync(gl, shaders) {
|
|
5857
|
-
for (var
|
|
5858
|
-
args[
|
|
5888
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
5889
|
+
args[_key3 - 2] = arguments[_key3];
|
|
5859
5890
|
}
|
|
5860
5891
|
|
|
5861
5892
|
return new Promise(function (resolve, reject) {
|
|
@@ -5869,7 +5900,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
5869
5900
|
}
|
|
5870
5901
|
};
|
|
5871
5902
|
|
|
5872
|
-
|
|
5903
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
5873
5904
|
});
|
|
5874
5905
|
}
|
|
5875
5906
|
/**
|
|
@@ -5879,6 +5910,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
5879
5910
|
* @param {WebGLRenderingContext} gl The context
|
|
5880
5911
|
* @param {WebGLProgram} program The program
|
|
5881
5912
|
* @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
|
|
5913
|
+
* @private
|
|
5882
5914
|
*/
|
|
5883
5915
|
|
|
5884
5916
|
|
|
@@ -5891,12 +5923,13 @@ function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
|
5891
5923
|
* @param {WebGLProgram} program Program to check
|
|
5892
5924
|
* @param {ErrorCallback} [errFn] func for errors
|
|
5893
5925
|
* @return {bool} true if program is ok
|
|
5926
|
+
* @private
|
|
5894
5927
|
*/
|
|
5895
5928
|
|
|
5896
5929
|
|
|
5897
5930
|
function _checkForProgramLinkCompletionAsync() {
|
|
5898
5931
|
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
|
|
5899
|
-
var ext, checkFn, waitTime,
|
|
5932
|
+
var ext, checkFn, waitTime, success, err, errFn;
|
|
5900
5933
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
5901
5934
|
while (1) {
|
|
5902
5935
|
switch (_context.prev = _context.next) {
|
|
@@ -5924,11 +5957,8 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
5924
5957
|
}
|
|
5925
5958
|
|
|
5926
5959
|
case 7:
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
return errMsgs.push(msg);
|
|
5930
|
-
});
|
|
5931
|
-
err = success ? undefined : errMsgs.join('\n');
|
|
5960
|
+
success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
5961
|
+
err = success ? undefined : progOptions.errors.join('\n');
|
|
5932
5962
|
|
|
5933
5963
|
if (!success) {
|
|
5934
5964
|
errFn = progOptions.errorCallback || error;
|
|
@@ -5941,7 +5971,7 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
5941
5971
|
|
|
5942
5972
|
progOptions.callback(err, program);
|
|
5943
5973
|
|
|
5944
|
-
case
|
|
5974
|
+
case 11:
|
|
5945
5975
|
case "end":
|
|
5946
5976
|
return _context.stop();
|
|
5947
5977
|
}
|
|
@@ -5959,16 +5989,7 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
5959
5989
|
if (!linked) {
|
|
5960
5990
|
// something went wrong with the link
|
|
5961
5991
|
var lastError = gl.getProgramInfoLog(program);
|
|
5962
|
-
errFn("".concat(
|
|
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);
|
|
5969
|
-
var type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
5970
|
-
return "".concat(utils.glEnumToString(gl, type), "\n").concat(src, "}");
|
|
5971
|
-
}).join('\n'), "\nError in program linking: ").concat(lastError));
|
|
5992
|
+
errFn("Error in program linking: ".concat(lastError));
|
|
5972
5993
|
}
|
|
5973
5994
|
|
|
5974
5995
|
return linked;
|
|
@@ -5979,28 +6000,28 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
5979
6000
|
* @param {string} scriptId The id of the script tag.
|
|
5980
6001
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
5981
6002
|
* be derived from the type of the script tag.
|
|
5982
|
-
* @param {module:twgl.
|
|
6003
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
5983
6004
|
* @return {WebGLShader?} The created shader or null if error.
|
|
5984
6005
|
* @private
|
|
5985
6006
|
*/
|
|
5986
6007
|
|
|
5987
6008
|
|
|
5988
|
-
function createShaderFromScript(gl, scriptId, opt_shaderType,
|
|
6009
|
+
function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
5989
6010
|
var shaderSource = "";
|
|
5990
6011
|
var shaderScript = getElementById(scriptId);
|
|
5991
6012
|
|
|
5992
6013
|
if (!shaderScript) {
|
|
5993
|
-
|
|
6014
|
+
return reportError(progOptions, "unknown script element: ".concat(scriptId));
|
|
5994
6015
|
}
|
|
5995
6016
|
|
|
5996
6017
|
shaderSource = shaderScript.text;
|
|
5997
6018
|
var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
5998
6019
|
|
|
5999
6020
|
if (!shaderType) {
|
|
6000
|
-
|
|
6021
|
+
return reportError(progOptions, 'unknown shader type');
|
|
6001
6022
|
}
|
|
6002
6023
|
|
|
6003
|
-
return loadShader(gl, shaderSource, shaderType,
|
|
6024
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
6004
6025
|
}
|
|
6005
6026
|
/**
|
|
6006
6027
|
* Creates a program from 2 script tags.
|
|
@@ -6021,7 +6042,7 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback)
|
|
|
6021
6042
|
* @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.
|
|
6022
6043
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
6023
6044
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
6024
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
6045
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
6025
6046
|
* @memberOf module:twgl/programs
|
|
6026
6047
|
*/
|
|
6027
6048
|
|
|
@@ -6031,7 +6052,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
6031
6052
|
var shaders = [];
|
|
6032
6053
|
|
|
6033
6054
|
for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
6034
|
-
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
6055
|
+
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
6035
6056
|
|
|
6036
6057
|
if (!shader) {
|
|
6037
6058
|
return null;
|
|
@@ -6061,7 +6082,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
6061
6082
|
* @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.
|
|
6062
6083
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
6063
6084
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
6064
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
6085
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
6065
6086
|
* @memberOf module:twgl/programs
|
|
6066
6087
|
*/
|
|
6067
6088
|
|
|
@@ -6071,9 +6092,9 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
|
|
|
6071
6092
|
var shaders = [];
|
|
6072
6093
|
|
|
6073
6094
|
for (var ii = 0; ii < shaderSources.length; ++ii) {
|
|
6074
|
-
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions
|
|
6095
|
+
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
6075
6096
|
|
|
6076
|
-
if (!shader) {
|
|
6097
|
+
if (!progOptions.callback && !shader) {
|
|
6077
6098
|
return null;
|
|
6078
6099
|
}
|
|
6079
6100
|
|
|
@@ -7202,11 +7223,7 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
7202
7223
|
});
|
|
7203
7224
|
|
|
7204
7225
|
if (errors.length) {
|
|
7205
|
-
|
|
7206
|
-
progOptions.callback(errors.join('\n'));
|
|
7207
|
-
}
|
|
7208
|
-
|
|
7209
|
-
return null;
|
|
7226
|
+
return reportError(progOptions, '');
|
|
7210
7227
|
}
|
|
7211
7228
|
|
|
7212
7229
|
var origCallback = progOptions.callback;
|
|
@@ -7226,7 +7243,6 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
7226
7243
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
7227
7244
|
|
|
7228
7245
|
if (!program) {
|
|
7229
|
-
// we should never get if if we have a callback
|
|
7230
7246
|
return null;
|
|
7231
7247
|
}
|
|
7232
7248
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @license twgl.js 4.23.
|
|
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
|
/*
|
|
@@ -7286,15 +7286,32 @@ function prepShaderSource(shaderSource) {
|
|
|
7286
7286
|
return {lineOffset, shaderSource};
|
|
7287
7287
|
}
|
|
7288
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
|
+
|
|
7289
7305
|
/**
|
|
7290
7306
|
* Loads a shader.
|
|
7291
7307
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
7292
7308
|
* @param {string} shaderSource The shader source.
|
|
7293
7309
|
* @param {number} shaderType The type of shader.
|
|
7310
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
7294
7311
|
* @return {WebGLShader} The created shader.
|
|
7295
7312
|
* @private
|
|
7296
7313
|
*/
|
|
7297
|
-
function loadShader(gl, shaderSource, shaderType) {
|
|
7314
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
7298
7315
|
// Create the shader object
|
|
7299
7316
|
const shader = gl.createShader(shaderType);
|
|
7300
7317
|
|
|
@@ -7304,15 +7321,22 @@ function loadShader(gl, shaderSource, shaderType) {
|
|
|
7304
7321
|
// Compile the shader
|
|
7305
7322
|
gl.compileShader(shader);
|
|
7306
7323
|
|
|
7324
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
7325
|
+
gl.deleteShader(shader);
|
|
7326
|
+
return null;
|
|
7327
|
+
}
|
|
7328
|
+
|
|
7307
7329
|
return shader;
|
|
7308
7330
|
}
|
|
7309
7331
|
|
|
7310
7332
|
/**
|
|
7311
7333
|
* Check Shader status
|
|
7312
7334
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
7335
|
+
* @param {number} shaderType The shader type
|
|
7313
7336
|
* @param {WebGLShader} shader The shader
|
|
7314
7337
|
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
7315
|
-
* @
|
|
7338
|
+
* @return {bool} true if shader is ok.
|
|
7339
|
+
* @private
|
|
7316
7340
|
*/
|
|
7317
7341
|
function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
7318
7342
|
errFn = errFn || error$1;
|
|
@@ -7321,7 +7345,6 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
7321
7345
|
if (!compiled) {
|
|
7322
7346
|
// Something went wrong during compilation; get the error
|
|
7323
7347
|
const lastError = gl.getShaderInfoLog(shader);
|
|
7324
|
-
const shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
7325
7348
|
const {lineOffset, shaderSource} = prepShaderSource(gl.getShaderSource(shader));
|
|
7326
7349
|
errFn(`${addLineNumbersWithError(shaderSource, lastError, lineOffset)}\nError compiling ${glEnumToString(gl, shaderType)}: ${lastError}`);
|
|
7327
7350
|
}
|
|
@@ -7363,7 +7386,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
7363
7386
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
7364
7387
|
// If we have an errorCallback we can just return this object
|
|
7365
7388
|
// Otherwise we need to construct one with default errorCallback
|
|
7366
|
-
if (opt_attribs.errorCallback) {
|
|
7389
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
7367
7390
|
return opt_attribs;
|
|
7368
7391
|
}
|
|
7369
7392
|
const opt = opt_attribs;
|
|
@@ -7374,11 +7397,17 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
7374
7397
|
callback = opt.callback;
|
|
7375
7398
|
}
|
|
7376
7399
|
|
|
7400
|
+
const errorCallback = opt_errorCallback || error$1;
|
|
7401
|
+
const errors = [];
|
|
7377
7402
|
const options = {
|
|
7378
|
-
errorCallback
|
|
7403
|
+
errorCallback(msg, ...args) {
|
|
7404
|
+
errors.push(msg);
|
|
7405
|
+
errorCallback(msg, ...args);
|
|
7406
|
+
},
|
|
7379
7407
|
transformFeedbackVaryings,
|
|
7380
7408
|
transformFeedbackMode,
|
|
7381
7409
|
callback,
|
|
7410
|
+
errors,
|
|
7382
7411
|
};
|
|
7383
7412
|
|
|
7384
7413
|
if (opt_attribs) {
|
|
@@ -7420,7 +7449,7 @@ const wait = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
7420
7449
|
|
|
7421
7450
|
/**
|
|
7422
7451
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
7423
|
-
* program
|
|
7452
|
+
* program.
|
|
7424
7453
|
*
|
|
7425
7454
|
* NOTE: There are 4 signatures for this function
|
|
7426
7455
|
*
|
|
@@ -7435,7 +7464,7 @@ const wait = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
7435
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.
|
|
7436
7465
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
7437
7466
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
7438
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
7467
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
7439
7468
|
* @memberOf module:twgl/programs
|
|
7440
7469
|
*/
|
|
7441
7470
|
function createProgram(
|
|
@@ -7454,11 +7483,7 @@ function createProgram(
|
|
|
7454
7483
|
if (elem && elem.type) {
|
|
7455
7484
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
7456
7485
|
}
|
|
7457
|
-
shader = loadShader(gl, src, type);
|
|
7458
|
-
if (!progOptions.callback && !checkShaderStatus(gl, shader, opt_errorCallback)) {
|
|
7459
|
-
gl.deleteShader(shader);
|
|
7460
|
-
shader = null;
|
|
7461
|
-
}
|
|
7486
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
7462
7487
|
newShaders.push(shader);
|
|
7463
7488
|
}
|
|
7464
7489
|
if (isShader(gl, shader)) {
|
|
@@ -7467,9 +7492,8 @@ function createProgram(
|
|
|
7467
7492
|
}
|
|
7468
7493
|
|
|
7469
7494
|
if (realShaders.length !== shaders.length) {
|
|
7470
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
7471
7495
|
deleteShaders(gl, newShaders);
|
|
7472
|
-
return
|
|
7496
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
7473
7497
|
}
|
|
7474
7498
|
|
|
7475
7499
|
const program = gl.createProgram();
|
|
@@ -7535,7 +7559,7 @@ function createProgramAsync(gl, shaders, ...args) {
|
|
|
7535
7559
|
resolve(program);
|
|
7536
7560
|
}
|
|
7537
7561
|
};
|
|
7538
|
-
|
|
7562
|
+
createProgram(gl, shaders, programOptions);
|
|
7539
7563
|
});
|
|
7540
7564
|
}
|
|
7541
7565
|
|
|
@@ -7563,7 +7587,7 @@ function createProgramInfoAsync(gl, shaders, ...args) {
|
|
|
7563
7587
|
resolve(programInfo);
|
|
7564
7588
|
}
|
|
7565
7589
|
};
|
|
7566
|
-
|
|
7590
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
7567
7591
|
});
|
|
7568
7592
|
}
|
|
7569
7593
|
|
|
@@ -7575,6 +7599,7 @@ function createProgramInfoAsync(gl, shaders, ...args) {
|
|
|
7575
7599
|
* @param {WebGLRenderingContext} gl The context
|
|
7576
7600
|
* @param {WebGLProgram} program The program
|
|
7577
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
|
|
7578
7603
|
*/
|
|
7579
7604
|
async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
|
|
7580
7605
|
const ext = gl.getExtension('KHR_parallel_shader_compile');
|
|
@@ -7588,9 +7613,8 @@ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
|
|
|
7588
7613
|
waitTime = 1000 / 60;
|
|
7589
7614
|
} while (!checkFn(gl, program));
|
|
7590
7615
|
|
|
7591
|
-
const
|
|
7592
|
-
const
|
|
7593
|
-
const err = success ? undefined : errMsgs.join('\n');
|
|
7616
|
+
const success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
7617
|
+
const err = success ? undefined : progOptions.errors.join('\n');
|
|
7594
7618
|
if (!success) {
|
|
7595
7619
|
const errFn = progOptions.errorCallback || error$1;
|
|
7596
7620
|
errFn(err);
|
|
@@ -7608,6 +7632,7 @@ async function checkForProgramLinkCompletionAsync(gl, program, progOptions) {
|
|
|
7608
7632
|
* @param {WebGLProgram} program Program to check
|
|
7609
7633
|
* @param {ErrorCallback} [errFn] func for errors
|
|
7610
7634
|
* @return {bool} true if program is ok
|
|
7635
|
+
* @private
|
|
7611
7636
|
*/
|
|
7612
7637
|
function checkProgramStatus(gl, program, errFn) {
|
|
7613
7638
|
errFn = errFn || error$1;
|
|
@@ -7616,15 +7641,7 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
7616
7641
|
if (!linked) {
|
|
7617
7642
|
// something went wrong with the link
|
|
7618
7643
|
const lastError = gl.getProgramInfoLog(program);
|
|
7619
|
-
errFn(
|
|
7620
|
-
gl.getAttachedShaders(program).map(shader => {
|
|
7621
|
-
const {lineOffset, shaderSource} = prepShaderSource(gl.getShaderSource(shader));
|
|
7622
|
-
const shaderError = gl.getShaderInfoLog(shader);
|
|
7623
|
-
const src = addLineNumbersWithError(shaderSource, shaderError, lineOffset);
|
|
7624
|
-
const type = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
7625
|
-
return `${glEnumToString(gl, type)}\n${src}}`;
|
|
7626
|
-
}).join('\n')
|
|
7627
|
-
}\nError in program linking: ${lastError}`);
|
|
7644
|
+
errFn(`Error in program linking: ${lastError}`);
|
|
7628
7645
|
}
|
|
7629
7646
|
return linked;
|
|
7630
7647
|
}
|
|
@@ -7635,25 +7652,25 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
7635
7652
|
* @param {string} scriptId The id of the script tag.
|
|
7636
7653
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
7637
7654
|
* be derived from the type of the script tag.
|
|
7638
|
-
* @param {module:twgl.
|
|
7655
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
7639
7656
|
* @return {WebGLShader?} The created shader or null if error.
|
|
7640
7657
|
* @private
|
|
7641
7658
|
*/
|
|
7642
7659
|
function createShaderFromScript(
|
|
7643
|
-
gl, scriptId, opt_shaderType,
|
|
7660
|
+
gl, scriptId, opt_shaderType, progOptions) {
|
|
7644
7661
|
let shaderSource = "";
|
|
7645
7662
|
const shaderScript = getElementById(scriptId);
|
|
7646
7663
|
if (!shaderScript) {
|
|
7647
|
-
|
|
7664
|
+
return reportError(progOptions, `unknown script element: ${scriptId}`);
|
|
7648
7665
|
}
|
|
7649
7666
|
shaderSource = shaderScript.text;
|
|
7650
7667
|
|
|
7651
7668
|
const shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
7652
7669
|
if (!shaderType) {
|
|
7653
|
-
|
|
7670
|
+
return reportError(progOptions, 'unknown shader type');
|
|
7654
7671
|
}
|
|
7655
7672
|
|
|
7656
|
-
return loadShader(gl, shaderSource, shaderType);
|
|
7673
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
7657
7674
|
}
|
|
7658
7675
|
|
|
7659
7676
|
/**
|
|
@@ -7675,7 +7692,7 @@ function createShaderFromScript(
|
|
|
7675
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.
|
|
7676
7693
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
7677
7694
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
7678
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
7695
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
7679
7696
|
* @memberOf module:twgl/programs
|
|
7680
7697
|
*/
|
|
7681
7698
|
function createProgramFromScripts(
|
|
@@ -7684,7 +7701,7 @@ function createProgramFromScripts(
|
|
|
7684
7701
|
const shaders = [];
|
|
7685
7702
|
for (let ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
7686
7703
|
const shader = createShaderFromScript(
|
|
7687
|
-
gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
7704
|
+
gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
7688
7705
|
if (!shader) {
|
|
7689
7706
|
return null;
|
|
7690
7707
|
}
|
|
@@ -7712,7 +7729,7 @@ function createProgramFromScripts(
|
|
|
7712
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.
|
|
7713
7730
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
7714
7731
|
* on error. If you want something else pass an callback. It's passed an error message.
|
|
7715
|
-
* @return {WebGLProgram?} the created program or null if error.
|
|
7732
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
7716
7733
|
* @memberOf module:twgl/programs
|
|
7717
7734
|
*/
|
|
7718
7735
|
function createProgramFromSources(
|
|
@@ -7720,9 +7737,8 @@ function createProgramFromSources(
|
|
|
7720
7737
|
const progOptions = getProgramOptions(opt_attribs, opt_locations, opt_errorCallback);
|
|
7721
7738
|
const shaders = [];
|
|
7722
7739
|
for (let ii = 0; ii < shaderSources.length; ++ii) {
|
|
7723
|
-
const shader = loadShader(
|
|
7724
|
-
|
|
7725
|
-
if (!shader) {
|
|
7740
|
+
const shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
7741
|
+
if (!progOptions.callback && !shader) {
|
|
7726
7742
|
return null;
|
|
7727
7743
|
}
|
|
7728
7744
|
shaders.push(shader);
|
|
@@ -8786,10 +8802,7 @@ function createProgramInfo(
|
|
|
8786
8802
|
return source;
|
|
8787
8803
|
});
|
|
8788
8804
|
if (errors.length) {
|
|
8789
|
-
|
|
8790
|
-
progOptions.callback(errors.join('\n'));
|
|
8791
|
-
}
|
|
8792
|
-
return null;
|
|
8805
|
+
return reportError(progOptions, '');
|
|
8793
8806
|
}
|
|
8794
8807
|
const origCallback = progOptions.callback;
|
|
8795
8808
|
if (origCallback) {
|
|
@@ -8803,7 +8816,6 @@ function createProgramInfo(
|
|
|
8803
8816
|
}
|
|
8804
8817
|
const program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
8805
8818
|
if (!program) {
|
|
8806
|
-
// we should never get if if we have a callback
|
|
8807
8819
|
return null;
|
|
8808
8820
|
}
|
|
8809
8821
|
return createProgramInfoFromProgram(gl, program);
|
package/dist/4.x/twgl.d.ts
CHANGED
|
@@ -259,12 +259,9 @@ export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?:
|
|
|
259
259
|
export function getBindPointForSamplerType(): void;
|
|
260
260
|
export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo) => void;
|
|
261
261
|
export function prepShaderSource(shaderSource: string): any;
|
|
262
|
-
export function checkShaderStatus(gl: WebGLRenderingContext, shader: WebGLShader, errFn?: ErrorCallback): boolean;
|
|
263
262
|
export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
264
263
|
export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
|
|
265
264
|
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;
|
|
268
265
|
export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
269
266
|
export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
270
267
|
export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
|
package/dist/4.x/twgl.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @license twgl.js 4.23.
|
|
2
|
+
* @license twgl.js 4.23.1 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
|
*/
|
|
@@ -2459,31 +2459,59 @@ function prepShaderSource(shaderSource) {
|
|
|
2459
2459
|
shaderSource: shaderSource
|
|
2460
2460
|
};
|
|
2461
2461
|
}
|
|
2462
|
+
/**
|
|
2463
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
2464
|
+
* @param {string} msg
|
|
2465
|
+
* @return null
|
|
2466
|
+
* @private
|
|
2467
|
+
*/
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
function reportError(progOptions, msg) {
|
|
2471
|
+
progOptions.errorCallback(msg);
|
|
2472
|
+
|
|
2473
|
+
if (progOptions.callback) {
|
|
2474
|
+
setTimeout(function () {
|
|
2475
|
+
progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
|
|
2476
|
+
});
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
return null;
|
|
2480
|
+
}
|
|
2462
2481
|
/**
|
|
2463
2482
|
* Loads a shader.
|
|
2464
2483
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2465
2484
|
* @param {string} shaderSource The shader source.
|
|
2466
2485
|
* @param {number} shaderType The type of shader.
|
|
2486
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
2467
2487
|
* @return {WebGLShader} The created shader.
|
|
2468
2488
|
* @private
|
|
2469
2489
|
*/
|
|
2470
2490
|
|
|
2471
2491
|
|
|
2472
|
-
function loadShader(gl, shaderSource, shaderType) {
|
|
2492
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
2473
2493
|
// Create the shader object
|
|
2474
2494
|
var shader = gl.createShader(shaderType); // Load the shader source
|
|
2475
2495
|
|
|
2476
2496
|
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
|
|
2477
2497
|
|
|
2478
2498
|
gl.compileShader(shader);
|
|
2499
|
+
|
|
2500
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
2501
|
+
gl.deleteShader(shader);
|
|
2502
|
+
return null;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2479
2505
|
return shader;
|
|
2480
2506
|
}
|
|
2481
2507
|
/**
|
|
2482
2508
|
* Check Shader status
|
|
2483
2509
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
2510
|
+
* @param {number} shaderType The shader type
|
|
2484
2511
|
* @param {WebGLShader} shader The shader
|
|
2485
2512
|
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
2486
|
-
* @
|
|
2513
|
+
* @return {bool} true if shader is ok.
|
|
2514
|
+
* @private
|
|
2487
2515
|
*/
|
|
2488
2516
|
|
|
2489
2517
|
|
|
@@ -2496,13 +2524,11 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
2496
2524
|
// Something went wrong during compilation; get the error
|
|
2497
2525
|
var lastError = gl.getShaderInfoLog(shader);
|
|
2498
2526
|
|
|
2499
|
-
var _shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
2500
|
-
|
|
2501
2527
|
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
2502
2528
|
lineOffset = _prepShaderSource.lineOffset,
|
|
2503
2529
|
shaderSource = _prepShaderSource.shaderSource;
|
|
2504
2530
|
|
|
2505
|
-
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl,
|
|
2531
|
+
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
|
|
2506
2532
|
}
|
|
2507
2533
|
|
|
2508
2534
|
return compiled;
|
|
@@ -2546,7 +2572,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2546
2572
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
2547
2573
|
// If we have an errorCallback we can just return this object
|
|
2548
2574
|
// Otherwise we need to construct one with default errorCallback
|
|
2549
|
-
if (opt_attribs.errorCallback) {
|
|
2575
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
2550
2576
|
return opt_attribs;
|
|
2551
2577
|
}
|
|
2552
2578
|
|
|
@@ -2558,11 +2584,23 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
2558
2584
|
callback = opt.callback;
|
|
2559
2585
|
}
|
|
2560
2586
|
|
|
2587
|
+
var _errorCallback = opt_errorCallback || error;
|
|
2588
|
+
|
|
2589
|
+
var errors = [];
|
|
2561
2590
|
var options = {
|
|
2562
|
-
errorCallback:
|
|
2591
|
+
errorCallback: function errorCallback(msg) {
|
|
2592
|
+
errors.push(msg);
|
|
2593
|
+
|
|
2594
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2595
|
+
args[_key - 1] = arguments[_key];
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
_errorCallback.apply(void 0, [msg].concat(args));
|
|
2599
|
+
},
|
|
2563
2600
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
2564
2601
|
transformFeedbackMode: transformFeedbackMode,
|
|
2565
|
-
callback: callback
|
|
2602
|
+
callback: callback,
|
|
2603
|
+
errors: errors
|
|
2566
2604
|
};
|
|
2567
2605
|
|
|
2568
2606
|
if (opt_attribs) {
|
|
@@ -2608,7 +2646,7 @@ var wait = function wait() {
|
|
|
2608
2646
|
};
|
|
2609
2647
|
/**
|
|
2610
2648
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
2611
|
-
* program
|
|
2649
|
+
* program.
|
|
2612
2650
|
*
|
|
2613
2651
|
* NOTE: There are 4 signatures for this function
|
|
2614
2652
|
*
|
|
@@ -2623,7 +2661,7 @@ var wait = function wait() {
|
|
|
2623
2661
|
* @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
2662
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2625
2663
|
* 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.
|
|
2664
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
2627
2665
|
* @memberOf module:twgl/programs
|
|
2628
2666
|
*/
|
|
2629
2667
|
|
|
@@ -2647,13 +2685,7 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2647
2685
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
2648
2686
|
}
|
|
2649
2687
|
|
|
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
|
-
|
|
2688
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
2657
2689
|
newShaders.push(shader);
|
|
2658
2690
|
}
|
|
2659
2691
|
|
|
@@ -2663,9 +2695,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2663
2695
|
}
|
|
2664
2696
|
|
|
2665
2697
|
if (realShaders.length !== shaders.length) {
|
|
2666
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
2667
2698
|
deleteShaders(gl, newShaders);
|
|
2668
|
-
return
|
|
2699
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
2669
2700
|
}
|
|
2670
2701
|
|
|
2671
2702
|
var program = gl.createProgram();
|
|
@@ -2730,8 +2761,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
2730
2761
|
|
|
2731
2762
|
|
|
2732
2763
|
function createProgramAsync(gl, shaders) {
|
|
2733
|
-
for (var
|
|
2734
|
-
args[
|
|
2764
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
2765
|
+
args[_key2 - 2] = arguments[_key2];
|
|
2735
2766
|
}
|
|
2736
2767
|
|
|
2737
2768
|
return new Promise(function (resolve, reject) {
|
|
@@ -2745,7 +2776,7 @@ function createProgramAsync(gl, shaders) {
|
|
|
2745
2776
|
}
|
|
2746
2777
|
};
|
|
2747
2778
|
|
|
2748
|
-
|
|
2779
|
+
createProgram(gl, shaders, programOptions);
|
|
2749
2780
|
});
|
|
2750
2781
|
}
|
|
2751
2782
|
/**
|
|
@@ -2765,8 +2796,8 @@ function createProgramAsync(gl, shaders) {
|
|
|
2765
2796
|
|
|
2766
2797
|
|
|
2767
2798
|
function createProgramInfoAsync(gl, shaders) {
|
|
2768
|
-
for (var
|
|
2769
|
-
args[
|
|
2799
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2800
|
+
args[_key3 - 2] = arguments[_key3];
|
|
2770
2801
|
}
|
|
2771
2802
|
|
|
2772
2803
|
return new Promise(function (resolve, reject) {
|
|
@@ -2780,7 +2811,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
2780
2811
|
}
|
|
2781
2812
|
};
|
|
2782
2813
|
|
|
2783
|
-
|
|
2814
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
2784
2815
|
});
|
|
2785
2816
|
}
|
|
2786
2817
|
/**
|
|
@@ -2790,6 +2821,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
2790
2821
|
* @param {WebGLRenderingContext} gl The context
|
|
2791
2822
|
* @param {WebGLProgram} program The program
|
|
2792
2823
|
* @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
|
|
2824
|
+
* @private
|
|
2793
2825
|
*/
|
|
2794
2826
|
|
|
2795
2827
|
|
|
@@ -2802,12 +2834,13 @@ function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
|
2802
2834
|
* @param {WebGLProgram} program Program to check
|
|
2803
2835
|
* @param {ErrorCallback} [errFn] func for errors
|
|
2804
2836
|
* @return {bool} true if program is ok
|
|
2837
|
+
* @private
|
|
2805
2838
|
*/
|
|
2806
2839
|
|
|
2807
2840
|
|
|
2808
2841
|
function _checkForProgramLinkCompletionAsync() {
|
|
2809
2842
|
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
|
|
2810
|
-
var ext, checkFn, waitTime,
|
|
2843
|
+
var ext, checkFn, waitTime, success, err, errFn;
|
|
2811
2844
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
2812
2845
|
while (1) {
|
|
2813
2846
|
switch (_context.prev = _context.next) {
|
|
@@ -2835,11 +2868,8 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
2835
2868
|
}
|
|
2836
2869
|
|
|
2837
2870
|
case 7:
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
return errMsgs.push(msg);
|
|
2841
|
-
});
|
|
2842
|
-
err = success ? undefined : errMsgs.join('\n');
|
|
2871
|
+
success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
2872
|
+
err = success ? undefined : progOptions.errors.join('\n');
|
|
2843
2873
|
|
|
2844
2874
|
if (!success) {
|
|
2845
2875
|
errFn = progOptions.errorCallback || error;
|
|
@@ -2852,7 +2882,7 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
2852
2882
|
|
|
2853
2883
|
progOptions.callback(err, program);
|
|
2854
2884
|
|
|
2855
|
-
case
|
|
2885
|
+
case 11:
|
|
2856
2886
|
case "end":
|
|
2857
2887
|
return _context.stop();
|
|
2858
2888
|
}
|
|
@@ -2870,16 +2900,7 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
2870
2900
|
if (!linked) {
|
|
2871
2901
|
// something went wrong with the link
|
|
2872
2902
|
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));
|
|
2903
|
+
errFn("Error in program linking: ".concat(lastError));
|
|
2883
2904
|
}
|
|
2884
2905
|
|
|
2885
2906
|
return linked;
|
|
@@ -2890,28 +2911,28 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
2890
2911
|
* @param {string} scriptId The id of the script tag.
|
|
2891
2912
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
2892
2913
|
* be derived from the type of the script tag.
|
|
2893
|
-
* @param {module:twgl.
|
|
2914
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
2894
2915
|
* @return {WebGLShader?} The created shader or null if error.
|
|
2895
2916
|
* @private
|
|
2896
2917
|
*/
|
|
2897
2918
|
|
|
2898
2919
|
|
|
2899
|
-
function createShaderFromScript(gl, scriptId, opt_shaderType,
|
|
2920
|
+
function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
2900
2921
|
var shaderSource = "";
|
|
2901
2922
|
var shaderScript = getElementById(scriptId);
|
|
2902
2923
|
|
|
2903
2924
|
if (!shaderScript) {
|
|
2904
|
-
|
|
2925
|
+
return reportError(progOptions, "unknown script element: ".concat(scriptId));
|
|
2905
2926
|
}
|
|
2906
2927
|
|
|
2907
2928
|
shaderSource = shaderScript.text;
|
|
2908
2929
|
var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
2909
2930
|
|
|
2910
2931
|
if (!shaderType) {
|
|
2911
|
-
|
|
2932
|
+
return reportError(progOptions, 'unknown shader type');
|
|
2912
2933
|
}
|
|
2913
2934
|
|
|
2914
|
-
return loadShader(gl, shaderSource, shaderType,
|
|
2935
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
2915
2936
|
}
|
|
2916
2937
|
/**
|
|
2917
2938
|
* Creates a program from 2 script tags.
|
|
@@ -2932,7 +2953,7 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback)
|
|
|
2932
2953
|
* @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
2954
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2934
2955
|
* 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.
|
|
2956
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
2936
2957
|
* @memberOf module:twgl/programs
|
|
2937
2958
|
*/
|
|
2938
2959
|
|
|
@@ -2942,7 +2963,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
2942
2963
|
var shaders = [];
|
|
2943
2964
|
|
|
2944
2965
|
for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
2945
|
-
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
2966
|
+
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
2946
2967
|
|
|
2947
2968
|
if (!shader) {
|
|
2948
2969
|
return null;
|
|
@@ -2972,7 +2993,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
2972
2993
|
* @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
2994
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
2974
2995
|
* 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.
|
|
2996
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
2976
2997
|
* @memberOf module:twgl/programs
|
|
2977
2998
|
*/
|
|
2978
2999
|
|
|
@@ -2982,9 +3003,9 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
|
|
|
2982
3003
|
var shaders = [];
|
|
2983
3004
|
|
|
2984
3005
|
for (var ii = 0; ii < shaderSources.length; ++ii) {
|
|
2985
|
-
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions
|
|
3006
|
+
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
2986
3007
|
|
|
2987
|
-
if (!shader) {
|
|
3008
|
+
if (!progOptions.callback && !shader) {
|
|
2988
3009
|
return null;
|
|
2989
3010
|
}
|
|
2990
3011
|
|
|
@@ -4113,11 +4134,7 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4113
4134
|
});
|
|
4114
4135
|
|
|
4115
4136
|
if (errors.length) {
|
|
4116
|
-
|
|
4117
|
-
progOptions.callback(errors.join('\n'));
|
|
4118
|
-
}
|
|
4119
|
-
|
|
4120
|
-
return null;
|
|
4137
|
+
return reportError(progOptions, '');
|
|
4121
4138
|
}
|
|
4122
4139
|
|
|
4123
4140
|
var origCallback = progOptions.callback;
|
|
@@ -4137,7 +4154,6 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
4137
4154
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
4138
4155
|
|
|
4139
4156
|
if (!program) {
|
|
4140
|
-
// we should never get if if we have a callback
|
|
4141
4157
|
return null;
|
|
4142
4158
|
}
|
|
4143
4159
|
|