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,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 6.2.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 7.0.3 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
  */
@@ -1093,6 +1093,8 @@ renderbufferFormats[RGB5_A1] = true;
1093
1093
  renderbufferFormats[RGB565] = true;
1094
1094
  renderbufferFormats[DEPTH_STENCIL] = true;
1095
1095
  renderbufferFormats[DEPTH_COMPONENT16] = true;
1096
+ renderbufferFormats[DEPTH_COMPONENT24] = true;
1097
+ renderbufferFormats[DEPTH_COMPONENT32F] = true;
1096
1098
  renderbufferFormats[STENCIL_INDEX] = true;
1097
1099
  renderbufferFormats[STENCIL_INDEX8] = true;
1098
1100
  function isRenderbufferFormat(format) {
@@ -1938,8 +1940,7 @@ function setAxis(a, v, axis, dst) {
1938
1940
  * the distances to the near and far clipping planes. Note that near and far
1939
1941
  * are not z coordinates, but rather they are distances along the negative
1940
1942
  * z-axis. The matrix generated sends the viewing frustum to the unit box.
1941
- * We assume a unit box extending from -1 to 1 in the x and y dimensions and
1942
- * from 0 to 1 in the z dimension.
1943
+ * We assume a unit box extending from -1 to 1 in the x, y and z dimensions.
1943
1944
  * @param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).
1944
1945
  * @param {number} aspect The aspect ratio width / height.
1945
1946
  * @param {number} zNear The depth (negative z coordinate)
@@ -2017,8 +2018,7 @@ function ortho(left, right, bottom, top, near, far, dst) {
2017
2018
  * distances to the near and far clipping planes. Note that near and far are not
2018
2019
  * z coordinates, but rather they are distances along the negative z-axis. The
2019
2020
  * matrix generated sends the viewing frustum to the unit box. We assume a unit
2020
- * box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z
2021
- * dimension.
2021
+ * box extending from -1 to 1 in the x, y and z dimensions.
2022
2022
  * @param {number} left The x coordinate of the left plane of the box.
2023
2023
  * @param {number} right The x coordinate of the right plane of the box.
2024
2024
  * @param {number} bottom The y coordinate of the bottom plane of the box.
@@ -2044,11 +2044,11 @@ function frustum(left, right, bottom, top, near, far, dst) {
2044
2044
  dst[7] = 0;
2045
2045
  dst[8] = (left + right) / dx;
2046
2046
  dst[9] = (top + bottom) / dy;
2047
- dst[10] = far / dz;
2047
+ dst[10] = (near + far) / dz;
2048
2048
  dst[11] = -1;
2049
2049
  dst[12] = 0;
2050
2050
  dst[13] = 0;
2051
- dst[14] = near * far / dz;
2051
+ dst[14] = 2 * near * far / dz;
2052
2052
  dst[15] = 0;
2053
2053
  return dst;
2054
2054
  }
@@ -3620,29 +3620,29 @@ function create3DFVertices() {
3620
3620
  // left column front
3621
3621
  // top rung front
3622
3622
  // middle rung front
3623
- 18, 0, 0, 1,
3623
+ 18, 0, 0, -1,
3624
3624
  // left column back
3625
3625
  // top rung back
3626
3626
  // middle rung back
3627
- 18, 0, 0, -1,
3627
+ 18, 0, 0, 1,
3628
3628
  // top
3629
- 6, 0, 1, 0,
3629
+ 6, 0, -1, 0,
3630
3630
  // top rung front
3631
3631
  6, 1, 0, 0,
3632
3632
  // under top rung
3633
- 6, 0, -1, 0,
3633
+ 6, 0, 1, 0,
3634
3634
  // between top rung and middle
3635
3635
  6, 1, 0, 0,
3636
3636
  // top of middle rung
3637
- 6, 0, 1, 0,
3637
+ 6, 0, -1, 0,
3638
3638
  // front of middle rung
3639
3639
  6, 1, 0, 0,
3640
3640
  // bottom of middle rung.
3641
- 6, 0, -1, 0,
3641
+ 6, 0, 1, 0,
3642
3642
  // front of bottom
3643
3643
  6, 1, 0, 0,
3644
3644
  // bottom
3645
- 6, 0, -1, 0,
3645
+ 6, 0, 1, 0,
3646
3646
  // left side
3647
3647
  6, -1, 0, 0]);
3648
3648
  var colors = expandRLEData([
@@ -7152,6 +7152,7 @@ var CLAMP_TO_EDGE = 0x812f;
7152
7152
  /* TextureMagFilter */
7153
7153
  var NEAREST = 0x2600;
7154
7154
  var LINEAR = 0x2601;
7155
+ var NEAREST_MIPMAP_LINEAR = 0x2702;
7155
7156
 
7156
7157
  /* TextureMinFilter */
7157
7158
  // const NEAREST_MIPMAP_NEAREST = 0x2700;
@@ -7395,6 +7396,14 @@ var formatInfo = {};
7395
7396
  };
7396
7397
  }
7397
7398
 
7399
+ /**
7400
+ * @typedef {Object} BlockInfo
7401
+ * @property {number} bytes number of bytes in the block
7402
+ * @property {number} width width of the block
7403
+ * @property {number} height height of the block
7404
+ * @private
7405
+ */
7406
+
7398
7407
  /**
7399
7408
  * @typedef {Object} TextureFormatDetails
7400
7409
  * @property {number} textureFormat format to pass texImage2D and similar functions.
@@ -7402,7 +7411,7 @@ var formatInfo = {};
7402
7411
  * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
7403
7412
  * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
7404
7413
  * @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
7414
+ * @property {BlockInfo} [block] block size, only for compressed textures
7406
7415
  * @private
7407
7416
  */
7408
7417
 
@@ -7843,321 +7852,514 @@ function getTextureInternalFormatInfo(internalFormat) {
7843
7852
  info.bytesPerElementMap[type] = bytesPerElement;
7844
7853
  });
