twgl.js 5.5.4 → 6.2.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 5.5.4 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 6.2.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
  */
@@ -5408,7 +5408,7 @@ function deleteProgramAndShaders(gl, program, notThese) {
5408
5408
  try {
5409
5409
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
5410
5410
  var shader = _step.value;
5411
- if (notThese.has(shader)) {
5411
+ if (!notThese.has(shader)) {
5412
5412
  gl.deleteShader(shader);
5413
5413
  }
5414
5414
  }
@@ -5443,8 +5443,8 @@ function createProgramNoCheck(gl, shaders, programOptions) {
5443
5443
  shader = gl.createShader(type);
5444
5444
  gl.shaderSource(shader, prepShaderSource(src).shaderSource);
5445
5445
  gl.compileShader(shader);
5446
- gl.attachShader(program, shader);
5447
5446
  }
5447
+ gl.attachShader(program, shader);
5448
5448
  }
5449
5449
  Object.entries(attribLocations).forEach(function (_ref) {
5450
5450
  var _ref2 = _slicedToArray(_ref, 2),
@@ -6064,6 +6064,7 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
6064
6064
  * @property {ArrayBuffer} array The array buffer that contains the uniform values
6065
6065
  * @property {Float32Array} asFloat A float view on the array buffer. This is useful
6066
6066
  * inspecting the contents of the buffer in the debugger.
6067
+ * @property {Uint8Array} asUint8t A uint8 view on the array buffer.
6067
6068
  * @property {WebGLBuffer} buffer A WebGL buffer that will hold a copy of the uniform values for rendering.
6068
6069
  * @property {number} [offset] offset into buffer
6069
6070
  * @property {Object<string, ArrayBufferView>} uniforms A uniform name to ArrayBufferView map.
@@ -6082,6 +6083,15 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
6082
6083
  * @memberOf module:twgl
6083
6084
  */
6084
6085
 
6086
+ /**
6087
+ * Options to allow createUniformBlockInfo to use an existing buffer and arrayBuffer at an offset
6088
+ * @typedef {Object} UniformBlockInfoOptions
6089
+ * @property {ArrayBuffer} [array] an existing array buffer to use for values
6090
+ * @property {number} [offset] the offset in bytes to use in the array buffer (default = 0)
6091
+ * @property {WebGLBuffer} [buffer] the buffer to use for this uniform block info
6092
+ * @property {number} [bufferOffset] the offset in bytes in the buffer to use (default = use offset above)
6093
+ */
6094
+
6085
6095
  /**
6086
6096
  * Creates a `UniformBlockInfo` for the specified block
6087
6097
  *
@@ -6096,10 +6106,13 @@ function createUniformBlockUniformSetter(view, isArray, rows, cols) {
6096
6106
  * @param {module:twgl.UniformBlockSpec} uniformBlockSpec. A UniformBlockSpec as returned
6097
6107
  * from {@link module:twgl.createUniformBlockSpecFromProgram}.
6098
6108
  * @param {string} blockName The name of the block.
6109
+ * @param {module:twgl.UniformBlockInfoOptions} [options] Optional options for using existing an existing buffer and arrayBuffer
6099
6110
  * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
6100
6111
  * @memberOf module:twgl/programs
6101
6112
  */
6102
6113
  function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockName) {
6114
+ var _options$offset, _options$array, _options$buffer, _options$bufferOffset;
6115
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
6103
6116
  var blockSpecs = uniformBlockSpec.blockSpecs;
6104
6117
  var uniformData = uniformBlockSpec.uniformData;
6105
6118
  var blockSpec = blockSpecs[blockName];
@@ -6110,10 +6123,14 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
6110
6123
  uniforms: {}
6111
6124
  };
6112
6125
  }
6113
- var array = new ArrayBuffer(blockSpec.size);
6114
- var buffer = gl.createBuffer();
6126
+ var offset = (_options$offset = options.offset) !== null && _options$offset !== void 0 ? _options$offset : 0;
6127
+ var array = (_options$array = options.array) !== null && _options$array !== void 0 ? _options$array : new ArrayBuffer(blockSpec.size);
6128
+ var buffer = (_options$buffer = options.buffer) !== null && _options$buffer !== void 0 ? _options$buffer : gl.createBuffer();
6115
6129
  var uniformBufferIndex = blockSpec.index;
6116
6130
  gl.bindBuffer(UNIFORM_BUFFER, buffer);
6131
+ if (!options.buffer) {
6132
+ gl.bufferData(UNIFORM_BUFFER, array.byteLength, DYNAMIC_DRAW);
6133
+ }
6117
6134
  gl.uniformBlockBinding(program, blockSpec.index, uniformBufferIndex);
6118
6135
  var prefix = blockName + ".";
6119
6136
  if (arraySuffixRE.test(prefix)) {
@@ -6135,7 +6152,7 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
6135
6152
  var typeInfo = typeMap[data.type];
6136
6153
  var Type = typeInfo.Type;
6137
6154
  var byteLength = isArray ? pad(typeInfo.size, 16) * data.size : typeInfo.size * data.size;
6138
- var uniformView = new Type(array, data.offset, byteLength / Type.BYTES_PER_ELEMENT);
6155
+ var uniformView = new Type(array, offset + data.offset, byteLength / Type.BYTES_PER_ELEMENT);
6139
6156
  uniforms[name] = uniformView;
6140
6157
  // Note: I'm not sure what to do here. The original
6141
6158
  // idea was to create TypedArray views into each part
@@ -6171,9 +6188,13 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
6171
6188
  array: array,
6172
6189
  asFloat: new Float32Array(array),
6173
6190
  // for debugging
6191
+ asUint8: new Uint8Array(array),
6192
+ // needed for gl.bufferSubData because it doesn't take an array buffer
6174
6193
  buffer: buffer,
6175
6194
  uniforms: uniforms,
6176
- setters: setters
6195
+ setters: setters,
6196
+ offset: (_options$bufferOffset = options.bufferOffset) !== null && _options$bufferOffset !== void 0 ? _options$bufferOffset : offset,
6197
+ size: blockSpec.size
6177
6198
  };
6178
6199
  }
6179
6200
 
@@ -6190,11 +6211,13 @@ function createUniformBlockInfoFromProgram(gl, program, uniformBlockSpec, blockN
6190
6211
  * @param {module:twgl.ProgramInfo} programInfo a `ProgramInfo`
6191
6212
  * as returned from {@link module:twgl.createProgramInfo}
6192
6213
  * @param {string} blockName The name of the block.
6214
+ * @param {module:twgl.UniformBlockInfoOptions} [options] Optional options for using existing an existing buffer and arrayBuffer
6193
6215
  * @return {module:twgl.UniformBlockInfo} The created UniformBlockInfo
6194
6216
  * @memberOf module:twgl/programs
6195
6217
  */
6196
6218
  function createUniformBlockInfo(gl, programInfo, blockName) {
6197
- return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName);
6219
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
6220
+ return createUniformBlockInfoFromProgram(gl, programInfo.program, programInfo.uniformBlockSpec, blockName, options);
6198
6221
  }
6199
6222
 
