twgl.js 6.1.1 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @license twgl.js 6.1.1 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
2
+ * @license twgl.js 7.0.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
3
3
  * Available via the MIT license.
4
4
  * see: http://github.com/greggman/twgl.js for details
5
5
  */
@@ -4177,6 +4177,7 @@ var CLAMP_TO_EDGE = 0x812f;
4177
4177
  /* TextureMagFilter */
4178
4178
  var NEAREST = 0x2600;
4179
4179
  var LINEAR = 0x2601;
4180
+ var NEAREST_MIPMAP_LINEAR = 0x2702;
4180
4181
 
4181
4182
  /* TextureMinFilter */
4182
4183
  // const NEAREST_MIPMAP_NEAREST = 0x2700;
@@ -4300,6 +4301,74 @@ var RED = 0x1903;
4300
4301
  var RED_INTEGER = 0x8D94;
4301
4302
  var RGB_INTEGER = 0x8D98;
4302
4303
  var RGBA_INTEGER = 0x8D99;
4304
+
4305
+ /* Compressed Texture Formats */
4306
+ // s3tc
4307
+ var COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
4308
+ var COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
4309
+ var COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
4310
+ var COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
4311
+ // s3tc_srgb
4312
+ var COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
4313
+ var COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D;
4314
+ var COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E;
4315
+ var COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
4316
+ // etc
4317
+ var COMPRESSED_RGB_ETC1_WEBGL = 0x8D64;
4318
+ var COMPRESSED_R11_EAC = 0x9270;
4319
+ var COMPRESSED_SIGNED_R11_EAC = 0x9271;
4320
+ var COMPRESSED_RG11_EAC = 0x9272;
4321
+ var COMPRESSED_SIGNED_RG11_EAC = 0x9273;
4322
+ var COMPRESSED_RGB8_ETC2 = 0x9274;
4323
+ var COMPRESSED_SRGB8_ETC2 = 0x9275;
4324
+ var COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276;
4325
+ var COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277;
4326
+ var COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
4327
+ var COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279;
4328
+ // pvrtc
4329
+ var COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00;
4330
+ var COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01;
4331
+ var COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02;
4332
+ var COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03;
4333
+ // astc
4334
+ var COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
4335
+ var COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1;
4336
+ var COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2;
4337
+ var COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3;
4338
+ var COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4;
4339
+ var COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5;
4340
+ var COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6;
4341
+ var COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7;
4342
+ var COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8;
4343
+ var COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9;
4344
+ var COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA;
4345
+ var COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB;
4346
+ var COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC;
4347
+ var COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD;
4348
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0;
4349
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1;
4350
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2;
4351
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3;
4352
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4;
4353
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5;
4354
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6;
4355
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7;
4356
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8;
4357
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9;
4358
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA;
4359
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB;
4360
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC;
4361
+ var COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD;
4362
+ // bptc
4363
+ var COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8E8C;
4364
+ var COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = 0x8E8D;
4365
+ var COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT = 0x8E8E;
4366
+ var COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT = 0x8E8F;
4367
+ // rgtc
4368
+ var COMPRESSED_RED_RGTC1_EXT = 0x8DBB;
4369
+ var COMPRESSED_SIGNED_RED_RGTC1_EXT = 0x8DBC;
4370
+ var COMPRESSED_RED_GREEN_RGTC2_EXT = 0x8DBD;
4371
+ var COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT = 0x8DBE;
4303
4372
  var formatInfo = {};
4304
4373
  {
4305
4374
  // NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle
@@ -4352,13 +4421,22 @@ var formatInfo = {};
4352
4421
  };
4353
4422
  }
4354
4423
 
4424
+ /**
4425
+ * @typedef {Object} BlockInfo
4426
+ * @property {number} bytes number of bytes in the block
4427
+ * @property {number} width width of the block
4428
+ * @property {number} height height of the block
4429
+ * @private
4430
+ */
4431
+
4355
4432
  /**
4356
4433
  * @typedef {Object} TextureFormatDetails
4357
4434
  * @property {number} textureFormat format to pass texImage2D and similar functions.
4358
4435
  * @property {boolean} colorRenderable true if you can render to this format of texture.
4359
4436
  * @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
4360
4437
  * @property {number[]} type Array of possible types you can pass to texImage2D and similar function
4361
- * @property {Object.<number,number>} bytesPerElementMap A map of types to bytes per element
4438
+ * @property {Object.<number,number>} [bytesPerElementMap] A map of types to bytes per element
4439
+ * @property {BlockInfo} [block] block size, only for compressed textures
4362
4440
  * @private
4363
4441
  */
4364
4442
 
@@ -4799,9 +4877,514 @@ function getTextureInternalFormatInfo(internalFormat) {
4799
4877
  info.bytesPerElementMap[type] = bytesPerElement;
4800
4878
  });
4801
4879
  });
