twgl.js 4.23.1 → 4.23.2

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 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
- [![Build Status](https://travis-ci.org/greggman/twgl.js.svg?branch=master)](https://travis-ci.org/greggman/twgl.js)
4
+ [![Build Status](https://github.com/greggman/twgl.js/actions/workflows/test.yml/badge.svg)](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
 
@@ -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,9 +255,7 @@ 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
259
  export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
263
260
  export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
264
261
  export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
@@ -288,11 +285,6 @@ export function setUniformsAndBindTextures(setters: ProgramInfo | {
288
285
  export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
289
286
  [key: string]: (...params: any[]) => any;
290
287
  };
291
- export function setAttributes(setters: {
292
- [key: string]: (...params: any[]) => any;
293
- }, buffers: {
294
- [key: string]: AttribInfo;
295
- }): void;
296
288
  export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
297
289
  [key: string]: (...params: any[]) => any;
298
290
  }, buffers: BufferInfo | VertexArrayInfo): void;
@@ -314,10 +306,7 @@ export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTextur
314
306
  export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
315
307
  export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
316
308
  export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
317
- export function setTextureTo1PixelColor(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions): void;
318
309
  export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
319
- export function loadCubemapFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: CubemapReadyCallback): void;
320
- export function loadSlicesFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: ThreeDReadyCallback): void;
321
310
  export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
322
311
  export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
323
312
  export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.23.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 4.23.2 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);
@@ -4814,6 +4824,7 @@ var TEXTURE_2D_ARRAY = 0x8C1A;
4814
4824
  var typeMap = {};
4815
4825
  /**
4816
4826
  * Returns the corresponding bind point for a given sampler type
4827
+ * @private
4817
4828
  */
4818
4829
 
