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/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
TWGL: A Tiny WebGL helper Library<div id="pronounce" style="font-size: xx-small;">[rhymes with wiggle]</div>
|
|
2
2
|
=====================================================
|
|
3
3
|
|
|
4
|
-
[](https://github.com/greggman/twgl.js/actions/workflows/test.yml)
|
|
5
5
|
|
|
6
6
|
This library's sole purpose is to make using the WebGL API less verbose.
|
|
7
7
|
|
package/dist/4.x/twgl-full.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export type Defaults = {
|
|
|
7
7
|
};
|
|
8
8
|
export function setDefaults(newDefaults: Defaults): void;
|
|
9
9
|
export function addExtensionsToContext(gl: WebGLRenderingContext): void;
|
|
10
|
-
export function getWebGLContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
|
|
11
10
|
export function createContext(canvas: HTMLCanvasElement): WebGLRenderingContext;
|
|
12
11
|
export function getContext(canvas: HTMLCanvasElement, opt_attribs?: WebGLContextAttributes): WebGLRenderingContext;
|
|
13
12
|
export function resizeCanvasToDisplaySize(canvas: HTMLCanvasElement, multiplier?: number): boolean;
|
|
@@ -256,15 +255,10 @@ export function resizeFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo
|
|
|
256
255
|
export function bindFramebufferInfo(gl: WebGLRenderingContext, framebufferInfo?: FramebufferInfo | null, target?: number): void;
|
|
257
256
|
|
|
258
257
|
|
|
259
|
-
export function getBindPointForSamplerType(): void;
|
|
260
258
|
export type ProgramCallback = (err?: string, result?: WebGLProgram | ProgramInfo) => void;
|
|
261
|
-
export function prepShaderSource(shaderSource: string): any;
|
|
262
|
-
export function checkShaderStatus(gl: WebGLRenderingContext, shader: WebGLShader, errFn?: ErrorCallback): boolean;
|
|
263
259
|
export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
264
260
|
export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
|
|
265
261
|
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
262
|
export function createProgramFromScripts(gl: WebGLRenderingContext, shaderScriptIds: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
269
263
|
export function createProgramFromSources(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
|
|
270
264
|
export function createUniformSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
|
|
@@ -291,11 +285,6 @@ export function setUniformsAndBindTextures(setters: ProgramInfo | {
|
|
|
291
285
|
export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
|
|
292
286
|
[key: string]: (...params: any[]) => any;
|
|
293
287
|
};
|
|
294
|
-
export function setAttributes(setters: {
|
|
295
|
-
[key: string]: (...params: any[]) => any;
|
|
296
|
-
}, buffers: {
|
|
297
|
-
[key: string]: AttribInfo;
|
|
298
|
-
}): void;
|
|
299
288
|
export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
|
|
300
289
|
[key: string]: (...params: any[]) => any;
|
|
301
290
|
}, buffers: BufferInfo | VertexArrayInfo): void;
|
|
@@ -317,10 +306,7 @@ export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTextur
|
|
|
317
306
|
export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
|
|
318
307
|
export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
|
|
319
308
|
export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
|
|
320
|
-
export function setTextureTo1PixelColor(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions): void;
|
|
321
309
|
export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
|
|
322
|
-
export function loadCubemapFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: CubemapReadyCallback): void;
|
|
323
|
-
export function loadSlicesFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: ThreeDReadyCallback): void;
|
|
324
310
|
export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
|
|
325
311
|
export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
|
|
326
312
|
export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
|
package/dist/4.x/twgl-full.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
|
/**
|
|
@@ -4814,6 +4842,7 @@ var TEXTURE_2D_ARRAY = 0x8C1A;
|
|
|
4814
4842
|
var typeMap = {};
|
|
4815
4843
|
/**
|
|
4816
4844
|
* Returns the corresponding bind point for a given sampler type
|
|
4845
|
+
* @private
|
|
4817
4846
|
*/
|
|
4818
4847
|
|
|
4819
4848
|
function getBindPointForSamplerType(gl, type) {
|
|
@@ -5533,6 +5562,7 @@ var spaceRE = /^[ \t]*\n/;
|
|
|
5533
5562
|
*
|
|
5534
5563
|
* @param {string} shaderSource The source of the shader
|
|
5535
5564
|
* @returns {{shaderSource: string, lineOffset: number}}
|
|
5565
|
+
* @private
|
|
5536
5566
|
*/
|
|
5537
5567
|
|
|
5538
5568
|
function prepShaderSource(shaderSource) {
|
|
@@ -5548,31 +5578,59 @@ function prepShaderSource(shaderSource) {
|
|
|
5548
5578
|
shaderSource: shaderSource
|
|
5549
5579
|
};
|
|
5550
5580
|
}
|
|
5581
|
+
/**
|
|
5582
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
5583
|
+
* @param {string} msg
|
|
5584
|
+
* @return null
|
|
5585
|
+
* @private
|
|
5586
|
+
*/
|
|
5587
|
+
|
|
5588
|
+
|
|
5589
|
+
function reportError(progOptions, msg) {
|
|
5590
|
+
progOptions.errorCallback(msg);
|
|
5591
|
+
|
|
5592
|
+
if (progOptions.callback) {
|
|
5593
|
+
setTimeout(function () {
|
|
5594
|
+
progOptions.callback("".concat(msg, "\n").concat(progOptions.errors.join('\n')));
|
|
5595
|
+
});
|
|
5596
|
+
}
|
|
5597
|
+
|
|
5598
|
+
return null;
|
|
5599
|
+
}
|
|
5551
5600
|
/**
|
|
5552
5601
|
* Loads a shader.
|
|
5553
5602
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5554
5603
|
* @param {string} shaderSource The shader source.
|
|
5555
5604
|
* @param {number} shaderType The type of shader.
|
|
5605
|
+
* @param {module:twgl.ProgramOptions} progOptions
|
|
5556
5606
|
* @return {WebGLShader} The created shader.
|
|
5557
5607
|
* @private
|
|
5558
5608
|
*/
|
|
5559
5609
|
|
|
5560
5610
|
|
|
5561
|
-
function loadShader(gl, shaderSource, shaderType) {
|
|
5611
|
+
function loadShader(gl, shaderSource, shaderType, progOptions) {
|
|
5562
5612
|
// Create the shader object
|
|
5563
5613
|
var shader = gl.createShader(shaderType); // Load the shader source
|
|
5564
5614
|
|
|
5565
5615
|
gl.shaderSource(shader, prepShaderSource(shaderSource).shaderSource); // Compile the shader
|
|
5566
5616
|
|
|
5567
5617
|
gl.compileShader(shader);
|
|
5618
|
+
|
|
5619
|
+
if (!progOptions.callback && !checkShaderStatus(gl, shaderType, shader, progOptions.errorCallback)) {
|
|
5620
|
+
gl.deleteShader(shader);
|
|
5621
|
+
return null;
|
|
5622
|
+
}
|
|
5623
|
+
|
|
5568
5624
|
return shader;
|
|
5569
5625
|
}
|
|
5570
5626
|
/**
|
|
5571
5627
|
* Check Shader status
|
|
5572
5628
|
* @param {WebGLRenderingContext} gl The WebGLRenderingContext to use.
|
|
5629
|
+
* @param {number} shaderType The shader type
|
|
5573
5630
|
* @param {WebGLShader} shader The shader
|
|
5574
5631
|
* @param {ErrorCallback} [errFn] function to receive error message.
|
|
5575
|
-
* @
|
|
5632
|
+
* @return {bool} true if shader is ok.
|
|
5633
|
+
* @private
|
|
5576
5634
|
*/
|
|
5577
5635
|
|
|
5578
5636
|
|
|
@@ -5585,13 +5643,11 @@ function checkShaderStatus(gl, shaderType, shader, errFn) {
|
|
|
5585
5643
|
// Something went wrong during compilation; get the error
|
|
5586
5644
|
var lastError = gl.getShaderInfoLog(shader);
|
|
5587
5645
|
|
|
5588
|
-
var _shaderType = gl.getShaderParameter(shader, gl.SHADER_TYPE);
|
|
5589
|
-
|
|
5590
5646
|
var _prepShaderSource = prepShaderSource(gl.getShaderSource(shader)),
|
|
5591
5647
|
lineOffset = _prepShaderSource.lineOffset,
|
|
5592
5648
|
shaderSource = _prepShaderSource.shaderSource;
|
|
5593
5649
|
|
|
5594
|
-
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl,
|
|
5650
|
+
errFn("".concat(addLineNumbersWithError(shaderSource, lastError, lineOffset), "\nError compiling ").concat(utils.glEnumToString(gl, shaderType), ": ").concat(lastError));
|
|
5595
5651
|
}
|
|
5596
5652
|
|
|
5597
5653
|
return compiled;
|
|
@@ -5635,7 +5691,7 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
5635
5691
|
} else if (opt_attribs && !Array.isArray(opt_attribs)) {
|
|
5636
5692
|
// If we have an errorCallback we can just return this object
|
|
5637
5693
|
// Otherwise we need to construct one with default errorCallback
|
|
5638
|
-
if (opt_attribs.errorCallback) {
|
|
5694
|
+
if (opt_attribs.errorCallback && opt_attribs.errors) {
|
|
5639
5695
|
return opt_attribs;
|
|
5640
5696
|
}
|
|
5641
5697
|
|
|
@@ -5647,11 +5703,23 @@ function getProgramOptions(opt_attribs, opt_locations, opt_errorCallback) {
|
|
|
5647
5703
|
callback = opt.callback;
|
|
5648
5704
|
}
|
|
5649
5705
|
|
|
5706
|
+
var _errorCallback = opt_errorCallback || error;
|
|
5707
|
+
|
|
5708
|
+
var errors = [];
|
|
5650
5709
|
var options = {
|
|
5651
|
-
errorCallback:
|
|
5710
|
+
errorCallback: function errorCallback(msg) {
|
|
5711
|
+
errors.push(msg);
|
|
5712
|
+
|
|
5713
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
5714
|
+
args[_key - 1] = arguments[_key];
|
|
5715
|
+
}
|
|
5716
|
+
|
|
5717
|
+
_errorCallback.apply(void 0, [msg].concat(args));
|
|
5718
|
+
},
|
|
5652
5719
|
transformFeedbackVaryings: transformFeedbackVaryings,
|
|
5653
5720
|
transformFeedbackMode: transformFeedbackMode,
|
|
5654
|
-
callback: callback
|
|
5721
|
+
callback: callback,
|
|
5722
|
+
errors: errors
|
|
5655
5723
|
};
|
|
5656
5724
|
|
|
5657
5725
|
if (opt_attribs) {
|
|
@@ -5697,7 +5765,7 @@ var wait = function wait() {
|
|
|
5697
5765
|
};
|
|
5698
5766
|
/**
|
|
5699
5767
|
* Creates a program, attaches (and/or compiles) shaders, binds attrib locations, links the
|
|
5700
|
-
* program
|
|
5768
|
+
* program.
|
|
5701
5769
|
*
|
|
5702
5770
|
* NOTE: There are 4 signatures for this function
|
|
5703
5771
|
*
|
|
@@ -5712,7 +5780,7 @@ var wait = function wait() {
|
|
|
5712
5780
|
* @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
5781
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
5714
5782
|
* 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.
|
|
5783
|
+
* @return {WebGLProgram?} the created program or null if error of a callback was provided.
|
|
5716
5784
|
* @memberOf module:twgl/programs
|
|
5717
5785
|
*/
|
|
5718
5786
|
|
|
@@ -5736,13 +5804,7 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5736
5804
|
type = getShaderTypeFromScriptType(gl, elem.type) || type;
|
|
5737
5805
|
}
|
|
5738
5806
|
|
|
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
|
-
|
|
5807
|
+
shader = loadShader(gl, src, type, progOptions);
|
|
5746
5808
|
newShaders.push(shader);
|
|
5747
5809
|
}
|
|
5748
5810
|
|
|
@@ -5752,9 +5814,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5752
5814
|
}
|
|
5753
5815
|
|
|
5754
5816
|
if (realShaders.length !== shaders.length) {
|
|
5755
|
-
progOptions.errorCallback("not enough shaders for program");
|
|
5756
5817
|
deleteShaders(gl, newShaders);
|
|
5757
|
-
return
|
|
5818
|
+
return reportError(progOptions, "not enough shaders for program");
|
|
5758
5819
|
}
|
|
5759
5820
|
|
|
5760
5821
|
var program = gl.createProgram();
|
|
@@ -5819,8 +5880,8 @@ function createProgram(gl, shaders, opt_attribs, opt_locations, opt_errorCallbac
|
|
|
5819
5880
|
|
|
5820
5881
|
|
|
5821
5882
|
function createProgramAsync(gl, shaders) {
|
|
5822
|
-
for (var
|
|
5823
|
-
args[
|
|
5883
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
5884
|
+
args[_key2 - 2] = arguments[_key2];
|
|
5824
5885
|
}
|
|
5825
5886
|
|
|
5826
5887
|
return new Promise(function (resolve, reject) {
|
|
@@ -5834,7 +5895,7 @@ function createProgramAsync(gl, shaders) {
|
|
|
5834
5895
|
}
|
|
5835
5896
|
};
|
|
5836
5897
|
|
|
5837
|
-
|
|
5898
|
+
createProgram(gl, shaders, programOptions);
|
|
5838
5899
|
});
|
|
5839
5900
|
}
|
|
5840
5901
|
/**
|
|
@@ -5854,8 +5915,8 @@ function createProgramAsync(gl, shaders) {
|
|
|
5854
5915
|
|
|
5855
5916
|
|
|
5856
5917
|
function createProgramInfoAsync(gl, shaders) {
|
|
5857
|
-
for (var
|
|
5858
|
-
args[
|
|
5918
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
5919
|
+
args[_key3 - 2] = arguments[_key3];
|
|
5859
5920
|
}
|
|
5860
5921
|
|
|
5861
5922
|
return new Promise(function (resolve, reject) {
|
|
@@ -5869,7 +5930,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
5869
5930
|
}
|
|
5870
5931
|
};
|
|
5871
5932
|
|
|
5872
|
-
|
|
5933
|
+
createProgramInfo(gl, shaders, programOptions);
|
|
5873
5934
|
});
|
|
5874
5935
|
}
|
|
5875
5936
|
/**
|
|
@@ -5879,6 +5940,7 @@ function createProgramInfoAsync(gl, shaders) {
|
|
|
5879
5940
|
* @param {WebGLRenderingContext} gl The context
|
|
5880
5941
|
* @param {WebGLProgram} program The program
|
|
5881
5942
|
* @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
|
|
5943
|
+
* @private
|
|
5882
5944
|
*/
|
|
5883
5945
|
|
|
5884
5946
|
|
|
@@ -5891,12 +5953,13 @@ function checkForProgramLinkCompletionAsync(_x, _x2, _x3) {
|
|
|
5891
5953
|
* @param {WebGLProgram} program Program to check
|
|
5892
5954
|
* @param {ErrorCallback} [errFn] func for errors
|
|
5893
5955
|
* @return {bool} true if program is ok
|
|
5956
|
+
* @private
|
|
5894
5957
|
*/
|
|
5895
5958
|
|
|
5896
5959
|
|
|
5897
5960
|
function _checkForProgramLinkCompletionAsync() {
|
|
5898
5961
|
_checkForProgramLinkCompletionAsync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(gl, program, progOptions) {
|
|
5899
|
-
var ext, checkFn, waitTime,
|
|
5962
|
+
var ext, checkFn, waitTime, success, err, errFn;
|
|
5900
5963
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
5901
5964
|
while (1) {
|
|
5902
5965
|
switch (_context.prev = _context.next) {
|
|
@@ -5924,11 +5987,8 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
5924
5987
|
}
|
|
5925
5988
|
|
|
5926
5989
|
case 7:
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
return errMsgs.push(msg);
|
|
5930
|
-
});
|
|
5931
|
-
err = success ? undefined : errMsgs.join('\n');
|
|
5990
|
+
success = checkProgramStatus(gl, program, progOptions.errorCallback);
|
|
5991
|
+
err = success ? undefined : progOptions.errors.join('\n');
|
|
5932
5992
|
|
|
5933
5993
|
if (!success) {
|
|
5934
5994
|
errFn = progOptions.errorCallback || error;
|
|
@@ -5941,7 +6001,7 @@ function _checkForProgramLinkCompletionAsync() {
|
|
|
5941
6001
|
|
|
5942
6002
|
progOptions.callback(err, program);
|
|
5943
6003
|
|
|
5944
|
-
case
|
|
6004
|
+
case 11:
|
|
5945
6005
|
case "end":
|
|
5946
6006
|
return _context.stop();
|
|
5947
6007
|
}
|
|
@@ -5959,16 +6019,7 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
5959
6019
|
if (!linked) {
|
|
5960
6020
|
// something went wrong with the link
|
|
5961
6021
|
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));
|
|
6022
|
+
errFn("Error in program linking: ".concat(lastError));
|
|
5972
6023
|
}
|
|
5973
6024
|
|
|
5974
6025
|
return linked;
|
|
@@ -5979,28 +6030,28 @@ function checkProgramStatus(gl, program, errFn) {
|
|
|
5979
6030
|
* @param {string} scriptId The id of the script tag.
|
|
5980
6031
|
* @param {number} [opt_shaderType] The type of shader. If not passed in it will
|
|
5981
6032
|
* be derived from the type of the script tag.
|
|
5982
|
-
* @param {module:twgl.
|
|
6033
|
+
* @param {module:twgl.ProgramOptions} [progOptions] callback for errors.
|
|
5983
6034
|
* @return {WebGLShader?} The created shader or null if error.
|
|
5984
6035
|
* @private
|
|
5985
6036
|
*/
|
|
5986
6037
|
|
|
5987
6038
|
|
|
5988
|
-
function createShaderFromScript(gl, scriptId, opt_shaderType,
|
|
6039
|
+
function createShaderFromScript(gl, scriptId, opt_shaderType, progOptions) {
|
|
5989
6040
|
var shaderSource = "";
|
|
5990
6041
|
var shaderScript = getElementById(scriptId);
|
|
5991
6042
|
|
|
5992
6043
|
if (!shaderScript) {
|
|
5993
|
-
|
|
6044
|
+
return reportError(progOptions, "unknown script element: ".concat(scriptId));
|
|
5994
6045
|
}
|
|
5995
6046
|
|
|
5996
6047
|
shaderSource = shaderScript.text;
|
|
5997
6048
|
var shaderType = opt_shaderType || getShaderTypeFromScriptType(gl, shaderScript.type);
|
|
5998
6049
|
|
|
5999
6050
|
if (!shaderType) {
|
|
6000
|
-
|
|
6051
|
+
return reportError(progOptions, 'unknown shader type');
|
|
6001
6052
|
}
|
|
6002
6053
|
|
|
6003
|
-
return loadShader(gl, shaderSource, shaderType,
|
|
6054
|
+
return loadShader(gl, shaderSource, shaderType, progOptions);
|
|
6004
6055
|
}
|
|
6005
6056
|
/**
|
|
6006
6057
|
* Creates a program from 2 script tags.
|
|
@@ -6021,7 +6072,7 @@ function createShaderFromScript(gl, scriptId, opt_shaderType, opt_errorCallback)
|
|
|
6021
6072
|
* @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
6073
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
6023
6074
|
* 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.
|
|
6075
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
6025
6076
|
* @memberOf module:twgl/programs
|
|
6026
6077
|
*/
|
|
6027
6078
|
|
|
@@ -6031,7 +6082,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
6031
6082
|
var shaders = [];
|
|
6032
6083
|
|
|
6033
6084
|
for (var ii = 0; ii < shaderScriptIds.length; ++ii) {
|
|
6034
|
-
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions
|
|
6085
|
+
var shader = createShaderFromScript(gl, shaderScriptIds[ii], gl[defaultShaderType[ii]], progOptions);
|
|
6035
6086
|
|
|
6036
6087
|
if (!shader) {
|
|
6037
6088
|
return null;
|
|
@@ -6061,7 +6112,7 @@ function createProgramFromScripts(gl, shaderScriptIds, opt_attribs, opt_location
|
|
|
6061
6112
|
* @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
6113
|
* @param {module:twgl.ErrorCallback} [opt_errorCallback] callback for errors. By default it just prints an error to the console
|
|
6063
6114
|
* 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.
|
|
6115
|
+
* @return {WebGLProgram?} the created program or null if error or a callback was provided.
|
|
6065
6116
|
* @memberOf module:twgl/programs
|
|
6066
6117
|
*/
|
|
6067
6118
|
|
|
@@ -6071,9 +6122,9 @@ function createProgramFromSources(gl, shaderSources, opt_attribs, opt_locations,
|
|
|
6071
6122
|
var shaders = [];
|
|
6072
6123
|
|
|
6073
6124
|
for (var ii = 0; ii < shaderSources.length; ++ii) {
|
|
6074
|
-
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions
|
|
6125
|
+
var shader = loadShader(gl, shaderSources[ii], gl[defaultShaderType[ii]], progOptions);
|
|
6075
6126
|
|
|
6076
|
-
if (!shader) {
|
|
6127
|
+
if (!progOptions.callback && !shader) {
|
|
6077
6128
|
return null;
|
|
6078
6129
|
}
|
|
6079
6130
|
|
|
@@ -7041,6 +7092,7 @@ function createAttributeSetters(gl, program) {
|
|
|
7041
7092
|
* @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
|
|
7042
7093
|
* @memberOf module:twgl/programs
|
|
7043
7094
|
* @deprecated use {@link module:twgl.setBuffersAndAttributes}
|
|
7095
|
+
* @private
|
|
7044
7096
|
*/
|
|
7045
7097
|
|
|
7046
7098
|
|
|
@@ -7202,11 +7254,7 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
7202
7254
|
});
|
|
7203
7255
|
|
|
7204
7256
|
if (errors.length) {
|
|
7205
|
-
|
|
7206
|
-
progOptions.callback(errors.join('\n'));
|
|
7207
|
-
}
|
|
7208
|
-
|
|
7209
|
-
return null;
|
|
7257
|
+
return reportError(progOptions, '');
|
|
7210
7258
|
}
|
|
7211
7259
|
|
|
7212
7260
|
var origCallback = progOptions.callback;
|
|
@@ -7226,7 +7274,6 @@ function createProgramInfo(gl, shaderSources, opt_attribs, opt_locations, opt_er
|
|
|
7226
7274
|
var program = createProgramFromSources(gl, shaderSources, progOptions);
|
|
7227
7275
|
|
|
7228
7276
|
if (!program) {
|
|
7229
|
-
// we should never get if if we have a callback
|
|
7230
7277
|
return null;
|
|
7231
7278
|
}
|
|
7232
7279
|
|
|
@@ -8882,6 +8929,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
|
|
|
8882
8929
|
* @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
|
|
8883
8930
|
* This is often the same options you passed in when you created the texture.
|
|
8884
8931
|
* @memberOf module:twgl/textures
|
|
8932
|
+
* @private
|
|
8885
8933
|
*/
|
|
8886
8934
|
|
|
8887
8935
|
|
|
@@ -8996,6 +9044,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
|
|
|
8996
9044
|
* @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
8997
9045
|
* be non null if there was an error.
|
|
8998
9046
|
* @memberOf module:twgl/textures
|
|
9047
|
+
* @private
|
|
8999
9048
|
*/
|
|
9000
9049
|
|
|
9001
9050
|
|
|
@@ -9084,6 +9133,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
9084
9133
|
* @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
|
|
9085
9134
|
* be non null if there was an error.
|
|
9086
9135
|
* @memberOf module:twgl/textures
|
|
9136
|
+
* @private
|
|
9087
9137
|
*/
|
|
9088
9138
|
|
|
9089
9139
|
|
|
@@ -9993,6 +10043,8 @@ function create3DContext(canvas, opt_attribs) {
|
|
|
9993
10043
|
* @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
|
|
9994
10044
|
* @return {WebGLRenderingContext} The created context.
|
|
9995
10045
|
* @memberOf module:twgl
|
|
10046
|
+
* @deprecated
|
|
10047
|
+
* @private
|
|
9996
10048
|
*/
|
|
9997
10049
|
|
|
9998
10050
|
|