4880
+ var block8_4_4 = {
4881
+ bytes: 8,
4882
+ width: 4,
4883
+ height: 4
4884
+ };
4885
+ var block16_4_4 = {
4886
+ bytes: 16,
4887
+ width: 4,
4888
+ height: 4
4889
+ };
4890
+
4891
+ // compressed texture formats
4892
+ // s3tc:https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
4893
+ t[COMPRESSED_RGB_S3TC_DXT1_EXT] = {
4894
+ textureFormat: COMPRESSED_RGB_S3TC_DXT1_EXT,
4895
+ colorRenderable: false,
4896
+ textureFilterable: true,
4897
+ block: block8_4_4
4898
+ };
4899
+ t[COMPRESSED_RGBA_S3TC_DXT1_EXT] = {
4900
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT1_EXT,
4901
+ colorRenderable: false,
4902
+ textureFilterable: true,
4903
+ block: block8_4_4
4904
+ };
4905
+ t[COMPRESSED_RGBA_S3TC_DXT3_EXT] = {
4906
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT3_EXT,
4907
+ colorRenderable: false,
4908
+ textureFilterable: true,
4909
+ block: block16_4_4
4910
+ };
4911
+ t[COMPRESSED_RGBA_S3TC_DXT5_EXT] = {
4912
+ textureFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT,
4913
+ colorRenderable: false,
4914
+ textureFilterable: true,
4915
+ block: block16_4_4
4916
+ };
4917
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
4918
+ t[COMPRESSED_SRGB_S3TC_DXT1_EXT] = {
4919
+ textureFormat: COMPRESSED_SRGB_S3TC_DXT1_EXT,
4920
+ colorRenderable: false,
4921
+ textureFilterable: true,
4922
+ block: block8_4_4
4923
+ };
4924
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = {
4925
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
4926
+ colorRenderable: false,
4927
+ textureFilterable: true,
4928
+ block: block8_4_4
4929
+ };
4930
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = {
4931
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
4932
+ colorRenderable: false,
4933
+ textureFilterable: true,
4934
+ block: block16_4_4
4935
+ };
4936
+ t[COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = {
4937
+ textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
4938
+ colorRenderable: false,
4939
+ textureFilterable: true,
4940
+ block: block16_4_4
4941
+ };
4942
+ // https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
4943
+ t[COMPRESSED_RGB_ETC1_WEBGL] = {
4944
+ textureFormat: COMPRESSED_RGB_ETC1_WEBGL,
4945
+ colorRenderable: false,
4946
+ textureFilterable: true,
4947
+ block: block8_4_4
4948
+ };
4949
+ t[COMPRESSED_R11_EAC] = {
4950
+ textureFormat: COMPRESSED_R11_EAC,
4951
+ colorRenderable: false,
4952
+ textureFilterable: true,
4953
+ block: block8_4_4
4954
+ };
4955
+ t[COMPRESSED_SIGNED_R11_EAC] = {
4956
+ textureFormat: COMPRESSED_SIGNED_R11_EAC,
4957
+ colorRenderable: false,
4958
+ textureFilterable: true,
4959
+ block: block8_4_4
4960
+ };
4961
+ t[COMPRESSED_RG11_EAC] = {
4962
+ textureFormat: COMPRESSED_RG11_EAC,
4963
+ colorRenderable: false,
4964
+ textureFilterable: true,
4965
+ block: block16_4_4
4966
+ };
4967
+ t[COMPRESSED_SIGNED_RG11_EAC] = {
4968
+ textureFormat: COMPRESSED_SIGNED_RG11_EAC,
4969
+ colorRenderable: false,
4970
+ textureFilterable: true,
4971
+ block: block16_4_4
4972
+ };
4973
+ t[COMPRESSED_RGB8_ETC2] = {
4974
+ textureFormat: COMPRESSED_RGB8_ETC2,
4975
+ colorRenderable: false,
4976
+ textureFilterable: true,
4977
+ block: block8_4_4
4978
+ };
4979
+ t[COMPRESSED_SRGB8_ETC2] = {
4980
+ textureFormat: COMPRESSED_SRGB8_ETC2,
4981
+ colorRenderable: false,
4982
+ textureFilterable: true,
4983
+ block: block8_4_4
4984
+ };
4985
+ t[COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = {
4986
+ textureFormat: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
4987
+ colorRenderable: false,
4988
+ textureFilterable: true,
4989
+ block: block8_4_4
4990
+ };
4991
+ t[COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = {
4992
+ textureFormat: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
4993
+ colorRenderable: false,
4994
+ textureFilterable: true,
4995
+ block: block8_4_4
4996
+ };
4997
+ t[COMPRESSED_RGBA8_ETC2_EAC] = {
4998
+ textureFormat: COMPRESSED_RGBA8_ETC2_EAC,
4999
+ colorRenderable: false,
5000
+ textureFilterable: true,
5001
+ block: block16_4_4
5002
+ };
5003
+ t[COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = {
5004
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
5005
+ colorRenderable: false,
5006
+ textureFilterable: true,
5007
+ block: block16_4_4
5008
+ };
5009
+ // https://registry.khronos.org/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
5010
+ t[COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = {
5011
+ textureFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
5012
+ colorRenderable: false,
5013
+ textureFilterable: true,
5014
+ block: {
5015
+ bytes: 32,
5016
+ width: 8,
5017
+ height: 8
5018
+ }
5019
+ };
5020
+ t[COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = {
5021
+ textureFormat: COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
5022
+ colorRenderable: false,
5023
+ textureFilterable: true,
5024
+ block: {
5025
+ bytes: 32,
5026
+ width: 16,
5027
+ height: 8
5028
+ }
5029
+ };
5030
+ t[COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = {
5031
+ textureFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
5032
+ colorRenderable: false,
5033
+ textureFilterable: true,
5034
+ block: {
5035
+ bytes: 32,
5036
+ width: 8,
5037
+ height: 8
5038
+ }
5039
+ };
5040
+ t[COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = {
5041
+ textureFormat: COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,
5042
+ colorRenderable: false,
5043
+ textureFilterable: true,
5044
+ block: {
5045
+ bytes: 32,
5046
+ width: 16,
5047
+ height: 8
5048
+ }
5049
+ };
5050
+ // https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
5051
+ t[COMPRESSED_RGBA_ASTC_4x4_KHR] = {
5052
+ textureFormat: COMPRESSED_RGBA_ASTC_4x4_KHR,
5053
+ colorRenderable: false,
5054
+ textureFilterable: true,
5055
+ block: {
5056
+ bytes: 16,
5057
+ width: 4,
5058
+ height: 4
5059
+ }
5060
+ };
5061
+ t[COMPRESSED_RGBA_ASTC_5x4_KHR] = {
5062
+ textureFormat: COMPRESSED_RGBA_ASTC_5x4_KHR,
5063
+ colorRenderable: false,
5064
+ textureFilterable: true,
5065
+ block: {
5066
+ bytes: 16,
5067
+ width: 5,
5068
+ height: 4
5069
+ }
5070
+ };
5071
+ t[COMPRESSED_RGBA_ASTC_5x5_KHR] = {
5072
+ textureFormat: COMPRESSED_RGBA_ASTC_5x5_KHR,
5073
+ colorRenderable: false,
5074
+ textureFilterable: true,
5075
+ block: {
5076
+ bytes: 16,
5077
+ width: 5,
5078
+ height: 5
5079
+ }
5080
+ };
5081
+ t[COMPRESSED_RGBA_ASTC_6x5_KHR] = {
5082
+ textureFormat: COMPRESSED_RGBA_ASTC_6x5_KHR,
5083
+ colorRenderable: false,
5084
+ textureFilterable: true,
5085
+ block: {
5086
+ bytes: 16,
5087
+ width: 6,
5088
+ height: 5
5089
+ }
5090
+ };
5091
+ t[COMPRESSED_RGBA_ASTC_6x6_KHR] = {
5092
+ textureFormat: COMPRESSED_RGBA_ASTC_6x6_KHR,
5093
+ colorRenderable: false,
5094
+ textureFilterable: true,
5095
+ block: {
5096
+ bytes: 16,
5097
+ width: 6,
5098
+ height: 6
5099
+ }
5100
+ };
5101
+ t[COMPRESSED_RGBA_ASTC_8x5_KHR] = {
5102
+ textureFormat: COMPRESSED_RGBA_ASTC_8x5_KHR,
5103
+ colorRenderable: false,
5104
+ textureFilterable: true,
5105
+ block: {
5106
+ bytes: 16,
5107
+ width: 8,
5108
+ height: 5
5109
+ }
5110
+ };
5111
+ t[COMPRESSED_RGBA_ASTC_8x6_KHR] = {
5112
+ textureFormat: COMPRESSED_RGBA_ASTC_8x6_KHR,
5113
+ colorRenderable: false,
5114
+ textureFilterable: true,
5115
+ block: {
5116
+ bytes: 16,
5117
+ width: 8,
5118
+ height: 6
5119
+ }
5120
+ };
5121
+ t[COMPRESSED_RGBA_ASTC_8x8_KHR] = {
5122
+ textureFormat: COMPRESSED_RGBA_ASTC_8x8_KHR,
5123
+ colorRenderable: false,
5124
+ textureFilterable: true,
5125
+ block: {
5126
+ bytes: 16,
5127
+ width: 8,
5128
+ height: 8
5129
+ }
5130
+ };
5131
+ t[COMPRESSED_RGBA_ASTC_10x5_KHR] = {
5132
+ textureFormat: COMPRESSED_RGBA_ASTC_10x5_KHR,
5133
+ colorRenderable: false,
5134
+ textureFilterable: true,
5135
+ block: {
5136
+ bytes: 16,
5137
+ width: 10,
5138
+ height: 5
5139
+ }
5140
+ };
5141
+ t[COMPRESSED_RGBA_ASTC_10x6_KHR] = {
5142
+ textureFormat: COMPRESSED_RGBA_ASTC_10x6_KHR,
5143
+ colorRenderable: false,
5144
+ textureFilterable: true,
5145
+ block: {
5146
+ bytes: 16,
5147
+ width: 10,
5148
+ height: 6
5149
+ }
5150
+ };
5151
+ t[COMPRESSED_RGBA_ASTC_10x8_KHR] = {
5152
+ textureFormat: COMPRESSED_RGBA_ASTC_10x8_KHR,
5153
+ colorRenderable: false,
5154
+ textureFilterable: true,
5155
+ block: {
5156
+ bytes: 16,
5157
+ width: 10,
5158
+ height: 8
5159
+ }
5160
+ };
5161
+ t[COMPRESSED_RGBA_ASTC_10x10_KHR] = {
5162
+ textureFormat: COMPRESSED_RGBA_ASTC_10x10_KHR,
5163
+ colorRenderable: false,
5164
+ textureFilterable: true,
5165
+ block: {
5166
+ bytes: 16,
5167
+ width: 10,
5168
+ height: 10
5169
+ }
5170
+ };
5171
+ t[COMPRESSED_RGBA_ASTC_12x10_KHR] = {
5172
+ textureFormat: COMPRESSED_RGBA_ASTC_12x10_KHR,
5173
+ colorRenderable: false,
5174
+ textureFilterable: true,
5175
+ block: {
5176
+ bytes: 16,
5177
+ width: 12,
5178
+ height: 10
5179
+ }
5180
+ };
5181
+ t[COMPRESSED_RGBA_ASTC_12x12_KHR] = {
5182
+ textureFormat: COMPRESSED_RGBA_ASTC_12x12_KHR,
5183
+ colorRenderable: false,
5184
+ textureFilterable: true,
5185
+ block: {
5186
+ bytes: 16,
5187
+ width: 12,
5188
+ height: 12
5189
+ }
5190
+ };
5191
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR] = {
5192
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
5193
+ colorRenderable: false,
5194
+ textureFilterable: true,
5195
+ block: {
5196
+ bytes: 16,
5197
+ width: 4,
5198
+ height: 4
5199
+ }
5200
+ };
5201
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR] = {
5202
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
5203
+ colorRenderable: false,
5204
+ textureFilterable: true,
5205
+ block: {
5206
+ bytes: 16,
5207
+ width: 5,
5208
+ height: 4
5209
+ }
5210
+ };
5211
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR] = {
5212
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
5213
+ colorRenderable: false,
5214
+ textureFilterable: true,
5215
+ block: {
5216
+ bytes: 16,
5217
+ width: 5,
5218
+ height: 5
5219
+ }
5220
+ };
5221
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR] = {
5222
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
5223
+ colorRenderable: false,
5224
+ textureFilterable: true,
5225
+ block: {
5226
+ bytes: 16,
5227
+ width: 6,
5228
+ height: 5
5229
+ }
5230
+ };
5231
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR] = {
5232
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
5233
+ colorRenderable: false,
5234
+ textureFilterable: true,
5235
+ block: {
5236
+ bytes: 16,
5237
+ width: 6,
5238
+ height: 6
5239
+ }
5240
+ };
5241
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR] = {
5242
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
5243
+ colorRenderable: false,
5244
+ textureFilterable: true,
5245
+ block: {
5246
+ bytes: 16,
5247
+ width: 8,
5248
+ height: 5
5249
+ }
5250
+ };
5251
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR] = {
5252
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
5253
+ colorRenderable: false,
5254
+ textureFilterable: true,
5255
+ block: {
5256
+ bytes: 16,
5257
+ width: 8,
5258
+ height: 6
5259
+ }
5260
+ };
5261
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR] = {
5262
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
5263
+ colorRenderable: false,
5264
+ textureFilterable: true,
5265
+ block: {
5266
+ bytes: 16,
5267
+ width: 8,
5268
+ height: 8
5269
+ }
5270
+ };
5271
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR] = {
5272
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
5273
+ colorRenderable: false,
5274
+ textureFilterable: true,
5275
+ block: {
5276
+ bytes: 16,
5277
+ width: 10,
5278
+ height: 5
5279
+ }
5280
+ };
5281
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR] = {
5282
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
5283
+ colorRenderable: false,
5284
+ textureFilterable: true,
5285
+ block: {
5286
+ bytes: 16,
5287
+ width: 10,
5288
+ height: 6
5289
+ }
5290
+ };
5291
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR] = {
5292
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
5293
+ colorRenderable: false,
5294
+ textureFilterable: true,
5295
+ block: {
5296
+ bytes: 16,
5297
+ width: 10,
5298
+ height: 8
5299
+ }
5300
+ };
5301
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR] = {
5302
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
5303
+ colorRenderable: false,
5304
+ textureFilterable: true,
5305
+ block: {
5306
+ bytes: 16,
5307
+ width: 10,
5308
+ height: 10
5309
+ }
5310
+ };
5311
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR] = {
5312
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
5313
+ colorRenderable: false,
5314
+ textureFilterable: true,
5315
+ block: {
5316
+ bytes: 16,
5317
+ width: 12,
5318
+ height: 10
5319
+ }
5320
+ };
5321
+ t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR] = {
5322
+ textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
5323
+ colorRenderable: false,
5324
+ textureFilterable: true,
5325
+ block: {
5326
+ bytes: 16,
5327
+ width: 12,
5328
+ height: 12
5329
+ }
5330
+ };
5331
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
5332
+ t[COMPRESSED_RGBA_BPTC_UNORM_EXT] = {
5333
+ textureFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT,
5334
+ colorRenderable: false,
5335
+ textureFilterable: true,
5336
+ block: block16_4_4
5337
+ };
5338
+ t[COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT] = {
5339
+ textureFormat: COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,
5340
+ colorRenderable: false,
5341
+ textureFilterable: true,
5342
+ block: block16_4_4
5343
+ };
5344
+ t[COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT] = {
5345
+ textureFormat: COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,
5346
+ colorRenderable: false,
5347
+ textureFilterable: true,
5348
+ block: block16_4_4
5349
+ };
5350
+ t[COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT] = {
5351
+ textureFormat: COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,
5352
+ colorRenderable: false,
5353
+ textureFilterable: true,
5354
+ block: block16_4_4
5355
+ };
5356
+ // https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
5357
+ t[COMPRESSED_RED_RGTC1_EXT] = {
5358
+ textureFormat: COMPRESSED_RED_RGTC1_EXT,
5359
+ colorRenderable: false,
5360
+ textureFilterable: true,
5361
+ block: block8_4_4
5362
+ };
5363
+ t[COMPRESSED_SIGNED_RED_RGTC1_EXT] = {
5364
+ textureFormat: COMPRESSED_SIGNED_RED_RGTC1_EXT,
5365
+ colorRenderable: false,
5366
+ textureFilterable: true,
5367
+ block: block8_4_4
5368
+ };
5369
+ t[COMPRESSED_RED_GREEN_RGTC2_EXT] = {
5370
+ textureFormat: COMPRESSED_RED_GREEN_RGTC2_EXT,
5371
+ colorRenderable: false,
5372
+ textureFilterable: true,
5373
+ block: block8_4_4
5374
+ };
5375
+ t[COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT] = {
5376
+ textureFormat: COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT,
5377
+ colorRenderable: false,
5378
+ textureFilterable: true,
5379
+ block: block8_4_4
5380
+ };
4802
5381
  s_textureInternalFormatInfo = t;
