twgl.js 6.2.0 → 7.0.3

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,4 +1,4 @@
1
- /* @license twgl.js 6.2.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
1
+ /* @license twgl.js 7.0.3 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
  /*
@@ -944,8 +944,7 @@ function setAxis(a, v, axis, dst) {
944
944
  * the distances to the near and far clipping planes. Note that near and far
945
945
  * are not z coordinates, but rather they are distances along the negative
946
946
  * z-axis. The matrix generated sends the viewing frustum to the unit box.
947
- * We assume a unit box extending from -1 to 1 in the x and y dimensions and
948
- * from 0 to 1 in the z dimension.
947
+ * We assume a unit box extending from -1 to 1 in the x, y and z dimensions.
949
948
  * @param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).
950
949
  * @param {number} aspect The aspect ratio width / height.
951
950
  * @param {number} zNear The depth (negative z coordinate)
@@ -1034,8 +1033,7 @@ function ortho(left, right, bottom, top, near, far, dst) {
1034
1033
  * distances to the near and far clipping planes. Note that near and far are not
1035
1034
  * z coordinates, but rather they are distances along the negative z-axis. The
1036
1035
  * matrix generated sends the viewing frustum to the unit box. We assume a unit
1037
- * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z
1038
- * dimension.
1036
+ * box extending from -1 to 1 in the x, y and z dimensions.
1039
1037
  * @param {number} left The x coordinate of the left plane of the box.
1040
1038
  * @param {number} right The x coordinate of the right plane of the box.
1041
1039
  * @param {number} bottom The y coordinate of the bottom plane of the box.
@@ -1063,11 +1061,11 @@ function frustum(left, right, bottom, top, near, far, dst) {
1063
1061
  dst[ 7] = 0;
1064
1062
  dst[ 8] = (left + right) / dx;
1065
1063
  dst[ 9] = (top + bottom) / dy;
1066
- dst[10] = far / dz;
1064
+ dst[10] = (near + far) / dz;
1067
1065
  dst[11] = -1;
1068
1066
  dst[12] = 0;
1069
1067
  dst[13] = 0;
1070
- dst[14] = near * far / dz;
1068
+ dst[14] = 2 * near * far / dz;
1071
1069
  dst[15] = 0;
1072
1070
 
1073
1071
  return dst;
@@ -3925,39 +3923,39 @@ function create3DFVertices() {
3925
3923
  // left column front
3926
3924
  // top rung front
3927
3925
  // middle rung front
3928
- 18, 0, 0, 1,
3926
+ 18, 0, 0, -1,
3929
3927
 
3930
3928
  // left column back
3931
3929
  // top rung back
3932
3930
  // middle rung back
3933
- 18, 0, 0, -1,
3931
+ 18, 0, 0, 1,
3934
3932
 
3935
3933
  // top
3936
- 6, 0, 1, 0,
3934
+ 6, 0, -1, 0,
3937
3935
 
3938
3936
  // top rung front
3939
3937
  6, 1, 0, 0,
3940
3938
 
3941
3939
  // under top rung
3942
- 6, 0, -1, 0,
3940
+ 6, 0, 1, 0,
3943
3941
 
3944
3942
  // between top rung and middle
3945
3943
  6, 1, 0, 0,
3946
3944
 
3947
3945
  // top of middle rung
3948
- 6, 0, 1, 0,
3946
+ 6, 0, -1, 0,
3949
3947
 
3950
3948
  // front of middle rung
3951
3949
  6, 1, 0, 0,
3952
3950
 
3953
3951
  // bottom of middle rung.
3954
- 6, 0, -1, 0,
3952
+ 6, 0, 1, 0,
3955
3953
 
3956
3954
  // front of bottom
3957
3955
  6, 1, 0, 0,
3958
3956
 
3959
3957
  // bottom
3960
- 6, 0, -1, 0,
3958
+ 6, 0, 1, 0,
3961
3959
 
3962
3960
  // left side
3963
3961
  6, -1, 0, 0,
@@ -5025,6 +5023,24 @@ var utils = /*#__PURE__*/Object.freeze({
5025
5023
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
5026
5024
  * DEALINGS IN THE SOFTWARE.
5027
5025
  */
5026
+
5027
+ /**
5028
+ * Low level texture related functions
5029
+ *
5030
+ * You should generally not need to use these functions. They are provided
5031
+ * for those cases where you're doing something out of the ordinary
5032
+ * and you need lower level access.
5033
+ *
5034
+ * For backward compatibility they are available at both `twgl.textures` and `twgl`
5035
+ * itself
5036
+ *
5037
+ * See {@link module:twgl} for core functions
5038
+ *
5039
+ * @module twgl/textures
5040
+ */
5041
+
5042
+ // make sure we don't see a global gl
5043
+ const gl = undefined; /* eslint-disable-line */
5028
5044
  const defaults$1 = {
5029
5045
  textureColor: new Uint8Array([128, 192, 255, 255]),
5030
5046
  textureOptions: {},
@@ -5073,6 +5089,7 @@ const CLAMP_TO_EDGE$1 = 0x812f;
5073
5089
  /* TextureMagFilter */
5074
5090
  const NEAREST = 0x2600;
5075
5091
  const LINEAR$1 = 0x2601;
5092
+ const NEAREST_MIPMAP_LINEAR = 0x2702;
5076
5093
 
5077
5094
  /* TextureMinFilter */
5078
5095
  // const NEAREST_MIPMAP_NEAREST = 0x2700;
@@ -5290,6 +5307,14 @@ const formatInfo = {};
5290
5307
  f[DEPTH_STENCIL$1] = { numColorComponents: 2, };
5291
5308
  }
5292
5309
 
5310
+ /**
5311
+ * @typedef {Object} BlockInfo
5312
+ * @property {number} bytes number of bytes in the block
5313
+ * @property {number} width width of the block
5314
+ * @property {number} height height of the block
5315
+ * @private
5316
+ */
5317
+
5293
5318
  /**
5294
5319
  * @typedef {Object} TextureFormatDetails
5295
5320
  * @property {number} textureFormat format to pass texImage2D and similar functions.
@@ -5297,7 +5322,7 @@ const formatInfo = {};
5297
5322
  * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
5298
5323
  * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
5299
5324
  * @property {Object.<number,number>} [bytesPerElementMap] A map of types to bytes per element
5300
- * @property {boolean} [compressed] true if it's a compressed texture format
5325
+ * @property {BlockInfo} [block] block size, only for compressed textures
5301
5326
  * @private
5302
5327
  */
5303
5328
 
@@ -5380,87 +5405,84 @@ function getTextureInternalFormatInfo(internalFormat) {
5380
5405
  });
5381
5406
  });