6200
6223
  /**
@@ -6219,8 +6242,9 @@ function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
6219
6242
  var uniformBlockSpec = programInfo.uniformBlockSpec || programInfo;
6220
6243
  var blockSpec = uniformBlockSpec.blockSpecs[uniformBlockInfo.name];
6221
6244
  if (blockSpec) {
6245
+ var _uniformBlockInfo$siz;
6222
6246
  var bufferBindIndex = blockSpec.index;
6223
- gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, uniformBlockInfo.array.byteLength);
6247
+ gl.bindBufferRange(UNIFORM_BUFFER, bufferBindIndex, uniformBlockInfo.buffer, uniformBlockInfo.offset || 0, (_uniformBlockInfo$siz = uniformBlockInfo.size) !== null && _uniformBlockInfo$siz !== void 0 ? _uniformBlockInfo$siz : uniformBlockInfo.array.byteLength);
6224
6248
  return true;
6225
6249
  }
6226
6250
  return false;
@@ -6243,7 +6267,7 @@ function bindUniformBlock(gl, programInfo, uniformBlockInfo) {
6243
6267
  */
6244
6268
  function setUniformBlock(gl, programInfo, uniformBlockInfo) {
6245
6269
  if (bindUniformBlock(gl, programInfo, uniformBlockInfo)) {
6246
- gl.bufferData(UNIFORM_BUFFER, uniformBlockInfo.array, DYNAMIC_DRAW);
6270
+ gl.bufferSubData(UNIFORM_BUFFER, 0, uniformBlockInfo.asUint8, uniformBlockInfo.offset || 0, uniformBlockInfo.size || 0);
6247
6271
  }
6248
6272
  }
6249
6273
 
@@ -6685,6 +6709,8 @@ function setBuffersAndAttributes(gl, programInfo, buffers) {
6685
6709
  /**
6686
6710
  * @typedef {Object} ProgramInfo
6687
6711
  * @property {WebGLProgram} program A shader program
6712
+ * @property {Object<string, WebGLUniformLocation>} uniformLocations The uniform locations of each uniform
6713
+ * @property {Object<string, number>} attribLocations The locations of each attribute
6688
6714
  * @property {Object<string, function>} uniformSetters object of setters as returned from createUniformSetters,
6689
6715
  * @property {Object<string, function>} attribSetters object of setters as returned from createAttribSetters,
6690
6716
  * @property {module:twgl.UniformBlockSpec} [uniformBlockSpec] a uniform block spec for making UniformBlockInfos with createUniformBlockInfo etc..
@@ -6715,7 +6741,19 @@ function createProgramInfoFromProgram(gl, program) {
6715
6741
  var programInfo = {
6716
6742
  program: program,
6717
6743
  uniformSetters: uniformSetters,
6718
- attribSetters: attribSetters
6744
+ attribSetters: attribSetters,
6745
+ uniformLocations: Object.fromEntries(Object.entries(uniformSetters).map(function (_ref3) {
6746
+ var _ref4 = _slicedToArray(_ref3, 2),
6747
+ k = _ref4[0],
6748
+ v = _ref4[1];
6749
+ return [k, v.location];
6750
+ })),
6751
+ attribLocations: Object.fromEntries(Object.entries(attribSetters).map(function (_ref5) {
6752
+ var _ref6 = _slicedToArray(_ref5, 2),
6753
+ k = _ref6[0],
6754
+ v = _ref6[1];
6755
+ return [k, v.location];
6756
+ }))
6719
6757
  };
6720
6758
  if (utils.isWebGL2(gl)) {
6721
6759
  programInfo.uniformBlockSpec = createUniformBlockSpecFromProgram(gl, program);
@@ -6858,10 +6896,10 @@ function createPrograms(gl, programSpecs) {
6858
6896
  var noDeleteShadersSet = new Set();
6859
6897
 
6860
6898
  // compile and link everything
6861
- var programs = Object.fromEntries(Object.entries(programSpecs).map(function (_ref3) {
6862
- var _ref4 = _slicedToArray(_ref3, 2),
6863
- name = _ref4[0],
6864
- spec = _ref4[1];
6899
+ var programs = Object.fromEntries(Object.entries(programSpecs).map(function (_ref7) {
6900
+ var _ref8 = _slicedToArray(_ref7, 2),
6901
+ name = _ref8[0],
6902
+ spec = _ref8[1];
6865
6903
  var options = _objectSpread({}, programOptions);
6866
6904
  var shaders = Array.isArray(spec) ? spec : spec.shaders;
6867
6905
  if (!Array.isArray(spec)) {
@@ -6921,10 +6959,10 @@ function createPrograms(gl, programSpecs) {
6921
6959
  function createProgramInfos(gl, programSpecs, programOptions) {
6922
6960
  programOptions = getProgramOptions(programOptions);
6923
6961
  function createProgramInfosForPrograms(gl, programs) {
6924
- return Object.fromEntries(Object.entries(programs).map(function (_ref5) {
6925
- var _ref6 = _slicedToArray(_ref5, 2),
6926
- name = _ref6[0],
6927
- program = _ref6[1];
6962
+ return Object.fromEntries(Object.entries(programs).map(function (_ref9) {
6963
+ var _ref10 = _slicedToArray(_ref9, 2),
6964
+ name = _ref10[0],
6965
+ program = _ref10[1];
6928
6966
  return [name, createProgramInfoFromProgram(gl, program)];
6929
6967
  }));
6930
6968
  }
@@ -6999,14 +7037,15 @@ var createProgramInfosAsync = exports.createProgramInfosAsync = wrapCallbackFnTo
6999
7037
 
7000
7038
 
7001
7039
 
7002
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
7003
7040
  exports.__esModule = true;
7004
7041
  exports.canFilter = canFilter;
7005
7042
  exports.canGenerateMipmap = canGenerateMipmap;
7006
7043
  exports.createSampler = createSampler;
7007
7044
  exports.createSamplers = createSamplers;
7008
7045
  exports.createTexture = createTexture;
7046
+ exports.createTextureAsync = createTextureAsync;
7009
7047
  exports.createTextures = createTextures;
7048
+ exports.createTexturesAsync = createTexturesAsync;
7010
7049
  exports.getBytesPerElementForInternalFormat = getBytesPerElementForInternalFormat;
7011
7050
  exports.getFormatAndTypeForInternalFormat = getFormatAndTypeForInternalFormat;
7012
7051
  exports.getNumComponentsForFormat = getNumComponentsForFormat;
@@ -7025,7 +7064,12 @@ var typedArrays = _interopRequireWildcard(__webpack_require__(/*! ./typedarrays.
7025
7064
  var helper = _interopRequireWildcard(__webpack_require__(/*! ./helper.js */ "./src/helper.js"));
7026
7065
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
7027
7066
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
7028
- /*
7067
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
7068
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7069
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7070
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7071
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7072
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
7029
7073
  * Copyright 2019 Gregg Tavares
7030
7074
  *
7031
7075
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -7046,7 +7090,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
7046
7090
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
7047
7091
  * DEALINGS IN THE SOFTWARE.
7048
7092
  */
