twgl.js 4.23.2 → 5.0.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
@@ -16,7 +16,7 @@ Not including the shaders (which is a simple quad shader) here's the entire code
16
16
 
17
17
  ```html
18
18
  <canvas id="c"></canvas>
19
- <script src="../dist/4.x/twgl-full.min.js"></script>
19
+ <script src="../dist/5.x/twgl-full.min.js"></script>
20
20
  <script>
21
21
  const gl = document.getElementById("c").getContext("webgl");
22
22
  const programInfo = twgl.createProgramInfo(gl, ["vs", "fs"]);
File without changes
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.23.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 5.0.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
  */
@@ -349,8 +349,9 @@ function makeTypedArray(array, name) {
349
349
  * @property {boolean} [normalize] whether or not to normalize the data. Default = false
350
350
  * @property {number} [offset] offset into buffer in bytes. Default = 0
351
351
  * @property {number} [stride] the stride in bytes per element. Default = 0
352
- * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
353
- * where as anything else = do call it with this value
352
+ * @property {number} [divisor] the divisor in instances. Default = 0.
353
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
354
+ * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
354
355
  * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
355
356
  * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
356
357
  * @memberOf module:twgl
@@ -372,8 +373,9 @@ function makeTypedArray(array, name) {
372
373
  * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
373
374
  * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
374
375
  * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
375
- * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
376
- * where as anything else = do call it with this value
376
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = 0.
377
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
378
+ * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
377
379
  * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
378
380
  * @property {string} [name] synonym for `attrib`.
379
381
  * @property {string} [attribName] synonym for `attrib`.
@@ -1253,6 +1255,12 @@ renderbufferFormats[STENCIL_INDEX8] = true;
1253
1255
  function isRenderbufferFormat(format) {
1254
1256
  return renderbufferFormats[format];
1255
1257
  }
1258
+
1259
+ var MAX_COLOR_ATTACHMENT_POINTS = 32; // even an 3090 only supports 8 but WebGL/OpenGL ES define constants for 32
1260
+
1261
+ function isColorAttachmentPoint(attachmentPoint) {
1262
+ return attachmentPoint >= COLOR_ATTACHMENT0 && attachmentPoint < COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENT_POINTS;
1263
+ }
1256
1264
  /**
1257
1265
  * @typedef {Object} FramebufferInfo
1258
1266
  * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
@@ -1266,6 +1274,9 @@ function isRenderbufferFormat(format) {
1266
1274
  * Creates a framebuffer and attachments.
1267
1275
  *
1268
1276
  * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
1277
+ * It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
1278
+ * Note: If this is WebGL2 or if you called {@link module:twgl.addExtensionsToContext} then it will set the drawBuffers
1279
+ * to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
1269
1280
  *
1270
1281
  * The simplest usage
1271
1282
  *
@@ -1307,21 +1318,25 @@ function createFramebufferInfo(gl, attachments, width, height) {
1307
1318
  width = width || gl.drawingBufferWidth;
1308
1319
  height = height || gl.drawingBufferHeight;
1309
1320
  attachments = attachments || defaultAttachments;
1310
- var colorAttachmentCount = 0;
1321
+ var usedColorAttachmentsPoints = [];
1311
1322
  var framebufferInfo = {
1312
1323
  framebuffer: fb,
1313
1324
  attachments: [],
1314
1325
  width: width,
1315
1326
  height: height
1316
1327
  };
1317
- attachments.forEach(function (attachmentOptions) {
1328
+ attachments.forEach(function (attachmentOptions, i) {
1318
1329
  var attachment = attachmentOptions.attachment;
1319
1330
  var samples = attachmentOptions.samples;
1320
1331
  var format = attachmentOptions.format;
1321
1332
  var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
1322
1333
 
1323
1334
  if (!attachmentPoint) {
1324
- attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
1335
+ attachmentPoint = COLOR_ATTACHMENT0 + i;
1336
+ }
1337
+
1338
+ if (isColorAttachmentPoint(attachmentPoint)) {
1339
+ usedColorAttachmentsPoints.push(attachmentPoint);
1325
1340
  }
1326
1341
 
1327
1342
  if (!attachment) {
@@ -1365,6 +1380,11 @@ function createFramebufferInfo(gl, attachments, width, height) {
1365
1380
 
1366
1381
  framebufferInfo.attachments.push(attachment);
1367
1382
  });
1383
+
1384
+ if (gl.drawBuffers) {
1385
+ gl.drawBuffers(usedColorAttachmentsPoints);
1386
+ }
1387
+
1368
1388
  return framebufferInfo;
1369
1389
  }
1370
1390
  /**
@@ -2948,7 +2968,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
2948
2968
  *
2949
2969
  * example:
2950
2970
  *
2951
- * const arrays = twgl.primitives.createPlaneArrays(1);
2971
+ * const arrays = twgl.primitives.createPlaneVertices(1);
2952
2972
  * twgl.primitives.reorientVertices(arrays, m4.rotationX(Math.PI * 0.5));
2953
2973
  * const bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
2954
2974
  *
@@ -5332,8 +5352,8 @@ function floatAttribSetter(gl, index) {
5332
5352
  gl.enableVertexAttribArray(index);
5333
5353
  gl.vertexAttribPointer(index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
5334
5354
 
5335
- if (b.divisor !== undefined) {
5336
- gl.vertexAttribDivisor(index, b.divisor);
5355
+ if (gl.vertexAttribDivisor) {
5356
+ gl.vertexAttribDivisor(index, b.divisor || 0);
5337
5357
  }
5338
5358
  }
5339
5359
  };
@@ -5354,8 +5374,8 @@ function intAttribSetter(gl, index) {
5354
5374
  gl.enableVertexAttribArray(index);
5355
5375
  gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
5356
5376
 
5357
- if (b.divisor !== undefined) {
5358
- gl.vertexAttribDivisor(index, b.divisor);
5377
+ if (gl.vertexAttribDivisor) {
5378
+ gl.vertexAttribDivisor(index, b.divisor || 0);
5359
5379
  }
5360
5380
  }
5361
5381
  };
@@ -5376,8 +5396,8 @@ function uintAttribSetter(gl, index) {
5376
5396
  gl.enableVertexAttribArray(index);
5377
5397
  gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
5378
5398
 
5379
- if (b.divisor !== undefined) {
5380
- gl.vertexAttribDivisor(index, b.divisor);
5399
+ if (gl.vertexAttribDivisor) {
5400
+ gl.vertexAttribDivisor(index, b.divisor || 0);
5381
5401
  }
5382
5402
  }
5383
5403
  };
@@ -5401,8 +5421,8 @@ function matAttribSetter(gl, index, typeInfo) {
5401
5421
  gl.enableVertexAttribArray(index + i);
5402
5422
  gl.vertexAttribPointer(index + i, size, type, normalize, stride, offset + rowOffset * i);
5403
5423
 
5404
- if (b.divisor !== undefined) {
5405
- gl.vertexAttribDivisor(index + i, b.divisor);
5424
+ if (gl.vertexAttribDivisor) {
5425
+ gl.vertexAttribDivisor(index + i, b.divisor || 0);
5406
5426
  }
5407
5427
  }
5408
5428
  };
@@ -1,4 +1,4 @@
1
- /* @license twgl.js 4.23.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
1
+ /* @license twgl.js 5.0.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
  /*
@@ -2148,8 +2148,9 @@ function makeTypedArray(array, name) {
2148
2148
  * @property {boolean} [normalize] whether or not to normalize the data. Default = false
2149
2149
  * @property {number} [offset] offset into buffer in bytes. Default = 0
2150
2150
  * @property {number} [stride] the stride in bytes per element. Default = 0
2151
- * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
2152
- * where as anything else = do call it with this value
2151
+ * @property {number} [divisor] the divisor in instances. Default = 0.
2152
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
2153
+ * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
2153
2154
  * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
2154
2155
  * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
2155
2156
  * @memberOf module:twgl
@@ -2171,8 +2172,9 @@ function makeTypedArray(array, name) {
2171
2172
  * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
2172
2173
  * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
2173
2174
  * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
2174
- * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
2175
- * where as anything else = do call it with this value
2175
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = 0.
2176
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
2177
+ * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
2176
2178
  * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
2177
2179
  * @property {string} [name] synonym for `attrib`.
2178
2180
  * @property {string} [attribName] synonym for `attrib`.
@@ -7141,8 +7143,8 @@ function floatAttribSetter(gl, index) {
7141
7143
  gl.enableVertexAttribArray(index);
7142
7144
  gl.vertexAttribPointer(
7143
7145
  index, b.numComponents || b.size, b.type || FLOAT$3, b.normalize || false, b.stride || 0, b.offset || 0);
7144
- if (b.divisor !== undefined) {
7145
- gl.vertexAttribDivisor(index, b.divisor);
7146
+ if (gl.vertexAttribDivisor) {
7147
+ gl.vertexAttribDivisor(index, b.divisor || 0);
7146
7148
  }
7147
7149
  }
7148
7150
  };
@@ -7162,8 +7164,8 @@ function intAttribSetter(gl, index) {
7162
7164
  gl.enableVertexAttribArray(index);
7163
7165
  gl.vertexAttribIPointer(
7164
7166
  index, b.numComponents || b.size, b.type || INT$3, b.stride || 0, b.offset || 0);
7165
- if (b.divisor !== undefined) {
7166
- gl.vertexAttribDivisor(index, b.divisor);
7167
+ if (gl.vertexAttribDivisor) {
7168
+ gl.vertexAttribDivisor(index, b.divisor || 0);
7167
7169
  }
7168
7170
  }
7169
7171
  };
@@ -7183,8 +7185,8 @@ function uintAttribSetter(gl, index) {
7183
7185
  gl.enableVertexAttribArray(index);
7184
7186
  gl.vertexAttribIPointer(
7185
7187
  index, b.numComponents || b.size, b.type || UNSIGNED_INT$3, b.stride || 0, b.offset || 0);
7186
- if (b.divisor !== undefined) {
7187
- gl.vertexAttribDivisor(index, b.divisor);
7188
+ if (gl.vertexAttribDivisor) {
7189
+ gl.vertexAttribDivisor(index, b.divisor || 0);
7188
7190
  }
7189
7191
  }
7190
7192
  };
@@ -7208,8 +7210,8 @@ function matAttribSetter(gl, index, typeInfo) {
7208
7210
  gl.enableVertexAttribArray(index + i);
7209
7211
  gl.vertexAttribPointer(
7210
7212
  index + i, size, type, normalize, stride, offset + rowOffset * i);
7211
- if (b.divisor !== undefined) {
7212
- gl.vertexAttribDivisor(index + i, b.divisor);
7213
+ if (gl.vertexAttribDivisor) {
7214
+ gl.vertexAttribDivisor(index + i, b.divisor || 0);
7213
7215
  }
7214
7216
  }
7215
7217
  };
@@ -9146,6 +9148,12 @@ function isRenderbufferFormat(format) {
9146
9148
  return renderbufferFormats[format];
9147
9149
  }
9148
9150
 
9151
+ const MAX_COLOR_ATTACHMENT_POINTS = 32; // even an 3090 only supports 8 but WebGL/OpenGL ES define constants for 32
9152
+
9153
+ function isColorAttachmentPoint(attachmentPoint) {
9154
+ return attachmentPoint >= COLOR_ATTACHMENT0 && attachmentPoint < COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENT_POINTS;
9155
+ }
9156
+
9149
9157
  /**
9150
9158
  * @typedef {Object} FramebufferInfo
9151
9159
  * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
@@ -9159,6 +9167,9 @@ function isRenderbufferFormat(format) {
9159
9167
  * Creates a framebuffer and attachments.
9160
9168
  *
9161
9169
  * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
9170
+ * It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
9171
+ * Note: If this is WebGL2 or if you called {@link module:twgl.addExtensionsToContext} then it will set the drawBuffers
9172
+ * to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
9162
9173
  *
9163
9174
  * The simplest usage
9164
9175
  *
@@ -9198,20 +9209,24 @@ function createFramebufferInfo(gl, attachments, width, height) {
9198
9209
  width = width || gl.drawingBufferWidth;
9199
9210
  height = height || gl.drawingBufferHeight;
9200
9211
  attachments = attachments || defaultAttachments;
9201
- let colorAttachmentCount = 0;
9212
+ const usedColorAttachmentsPoints = [];
9202
9213
  const framebufferInfo = {
9203
9214
  framebuffer: fb,
9204
9215
  attachments: [],
9205
9216
  width: width,
9206
9217
  height: height,
9207
9218
  };
9208
- attachments.forEach(function(attachmentOptions) {
9219
+
9220
+ attachments.forEach(function(attachmentOptions, i) {
9209
9221
  let attachment = attachmentOptions.attachment;
9210
9222
  const samples = attachmentOptions.samples;
9211
9223
  const format = attachmentOptions.format;
9212
9224
  let attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
9213
9225
  if (!attachmentPoint) {
9214
- attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
9226
+ attachmentPoint = COLOR_ATTACHMENT0 + i;
9227
+ }
9228
+ if (isColorAttachmentPoint(attachmentPoint)) {
9229
+ usedColorAttachmentsPoints.push(attachmentPoint);
9215
9230
  }
9216
9231
  if (!attachment) {
9217
9232
  if (samples !== undefined || isRenderbufferFormat(format)) {
@@ -9259,6 +9274,9 @@ function createFramebufferInfo(gl, attachments, width, height) {
9259
9274
  }
9260
9275
  framebufferInfo.attachments.push(attachment);
9261
9276
  });
9277
+ if (gl.drawBuffers) {
9278
+ gl.drawBuffers(usedColorAttachmentsPoints);
9279
+ }
9262
9280
  return framebufferInfo;
9263
9281
  }
9264
9282
 
File without changes
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 4.23.2 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 5.0.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
  */
@@ -349,8 +349,9 @@ function makeTypedArray(array, name) {
349
349
  * @property {boolean} [normalize] whether or not to normalize the data. Default = false
350
350
  * @property {number} [offset] offset into buffer in bytes. Default = 0
351
351
  * @property {number} [stride] the stride in bytes per element. Default = 0
352
- * @property {number} [divisor] the divisor in instances. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
353
- * where as anything else = do call it with this value
352
+ * @property {number} [divisor] the divisor in instances. Default = 0.
353
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
354
+ * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
354
355
  * @property {WebGLBuffer} buffer the buffer that contains the data for this attribute
355
356
  * @property {number} [drawType] the draw type passed to gl.bufferData. Default = gl.STATIC_DRAW
356
357
  * @memberOf module:twgl
@@ -372,8 +373,9 @@ function makeTypedArray(array, name) {
372
373
  * @property {boolean} [normalize] normalize for `vertexAttribPointer`. Default is true if type is `Int8Array` or `Uint8Array` otherwise false.
373
374
  * @property {number} [stride] stride for `vertexAttribPointer`. Default = 0
374
375
  * @property {number} [offset] offset for `vertexAttribPointer`. Default = 0
375
- * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = undefined. Note: undefined = don't call gl.vertexAttribDivisor
376
- * where as anything else = do call it with this value
376
+ * @property {number} [divisor] divisor for `vertexAttribDivisor`. Default = 0.
377
+ * Requires WebGL2 or the ANGLE_instanced_arrays extension.
378
+ * and, if you using WebGL1 you must have called {@link module:twgl.addExtensionsToContext}
377
379
  * @property {string} [attrib] name of attribute this array maps to. Defaults to same name as array prefixed by the default attribPrefix.
378
380
  * @property {string} [name] synonym for `attrib`.
379
381
  * @property {string} [attribName] synonym for `attrib`.
@@ -1253,6 +1255,12 @@ renderbufferFormats[STENCIL_INDEX8] = true;
1253
1255
  function isRenderbufferFormat(format) {
1254
1256
  return renderbufferFormats[format];
1255
1257
  }
1258
+
1259
+ var MAX_COLOR_ATTACHMENT_POINTS = 32; // even an 3090 only supports 8 but WebGL/OpenGL ES define constants for 32
1260
+
1261
+ function isColorAttachmentPoint(attachmentPoint) {
1262
+ return attachmentPoint >= COLOR_ATTACHMENT0 && attachmentPoint < COLOR_ATTACHMENT0 + MAX_COLOR_ATTACHMENT_POINTS;
1263
+ }
1256
1264
  /**
1257
1265
  * @typedef {Object} FramebufferInfo
1258
1266
  * @property {WebGLFramebuffer} framebuffer The WebGLFramebuffer for this framebufferInfo
@@ -1266,6 +1274,9 @@ function isRenderbufferFormat(format) {
1266
1274
  * Creates a framebuffer and attachments.
1267
1275
  *
1268
1276
  * This returns a {@link module:twgl.FramebufferInfo} because it needs to return the attachments as well as the framebuffer.
1277
+ * It also leaves the framebuffer it just created as the currently bound `FRAMEBUFFER`.
1278
+ * Note: If this is WebGL2 or if you called {@link module:twgl.addExtensionsToContext} then it will set the drawBuffers
1279
+ * to `[COLOR_ATTACHMENT0, COLOR_ATTACHMENT1, ...]` for how ever many color attachments were created.
1269
1280
  *
1270
1281
  * The simplest usage
1271
1282
  *
@@ -1307,21 +1318,25 @@ function createFramebufferInfo(gl, attachments, width, height) {
1307
1318
  width = width || gl.drawingBufferWidth;
1308
1319
  height = height || gl.drawingBufferHeight;
1309
1320
  attachments = attachments || defaultAttachments;
1310
- var colorAttachmentCount = 0;
1321
+ var usedColorAttachmentsPoints = [];
1311
1322
  var framebufferInfo = {
1312
1323
  framebuffer: fb,
1313
1324
  attachments: [],
1314
1325
  width: width,
1315
1326
  height: height
1316
1327
  };
1317
- attachments.forEach(function (attachmentOptions) {
1328
+ attachments.forEach(function (attachmentOptions, i) {
1318
1329
  var attachment = attachmentOptions.attachment;
1319
1330
  var samples = attachmentOptions.samples;
1320
1331
  var format = attachmentOptions.format;
1321
1332
  var attachmentPoint = attachmentOptions.attachmentPoint || getAttachmentPointForFormat(format, attachmentOptions.internalFormat);
1322
1333
 
1323
1334
  if (!attachmentPoint) {
1324
- attachmentPoint = COLOR_ATTACHMENT0 + colorAttachmentCount++;
1335
+ attachmentPoint = COLOR_ATTACHMENT0 + i;
1336
+ }
1337
+
1338
+ if (isColorAttachmentPoint(attachmentPoint)) {
1339
+ usedColorAttachmentsPoints.push(attachmentPoint);
1325
1340
  }
1326
1341
 
1327
1342
  if (!attachment) {
@@ -1365,6 +1380,11 @@ function createFramebufferInfo(gl, attachments, width, height) {
1365
1380
 
1366
1381
  framebufferInfo.attachments.push(attachment);
1367
1382
  });
1383
+
1384
+ if (gl.drawBuffers) {
1385
+ gl.drawBuffers(usedColorAttachmentsPoints);
1386
+ }
1387
+
1368
1388
  return framebufferInfo;
1369
1389
  }
1370
1390
  /**
@@ -2243,8 +2263,8 @@ function floatAttribSetter(gl, index) {
2243
2263
  gl.enableVertexAttribArray(index);
2244
2264
  gl.vertexAttribPointer(index, b.numComponents || b.size, b.type || FLOAT, b.normalize || false, b.stride || 0, b.offset || 0);
2245
2265
 
2246
- if (b.divisor !== undefined) {
2247
- gl.vertexAttribDivisor(index, b.divisor);
2266
+ if (gl.vertexAttribDivisor) {
2267
+ gl.vertexAttribDivisor(index, b.divisor || 0);
2248
2268
  }
2249
2269
  }
2250
2270
  };
@@ -2265,8 +2285,8 @@ function intAttribSetter(gl, index) {
2265
2285
  gl.enableVertexAttribArray(index);
2266
2286
  gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || INT, b.stride || 0, b.offset || 0);
2267
2287
 
2268
- if (b.divisor !== undefined) {
2269
- gl.vertexAttribDivisor(index, b.divisor);
2288
+ if (gl.vertexAttribDivisor) {
2289
+ gl.vertexAttribDivisor(index, b.divisor || 0);
2270
2290
  }
2271
2291
  }
2272
2292
  };
@@ -2287,8 +2307,8 @@ function uintAttribSetter(gl, index) {
2287
2307
  gl.enableVertexAttribArray(index);
2288
2308
  gl.vertexAttribIPointer(index, b.numComponents || b.size, b.type || UNSIGNED_INT, b.stride || 0, b.offset || 0);
2289
2309
 
2290
- if (b.divisor !== undefined) {
2291
- gl.vertexAttribDivisor(index, b.divisor);
2310
+ if (gl.vertexAttribDivisor) {
2311
+ gl.vertexAttribDivisor(index, b.divisor || 0);
2292
2312
  }
2293
2313
  }
2294
2314
  };
@@ -2312,8 +2332,8 @@ function matAttribSetter(gl, index, typeInfo) {
2312
2332
  gl.enableVertexAttribArray(index + i);
2313
2333
  gl.vertexAttribPointer(index + i, size, type, normalize, stride, offset + rowOffset * i);
2314
2334
 
2315
- if (b.divisor !== undefined) {
2316
- gl.vertexAttribDivisor(index + i, b.divisor);
2335
+ if (gl.vertexAttribDivisor) {
2336
+ gl.vertexAttribDivisor(index + i, b.divisor || 0);
2317
2337
  }
2318
2338
  }
2319
2339
  };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "twgl.js",
3
- "version": "4.23.2",
3
+ "version": "5.0.1",
4
4
  "description": "A Tiny WebGL helper library",
5
- "main": "dist/4.x/twgl-full.js",
6
- "types": "dist/4.x/twgl-full.d.ts",
7
- "module": "dist/4.x/twgl-full.module.js",
5
+ "main": "dist/5.x/twgl-full.js",
6
+ "types": "dist/5.x/twgl-full.d.ts",
7
+ "module": "dist/5.x/twgl-full.module.js",
8
8
  "scripts": {
9
9
  "check-ci": "npm run lint && npm run build && npm test",
10
10
  "test": "npm run testts && npm run testbrowser",
@@ -38,11 +38,11 @@
38
38
  },
39
39
  "homepage": "https://github.com/greggman/twgl.js",
40
40
  "files": [
41
- "dist/4.x/twgl-full.js",
42
- "dist/4.x/twgl.js",
43
- "dist/4.x/twgl-full.d.ts",
44
- "dist/4.x/twgl.d.ts",
45
- "dist/4.x/twgl-full.module.js"
41
+ "dist/5.x/twgl-full.js",
42
+ "dist/5.x/twgl.js",
43
+ "dist/5.x/twgl-full.d.ts",
44
+ "dist/5.x/twgl.d.ts",
45
+ "dist/5.x/twgl-full.module.js"
46
46
  ],
47
47
  "devDependencies": {
48
48
  "@babel/core": "^7.11.6",