5382
5407
 
5383
- const getCompressedFormatInfo = () => {
5384
- const t = {};
5385
- // compressed texture formats
5386
- // s3tc:https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
5387
- t[COMPRESSED_RGB_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_RGB_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true };
5388
- t[COMPRESSED_RGBA_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true };
5389
- t[COMPRESSED_RGBA_S3TC_DXT3_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT3_EXT, colorRenderable: false, textureFilterable: true };
5390
- t[COMPRESSED_RGBA_S3TC_DXT5_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT, colorRenderable: false, textureFilterable: true };
5391
- // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
5392
- t[COMPRESSED_SRGB_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_SRGB_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true };
5393
- t[COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true };
5394
- t[COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, colorRenderable: false, textureFilterable: true };
5395
- t[COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, colorRenderable: false, textureFilterable: true };
5396
- // https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
5397
- t[COMPRESSED_RGB_ETC1_WEBGL] = { textureFormat: COMPRESSED_RGB_ETC1_WEBGL, colorRenderable: false, textureFilterable: true };
5398
- t[COMPRESSED_R11_EAC] = { textureFormat: COMPRESSED_R11_EAC, colorRenderable: false, textureFilterable: true };
5399
- t[COMPRESSED_SIGNED_R11_EAC] = { textureFormat: COMPRESSED_SIGNED_R11_EAC, colorRenderable: false, textureFilterable: true };
5400
- t[COMPRESSED_RG11_EAC] = { textureFormat: COMPRESSED_RG11_EAC, colorRenderable: false, textureFilterable: true };
5401
- t[COMPRESSED_SIGNED_RG11_EAC] = { textureFormat: COMPRESSED_SIGNED_RG11_EAC, colorRenderable: false, textureFilterable: true };
5402
- t[COMPRESSED_RGB8_ETC2] = { textureFormat: COMPRESSED_RGB8_ETC2, colorRenderable: false, textureFilterable: true };
5403
- t[COMPRESSED_SRGB8_ETC2] = { textureFormat: COMPRESSED_SRGB8_ETC2, colorRenderable: false, textureFilterable: true };
5404
- t[COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = { textureFormat: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, colorRenderable: false, textureFilterable: true };
5405
- t[COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = { textureFormat: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, colorRenderable: false, textureFilterable: true };
5406
- t[COMPRESSED_RGBA8_ETC2_EAC] = { textureFormat: COMPRESSED_RGBA8_ETC2_EAC, colorRenderable: false, textureFilterable: true };
5407
- t[COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, colorRenderable: false, textureFilterable: true };
5408
- // https://registry.khronos.org/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
5409
- t[COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = { textureFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG, colorRenderable: false, textureFilterable: true };
5410
- t[COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = { textureFormat: COMPRESSED_RGB_PVRTC_2BPPV1_IMG, colorRenderable: false, textureFilterable: true };
5411
- t[COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = { textureFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, colorRenderable: false, textureFilterable: true };
5412
- t[COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = { textureFormat: COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, colorRenderable: false, textureFilterable: true };
5413
- // https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
5414
- t[COMPRESSED_RGBA_ASTC_4x4_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_4x4_KHR, colorRenderable: false, textureFilterable: true };
5415
- t[COMPRESSED_RGBA_ASTC_5x4_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_5x4_KHR, colorRenderable: false, textureFilterable: true };
5416
- t[COMPRESSED_RGBA_ASTC_5x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_5x5_KHR, colorRenderable: false, textureFilterable: true };
5417
- t[COMPRESSED_RGBA_ASTC_6x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_6x5_KHR, colorRenderable: false, textureFilterable: true };
5418
- t[COMPRESSED_RGBA_ASTC_6x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_6x6_KHR, colorRenderable: false, textureFilterable: true };
5419
- t[COMPRESSED_RGBA_ASTC_8x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x5_KHR, colorRenderable: false, textureFilterable: true };
5420
- t[COMPRESSED_RGBA_ASTC_8x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x6_KHR, colorRenderable: false, textureFilterable: true };
5421
- t[COMPRESSED_RGBA_ASTC_8x8_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x8_KHR, colorRenderable: false, textureFilterable: true };
5422
- t[COMPRESSED_RGBA_ASTC_10x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x5_KHR, colorRenderable: false, textureFilterable: true };
5423
- t[COMPRESSED_RGBA_ASTC_10x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x6_KHR, colorRenderable: false, textureFilterable: true };
5424
- t[COMPRESSED_RGBA_ASTC_10x8_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x8_KHR, colorRenderable: false, textureFilterable: true };
5425
- t[COMPRESSED_RGBA_ASTC_10x10_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x10_KHR, colorRenderable: false, textureFilterable: true };
5426
- t[COMPRESSED_RGBA_ASTC_12x10_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_12x10_KHR, colorRenderable: false, textureFilterable: true };
5427
- t[COMPRESSED_RGBA_ASTC_12x12_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_12x12_KHR, colorRenderable: false, textureFilterable: true };
5428
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, colorRenderable: false, textureFilterable: true };
5429
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, colorRenderable: false, textureFilterable: true };
5430
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, colorRenderable: false, textureFilterable: true };
5431
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, colorRenderable: false, textureFilterable: true };
5432
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, colorRenderable: false, textureFilterable: true };
5433
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, colorRenderable: false, textureFilterable: true };
5434
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, colorRenderable: false, textureFilterable: true };
5435
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, colorRenderable: false, textureFilterable: true };
5436
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, colorRenderable: false, textureFilterable: true };
5437
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, colorRenderable: false, textureFilterable: true };
5438
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, colorRenderable: false, textureFilterable: true };
5439
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, colorRenderable: false, textureFilterable: true };
5440
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, colorRenderable: false, textureFilterable: true };
5441
- t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, colorRenderable: false, textureFilterable: true };
5442
- // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
5443
- t[COMPRESSED_RGBA_BPTC_UNORM_EXT] = { textureFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT, colorRenderable: false, textureFilterable: true };
5444
- t[COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, colorRenderable: false, textureFilterable: true };
5445
- t[COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT] = { textureFormat: COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, colorRenderable: false, textureFilterable: true };
5446
- t[COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT] = { textureFormat: COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, colorRenderable: false, textureFilterable: true };
5447
- // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
5448
- t[COMPRESSED_RED_RGTC1_EXT] = { textureFormat: COMPRESSED_RED_RGTC1_EXT, colorRenderable: false, textureFilterable: true };
5449
- t[COMPRESSED_SIGNED_RED_RGTC1_EXT] = { textureFormat: COMPRESSED_SIGNED_RED_RGTC1_EXT, colorRenderable: false, textureFilterable: true };
5450
- t[COMPRESSED_RED_GREEN_RGTC2_EXT] = { textureFormat: COMPRESSED_RED_GREEN_RGTC2_EXT, colorRenderable: false, textureFilterable: true };
5451
- t[COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT] = { textureFormat: COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, colorRenderable: false, textureFilterable: true };
5452
-
5453
- for (const info of Object.values(t)) {
5454
- info.compressed = true;
5455
- }
5456
-
5457
- return t;
5458
- };
5459
- Object.assign(t, getCompressedFormatInfo());
5408
+ const block8_4_4 = { bytes: 8, width: 4, height: 4 };
5409
+ const block16_4_4 = { bytes: 16, width: 4, height: 4 };
5410
+
5411
+ // compressed texture formats
5412
+ // s3tc:https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
5413
+ t[COMPRESSED_RGB_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_RGB_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5414
+ t[COMPRESSED_RGBA_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5415
+ t[COMPRESSED_RGBA_S3TC_DXT3_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT3_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5416
+ t[COMPRESSED_RGBA_S3TC_DXT5_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5417
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
5418
+ t[COMPRESSED_SRGB_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_SRGB_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5419
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5420
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5421
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5422
+ // https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
5423
+ t[COMPRESSED_RGB_ETC1_WEBGL] = { textureFormat: COMPRESSED_RGB_ETC1_WEBGL, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5424
+ t[COMPRESSED_R11_EAC] = { textureFormat: COMPRESSED_R11_EAC, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5425
+ t[COMPRESSED_SIGNED_R11_EAC] = { textureFormat: COMPRESSED_SIGNED_R11_EAC, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5426
+ t[COMPRESSED_RG11_EAC] = { textureFormat: COMPRESSED_RG11_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5427
+ t[COMPRESSED_SIGNED_RG11_EAC] = { textureFormat: COMPRESSED_SIGNED_RG11_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5428
+ t[COMPRESSED_RGB8_ETC2] = { textureFormat: COMPRESSED_RGB8_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5429
+ t[COMPRESSED_SRGB8_ETC2] = { textureFormat: COMPRESSED_SRGB8_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5430
+ t[COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = { textureFormat: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5431
+ t[COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = { textureFormat: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5432
+ t[COMPRESSED_RGBA8_ETC2_EAC] = { textureFormat: COMPRESSED_RGBA8_ETC2_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5433
+ t[COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5434
+ // https://registry.khronos.org/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
5435
+ t[COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = { textureFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 8, height: 8, } };
5436
+ t[COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = { textureFormat: COMPRESSED_RGB_PVRTC_2BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 16, height: 8, } };
5437
+ t[COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = { textureFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 8, height: 8, } };
5438
+ t[COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = { textureFormat: COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 16, height: 8, } };
5439
+ // https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
5440
+ t[COMPRESSED_RGBA_ASTC_4x4_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_4x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 4, height: 4, } };
5441
+ t[COMPRESSED_RGBA_ASTC_5x4_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_5x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 4, } };
5442
+ t[COMPRESSED_RGBA_ASTC_5x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_5x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 5, } };
5443
+ t[COMPRESSED_RGBA_ASTC_6x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_6x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 5, } };
5444
+ t[COMPRESSED_RGBA_ASTC_6x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_6x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 6, } };
5445
+ t[COMPRESSED_RGBA_ASTC_8x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 5, } };
5446
+ t[COMPRESSED_RGBA_ASTC_8x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 6, } };
5447
+ t[COMPRESSED_RGBA_ASTC_8x8_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 8, } };
5448
+ t[COMPRESSED_RGBA_ASTC_10x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 5, } };
5449
+ t[COMPRESSED_RGBA_ASTC_10x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 6, } };
5450
+ t[COMPRESSED_RGBA_ASTC_10x8_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 8, } };
5451
+ t[COMPRESSED_RGBA_ASTC_10x10_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 10, } };
5452
+ t[COMPRESSED_RGBA_ASTC_12x10_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_12x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 10, } };
5453
+ t[COMPRESSED_RGBA_ASTC_12x12_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_12x12_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 12, } };
5454
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 4, height: 4, } };
5455
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 4, } };
5456
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 5, } };
5457
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 5, } };
5458
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 6, } };
5459
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 5, } };
5460
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 6, } };
5461
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 8, } };
5462
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 5, } };
5463
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 6, } };
5464
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 8, } };
5465
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 10, } };
5466
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 10, } };
5467
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 12, } };
5468
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
5469
+ t[COMPRESSED_RGBA_BPTC_UNORM_EXT] = { textureFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5470
+ t[COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5471
+ t[COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT] = { textureFormat: COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5472
+ t[COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT] = { textureFormat: COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
5473
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
5474
+ t[COMPRESSED_RED_RGTC1_EXT] = { textureFormat: COMPRESSED_RED_RGTC1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5475
+ t[COMPRESSED_SIGNED_RED_RGTC1_EXT] = { textureFormat: COMPRESSED_SIGNED_RED_RGTC1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5476
+ t[COMPRESSED_RED_GREEN_RGTC2_EXT] = { textureFormat: COMPRESSED_RED_GREEN_RGTC2_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5477
+ t[COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT] = { textureFormat: COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
5460
5478
 
5461
5479
  s_textureInternalFormatInfo = t;
5462
5480
  }
5463
- return s_textureInternalFormatInfo[internalFormat];
5481
+ const info = s_textureInternalFormatInfo[internalFormat];
5482
+ if (!info) {
5483
+ throw new Error("unknown internal format");
5484
+ }
5485
+ return info;
5464
5486
  }
5465
5487
 
5466
5488
  /**
@@ -5472,12 +5494,9 @@ function getTextureInternalFormatInfo(internalFormat) {
5472
5494
  */
5473
5495
  function getBytesPerElementForInternalFormat(internalFormat, type) {
5474
5496
  const info = getTextureInternalFormatInfo(internalFormat);
5475
- if (!info) {
5476
- throw "unknown internal format";
5477
- }
5478
5497
  const bytesPerElement = info.bytesPerElementMap[type];
5479
5498
  if (bytesPerElement === undefined) {
5480
- throw "unknown internal format";
5499
+ throw new Error("type not supported for internal format");
5481
5500
  }
5482
5501
  return bytesPerElement;
5483
5502
  }
@@ -5502,7 +5521,7 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
5502
5521
  function getFormatAndTypeForInternalFormat(internalFormat) {
5503
5522
  const info = getTextureInternalFormatInfo(internalFormat);
5504
5523
  if (!info) {
5505
- throw "unknown internal format";
5524
+ throw new Error("unknown internal format");
5506
5525
  }
5507
5526
  return {
5508
5527
  format: info.textureFormat,
@@ -5517,10 +5536,22 @@ function getFormatAndTypeForInternalFormat(internalFormat) {
5517
5536
  */
5518
5537
  function isCompressedInternalFormat(internalFormat) {
5519
5538
  const info = getTextureInternalFormatInfo(internalFormat);
5520
- if (!info) {
5521
- throw "unknown internal format";
5539
+ return !!info.block;
5540
+ }
5541
+
5542
+ /**
5543
+ * Gets the width, height, and bytes per block for the given internal format
5544
+ * @param {number} internalFormat
5545
+ * @param {number} type
5546
+ * @private
5547
+ */
5548
+ function getBlockInfoForInternalFormat(internalFormat, type) {
5549
+ const info = getTextureInternalFormatInfo(internalFormat);
5550
+ if (info.block) {
5551
+ return { blockWidth: info.block.width, blockHeight: info.block.height, bytesPerBlock: info.block.bytes };
5522
5552
  }
5523
- return !!info.compressed;
5553
+ const bytesPerBlock = getBytesPerElementForInternalFormat(internalFormat, type);
5554
+ return { blockWidth: 1, blockHeight: 1, bytesPerBlock };
5524
5555
  }
5525
5556
 
5526
5557
  /**
@@ -5549,9 +5580,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
5549
5580
  return isPowerOf2(width) && isPowerOf2(height);
5550
5581
  }
5551
5582
  const info = getTextureInternalFormatInfo(internalFormat);
5552
- if (!info) {
5553
- throw "unknown internal format";
5554
- }
5555
5583
  return info.colorRenderable && info.textureFilterable;
5556
5584
  }
5557
5585
 
@@ -5563,9 +5591,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
5563
5591
  */
5564
5592
  function canFilter(internalFormat) {
5565
5593
  const info = getTextureInternalFormatInfo(internalFormat);
5566
- if (!info) {
5567
- throw "unknown internal format";
5568
- }
5569
5594
  return info.textureFilterable;
5570
5595
  }
5571
5596
 
@@ -5577,9 +5602,6 @@ function canFilter(internalFormat) {
5577
5602
  */
5578
5603
  function getNumComponentsForFormat(format) {
5579
5604
  const info = formatInfo[format];
5580
- if (!info) {
5581
- throw "unknown format: " + format;
5582
- }
5583
5605
  return info.numColorComponents;
5584
5606
  }
5585
5607
 
@@ -5598,7 +5620,7 @@ function getTextureTypeForArrayType(gl, src, defaultType) {
5598
5620
 
5599
5621
  function guessDimensions(gl, target, width, height, numElements) {
5600
5622
  if (numElements % 1 !== 0) {
5601
- throw "can't guess dimensions";
5623
+ throw new Error("can't guess dimensions");
5602
5624
  }
5603
5625
  if (!width && !height) {
5604
5626
  const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP$1 ? 6 : 1));
@@ -5612,12 +5634,12 @@ function guessDimensions(gl, target, width, height, numElements) {
5612
5634
  } else if (!height) {
5613
5635
  height = numElements / width;
5614
5636
  if (height % 1) {
5615
- throw "can't guess dimensions";
5637
+ throw new Error("can't guess dimensions");
5616
5638
  }
5617
5639
  } else if (!width) {
5618
5640
  width = numElements / height;
5619
5641
  if (width % 1) {
5620
- throw "can't guess dimensions";
5642
+ throw new Error("can't guess dimensions");
5621
5643
  }
5622
5644
  }
5623
5645
  return {
@@ -5671,7 +5693,7 @@ function setDefaults$1(newDefaults) {
5671
5693
  * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
5672
5694
  * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
5673
5695
  * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
5674
- * @property {number} [depth] the depth of a texture. Only used if src is an array or type array or null and target is `TEXTURE_3D` .
5696
+ * @property {number} [depth] the depth of a texture. Only used if src is an array or typed array or null and target is `TEXTURE_3D` .
5675
5697
  * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
5676
5698
  * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
5677
5699
  * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
@@ -5730,15 +5752,24 @@ function setDefaults$1(newDefaults) {
5730
5752
  * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
5731
5753
  * `HTMLCanvasElement`, `HTMLVideoElement`.
5732
5754
  *
5733
- * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
5734
- * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
5735
- * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
5736
- * by 6. Then
5755
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture.
5756
+ *
5757
+ * * If `width` or `height` is not specified it is guessed as follows.
5737
5758
  *
5738
- * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
5739
- * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
5759
+ * First the number of elements is computed by `src.length / numComponents`
5760
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
5761
+ * by 6. Then
5740
5762
  *
5741
- * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
5763
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
5764
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
5765
+ *
5766
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
5767
+ *
5768
+ * * If both `width` and `height` is specified, then, the size of mip levels from `level` will be computed
5769
+ * and data for consecutive mip levels will be uploaded until the data runs out.
5770
+ *
5771
+ * In other words: `{ format: g.RGBA, width: 4, height: 4, src: Uint8Array((4 * 4 + 2 * 2 + 1) * 4) }`
5772
+ * uploads 3 mip levels (4x4, 2x2, 1x1) because src is more than the data for the first mip level.
5742
5773
  *
5743
5774
  * If `number[]` will be converted to `type`.
5744
5775
  *
@@ -5999,27 +6030,47 @@ function make1Pixel(color) {
5999
6030
  return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
6000
6031
  }
6001
6032
 
6033
+ /**
6034
+ * @typedef {Object} SetTextureFilteringInternalOptions
6035
+ * @property {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
6036
+ * This is often the same options you passed in when you created the texture.
6037
+ * @property {number} [width] width of texture
6038
+ * @property {number} [height] height of texture
6039
+ * @property {number} [internalFormat] The internalFormat parameter from texImage2D etc..
6040
+ * @property {number} [lastMipLevelUploaded] The last mip level manually uploaded
6041
+ * @private
6042
+ */
6043
+
6002
6044
  /**
6003
6045
  * Sets filtering or generates mips for texture based on width or height
6004
6046
  * If width or height is not passed in uses `options.width` and//or `options.height`
6005
6047
  *
6006
6048
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
6007
6049
  * @param {WebGLTexture} tex the WebGLTexture to set parameters for
6008
- * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
6009
- * This is often the same options you passed in when you created the texture.
6010
- * @param {number} [width] width of texture
6011
- * @param {number} [height] height of texture
6012
- * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
6013
- * @memberOf module:twgl/textures
6050
+ * @param {SetTextureFilteringInternalOptions} p
6051
+ * @private
6014
6052
  */
6015
- function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
6053
+ function setTextureFilteringForSizeInternal(gl, tex, {options, width, height, internalFormat, lastMipLevelUploaded }) {
6016
6054
  options = options || defaults$1.textureOptions;
6017
6055
  internalFormat = internalFormat || RGBA$1;
6018
6056
  const target = options.target || TEXTURE_2D$2;
6019
6057
  width = width || options.width;
6020
6058
  height = height || options.height;
6021
6059
  gl.bindTexture(target, tex);
6022
- if (canGenerateMipmap(gl, width, height, internalFormat)) {
6060
+ if (lastMipLevelUploaded > 1) {
6061
+ const lastLevelWidth = Math.max(1, width >> lastMipLevelUploaded);
6062
+ const lastLevelHeight = Math.max(1, height >> lastMipLevelUploaded);
6063
+ // Note: This is a guess. The user can set maxLod etc...
6064
+ const canUseMips = lastLevelWidth === 1 && lastLevelHeight === 1;
6065
+ const magFiltering = canFilter(internalFormat) ? LINEAR$1 : NEAREST;
6066
+ const minFiltering = canFilter(internalFormat)
6067
+ ? canUseMips
6068
+ ? NEAREST_MIPMAP_LINEAR
6069
+ : LINEAR$1
6070
+ : NEAREST;
6071
+ gl.texParameteri(target, TEXTURE_MAG_FILTER, magFiltering);
6072
+ gl.texParameteri(target, TEXTURE_MIN_FILTER, minFiltering);
6073
+ } else if (canGenerateMipmap(gl, width, height, internalFormat)) {
6023
6074
  gl.generateMipmap(target);
6024
6075
  } else {
6025
6076
  const filtering = canFilter(internalFormat) ? LINEAR$1 : NEAREST;
@@ -6030,6 +6081,23 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
6030
6081
  }
6031
6082
  }
6032
6083
 
6084
+ /**
6085
+ * Sets filtering or generates mips for texture based on width or height
6086
+ * If width or height is not passed in uses `options.width` and//or `options.height`
6087
+ *
6088
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
6089
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
6090
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
6091
+ * This is often the same options you passed in when you created the texture.
6092
+ * @param {number} [width] width of texture
6093
+ * @param {number} [height] height of texture
6094
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
6095
+ * @memberOf module:twgl/textures
6096
+ */
6097
+ function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
6098
+ setTextureFilteringForSizeInternal(gl, tex, { options, width, height, internalFormat });
6099
+ }
6100
+
6033
6101
  function shouldAutomaticallySetTextureFilteringForSize(options) {
6034
6102
  return options.auto === true || (options.auto === undefined && options.level === undefined);
6035
6103
  }
@@ -6133,7 +6201,7 @@ function setTextureFromElement(gl, tex, element, options) {
6133
6201
  size = imgWidth / 2;
6134
6202
  slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
6135
6203
  } else {
6136
- throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
6204
+ throw new Error(`can't figure out cube map from element: ${element.src ? element.src : element.nodeName}`);
6137
6205
  }
6138
6206
  const ctx = getShared2DContext();
6139
6207
  if (ctx) {
@@ -6187,7 +6255,7 @@ function setTextureFromElement(gl, tex, element, options) {
6187
6255
  const largest = Math.max(element.width, element.height);
6188
6256
  const depth = largest / smallest;
6189
6257
  if (depth % 1 !== 0) {
6190
- throw "can not compute 3D dimensions of element";
6258
+ throw new Error("can not compute 3D dimensions of element");
6191
6259
  }
6192
6260
  const xMult = element.width === largest ? 1 : 0;
6193
6261
  const yMult = element.height === largest ? 1 : 0;
@@ -6484,7 +6552,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6484
6552
  callback = callback || noop;
6485
6553
  const urls = options.src;
6486
6554
  if (urls.length !== 6) {
6487
- throw "there must be 6 urls for a cubemap";
6555
+ throw new Error("there must be 6 urls for a cubemap");
6488
6556
  }
6489
6557
  const level = options.level || 0;
6490
6558
  const internalFormat = options.internalFormat || options.format || RGBA$1;
@@ -6493,7 +6561,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
6493
6561
  const type = options.type || UNSIGNED_BYTE$1;
6494
6562
  const target = options.target || TEXTURE_2D$2;
6495
6563
  if (target !== TEXTURE_CUBE_MAP$1) {
6496
- throw "target must be TEXTURE_CUBE_MAP";
6564
+ throw new Error("target must be TEXTURE_CUBE_MAP");
6497
6565
  }
6498
6566
  setTextureTo1PixelColor(gl, tex, options);
6499
6567
  // Because it's async we need to copy the options.
@@ -6574,7 +6642,7 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
6574
6642
  const type = options.type || UNSIGNED_BYTE$1;
6575
6643
  const target = options.target || TEXTURE_2D_ARRAY$1;
6576
6644
  if (target !== TEXTURE_3D$1 && target !== TEXTURE_2D_ARRAY$1) {
6577
- throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
6645
+ throw new Error("target must be TEXTURE_3D or TEXTURE_2D_ARRAY");
6578
6646
  }
6579
6647
  setTextureTo1PixelColor(gl, tex, options);
6580
6648
  // Because it's async we need to copy the options.
@@ -6671,63 +6739,86 @@ function setTextureFromArray(gl, tex, src, options) {
6671
6739
  src = new Uint8Array(src.buffer);
6672
6740
  }
6673
6741
 
6674
- const { width, height, depth } = getTextureSize(gl, target, src, options, internalFormat, format, type);
6742
+ const { width, height, depth } = getTextureSize(target, src, options, internalFormat, format, type);
6675
6743
  const compressed = isCompressedInternalFormat(internalFormat);
6676
6744
 
6677
6745
  setSkipStateToDefault(gl);
6678
6746
  gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
6747
+ let mipLevelOffset = 0; // this is in addition to level
6679
6748
  scopedSetPackState(gl, options, () => {
6680
- if (target === TEXTURE_CUBE_MAP$1) {
6681
- const faceSize = src.length / 6;
6682
- getCubeFacesWithNdx(gl, options).forEach(f => {
6683
- const offset = faceSize * f.ndx;
6684
- const data = src.subarray(offset, offset + faceSize);
6749
+ let mipLevelByteOffset = 0;
6750
+ const { blockWidth, blockHeight, bytesPerBlock } = getBlockInfoForInternalFormat(internalFormat, type);
6751
+ while (mipLevelByteOffset < src.byteLength) {
6752
+ const mipWidth = Math.max(1, width >> mipLevelOffset);
6753
+ const mipHeight = Math.max(1, height >> mipLevelOffset);
6754
+ const mipDepth = target === TEXTURE_2D$2 ? Math.max(1, depth >> mipLevelOffset) : depth;
6755
+ const blocksAcross = Math.ceil(mipWidth / blockWidth);
6756
+ const blocksDown = Math.ceil(mipHeight / blockHeight);
6757
+ const numFaces = target === TEXTURE_CUBE_MAP$1 ? 6 : 1;
6758
+ const bytesPerMipLevel = blocksAcross * blocksDown * bytesPerBlock * mipDepth * numFaces;
6759
+ if (mipLevelByteOffset + bytesPerMipLevel > src.byteLength) {
6760
+ throw new Error('src size does not match number of mip levels');
6761
+ }
6762
+ const mipSource = src.subarray(mipLevelByteOffset / src.BYTES_PER_ELEMENT, (mipLevelByteOffset + bytesPerMipLevel) / src.BYTES_PER_ELEMENT);
6763
+ const mipLevel = level + mipLevelOffset;
6764
+
6765
+ if (target === TEXTURE_CUBE_MAP$1) {
6766
+ const faceSize = mipSource.length / 6;
6767
+ getCubeFacesWithNdx(gl, options).forEach(f => {
6768
+ const offset = faceSize * f.ndx;
6769
+ const data = mipSource.subarray(offset, offset + faceSize);
6770
+ if (compressed) {
6771
+ gl.compressedTexImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, data);
6772
+ } else {
6773
+ gl.texImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, data);
6774
+ }
6775
+ });
6776
+ } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6777
+ gl.texImage3D(target, mipLevel, internalFormat, mipWidth, mipHeight, mipDepth, 0, format, type, mipSource);
6778
+ } else {
6685
6779
  if (compressed) {
6686
- gl.compressedTexImage2D(f.face, level, internalFormat, width, height, 0, data);
6780
+ gl.compressedTexImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, mipSource);
6687
6781
  } else {
6688
- gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
6782
+ gl.texImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, mipSource);
6689
6783
  }
6690
- });
6691
- } else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6692
- gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
6693
- } else {
6694
- if (compressed) {
6695
- gl.compressedTexImage2D(target, level, internalFormat, width, height, 0, src);
6696
- } else {
6697
- gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
6784
+ }
6785
+ ++mipLevelOffset;
6786
+ mipLevelByteOffset += bytesPerMipLevel;
6787
+ if (mipWidth === 1 && mipHeight === 1 && mipDepth === 1 && mipLevelByteOffset !== src.byteLength) {
6788
+ throw new Error('src size has more data than can fit in mip levels');
6698
6789
  }
6699
6790
  }
6700
6791
  });
6701
- return {
6702
- width: width,
6703
- height: height,
6704
- depth: depth,
6705
- type: type,
6706
- };
6792
+ return { width, height, depth, type, lastMipLevelUploaded: level + mipLevelOffset - 1 };
6707
6793
  }
6708
6794
 
6709
- function getTextureSize(gl, target, src, options, internalFormat, format, type) {
6795
+ function getTextureSize(target, src, options, internalFormat, format, type) {
6710
6796
  let width = options.width;
6711
6797
  let height = options.height;
6712
6798
  let depth = options.depth;
6713
6799
 
6714
6800
  const compressed = isCompressedInternalFormat(internalFormat);
6801
+
6715
6802
  if (compressed) {
6716
6803
  if (!width || !height) {
6717
- throw "compressed texture needs to set width and height!";
6804
+ throw new Error("compressed texture needs to set width and height!");
6718
6805
  }
6806
+ depth = depth || 1;
6719
6807
  } else {
6720
6808
  const bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
6721
6809
  const numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
6722
6810
  if (numElements % 1) {
6723
- throw "length wrong size for format: " + glEnumToString(gl, format);
6811
+ throw new Error(`length wrong size for format: ${glEnumToString(gl, format)}`);
6812
+ }
6813
+ if (compressed && (!width || !height)) {
6814
+ throw new Error("compressed texture needs to set width and height!");
6724
6815
  }
6725
6816
  let dimensions;
6726
6817
  if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
6727
6818
  if (!width && !height && !depth) {
6728
6819
  const size = Math.cbrt(numElements);
6729
6820
  if (size % 1 !== 0) {
6730
- throw "can't guess cube size of array of numElements: " + numElements;
6821
+ throw new Error(`can't guess cube size of array of numElements: ${numElements}`);
6731
6822
  }
6732
6823
  width = size;
6733
6824
  height = size;
@@ -6828,6 +6919,7 @@ function createTexture(gl, options, callback) {
6828
6919
  const target = options.target || TEXTURE_2D$2;
6829
6920
  let width = options.width || 1;
6830
6921
  let height = options.height || 1;
6922
+ let lastMipLevelUploaded = 0;
6831
6923
  const internalFormat = options.internalFormat || RGBA$1;
6832
6924
  gl.bindTexture(target, tex);
6833
6925
  if (target === TEXTURE_CUBE_MAP$1) {
@@ -6852,6 +6944,7 @@ function createTexture(gl, options, callback) {
6852
6944
  const dimensions = setTextureFromArray(gl, tex, src, options);
6853
6945
  width = dimensions.width;
6854
6946
  height = dimensions.height;
6947
+ lastMipLevelUploaded = dimensions.lastMipLevelUploaded;
6855
6948
  } else if (Array.isArray(src) && (typeof (src[0]) === 'string' || isTexImageSource(src[0]))) {
6856
6949
  if (target === TEXTURE_CUBE_MAP$1) {
6857
6950
  loadCubemapFromUrls(gl, tex, options, callback);
@@ -6867,7 +6960,7 @@ function createTexture(gl, options, callback) {
6867
6960
  setEmptyTexture(gl, tex, options);
6868
6961
  }
6869
6962
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
6870
- setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
6963
+ setTextureFilteringForSizeInternal(gl, tex, { options, width, height, internalFormat, lastMipLevelUploaded });
6871
6964
  }
6872
6965
  setTextureParameters(gl, tex, options);
6873
6966
  return tex;
@@ -9703,6 +9796,8 @@ renderbufferFormats[RGB5_A1] = true;
9703
9796
  renderbufferFormats[RGB565] = true;
9704
9797
  renderbufferFormats[DEPTH_STENCIL] = true;
9705
9798
  renderbufferFormats[DEPTH_COMPONENT16] = true;
9799
+ renderbufferFormats[DEPTH_COMPONENT24] = true;
9800
+ renderbufferFormats[DEPTH_COMPONENT32F] = true;
9706
9801
  renderbufferFormats[STENCIL_INDEX] = true;
9707
9802
  renderbufferFormats[STENCIL_INDEX8] = true;
9708
9803