4819
4830
  function getBindPointForSamplerType(gl, type) {
@@ -5533,6 +5544,7 @@ var spaceRE = /^[ \t]*\n/;
5533
5544
  *
5534
5545
  * @param {string} shaderSource The source of the shader
5535
5546
  * @returns {{shaderSource: string, lineOffset: number}}
5547
+ * @private
5536
5548
  */
5537
5549
 
5538
5550
  function prepShaderSource(shaderSource) {
@@ -7062,6 +7074,7 @@ function createAttributeSetters(gl, program) {
7062
7074
  * @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
7063
7075
  * @memberOf module:twgl/programs
7064
7076
  * @deprecated use {@link module:twgl.setBuffersAndAttributes}
7077
+ * @private
7065
7078
  */
7066
7079
 
7067
7080
 
@@ -8898,6 +8911,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
8898
8911
  * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
8899
8912
  * This is often the same options you passed in when you created the texture.
8900
8913
  * @memberOf module:twgl/textures
8914
+ * @private
8901
8915
  */
8902
8916
 
8903
8917
 
@@ -9012,6 +9026,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
9012
9026
  * @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
9013
9027
  * be non null if there was an error.
9014
9028
  * @memberOf module:twgl/textures
9029
+ * @private
9015
9030
  */
9016
9031
 
9017
9032
 
@@ -9100,6 +9115,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
9100
9115
  * @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
9101
9116
  * be non null if there was an error.
9102
9117
  * @memberOf module:twgl/textures
9118
+ * @private
9103
9119
  */
9104
9120
 
9105
9121
 
@@ -10009,6 +10025,8 @@ function create3DContext(canvas, opt_attribs) {
10009
10025
  * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
10010
10026
  * @return {WebGLRenderingContext} The created context.
10011
10027
  * @memberOf module:twgl
10028
+ * @deprecated
10029
+ * @private
10012
10030
  */
10013
10031
 
10014
10032
 
@@ -1,4 +1,4 @@
1
- /* @license twgl.js 4.23.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
1
+ /* @license twgl.js 4.23.2 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
  /*
@@ -2431,6 +2431,9 @@ function getNumElementsFromNonIndexedArrays(arrays) {
2431
2431
  }
2432
2432
  const array = arrays[key];
2433
2433
  const length = getArray(array).length;
2434
+ if (length === undefined) {
2435
+ return 1; // There's no arrays
2436
+ }
2434
2437
  const numComponents = getNumComponents(array, key);
2435
2438
  const numElements = length / numComponents;
2436
2439
  if (length % numComponents > 0) {
@@ -2456,6 +2459,9 @@ function getNumElementsFromAttributes(gl, attribs) {
2456
2459
  key = Object.keys(attribs)[0];
2457
2460
  }
2458
2461
  const attrib = attribs[key];
2462
+ if (!attrib.buffer) {
2463
+ return 1; // There's no buffer
2464
+ }
2459
2465
  gl.bindBuffer(ARRAY_BUFFER, attrib.buffer);
2460
2466
  const numBytes = gl.getBufferParameter(ARRAY_BUFFER, BUFFER_SIZE);
2461
2467
  gl.bindBuffer(ARRAY_BUFFER, null);
@@ -6088,6 +6094,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
6088
6094
  * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
6089
6095
  * This is often the same options you passed in when you created the texture.
6090
6096
  * @memberOf module:twgl/textures
6097
+ * @private
6091
6098
  */
6092
6099
  function setTextureTo1PixelColor(gl, tex, options) {
6093
6100
  options = options || defaults$1.textureOptions;
@@ -6197,6 +6204,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
6197
6204
  * @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
6198
6205
  * be non null if there was an error.
6199
6206
  * @memberOf module:twgl/textures
6207
+ * @private
6200
6208
  */
6201
6209
  function loadCubemapFromUrls(gl, tex, options, callback) {
6202
6210
  callback = callback || noop;
@@ -6280,6 +6288,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6280
6288
  * @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
6281
6289
  * be non null if there was an error.
6282
6290
  * @memberOf module:twgl/textures
6291
+ * @private
6283
6292
  */
6284
6293
  function loadSlicesFromUrls(gl, tex, options, callback) {
6285
6294
  callback = callback || noop;
@@ -6858,6 +6867,7 @@ const typeMap = {};
6858
6867
 
6859
6868
  /**
6860
6869
  * Returns the corresponding bind point for a given sampler type
6870
+ * @private
6861
6871
  */
6862
6872
  function getBindPointForSamplerType(gl, type) {
6863
6873
  return typeMap[type].bindPoint;
@@ -7276,6 +7286,7 @@ const spaceRE = /^[ \t]*\n/;
7276
7286
  *
7277
7287
  * @param {string} shaderSource The source of the shader
7278
7288
  * @returns {{shaderSource: string, lineOffset: number}}
7289
+ * @private
7279
7290
  */
7280
7291
  function prepShaderSource(shaderSource) {
7281
7292
  let lineOffset = 0;
@@ -8649,6 +8660,7 @@ function createAttributeSetters(gl, program) {
8649
8660
  * @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
8650
8661
  * @memberOf module:twgl/programs
8651
8662
  * @deprecated use {@link module:twgl.setBuffersAndAttributes}
8663
+ * @private
8652
8664
  */
8653
8665
  function setAttributes(setters, buffers) {
8654
8666
  for (const name in buffers) {
@@ -9776,6 +9788,8 @@ function create3DContext(canvas, opt_attribs) {
9776
9788
  * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
9777
9789
  * @return {WebGLRenderingContext} The created context.
9778
9790
  * @memberOf module:twgl
9791
+ * @deprecated
9792
+ * @private
9779
9793
  */
9780
9794
  function getWebGLContext(canvas, opt_attribs) {
9781
9795
  const gl = create3DContext(canvas, opt_attribs);
@@ -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,9 +255,7 @@ 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
259
  export function createProgram(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): WebGLProgram;
263
260
  export function createProgramAsync(gl: WebGLRenderingContext, shaders: WebGLShader[] | string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<WebGLProgram>;
264
261
  export function createProgramInfoAsync(gl: WebGLRenderingContext, shaderSources: string[], opt_attribs?: ProgramOptions | string[] | ErrorCallback, opt_errorCallback?: ErrorCallback): Promise<ProgramInfo>;
@@ -288,11 +285,6 @@ export function setUniformsAndBindTextures(setters: ProgramInfo | {
288
285
  export function createAttributeSetters(gl: WebGLRenderingContext, program: WebGLProgram): {
289
286
  [key: string]: (...params: any[]) => any;
290
287
  };
291
- export function setAttributes(setters: {
292
- [key: string]: (...params: any[]) => any;
293
- }, buffers: {
294
- [key: string]: AttribInfo;
295
- }): void;
296
288
  export function setBuffersAndAttributes(gl: WebGLRenderingContext, setters: ProgramInfo | {
297
289
  [key: string]: (...params: any[]) => any;
298
290
  }, buffers: BufferInfo | VertexArrayInfo): void;
@@ -314,10 +306,7 @@ export function setTextureParameters(gl: WebGLRenderingContext, tex: WebGLTextur
314
306
  export function setSamplerParameters(gl: WebGLRenderingContext, sampler: WebGLSampler, options: TextureOptions): void;
315
307
  export function setTextureFilteringForSize(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, width?: number, height?: number, internalFormat?: number): void;
316
308
  export function setTextureFromElement(gl: WebGLRenderingContext, tex: WebGLTexture, element: HTMLElement, options?: TextureOptions): void;
317
- export function setTextureTo1PixelColor(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions): void;
318
309
  export function loadTextureFromUrl(gl: WebGLRenderingContext, tex: WebGLTexture, options?: TextureOptions, callback?: TextureReadyCallback): HTMLImageElement;
319
- export function loadCubemapFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: CubemapReadyCallback): void;
320
- export function loadSlicesFromUrls(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions, callback?: ThreeDReadyCallback): void;
321
310
  export function setTextureFromArray(gl: WebGLRenderingContext, tex: WebGLTexture, src: number[] | ArrayBufferView, options?: TextureOptions): void;
322
311
  export function setEmptyTexture(gl: WebGLRenderingContext, tex: WebGLTexture, options: TextureOptions): void;
323
312
  export function createTexture(gl: WebGLRenderingContext, options?: TextureOptions, callback?: TextureReadyCallback): WebGLTexture;
package/dist/4.x/twgl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.23.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 4.23.2 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);
@@ -1725,6 +1735,7 @@ var TEXTURE_2D_ARRAY = 0x8C1A;
1725
1735
  var typeMap = {};
1726
1736
  /**
1727
1737
  * Returns the corresponding bind point for a given sampler type
1738
+ * @private
1728
1739
  */
1729
1740
 
1730
1741
  function getBindPointForSamplerType(gl, type) {
@@ -2444,6 +2455,7 @@ var spaceRE = /^[ \t]*\n/;
2444
2455
  *
2445
2456
  * @param {string} shaderSource The source of the shader
2446
2457
  * @returns {{shaderSource: string, lineOffset: number}}
2458
+ * @private
2447
2459
  */
2448
2460
 
2449
2461
  function prepShaderSource(shaderSource) {
@@ -3973,6 +3985,7 @@ function createAttributeSetters(gl, program) {
3973
3985
  * @param {Object.<string, module:twgl.AttribInfo>} buffers AttribInfos mapped by attribute name.
3974
3986
  * @memberOf module:twgl/programs
3975
3987
  * @deprecated use {@link module:twgl.setBuffersAndAttributes}
3988
+ * @private
3976
3989
  */
3977
3990
 
3978
3991
 
@@ -5809,6 +5822,7 @@ function loadAndUseImage(obj, crossOrigin, callback) {
5809
5822
  * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
5810
5823
  * This is often the same options you passed in when you created the texture.
5811
5824
  * @memberOf module:twgl/textures
5825
+ * @private
5812
5826
  */
5813
5827
 
5814
5828
 
@@ -5923,6 +5937,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
5923
5937
  * @param {module:twgl.CubemapReadyCallback} [callback] A function to be called when all the images have finished loading. err will
5924
5938
  * be non null if there was an error.
5925
5939
  * @memberOf module:twgl/textures
5940
+ * @private
5926
5941
  */
5927
5942
 
5928
5943
 
@@ -6011,6 +6026,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6011
6026
  * @param {module:twgl.ThreeDReadyCallback} [callback] A function to be called when all the images have finished loading. err will
6012
6027
  * be non null if there was an error.
6013
6028
  * @memberOf module:twgl/textures
6029
+ * @private
6014
6030
  */
6015
6031
 
6016
6032
 
@@ -6895,6 +6911,8 @@ function create3DContext(canvas, opt_attribs) {
6895
6911
  * @param {WebGLContextAttributes} [opt_attribs] optional webgl context creation attributes
6896
6912
  * @return {WebGLRenderingContext} The created context.
6897
6913
  * @memberOf module:twgl
6914
+ * @deprecated
6915
+ * @private
6898
6916
  */
6899
6917
 
6900
6918
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twgl.js",
3
- "version": "4.23.1",
3
+ "version": "4.23.2",
4
4
  "description": "A Tiny WebGL helper library",
5
5
  "main": "dist/4.x/twgl-full.js",
6
6
  "types": "dist/4.x/twgl-full.d.ts",