7845
7854
  });
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;
7855
+ var block8_4_4 = {
7856
+ bytes: 8,
7857
+ width: 4,
7858
+ height: 4
7859
+ };
7860
+ var block16_4_4 = {
7861
+ bytes: 16,
7862
+ width: 4,
7863
+ height: 4
7864
+ };
7865
+
7866
+ // compressed texture formats
7867
+ // s3tc:https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
7868
+ t[COMPRESSED_RGB_S3TC_DXT1_EXT] = {
7869
+ textureFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
7870
+ colorRenderable: false,
7871
+ textureFilterable: true,
7872
+ block: block8_4_4
7873
+ };
7874
+ t[COMPRESSED_RGBA_S3TC_DXT1_EXT] = {
7875
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT1_EXT,
7876
+ colorRenderable: false,
7877
+ textureFilterable: true,
7878
+ block: block8_4_4
7879
+ };
7880
+ t[COMPRESSED_RGBA_S3TC_DXT3_EXT] = {
7881
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT3_EXT,
7882
+ colorRenderable: false,
7883
+ textureFilterable: true,
7884
+ block: block16_4_4
7885
+ };
7886
+ t[COMPRESSED_RGBA_S3TC_DXT5_EXT] = {
7887
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
7888
+ colorRenderable: false,
7889
+ textureFilterable: true,
7890
+ block: block16_4_4
7891
+ };
7892
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
7893
+ t[COMPRESSED_SRGB_S3TC_DXT1_EXT] = {
7894
+ textureFormat: COMPRESSED_SRGB_S3TC_DXT1_EXT,
7895
+ colorRenderable: false,
7896
+ textureFilterable: true,
7897
+ block: block8_4_4
7898
+ };
7899
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = {
7900
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
7901
+ colorRenderable: false,
7902
+ textureFilterable: true,
7903
+ block: block8_4_4
7904
+ };
7905
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = {
7906
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
7907
+ colorRenderable: false,
7908
+ textureFilterable: true,
7909
+ block: block16_4_4
7910
+ };
7911
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = {
7912
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
7913
+ colorRenderable: false,
7914
+ textureFilterable: true,
7915
+ block: block16_4_4
7916
+ };
7917
+ // https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
7918
+ t[COMPRESSED_RGB_ETC1_WEBGL] = {
7919
+ textureFormat: COMPRESSED_RGB_ETC1_WEBGL,
7920
+ colorRenderable: false,
7921
+ textureFilterable: true,
7922
+ block: block8_4_4
7923
+ };
7924
+ t[COMPRESSED_R11_EAC] = {
7925
+ textureFormat: COMPRESSED_R11_EAC,
7926
+ colorRenderable: false,
7927
+ textureFilterable: true,
7928
+ block: block8_4_4
7929
+ };
7930
+ t[COMPRESSED_SIGNED_R11_EAC] = {
7931
+ textureFormat: COMPRESSED_SIGNED_R11_EAC,
7932
+ colorRenderable: false,
7933
+ textureFilterable: true,
7934
+ block: block8_4_4
7935
+ };
7936
+ t[COMPRESSED_RG11_EAC] = {
7937
+ textureFormat: COMPRESSED_RG11_EAC,
7938
+ colorRenderable: false,
7939
+ textureFilterable: true,
7940
+ block: block16_4_4
7941
+ };
7942
+ t[COMPRESSED_SIGNED_RG11_EAC] = {
7943
+ textureFormat: COMPRESSED_SIGNED_RG11_EAC,
7944
+ colorRenderable: false,
7945
+ textureFilterable: true,
7946
+ block: block16_4_4
7947
+ };
7948
+ t[COMPRESSED_RGB8_ETC2] = {
7949
+ textureFormat: COMPRESSED_RGB8_ETC2,
7950
+ colorRenderable: false,
7951
+ textureFilterable: true,
7952
+ block: block8_4_4
7953
+ };
7954
+ t[COMPRESSED_SRGB8_ETC2] = {
7955
+ textureFormat: COMPRESSED_SRGB8_ETC2,
7956
+ colorRenderable: false,
7957
+ textureFilterable: true,
7958
+ block: block8_4_4
7959
+ };
7960
+ t[COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = {
7961
+ textureFormat: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
7962
+ colorRenderable: false,
7963
+ textureFilterable: true,
7964
+ block: block8_4_4
7965
+ };
7966
+ t[COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = {
7967
+ textureFormat: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
7968
+ colorRenderable: false,
7969
+ textureFilterable: true,
7970
+ block: block8_4_4
7971
+ };
7972
+ t[COMPRESSED_RGBA8_ETC2_EAC] = {
7973
+ textureFormat: COMPRESSED_RGBA8_ETC2_EAC,
7974
+ colorRenderable: false,
7975
+ textureFilterable: true,
7976
+ block: block16_4_4
7977
+ };
7978
+ t[COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = {
7979
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
7980
+ colorRenderable: false,
7981
+ textureFilterable: true,
7982
+ block: block16_4_4
7983
+ };
7984
+ // https://registry.khronos.org/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
7985
+ t[COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = {
7986
+ textureFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
7987
+ colorRenderable: false,
7988
+ textureFilterable: true,
7989
+ block: {
7990
+ bytes: 32,
7991
+ width: 8,
7992
+ height: 8
7993
+ }
7994
+ };
7995
+ t[COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = {
7996
+ textureFormat: COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
7997
+ colorRenderable: false,
7998
+ textureFilterable: true,
7999
+ block: {
8000
+ bytes: 32,
8001
+ width: 16,
8002
+ height: 8
8154
8003
  }
8155
- return t;
8156
8004
  };
8157
- Object.assign(t, getCompressedFormatInfo());
8005
+ t[COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = {
8006
+ textureFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
8007
+ colorRenderable: false,
8008
+ textureFilterable: true,
8009
+ block: {
8010
+ bytes: 32,
8011
+ width: 8,
8012
+ height: 8
8013
+ }
8014
+ };
8015
+ t[COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = {
8016
+ textureFormat: COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
8017
+ colorRenderable: false,
8018
+ textureFilterable: true,
8019
+ block: {
8020
+ bytes: 32,
8021
+ width: 16,
8022
+ height: 8
8023
+ }
8024
+ };
8025
+ // https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
8026
+ t[COMPRESSED_RGBA_ASTC_4x4_KHR] = {
8027
+ textureFormat: COMPRESSED_RGBA_ASTC_4x4_KHR,
8028
+ colorRenderable: false,
8029
+ textureFilterable: true,
8030
+ block: {
8031
+ bytes: 16,
8032
+ width: 4,
8033
+ height: 4
8034
+ }
8035
+ };
8036
+ t[COMPRESSED_RGBA_ASTC_5x4_KHR] = {
8037
+ textureFormat: COMPRESSED_RGBA_ASTC_5x4_KHR,
8038
+ colorRenderable: false,
8039
+ textureFilterable: true,
8040
+ block: {
8041
+ bytes: 16,
8042
+ width: 5,
8043
+ height: 4
8044
+ }
8045
+ };
8046
+ t[COMPRESSED_RGBA_ASTC_5x5_KHR] = {
8047
+ textureFormat: COMPRESSED_RGBA_ASTC_5x5_KHR,
8048
+ colorRenderable: false,
8049
+ textureFilterable: true,
8050
+ block: {
8051
+ bytes: 16,
8052
+ width: 5,
8053
+ height: 5
8054
+ }
8055
+ };
8056
+ t[COMPRESSED_RGBA_ASTC_6x5_KHR] = {
8057
+ textureFormat: COMPRESSED_RGBA_ASTC_6x5_KHR,
8058
+ colorRenderable: false,
8059
+ textureFilterable: true,
8060
+ block: {
8061
+ bytes: 16,
8062
+ width: 6,
8063
+ height: 5
8064
+ }
8065
+ };
8066
+ t[COMPRESSED_RGBA_ASTC_6x6_KHR] = {
8067
+ textureFormat: COMPRESSED_RGBA_ASTC_6x6_KHR,
8068
+ colorRenderable: false,
8069
+ textureFilterable: true,
8070
+ block: {
8071
+ bytes: 16,
8072
+ width: 6,
8073
+ height: 6
8074
+ }
8075
+ };
8076
+ t[COMPRESSED_RGBA_ASTC_8x5_KHR] = {
8077
+ textureFormat: COMPRESSED_RGBA_ASTC_8x5_KHR,
8078
+ colorRenderable: false,
8079
+ textureFilterable: true,
8080
+ block: {
8081
+ bytes: 16,
8082
+ width: 8,
8083
+ height: 5
8084
+ }
8085
+ };
8086
+ t[COMPRESSED_RGBA_ASTC_8x6_KHR] = {
8087
+ textureFormat: COMPRESSED_RGBA_ASTC_8x6_KHR,
8088
+ colorRenderable: false,
8089
+ textureFilterable: true,
8090
+ block: {
8091
+ bytes: 16,
8092
+ width: 8,
8093
+ height: 6
8094
+ }
8095
+ };
8096
+ t[COMPRESSED_RGBA_ASTC_8x8_KHR] = {
8097
+ textureFormat: COMPRESSED_RGBA_ASTC_8x8_KHR,
8098
+ colorRenderable: false,
8099
+ textureFilterable: true,
8100
+ block: {
8101
+ bytes: 16,
8102
+ width: 8,
8103
+ height: 8
8104
+ }
8105
+ };
8106
+ t[COMPRESSED_RGBA_ASTC_10x5_KHR] = {
8107
+ textureFormat: COMPRESSED_RGBA_ASTC_10x5_KHR,
8108
+ colorRenderable: false,
8109
+ textureFilterable: true,
8110
+ block: {
8111
+ bytes: 16,
8112
+ width: 10,
8113
+ height: 5
8114
+ }
8115
+ };
8116
+ t[COMPRESSED_RGBA_ASTC_10x6_KHR] = {
8117
+ textureFormat: COMPRESSED_RGBA_ASTC_10x6_KHR,
8118
+ colorRenderable: false,
8119
+ textureFilterable: true,
8120
+ block: {
8121
+ bytes: 16,
8122
+ width: 10,
8123
+ height: 6
8124
+ }
8125
+ };
8126
+ t[COMPRESSED_RGBA_ASTC_10x8_KHR] = {
8127
+ textureFormat: COMPRESSED_RGBA_ASTC_10x8_KHR,
8128
+ colorRenderable: false,
8129
+ textureFilterable: true,
8130
+ block: {
8131
+ bytes: 16,
8132
+ width: 10,
8133
+ height: 8
8134
+ }
8135
+ };
8136
+ t[COMPRESSED_RGBA_ASTC_10x10_KHR] = {
8137
+ textureFormat: COMPRESSED_RGBA_ASTC_10x10_KHR,
8138
+ colorRenderable: false,
8139
+ textureFilterable: true,
8140
+ block: {
8141
+ bytes: 16,
8142
+ width: 10,
8143
+ height: 10
8144
+ }
8145
+ };
8146
+ t[COMPRESSED_RGBA_ASTC_12x10_KHR] = {
8147
+ textureFormat: COMPRESSED_RGBA_ASTC_12x10_KHR,
8148
+ colorRenderable: false,
8149
+ textureFilterable: true,
8150
+ block: {
8151
+ bytes: 16,
8152
+ width: 12,
8153
+ height: 10
8154
+ }
8155
+ };
8156
+ t[COMPRESSED_RGBA_ASTC_12x12_KHR] = {
8157
+ textureFormat: COMPRESSED_RGBA_ASTC_12x12_KHR,
8158
+ colorRenderable: false,
8159
+ textureFilterable: true,
8160
+ block: {
8161
+ bytes: 16,
8162
+ width: 12,
8163
+ height: 12
8164
+ }
8165
+ };
8166
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR] = {
8167
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
8168
+ colorRenderable: false,
8169
+ textureFilterable: true,
8170
+ block: {
8171
+ bytes: 16,
8172
+ width: 4,
8173
+ height: 4
8174
+ }
8175
+ };
8176
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR] = {
8177
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
8178
+ colorRenderable: false,
8179
+ textureFilterable: true,
8180
+ block: {
8181
+ bytes: 16,
8182
+ width: 5,
8183
+ height: 4
8184
+ }
8185
+ };
8186
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR] = {
8187
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
8188
+ colorRenderable: false,
8189
+ textureFilterable: true,
8190
+ block: {
8191
+ bytes: 16,
8192
+ width: 5,
8193
+ height: 5
8194
+ }
8195
+ };
8196
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR] = {
8197
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
8198
+ colorRenderable: false,
8199
+ textureFilterable: true,
8200
+ block: {
8201
+ bytes: 16,
8202
+ width: 6,
8203
+ height: 5
8204
+ }
8205
+ };
8206
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR] = {
8207
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
8208
+ colorRenderable: false,
8209
+ textureFilterable: true,
8210
+ block: {
8211
+ bytes: 16,
8212
+ width: 6,
8213
+ height: 6
8214
+ }
8215
+ };
8216
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR] = {
8217
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
8218
+ colorRenderable: false,
8219
+ textureFilterable: true,
8220
+ block: {
8221
+ bytes: 16,
8222
+ width: 8,
8223
+ height: 5
8224
+ }
8225
+ };
8226
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR] = {
8227
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
8228
+ colorRenderable: false,
8229
+ textureFilterable: true,
8230
+ block: {
8231
+ bytes: 16,
8232
+ width: 8,
8233
+ height: 6
8234
+ }
8235
+ };
8236
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR] = {
8237
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
8238
+ colorRenderable: false,
8239
+ textureFilterable: true,
8240
+ block: {
8241
+ bytes: 16,
8242
+ width: 8,
8243
+ height: 8
8244
+ }
8245
+ };
8246
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR] = {
8247
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
8248
+ colorRenderable: false,
8249
+ textureFilterable: true,
8250
+ block: {
8251
+ bytes: 16,
8252
+ width: 10,
8253
+ height: 5
8254
+ }
8255
+ };
8256
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR] = {
8257
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
8258
+ colorRenderable: false,
8259
+ textureFilterable: true,
8260
+ block: {
8261
+ bytes: 16,
8262
+ width: 10,
8263
+ height: 6
8264
+ }
8265
+ };
8266
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR] = {
8267
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
8268
+ colorRenderable: false,
8269
+ textureFilterable: true,
8270
+ block: {
8271
+ bytes: 16,
8272
+ width: 10,
8273
+ height: 8
8274
+ }
8275
+ };
8276
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR] = {
8277
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
8278
+ colorRenderable: false,
8279
+ textureFilterable: true,
8280
+ block: {
8281
+ bytes: 16,
8282
+ width: 10,
8283
+ height: 10
8284
+ }
8285
+ };
8286
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR] = {
8287
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
8288
+ colorRenderable: false,
8289
+ textureFilterable: true,
8290
+ block: {
8291
+ bytes: 16,
8292
+ width: 12,
8293
+ height: 10
8294
+ }
8295
+ };
8296
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR] = {
8297
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
8298
+ colorRenderable: false,
8299
+ textureFilterable: true,
8300
+ block: {
8301
+ bytes: 16,
8302
+ width: 12,
8303
+ height: 12
8304
+ }
8305
+ };
8306
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
8307
+ t[COMPRESSED_RGBA_BPTC_UNORM_EXT] = {
8308
+ textureFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
8309
+ colorRenderable: false,
8310
+ textureFilterable: true,
8311
+ block: block16_4_4
8312
+ };
8313
+ t[COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT] = {
8314
+ textureFormat: COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,
8315
+ colorRenderable: false,
8316
+ textureFilterable: true,
8317
+ block: block16_4_4
8318
+ };
8319
+ t[COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT] = {
8320
+ textureFormat: COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
8321
+ colorRenderable: false,
8322
+ textureFilterable: true,
8323
+ block: block16_4_4
8324
+ };
8325
+ t[COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT] = {
8326
+ textureFormat: COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
8327
+ colorRenderable: false,
8328
+ textureFilterable: true,
8329
+ block: block16_4_4
8330
+ };
8331
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
8332
+ t[COMPRESSED_RED_RGTC1_EXT] = {
8333
+ textureFormat: COMPRESSED_RED_RGTC1_EXT,
8334
+ colorRenderable: false,
8335
+ textureFilterable: true,
8336
+ block: block8_4_4
8337
+ };
8338
+ t[COMPRESSED_SIGNED_RED_RGTC1_EXT] = {
8339
+ textureFormat: COMPRESSED_SIGNED_RED_RGTC1_EXT,
8340
+ colorRenderable: false,
8341
+ textureFilterable: true,
8342
+ block: block8_4_4
8343
+ };
8344
+ t[COMPRESSED_RED_GREEN_RGTC2_EXT] = {
8345
+ textureFormat: COMPRESSED_RED_GREEN_RGTC2_EXT,
8346
+ colorRenderable: false,
8347
+ textureFilterable: true,
8348
+ block: block8_4_4
8349
+ };
8350
+ t[COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT] = {
8351
+ textureFormat: COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,
8352
+ colorRenderable: false,
8353
+ textureFilterable: true,
8354
+ block: block8_4_4
8355
+ };
8158
8356
  s_textureInternalFormatInfo = t;
