twgl.js 6.2.0 → 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 +679 -376
- package/dist/{6.x → 7.x}/twgl-full.module.js +243 -148
- package/dist/{6.x → 7.x}/twgl.d.ts +15 -6
- package/dist/{6.x → 7.x}/twgl.js +679 -376
- 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;
|
|
@@ -5290,6 +5309,14 @@ const formatInfo = {};
|
|
|
5290
5309
|
f[DEPTH_STENCIL$1] = { numColorComponents: 2, };
|
|
5291
5310
|
}
|
|
5292
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
|
+
|
|
5293
5320
|
/**
|
|
5294
5321
|
* @typedef {Object} TextureFormatDetails
|
|
5295
5322
|
* @property {number} textureFormat format to pass texImage2D and similar functions.
|
|
@@ -5297,7 +5324,7 @@ const formatInfo = {};
|
|
|
5297
5324
|
* @property {boolean} textureFilterable true if you can filter the texture, false if you can ony use `NEAREST`.
|
|
5298
5325
|
* @property {number[]} type Array of possible types you can pass to texImage2D and similar function
|
|
5299
5326
|
* @property {Object.<number,number>} [bytesPerElementMap] A map of types to bytes per element
|
|
5300
|
-
* @property {
|
|
5327
|
+
* @property {BlockInfo} [block] block size, only for compressed textures
|
|
5301
5328
|
* @private
|
|
5302
5329
|
*/
|
|
5303
5330
|
|
|
@@ -5380,87 +5407,84 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
5380
5407
|
});
|
|
5381
5408
|
});
|
|
5382
5409
|
|
|
5383
|
-
const
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5408
|
-
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
for (const info of Object.values(t)) {
|
|
5454
|
-
info.compressed = true;
|
|
5455
|
-
}
|
|
5456
|
-
|
|
5457
|
-
return t;
|
|
5458
|
-
};
|
|
5459
|
-
Object.assign(t, getCompressedFormatInfo());
|
|
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 };
|
|
5460
5480
|
|
|
5461
5481
|
s_textureInternalFormatInfo = t;
|
|
5462
5482
|
}
|
|
5463
|
-
|
|
5483
|
+
const info = s_textureInternalFormatInfo[internalFormat];
|
|
5484
|
+
if (!info) {
|
|
5485
|
+
throw new Error("unknown internal format");
|
|
5486
|
+
}
|
|
5487
|
+
return info;
|
|
5464
5488
|
}
|
|
5465
5489
|
|
|
5466
5490
|
/**
|
|
@@ -5472,12 +5496,9 @@ function getTextureInternalFormatInfo(internalFormat) {
|
|
|
5472
5496
|
*/
|
|
5473
5497
|
function getBytesPerElementForInternalFormat(internalFormat, type) {
|
|
5474
5498
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5475
|
-
if (!info) {
|
|
5476
|
-
throw "unknown internal format";
|
|
5477
|
-
}
|
|
5478
5499
|
const bytesPerElement = info.bytesPerElementMap[type];
|
|
5479
5500
|
if (bytesPerElement === undefined) {
|
|
5480
|
-
throw "
|
|
5501
|
+
throw new Error("type not supported for internal format");
|
|
5481
5502
|
}
|
|
5482
5503
|
return bytesPerElement;
|
|
5483
5504
|
}
|
|
@@ -5502,7 +5523,7 @@ function getBytesPerElementForInternalFormat(internalFormat, type) {
|
|
|
5502
5523
|
function getFormatAndTypeForInternalFormat(internalFormat) {
|
|
5503
5524
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5504
5525
|
if (!info) {
|
|
5505
|
-
throw "unknown internal format";
|
|
5526
|
+
throw new Error("unknown internal format");
|
|
5506
5527
|
}
|
|
5507
5528
|
return {
|
|
5508
5529
|
format: info.textureFormat,
|
|
@@ -5517,10 +5538,22 @@ function getFormatAndTypeForInternalFormat(internalFormat) {
|
|
|
5517
5538
|
*/
|
|
5518
5539
|
function isCompressedInternalFormat(internalFormat) {
|
|
5519
5540
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5520
|
-
|
|
5521
|
-
|
|
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 };
|
|
5522
5554
|
}
|
|
5523
|
-
|
|
5555
|
+
const bytesPerBlock = getBytesPerElementForInternalFormat(internalFormat, type);
|
|
5556
|
+
return { blockWidth: 1, blockHeight: 1, bytesPerBlock };
|
|
5524
5557
|
}
|
|
5525
5558
|
|
|
5526
5559
|
/**
|
|
@@ -5549,9 +5582,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
|
|
|
5549
5582
|
return isPowerOf2(width) && isPowerOf2(height);
|
|
5550
5583
|
}
|
|
5551
5584
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5552
|
-
if (!info) {
|
|
5553
|
-
throw "unknown internal format";
|
|
5554
|
-
}
|
|
5555
5585
|
return info.colorRenderable && info.textureFilterable;
|
|
5556
5586
|
}
|
|
5557
5587
|
|
|
@@ -5563,9 +5593,6 @@ function canGenerateMipmap(gl, width, height, internalFormat) {
|
|
|
5563
5593
|
*/
|
|
5564
5594
|
function canFilter(internalFormat) {
|
|
5565
5595
|
const info = getTextureInternalFormatInfo(internalFormat);
|
|
5566
|
-
if (!info) {
|
|
5567
|
-
throw "unknown internal format";
|
|
5568
|
-
}
|
|
5569
5596
|
return info.textureFilterable;
|
|
5570
5597
|
}
|
|
5571
5598
|
|
|
@@ -5577,9 +5604,6 @@ function canFilter(internalFormat) {
|
|
|
5577
5604
|
*/
|
|
5578
5605
|
function getNumComponentsForFormat(format) {
|
|
5579
5606
|
const info = formatInfo[format];
|
|
5580
|
-
if (!info) {
|
|
5581
|
-
throw "unknown format: " + format;
|
|
5582
|
-
}
|
|
5583
5607
|
return info.numColorComponents;
|
|
5584
5608
|
}
|
|
5585
5609
|
|
|
@@ -5598,7 +5622,7 @@ function getTextureTypeForArrayType(gl, src, defaultType) {
|
|
|
5598
5622
|
|
|
5599
5623
|
function guessDimensions(gl, target, width, height, numElements) {
|
|
5600
5624
|
if (numElements % 1 !== 0) {
|
|
5601
|
-
throw "can't guess dimensions";
|
|
5625
|
+
throw new Error("can't guess dimensions");
|
|
5602
5626
|
}
|
|
5603
5627
|
if (!width && !height) {
|
|
5604
5628
|
const size = Math.sqrt(numElements / (target === TEXTURE_CUBE_MAP$1 ? 6 : 1));
|
|
@@ -5612,12 +5636,12 @@ function guessDimensions(gl, target, width, height, numElements) {
|
|
|
5612
5636
|
} else if (!height) {
|
|
5613
5637
|
height = numElements / width;
|
|
5614
5638
|
if (height % 1) {
|
|
5615
|
-
throw "can't guess dimensions";
|
|
5639
|
+
throw new Error("can't guess dimensions");
|
|
5616
5640
|
}
|
|
5617
5641
|
} else if (!width) {
|
|
5618
5642
|
width = numElements / height;
|
|
5619
5643
|
if (width % 1) {
|
|
5620
|
-
throw "can't guess dimensions";
|
|
5644
|
+
throw new Error("can't guess dimensions");
|
|
5621
5645
|
}
|
|
5622
5646
|
}
|
|
5623
5647
|
return {
|
|
@@ -5671,7 +5695,7 @@ function setDefaults$1(newDefaults) {
|
|
|
5671
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.
|
|
5672
5696
|
* @property {number} [width] the width of the texture. Only used if src is an array or typed array or null.
|
|
5673
5697
|
* @property {number} [height] the height of a texture. Only used if src is an array or typed array or null.
|
|
5674
|
-
* @property {number} [depth] the depth of a texture. Only used if src is an array or
|
|
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` .
|
|
5675
5699
|
* @property {number} [min] the min filter setting (eg. `gl.LINEAR`). Defaults to `gl.NEAREST_MIPMAP_LINEAR`
|
|
5676
5700
|
* or if texture is not a power of 2 on both dimensions then defaults to `gl.LINEAR`.
|
|
5677
5701
|
* @property {number} [mag] the mag filter setting (eg. `gl.LINEAR`). Defaults to `gl.LINEAR`
|
|
@@ -5730,15 +5754,24 @@ function setDefaults$1(newDefaults) {
|
|
|
5730
5754
|
* If `TexImageSource` then it wil be used immediately to create the contents of the texture. Examples `HTMLImageElement`,
|
|
5731
5755
|
* `HTMLCanvasElement`, `HTMLVideoElement`.
|
|
5732
5756
|
*
|
|
5733
|
-
* If `number[]` or `ArrayBufferView` it's assumed to be data for a texture.
|
|
5734
|
-
*
|
|
5735
|
-
*
|
|
5736
|
-
*
|
|
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.
|
|
5760
|
+
*
|
|
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
|
|
5764
|
+
*
|
|
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`.
|
|
5737
5767
|
*
|
|
5738
|
-
*
|
|
5739
|
-
* are set to `sqrt(numElements)`. Otherwise `width = numElements` and `height = 1`.
|
|
5768
|
+
* * If only one of `width` or `height` is specified then the other equals `numElements / specifiedDimension`.
|
|
5740
5769
|
*
|
|
5741
|
-
* *
|
|
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.
|
|
5742
5775
|
*
|
|
5743
5776
|
* If `number[]` will be converted to `type`.
|
|
5744
5777
|
*
|
|
@@ -5999,27 +6032,47 @@ function make1Pixel(color) {
|
|
|
5999
6032
|
return new Uint8Array([color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255]);
|
|
6000
6033
|
}
|
|
6001
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
|
+
|
|
6002
6046
|
/**
|
|
6003
6047
|
* Sets filtering or generates mips for texture based on width or height
|
|
6004
6048
|
* If width or height is not passed in uses `options.width` and//or `options.height`
|
|
6005
6049
|
*
|
|
6006
6050
|
* @param {WebGLRenderingContext} gl the WebGLRenderingContext
|
|
6007
6051
|
* @param {WebGLTexture} tex the WebGLTexture to set parameters for
|
|
6008
|
-
* @param {
|
|
6009
|
-
*
|
|
6010
|
-
* @param {number} [width] width of texture
|
|
6011
|
-
* @param {number} [height] height of texture
|
|
6012
|
-
* @param {number} [internalFormat] The internalFormat parameter from texImage2D etc..
|
|
6013
|
-
* @memberOf module:twgl/textures
|
|
6052
|
+
* @param {SetTextureFilteringInternalOptions} p
|
|
6053
|
+
* @private
|
|
6014
6054
|
*/
|
|
6015
|
-
function
|
|
6055
|
+
function setTextureFilteringForSizeInternal(gl, tex, {options, width, height, internalFormat, lastMipLevelUploaded }) {
|
|
6016
6056
|
options = options || defaults$1.textureOptions;
|
|
6017
6057
|
internalFormat = internalFormat || RGBA$1;
|
|
6018
6058
|
const target = options.target || TEXTURE_2D$2;
|
|
6019
6059
|
width = width || options.width;
|
|
6020
6060
|
height = height || options.height;
|
|
6021
6061
|
gl.bindTexture(target, tex);
|
|
6022
|
-
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)) {
|
|
6023
6076
|
gl.generateMipmap(target);
|
|
6024
6077
|
} else {
|
|
6025
6078
|
const filtering = canFilter(internalFormat) ? LINEAR$1 : NEAREST;
|
|
@@ -6030,6 +6083,23 @@ function setTextureFilteringForSize(gl, tex, options, width, height, internalFor
|
|
|
6030
6083
|
}
|
|
6031
6084
|
}
|
|
6032
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
|
+
|
|
6033
6103
|
function shouldAutomaticallySetTextureFilteringForSize(options) {
|
|
6034
6104
|
return options.auto === true || (options.auto === undefined && options.level === undefined);
|
|
6035
6105
|
}
|
|
@@ -6133,7 +6203,7 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
6133
6203
|
size = imgWidth / 2;
|
|
6134
6204
|
slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
|
|
6135
6205
|
} else {
|
|
6136
|
-
throw
|
|
6206
|
+
throw new Error(`can't figure out cube map from element: ${element.src ? element.src : element.nodeName}`);
|
|
6137
6207
|
}
|
|
6138
6208
|
const ctx = getShared2DContext();
|
|
6139
6209
|
if (ctx) {
|
|
@@ -6187,7 +6257,7 @@ function setTextureFromElement(gl, tex, element, options) {
|
|
|
6187
6257
|
const largest = Math.max(element.width, element.height);
|
|
6188
6258
|
const depth = largest / smallest;
|
|
6189
6259
|
if (depth % 1 !== 0) {
|
|
6190
|
-
throw "can not compute 3D dimensions of element";
|
|
6260
|
+
throw new Error("can not compute 3D dimensions of element");
|
|
6191
6261
|
}
|
|
6192
6262
|
const xMult = element.width === largest ? 1 : 0;
|
|
6193
6263
|
const yMult = element.height === largest ? 1 : 0;
|
|
@@ -6484,7 +6554,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6484
6554
|
callback = callback || noop;
|
|
6485
6555
|
const urls = options.src;
|
|
6486
6556
|
if (urls.length !== 6) {
|
|
6487
|
-
throw "there must be 6 urls for a cubemap";
|
|
6557
|
+
throw new Error("there must be 6 urls for a cubemap");
|
|
6488
6558
|
}
|
|
6489
6559
|
const level = options.level || 0;
|
|
6490
6560
|
const internalFormat = options.internalFormat || options.format || RGBA$1;
|
|
@@ -6493,7 +6563,7 @@ function loadCubemapFromUrls(gl, tex, options, callback) {
|
|
|
6493
6563
|
const type = options.type || UNSIGNED_BYTE$1;
|
|
6494
6564
|
const target = options.target || TEXTURE_2D$2;
|
|
6495
6565
|
if (target !== TEXTURE_CUBE_MAP$1) {
|
|
6496
|
-
throw "target must be TEXTURE_CUBE_MAP";
|
|
6566
|
+
throw new Error("target must be TEXTURE_CUBE_MAP");
|
|
6497
6567
|
}
|
|
6498
6568
|
setTextureTo1PixelColor(gl, tex, options);
|
|
6499
6569
|
// Because it's async we need to copy the options.
|
|
@@ -6574,7 +6644,7 @@ function loadSlicesFromUrls(gl, tex, options, callback) {
|
|
|
6574
6644
|
const type = options.type || UNSIGNED_BYTE$1;
|
|
6575
6645
|
const target = options.target || TEXTURE_2D_ARRAY$1;
|
|
6576
6646
|
if (target !== TEXTURE_3D$1 && target !== TEXTURE_2D_ARRAY$1) {
|
|
6577
|
-
throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
|
|
6647
|
+
throw new Error("target must be TEXTURE_3D or TEXTURE_2D_ARRAY");
|
|
6578
6648
|
}
|
|
6579
6649
|
setTextureTo1PixelColor(gl, tex, options);
|
|
6580
6650
|
// Because it's async we need to copy the options.
|
|
@@ -6671,63 +6741,86 @@ function setTextureFromArray(gl, tex, src, options) {
|
|
|
6671
6741
|
src = new Uint8Array(src.buffer);
|
|
6672
6742
|
}
|
|
6673
6743
|
|
|
6674
|
-
const { width, height, depth } = getTextureSize(
|
|
6744
|
+
const { width, height, depth } = getTextureSize(target, src, options, internalFormat, format, type);
|
|
6675
6745
|
const compressed = isCompressedInternalFormat(internalFormat);
|
|
6676
6746
|
|
|
6677
6747
|
setSkipStateToDefault(gl);
|
|
6678
6748
|
gl.pixelStorei(UNPACK_ALIGNMENT, options.unpackAlignment || 1);
|
|
6749
|
+
let mipLevelOffset = 0; // this is in addition to level
|
|
6679
6750
|
scopedSetPackState(gl, options, () => {
|
|
6680
|
-
|
|
6681
|
-
|
|
6682
|
-
|
|
6683
|
-
|
|
6684
|
-
|
|
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 {
|
|
6685
6781
|
if (compressed) {
|
|
6686
|
-
gl.compressedTexImage2D(
|
|
6782
|
+
gl.compressedTexImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, mipSource);
|
|
6687
6783
|
} else {
|
|
6688
|
-
gl.texImage2D(
|
|
6784
|
+
gl.texImage2D(target, mipLevel, internalFormat, mipWidth, mipHeight, 0, format, type, mipSource);
|
|
6689
6785
|
}
|
|
6690
|
-
}
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
gl.compressedTexImage2D(target, level, internalFormat, width, height, 0, src);
|
|
6696
|
-
} else {
|
|
6697
|
-
gl.texImage2D(target, level, internalFormat, width, height, 0, format, type, src);
|
|
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');
|
|
6698
6791
|
}
|
|
6699
6792
|
}
|
|
6700
6793
|
});
|
|
6701
|
-
return {
|
|
6702
|
-
width: width,
|
|
6703
|
-
height: height,
|
|
6704
|
-
depth: depth,
|
|
6705
|
-
type: type,
|
|
6706
|
-
};
|
|
6794
|
+
return { width, height, depth, type, lastMipLevelUploaded: level + mipLevelOffset - 1 };
|
|
6707
6795
|
}
|
|
6708
6796
|
|
|
6709
|
-
function getTextureSize(
|
|
6797
|
+
function getTextureSize(target, src, options, internalFormat, format, type) {
|
|
6710
6798
|
let width = options.width;
|
|
6711
6799
|
let height = options.height;
|
|
6712
6800
|
let depth = options.depth;
|
|
6713
6801
|
|
|
6714
6802
|
const compressed = isCompressedInternalFormat(internalFormat);
|
|
6803
|
+
|
|
6715
6804
|
if (compressed) {
|
|
6716
6805
|
if (!width || !height) {
|
|
6717
|
-
throw "compressed texture needs to set width and height!";
|
|
6806
|
+
throw new Error("compressed texture needs to set width and height!");
|
|
6718
6807
|
}
|
|
6808
|
+
depth = depth || 1;
|
|
6719
6809
|
} else {
|
|
6720
6810
|
const bytesPerElement = getBytesPerElementForInternalFormat(internalFormat, type);
|
|
6721
6811
|
const numElements = src.byteLength / bytesPerElement; // TODO: check UNPACK_ALIGNMENT?
|
|
6722
6812
|
if (numElements % 1) {
|
|
6723
|
-
throw
|
|
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!");
|
|
6724
6817
|
}
|
|
6725
6818
|
let dimensions;
|
|
6726
6819
|
if (target === TEXTURE_3D$1 || target === TEXTURE_2D_ARRAY$1) {
|
|
6727
6820
|
if (!width && !height && !depth) {
|
|
6728
6821
|
const size = Math.cbrt(numElements);
|
|
6729
6822
|
if (size % 1 !== 0) {
|
|
6730
|
-
throw
|
|
6823
|
+
throw new Error(`can't guess cube size of array of numElements: ${numElements}`);
|
|
6731
6824
|
}
|
|
6732
6825
|
width = size;
|
|
6733
6826
|
height = size;
|
|
@@ -6828,6 +6921,7 @@ function createTexture(gl, options, callback) {
|
|
|
6828
6921
|
const target = options.target || TEXTURE_2D$2;
|
|
6829
6922
|
let width = options.width || 1;
|
|
6830
6923
|
let height = options.height || 1;
|
|
6924
|
+
let lastMipLevelUploaded = 0;
|
|
6831
6925
|
const internalFormat = options.internalFormat || RGBA$1;
|
|
6832
6926
|
gl.bindTexture(target, tex);
|
|
6833
6927
|
if (target === TEXTURE_CUBE_MAP$1) {
|
|
@@ -6852,6 +6946,7 @@ function createTexture(gl, options, callback) {
|
|
|
6852
6946
|
const dimensions = setTextureFromArray(gl, tex, src, options);
|
|
6853
6947
|
width = dimensions.width;
|
|
6854
6948
|
height = dimensions.height;
|
|
6949
|
+
lastMipLevelUploaded = dimensions.lastMipLevelUploaded;
|
|
6855
6950
|
} else if (Array.isArray(src) && (typeof (src[0]) === 'string' || isTexImageSource(src[0]))) {
|
|
6856
6951
|
if (target === TEXTURE_CUBE_MAP$1) {
|
|
6857
6952
|
loadCubemapFromUrls(gl, tex, options, callback);
|
|
@@ -6867,7 +6962,7 @@ function createTexture(gl, options, callback) {
|
|
|
6867
6962
|
setEmptyTexture(gl, tex, options);
|
|
6868
6963
|
}
|
|
6869
6964
|
if (shouldAutomaticallySetTextureFilteringForSize(options)) {
|
|
6870
|
-
|
|
6965
|
+
setTextureFilteringForSizeInternal(gl, tex, { options, width, height, internalFormat, lastMipLevelUploaded });
|
|
6871
6966
|
}
|
|
6872
6967
|
setTextureParameters(gl, tex, options);
|
|
6873
6968
|
return tex;
|