4803
5382
  }
4804
- return s_textureInternalFormatInfo[internalFormat];
5383
+ var info = s_textureInternalFormatInfo[internalFormat];
5384
+ if (!info) {
5385
+ throw new Error("unknown internal format");
5386
+ }
5387
+ return info;
4805
5388
  }
4806
5389
 
4807
5390
  /**
@@ -4813,12 +5396,9 @@ function getTextureInternalFormatInfo(internalFormat) {
4813
5396
  */
4814
5397
  function getBytesPerElementForInternalFormat(internalFormat, type) {
4815
5398
  var info = getTextureInternalFormatInfo(internalFormat);
4816
- if (!info) {
4817
- throw "unknown internal format";
4818
- }
4819
5399
  var bytesPerElement = info.bytesPerElementMap[type];
4820
5400
  if (bytesPerElement === undefined) {
4821
- throw "unknown internal format";
5401
+ throw new Error("type not supported for internal format");
4822
5402
  }
4823
5403
  return bytesPerElement;
4824
5404
  }
@@ -4841,13 +5421,47 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
4841
5421
  * @memberOf module:twgl/textures
4842
5422
  */
4843
5423
  function getFormatAndTypeForInternalFormat(internalFormat) {
5424
+ var _info$type$, _info$type;
4844
5425
  var info = getTextureInternalFormatInfo(internalFormat);
4845
5426
  if (!info) {
4846
- throw "unknown internal format";
5427
+ throw new Error("unknown internal format");
4847
5428
  }
4848
5429
  return {
4849
5430
  format: info.textureFormat,
4850
- type: info.type[0]
5431
+ type: (_info$type$ = (_info$type = info.type) === null || _info$type === void 0 ? void 0 : _info$type[0]) !== null && _info$type$ !== void 0 ? _info$type$ : UNSIGNED_BYTE
5432
+ };
5433
+ }
5434
+
5435
+ /**
5436
+ * @param {number} internalFormat The internal format
5437
+ * @returns if the internalFormat is a compressed format
5438
+ * @private
5439
+ */
5440
+ function isCompressedInternalFormat(internalFormat) {
5441
+ var info = getTextureInternalFormatInfo(internalFormat);
5442
+ return !!info.block;
5443
+ }
5444
+
5445
+ /**
5446
+ * Gets the width, height, and bytes per block for the given internal format
5447
+ * @param {number} internalFormat
5448
+ * @param {number} type
5449
+ * @private
5450
+ */
5451
+ function getBlockInfoForInternalFormat(internalFormat, type) {
5452
+ var info = getTextureInternalFormatInfo(internalFormat);
5453
+ if (info.block) {
5454
+ return {
5455
+ blockWidth: info.block.width,
5456
+ blockHeight: info.block.height,
5457
+ bytesPerBlock: info.block.bytes
5458
+ };
5459
+ }
5460
+ var bytesPerBlock = getBytesPerElementForInternalFormat(internalFormat, type);
5461
+ return {
5462
+ blockWidth: 1,
5463
+ blockHeight: 1,
5464
+ bytesPerBlock: bytesPerBlock
4851
5465
  };
4852
5466
  }