7049
-
7050
7093
  /**
7051
7094
  * Low level texture related functions
7052
7095
  *
@@ -7232,6 +7275,74 @@ var RED = 0x1903;
7232
7275
  var RED_INTEGER = 0x8D94;
7233
7276
  var RGB_INTEGER = 0x8D98;
7234
7277
  var RGBA_INTEGER = 0x8D99;
7278
+
7279
+ /* Compressed Texture Formats */
7280
+ // s3tc
7281
+ var COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
7282
+ var COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
7283
+ var COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
7284
+ var COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
7285
+ // s3tc_srgb
7286
+ var COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
7287
+ var COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D;
7288
+ var COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E;
7289
+ var COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
7290
+ // etc
7291
+ var COMPRESSED_RGB_ETC1_WEBGL = 0x8D64;
7292
+ var COMPRESSED_R11_EAC = 0x9270;
7293
+ var COMPRESSED_SIGNED_R11_EAC = 0x9271;
7294
+ var COMPRESSED_RG11_EAC = 0x9272;
7295
+ var COMPRESSED_SIGNED_RG11_EAC = 0x9273;
7296
+ var COMPRESSED_RGB8_ETC2 = 0x9274;
7297
+ var COMPRESSED_SRGB8_ETC2 = 0x9275;
7298
+ var COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276;
7299
+ var COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277;
7300
+ var COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
7301
+ var COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279;
7302
+ // pvrtc
7303
+ var COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00;
7304
+ var COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01;
7305
+ var COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02;
7306
+ var COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03;
7307
+ // astc
7308
+ var COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
7309
+ var COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1;
7310
+ var COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2;
7311
+ var COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3;
7312
+ var COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4;
7313
+ var COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5;
7314
+ var COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6;
7315
+ var COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7;
7316
+ var COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8;
7317
+ var COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9;
7318
+ var COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA;
7319
+ var COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB;
7320
+ var COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC;
7321
+ var COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD;
7322
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0;
7323
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1;
7324
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2;
7325
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3;
7326
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4;
7327
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5;
7328
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6;
7329
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7;
7330
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8;
7331
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9;
7332
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA;
7333
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB;
7334
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC;
7335
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD;
7336
+ // bptc
7337
+ var COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8E8C;
7338
+ var COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = 0x8E8D;
7339
+ var COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT = 0x8E8E;
7340
+ var COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT = 0x8E8F;
7341
+ // rgtc
7342
+ var COMPRESSED_RED_RGTC1_EXT = 0x8DBB;
7343
+ var COMPRESSED_SIGNED_RED_RGTC1_EXT = 0x8DBC;
7344
+ var COMPRESSED_RED_GREEN_RGTC2_EXT = 0x8DBD;
7345
+ var COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT = 0x8DBE;
7235
7346
  var formatInfo = {};
7236
7347
  {
7237
7348
  // NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle
@@ -7290,7 +7401,8 @@ var formatInfo = {};
7290
7401
  * @property {boolean} colorRenderable true if you can render to this format of texture.
7291
7402
  * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
7292
7403
  * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
7293
- * @property {Object.<number,number>} bytesPerElementMap A map of types to bytes per element
7404
+ * @property {Object.<number,number>} [bytesPerElementMap] A map of types to bytes per element
7405
+ * @property {boolean} [compressed] true if it's a compressed texture format
7294
7406
  * @private
7295
7407
  */
7296
7408
 
@@ -7731,6 +7843,318 @@ function getTextureInternalFormatInfo(internalFormat) {
7731
7843
  info.bytesPerElementMap[type] = bytesPerElement;
7732
7844
  });
7733
7845
  });
