twgl.js 4.21.1 → 4.22.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/README.md CHANGED
@@ -427,7 +427,7 @@ If you just want to set the 2nd light in TWGL you can do this
427
427
  const progInfo = twgl.createProgramInfo(gl, [vs, fs]);
428
428
  ...
429
429
  twgl.setUniforms(progInfo, {
430
- lights[1]: { intensity: 5.0, shininess: 100, color: [1, 0, 0, 1] },
430
+ 'lights[1]': { intensity: 5.0, shininess: 100, color: [1, 0, 0, 1] },
431
431
  });
432
432
  ```
433
433
 
@@ -68,6 +68,7 @@ export type AttachmentOptions = TextureOptions & {
68
68
  format?: number;
69
69
  type?: number;
70
70
  target?: number;
71
+ samples?: number;
71
72
  level?: number;
72
73
  layer?: number;
73
74
  attachment?: WebGLRenderbuffer | WebGLTexture;
@@ -333,10 +334,10 @@ export function createVAOAndSetAttributes(gl: WebGLRenderingContext, setters: {
333
334
  [key: string]: (...params: any[]) => any;
334
335
  }, attribs: {
335
336
  [key: string]: AttribInfo;
336
- }, indices?: WebGLBuffer): void;
337
+ }, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
337
338
  export function createVAOFromBufferInfo(gl: WebGLRenderingContext, programInfo: {
338
339
  [key: string]: (...params: any[]) => any;
339
- } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): void;
340
+ } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
340
341
 
341
342
  declare module v3 {
342
343
  export type Vec3 = number[] | Float32Array;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.21.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 4.22.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
  */
@@ -1197,6 +1197,7 @@ var LINEAR = 0x2601;
1197
1197
  * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
1198
1198
  * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
1199
1199
  * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
1200
+ * @property {number} [samples] The number of samples. Default = 1
1200
1201
  * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
1201
1202
  * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
1202
1203
  * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
@@ -1305,6 +1306,7 @@ function createFramebufferInfo(gl, attachments, width, height) {
1305
1306
  };
1306
1307
  attachments.forEach(function (attachmentOptions) {
1307
1308
  var attachment = attachmentOptions.attachment;
1309
+ var samples = attachmentOptions.samples;
1308
1310
  var format = attachmentOptions.format;
1309
1311
  var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
1310
1312
 
@@ -1313,10 +1315,15 @@ function createFramebufferInfo(gl, attachments, width, height) {
1313
1315
  }
1314
1316
 
1315
1317
  if (!attachment) {
1316
- if (isRenderbufferFormat(format)) {
1318
+ if (samples !== undefined || isRenderbufferFormat(format)) {
1317
1319
  attachment = gl.createRenderbuffer();
1318
1320
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1319
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1321
+
1322
+ if (samples > 1) {
1323
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1324
+ } else {
1325
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1326
+ }
1320
1327
  } else {
1321
1328
  var textureOptions = Object.assign({}, attachmentOptions);
1322
1329
  textureOptions.width = width;
@@ -1404,10 +1411,16 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
1404
1411
  attachments.forEach(function (attachmentOptions, ndx) {
1405
1412
  var attachment = framebufferInfo.attachments[ndx];
1406
1413
  var format = attachmentOptions.format;
1414
+ var samples = attachmentOptions.samples;
1407
1415
 
1408
- if (helper.isRenderbuffer(gl, attachment)) {
1416
+ if (samples !== undefined || helper.isRenderbuffer(gl, attachment)) {
1409
1417
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1410
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1418
+
1419
+ if (samples > 1) {
1420
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1421
+ } else {
1422
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1423
+ }
1411
1424
  } else if (helper.isTexture(gl, attachment)) {
1412
1425
  textures.resizeTexture(gl, attachment, attachmentOptions, width, height);
1413
1426
  } else {
@@ -5850,14 +5863,16 @@ function isBuiltIn(info) {
5850
5863
  return name.startsWith("gl_") || name.startsWith("webgl_");
5851
5864
  }
5852
5865
 
5853
- var tokenRE = /(?=[.[\]])|(?<=[.[\]])/g;
5866
+ var tokenRE = /(\.|\[|]|\w+)/g;
5854
5867
 
5855
5868
  var isDigit = function isDigit(s) {
5856
5869
  return s >= '0' && s <= '9';
5857
5870
  };
5858
5871
 
5859
5872
  function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
5860
- var tokens = fullPath.split(tokenRE);
5873
+ var tokens = fullPath.split(tokenRE).filter(function (s) {
5874
+ return s !== '';
5875
+ });
5861
5876
  var tokenNdx = 0;
5862
5877
  var path = '';
5863
5878
 
@@ -6422,6 +6437,7 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
6422
6437
  * struct Light {
6423
6438
  * float intensity;
6424
6439
  * vec4 color;
6440
+ * float nearFar[2];
6425
6441
  * };
6426
6442
  * uniform Lights {
6427
6443
  * Light lights[2];
@@ -6431,28 +6447,35 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
6431
6447
  *
6432
6448
  * twgl.setBlockUniforms(someBlockInfo, {
6433
6449
  * lights: [
6434
- * { intensity: 5.0, color: [1, 0, 0, 1] },
6435
- * { intensity: 2.0, color: [0, 0, 1, 1] },
6450
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
6451
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
6436
6452
  * ],
6437
6453
  * });
6438
6454
  *
6439
- * // or the more traditional way
6455
+ * or the more traditional way
6440
6456
  *
6441
6457
  * twgl.setBlockUniforms(someBlockInfo, {
6442
6458
  * "lights[0].intensity": 5.0,
6443
6459
  * "lights[0].color": [1, 0, 0, 1],
6460
+ * "lights[0].nearFar": [0.1, 10],
6444
6461
  * "lights[1].intensity": 2.0,
6445
6462
  * "lights[1].color": [0, 0, 1, 1],
6463
+ * "lights[1].nearFar": [0.2, 15],
6446
6464
  * });
6447
6465
  *
6448
6466
  * You can also specify partial paths
6449
6467
  *
6450
6468
  * twgl.setBlockUniforms(someBlockInfo, {
6451
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
6469
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
6452
6470
  * });
6453
6471
  *
6454
6472
  * But you can not specify leaf array indices.
6455
6473
  *
6474
+ * twgl.setBlockUniforms(someBlockInfo, {
6475
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
6476
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
6477
+ * });
6478
+ *
6456
6479
  * **IMPORTANT!**, packing in a UniformBlock is unintuitive.
6457
6480
  * For example the actual layout of `someVec3Array` above in memory
6458
6481
  * is `1, 2, 3, unused, 4, 5, 6, unused`. twgl takes in 6 values
@@ -6612,6 +6635,7 @@ function setUniformTree(tree, values) {
6612
6635
  * struct Light {
6613
6636
  * float intensity;
6614
6637
  * vec4 color;
6638
+ * float nearFar[2];
6615
6639
  * };
6616
6640
  * uniform Light lights[2];
6617
6641
  *
@@ -6619,8 +6643,8 @@ function setUniformTree(tree, values) {
6619
6643
  *
6620
6644
  * twgl.setUniforms(programInfo, {
6621
6645
  * lights: [
6622
- * { intensity: 5.0, color: [1, 0, 0, 1] },
6623
- * { intensity: 2.0, color: [0, 0, 1, 1] },
6646
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
6647
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
6624
6648
  * ],
6625
6649
  * });
6626
6650
  *
@@ -6629,18 +6653,25 @@ function setUniformTree(tree, values) {
6629
6653
  * twgl.setUniforms(programInfo, {
6630
6654
  * "lights[0].intensity": 5.0,
6631
6655
  * "lights[0].color": [1, 0, 0, 1],
6656
+ * "lights[0].nearFar": [0.1, 10],
6632
6657
  * "lights[1].intensity": 2.0,
6633
6658
  * "lights[1].color": [0, 0, 1, 1],
6659
+ * "lights[1].nearFar": [0.2, 15],
6634
6660
  * });
6635
6661
  *
6636
6662
  * You can also specify partial paths
6637
6663
  *
6638
6664
  * twgl.setUniforms(programInfo, {
6639
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
6665
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
6640
6666
  * });
6641
6667
  *
6642
6668
  * But you can not specify leaf array indices
6643
6669
  *
6670
+ * twgl.setUniforms(programInfo, {
6671
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
6672
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
6673
+ * });
6674
+ *
6644
6675
  * @memberOf module:twgl/programs
6645
6676
  */
6646
6677
 
@@ -10754,6 +10785,9 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
10754
10785
  * @param {Object.<string, function>} setters Attribute setters as returned from createAttributeSetters
10755
10786
  * @param {Object.<string, module:twgl.AttribInfo>} attribs AttribInfos mapped by attribute name.
10756
10787
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
10788
+ *
10789
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
10790
+ *
10757
10791
  * @memberOf module:twgl/vertexArrays
10758
10792
  */
10759
10793
 
@@ -10781,6 +10815,9 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
10781
10815
  * @param {Object.<string, function>| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
10782
10816
  * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
10783
10817
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
10818
+ *
10819
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
10820
+ *
10784
10821
  * @memberOf module:twgl/vertexArrays
10785
10822
  */
10786
10823
 
@@ -1,4 +1,4 @@
1
- /* @license twgl.js 4.21.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
1
+ /* @license twgl.js 4.22.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
  /*
@@ -7591,10 +7591,10 @@ function isBuiltIn(info) {
7591
7591
  return name.startsWith("gl_") || name.startsWith("webgl_");
7592
7592
  }
7593
7593
 
7594
- const tokenRE = /(?=[.[\]])|(?<=[.[\]])/g;
7594
+ const tokenRE = /(\.|\[|]|\w+)/g;
7595
7595
  const isDigit = s => s >= '0' && s <= '9';
7596
7596
  function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
7597
- const tokens = fullPath.split(tokenRE);
7597
+ const tokens = fullPath.split(tokenRE).filter(s => s !== '');
7598
7598
  let tokenNdx = 0;
7599
7599
  let path = '';
7600
7600
 
@@ -8125,6 +8125,7 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
8125
8125
  * struct Light {
8126
8126
  * float intensity;
8127
8127
  * vec4 color;
8128
+ * float nearFar[2];
8128
8129
  * };
8129
8130
  * uniform Lights {
8130
8131
  * Light lights[2];
@@ -8134,28 +8135,35 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
8134
8135
  *
8135
8136
  * twgl.setBlockUniforms(someBlockInfo, {
8136
8137
  * lights: [
8137
- * { intensity: 5.0, color: [1, 0, 0, 1] },
8138
- * { intensity: 2.0, color: [0, 0, 1, 1] },
8138
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
8139
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
8139
8140
  * ],
8140
8141
  * });
8141
8142
  *
8142
- * // or the more traditional way
8143
+ * or the more traditional way
8143
8144
  *
8144
8145
  * twgl.setBlockUniforms(someBlockInfo, {
8145
8146
  * "lights[0].intensity": 5.0,
8146
8147
  * "lights[0].color": [1, 0, 0, 1],
8148
+ * "lights[0].nearFar": [0.1, 10],
8147
8149
  * "lights[1].intensity": 2.0,
8148
8150
  * "lights[1].color": [0, 0, 1, 1],
8151
+ * "lights[1].nearFar": [0.2, 15],
8149
8152
  * });
8150
8153
  *
8151
8154
  * You can also specify partial paths
8152
8155
  *
8153
8156
  * twgl.setBlockUniforms(someBlockInfo, {
8154
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
8157
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
8155
8158
  * });
8156
8159
  *
8157
8160
  * But you can not specify leaf array indices.
8158
8161
  *
8162
+ * twgl.setBlockUniforms(someBlockInfo, {
8163
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
8164
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
8165
+ * });
8166
+ *
8159
8167
  * **IMPORTANT!**, packing in a UniformBlock is unintuitive.
8160
8168
  * For example the actual layout of `someVec3Array` above in memory
8161
8169
  * is `1, 2, 3, unused, 4, 5, 6, unused`. twgl takes in 6 values
@@ -8311,6 +8319,7 @@ function setUniformTree(tree, values) {
8311
8319
  * struct Light {
8312
8320
  * float intensity;
8313
8321
  * vec4 color;
8322
+ * float nearFar[2];
8314
8323
  * };
8315
8324
  * uniform Light lights[2];
8316
8325
  *
@@ -8318,8 +8327,8 @@ function setUniformTree(tree, values) {
8318
8327
  *
8319
8328
  * twgl.setUniforms(programInfo, {
8320
8329
  * lights: [
8321
- * { intensity: 5.0, color: [1, 0, 0, 1] },
8322
- * { intensity: 2.0, color: [0, 0, 1, 1] },
8330
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
8331
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
8323
8332
  * ],
8324
8333
  * });
8325
8334
  *
@@ -8328,18 +8337,25 @@ function setUniformTree(tree, values) {
8328
8337
  * twgl.setUniforms(programInfo, {
8329
8338
  * "lights[0].intensity": 5.0,
8330
8339
  * "lights[0].color": [1, 0, 0, 1],
8340
+ * "lights[0].nearFar": [0.1, 10],
8331
8341
  * "lights[1].intensity": 2.0,
8332
8342
  * "lights[1].color": [0, 0, 1, 1],
8343
+ * "lights[1].nearFar": [0.2, 15],
8333
8344
  * });
8334
8345
  *
8335
8346
  * You can also specify partial paths
8336
8347
  *
8337
8348
  * twgl.setUniforms(programInfo, {
8338
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
8349
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
8339
8350
  * });
8340
8351
  *
8341
8352
  * But you can not specify leaf array indices
8342
8353
  *
8354
+ * twgl.setUniforms(programInfo, {
8355
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
8356
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
8357
+ * });
8358
+ *
8343
8359
  * @memberOf module:twgl/programs
8344
8360
  */
8345
8361
  function setUniforms(setters, ...args) { // eslint-disable-line
@@ -8882,6 +8898,7 @@ const LINEAR$1 = 0x2601;
8882
8898
  * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
8883
8899
  * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
8884
8900
  * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
8901
+ * @property {number} [samples] The number of samples. Default = 1
8885
8902
  * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
8886
8903
  * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
8887
8904
  * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
@@ -8986,16 +9003,21 @@ function createFramebufferInfo(gl, attachments, width, height) {
8986
9003
  };
8987
9004
  attachments.forEach(function(attachmentOptions) {
8988
9005
  let attachment = attachmentOptions.attachment;
9006
+ const samples = attachmentOptions.samples;
8989
9007
  const format = attachmentOptions.format;
8990
9008
  let attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
8991
9009
  if (!attachmentPoint) {
8992
9010
  attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
8993
9011
  }
8994
9012
  if (!attachment) {
8995
- if (isRenderbufferFormat(format)) {
9013
+ if (samples !== undefined || isRenderbufferFormat(format)) {
8996
9014
  attachment = gl.createRenderbuffer();
8997
9015
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
8998
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
9016
+ if (samples > 1) {
9017
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
9018
+ } else {
9019
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
9020
+ }
8999
9021
  } else {
9000
9022
  const textureOptions = Object.assign({}, attachmentOptions);
9001
9023
  textureOptions.width = width;
@@ -9088,9 +9110,14 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
9088
9110
  attachments.forEach(function(attachmentOptions, ndx) {
9089
9111
  const attachment = framebufferInfo.attachments[ndx];
9090
9112
  const format = attachmentOptions.format;
9091
- if (isRenderbuffer(gl, attachment)) {
9113
+ const samples = attachmentOptions.samples;
9114
+ if (samples !== undefined || isRenderbuffer(gl, attachment)) {
9092
9115
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
9093
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
9116
+ if (samples > 1) {
9117
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
9118
+ } else {
9119
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
9120
+ }
9094
9121
  } else if (isTexture(gl, attachment)) {
9095
9122
  resizeTexture(gl, attachment, attachmentOptions, width, height);
9096
9123
  } else {
@@ -9244,6 +9271,9 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
9244
9271
  * @param {Object.<string, function>} setters Attribute setters as returned from createAttributeSetters
9245
9272
  * @param {Object.<string, module:twgl.AttribInfo>} attribs AttribInfos mapped by attribute name.
9246
9273
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
9274
+ *
9275
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
9276
+ *
9247
9277
  * @memberOf module:twgl/vertexArrays
9248
9278
  */
9249
9279
  function createVAOAndSetAttributes(gl, setters, attribs, indices) {
@@ -9268,6 +9298,9 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
9268
9298
  * @param {Object.<string, function>| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
9269
9299
  * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
9270
9300
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
9301
+ *
9302
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
9303
+ *
9271
9304
  * @memberOf module:twgl/vertexArrays
9272
9305
  */
9273
9306
  function createVAOFromBufferInfo(gl, programInfo, bufferInfo) {
@@ -68,6 +68,7 @@ export type AttachmentOptions = TextureOptions & {
68
68
  format?: number;
69
69
  type?: number;
70
70
  target?: number;
71
+ samples?: number;
71
72
  level?: number;
72
73
  layer?: number;
73
74
  attachment?: WebGLRenderbuffer | WebGLTexture;
@@ -333,7 +334,7 @@ export function createVAOAndSetAttributes(gl: WebGLRenderingContext, setters: {
333
334
  [key: string]: (...params: any[]) => any;
334
335
  }, attribs: {
335
336
  [key: string]: AttribInfo;
336
- }, indices?: WebGLBuffer): void;
337
+ }, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
337
338
  export function createVAOFromBufferInfo(gl: WebGLRenderingContext, programInfo: {
338
339
  [key: string]: (...params: any[]) => any;
339
- } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): void;
340
+ } | ProgramInfo, bufferInfo: BufferInfo, indices?: WebGLBuffer): WebGLVertexArrayObject | null;
package/dist/4.x/twgl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.21.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 4.22.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
  */
@@ -1197,6 +1197,7 @@ var LINEAR = 0x2601;
1197
1197
  * @property {number} [type] The type. Used for texture. Default = `gl.UNSIGNED_BYTE`.
1198
1198
  * @property {number} [target] The texture target for `gl.framebufferTexture2D`.
1199
1199
  * Defaults to `gl.TEXTURE_2D`. Set to appropriate face for cube maps.
1200
+ * @property {number} [samples] The number of samples. Default = 1
1200
1201
  * @property {number} [level] level for `gl.framebufferTexture2D`. Defaults to 0.
1201
1202
  * @property {number} [layer] layer for `gl.framebufferTextureLayer`. Defaults to undefined.
1202
1203
  * If set then `gl.framebufferTextureLayer` is called, if not then `gl.framebufferTexture2D`
@@ -1305,6 +1306,7 @@ function createFramebufferInfo(gl, attachments, width, height) {
1305
1306
  };
1306
1307
  attachments.forEach(function (attachmentOptions) {
1307
1308
  var attachment = attachmentOptions.attachment;
1309
+ var samples = attachmentOptions.samples;
1308
1310
  var format = attachmentOptions.format;
1309
1311
  var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
1310
1312
 
@@ -1313,10 +1315,15 @@ function createFramebufferInfo(gl, attachments, width, height) {
1313
1315
  }
1314
1316
 
1315
1317
  if (!attachment) {
1316
- if (isRenderbufferFormat(format)) {
1318
+ if (samples !== undefined || isRenderbufferFormat(format)) {
1317
1319
  attachment = gl.createRenderbuffer();
1318
1320
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1319
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1321
+
1322
+ if (samples > 1) {
1323
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1324
+ } else {
1325
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1326
+ }
1320
1327
  } else {
1321
1328
  var textureOptions = Object.assign({}, attachmentOptions);
1322
1329
  textureOptions.width = width;
@@ -1404,10 +1411,16 @@ function resizeFramebufferInfo(gl, framebufferInfo, attachments, width, height)
1404
1411
  attachments.forEach(function (attachmentOptions, ndx) {
1405
1412
  var attachment = framebufferInfo.attachments[ndx];
1406
1413
  var format = attachmentOptions.format;
1414
+ var samples = attachmentOptions.samples;
1407
1415
 
1408
- if (helper.isRenderbuffer(gl, attachment)) {
1416
+ if (samples !== undefined || helper.isRenderbuffer(gl, attachment)) {
1409
1417
  gl.bindRenderbuffer(RENDERBUFFER, attachment);
1410
- gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1418
+
1419
+ if (samples > 1) {
1420
+ gl.renderbufferStorageMultisample(RENDERBUFFER, samples, format, width, height);
1421
+ } else {
1422
+ gl.renderbufferStorage(RENDERBUFFER, format, width, height);
1423
+ }
1411
1424
  } else if (helper.isTexture(gl, attachment)) {
1412
1425
  textures.resizeTexture(gl, attachment, attachmentOptions, width, height);
1413
1426
  } else {
@@ -2772,14 +2785,16 @@ function isBuiltIn(info) {
2772
2785
  return name.startsWith("gl_") || name.startsWith("webgl_");
2773
2786
  }
2774
2787
 
2775
- var tokenRE = /(?=[.[\]])|(?<=[.[\]])/g;
2788
+ var tokenRE = /(\.|\[|]|\w+)/g;
2776
2789
 
2777
2790
  var isDigit = function isDigit(s) {
2778
2791
  return s >= '0' && s <= '9';
2779
2792
  };
2780
2793
 
2781
2794
  function addSetterToUniformTree(fullPath, setter, node, uniformSetters) {
2782
- var tokens = fullPath.split(tokenRE);
2795
+ var tokens = fullPath.split(tokenRE).filter(function (s) {
2796
+ return s !== '';
2797
+ });
2783
2798
  var tokenNdx = 0;
2784
2799
  var path = '';
2785
2800
 
@@ -3344,6 +3359,7 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
3344
3359
  * struct Light {
3345
3360
  * float intensity;
3346
3361
  * vec4 color;
3362
+ * float nearFar[2];
3347
3363
  * };
3348
3364
  * uniform Lights {
3349
3365
  * Light lights[2];
@@ -3353,28 +3369,35 @@ function setUniformBlock(gl, programInfo, uniformBlockInfo) {
3353
3369
  *
3354
3370
  * twgl.setBlockUniforms(someBlockInfo, {
3355
3371
  * lights: [
3356
- * { intensity: 5.0, color: [1, 0, 0, 1] },
3357
- * { intensity: 2.0, color: [0, 0, 1, 1] },
3372
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
3373
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
3358
3374
  * ],
3359
3375
  * });
3360
3376
  *
3361
- * // or the more traditional way
3377
+ * or the more traditional way
3362
3378
  *
3363
3379
  * twgl.setBlockUniforms(someBlockInfo, {
3364
3380
  * "lights[0].intensity": 5.0,
3365
3381
  * "lights[0].color": [1, 0, 0, 1],
3382
+ * "lights[0].nearFar": [0.1, 10],
3366
3383
  * "lights[1].intensity": 2.0,
3367
3384
  * "lights[1].color": [0, 0, 1, 1],
3385
+ * "lights[1].nearFar": [0.2, 15],
3368
3386
  * });
3369
3387
  *
3370
3388
  * You can also specify partial paths
3371
3389
  *
3372
3390
  * twgl.setBlockUniforms(someBlockInfo, {
3373
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
3391
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
3374
3392
  * });
3375
3393
  *
3376
3394
  * But you can not specify leaf array indices.
3377
3395
  *
3396
+ * twgl.setBlockUniforms(someBlockInfo, {
3397
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
3398
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
3399
+ * });
3400
+ *
3378
3401
  * **IMPORTANT!**, packing in a UniformBlock is unintuitive.
3379
3402
  * For example the actual layout of `someVec3Array` above in memory
3380
3403
  * is `1, 2, 3, unused, 4, 5, 6, unused`. twgl takes in 6 values
@@ -3534,6 +3557,7 @@ function setUniformTree(tree, values) {
3534
3557
  * struct Light {
3535
3558
  * float intensity;
3536
3559
  * vec4 color;
3560
+ * float nearFar[2];
3537
3561
  * };
3538
3562
  * uniform Light lights[2];
3539
3563
  *
@@ -3541,8 +3565,8 @@ function setUniformTree(tree, values) {
3541
3565
  *
3542
3566
  * twgl.setUniforms(programInfo, {
3543
3567
  * lights: [
3544
- * { intensity: 5.0, color: [1, 0, 0, 1] },
3545
- * { intensity: 2.0, color: [0, 0, 1, 1] },
3568
+ * { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.1, 10] },
3569
+ * { intensity: 2.0, color: [0, 0, 1, 1], nearFar[0.2, 15] },
3546
3570
  * ],
3547
3571
  * });
3548
3572
  *
@@ -3551,18 +3575,25 @@ function setUniformTree(tree, values) {
3551
3575
  * twgl.setUniforms(programInfo, {
3552
3576
  * "lights[0].intensity": 5.0,
3553
3577
  * "lights[0].color": [1, 0, 0, 1],
3578
+ * "lights[0].nearFar": [0.1, 10],
3554
3579
  * "lights[1].intensity": 2.0,
3555
3580
  * "lights[1].color": [0, 0, 1, 1],
3581
+ * "lights[1].nearFar": [0.2, 15],
3556
3582
  * });
3557
3583
  *
3558
3584
  * You can also specify partial paths
3559
3585
  *
3560
3586
  * twgl.setUniforms(programInfo, {
3561
- * 'lights[1]: { intensity: 5.0, color: [1, 0, 0, 1] },
3587
+ * 'lights[1]': { intensity: 5.0, color: [1, 0, 0, 1], nearFar[0.2, 15] },
3562
3588
  * });
3563
3589
  *
3564
3590
  * But you can not specify leaf array indices
3565
3591
  *
3592
+ * twgl.setUniforms(programInfo, {
3593
+ * 'lights[1].nearFar[1]': 15, // BAD! nearFar is a leaf
3594
+ * 'lights[1].nearFar': [0.2, 15], // GOOD
3595
+ * });
3596
+ *
3566
3597
  * @memberOf module:twgl/programs
3567
3598
  */
3568
3599
 
@@ -7195,6 +7226,9 @@ function createVertexArrayInfo(gl, programInfos, bufferInfo) {
7195
7226
  * @param {Object.<string, function>} setters Attribute setters as returned from createAttributeSetters
7196
7227
  * @param {Object.<string, module:twgl.AttribInfo>} attribs AttribInfos mapped by attribute name.
7197
7228
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
7229
+ *
7230
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
7231
+ *
7198
7232
  * @memberOf module:twgl/vertexArrays
7199
7233
  */
7200
7234
 
@@ -7222,6 +7256,9 @@ function createVAOAndSetAttributes(gl, setters, attribs, indices) {
7222
7256
  * @param {Object.<string, function>| module:twgl.ProgramInfo} programInfo as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters
7223
7257
  * @param {module:twgl.BufferInfo} bufferInfo BufferInfo as returned from createBufferInfoFromArrays etc...
7224
7258
  * @param {WebGLBuffer} [indices] an optional ELEMENT_ARRAY_BUFFER of indices
7259
+ *
7260
+ * @return {WebGLVertexArrayObject|null} The created WebGLVertexArrayObject
7261
+ *
7225
7262
  * @memberOf module:twgl/vertexArrays
7226
7263
  */
7227
7264
 
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "twgl.js",
3
- "version": "4.21.1",
3
+ "version": "4.22.1",
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",
7
7
  "module": "dist/4.x/twgl-full.module.js",
8
8
  "scripts": {
9
9
  "check-ci": "npm run lint && npm run build && npm test",
10
- "test": "npm run testjs && npm run testts && npm run testbrowser",
11
- "testjs": "node node_modules/mocha/bin/mocha --recursive 'test/src/js/*-harness.js'",
10
+ "test": "npm run testts && npm run testbrowser",
12
11
  "testts": "tsc --project test/src/ts/",
13
12
  "testbrowser": "node test/puppeteer.js",
14
13
  "pre-push": "grunt eslint",
@@ -73,13 +72,11 @@
73
72
  "load-grunt-tasks": "^5.1.0",
74
73
  "marked": "^1.1.1",
75
74
  "minami": "^1.2.3",
76
- "mocha": "^8.1.3",
77
75
  "puppeteer": "^10.4.0",
78
76
  "requirejs": "^2.3.5",
79
77
  "rollup": "^2.27.1",
80
78
  "semver": "^7.3.2",
81
79
  "servez": "^1.10.0",
82
- "should": "^13.2.0",
83
80
  "terser-webpack-plugin": "^4.2.2",
84
81
  "tsd-jsdoc": "^2.1.2",
85
82
  "typescript": "^3.9.7",