4853
5467
 
@@ -4877,9 +5491,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
4877
5491
  return isPowerOf2(width) && isPowerOf2(height);
4878
5492
  }
4879
5493
  var info = getTextureInternalFormatInfo(internalFormat);
4880
- if (!info) {
4881
- throw "unknown internal format";
4882
- }
4883
5494
  return info.colorRenderable && info.textureFilterable;
4884
5495
  }
4885
5496
 
@@ -4891,9 +5502,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
4891
5502
  */
4892
5503
  function canFilter(internalFormat) {
4893
5504
  var info = getTextureInternalFormatInfo(internalFormat);
4894
- if (!info) {
4895
- throw "unknown internal format";
4896
- }
4897
5505
  return info.textureFilterable;
4898
5506
  }
4899
5507
 
@@ -4905,9 +5513,6 @@ function canFilter(internalFormat) {
4905
5513
  */
4906
5514
  function getNumComponentsForFormat(format) {
4907
5515
  var info = formatInfo[format];
4908
- if (!info) {
4909
- throw "unknown format: " + format;
4910
- }
4911
5516
  return info.numColorComponents;
4912
5517
  }
4913
5518
 
@@ -4925,7 +5530,7 @@ function getTextureTypeForArrayType(gl, src, defaultType) {
4925
5530
  }
4926
5531
  function guessDimensions(gl, target, width, height, numElements) {
4927
5532
  if (numElements % 1 !== 0) {
4928
- throw "can't guess dimensions";
5533
+ throw new Error("can't guess dimensions");
4929
5534
  }
4930
5535
  if (!width && !height) {
4931
5536
  var size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP ? 6 : 1));
@@ -4939,12 +5544,12 @@ function guessDimensions(gl, target, width, height, numElements) {
4939
5544
  } else if (!height) {
4940
5545
  height = numElements / width;
4941
5546
  if (height % 1) {
4942
- throw "can't guess dimensions";
5547
+ throw new Error("can't guess dimensions");
4943
5548
  }
4944
5549
  } else if (!width) {
4945
5550
  width = numElements / height;
4946
5551
  if (width % 1) {
4947
- throw "can't guess dimensions";
5552
+ throw new Error("can't guess dimensions");
4948
5553
  }
4949
5554
  }
4950
5555
  return {
@@ -4997,7 +5602,7 @@ function setDefaults(newDefaults) {
4997
5602
  * @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
4998
5603
  * @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
4999
5604
  * @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
5000
- * @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` .
5605
+ * @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` .
5001
5606
  * @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
5002
5607
  * or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
5003
5608
  * @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
@@ -5056,15 +5661,24 @@ function setDefaults(newDefaults) {
5056
5661
  * If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
5057
5662
  * `HTMLCanvasElement`, `HTMLVideoElement`.
5058
5663
  *
5059
- * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture. If `width` or `height` is
5060
- * not specified it is guessed as follows. First the number of elements is computed by `src.length / numComponents`
5061
- * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
5062
- * by 6. Then
5664
+ * If `number[]` or `ArrayBufferView` it's assumed to be data for a texture.
5063
5665
  *
5064
- * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
5065
- * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
5666
+ * * If `width` or `height` is not specified it is guessed as follows.
5066
5667
  *
5067
- * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
5668
+ * First the number of elements is computed by `src.length / numComponents`
5669
+ * where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
5670
+ * by 6. Then
5671
+ *
5672
+ * * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
5673
+ * are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
5674
+ *
5675
+ * * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
5676
+ *
5677
+ * * If both `width` and `height` is specified, then, the size of mip levels from `level` will be computed
5678
+ * and data for consecutive mip levels will be uploaded until the data runs out.
5679
+ *
5680
+ * In other words: `{ format: g.RGBA, width: 4, height: 4, src: Uint8Array((4 * 4 + 2 * 2 + 1) * 4) }`
5681
+ * uploads 3 mip levels (4x4, 2x2, 1x1) because src is more than the data for the first mip level.
5068
5682
  *
5069
5683
  * If `number[]` will be converted to `type`.
5070
5684
  *
@@ -5315,27 +5929,48 @@ function make1Pixel(color) {
5315
5929
  return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
5316
5930
  }
5317
5931
 
5932
+ /**
5933
+ * @typedef {Object} SetTextureFilteringInternalOptions
5934
+ * @property {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
5935
+ * This is often the same options you passed in when you created the texture.
5936
+ * @property {number} [width] width of texture
5937
+ * @property {number} [height] height of texture
5938
+ * @property {number} [internalFormat] The internalFormat parameter from texImage2D etc..
5939
+ * @property {number} [lastMipLevelUploaded] The last mip level manually uploaded
5940
+ * @private
5941
+ */
5942
+
5318
5943
  /**
5319
5944
  * Sets filtering or generates mips for texture based on width or height
5320
5945
  * If width or height is not passed in uses `options.width` and//or `options.height`
5321
5946
  *
5322
5947
  * @param {WebGLRenderingContext} gl the WebGLRenderingContext
5323
5948
  * @param {WebGLTexture} tex the WebGLTexture to set parameters for
5324
- * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
5325
- * This is often the same options you passed in when you created the texture.
5326
- * @param {number} [width] width of texture
5327
- * @param {number} [height] height of texture
5328
- * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
5329
- * @memberOf module:twgl/textures
5949
+ * @param {SetTextureFilteringInternalOptions} p
5950
+ * @private
5330
5951
  */
5331
- function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
5952
+ function setTextureFilteringForSizeInternal(gl, tex, _ref2) {
5953
+ var options = _ref2.options,
5954
+ width = _ref2.width,
5955
+ height = _ref2.height,
5956
+ internalFormat = _ref2.internalFormat,
5957
+ lastMipLevelUploaded = _ref2.lastMipLevelUploaded;
5332
5958
  options = options || defaults.textureOptions;
5333
5959
  internalFormat = internalFormat || RGBA;
5334
5960
  var target = options.target || TEXTURE_2D;
5335
5961
  width = width || options.width;
5336
5962
  height = height || options.height;
5337
5963
  gl.bindTexture(target, tex);
5338
- if (canGenerateMipmap(gl, width, height, internalFormat)) {
5964
+ if (lastMipLevelUploaded > 1) {
5965
+ var lastLevelWidth = Math.max(1, width >> lastMipLevelUploaded);
5966
+ var lastLevelHeight = Math.max(1, height >> lastMipLevelUploaded);
5967
+ // Note: This is a guess. The user can set maxLod etc...
5968
+ var canUseMips = lastLevelWidth === 1 && lastLevelHeight === 1;
5969
+ var magFiltering = canFilter(internalFormat) ? LINEAR : NEAREST;
5970
+ var minFiltering = canFilter(internalFormat) ? canUseMips ? NEAREST_MIPMAP_LINEAR : LINEAR : NEAREST;
5971
+ gl.texParameteri(target, TEXTURE_MAG_FILTER, magFiltering);
5972
+ gl.texParameteri(target, TEXTURE_MIN_FILTER, minFiltering);
5973
+ } else if (canGenerateMipmap(gl, width, height, internalFormat)) {
5339
5974
  gl.generateMipmap(target);
5340
5975
  } else {
5341
5976
  var filtering = canFilter(internalFormat) ? LINEAR : NEAREST;
@@ -5345,6 +5980,28 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
5345
5980
  gl.texParameteri(target, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
5346
5981
  }
5347
5982
  }
5983
+
5984
+ /**
5985
+ * Sets filtering or generates mips for texture based on width or height
5986
+ * If width or height is not passed in uses `options.width` and//or `options.height`
5987
+ *
5988
+ * @param {WebGLRenderingContext} gl the WebGLRenderingContext
5989
+ * @param {WebGLTexture} tex the WebGLTexture to set parameters for
5990
+ * @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
5991
+ * This is often the same options you passed in when you created the texture.
5992
+ * @param {number} [width] width of texture
5993
+ * @param {number} [height] height of texture
5994
+ * @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
5995
+ * @memberOf module:twgl/textures
5996
+ */
5997
+ function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
5998
+ setTextureFilteringForSizeInternal(gl, tex, {
5999
+ options: options,
6000
+ width: width,
6001
+ height: height,
6002
+ internalFormat: internalFormat
6003
+ });
6004
+ }
5348
6005
  function shouldAutomaticallySetTextureFilteringForSize(options) {
5349
6006
  return options.auto === true || options.auto === undefined && options.level === undefined;
5350
6007
  }
@@ -5444,7 +6101,7 @@ function setTextureFromElement(gl, tex, element, options) {
5444
6101
  size = imgWidth / 2;
5445
6102
  slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
5446
6103
  } else {
5447
- throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
6104
+ throw new Error("can't figure out cube map from element: ".concat(element.src ? element.src : element.nodeName));
5448
6105
  }
5449
6106
  var ctx = getShared2DContext();
5450
6107
  if (ctx) {
@@ -5497,7 +6154,7 @@ function setTextureFromElement(gl, tex, element, options) {
5497
6154
  var largest = Math.max(element.width, element.height);
5498
6155
  var depth = largest / smallest;
5499
6156
  if (depth % 1 !== 0) {
5500
- throw "can not compute 3D dimensions of element";
6157
+ throw new Error("can not compute 3D dimensions of element");
5501
6158
  }
5502
6159
  var xMult = element.width === largest ? 1 : 0;
5503
6160
  var yMult = element.height === largest ? 1 : 0;
@@ -5779,7 +6436,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
5779
6436
  callback = callback || noop;
5780
6437
  var urls = options.src;
5781
6438
  if (urls.length !== 6) {
5782
- throw "there must be 6 urls for a cubemap";
6439
+ throw new Error("there must be 6 urls for a cubemap");
5783
6440
  }
5784
6441
  var level = options.level || 0;
5785
6442
  var internalFormat = options.internalFormat || options.format || RGBA;
@@ -5788,7 +6445,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
5788
6445
  var type = options.type || UNSIGNED_BYTE;
5789
6446
  var target = options.target || TEXTURE_2D;
5790
6447
  if (target !== TEXTURE_CUBE_MAP) {
5791
- throw "target must be TEXTURE_CUBE_MAP";
6448
+ throw new Error("target must be TEXTURE_CUBE_MAP");
5792
6449
  }
5793
6450
  setTextureTo1PixelColor(gl, tex, options);
5794
6451
  // Because it's async we need to copy the options.
@@ -5866,7 +6523,7 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
5866
6523
  var type = options.type || UNSIGNED_BYTE;
5867
6524
  var target = options.target || TEXTURE_2D_ARRAY;
5868
6525
  if (target !== TEXTURE_3D && target !== TEXTURE_2D_ARRAY) {
5869
- throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
6526
+ throw new Error("target must be TEXTURE_3D or TEXTURE_2D_ARRAY");
5870
6527
  }
5871
6528
  setTextureTo1PixelColor(gl, tex, options);
5872
6529
  // Because it's async we need to copy the options.
@@ -5945,9 +6602,6 @@ function setTextureFromArray(gl, tex, src, options) {
5945
6602
  options = options || defaults.textureOptions;
5946
6603
  var target = options.target || TEXTURE_2D;
5947
6604
  gl.bindTexture(target, tex);
5948
- var width = options.width;
5949
- var height = options.height;
5950
- var depth = options.depth;
5951
6605
  var level = options.level || 0;
5952
6606
  var internalFormat = options.internalFormat || options.format || RGBA;
5953
6607
  var formatType = getFormatAndTypeForInternalFormat(internalFormat);
@@ -5959,61 +6613,123 @@ function setTextureFromArray(gl, tex, src, options) {
5959
6613
  } else if (src instanceof Uint8ClampedArray) {
5960
6614
  src = new Uint8Array(src.buffer);
5961
6615
  }
5962
- var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
5963
- var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
5964
- if (numElements % 1) {
5965
- throw "length wrong size for format: " + utils.glEnumToString(gl, format);
5966
- }
5967
- var dimensions;
5968
- if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
5969
- if (!width && !height && !depth) {
5970
- var size = Math.cbrt(numElements);
5971
- if (size % 1 !== 0) {
5972
- throw "can't guess cube size of array of numElements: " + numElements;
5973
- }
5974
- width = size;
5975
- height = size;
5976
- depth = size;
5977
- } else if (width && (!height || !depth)) {
5978
- dimensions = guessDimensions(gl, target, height, depth, numElements / width);
5979
- height = dimensions.width;
5980
- depth = dimensions.height;
5981
- } else if (height && (!width || !depth)) {
5982
- dimensions = guessDimensions(gl, target, width, depth, numElements / height);
5983
- width = dimensions.width;
5984
- depth = dimensions.height;
5985
- } else {
5986
- dimensions = guessDimensions(gl, target, width, height, numElements / depth);
5987
- width = dimensions.width;
5988
- height = dimensions.height;
5989
- }
5990
- } else {
5991
- dimensions = guessDimensions(gl, target, width, height, numElements);
5992
- width = dimensions.width;
5993
- height = dimensions.height;
5994
- }
6616
+ var _getTextureSize = getTextureSize(target, src, options, internalFormat, format, type),
6617
+ width = _getTextureSize.width,
6618
+ height = _getTextureSize.height,
6619
+ depth = _getTextureSize.depth;
6620
+ var compressed = isCompressedInternalFormat(internalFormat);
5995
6621
  setSkipStateToDefault(gl);
5996
6622
  gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
6623
+ var mipLevelOffset = 0; // this is in addition to level
5997
6624
  scopedSetPackState(gl, options, function () {
5998
- if (target === TEXTURE_CUBE_MAP) {
5999
- var elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
6000
- var faceSize = numElements / 6 * elementsPerElement;
6001
- getCubeFacesWithNdx(gl, options).forEach(function (f) {
6002
- var offset = faceSize * f.ndx;
6003
- var data = src.subarray(offset, offset + faceSize);
6004
- gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
6005
- });
6006
- } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6007
- gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
6008
- } else {
6009
- gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
6625
+ var mipLevelByteOffset = 0;
6626
+ var _getBlockInfoForInter = getBlockInfoForInternalFormat(internalFormat, type),
6627
+ blockWidth = _getBlockInfoForInter.blockWidth,
6628
+ blockHeight = _getBlockInfoForInter.blockHeight,
6629
+ bytesPerBlock = _getBlockInfoForInter.bytesPerBlock;
6630
+ var _loop = function _loop() {
6631
+ var mipWidth = Math.max(1, width >> mipLevelOffset);
6632
+ var mipHeight = Math.max(1, height >> mipLevelOffset);
6633
+ var mipDepth = target === TEXTURE_2D ? Math.max(1, depth >> mipLevelOffset) : depth;
6634
+ var blocksAcross = Math.ceil(mipWidth / blockWidth);
6635
+ var blocksDown = Math.ceil(mipHeight / blockHeight);
6636
+ var numFaces = target === TEXTURE_CUBE_MAP ? 6 : 1;
6637
+ var bytesPerMipLevel = blocksAcross * blocksDown * bytesPerBlock * mipDepth * numFaces;
6638
+ if (mipLevelByteOffset + bytesPerMipLevel > src.byteLength) {
6639
+ throw new Error('src size does not match number of mip levels');
6640
+ }
6641
+ var mipSource = src.subarray(mipLevelByteOffset / src.BYTES_PER_ELEMENT, (mipLevelByteOffset + bytesPerMipLevel) / src.BYTES_PER_ELEMENT);
6642
+ var mipLevel = level + mipLevelOffset;
6643
+ if (target === TEXTURE_CUBE_MAP) {
6644
+ var faceSize = mipSource.length / 6;
6645
+ getCubeFacesWithNdx(gl, options).forEach(function (f) {
6646
+ var offset = faceSize * f.ndx;
6647
+ var data = mipSource.subarray(offset, offset + faceSize);
6648
+ if (compressed) {
6649
+ gl.compressedTexImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, data);
6650
+ } else {
6651
+ gl.texImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, data);
6652
+ }
6653
+ });
6654
+ } else if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6655
+ gl.texImage3D(target, mipLevel, internalFormat, mipWidth, mipHeight, mipDepth, 0, format, type, mipSource);
6656
+ } else {
6657
+ if (compressed) {
6658
+ gl.compressedTexImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, mipSource);
6659
+ } else {
6660
+ gl.texImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, mipSource);
6661
+ }
6662
+ }
6663
+ ++mipLevelOffset;
6664
+ mipLevelByteOffset += bytesPerMipLevel;
6665
+ if (mipWidth === 1 && mipHeight === 1 && mipDepth === 1 && mipLevelByteOffset !== src.byteLength) {
6666
+ throw new Error('src size has more data than can fit in mip levels');
6667
+ }
6668
+ };
6669
+ while (mipLevelByteOffset < src.byteLength) {
6670
+ _loop();
6010
6671
  }
6011
6672
  });
6012
6673
  return {
6013
6674
  width: width,
6014
6675
  height: height,
6015
6676
  depth: depth,
6016
- type: type
6677
+ type: type,
6678
+ lastMipLevelUploaded: level + mipLevelOffset - 1
6679
+ };
6680
+ }
6681
+ function getTextureSize(target, src, options, internalFormat, format, type) {
6682
+ var width = options.width;
6683
+ var height = options.height;
6684
+ var depth = options.depth;
6685
+ var compressed = isCompressedInternalFormat(internalFormat);
6686
+ if (compressed) {
6687
+ if (!width || !height) {
6688
+ throw new Error("compressed texture needs to set width and height!");
6689
+ }
6690
+ depth = depth || 1;
6691
+ } else {
6692
+ var bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
6693
+ var numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
6694
+ if (numElements % 1) {
6695
+ throw new Error("length wrong size for format: ".concat(utils.glEnumToString(gl, format)));
6696
+ }
6697
+ if (compressed && (!width || !height)) {
6698
+ throw new Error("compressed texture needs to set width and height!");
6699
+ }
6700
+ var dimensions;
6701
+ if (target === TEXTURE_3D || target === TEXTURE_2D_ARRAY) {
6702
+ if (!width && !height && !depth) {
6703
+ var size = Math.cbrt(numElements);
6704
+ if (size % 1 !== 0) {
6705
+ throw new Error("can't guess cube size of array of numElements: ".concat(numElements));
6706
+ }
6707
+ width = size;
6708
+ height = size;
6709
+ depth = size;
6710
+ } else if (width && (!height || !depth)) {
6711
+ dimensions = guessDimensions(gl, target, height, depth, numElements / width);
6712
+ height = dimensions.width;
6713
+ depth = dimensions.height;
6714
+ } else if (height && (!width || !depth)) {
6715
+ dimensions = guessDimensions(gl, target, width, depth, numElements / height);
6716
+ width = dimensions.width;
6717
+ depth = dimensions.height;
6718
+ } else {
6719
+ dimensions = guessDimensions(gl, target, width, height, numElements / depth);
6720
+ width = dimensions.width;
6721
+ height = dimensions.height;
6722
+ }
6723
+ } else {
6724
+ dimensions = guessDimensions(gl, target, width, height, numElements);
6725
+ width = dimensions.width;
6726
+ height = dimensions.height;
6727
+ }
6728
+ }
6729
+ return {
6730
+ width: width,
6731
+ height: height,
6732
+ depth: depth
6017
6733
  };
6018
6734
  }
6019
6735
 
@@ -6086,6 +6802,7 @@ function createTexture(gl, options, callback) {
6086
6802
  var target = options.target || TEXTURE_2D;
6087
6803
  var width = options.width || 1;
6088
6804
  var height = options.height || 1;
6805
+ var lastMipLevelUploaded = 0;
6089
6806
  var internalFormat = options.internalFormat || RGBA;
6090
6807
  gl.bindTexture(target, tex);
6091
6808
  if (target === TEXTURE_CUBE_MAP) {
@@ -6104,6 +6821,7 @@ function createTexture(gl, options, callback) {
6104
6821
  var dimensions = setTextureFromArray(gl, tex, src, options);
6105
6822
  width = dimensions.width;
6106
6823
  height = dimensions.height;
6824
+ lastMipLevelUploaded = dimensions.lastMipLevelUploaded;
6107
6825
  } else if (Array.isArray(src) && (typeof src[0] === 'string' || isTexImageSource(src[0]))) {
6108
6826
  if (target === TEXTURE_CUBE_MAP) {
6109
6827
  loadCubemapFromUrls(gl, tex, options, callback);
@@ -6120,7 +6838,13 @@ function createTexture(gl, options, callback) {
6120
6838
  setEmptyTexture(gl, tex, options);
6121
6839
  }
6122
6840
  if (shouldAutomaticallySetTextureFilteringForSize(options)) {
6123
- setTextureFilteringForSize(gl, tex, options, width, height, internalFormat);
6841
+ setTextureFilteringForSizeInternal(gl, tex, {
6842
+ options: options,
6843
+ width: width,
6844
+ height: height,
6845
+ internalFormat: internalFormat,
6846
+ lastMipLevelUploaded: lastMipLevelUploaded
6847
+ });
6124
6848
  }
6125
6849
  setTextureParameters(gl, tex, options);
6126
6850
  return tex;
@@ -6680,7 +7404,7 @@ function addExtensionToContext(gl, extensionName) {
6680
7404
  * list.
6681
7405
  *
6682
7406
  */
6683
- var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_float', 'EXT_color_buffer_half_float', 'EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2', 'EXT_frag_depth', 'EXT_sRGB', 'EXT_shader_texture_lod', 'EXT_texture_filter_anisotropic', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_atc', 'WEBGL_compressed_texture_etc1', 'WEBGL_compressed_texture_pvrtc', 'WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_depth_texture', 'WEBGL_draw_buffers'];
7407
+ var supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_float', 'EXT_color_buffer_half_float', 'EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2', 'EXT_frag_depth', 'EXT_sRGB', 'EXT_shader_texture_lod', 'EXT_texture_compression_bptc', 'EXT_texture_compression_rgtc', 'EXT_texture_filter_anisotropic', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_atc', 'WEBGL_compressed_texture_etc1', 'WEBGL_compressed_texture_etc', 'WEBGL_compressed_texture_pvrtc', 'WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_depth_texture', 'WEBGL_draw_buffers'];
6684
7408
 
6685
7409
  /**
6686
7410
  * Attempts to enable all of the following extensions