7846
+ var getCompressedFormatInfo = function getCompressedFormatInfo() {
7847
+ var t = {};
7848
+ // compressed texture formats
7849
+ // s3tc:https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
7850
+ t[COMPRESSED_RGB_S3TC_DXT1_EXT] = {
7851
+ textureFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
7852
+ colorRenderable: false,
7853
+ textureFilterable: true
7854
+ };
7855
+ t[COMPRESSED_RGBA_S3TC_DXT1_EXT] = {
7856
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT1_EXT,
7857
+ colorRenderable: false,
7858
+ textureFilterable: true
7859
+ };
7860
+ t[COMPRESSED_RGBA_S3TC_DXT3_EXT] = {
7861
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT3_EXT,
7862
+ colorRenderable: false,
7863
+ textureFilterable: true
7864
+ };
7865
+ t[COMPRESSED_RGBA_S3TC_DXT5_EXT] = {
7866
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
7867
+ colorRenderable: false,
7868
+ textureFilterable: true
7869
+ };
7870
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
7871
+ t[COMPRESSED_SRGB_S3TC_DXT1_EXT] = {
7872
+ textureFormat: COMPRESSED_SRGB_S3TC_DXT1_EXT,
7873
+ colorRenderable: false,
7874
+ textureFilterable: true
7875
+ };
7876
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = {
7877
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
7878
+ colorRenderable: false,
7879
+ textureFilterable: true
7880
+ };
7881
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = {
7882
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
7883
+ colorRenderable: false,
7884
+ textureFilterable: true
7885
+ };
7886
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = {
7887
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
7888
+ colorRenderable: false,
7889
+ textureFilterable: true
7890
+ };
7891
+ // https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
7892
+ t[COMPRESSED_RGB_ETC1_WEBGL] = {
7893
+ textureFormat: COMPRESSED_RGB_ETC1_WEBGL,
7894
+ colorRenderable: false,
7895
+ textureFilterable: true
7896
+ };
7897
+ t[COMPRESSED_R11_EAC] = {
7898
+ textureFormat: COMPRESSED_R11_EAC,
7899
+ colorRenderable: false,
7900
+ textureFilterable: true
7901
+ };
7902
+ t[COMPRESSED_SIGNED_R11_EAC] = {
7903
+ textureFormat: COMPRESSED_SIGNED_R11_EAC,
7904
+ colorRenderable: false,
7905
+ textureFilterable: true
7906
+ };
7907
+ t[COMPRESSED_RG11_EAC] = {
7908
+ textureFormat: COMPRESSED_RG11_EAC,
7909
+ colorRenderable: false,
7910
+ textureFilterable: true
7911
+ };
7912
+ t[COMPRESSED_SIGNED_RG11_EAC] = {
7913
+ textureFormat: COMPRESSED_SIGNED_RG11_EAC,
7914
+ colorRenderable: false,
7915
+ textureFilterable: true
7916
+ };
7917
+ t[COMPRESSED_RGB8_ETC2] = {
7918
+ textureFormat: COMPRESSED_RGB8_ETC2,
7919
+ colorRenderable: false,
7920
+ textureFilterable: true
7921
+ };
7922
+ t[COMPRESSED_SRGB8_ETC2] = {
7923
+ textureFormat: COMPRESSED_SRGB8_ETC2,
7924
+ colorRenderable: false,
7925
+ textureFilterable: true
7926
+ };
7927
+ t[COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = {
7928
+ textureFormat: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
7929
+ colorRenderable: false,
7930
+ textureFilterable: true
7931
+ };
7932
+ t[COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = {
7933
+ textureFormat: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
7934
+ colorRenderable: false,
7935
+ textureFilterable: true
7936
+ };
7937
+ t[COMPRESSED_RGBA8_ETC2_EAC] = {
7938
+ textureFormat: COMPRESSED_RGBA8_ETC2_EAC,
7939
+ colorRenderable: false,
7940
+ textureFilterable: true
7941
+ };
7942
+ t[COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = {
7943
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
7944
+ colorRenderable: false,
7945
+ textureFilterable: true
7946
+ };
7947
+ // https://registry.khronos.org/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
7948
+ t[COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = {
7949
+ textureFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
7950
+ colorRenderable: false,
7951
+ textureFilterable: true
7952
+ };
7953
+ t[COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = {
7954
+ textureFormat: COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
7955
+ colorRenderable: false,
7956
+ textureFilterable: true
7957
+ };
7958
+ t[COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = {
7959
+ textureFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
7960
+ colorRenderable: false,
7961
+ textureFilterable: true
7962
+ };
7963
+ t[COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = {
7964
+ textureFormat: COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
7965
+ colorRenderable: false,
7966
+ textureFilterable: true
7967
+ };
7968
+ // https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
7969
+ t[COMPRESSED_RGBA_ASTC_4x4_KHR] = {
7970
+ textureFormat: COMPRESSED_RGBA_ASTC_4x4_KHR,
7971
+ colorRenderable: false,
7972
+ textureFilterable: true
7973
+ };
7974
+ t[COMPRESSED_RGBA_ASTC_5x4_KHR] = {
7975
+ textureFormat: COMPRESSED_RGBA_ASTC_5x4_KHR,
7976
+ colorRenderable: false,
7977
+ textureFilterable: true
7978
+ };
7979
+ t[COMPRESSED_RGBA_ASTC_5x5_KHR] = {
7980
+ textureFormat: COMPRESSED_RGBA_ASTC_5x5_KHR,
7981
+ colorRenderable: false,
7982
+ textureFilterable: true
7983
+ };
7984
+ t[COMPRESSED_RGBA_ASTC_6x5_KHR] = {
7985
+ textureFormat: COMPRESSED_RGBA_ASTC_6x5_KHR,
7986
+ colorRenderable: false,
7987
+ textureFilterable: true
7988
+ };
7989
+ t[COMPRESSED_RGBA_ASTC_6x6_KHR] = {
7990
+ textureFormat: COMPRESSED_RGBA_ASTC_6x6_KHR,
7991
+ colorRenderable: false,
7992
+ textureFilterable: true
7993
+ };
7994
+ t[COMPRESSED_RGBA_ASTC_8x5_KHR] = {
7995
+ textureFormat: COMPRESSED_RGBA_ASTC_8x5_KHR,
7996
+ colorRenderable: false,
7997
+ textureFilterable: true
7998
+ };
7999
+ t[COMPRESSED_RGBA_ASTC_8x6_KHR] = {
8000
+ textureFormat: COMPRESSED_RGBA_ASTC_8x6_KHR,
8001
+ colorRenderable: false,
8002
+ textureFilterable: true
8003
+ };
8004
+ t[COMPRESSED_RGBA_ASTC_8x8_KHR] = {
8005
+ textureFormat: COMPRESSED_RGBA_ASTC_8x8_KHR,
8006
+ colorRenderable: false,
8007
+ textureFilterable: true
8008
+ };
8009
+ t[COMPRESSED_RGBA_ASTC_10x5_KHR] = {
8010
+ textureFormat: COMPRESSED_RGBA_ASTC_10x5_KHR,
8011
+ colorRenderable: false,
8012
+ textureFilterable: true
8013
+ };
8014
+ t[COMPRESSED_RGBA_ASTC_10x6_KHR] = {
8015
+ textureFormat: COMPRESSED_RGBA_ASTC_10x6_KHR,
8016
+ colorRenderable: false,
8017
+ textureFilterable: true
8018
+ };
8019
+ t[COMPRESSED_RGBA_ASTC_10x8_KHR] = {
8020
+ textureFormat: COMPRESSED_RGBA_ASTC_10x8_KHR,
8021
+ colorRenderable: false,
8022
+ textureFilterable: true
8023
+ };
8024
+ t[COMPRESSED_RGBA_ASTC_10x10_KHR] = {
8025
+ textureFormat: COMPRESSED_RGBA_ASTC_10x10_KHR,
8026
+ colorRenderable: false,
8027
+ textureFilterable: true
8028
+ };
8029
+ t[COMPRESSED_RGBA_ASTC_12x10_KHR] = {
8030
+ textureFormat: COMPRESSED_RGBA_ASTC_12x10_KHR,
8031
+ colorRenderable: false,
8032
+ textureFilterable: true
8033
+ };
8034
+ t[COMPRESSED_RGBA_ASTC_12x12_KHR] = {
8035
+ textureFormat: COMPRESSED_RGBA_ASTC_12x12_KHR,
8036
+ colorRenderable: false,
8037
+ textureFilterable: true
8038
+ };
8039
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR] = {
8040
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
8041
+ colorRenderable: false,
8042
+ textureFilterable: true
8043
+ };
8044
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR] = {
8045
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
8046
+ colorRenderable: false,
8047
+ textureFilterable: true
8048
+ };
8049
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR] = {
8050
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
8051
+ colorRenderable: false,
8052
+ textureFilterable: true
8053
+ };
8054
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR] = {
8055
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
8056
+ colorRenderable: false,
8057
+ textureFilterable: true
8058
+ };
8059
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR] = {
8060
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
8061
+ colorRenderable: false,
8062
+ textureFilterable: true
8063
+ };
8064
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR] = {
8065
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
8066
+ colorRenderable: false,
8067
+ textureFilterable: true
8068
+ };
8069
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR] = {
8070
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
8071
+ colorRenderable: false,
8072
+ textureFilterable: true
8073
+ };
8074
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR] = {
8075
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
8076
+ colorRenderable: false,
8077
+ textureFilterable: true
8078
+ };
8079
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR] = {
8080
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
8081
+ colorRenderable: false,
8082
+ textureFilterable: true
8083
+ };
8084
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR] = {
8085
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
8086
+ colorRenderable: false,
8087
+ textureFilterable: true
8088
+ };
8089
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR] = {
8090
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
8091
+ colorRenderable: false,
8092
+ textureFilterable: true
8093
+ };
8094
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR] = {
8095
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
8096
+ colorRenderable: false,
8097
+ textureFilterable: true
8098
+ };
8099
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR] = {
8100
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
8101
+ colorRenderable: false,
8102
+ textureFilterable: true
8103
+ };
8104
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR] = {
8105
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
8106
+ colorRenderable: false,
8107
+ textureFilterable: true
8108
+ };
8109
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
8110
+ t[COMPRESSED_RGBA_BPTC_UNORM_EXT] = {
8111
+ textureFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
8112
+ colorRenderable: false,
8113
+ textureFilterable: true
8114
+ };
8115
+ t[COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT] = {
8116
+ textureFormat: COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,
8117
+ colorRenderable: false,
8118
+ textureFilterable: true
8119
+ };
8120
+ t[COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT] = {
8121
+ textureFormat: COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
8122
+ colorRenderable: false,
8123
+ textureFilterable: true
8124
+ };
8125
+ t[COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT] = {
8126
+ textureFormat: COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
8127
+ colorRenderable: false,
8128
+ textureFilterable: true
8129
+ };
8130
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
8131
+ t[COMPRESSED_RED_RGTC1_EXT] = {
8132
+ textureFormat: COMPRESSED_RED_RGTC1_EXT,
8133
+ colorRenderable: false,
8134
+ textureFilterable: true
8135
+ };
8136
+ t[COMPRESSED_SIGNED_RED_RGTC1_EXT] = {
8137
+ textureFormat: COMPRESSED_SIGNED_RED_RGTC1_EXT,
8138
+ colorRenderable: false,
8139
+ textureFilterable: true
8140
+ };
8141
+ t[COMPRESSED_RED_GREEN_RGTC2_EXT] = {
8142
+ textureFormat: COMPRESSED_RED_GREEN_RGTC2_EXT,
8143
+ colorRenderable: false,
8144
+ textureFilterable: true
8145
+ };
8146
+ t[COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT] = {
8147
+ textureFormat: COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,
8148
+ colorRenderable: false,
8149
+ textureFilterable: true
8150
+ };
8151
+ for (var _i = 0, _Object$values = Object.values(t); _i < _Object$values.length; _i++) {
8152
+ var info = _Object$values[_i];
8153
+ info.compressed = true;
8154
+ }
8155
+ return t;
8156
+ };
8157
+ Object.assign(t, getCompressedFormatInfo());
7734
8158
  s_textureInternalFormatInfo = t;
7735
8159
  }
7736
8160
  return s_textureInternalFormatInfo[internalFormat];