8159
8357
  }
8160
- return s_textureInternalFormatInfo[internalFormat];
8358
+ var info = s_textureInternalFormatInfo[internalFormat];
8359
+ if (!info) {
8360
+ throw new Error("unknown internal format");
8361
+ }
8362
+ return info;
8161
8363
  }
8162
8364
 
8163
8365
  /**
@@ -8169,12 +8371,9 @@ function getTextureInternalFormatInfo(internalFormat) {
8169
8371
  */
8170
8372
  function getBytesPerElementForInternalFormat(internalFormat, type) {
8171
8373
  var info = getTextureInternalFormatInfo(internalFormat);
8172
- if (!info) {
8173
- throw "unknown internal format";
8174
- }
8175
8374
  var bytesPerElement = info.bytesPerElementMap[type];
8176
8375
  if (bytesPerElement === undefined) {
8177
- throw "unknown internal format";
8376
+ throw new Error("type not supported for internal format");
8178
8377
  }
8179
8378
  return bytesPerElement;
8180
8379
  }
@@ -8200,7 +8399,7 @@ function getFormatAndTypeForInternalFormat(internalFormat) {
8200
8399
  var _info$type$, _info$type;
8201
8400
  var info = getTextureInternalFormatInfo(internalFormat);
8202
8401
  if (!info) {
8203
- throw "unknown internal format";
8402
+ throw new Error("unknown internal format");
8204
8403
  }
8205
8404
  return {
8206
8405
  format: info.textureFormat,
@@ -8215,10 +8414,30 @@ function getFormatAndTypeForInternalFormat(internalFormat) {
8215
8414
  */
8216
8415
  function isCompressedInternalFormat(internalFormat) {
8217
8416
  var info = getTextureInternalFormatInfo(internalFormat);
8218
- if (!info) {
8219
- throw "unknown internal format";
8417
+ return !!info.block;
8418
+ }
8419
+
8420
+ /**
8421
+ * Gets the width, height, and bytes per block for the given internal format
8422
+ * @param {number} internalFormat
8423
+ * @param {number} type
8424
+ * @private
8425
+ */
8426
+ function getBlockInfoForInternalFormat(internalFormat, type) {
8427
+ var info = getTextureInternalFormatInfo(internalFormat);
8428
+ if (info.block) {
8429
+ return {
8430
+ blockWidth: info.block.width,
8431
+ blockHeight: info.block.height,
8432
+ bytesPerBlock: info.block.bytes
8433
+ };
8220
8434
  }
8221
- return !!info.compressed;
8435
+ var bytesPerBlock = getBytesPerElementForInternalFormat(internalFormat, type);
8436
+ return {
8437
+ blockWidth: 1,
8438
+ blockHeight: 1,
8439
+ bytesPerBlock: bytesPerBlock
8440
+ };
8222
8441
  }
8223
8442
 
8224
8443
  /**
@@ -8247,9 +8466,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
8247
8466
  return isPowerOf2(width) && isPowerOf2(height);
8248
8467
  }
8249
8468
  var info = getTextureInternalFormatInfo(internalFormat);
8250
- if (!info) {
8251
- throw "unknown internal format";
8252
- }
8253
8469
  return info.colorRenderable && info.textureFilterable;
8254
8470
  }
8255
8471
 
@@ -8261,9 +8477,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
8261
8477
  */
8262
8478
  function canFilter(internalFormat) {
8263
8479
  var info = getTextureInternalFormatInfo(internalFormat);
8264
- if (!info) {
8265
- throw "unknown internal format";
8266
- }
8267
8480
  return info.textureFilterable;
8268
8481
  }
8269
8482
 
@@ -8275,9 +8488,6 @@ function canFilter(internalFormat) {
8275
8488
  */
8276
8489
  function getNumComponentsForFormat(format) {
8277
8490
  var info = formatInfo[format];
8278
- if (!info) {
8279
- throw "unknown format: " + format;
8280
- }
8281
8491
  return info.numColorComponents;
8282
8492
  }
8283
8493
 
@@ -8295,7 +8505,7 @@ function getTextureTypeForArrayType(gl, src, defaultType) {
8295
8505
  }
8296
8506
  function guessDimensions(gl, target, width, height, numElements) {
8297
8507
  if (numElements % 1 !== 0) {
8298
- throw "can't guess dimensions";
8508
+ throw new Error("can't guess dimensions");
8299
8509
  }
8300
8510
  if (!width && !height) {
8301
8511
  var size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
@@ -8309,12 +8519,12 @@ function guessDimensions(gl, target, width, height, numElements) {
8309
8519
  } else if (!height) {
8310
8520
  height = numElements / width;
8311
8521
  if (height % 1) {
8312
- throw "can't guess dimensions";
8522
+ throw new Error("can't guess dimensions");
8313
8523
  }
8314
8524
  } else if (!width) {
8315
8525
  width = numElements / height;
8316
8526
  if (width % 1) {
8317
- throw "can't guess dimensions";
8527
+ throw new Error("can't guess dimensions");
8318
8528
  }
8319
8529
  }
8320
8530
  return {
@@ -8367,7 +8577,7 @@ function setDefaults(newDefaults) {
8367
8577
  * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
8368
8578
  * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
8369
8579
  * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
8370
- * @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` .
8580
+ * @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` .
8371
8581
  * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
8372
8582
  * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
8373
8583
  * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
@@ -8426,15 +8636,24 @@ function setDefaults(newDefaults) {
8426
8636
  * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
8427
8637
  * `HTMLCanvasElement`, `HTMLVideoElement`.
8428
8638
  *
8429
- * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
8430
- * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
8431
- * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
8432
- * by 6. Then
8639
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture.
8640
+ *
8641
+ * * If `width` or `height` is not specified it is guessed as follows.
8642
+ *
8643
+ * First the number of elements is computed by `src.length / numComponents`
8644
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
8645
+ * by 6. Then
8646
+ *
8647
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
8648
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
8649
+ *
8650
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
8433
8651
  *
8434
- * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
8435
- * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
8652
+ * * If both `width` and `height` is specified, then, the size of mip levels from `level` will be computed
8653
+ * and data for consecutive mip levels will be uploaded until the data runs out.
8436
8654
  *
8437
- * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
8655
+ * In other words: `{ format: g.RGBA, width: 4, height: 4, src: Uint8Array((4 * 4 + 2 * 2 + 1) * 4) }`
8656
+ * uploads 3 mip levels (4x4, 2x2, 1x1) because src is more than the data for the first mip level.
8438
8657
  *
8439
8658
  * If `number[]` will be converted to `type`.
8440
8659
  *
@@ -8685,27 +8904,48 @@ function make1Pixel(color) {
8685
8904
  return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
8686
8905
  }
8687
8906
 
8907
+ /**
8908
+ * @typedef {Object} SetTextureFilteringInternalOptions
8909
+ * @property {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
8910
+ * This is often the same options you passed in when you created the texture.
8911
+ * @property {number} [width] width of texture
8912
+ * @property {number} [height] height of texture
8913
+ * @property {number} [internalFormat] The internalFormat parameter from texImage2D etc..
8914
+ * @property {number} [lastMipLevelUploaded] The last mip level manually uploaded
8915
+ * @private
8916
+ */
8917
+
8688
8918
  /**
8689
8919
  * Sets filtering or generates mips for texture based on width or height
8690
8920
  * If width or height is not passed in uses `options.width` and//or `options.height`
8691
8921
  *
8692
8922
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8693
8923
  * @param {WebGLTexture} tex the WebGLTexture to set parameters for
8694
- * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
8695
- * This is often the same options you passed in when you created the texture.
8696
- * @param {number} [width] width of texture
8697
- * @param {number} [height] height of texture
8698
- * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
8699
- * @memberOf module:twgl/textures
8924
+ * @param {SetTextureFilteringInternalOptions} p
8925
+ * @private
8700
8926
  */
8701
- function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
8927
+ function setTextureFilteringForSizeInternal(gl, tex, _ref2) {
8928
+ var options = _ref2.options,
8929
+ width = _ref2.width,
8930
+ height = _ref2.height,
8931
+ internalFormat = _ref2.internalFormat,
8932
+ lastMipLevelUploaded = _ref2.lastMipLevelUploaded;
8702
8933
  options = options || defaults.textureOptions;
8703
8934
  internalFormat = internalFormat || RGBA;
8704
8935
  var target = options.target || TEXTURE_2D;
8705
8936
  width = width || options.width;
8706
8937
  height = height || options.height;
8707
8938
  gl.bindTexture(target, tex);
8708
- if (canGenerateMipmap(gl, width, height, internalFormat)) {
8939
+ if (lastMipLevelUploaded > 1) {
8940
+ var lastLevelWidth = Math.max(1, width >> lastMipLevelUploaded);
8941
+ var lastLevelHeight = Math.max(1, height >> lastMipLevelUploaded);
8942
+ // Note: This is a guess. The user can set maxLod etc...
8943
+ var canUseMips = lastLevelWidth === 1 && lastLevelHeight === 1;
8944
+ var magFiltering = canFilter(internalFormat) ? LINEAR : NEAREST;
8945
+ var minFiltering = canFilter(internalFormat) ? canUseMips ? NEAREST_MIPMAP_LINEAR : LINEAR : NEAREST;
8946
+ gl.texParameteri(target, TEXTURE_MAG_FILTER, magFiltering);
8947
+ gl.texParameteri(target, TEXTURE_MIN_FILTER, minFiltering);
8948
+ } else if (canGenerateMipmap(gl, width, height, internalFormat)) {
8709
8949
  gl.generateMipmap(target);
8710
8950
  } else {
8711
8951
  var filtering = canFilter(internalFormat) ? LINEAR : NEAREST;
@@ -8715,6 +8955,28 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
8715
8955
  gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
8716
8956
  }
8717
8957
  }
8958
+
8959
+ /**
8960
+ * Sets filtering or generates mips for texture based on width or height
8961
+ * If width or height is not passed in uses `options.width` and//or `options.height`
8962
+ *
8963
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
8964
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
8965
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
8966
+ * This is often the same options you passed in when you created the texture.
8967
+ * @param {number} [width] width of texture
8968
+ * @param {number} [height] height of texture
8969
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
8970
+ * @memberOf module:twgl/textures
8971
+ */
8972
+ function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
8973
+ setTextureFilteringForSizeInternal(gl, tex, {
8974
+ options: options,
8975
+ width: width,
8976
+ height: height,
8977
+ internalFormat: internalFormat
8978
+ });
8979
+ }
8718
8980
  function shouldAutomaticallySetTextureFilteringForSize(options) {
8719
8981
  return options.auto === true || options.auto === undefined && options.level === undefined;
8720
8982
  }
@@ -8814,7 +9076,7 @@ function setTextureFromElement(gl, tex, element, options) {
8814
9076
  size = imgWidth / 2;
8815
9077
  slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
8816
9078
  } else {
8817
- throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
9079
+ throw new Error("can't figure out cube map from element: ".concat(element.src ? element.src : element.nodeName));
8818
9080
  }
8819
9081
  var ctx = getShared2DContext();
8820
9082
  if (ctx) {
@@ -8867,7 +9129,7 @@ function setTextureFromElement(gl, tex, element, options) {
8867
9129
  var largest = Math.max(element.width, element.height);
8868
9130
  var depth = largest / smallest;
8869
9131
  if (depth % 1 !== 0) {
8870
- throw "can not compute 3D dimensions of element";
9132
+ throw new Error("can not compute 3D dimensions of element");
8871
9133
  }
8872
9134
  var xMult = element.width === largest ? 1 : 0;
8873
9135
  var yMult = element.height === largest ? 1 : 0;
@@ -9149,7 +9411,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
9149
9411
  callback = callback || noop;
9150
9412
  var urls = options.src;
9151
9413
  if (urls.length !== 6) {
9152
- throw "there must be 6 urls for a cubemap";
9414
+ throw new Error("there must be 6 urls for a cubemap");
9153
9415
  }
9154
9416
  var level = options.level || 0;
9155
9417
  var internalFormat = options.internalFormat || options.format || RGBA;
@@ -9158,7 +9420,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
9158
9420
  var type = options.type || UNSIGNED_BYTE;
9159
9421
  var target = options.target || TEXTURE_2D;
9160
9422
  if (target !== TEXTURE_CUBE_MAP) {
9161
- throw "target must be TEXTURE_CUBE_MAP";
9423
+ throw new Error("target must be TEXTURE_CUBE_MAP");
9162
9424
  }
9163
9425
  setTextureTo1PixelColor(gl, tex, options);
9164
9426
  // Because it's async we need to copy the options.
@@ -9236,7 +9498,7 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
9236
9498
  var type = options.type || UNSIGNED_BYTE;
9237
9499
  var target = options.target || TEXTURE_2D_ARRAY;
9238
9500
  if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
9239
- throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
9501
+ throw new Error("target must be TEXTURE_3D or TEXTURE_2D_ARRAY");
9240
9502
  }
9241
9503
  setTextureTo1PixelColor(gl, tex, options);
9242
9504
  // Because it's async we need to copy the options.
@@ -9326,63 +9588,96 @@ function setTextureFromArray(gl, tex, src, options) {
9326
9588
  } else if (src instanceof Uint8ClampedArray) {
9327
9589
  src = new Uint8Array(src.buffer);
9328
9590
  }
9329
- var _getTextureSize = getTextureSize(gl, target, src, options, internalFormat, format, type),
9591
+ var _getTextureSize = getTextureSize(target, src, options, internalFormat, format, type),
9330
9592
  width = _getTextureSize.width,
9331
9593
  height = _getTextureSize.height,
9332
9594
  depth = _getTextureSize.depth;
9333
9595
  var compressed = isCompressedInternalFormat(internalFormat);
9334
9596
  setSkipStateToDefault(gl);
9335
9597
  gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
9598
+ var mipLevelOffset = 0; // this is in addition to level
9336
9599
  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);
9600
+ var mipLevelByteOffset = 0;
9601
+ var _getBlockInfoForInter = getBlockInfoForInternalFormat(internalFormat, type),
9602
+ blockWidth = _getBlockInfoForInter.blockWidth,
9603
+ blockHeight = _getBlockInfoForInter.blockHeight,
9604
+ bytesPerBlock = _getBlockInfoForInter.bytesPerBlock;
9605
+ var _loop = function _loop() {
9606
+ var mipWidth = Math.max(1, width >> mipLevelOffset);
9607
+ var mipHeight = Math.max(1, height >> mipLevelOffset);
9608
+ var mipDepth = target === TEXTURE_2D ? Math.max(1, depth >> mipLevelOffset) : depth;
9609
+ var blocksAcross = Math.ceil(mipWidth / blockWidth);
9610
+ var blocksDown = Math.ceil(mipHeight / blockHeight);
9611
+ var numFaces = target === TEXTURE_CUBE_MAP ? 6 : 1;
9612
+ var bytesPerMipLevel = blocksAcross * blocksDown * bytesPerBlock * mipDepth * numFaces;
9613
+ if (mipLevelByteOffset + bytesPerMipLevel > src.byteLength) {
9614
+ throw new Error('src size does not match number of mip levels');
9615
+ }
9616
+ var mipSource = src.subarray(mipLevelByteOffset / src.BYTES_PER_ELEMENT, (mipLevelByteOffset + bytesPerMipLevel) / src.BYTES_PER_ELEMENT);
9617
+ var mipLevel = level + mipLevelOffset;
9618
+ if (target === TEXTURE_CUBE_MAP) {
9619
+ var faceSize = mipSource.length / 6;
9620
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
9621
+ var offset = faceSize * f.ndx;
9622
+ var data = mipSource.subarray(offset, offset + faceSize);
9623
+ if (compressed) {
9624
+ gl.compressedTexImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, data);
9625
+ } else {
9626
+ gl.texImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, data);
9627
+ }
9628
+ });
9629
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
9630
+ gl.texImage3D(target, mipLevel, internalFormat, mipWidth, mipHeight, mipDepth, 0, format, type, mipSource);
9631
+ } else {
9342
9632
  if (compressed) {
9343
- gl.compressedTexImage2D(f.face, level, internalFormat, width, height, 0, data);
9633
+ gl.compressedTexImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, mipSource);
9344
9634
  } else {
9345
- gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
9635
+ gl.texImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, mipSource);
9346
9636
  }
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
9637
  }
9638
+ ++mipLevelOffset;
9639
+ mipLevelByteOffset += bytesPerMipLevel;
9640
+ if (mipWidth === 1 && mipHeight === 1 && mipDepth === 1 && mipLevelByteOffset !== src.byteLength) {
9641
+ throw new Error('src size has more data than can fit in mip levels');
9642
+ }
9643
+ };
9644
+ while (mipLevelByteOffset < src.byteLength) {
9645
+ _loop();
9356
9646
  }
9357
9647
  });
9358
9648
  return {
9359
9649
  width: width,
9360
9650
  height: height,
9361
9651
  depth: depth,
9362
- type: type
9652
+ type: type,
9653
+ lastMipLevelUploaded: level + mipLevelOffset - 1
9363
9654
  };
9364
9655
  }
9365
- function getTextureSize(gl, target, src, options, internalFormat, format, type) {
9656
+ function getTextureSize(target, src, options, internalFormat, format, type) {
9366
9657
  var width = options.width;
9367
9658
  var height = options.height;
9368
9659
  var depth = options.depth;
9369
9660
  var compressed = isCompressedInternalFormat(internalFormat);
9370
9661
  if (compressed) {
9371
9662
  if (!width || !height) {
9372
- throw "compressed texture needs to set width and height!";
9663
+ throw new Error("compressed texture needs to set width and height!");
9373
9664
  }
9665
+ depth = depth || 1;
9374
9666
  } else {
9375
9667
  var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
9376
9668
  var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
9377
9669
  if (numElements % 1) {
9378
- throw "length wrong size for format: " + utils.glEnumToString(gl, format);
9670
+ throw new Error("length wrong size for format: ".concat(utils.glEnumToString(gl, format)));
9671
+ }
9672
+ if (compressed && (!width || !height)) {
9673
+ throw new Error("compressed texture needs to set width and height!");
9379
9674
  }
9380
9675
  var dimensions;
9381
9676
  if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
9382
9677
  if (!width && !height && !depth) {
9383
9678
  var size = Math.cbrt(numElements);
9384
9679
  if (size % 1 !== 0) {
9385
- throw "can't guess cube size of array of numElements: " + numElements;
9680
+ throw new Error("can't guess cube size of array of numElements: ".concat(numElements));
9386
9681
  }
9387
9682
  width = size;
9388
9683
  height = size;
@@ -9482,6 +9777,7 @@ function createTexture(gl, options, callback) {
9482
9777
  var target = options.target || TEXTURE_2D;
9483
9778
  var width = options.width || 1;
9484
9779
  var height = options.height || 1;
9780
+ var lastMipLevelUploaded = 0;
9485
9781
  var internalFormat = options.internalFormat || RGBA;
9486
9782
  gl.bindTexture(target, tex);
9487
9783
  if (target === TEXTURE_CUBE_MAP) {
@@ -9500,6 +9796,7 @@ function createTexture(gl, options, callback) {
9500
9796
  var dimensions = setTextureFromArray(gl, tex, src, options);
9501
9797
  width = dimensions.width;
9502
9798
  height = dimensions.height;
9799
+ lastMipLevelUploaded = dimensions.lastMipLevelUploaded;
9503
9800
  } else if (Array.isArray(src) && (typeof src[0] === 'string' || isTexImageSource(src[0]))) {
9504
9801
  if (target === TEXTURE_CUBE_MAP) {
9505
9802
  loadCubemapFromUrls(gl, tex, options, callback);
@@ -9516,7 +9813,13 @@ function createTexture(gl, options, callback) {
9516
9813
  setEmptyTexture(gl, tex, options);
9517
9814
  }
9518
9815
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
9519
- setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
9816
+ setTextureFilteringForSizeInternal(gl, tex, {
9817
+ options: options,
9818
+ width: width,
9819
+ height: height,
9820
+ internalFormat: internalFormat,
9821
+ lastMipLevelUploaded: lastMipLevelUploaded
9822
+ });
9520
9823
  }
9521
9824
  setTextureParameters(gl, tex, options);
9522
9825
  return tex;