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.
- package/README.md +1 -1
- package/dist/{6.x → 7.x}/twgl-full.d.ts +15 -6
- package/dist/{6.x → 7.x}/twgl-full.js +817 -93
- package/dist/{6.x → 7.x}/twgl-full.module.js +379 -94
- package/dist/{6.x → 7.x}/twgl.d.ts +15 -6
- package/dist/{6.x → 7.x}/twgl.js +817 -93
- package/package.json +9 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @license twgl.js
|
|
1
|
+
/* @license twgl.js 7.0.0 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
|
|
2
2
|
Available via the MIT license.
|
|
3
3
|
see: http://github.com/greggman/twgl.js for details */
|
|
4
4
|
/*
|
|
@@ -5025,6 +5025,24 @@ var utils = /*#__PURE__*/Object.freeze({
|
|
|
5025
5025
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
5026
5026
|
* DEALINGS IN THE SOFTWARE.
|
|
5027
5027
|
*/
|
|
5028
|
+
|
|
5029
|
+
/**
|
|
5030
|
+
* Low level texture related functions
|
|
5031
|
+
*
|
|
5032
|
+
* You should generally not need to use these functions. They are provided
|
|
5033
|
+
* for those cases where you're doing something out of the ordinary
|
|
5034
|
+
* and you need lower level access.
|
|
5035
|
+
*
|
|
5036
|
+
* For backward compatibility they are available at both `twgl.textures` and `twgl`
|
|
5037
|
+
* itself
|
|
5038
|
+
*
|
|
5039
|
+
* See {@link module:twgl} for core functions
|
|
5040
|
+
*
|
|
5041
|
+
* @module twgl/textures
|
|
5042
|
+
*/
|
|
5043
|
+
|
|
5044
|
+
// make sure we don't see a global gl
|
|
5045
|
+
const gl = undefined; /* eslint-disable-line */
|
|
5028
5046
|
const defaults$1 = {
|
|
5029
5047
|
textureColor: new Uint8Array([128, 192, 255, 255]),
|
|
5030
5048
|
textureOptions: {},
|
|
@@ -5073,6 +5091,7 @@ const CLAMP_TO_EDGE$1 = 0x812f;
|
|
|
5073
5091
|
/* TextureMagFilter */
|
|
5074
5092
|
const NEAREST = 0x2600;
|
|
5075
5093
|
const LINEAR$1 = 0x2601;
|
|
5094
|
+
const NEAREST_MIPMAP_LINEAR = 0x2702;
|
|
5076
5095
|
|
|
5077
5096
|
/* TextureMinFilter */
|
|
5078
5097
|
// const NEAREST_MIPMAP_NEAREST = 0x2700;
|
|
@@ -5200,6 +5219,74 @@ const RED_INTEGER = 0x8D94;
|
|
|
5200
5219
|
const RGB_INTEGER = 0x8D98;
|
|
5201
5220
|
const RGBA_INTEGER = 0x8D99;
|
|
5202
5221
|
|
|
5222
|
+
/* Compressed Texture Formats */
|
|
5223
|
+
// s3tc
|
|
5224
|
+
const COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0;
|
|
5225
|
+
const COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1;
|
|
5226
|
+
const COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2;
|
|
5227
|
+
const COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3;
|
|
5228
|
+
// s3tc_srgb
|
|
5229
|
+
const COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C;
|
|
5230
|
+
const COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D;
|
|
5231
|
+
const COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E;
|
|
5232
|
+
const COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F;
|
|
5233
|
+
// etc
|
|
5234
|
+
const COMPRESSED_RGB_ETC1_WEBGL = 0x8D64;
|
|
5235
|
+
const COMPRESSED_R11_EAC = 0x9270;
|
|
5236
|
+
const COMPRESSED_SIGNED_R11_EAC = 0x9271;
|
|
5237
|
+
const COMPRESSED_RG11_EAC = 0x9272;
|
|
5238
|
+
const COMPRESSED_SIGNED_RG11_EAC = 0x9273;
|
|
5239
|
+
const COMPRESSED_RGB8_ETC2 = 0x9274;
|
|
5240
|
+
const COMPRESSED_SRGB8_ETC2 = 0x9275;
|
|
5241
|
+
const COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276;
|
|
5242
|
+
const COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277;
|
|
5243
|
+
const COMPRESSED_RGBA8_ETC2_EAC = 0x9278;
|
|
5244
|
+
const COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279;
|
|
5245
|
+
// pvrtc
|
|
5246
|
+
const COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00;
|
|
5247
|
+
const COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01;
|
|
5248
|
+
const COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02;
|
|
5249
|
+
const COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03;
|
|
5250
|
+
// astc
|
|
5251
|
+
const COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0;
|
|
5252
|
+
const COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1;
|
|
5253
|
+
const COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2;
|
|
5254
|
+
const COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3;
|
|
5255
|
+
const COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4;
|
|
5256
|
+
const COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5;
|
|
5257
|
+
const COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6;
|
|
5258
|
+
const COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7;
|
|
5259
|
+
const COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8;
|
|
5260
|
+
const COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9;
|
|
5261
|
+
const COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA;
|
|
5262
|
+
const COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB;
|
|
5263
|
+
const COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC;
|
|
5264
|
+
const COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD;
|
|
5265
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0;
|
|
5266
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1;
|
|
5267
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2;
|
|
5268
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3;
|
|
5269
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4;
|
|
5270
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5;
|
|
5271
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6;
|
|
5272
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7;
|
|
5273
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8;
|
|
5274
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9;
|
|
5275
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA;
|
|
5276
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB;
|
|
5277
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC;
|
|
5278
|
+
const COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD;
|
|
5279
|
+
// bptc
|
|
5280
|
+
const COMPRESSED_RGBA_BPTC_UNORM_EXT = 0x8E8C;
|
|
5281
|
+
const COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT = 0x8E8D;
|
|
5282
|
+
const COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT = 0x8E8E;
|
|
5283
|
+
const COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT = 0x8E8F;
|
|
5284
|
+
// rgtc
|
|
5285
|
+
const COMPRESSED_RED_RGTC1_EXT = 0x8DBB;
|
|
5286
|
+
const COMPRESSED_SIGNED_RED_RGTC1_EXT = 0x8DBC;
|
|
5287
|
+
const COMPRESSED_RED_GREEN_RGTC2_EXT = 0x8DBD;
|
|
5288
|
+
const COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT = 0x8DBE;
|
|
5289
|
+
|
|
5203
5290
|
const formatInfo = {};
|
|
5204
5291
|
{
|
|
5205
5292
|
// NOTE: this is named `numColorComponents` vs `numComponents` so we can let Uglify mangle
|
|
@@ -5222,13 +5309,22 @@ const formatInfo = {};
|
|
|
5222
5309
|
f[DEPTH_STENCIL$1] = { numColorComponents: 2, };
|
|
5223
5310
|
}
|
|
5224
5311
|
|
|
5312
|
+
/**
|
|
5313
|
+
* @typedef {Object} BlockInfo
|
|
5314
|
+
* @property {number} bytes number of bytes in the block
|
|
5315
|
+
* @property {number} width width of the block
|
|
5316
|
+
* @property {number} height height of the block
|
|
5317
|
+
* @private
|
|
5318
|
+
*/
|
|
5319
|
+
|
|
5225
5320
|
/**
|
|
5226
5321
|
* @typedef {Object} TextureFormatDetails
|
|
5227
5322
|
* @property {number} textureFormat format to pass texImage2D and similar functions.
|
|
5228
5323
|
* @property {boolean} colorRenderable true if you can render to this format of texture.
|
|
5229
5324
|
* @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
|
|
5230
5325
|
* @property {number[]} type Array of possible types you can pass to texImage2D and similar function
|
|
5231
|
-
* @property {Object.<number,number>} bytesPerElementMap A map of types to bytes per element
|
|
5326
|
+
* @property {Object.<number,number>} [bytesPerElementMap] A map of types to bytes per element
|
|
5327
|
+
* @property {BlockInfo} [block] block size, only for compressed textures
|
|
5232
5328
|
* @private
|
|
5233
5329
|
*/
|
|
5234
5330
|
|
|
@@ -5310,9 +5406,85 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
5310
5406
|
info.bytesPerElementMap[type] = bytesPerElement;
|
|
5311
5407
|
});
|
|
5312
5408
|
});
|
|
5409
|
+
|
|
5410
|
+
const block8_4_4 = { bytes: 8, width: 4, height: 4 };
|
|
5411
|
+
const block16_4_4 = { bytes: 16, width: 4, height: 4 };
|
|
5412
|
+
|
|
5413
|
+
// compressed texture formats
|
|
5414
|
+
// s3tc:https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc.txt
|
|
5415
|
+
t[COMPRESSED_RGB_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_RGB_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5416
|
+
t[COMPRESSED_RGBA_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5417
|
+
t[COMPRESSED_RGBA_S3TC_DXT3_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT3_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5418
|
+
t[COMPRESSED_RGBA_S3TC_DXT5_EXT] = { textureFormat: COMPRESSED_RGBA_S3TC_DXT5_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5419
|
+
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_s3tc_srgb.txt
|
|
5420
|
+
t[COMPRESSED_SRGB_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_SRGB_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5421
|
+
t[COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5422
|
+
t[COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5423
|
+
t[COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5424
|
+
// https://registry.khronos.org/OpenGL/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
|
|
5425
|
+
t[COMPRESSED_RGB_ETC1_WEBGL] = { textureFormat: COMPRESSED_RGB_ETC1_WEBGL, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5426
|
+
t[COMPRESSED_R11_EAC] = { textureFormat: COMPRESSED_R11_EAC, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5427
|
+
t[COMPRESSED_SIGNED_R11_EAC] = { textureFormat: COMPRESSED_SIGNED_R11_EAC, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5428
|
+
t[COMPRESSED_RG11_EAC] = { textureFormat: COMPRESSED_RG11_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5429
|
+
t[COMPRESSED_SIGNED_RG11_EAC] = { textureFormat: COMPRESSED_SIGNED_RG11_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5430
|
+
t[COMPRESSED_RGB8_ETC2] = { textureFormat: COMPRESSED_RGB8_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5431
|
+
t[COMPRESSED_SRGB8_ETC2] = { textureFormat: COMPRESSED_SRGB8_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5432
|
+
t[COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2] = { textureFormat: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5433
|
+
t[COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2] = { textureFormat: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5434
|
+
t[COMPRESSED_RGBA8_ETC2_EAC] = { textureFormat: COMPRESSED_RGBA8_ETC2_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5435
|
+
t[COMPRESSED_SRGB8_ALPHA8_ETC2_EAC] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5436
|
+
// https://registry.khronos.org/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
|
|
5437
|
+
t[COMPRESSED_RGB_PVRTC_4BPPV1_IMG] = { textureFormat: COMPRESSED_RGB_PVRTC_4BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 8, height: 8, } };
|
|
5438
|
+
t[COMPRESSED_RGB_PVRTC_2BPPV1_IMG] = { textureFormat: COMPRESSED_RGB_PVRTC_2BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 16, height: 8, } };
|
|
5439
|
+
t[COMPRESSED_RGBA_PVRTC_4BPPV1_IMG] = { textureFormat: COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 8, height: 8, } };
|
|
5440
|
+
t[COMPRESSED_RGBA_PVRTC_2BPPV1_IMG] = { textureFormat: COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, colorRenderable: false, textureFilterable: true, block: { bytes: 32, width: 16, height: 8, } };
|
|
5441
|
+
// https://registry.khronos.org/OpenGL/extensions/KHR/KHR_texture_compression_astc_hdr.txt
|
|
5442
|
+
t[COMPRESSED_RGBA_ASTC_4x4_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_4x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 4, height: 4, } };
|
|
5443
|
+
t[COMPRESSED_RGBA_ASTC_5x4_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_5x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 4, } };
|
|
5444
|
+
t[COMPRESSED_RGBA_ASTC_5x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_5x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 5, } };
|
|
5445
|
+
t[COMPRESSED_RGBA_ASTC_6x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_6x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 5, } };
|
|
5446
|
+
t[COMPRESSED_RGBA_ASTC_6x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_6x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 6, } };
|
|
5447
|
+
t[COMPRESSED_RGBA_ASTC_8x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 5, } };
|
|
5448
|
+
t[COMPRESSED_RGBA_ASTC_8x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 6, } };
|
|
5449
|
+
t[COMPRESSED_RGBA_ASTC_8x8_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_8x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 8, } };
|
|
5450
|
+
t[COMPRESSED_RGBA_ASTC_10x5_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 5, } };
|
|
5451
|
+
t[COMPRESSED_RGBA_ASTC_10x6_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 6, } };
|
|
5452
|
+
t[COMPRESSED_RGBA_ASTC_10x8_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 8, } };
|
|
5453
|
+
t[COMPRESSED_RGBA_ASTC_10x10_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_10x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 10, } };
|
|
5454
|
+
t[COMPRESSED_RGBA_ASTC_12x10_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_12x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 10, } };
|
|
5455
|
+
t[COMPRESSED_RGBA_ASTC_12x12_KHR] = { textureFormat: COMPRESSED_RGBA_ASTC_12x12_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 12, } };
|
|
5456
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 4, height: 4, } };
|
|
5457
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 4, } };
|
|
5458
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 5, height: 5, } };
|
|
5459
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 5, } };
|
|
5460
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 6, height: 6, } };
|
|
5461
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 5, } };
|
|
5462
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 6, } };
|
|
5463
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 8, height: 8, } };
|
|
5464
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 5, } };
|
|
5465
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 6, } };
|
|
5466
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 8, } };
|
|
5467
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 10, height: 10, } };
|
|
5468
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 10, } };
|
|
5469
|
+
t[COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR] = { textureFormat: COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, colorRenderable: false, textureFilterable: true, block: { bytes: 16, width: 12, height: 12, } };
|
|
5470
|
+
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_bptc.txt
|
|
5471
|
+
t[COMPRESSED_RGBA_BPTC_UNORM_EXT] = { textureFormat: COMPRESSED_RGBA_BPTC_UNORM_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5472
|
+
t[COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT] = { textureFormat: COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5473
|
+
t[COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT] = { textureFormat: COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5474
|
+
t[COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT] = { textureFormat: COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, colorRenderable: false, textureFilterable: true, block: block16_4_4 };
|
|
5475
|
+
// https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_compression_rgtc.txt
|
|
5476
|
+
t[COMPRESSED_RED_RGTC1_EXT] = { textureFormat: COMPRESSED_RED_RGTC1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5477
|
+
t[COMPRESSED_SIGNED_RED_RGTC1_EXT] = { textureFormat: COMPRESSED_SIGNED_RED_RGTC1_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5478
|
+
t[COMPRESSED_RED_GREEN_RGTC2_EXT] = { textureFormat: COMPRESSED_RED_GREEN_RGTC2_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5479
|
+
t[COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT] = { textureFormat: COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, colorRenderable: false, textureFilterable: true, block: block8_4_4 };
|
|
5480
|
+
|
|
5313
5481
|
s_textureInternalFormatInfo = t;
|
|
5314
5482
|
}
|
|
5315
|
-
|
|
5483
|
+
const info = s_textureInternalFormatInfo[internalFormat];
|
|
5484
|
+
if (!info) {
|
|
5485
|
+
throw new Error("unknown internal format");
|
|
5486
|
+
}
|
|
5487
|
+
return info;
|
|
5316
5488
|
}
|
|
5317
5489
|
|
|
5318
5490
|
/**
|
|
@@ -5324,12 +5496,9 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
5324
5496
|
*/
|
|
5325
5497
|
function getBytesPerElementForInternalFormat(internalFormat, type) {
|
|
5326
5498
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5327
|
-
if (!info) {
|
|
5328
|
-
throw "unknown internal format";
|
|
5329
|
-
}
|
|
5330
5499
|
const bytesPerElement = info.bytesPerElementMap[type];
|
|
5331
5500
|
if (bytesPerElement === undefined) {
|
|
5332
|
-
throw "
|
|
5501
|
+
throw new Error("type not supported for internal format");
|
|
5333
5502
|
}
|
|
5334
5503
|
return bytesPerElement;
|
|
5335
5504
|
}
|
|
@@ -5354,14 +5523,39 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
|
|
|
5354
5523
|
function getFormatAndTypeForInternalFormat(internalFormat) {
|
|
5355
5524
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5356
5525
|
if (!info) {
|
|
5357
|
-
throw "unknown internal format";
|
|
5526
|
+
throw new Error("unknown internal format");
|
|
5358
5527
|
}
|
|
5359
5528
|
return {
|
|
5360
5529
|
format: info.textureFormat,
|
|
5361
|
-
type: info.type[0],
|
|
5530
|
+
type: info.type?.[0] ?? UNSIGNED_BYTE$1,
|
|
5362
5531
|
};
|
|
5363
5532
|
}
|
|
5364
5533
|
|
|
5534
|
+
/**
|
|
5535
|
+
* @param {number} internalFormat The internal format
|
|
5536
|
+
* @returns if the internalFormat is a compressed format
|
|
5537
|
+
* @private
|
|
5538
|
+
*/
|
|
5539
|
+
function isCompressedInternalFormat(internalFormat) {
|
|
5540
|
+
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5541
|
+
return !!info.block;
|
|
5542
|
+
}
|
|
5543
|
+
|
|
5544
|
+
/**
|
|
5545
|
+
* Gets the width, height, and bytes per block for the given internal format
|
|
5546
|
+
* @param {number} internalFormat
|
|
5547
|
+
* @param {number} type
|
|
5548
|
+
* @private
|
|
5549
|
+
*/
|
|
5550
|
+
function getBlockInfoForInternalFormat(internalFormat, type) {
|
|
5551
|
+
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5552
|
+
if (info.block) {
|
|
5553
|
+
return { blockWidth: info.block.width, blockHeight: info.block.height, bytesPerBlock: info.block.bytes };
|
|
5554
|
+
}
|
|
5555
|
+
const bytesPerBlock = getBytesPerElementForInternalFormat(internalFormat, type);
|
|
5556
|
+
return { blockWidth: 1, blockHeight: 1, bytesPerBlock };
|
|
5557
|
+
}
|
|
5558
|
+
|
|
5365
5559
|
/**
|
|
5366
5560
|
* Returns true if value is power of 2
|
|
5367
5561
|
* @param {number} value number to check.
|
|
@@ -5388,9 +5582,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
|
|
|
5388
5582
|
return isPowerOf2(width) && isPowerOf2(height);
|
|
5389
5583
|
}
|
|
5390
5584
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5391
|
-
if (!info) {
|
|
5392
|
-
throw "unknown internal format";
|
|
5393
|
-
}
|
|
5394
5585
|
return info.colorRenderable && info.textureFilterable;
|
|
5395
5586
|
}
|
|
5396
5587
|
|
|
@@ -5402,9 +5593,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
|
|
|
5402
5593
|
*/
|
|
5403
5594
|
function canFilter(internalFormat) {
|
|
5404
5595
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5405
|
-
if (!info) {
|
|
5406
|
-
throw "unknown internal format";
|
|
5407
|
-
}
|
|
5408
5596
|
return info.textureFilterable;
|
|
5409
5597
|
}
|
|
5410
5598
|
|
|
@@ -5416,9 +5604,6 @@ function canFilter(internalFormat) {
|
|
|
5416
5604
|
*/
|
|
5417
5605
|
function getNumComponentsForFormat(format) {
|
|
5418
5606
|
const info = formatInfo[format];
|
|
5419
|
-
if (!info) {
|
|
5420
|
-
throw "unknown format: " + format;
|
|
5421
|
-
}
|
|
5422
5607
|
return info.numColorComponents;
|
|
5423
5608
|
}
|
|
5424
5609
|
|
|
@@ -5437,7 +5622,7 @@ function getTextureTypeForArrayType(gl, src, defaultType) {
|
|
|
5437
5622
|
|
|
5438
5623
|
function guessDimensions(gl, target, width, height, numElements) {
|
|
5439
5624
|
if (numElements % 1 !== 0) {
|
|
5440
|
-
throw "can't guess dimensions";
|
|
5625
|
+
throw new Error("can't guess dimensions");
|
|
5441
5626
|
}
|
|
5442
5627
|
if (!width && !height) {
|
|
5443
5628
|
const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP$1 ? 6 : 1));
|
|
@@ -5451,12 +5636,12 @@ function guessDimensions(gl, target, width, height, numElements) {
|
|
|
5451
5636
|
} else if (!height) {
|
|
5452
5637
|
height = numElements / width;
|
|
5453
5638
|
if (height % 1) {
|
|
5454
|
-
throw "can't guess dimensions";
|
|
5639
|
+
throw new Error("can't guess dimensions");
|
|
5455
5640
|
}
|
|
5456
5641
|
} else if (!width) {
|
|
5457
5642
|
width = numElements / height;
|
|
5458
5643
|
if (width % 1) {
|
|
5459
|
-
throw "can't guess dimensions";
|
|
5644
|
+
throw new Error("can't guess dimensions");
|
|
5460
5645
|
}
|
|
5461
5646
|
}
|
|
5462
5647
|
return {
|
|
@@ -5510,7 +5695,7 @@ function setDefaults$1(newDefaults) {
|
|
|
5510
5695
|
* @property {number} [level] the mip level to affect. Defaults to 0. Note, if set auto will be considered false unless explicitly set to true.
|
|
5511
5696
|
* @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
|
|
5512
5697
|
* @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
|
|
5513
|
-
* @property {number} [depth] the depth of a texture. Only used if src is an array or
|
|
5698
|
+
* @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` .
|
|
5514
5699
|
* @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
|
|
5515
5700
|
* or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
|
|
5516
5701
|
* @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
|
|
@@ -5569,15 +5754,24 @@ function setDefaults$1(newDefaults) {
|
|
|
5569
5754
|
* If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
|
|
5570
5755
|
* `HTMLCanvasElement`, `HTMLVideoElement`.
|
|
5571
5756
|
*
|
|
5572
|
-
* If `number[]` or `ArrayBufferView` it's assumed to be data for a texture.
|
|
5573
|
-
*
|
|
5574
|
-
*
|
|
5575
|
-
* by 6. Then
|
|
5757
|
+
* If `number[]` or `ArrayBufferView` it's assumed to be data for a texture.
|
|
5758
|
+
*
|
|
5759
|
+
* * If `width` or `height` is not specified it is guessed as follows.
|
|
5576
5760
|
*
|
|
5577
|
-
*
|
|
5578
|
-
*
|
|
5761
|
+
* First the number of elements is computed by `src.length / numComponents`
|
|
5762
|
+
* where `numComponents` is derived from `format`. If `target` is `gl.TEXTURE_CUBE_MAP` then `numElements` is divided
|
|
5763
|
+
* by 6. Then
|
|
5579
5764
|
*
|
|
5580
|
-
*
|
|
5765
|
+
* * If neither `width` nor `height` are specified and `sqrt(numElements)` is an integer then width and height
|
|
5766
|
+
* are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
|
|
5767
|
+
*
|
|
5768
|
+
* * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
|
|
5769
|
+
*
|
|
5770
|
+
* * If both `width` and `height` is specified, then, the size of mip levels from `level` will be computed
|
|
5771
|
+
* and data for consecutive mip levels will be uploaded until the data runs out.
|
|
5772
|
+
*
|
|
5773
|
+
* In other words: `{ format: g.RGBA, width: 4, height: 4, src: Uint8Array((4 * 4 + 2 * 2 + 1) * 4) }`
|
|
5774
|
+
* uploads 3 mip levels (4x4, 2x2, 1x1) because src is more than the data for the first mip level.
|
|
5581
5775
|
*
|
|
5582
5776
|
* If `number[]` will be converted to `type`.
|
|
5583
5777
|
*
|
|
@@ -5838,27 +6032,47 @@ function make1Pixel(color) {
|
|
|
5838
6032
|
return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
|
|
5839
6033
|
}
|
|
5840
6034
|
|
|
6035
|
+
/**
|
|
6036
|
+
* @typedef {Object} SetTextureFilteringInternalOptions
|
|
6037
|
+
* @property {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
|
|
6038
|
+
* This is often the same options you passed in when you created the texture.
|
|
6039
|
+
* @property {number} [width] width of texture
|
|
6040
|
+
* @property {number} [height] height of texture
|
|
6041
|
+
* @property {number} [internalFormat] The internalFormat parameter from texImage2D etc..
|
|
6042
|
+
* @property {number} [lastMipLevelUploaded] The last mip level manually uploaded
|
|
6043
|
+
* @private
|
|
6044
|
+
*/
|
|
6045
|
+
|
|
5841
6046
|
/**
|
|
5842
6047
|
* Sets filtering or generates mips for texture based on width or height
|
|
5843
6048
|
* If width or height is not passed in uses `options.width` and//or `options.height`
|
|
5844
6049
|
*
|
|
5845
6050
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
5846
6051
|
* @param {WebGLTexture} tex the WebGLTexture to set parameters for
|
|
5847
|
-
* @param {
|
|
5848
|
-
*
|
|
5849
|
-
* @param {number} [width] width of texture
|
|
5850
|
-
* @param {number} [height] height of texture
|
|
5851
|
-
* @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
|
|
5852
|
-
* @memberOf module:twgl/textures
|
|
6052
|
+
* @param {SetTextureFilteringInternalOptions} p
|
|
6053
|
+
* @private
|
|
5853
6054
|
*/
|
|
5854
|
-
function
|
|
6055
|
+
function setTextureFilteringForSizeInternal(gl, tex, {options, width, height, internalFormat, lastMipLevelUploaded }) {
|
|
5855
6056
|
options = options || defaults$1.textureOptions;
|
|
5856
6057
|
internalFormat = internalFormat || RGBA$1;
|
|
5857
6058
|
const target = options.target || TEXTURE_2D$2;
|
|
5858
6059
|
width = width || options.width;
|
|
5859
6060
|
height = height || options.height;
|
|
5860
6061
|
gl.bindTexture(target, tex);
|
|
5861
|
-
if (
|
|
6062
|
+
if (lastMipLevelUploaded > 1) {
|
|
6063
|
+
const lastLevelWidth = Math.max(1, width >> lastMipLevelUploaded);
|
|
6064
|
+
const lastLevelHeight = Math.max(1, height >> lastMipLevelUploaded);
|
|
6065
|
+
// Note: This is a guess. The user can set maxLod etc...
|
|
6066
|
+
const canUseMips = lastLevelWidth === 1 && lastLevelHeight === 1;
|
|
6067
|
+
const magFiltering = canFilter(internalFormat) ? LINEAR$1 : NEAREST;
|
|
6068
|
+
const minFiltering = canFilter(internalFormat)
|
|
6069
|
+
? canUseMips
|
|
6070
|
+
? NEAREST_MIPMAP_LINEAR
|
|
6071
|
+
: LINEAR$1
|
|
6072
|
+
: NEAREST;
|
|
6073
|
+
gl.texParameteri(target, TEXTURE_MAG_FILTER, magFiltering);
|
|
6074
|
+
gl.texParameteri(target, TEXTURE_MIN_FILTER, minFiltering);
|
|
6075
|
+
} else if (canGenerateMipmap(gl, width, height, internalFormat)) {
|
|
5862
6076
|
gl.generateMipmap(target);
|
|
5863
6077
|
} else {
|
|
5864
6078
|
const filtering = canFilter(internalFormat) ? LINEAR$1 : NEAREST;
|
|
@@ -5869,6 +6083,23 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
|
|
|
5869
6083
|
}
|
|
5870
6084
|
}
|
|
5871
6085
|
|
|
6086
|
+
/**
|
|
6087
|
+
* Sets filtering or generates mips for texture based on width or height
|
|
6088
|
+
* If width or height is not passed in uses `options.width` and//or `options.height`
|
|
6089
|
+
*
|
|
6090
|
+
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
6091
|
+
* @param {WebGLTexture} tex the WebGLTexture to set parameters for
|
|
6092
|
+
* @param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
|
|
6093
|
+
* This is often the same options you passed in when you created the texture.
|
|
6094
|
+
* @param {number} [width] width of texture
|
|
6095
|
+
* @param {number} [height] height of texture
|
|
6096
|
+
* @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
|
|
6097
|
+
* @memberOf module:twgl/textures
|
|
6098
|
+
*/
|
|
6099
|
+
function setTextureFilteringForSize(gl, tex, options, width, height, internalFormat) {
|
|
6100
|
+
setTextureFilteringForSizeInternal(gl, tex, { options, width, height, internalFormat });
|
|
6101
|
+
}
|
|
6102
|
+
|
|
5872
6103
|
function shouldAutomaticallySetTextureFilteringForSize(options) {
|
|
5873
6104
|
return options.auto === true || (options.auto === undefined && options.level === undefined);
|
|
5874
6105
|
}
|
|
@@ -5972,7 +6203,7 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
5972
6203
|
size = imgWidth / 2;
|
|
5973
6204
|
slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
|
|
5974
6205
|
} else {
|
|
5975
|
-
throw
|
|
6206
|
+
throw new Error(`can't figure out cube map from element: ${element.src ? element.src : element.nodeName}`);
|
|
5976
6207
|
}
|
|
5977
6208
|
const ctx = getShared2DContext();
|
|
5978
6209
|
if (ctx) {
|
|
@@ -6026,7 +6257,7 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
6026
6257
|
const largest = Math.max(element.width, element.height);
|
|
6027
6258
|
const depth = largest / smallest;
|
|
6028
6259
|
if (depth % 1 !== 0) {
|
|
6029
|
-
throw "can not compute 3D dimensions of element";
|
|
6260
|
+
throw new Error("can not compute 3D dimensions of element");
|
|
6030
6261
|
}
|
|
6031
6262
|
const xMult = element.width === largest ? 1 : 0;
|
|
6032
6263
|
const yMult = element.height === largest ? 1 : 0;
|
|
@@ -6323,7 +6554,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6323
6554
|
callback = callback || noop;
|
|
6324
6555
|
const urls = options.src;
|
|
6325
6556
|
if (urls.length !== 6) {
|
|
6326
|
-
throw "there must be 6 urls for a cubemap";
|
|
6557
|
+
throw new Error("there must be 6 urls for a cubemap");
|
|
6327
6558
|
}
|
|
6328
6559
|
const level = options.level || 0;
|
|
6329
6560
|
const internalFormat = options.internalFormat || options.format || RGBA$1;
|
|
@@ -6332,7 +6563,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6332
6563
|
const type = options.type || UNSIGNED_BYTE$1;
|
|
6333
6564
|
const target = options.target || TEXTURE_2D$2;
|
|
6334
6565
|
if (target !== TEXTURE_CUBE_MAP$1) {
|
|
6335
|
-
throw "target must be TEXTURE_CUBE_MAP";
|
|
6566
|
+
throw new Error("target must be TEXTURE_CUBE_MAP");
|
|
6336
6567
|
}
|
|
6337
6568
|
setTextureTo1PixelColor(gl, tex, options);
|
|
6338
6569
|
// Because it's async we need to copy the options.
|
|
@@ -6413,7 +6644,7 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
|
6413
6644
|
const type = options.type || UNSIGNED_BYTE$1;
|
|
6414
6645
|
const target = options.target || TEXTURE_2D_ARRAY$1;
|
|
6415
6646
|
if (target !== TEXTURE_3D$1 && target !== TEXTURE_2D_ARRAY$1) {
|
|
6416
|
-
throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
|
|
6647
|
+
throw new Error("target must be TEXTURE_3D or TEXTURE_2D_ARRAY");
|
|
6417
6648
|
}
|
|
6418
6649
|
setTextureTo1PixelColor(gl, tex, options);
|
|
6419
6650
|
// Because it's async we need to copy the options.
|
|
@@ -6498,9 +6729,6 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6498
6729
|
options = options || defaults$1.textureOptions;
|
|
6499
6730
|
const target = options.target || TEXTURE_2D$2;
|
|
6500
6731
|
gl.bindTexture(target, tex);
|
|
6501
|
-
let width = options.width;
|
|
6502
|
-
let height = options.height;
|
|
6503
|
-
let depth = options.depth;
|
|
6504
6732
|
const level = options.level || 0;
|
|
6505
6733
|
const internalFormat = options.internalFormat || options.format || RGBA$1;
|
|
6506
6734
|
const formatType = getFormatAndTypeForInternalFormat(internalFormat);
|
|
@@ -6513,62 +6741,114 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6513
6741
|
src = new Uint8Array(src.buffer);
|
|
6514
6742
|
}
|
|
6515
6743
|
|
|
6516
|
-
const
|
|
6517
|
-
const
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
let
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6744
|
+
const { width, height, depth } = getTextureSize(target, src, options, internalFormat, format, type);
|
|
6745
|
+
const compressed = isCompressedInternalFormat(internalFormat);
|
|
6746
|
+
|
|
6747
|
+
setSkipStateToDefault(gl);
|
|
6748
|
+
gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
|
|
6749
|
+
let mipLevelOffset = 0; // this is in addition to level
|
|
6750
|
+
scopedSetPackState(gl, options, () => {
|
|
6751
|
+
let mipLevelByteOffset = 0;
|
|
6752
|
+
const { blockWidth, blockHeight, bytesPerBlock } = getBlockInfoForInternalFormat(internalFormat, type);
|
|
6753
|
+
while (mipLevelByteOffset < src.byteLength) {
|
|
6754
|
+
const mipWidth = Math.max(1, width >> mipLevelOffset);
|
|
6755
|
+
const mipHeight = Math.max(1, height >> mipLevelOffset);
|
|
6756
|
+
const mipDepth = target === TEXTURE_2D$2 ? Math.max(1, depth >> mipLevelOffset) : depth;
|
|
6757
|
+
const blocksAcross = Math.ceil(mipWidth / blockWidth);
|
|
6758
|
+
const blocksDown = Math.ceil(mipHeight / blockHeight);
|
|
6759
|
+
const numFaces = target === TEXTURE_CUBE_MAP$1 ? 6 : 1;
|
|
6760
|
+
const bytesPerMipLevel = blocksAcross * blocksDown * bytesPerBlock * mipDepth * numFaces;
|
|
6761
|
+
if (mipLevelByteOffset + bytesPerMipLevel > src.byteLength) {
|
|
6762
|
+
throw new Error('src size does not match number of mip levels');
|
|
6763
|
+
}
|
|
6764
|
+
const mipSource = src.subarray(mipLevelByteOffset / src.BYTES_PER_ELEMENT, (mipLevelByteOffset + bytesPerMipLevel) / src.BYTES_PER_ELEMENT);
|
|
6765
|
+
const mipLevel = level + mipLevelOffset;
|
|
6766
|
+
|
|
6767
|
+
if (target === TEXTURE_CUBE_MAP$1) {
|
|
6768
|
+
const faceSize = mipSource.length / 6;
|
|
6769
|
+
getCubeFacesWithNdx(gl, options).forEach(f => {
|
|
6770
|
+
const offset = faceSize * f.ndx;
|
|
6771
|
+
const data = mipSource.subarray(offset, offset + faceSize);
|
|
6772
|
+
if (compressed) {
|
|
6773
|
+
gl.compressedTexImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, data);
|
|
6774
|
+
} else {
|
|
6775
|
+
gl.texImage2D(f.face, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, data);
|
|
6776
|
+
}
|
|
6777
|
+
});
|
|
6778
|
+
} else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
|
|
6779
|
+
gl.texImage3D(target, mipLevel, internalFormat, mipWidth, mipHeight, mipDepth, 0, format, type, mipSource);
|
|
6780
|
+
} else {
|
|
6781
|
+
if (compressed) {
|
|
6782
|
+
gl.compressedTexImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, mipSource);
|
|
6783
|
+
} else {
|
|
6784
|
+
gl.texImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, mipSource);
|
|
6785
|
+
}
|
|
6786
|
+
}
|
|
6787
|
+
++mipLevelOffset;
|
|
6788
|
+
mipLevelByteOffset += bytesPerMipLevel;
|
|
6789
|
+
if (mipWidth === 1 && mipHeight === 1 && mipDepth === 1 && mipLevelByteOffset !== src.byteLength) {
|
|
6790
|
+
throw new Error('src size has more data than can fit in mip levels');
|
|
6791
|
+
}
|
|
6792
|
+
}
|
|
6793
|
+
});
|
|
6794
|
+
return { width, height, depth, type, lastMipLevelUploaded: level + mipLevelOffset - 1 };
|
|
6795
|
+
}
|
|
6796
|
+
|
|
6797
|
+
function getTextureSize(target, src, options, internalFormat, format, type) {
|
|
6798
|
+
let width = options.width;
|
|
6799
|
+
let height = options.height;
|
|
6800
|
+
let depth = options.depth;
|
|
6801
|
+
|
|
6802
|
+
const compressed = isCompressedInternalFormat(internalFormat);
|
|
6803
|
+
|
|
6804
|
+
if (compressed) {
|
|
6805
|
+
if (!width || !height) {
|
|
6806
|
+
throw new Error("compressed texture needs to set width and height!");
|
|
6807
|
+
}
|
|
6808
|
+
depth = depth || 1;
|
|
6809
|
+
} else {
|
|
6810
|
+
const bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
|
|
6811
|
+
const numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
|
|
6812
|
+
if (numElements % 1) {
|
|
6813
|
+
throw new Error(`length wrong size for format: ${glEnumToString(gl, format)}`);
|
|
6814
|
+
}
|
|
6815
|
+
if (compressed && (!width || !height)) {
|
|
6816
|
+
throw new Error("compressed texture needs to set width and height!");
|
|
6817
|
+
}
|
|
6818
|
+
let dimensions;
|
|
6819
|
+
if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
|
|
6820
|
+
if (!width && !height && !depth) {
|
|
6821
|
+
const size = Math.cbrt(numElements);
|
|
6822
|
+
if (size % 1 !== 0) {
|
|
6823
|
+
throw new Error(`can't guess cube size of array of numElements: ${numElements}`);
|
|
6824
|
+
}
|
|
6825
|
+
width = size;
|
|
6826
|
+
height = size;
|
|
6827
|
+
depth = size;
|
|
6828
|
+
} else if (width && (!height || !depth)) {
|
|
6829
|
+
dimensions = guessDimensions(gl, target, height, depth, numElements / width);
|
|
6830
|
+
height = dimensions.width;
|
|
6831
|
+
depth = dimensions.height;
|
|
6832
|
+
} else if (height && (!width || !depth)) {
|
|
6833
|
+
dimensions = guessDimensions(gl, target, width, depth, numElements / height);
|
|
6834
|
+
width = dimensions.width;
|
|
6835
|
+
depth = dimensions.height;
|
|
6836
|
+
} else {
|
|
6837
|
+
dimensions = guessDimensions(gl, target, width, height, numElements / depth);
|
|
6838
|
+
width = dimensions.width;
|
|
6839
|
+
height = dimensions.height;
|
|
6527
6840
|
}
|
|
6528
|
-
width = size;
|
|
6529
|
-
height = size;
|
|
6530
|
-
depth = size;
|
|
6531
|
-
} else if (width && (!height || !depth)) {
|
|
6532
|
-
dimensions = guessDimensions(gl, target, height, depth, numElements / width);
|
|
6533
|
-
height = dimensions.width;
|
|
6534
|
-
depth = dimensions.height;
|
|
6535
|
-
} else if (height && (!width || !depth)) {
|
|
6536
|
-
dimensions = guessDimensions(gl, target, width, depth, numElements / height);
|
|
6537
|
-
width = dimensions.width;
|
|
6538
|
-
depth = dimensions.height;
|
|
6539
6841
|
} else {
|
|
6540
|
-
dimensions = guessDimensions(gl, target, width, height, numElements
|
|
6842
|
+
dimensions = guessDimensions(gl, target, width, height, numElements);
|
|
6541
6843
|
width = dimensions.width;
|
|
6542
6844
|
height = dimensions.height;
|
|
6543
6845
|
}
|
|
6544
|
-
} else {
|
|
6545
|
-
dimensions = guessDimensions(gl, target, width, height, numElements);
|
|
6546
|
-
width = dimensions.width;
|
|
6547
|
-
height = dimensions.height;
|
|
6548
6846
|
}
|
|
6549
|
-
setSkipStateToDefault(gl);
|
|
6550
|
-
gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
|
|
6551
|
-
scopedSetPackState(gl, options, () => {
|
|
6552
|
-
if (target === TEXTURE_CUBE_MAP$1) {
|
|
6553
|
-
const elementsPerElement = bytesPerElement / src.BYTES_PER_ELEMENT;
|
|
6554
|
-
const faceSize = numElements / 6 * elementsPerElement;
|
|
6555
6847
|
|
|
6556
|
-
getCubeFacesWithNdx(gl, options).forEach(f => {
|
|
6557
|
-
const offset = faceSize * f.ndx;
|
|
6558
|
-
const data = src.subarray(offset, offset + faceSize);
|
|
6559
|
-
gl.texImage2D(f.face, level, internalFormat, width, height, 0, format, type, data);
|
|
6560
|
-
});
|
|
6561
|
-
} else if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
|
|
6562
|
-
gl.texImage3D(target, level, internalFormat, width, height, depth, 0, format, type, src);
|
|
6563
|
-
} else {
|
|
6564
|
-
gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
|
|
6565
|
-
}
|
|
6566
|
-
});
|
|
6567
6848
|
return {
|
|
6568
|
-
width
|
|
6569
|
-
height
|
|
6570
|
-
depth
|
|
6571
|
-
type: type,
|
|
6849
|
+
width,
|
|
6850
|
+
height,
|
|
6851
|
+
depth,
|
|
6572
6852
|
};
|
|
6573
6853
|
}
|
|
6574
6854
|
|
|
@@ -6641,6 +6921,7 @@ function createTexture(gl, options, callback) {
|
|
|
6641
6921
|
const target = options.target || TEXTURE_2D$2;
|
|
6642
6922
|
let width = options.width || 1;
|
|
6643
6923
|
let height = options.height || 1;
|
|
6924
|
+
let lastMipLevelUploaded = 0;
|
|
6644
6925
|
const internalFormat = options.internalFormat || RGBA$1;
|
|
6645
6926
|
gl.bindTexture(target, tex);
|
|
6646
6927
|
if (target === TEXTURE_CUBE_MAP$1) {
|
|
@@ -6665,6 +6946,7 @@ function createTexture(gl, options, callback) {
|
|
|
6665
6946
|
const dimensions = setTextureFromArray(gl, tex, src, options);
|
|
6666
6947
|
width = dimensions.width;
|
|
6667
6948
|
height = dimensions.height;
|
|
6949
|
+
lastMipLevelUploaded = dimensions.lastMipLevelUploaded;
|
|
6668
6950
|
} else if (Array.isArray(src) && (typeof (src[0]) === 'string' || isTexImageSource(src[0]))) {
|
|
6669
6951
|
if (target === TEXTURE_CUBE_MAP$1) {
|
|
6670
6952
|
loadCubemapFromUrls(gl, tex, options, callback);
|
|
@@ -6680,7 +6962,7 @@ function createTexture(gl, options, callback) {
|
|
|
6680
6962
|
setEmptyTexture(gl, tex, options);
|
|
6681
6963
|
}
|
|
6682
6964
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
6683
|
-
|
|
6965
|
+
setTextureFilteringForSizeInternal(gl, tex, { options, width, height, internalFormat, lastMipLevelUploaded });
|
|
6684
6966
|
}
|
|
6685
6967
|
setTextureParameters(gl, tex, options);
|
|
6686
6968
|
return tex;
|
|
@@ -10075,6 +10357,8 @@ const supportedExtensions = [
|
|
|
10075
10357
|
'EXT_frag_depth',
|
|
10076
10358
|
'EXT_sRGB',
|
|
10077
10359
|
'EXT_shader_texture_lod',
|
|
10360
|
+
'EXT_texture_compression_bptc',
|
|
10361
|
+
'EXT_texture_compression_rgtc',
|
|
10078
10362
|
'EXT_texture_filter_anisotropic',
|
|
10079
10363
|
'OES_element_index_uint',
|
|
10080
10364
|
'OES_standard_derivatives',
|
|
@@ -10086,6 +10370,7 @@ const supportedExtensions = [
|
|
|
10086
10370
|
'WEBGL_color_buffer_float',
|
|
10087
10371
|
'WEBGL_compressed_texture_atc',
|
|
10088
10372
|
'WEBGL_compressed_texture_etc1',
|
|
10373
|
+
'WEBGL_compressed_texture_etc',
|
|
10089
10374
|
'WEBGL_compressed_texture_pvrtc',
|
|
10090
10375
|
'WEBGL_compressed_texture_s3tc',
|
|
10091
10376
|
'WEBGL_compressed_texture_s3tc_srgb',
|