@@ -7773,16 +8197,30 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
7773
8197
  * @memberOf module:twgl/textures
7774
8198
  */
7775
8199
  function getFormatAndTypeForInternalFormat(internalFormat) {
8200
+ var _info$type$, _info$type;
7776
8201
  var info = getTextureInternalFormatInfo(internalFormat);
7777
8202
  if (!info) {
7778
8203
  throw "unknown internal format";
7779
8204
  }
7780
8205
  return {
7781
8206
  format: info.textureFormat,
7782
- type: info.type[0]
8207
+ type: (_info$type$ = (_info$type = info.type) === null || _info$type === void 0 ? void 0 : _info$type[0]) !== null && _info$type$ !== void 0 ? _info$type$ : UNSIGNED_BYTE
7783
8208
  };
7784
8209
  }
7785
8210
 
8211
+ /**
8212
+ * @param {number} internalFormat The internal format
8213
+ * @returns if the internalFormat is a compressed format
8214
+ * @private
8215
+ */
8216
+ function isCompressedInternalFormat(internalFormat) {
8217
+ var info = getTextureInternalFormatInfo(internalFormat);
8218
+ if (!info) {
8219
+ throw "unknown internal format";
8220
+ }
8221
+ return !!info.compressed;
8222
+ }
8223
+
7786
8224
  /**
7787
8225
  * Returns true if value is power of 2
7788
8226
  * @param {number} value number to check.
@@ -8013,21 +8451,62 @@ function setDefaults(newDefaults) {
8013
8451
  */
8014
8452
 
8015
8453
  /**
8016
- * Sets any packing state that will be set based on the options.
8017
- * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
8454
+ * Saves the current packing state, sets the packing state as specified
8455
+ * then calls a function, after which the packing state will be restored.
8018
8456
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8457
+ * @param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
8458
+ * @param {function():void} [fn] A function to call, after which the packing state will be restored.
8019
8459
  * @private
8020
8460
  */
8021
- function setPackState(gl, options) {
8461
+ function scopedSetPackState(gl, options, fn) {
8462
+ var colorspaceConversion;
8463
+ var premultiplyAlpha;
8464
+ var flipY;
8022
8465
  if (options.colorspaceConversion !== undefined) {
8466
+ colorspaceConversion = gl.getParameter(UNPACK_COLORSPACE_CONVERSION_WEBGL);
8023
8467
  gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, options.colorspaceConversion);
8024
8468
  }
8025
8469
  if (options.premultiplyAlpha !== undefined) {
8470
+ premultiplyAlpha = gl.getParameter(UNPACK_PREMULTIPLY_ALPHA_WEBGL);
8026
8471
  gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, options.premultiplyAlpha);
8027
8472
  }
8028
8473
  if (options.flipY !== undefined) {
8474
+ flipY = gl.getParameter(UNPACK_FLIP_Y_WEBGL);
8029
8475
  gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, options.flipY);
8030
8476
  }
8477
+ fn();
8478
+ if (colorspaceConversion !== undefined) {
8479
+ gl.pixelStorei(UNPACK_COLORSPACE_CONVERSION_WEBGL, colorspaceConversion);
8480
+ }
8481
+ if (premultiplyAlpha !== undefined) {
8482
+ gl.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplyAlpha);
8483
+ }
8484
+ if (flipY !== undefined) {
8485
+ gl.pixelStorei(UNPACK_FLIP_Y_WEBGL, flipY);
8486
+ }
8487
+ }
8488
+
8489
+ /**
8490
+ * returns the property if set or the corresponding state if undefined
8491
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8492
+ * @param {module:twgl.TextureOptions} options
8493
+ * @param {string} property the name of the property to copy
8494
+ * @param {number} pname
8495
+ * @return {module:twgl.TextureOptions}
8496
+ */
8497
+ function getPackStateOption(gl, options, property, pname) {
8498
+ var v = options[property];
8499
+ return _defineProperty({}, property, v === undefined ? gl.getParameter(pname) : v);
8500
+ }
8501
+
8502
+ /**
8503
+ * Copy the options object and apply pack state
8504
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8505
+ * @param {module:twgl.TextureOptions} options
8506
+ * @return {module:twgl.TextureOptions}
8507
+ */
8508
+ function copyOptionsAndApplyPackState(gl, options) {
8509
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, options), getPackStateOption(gl, options, 'flipY', UNPACK_FLIP_Y_WEBGL)), getPackStateOption(gl, options, 'premultiplyAlpha', UNPACK_PREMULTIPLY_ALPHA_WEBGL)), getPackStateOption(gl, options, 'colorspaceConversion', UNPACK_COLORSPACE_CONVERSION_WEBGL));
8031
8510
  }
8032
8511
 
8033
8512
  /**
@@ -8311,7 +8790,6 @@ function setTextureFromElement(gl, tex, element, options) {
8311
8790
  var formatType = getFormatAndTypeForInternalFormat(internalFormat);
8312
8791
  var format = options.format || formatType.format;
8313
8792
  var type = options.type || formatType.type;
8314
- setPackState(gl, options);
8315
8793
  gl.bindTexture(target, tex);
8316
8794
  if (target === TEXTURE_CUBE_MAP) {
8317
8795
  // guess the parts
@@ -8344,15 +8822,17 @@ function setTextureFromElement(gl, tex, element, options) {
8344
8822
  ctx.canvas.height = size;
8345
8823
  width = size;
8346
8824
  height = size;
8347
- getCubeFacesWithNdx(gl, options).forEach(function (f) {
8348
- var xOffset = slices[f.ndx * 2 + 0] * size;
8349
- var yOffset = slices[f.ndx * 2 + 1] * size;
8350
- ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
8351
- gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
8825
+ scopedSetPackState(gl, options, function () {
8826
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
8827
+ var xOffset = slices[f.ndx * 2 + 0] * size;
8828
+ var yOffset = slices[f.ndx * 2 + 1] * size;
8829
+ ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
8830
+ gl.texImage2D(f.face, level, internalFormat, format, type, ctx.canvas);
8831
+ });
8832
+ // Free up the canvas memory
8833
+ ctx.canvas.width = 1;
8834
+ ctx.canvas.height = 1;
8352
8835
  });
8353
- // Free up the canvas memory
8354
- ctx.canvas.width = 1;
8355
- ctx.canvas.height = 1;
8356
8836
  } else if (typeof createImageBitmap !== 'undefined') {
8357
8837
  // NOTE: It seems like we should prefer ImageBitmap because unlike canvas it's
8358
8838
  // note lossy? (alpha is not premultiplied? although I'm not sure what
@@ -8371,39 +8851,44 @@ function setTextureFromElement(gl, tex, element, options) {
8371
8851
  premultiplyAlpha: 'none',
8372
8852
  colorSpaceConversion: 'none'
8373
8853
  }).then(function (imageBitmap) {
8374
- setPackState(gl, options);
8375
- gl.bindTexture(target, tex);
8376
- gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
8377
- if (shouldAutomaticallySetTextureFilteringForSize(options)) {
8378
- setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
8379
- }
8854
+ scopedSetPackState(gl, options, function () {
8855
+ gl.bindTexture(target, tex);
8856
+ gl.texImage2D(f.face, level, internalFormat, format, type, imageBitmap);
8857
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
8858
+ setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
8859
+ }
8860
+ });
8380
8861
  });
8381
8862
  });
8382
8863
  }
8383
8864
  } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
8384
- var smallest = Math.min(element.width, element.height);
8385
- var largest = Math.max(element.width, element.height);
8386
- var depth = largest / smallest;
8387
- if (depth % 1 !== 0) {
8388
- throw "can not compute 3D dimensions of element";
8389
- }
8390
- var xMult = element.width === largest ? 1 : 0;
8391
- var yMult = element.height === largest ? 1 : 0;
8392
- gl.pixelStorei(UNPACK_ALIGNMENT, 1);
8393
- gl.pixelStorei(UNPACK_ROW_LENGTH, element.width);
8394
- gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
8395
- gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
8396
- gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
8397
- for (var d = 0; d < depth; ++d) {
8398
- var srcX = d * smallest * xMult;
8399
- var srcY = d * smallest * yMult;
8400
- gl.pixelStorei(UNPACK_SKIP_PIXELS, srcX);
8401
- gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
8402
- gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
8403
- }
8404
- setSkipStateToDefault(gl);
8865
+ scopedSetPackState(gl, options, function () {
8866
+ var smallest = Math.min(element.width, element.height);
8867
+ var largest = Math.max(element.width, element.height);
8868
+ var depth = largest / smallest;
8869
+ if (depth % 1 !== 0) {
8870
+ throw "can not compute 3D dimensions of element";
8871
+ }
8872
+ var xMult = element.width === largest ? 1 : 0;
8873
+ var yMult = element.height === largest ? 1 : 0;
8874
+ gl.pixelStorei(UNPACK_ALIGNMENT, 1);
8875
+ gl.pixelStorei(UNPACK_ROW_LENGTH, element.width);
8876
+ gl.pixelStorei(UNPACK_IMAGE_HEIGHT, 0);
8877
+ gl.pixelStorei(UNPACK_SKIP_IMAGES, 0);
8878
+ gl.texImage3D(target, level, internalFormat, smallest, smallest, smallest, 0, format, type, null);
8879
+ for (var d = 0; d < depth; ++d) {
8880
+ var srcX = d * smallest * xMult;
8881
+ var srcY = d * smallest * yMult;
8882
+ gl.pixelStorei(UNPACK_SKIP_PIXELS, srcX);
8883
+ gl.pixelStorei(UNPACK_SKIP_ROWS, srcY);
8884
+ gl.texSubImage3D(target, level, 0, 0, d, smallest, smallest, 1, format, type, element);
8885
+ }
8886
+ setSkipStateToDefault(gl);
8887
+ });
8405
8888
  } else {
8406
- gl.texImage2D(target, level, internalFormat, format, type, element);
8889
+ scopedSetPackState(gl, options, function () {
8890
+ gl.texImage2D(target, level, internalFormat, format, type, element);
8891
+ });
8407
8892
  }
8408
8893
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
8409
8894
  setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
@@ -8637,7 +9122,7 @@ function loadTextureFromUrl(gl, tex, options, callback) {
8637
9122
  options = options || defaults.textureOptions;
8638
9123
  setTextureTo1PixelColor(gl, tex, options);
8639
9124
  // Because it's async we need to copy the options.
8640
- options = Object.assign({}, options);
9125
+ options = copyOptionsAndApplyPackState(gl, options);
8641
9126
  var img = loadAndUseImage(options.src, options.crossOrigin, function (err, img) {
8642
9127
  if (err) {
8643
9128
  callback(err, tex, img);
@@ -8677,7 +9162,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
8677
9162
  }
8678
9163
  setTextureTo1PixelColor(gl, tex, options);
8679
9164
  // Because it's async we need to copy the options.
8680
- options = Object.assign({}, options);
9165
+ options = copyOptionsAndApplyPackState(gl, options);
8681
9166
  var numToLoad = 6;
8682
9167
  var errors = [];
8683
9168
  var faces = getCubeFaceOrder(gl, options);
@@ -8692,23 +9177,24 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
8692
9177
  if (img.width !== img.height) {
8693
9178
  errors.push("cubemap face img is not a square: " + img.src);
8694
9179
  } else {
8695
- setPackState(gl, options);
8696
- gl.bindTexture(target, tex);
8697
-
8698
- // So assuming this is the first image we now have one face that's img sized
8699
- // and 5 faces that are 1x1 pixel so size the other faces
8700
- if (numToLoad === 5) {
8701
- // use the default order
8702
- getCubeFaceOrder(gl).forEach(function (otherTarget) {
8703
- // Should we re-use the same face or a color?
8704
- gl.texImage2D(otherTarget, level, internalFormat, format, type, img);
8705
- });
8706
- } else {
8707
- gl.texImage2D(faceTarget, level, internalFormat, format, type, img);
8708
- }
8709
- if (shouldAutomaticallySetTextureFilteringForSize(options)) {
8710
- gl.generateMipmap(target);
8711
- }
9180
+ scopedSetPackState(gl, options, function () {
9181
+ gl.bindTexture(target, tex);
9182
+
9183
+ // So assuming this is the first image we now have one face that's img sized
9184
+ // and 5 faces that are 1x1 pixel so size the other faces
9185
+ if (numToLoad === 5) {
9186
+ // use the default order
9187
+ getCubeFaceOrder(gl).forEach(function (otherTarget) {
9188
+ // Should we re-use the same face or a color?
9189
+ gl.texImage2D(otherTarget, level, internalFormat, format, type, img);
9190
+ });
9191
+ } else {
9192
+ gl.texImage2D(faceTarget, level, internalFormat, format, type, img);
9193
+ }
9194
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
9195
+ gl.generateMipmap(target);
9196
+ }
9197
+ });
8712
9198
  }
8713
9199
  }
8714
9200
  if (numToLoad === 0) {
@@ -8754,7 +9240,7 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
8754
9240
  }
8755
9241
  setTextureTo1PixelColor(gl, tex, options);
8756
9242
  // Because it's async we need to copy the options.
8757
- options = Object.assign({}, options);
9243
+ options = copyOptionsAndApplyPackState(gl, options);
8758
9244
  var numToLoad = urls.length;
8759
9245
  var errors = [];
8760
9246
  var imgs; // eslint-disable-line
@@ -8769,40 +9255,41 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
8769
9255
  if (err) {
8770
9256
  errors.push(err);
8771
9257
  } else {
8772
- setPackState(gl, options);
8773
- gl.bindTexture(target, tex);
8774
- if (firstImage) {
8775
- firstImage = false;
8776
- width = options.width || img.width;
8777
- height = options.height || img.height;
8778
- gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
8779
-
8780
- // put it in every slice otherwise some slices will be 0,0,0,0
8781
- for (var s = 0; s < depth; ++s) {
8782
- gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);
8783
- }
8784
- } else {
8785
- var src = img;
8786
- var ctx;
8787
- if (img.width !== width || img.height !== height) {
8788
- // Size the image to fix
8789
- ctx = getShared2DContext();
8790
- src = ctx.canvas;
8791
- ctx.canvas.width = width;
8792
- ctx.canvas.height = height;
8793
- ctx.drawImage(img, 0, 0, width, height);
8794
- }
8795
- gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src);
9258
+ scopedSetPackState(gl, options, function () {
9259
+ gl.bindTexture(target, tex);
9260
+ if (firstImage) {
9261
+ firstImage = false;
9262
+ width = options.width || img.width;
9263
+ height = options.height || img.height;
9264
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, null);
9265
+
9266
+ // put it in every slice otherwise some slices will be 0,0,0,0
9267
+ for (var s = 0; s < depth; ++s) {
9268
+ gl.texSubImage3D(target, level, 0, 0, s, width, height, 1, format, type, img);
9269
+ }
9270
+ } else {
9271
+ var src = img;
9272
+ var ctx;
9273
+ if (img.width !== width || img.height !== height) {
9274
+ // Size the image to fix
9275
+ ctx = getShared2DContext();
9276
+ src = ctx.canvas;
9277
+ ctx.canvas.width = width;
9278
+ ctx.canvas.height = height;
9279
+ ctx.drawImage(img, 0, 0, width, height);
9280
+ }
9281
+ gl.texSubImage3D(target, level, 0, 0, slice, width, height, 1, format, type, src);
8796
9282
 
8797
- // free the canvas memory
8798
- if (ctx && src === ctx.canvas) {
8799
- ctx.canvas.width = 0;
8800
- ctx.canvas.height = 0;
9283
+ // free the canvas memory
9284
+ if (ctx && src === ctx.canvas) {
9285
+ ctx.canvas.width = 0;
9286
+ ctx.canvas.height = 0;
9287
+ }
8801
9288
  }
8802
- }
8803
- if (shouldAutomaticallySetTextureFilteringForSize(options)) {
8804
- gl.generateMipmap(target);
8805
- }
9289
+ if (shouldAutomaticallySetTextureFilteringForSize(options)) {
9290
+ gl.generateMipmap(target);
9291
+ }
9292
+ });
8806
9293
  }
8807
9294
  if (numToLoad === 0) {
8808
9295
  callback(errors.length ? errors : undefined, tex, imgs);
@@ -8828,9 +9315,6 @@ function setTextureFromArray(gl, tex, src, options) {
8828
9315
  options = options || defaults.textureOptions;
8829
9316
  var target = options.target || TEXTURE_2D;
8830
9317
  gl.bindTexture(target, tex);
8831
- var width = options.width;
8832
- var height = options.height;
8833
- var depth = options.depth;
8834
9318
  var level = options.level || 0;
8835
9319
  var internalFormat = options.internalFormat || options.format || RGBA;
8836
9320
  var formatType = getFormatAndTypeForInternalFormat(internalFormat);
@@ -8842,60 +9326,90 @@ function setTextureFromArray(gl, tex, src, options) {
8842
9326
  } else if (src instanceof Uint8ClampedArray) {
8843
9327
  src = new Uint8Array(src.buffer);
8844
9328
  }
8845
- var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
8846
- var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
8847
- if (numElements % 1) {
8848
- throw "length wrong size for format: " + utils.glEnumToString(gl, format);
8849
- }
8850
- var dimensions;
8851
- if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
8852
- if (!width && !height && !depth) {
8853
- var size = Math.cbrt(numElements);
8854
- if (size % 1 !== 0) {
8855
- throw "can't guess cube size of array of numElements: " + numElements;
9329
+ var _getTextureSize = getTextureSize(gl, target, src, options, internalFormat, format, type),
9330
+ width = _getTextureSize.width,
9331
+ height = _getTextureSize.height,
9332
+ depth = _getTextureSize.depth;
9333
+ var compressed = isCompressedInternalFormat(internalFormat);
9334
+ setSkipStateToDefault(gl);
9335
+ gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
9336
+ scopedSetPackState(gl, options, function () {
9337
+ if (target === TEXTURE_CUBE_MAP) {
9338
+ var faceSize = src.length / 6;
9339
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
9340
+ var offset = faceSize * f.ndx;
9341
+ var data = src.subarray(offset, offset + faceSize);
9342
+ if (compressed) {
9343
+ gl.compressedTexImage2D(f.face, level, internalFormat, width, height, 0, data);
9344
+ } else {
9345
+ gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
9346
+ }
9347
+ });
9348
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
9349
+ gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
9350
+ } else {
9351
+ if (compressed) {
9352
+ gl.compressedTexImage2D(target, level, internalFormat, width, height, 0, src);
9353
+ } else {
9354
+ gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
9355
+ }
9356
+ }
9357
+ });
9358
+ return {
9359
+ width: width,
9360
+ height: height,
9361
+ depth: depth,
9362
+ type: type
9363
+ };
9364
+ }
9365
+ function getTextureSize(gl, target, src, options, internalFormat, format, type) {
9366
+ var width = options.width;
9367
+ var height = options.height;
9368
+ var depth = options.depth;
9369
+ var compressed = isCompressedInternalFormat(internalFormat);
9370
+ if (compressed) {
9371
+ if (!width || !height) {
9372
+ throw "compressed texture needs to set width and height!";
9373
+ }
9374
+ } else {
9375
+ var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
9376
+ var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
9377
+ if (numElements % 1) {
9378
+ throw "length wrong size for format: " + utils.glEnumToString(gl, format);
9379
+ }
9380
+ var dimensions;
9381
+ if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
9382
+ if (!width && !height && !depth) {
9383
+ var size = Math.cbrt(numElements);
9384
+ if (size % 1 !== 0) {
9385
+ throw "can't guess cube size of array of numElements: " + numElements;
9386
+ }
9387
+ width = size;
9388
+ height = size;
9389
+ depth = size;
9390
+ } else if (width && (!height || !depth)) {
9391
+ dimensions = guessDimensions(gl, target, height, depth, numElements / width);
9392
+ height = dimensions.width;
9393
+ depth = dimensions.height;
9394
+ } else if (height && (!width || !depth)) {
9395
+ dimensions = guessDimensions(gl, target, width, depth, numElements / height);
9396
+ width = dimensions.width;
9397
+ depth = dimensions.height;
9398
+ } else {
9399
+ dimensions = guessDimensions(gl, target, width, height, numElements / depth);
9400
+ width = dimensions.width;
9401
+ height = dimensions.height;
8856
9402
  }
8857
- width = size;
8858
- height = size;
8859
- depth = size;
8860
- } else if (width && (!height || !depth)) {
8861
- dimensions = guessDimensions(gl, target, height, depth, numElements / width);
8862
- height = dimensions.width;
8863
- depth = dimensions.height;
8864
- } else if (height && (!width || !depth)) {
8865
- dimensions = guessDimensions(gl, target, width, depth, numElements / height);
8866
- width = dimensions.width;
8867
- depth = dimensions.height;
8868
9403
  } else {
8869
- dimensions = guessDimensions(gl, target, width, height, numElements / depth);
9404
+ dimensions = guessDimensions(gl, target, width, height, numElements);
8870
9405
  width = dimensions.width;
8871
9406
  height = dimensions.height;
8872
9407
  }
8873
- } else {
8874
- dimensions = guessDimensions(gl, target, width, height, numElements);
8875
- width = dimensions.width;
8876
- height = dimensions.height;
8877
- }
8878
- setSkipStateToDefault(gl);
8879
- gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
8880
- setPackState(gl, options);
8881
- if (target === TEXTURE_CUBE_MAP) {
8882
- var elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
8883
- var faceSize = numElements / 6 * elementsPerElement;
8884
- getCubeFacesWithNdx(gl, options).forEach(function (f) {
8885
- var offset = faceSize * f.ndx;
8886
- var data = src.subarray(offset, offset + faceSize);
8887
- gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
8888
- });
8889
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
8890
- gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
8891
- } else {
8892
- gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
8893
9408
  }
8894
9409
  return {
8895
9410
  width: width,
8896
9411
  height: height,
8897
- depth: depth,
8898
- type: type
9412
+ depth: depth
8899
9413
  };
8900
9414
  }
8901
9415
 
@@ -8915,24 +9429,46 @@ function setEmptyTexture(gl, tex, options) {
8915
9429
  var formatType = getFormatAndTypeForInternalFormat(internalFormat);
8916
9430
  var format = options.format || formatType.format;
8917
9431
  var type = options.type || formatType.type;
8918
- setPackState(gl, options);
8919
- if (target === TEXTURE_CUBE_MAP) {
8920
- for (var ii = 0; ii < 6; ++ii) {
8921
- gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
9432
+ scopedSetPackState(gl, options, function () {
9433
+ if (target === TEXTURE_CUBE_MAP) {
9434
+ for (var ii = 0; ii < 6; ++ii) {
9435
+ gl.texImage2D(TEXTURE_CUBE_MAP_POSITIVE_X + ii, level, internalFormat, options.width, options.height, 0, format, type, null);
9436
+ }
9437
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
9438
+ gl.texImage3D(target, level, internalFormat, options.width, options.height, options.depth, 0, format, type, null);
9439
+ } else {
9440
+ gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
8922
9441
  }
8923
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
8924
- gl.texImage3D(target, level, internalFormat, options.width, options.height, options.depth, 0, format, type, null);
8925
- } else {
8926
- gl.texImage2D(target, level, internalFormat, options.width, options.height, 0, format, type, null);
8927
- }
9442
+ });
8928
9443
  }
8929
9444
 
8930
9445
  /**
8931
9446
  * Creates a texture based on the options passed in.
8932
9447
  *
9448
+ * See {@link module:twgl.TextureOptions}
9449
+ *
8933
9450
  * Note: may reset UNPACK_ALIGNMENT, UNPACK_ROW_LENGTH, UNPACK_IMAGE_HEIGHT, UNPACK_SKIP_IMAGES
8934
9451
  * UNPACK_SKIP_PIXELS, and UNPACK_SKIP_ROWS
8935
9452
  *
9453
+ * UNPACK_FLIP_Y_WEBGL, UNPACK_PREMULTIPLY_ALPHA_WEBGL, UNPACK_COLORSPACE_CONVERSION_WEBGL
9454
+ * are left as is though you can pass in options for flipY, premultiplyAlpha, and colorspaceConversion
9455
+ * to override them.
9456
+ *
9457
+ * As for the behavior of these settings
9458
+ *
9459
+ * ```js
9460
+ * gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
9461
+ * t1 = twgl.createTexture({src: someImage }); // flipped
9462
+ * t2 = twgl.createTexture({src: someImage, flipY: true }); // flipped
9463
+ * t3 = twgl.createTexture({src: someImage, flipY: false }); // not flipped
9464
+ * t4 = twgl.createTexture({src: someImage }); // flipped
9465
+ * ```
9466
+ *
9467
+ * * t1 is flipped because UNPACK_FLIP_Y_WEBGL is true
9468
+ * * t2 is flipped because it was requested
9469
+ * * t3 is not flipped because it was requested
9470
+ * * t4 is flipped because UNPACK_FLIP_Y_WEBGL has been restored to true
9471
+ *
8936
9472
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8937
9473
  * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
8938
9474
  * @param {module:twgl.TextureReadyCallback} [callback] A callback called when an image has been downloaded and uploaded to the texture.
@@ -8986,6 +9522,45 @@ function createTexture(gl, options, callback) {
8986
9522
  return tex;
8987
9523
  }
8988
9524
 
9525
+ /**
9526
+ * Value returned by createTextureAsync
9527
+ *
9528
+ * @typedef {Object} CreateTextureInfo
9529
+ * @param {WebGLTexture} texture the texture.
9530
+ * @param {module:twgl.TextureSrc} source image(s) used to as the src for the texture
9531
+ * @memberOf module:twgl
9532
+ */
9533
+
9534
+ /**
9535
+ * Creates a texture based on the options passed in.
9536
+ *
9537
+ * see {@link module:twgl/textures.createTexture}.
9538
+ * The only difference is this function returns a promise
9539
+ * where as the other returns a texture and takes a callback.
9540
+ *
9541
+ * Note: this is here for completeness. It is probably better to use
9542
+ * the non-async version as it returns a usable texture immediately
9543
+ * where as this one you have to wait for it to load.
9544
+ *
9545
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
9546
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
9547
+ * @return {Promise<CreateTextureInfo>} The created texture and source.
9548
+ */
9549
+ function createTextureAsync(gl, options) {
9550
+ return new Promise(function (resolve, reject) {
9551
+ createTexture(gl, options, function (err, texture, source) {
9552
+ if (err) {
9553
+ reject(err);
9554
+ } else {
9555
+ resolve({
9556
+ texture: texture,
9557
+ source: source
9558
+ });
9559
+ }
9560
+ });
9561
+ });
9562
+ }
9563
+
8989
9564
  /**
8990
9565
  * Resizes a texture based on the options passed in.
8991
9566
  *
@@ -9158,6 +9733,45 @@ function createTextures(gl, textureOptions, callback) {
9158
9733
  return textures;
9159
9734
  }
9160
9735
 
9736
+ /**
9737
+ * Value returned by createTextureAsync
9738
+ *
9739
+ * @typedef {Object} CreateTexturesInfo
9740
+ * @param {Object.<string, WebGLTexture>} textures the created textures by name. Same as returned by {@link module:twgl.createTextures}.
9741
+ * @param {Object.<string, module:twgl.TextureSrc>} sources the image(s) used for the texture by name.
9742
+ * @memberOf module:twgl
9743
+ */
9744
+
9745
+ /**
9746
+ * Creates textures based on the options passed in.
9747
+ *
9748
+ * see {@link module:twgl/textures.createTextures}.
9749
+ * The only difference is this function returns a promise
9750
+ * where as the other returns a texture and takes a callback.
9751
+ *
9752
+ * Note: this is here for completeness. It is probably better to use
9753
+ * the non-async version as it returns usable textures immediately
9754
+ * where as this one you have to wait for them to load.
9755
+ *
9756
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
9757
+ * @param {Object.<string,module:twgl.TextureOptions>} options A object of TextureOptions one per texture.
9758
+ * @return {Promise<CreateTexturesInfo>} The created textures and sources.
9759
+ */
9760
+ function createTexturesAsync(gl, options) {
9761
+ return new Promise(function (resolve, reject) {
9762
+ createTexture(gl, options, function (err, textures, sources) {
9763
+ if (err) {
9764
+ reject(err);
9765
+ } else {
9766
+ resolve({
9767
+ textures: textures,
9768
+ sources: sources
9769
+ });
9770
+ }
9771
+ });
9772
+ });
9773
+ }
9774
+
9161
9775
  /***/ }),
9162
9776
 
9163
9777
  /***/ "./src/twgl-full.js":
@@ -9478,7 +10092,7 @@ function addExtensionToContext(gl, extensionName) {
9478
10092
  * list.
9479
10093
  *
9480
10094
  */
9481
- var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_float', 'EXT_color_buffer_half_float', 'EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2', 'EXT_frag_depth', 'EXT_sRGB', 'EXT_shader_texture_lod', 'EXT_texture_filter_anisotropic', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_atc', 'WEBGL_compressed_texture_etc1', 'WEBGL_compressed_texture_pvrtc', 'WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_depth_texture', 'WEBGL_draw_buffers'];
10095
+ var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_float', 'EXT_color_buffer_half_float', 'EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2', 'EXT_frag_depth', 'EXT_sRGB', 'EXT_shader_texture_lod', 'EXT_texture_compression_bptc', 'EXT_texture_compression_rgtc', 'EXT_texture_filter_anisotropic', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_atc', 'WEBGL_compressed_texture_etc1', 'WEBGL_compressed_texture_etc', 'WEBGL_compressed_texture_pvrtc', 'WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_depth_texture', 'WEBGL_draw_buffers'];
9482
10096
 
9483
10097
  /**
9484
10098
  * Attempts to enable all of the following extensions