@predy-js/render-interface 0.3.0-beta.196 → 0.3.0-beta.197

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Name: @predy-js/render-interface
3
3
  * Description: undefined
4
4
  * Author: undefined
5
- * Version: v0.3.0-beta.196
5
+ * Version: v0.3.0-beta.197
6
6
  */
7
7
 
8
8
  'use strict';
@@ -155,7 +155,7 @@ exports.TextureSourceType = void 0;
155
155
 
156
156
  var GPUBufferOptionsMemoryShared = 1 << 1;
157
157
 
158
- var _a$7, _b$3;
158
+ var _a$6, _b$3;
159
159
  // @ts-expect-error safe to assign
160
160
  var constants = {};
161
161
  if (typeof WebGL2RenderingContext === 'function') {
@@ -208,15 +208,15 @@ function copy(target) {
208
208
  }
209
209
  }
210
210
  }
211
- var map = (_a$7 = {},
212
- _a$7[constants.INT] = Int32Array,
213
- _a$7[constants.FLOAT] = Float32Array,
214
- _a$7[constants.SHORT] = Int16Array,
215
- _a$7[constants.BYTE] = Int8Array,
216
- _a$7[constants.UNSIGNED_BYTE] = Uint8Array,
217
- _a$7[constants.UNSIGNED_INT] = Uint32Array,
218
- _a$7[constants.UNSIGNED_SHORT] = Uint16Array,
219
- _a$7);
211
+ var map = (_a$6 = {},
212
+ _a$6[constants.INT] = Int32Array,
213
+ _a$6[constants.FLOAT] = Float32Array,
214
+ _a$6[constants.SHORT] = Int16Array,
215
+ _a$6[constants.BYTE] = Int8Array,
216
+ _a$6[constants.UNSIGNED_BYTE] = Uint8Array,
217
+ _a$6[constants.UNSIGNED_INT] = Uint32Array,
218
+ _a$6[constants.UNSIGNED_SHORT] = Uint16Array,
219
+ _a$6);
220
220
  function getBytesPerElementByGLType(type) {
221
221
  var _a;
222
222
  return ((_a = map[type]) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT) || 0;
@@ -1271,9 +1271,9 @@ function requestAnimationFrame(cb) {
1271
1271
  return window.requestAnimationFrame(cb);
1272
1272
  }
1273
1273
 
1274
- var _a$6;
1275
- var DATA_DICT = (_a$6 = {},
1276
- _a$6[constants.FLOAT] = {
1274
+ var _a$5;
1275
+ var DATA_DICT = (_a$5 = {},
1276
+ _a$5[constants.FLOAT] = {
1277
1277
  name: constants.FLOAT,
1278
1278
  uniform: function (gl, info, value) {
1279
1279
  if (value.length != undefined) {
@@ -1284,79 +1284,79 @@ var DATA_DICT = (_a$6 = {},
1284
1284
  }
1285
1285
  },
1286
1286
  },
1287
- _a$6[constants.FLOAT_VEC2] = {
1287
+ _a$5[constants.FLOAT_VEC2] = {
1288
1288
  name: constants.FLOAT_VEC2,
1289
1289
  uniform: function (gl, info, value) {
1290
1290
  gl.uniform2fv(info.loc, value);
1291
1291
  },
1292
1292
  },
1293
- _a$6[constants.FLOAT_VEC3] = {
1293
+ _a$5[constants.FLOAT_VEC3] = {
1294
1294
  name: constants.FLOAT_VEC3,
1295
1295
  uniform: function (gl, info, value) {
1296
1296
  gl.uniform3fv(info.loc, value);
1297
1297
  },
1298
1298
  },
1299
- _a$6[constants.FLOAT_VEC4] = {
1299
+ _a$5[constants.FLOAT_VEC4] = {
1300
1300
  name: constants.FLOAT_VEC4,
1301
1301
  uniform: function (gl, info, value) {
1302
1302
  gl.uniform4fv(info.loc, value);
1303
1303
  },
1304
1304
  },
1305
- _a$6[constants.FLOAT_MAT2] = {
1305
+ _a$5[constants.FLOAT_MAT2] = {
1306
1306
  name: constants.FLOAT_MAT2,
1307
1307
  uniform: function (gl, info, value) {
1308
1308
  gl.uniformMatrix2fv(info.loc, false, value);
1309
1309
  },
1310
1310
  },
1311
- _a$6[constants.FLOAT_MAT2x3] = {
1311
+ _a$5[constants.FLOAT_MAT2x3] = {
1312
1312
  name: constants.FLOAT_MAT2x3,
1313
1313
  uniform: function (gl, info, value) {
1314
1314
  gl.uniformMatrix2x3fv(info.loc, false, value);
1315
1315
  },
1316
1316
  },
1317
- _a$6[constants.FLOAT_MAT2x4] = {
1317
+ _a$5[constants.FLOAT_MAT2x4] = {
1318
1318
  name: constants.FLOAT_MAT2x4,
1319
1319
  uniform: function (gl, info, value) {
1320
1320
  gl.uniformMatrix2x3fv(info.loc, false, value);
1321
1321
  },
1322
1322
  },
1323
- _a$6[constants.FLOAT_MAT3] = {
1323
+ _a$5[constants.FLOAT_MAT3] = {
1324
1324
  name: constants.FLOAT_MAT3,
1325
1325
  uniform: function (gl, info, value) {
1326
1326
  gl.uniformMatrix3fv(info.loc, false, value);
1327
1327
  },
1328
1328
  },
1329
- _a$6[constants.FLOAT_MAT3x2] = {
1329
+ _a$5[constants.FLOAT_MAT3x2] = {
1330
1330
  name: constants.FLOAT_MAT3x2,
1331
1331
  uniform: function (gl, info, value) {
1332
1332
  gl.uniformMatrix3x2fv(info.loc, false, value);
1333
1333
  },
1334
1334
  },
1335
- _a$6[constants.FLOAT_MAT3x4] = {
1335
+ _a$5[constants.FLOAT_MAT3x4] = {
1336
1336
  name: constants.FLOAT_MAT3x4,
1337
1337
  uniform: function (gl, info, value) {
1338
1338
  gl.uniformMatrix3x4fv(info.loc, false, value);
1339
1339
  },
1340
1340
  },
1341
- _a$6[constants.FLOAT_MAT4] = {
1341
+ _a$5[constants.FLOAT_MAT4] = {
1342
1342
  name: constants.FLOAT_MAT4,
1343
1343
  uniform: function (gl, info, value) {
1344
1344
  gl.uniformMatrix4fv(info.loc, false, value);
1345
1345
  },
1346
1346
  },
1347
- _a$6[constants.FLOAT_MAT4x3] = {
1347
+ _a$5[constants.FLOAT_MAT4x3] = {
1348
1348
  name: constants.FLOAT_MAT4x3,
1349
1349
  uniform: function (gl, info, value) {
1350
1350
  gl.uniformMatrix4x3fv(info.loc, false, value);
1351
1351
  },
1352
1352
  },
1353
- _a$6[constants.FLOAT_MAT4x2] = {
1353
+ _a$5[constants.FLOAT_MAT4x2] = {
1354
1354
  name: constants.FLOAT_MAT4x2,
1355
1355
  uniform: function (gl, info, value) {
1356
1356
  gl.uniformMatrix4x2fv(info.loc, false, value);
1357
1357
  },
1358
1358
  },
1359
- _a$6[constants.INT] = {
1359
+ _a$5[constants.INT] = {
1360
1360
  name: constants.INT,
1361
1361
  uniform: function (gl, info, value) {
1362
1362
  if (value.length != undefined) {
@@ -1367,49 +1367,49 @@ var DATA_DICT = (_a$6 = {},
1367
1367
  }
1368
1368
  },
1369
1369
  },
1370
- _a$6[constants.INT_VEC2] = {
1370
+ _a$5[constants.INT_VEC2] = {
1371
1371
  name: constants.INT_VEC2,
1372
1372
  uniform: function (gl, info, value) {
1373
1373
  gl.uniform2iv(info.loc, value);
1374
1374
  },
1375
1375
  },
1376
- _a$6[constants.INT_VEC3] = {
1376
+ _a$5[constants.INT_VEC3] = {
1377
1377
  name: constants.INT_VEC3,
1378
1378
  uniform: function (gl, info, value) {
1379
1379
  gl.uniform3iv(info.loc, value);
1380
1380
  },
1381
1381
  },
1382
- _a$6[constants.INT_VEC4] = {
1382
+ _a$5[constants.INT_VEC4] = {
1383
1383
  name: constants.INT_VEC4,
1384
1384
  uniform: function (gl, info, value) {
1385
1385
  gl.uniform4iv(info.loc, value);
1386
1386
  },
1387
1387
  },
1388
- _a$6[constants.UNSIGNED_INT] = {
1388
+ _a$5[constants.UNSIGNED_INT] = {
1389
1389
  name: constants.UNSIGNED_INT,
1390
1390
  uniform: function (gl, info, value) {
1391
1391
  gl.uniform1uiv(info.loc, value);
1392
1392
  },
1393
1393
  },
1394
- _a$6[constants.UNSIGNED_INT_VEC2] = {
1394
+ _a$5[constants.UNSIGNED_INT_VEC2] = {
1395
1395
  name: constants.UNSIGNED_INT_VEC2,
1396
1396
  uniform: function (gl, info, value) {
1397
1397
  gl.uniform2uiv(info.loc, value);
1398
1398
  },
1399
1399
  },
1400
- _a$6[constants.UNSIGNED_INT_VEC3] = {
1400
+ _a$5[constants.UNSIGNED_INT_VEC3] = {
1401
1401
  name: constants.UNSIGNED_INT_VEC3,
1402
1402
  uniform: function (gl, info, value) {
1403
1403
  gl.uniform3uiv(info.loc, value);
1404
1404
  },
1405
1405
  },
1406
- _a$6[constants.UNSIGNED_INT_VEC4] = {
1406
+ _a$5[constants.UNSIGNED_INT_VEC4] = {
1407
1407
  name: constants.UNSIGNED_INT_VEC4,
1408
1408
  uniform: function (gl, info, value) {
1409
1409
  gl.uniform4uiv(info.loc, value);
1410
1410
  },
1411
1411
  },
1412
- _a$6[constants.BOOL] = {
1412
+ _a$5[constants.BOOL] = {
1413
1413
  name: constants.BOOL,
1414
1414
  uniform: function (gl, info, value) {
1415
1415
  if (value.length != undefined) {
@@ -1420,33 +1420,33 @@ var DATA_DICT = (_a$6 = {},
1420
1420
  }
1421
1421
  },
1422
1422
  },
1423
- _a$6[constants.BOOL_VEC2] = {
1423
+ _a$5[constants.BOOL_VEC2] = {
1424
1424
  name: constants.BOOL_VEC2,
1425
1425
  uniform: function (gl, info, value) {
1426
1426
  gl.uniform2iv(info.loc, value);
1427
1427
  },
1428
1428
  },
1429
- _a$6[constants.BOOL_VEC4] = {
1429
+ _a$5[constants.BOOL_VEC4] = {
1430
1430
  name: constants.BOOL_VEC4,
1431
1431
  uniform: function (gl, info, value) {
1432
1432
  gl.uniform4iv(info.loc, value);
1433
1433
  },
1434
1434
  },
1435
- _a$6[constants.BOOL_VEC3] = {
1435
+ _a$5[constants.BOOL_VEC3] = {
1436
1436
  name: constants.BOOL_VEC3,
1437
1437
  uniform: function (gl, info, value) {
1438
1438
  gl.uniform3iv(info.loc, value);
1439
1439
  },
1440
1440
  },
1441
- _a$6[constants.SAMPLER_2D] = {
1441
+ _a$5[constants.SAMPLER_2D] = {
1442
1442
  name: constants.SAMPLER_2D,
1443
1443
  uniform: assignTexUniform,
1444
1444
  },
1445
- _a$6[constants.SAMPLER_CUBE] = {
1445
+ _a$5[constants.SAMPLER_CUBE] = {
1446
1446
  name: constants.SAMPLER_CUBE,
1447
1447
  uniform: assignTexUniform,
1448
1448
  },
1449
- _a$6);
1449
+ _a$5);
1450
1450
  function assignTexUniform(gl, info, value, renderer) {
1451
1451
  if (value) {
1452
1452
  if (info.size > 1) {
@@ -1480,7 +1480,7 @@ function assignTextureLoc(gl, info, value, renderer, index) {
1480
1480
  }
1481
1481
  }
1482
1482
 
1483
- var _a$5, _b$2;
1483
+ var _a$4, _b$2;
1484
1484
  var BlockUniformInfoOffset = 1;
1485
1485
  var BlockUniformInfoByteLength = 8;
1486
1486
  var BlockUniformInfoType = 0;
@@ -1593,35 +1593,35 @@ var arrSetter = function (type) { return function setArray(value, info, name, ra
1593
1593
  var setFloat32Array = arrSetter(Float32Array);
1594
1594
  var setInt32Array = arrSetter(Int32Array);
1595
1595
  var setUInt8Array = arrSetter(Uint8Array);
1596
- var MemorySetter = (_a$5 = {},
1597
- _a$5[constants.FLOAT] = numberSetter(Float32Array),
1598
- _a$5[constants.INT] = numberSetter(Int32Array),
1599
- _a$5[constants.UNSIGNED_INT] = numberSetter(Uint32Array),
1600
- _a$5[constants.SHORT] = numberSetter(Int16Array),
1601
- _a$5[constants.BOOL] = numberSetter(Uint8Array),
1602
- _a$5[constants.UNSIGNED_SHORT] = numberSetter(Uint16Array),
1603
- _a$5[constants.FLOAT_VEC2] = setFloat32Array,
1604
- _a$5[constants.FLOAT_VEC3] = setFloat32Array,
1605
- _a$5[constants.FLOAT_VEC4] = setFloat32Array,
1606
- _a$5[constants.FLOAT_MAT2] = setFloat32Array,
1607
- _a$5[constants.FLOAT_MAT3] = setFloat32Array,
1608
- _a$5[constants.FLOAT_MAT4] = setFloat32Array,
1609
- _a$5[constants.FLOAT_MAT2x3] = setFloat32Array,
1610
- _a$5[constants.FLOAT_MAT2x4] = setFloat32Array,
1611
- _a$5[constants.FLOAT_MAT4x3] = setFloat32Array,
1612
- _a$5[constants.FLOAT_MAT4x2] = setFloat32Array,
1613
- _a$5[constants.FLOAT_MAT3x4] = setFloat32Array,
1614
- _a$5[constants.FLOAT_MAT3x2] = setFloat32Array,
1615
- _a$5[constants.INT_VEC2] = setInt32Array,
1616
- _a$5[constants.INT_VEC3] = setInt32Array,
1617
- _a$5[constants.INT_VEC4] = setInt32Array,
1618
- _a$5[constants.UNSIGNED_INT_VEC2] = setInt32Array,
1619
- _a$5[constants.UNSIGNED_INT_VEC3] = setInt32Array,
1620
- _a$5[constants.UNSIGNED_INT_VEC4] = setInt32Array,
1621
- _a$5[constants.BOOL_VEC2] = setUInt8Array,
1622
- _a$5[constants.BOOL_VEC3] = setUInt8Array,
1623
- _a$5[constants.BOOL_VEC4] = setUInt8Array,
1624
- _a$5);
1596
+ var MemorySetter = (_a$4 = {},
1597
+ _a$4[constants.FLOAT] = numberSetter(Float32Array),
1598
+ _a$4[constants.INT] = numberSetter(Int32Array),
1599
+ _a$4[constants.UNSIGNED_INT] = numberSetter(Uint32Array),
1600
+ _a$4[constants.SHORT] = numberSetter(Int16Array),
1601
+ _a$4[constants.BOOL] = numberSetter(Uint8Array),
1602
+ _a$4[constants.UNSIGNED_SHORT] = numberSetter(Uint16Array),
1603
+ _a$4[constants.FLOAT_VEC2] = setFloat32Array,
1604
+ _a$4[constants.FLOAT_VEC3] = setFloat32Array,
1605
+ _a$4[constants.FLOAT_VEC4] = setFloat32Array,
1606
+ _a$4[constants.FLOAT_MAT2] = setFloat32Array,
1607
+ _a$4[constants.FLOAT_MAT3] = setFloat32Array,
1608
+ _a$4[constants.FLOAT_MAT4] = setFloat32Array,
1609
+ _a$4[constants.FLOAT_MAT2x3] = setFloat32Array,
1610
+ _a$4[constants.FLOAT_MAT2x4] = setFloat32Array,
1611
+ _a$4[constants.FLOAT_MAT4x3] = setFloat32Array,
1612
+ _a$4[constants.FLOAT_MAT4x2] = setFloat32Array,
1613
+ _a$4[constants.FLOAT_MAT3x4] = setFloat32Array,
1614
+ _a$4[constants.FLOAT_MAT3x2] = setFloat32Array,
1615
+ _a$4[constants.INT_VEC2] = setInt32Array,
1616
+ _a$4[constants.INT_VEC3] = setInt32Array,
1617
+ _a$4[constants.INT_VEC4] = setInt32Array,
1618
+ _a$4[constants.UNSIGNED_INT_VEC2] = setInt32Array,
1619
+ _a$4[constants.UNSIGNED_INT_VEC3] = setInt32Array,
1620
+ _a$4[constants.UNSIGNED_INT_VEC4] = setInt32Array,
1621
+ _a$4[constants.BOOL_VEC2] = setUInt8Array,
1622
+ _a$4[constants.BOOL_VEC3] = setUInt8Array,
1623
+ _a$4[constants.BOOL_VEC4] = setUInt8Array,
1624
+ _a$4);
1625
1625
  var ItemPerValueMap = (_b$2 = {},
1626
1626
  _b$2[constants.FLOAT] = 1,
1627
1627
  _b$2[constants.INT] = 1,
@@ -1974,21 +1974,21 @@ var GLProgram = /** @class */ (function () {
1974
1974
  return GLProgram;
1975
1975
  }());
1976
1976
 
1977
- var _a$4;
1977
+ var _a$3;
1978
1978
  var ShaderType;
1979
1979
  (function (ShaderType) {
1980
1980
  ShaderType[ShaderType["vertex"] = 0] = "vertex";
1981
1981
  ShaderType[ShaderType["fragment"] = 1] = "fragment";
1982
1982
  })(ShaderType || (ShaderType = {}));
1983
- var downgradeKeywords = (_a$4 = {},
1984
- _a$4[ShaderType.vertex] = {
1983
+ var downgradeKeywords = (_a$3 = {},
1984
+ _a$3[ShaderType.vertex] = {
1985
1985
  in: 'attribute',
1986
1986
  out: 'varying',
1987
1987
  },
1988
- _a$4[ShaderType.fragment] = {
1988
+ _a$3[ShaderType.fragment] = {
1989
1989
  in: 'varying',
1990
1990
  },
1991
- _a$4);
1991
+ _a$3);
1992
1992
  var shaderSeed = 1;
1993
1993
  var GLShaderLibrary = /** @class */ (function () {
1994
1994
  function GLShaderLibrary(renderer) {
@@ -2466,7 +2466,7 @@ function registerCompressedTexture(gl) {
2466
2466
  return 0;
2467
2467
  }
2468
2468
 
2469
- var _a$3, _b$1;
2469
+ var _a$2, _b$1;
2470
2470
  var flipCanvas;
2471
2471
  var imageBitMapAvailable$1 = typeof ImageBitmap === 'function' && typeof createImageBitmap == 'function';
2472
2472
  var GLTexture = /** @class */ (function () {
@@ -2803,14 +2803,14 @@ function nearestPowerOfTwo(value) {
2803
2803
  function isPowerOfTwo(value) {
2804
2804
  return (value & (value - 1)) === 0 && value !== 0;
2805
2805
  }
2806
- var FORMAT_HALF_FLOAT = (_a$3 = {},
2807
- _a$3[constants.RGBA] = 34842,
2808
- _a$3[constants.RGB] = 34843,
2809
- _a$3[constants.ALPHA] = 33325,
2810
- _a$3[constants.RED] = 33325,
2811
- _a$3[constants.LUMINANCE_ALPHA] = 33327,
2812
- _a$3[constants.LUMINANCE] = 33325,
2813
- _a$3);
2806
+ var FORMAT_HALF_FLOAT = (_a$2 = {},
2807
+ _a$2[constants.RGBA] = 34842,
2808
+ _a$2[constants.RGB] = 34843,
2809
+ _a$2[constants.ALPHA] = 33325,
2810
+ _a$2[constants.RED] = 33325,
2811
+ _a$2[constants.LUMINANCE_ALPHA] = 33327,
2812
+ _a$2[constants.LUMINANCE] = 33325,
2813
+ _a$2);
2814
2814
  var FORMAT_FLOAT = (_b$1 = {},
2815
2815
  _b$1[constants.RGBA] = 34836,
2816
2816
  _b$1[constants.RGB] = 34837,
@@ -3605,394 +3605,110 @@ function loadImageAsync(imgOrURL, options) {
3605
3605
  });
3606
3606
  }
3607
3607
 
3608
- ///////////////////////////////////////////////////
3609
- // KTX2 Header.
3610
- ///////////////////////////////////////////////////
3611
- const KHR_SUPERCOMPRESSION_NONE = 0;
3612
- ///////////////////////////////////////////////////
3613
- // Data Format Descriptor (DFD).
3614
- ///////////////////////////////////////////////////
3615
- const KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0;
3616
- const KHR_DF_VENDORID_KHRONOS = 0;
3617
- const KHR_DF_VERSION = 2;
3618
- const KHR_DF_MODEL_UNSPECIFIED = 0;
3619
- const KHR_DF_FLAG_ALPHA_STRAIGHT = 0;
3620
- const KHR_DF_TRANSFER_SRGB = 2;
3621
- const KHR_DF_PRIMARIES_BT709 = 1;
3622
- const KHR_DF_SAMPLE_DATATYPE_SIGNED = 0x40;
3623
- ///////////////////////////////////////////////////
3624
- // VK FORMAT.
3625
- ///////////////////////////////////////////////////
3626
- const VK_FORMAT_UNDEFINED = 0;
3627
- const VK_FORMAT_ASTC_4x4_UNORM_BLOCK = 157;
3628
- const VK_FORMAT_ASTC_4x4_SRGB_BLOCK = 158;
3629
- const VK_FORMAT_ASTC_5x4_UNORM_BLOCK = 159;
3630
- const VK_FORMAT_ASTC_5x4_SRGB_BLOCK = 160;
3631
- const VK_FORMAT_ASTC_5x5_UNORM_BLOCK = 161;
3632
- const VK_FORMAT_ASTC_5x5_SRGB_BLOCK = 162;
3633
- const VK_FORMAT_ASTC_6x5_UNORM_BLOCK = 163;
3634
- const VK_FORMAT_ASTC_6x5_SRGB_BLOCK = 164;
3635
- const VK_FORMAT_ASTC_6x6_UNORM_BLOCK = 165;
3636
- const VK_FORMAT_ASTC_6x6_SRGB_BLOCK = 166;
3637
- const VK_FORMAT_ASTC_8x5_UNORM_BLOCK = 167;
3638
- const VK_FORMAT_ASTC_8x5_SRGB_BLOCK = 168;
3639
- const VK_FORMAT_ASTC_8x6_UNORM_BLOCK = 169;
3640
- const VK_FORMAT_ASTC_8x6_SRGB_BLOCK = 170;
3641
- const VK_FORMAT_ASTC_8x8_UNORM_BLOCK = 171;
3642
- const VK_FORMAT_ASTC_8x8_SRGB_BLOCK = 172;
3643
- const VK_FORMAT_ASTC_10x5_UNORM_BLOCK = 173;
3644
- const VK_FORMAT_ASTC_10x5_SRGB_BLOCK = 174;
3645
- const VK_FORMAT_ASTC_10x6_UNORM_BLOCK = 175;
3646
- const VK_FORMAT_ASTC_10x6_SRGB_BLOCK = 176;
3647
- const VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177;
3648
- const VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178;
3649
- const VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179;
3650
- const VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180;
3651
- const VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181;
3652
- const VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182;
3653
- const VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183;
3654
- const VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184;
3655
-
3656
- /**
3657
- * Represents an unpacked KTX 2.0 texture container. Data for individual mip levels are stored in
3658
- * the `.levels` array, typically compressed in Basis Universal formats. Additional properties
3659
- * provide metadata required to process, transcode, and upload these textures.
3660
- */
3661
- class KTX2Container {
3662
- constructor() {
3663
- /**
3664
- * Specifies the image format using Vulkan VkFormat enum values. When using Basis Universal
3665
- * texture formats, `vkFormat` must be VK_FORMAT_UNDEFINED.
3666
- */
3667
- this.vkFormat = VK_FORMAT_UNDEFINED;
3668
- /**
3669
- * Size of the data type in bytes used to upload the data to a graphics API. When `vkFormat` is
3670
- * VK_FORMAT_UNDEFINED, `typeSize` must be 1.
3671
- */
3672
- this.typeSize = 1;
3673
- /** Width of the texture image for level 0, in pixels. */
3674
- this.pixelWidth = 0;
3675
- /** Height of the texture image for level 0, in pixels. */
3676
- this.pixelHeight = 0;
3677
- /** Depth of the texture image for level 0, in pixels (3D textures only). */
3678
- this.pixelDepth = 0;
3679
- /** Number of array elements (array textures only). */
3680
- this.layerCount = 0;
3681
- /**
3682
- * Number of cubemap faces. For cubemaps and cubemap arrays, `faceCount` must be 6. For all
3683
- * other textures, `faceCount` must be 1. Cubemap faces are stored in +X, -X, +Y, -Y, +Z, -Z
3684
- * order.
3685
- */
3686
- this.faceCount = 1;
3687
- /** Indicates which supercompression scheme has been applied to mip level images, if any. */
3688
- this.supercompressionScheme = KHR_SUPERCOMPRESSION_NONE;
3689
- /** Mip levels, ordered largest (original) to smallest (~1px). */
3690
- this.levels = [];
3691
- /** Data Format Descriptor. */
3692
- this.dataFormatDescriptor = [{
3693
- vendorId: KHR_DF_VENDORID_KHRONOS,
3694
- descriptorType: KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT,
3695
- descriptorBlockSize: 0,
3696
- versionNumber: KHR_DF_VERSION,
3697
- colorModel: KHR_DF_MODEL_UNSPECIFIED,
3698
- colorPrimaries: KHR_DF_PRIMARIES_BT709,
3699
- transferFunction: KHR_DF_TRANSFER_SRGB,
3700
- flags: KHR_DF_FLAG_ALPHA_STRAIGHT,
3701
- texelBlockDimension: [0, 0, 0, 0],
3702
- bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0],
3703
- samples: []
3704
- }];
3705
- /** Key/Value Data. */
3706
- this.keyValue = {};
3707
- /** Supercompression Global Data. */
3708
- this.globalData = null;
3709
- }
3710
- }
3711
-
3712
- class BufferReader {
3713
- constructor(data, byteOffset, byteLength, littleEndian) {
3714
- this._dataView = void 0;
3715
- this._littleEndian = void 0;
3716
- this._offset = void 0;
3717
- this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength);
3718
- this._littleEndian = littleEndian;
3719
- this._offset = 0;
3720
- }
3721
- _nextUint8() {
3722
- const value = this._dataView.getUint8(this._offset);
3723
- this._offset += 1;
3724
- return value;
3725
- }
3726
- _nextUint16() {
3727
- const value = this._dataView.getUint16(this._offset, this._littleEndian);
3728
- this._offset += 2;
3729
- return value;
3730
- }
3731
- _nextUint32() {
3732
- const value = this._dataView.getUint32(this._offset, this._littleEndian);
3733
- this._offset += 4;
3734
- return value;
3735
- }
3736
- _nextUint64() {
3737
- const left = this._dataView.getUint32(this._offset, this._littleEndian);
3738
- const right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
3739
- // TODO(cleanup): Just test this...
3740
- // const value = this._littleEndian ? left + (2 ** 32 * right) : (2 ** 32 * left) + right;
3741
- const value = left + 2 ** 32 * right;
3742
- this._offset += 8;
3743
- return value;
3744
- }
3745
- _nextInt32() {
3746
- const value = this._dataView.getInt32(this._offset, this._littleEndian);
3747
- this._offset += 4;
3748
- return value;
3749
- }
3750
- _nextUint8Array(len) {
3751
- const value = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._offset, len);
3752
- this._offset += len;
3753
- return value;
3754
- }
3755
- _skip(bytes) {
3756
- this._offset += bytes;
3757
- return this;
3758
- }
3759
- _scan(maxByteLength, term = 0x00) {
3760
- const byteOffset = this._offset;
3761
- let byteLength = 0;
3762
- while (this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength) {
3763
- byteLength++;
3764
- this._offset++;
3765
- }
3766
- if (byteLength < maxByteLength) this._offset++;
3767
- return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
3768
- }
3769
- }
3770
- ///////////////////////////////////////////////////
3771
- // KTX2 Header.
3772
- ///////////////////////////////////////////////////
3773
- const KTX2_ID = [
3774
- // '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
3775
- 0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a];
3776
- /** Decodes an ArrayBuffer to text. */
3777
- function decodeText(buffer) {
3778
- return new TextDecoder().decode(buffer);
3779
- }
3780
-
3781
- /**
3782
- * Parses a KTX 2.0 file, returning an unpacked {@link KTX2Container} instance with all associated
3783
- * data. The container's mip levels and other binary data are pointers into the original file, not
3784
- * copies, so the original file should not be overwritten after reading.
3785
- *
3786
- * @param data Bytes of KTX 2.0 file, as Uint8Array or Buffer.
3787
- */
3788
- function read(data) {
3789
- ///////////////////////////////////////////////////
3790
- // KTX 2.0 Identifier.
3791
- ///////////////////////////////////////////////////
3792
- const id = new Uint8Array(data.buffer, data.byteOffset, KTX2_ID.length);
3793
- if (id[0] !== KTX2_ID[0] ||
3794
- // '´'
3795
- id[1] !== KTX2_ID[1] ||
3796
- // 'K'
3797
- id[2] !== KTX2_ID[2] ||
3798
- // 'T'
3799
- id[3] !== KTX2_ID[3] ||
3800
- // 'X'
3801
- id[4] !== KTX2_ID[4] ||
3802
- // ' '
3803
- id[5] !== KTX2_ID[5] ||
3804
- // '2'
3805
- id[6] !== KTX2_ID[6] ||
3806
- // '0'
3807
- id[7] !== KTX2_ID[7] ||
3808
- // 'ª'
3809
- id[8] !== KTX2_ID[8] ||
3810
- // '\r'
3811
- id[9] !== KTX2_ID[9] ||
3812
- // '\n'
3813
- id[10] !== KTX2_ID[10] ||
3814
- // '\x1A'
3815
- id[11] !== KTX2_ID[11] // '\n'
3816
- ) {
3817
- throw new Error('Missing KTX 2.0 identifier.');
3818
- }
3819
- const container = new KTX2Container();
3820
- ///////////////////////////////////////////////////
3821
- // Header.
3822
- ///////////////////////////////////////////////////
3823
- const headerByteLength = 17 * Uint32Array.BYTES_PER_ELEMENT;
3824
- const headerReader = new BufferReader(data, KTX2_ID.length, headerByteLength, true);
3825
- container.vkFormat = headerReader._nextUint32();
3826
- container.typeSize = headerReader._nextUint32();
3827
- container.pixelWidth = headerReader._nextUint32();
3828
- container.pixelHeight = headerReader._nextUint32();
3829
- container.pixelDepth = headerReader._nextUint32();
3830
- container.layerCount = headerReader._nextUint32();
3831
- container.faceCount = headerReader._nextUint32();
3832
- const levelCount = headerReader._nextUint32();
3833
- container.supercompressionScheme = headerReader._nextUint32();
3834
- const dfdByteOffset = headerReader._nextUint32();
3835
- const dfdByteLength = headerReader._nextUint32();
3836
- const kvdByteOffset = headerReader._nextUint32();
3837
- const kvdByteLength = headerReader._nextUint32();
3838
- const sgdByteOffset = headerReader._nextUint64();
3839
- const sgdByteLength = headerReader._nextUint64();
3840
- ///////////////////////////////////////////////////
3841
- // Level Index.
3842
- ///////////////////////////////////////////////////
3843
- const levelByteLength = levelCount * 3 * 8;
3844
- const levelReader = new BufferReader(data, KTX2_ID.length + headerByteLength, levelByteLength, true);
3845
- for (let i = 0; i < levelCount; i++) {
3846
- container.levels.push({
3847
- levelData: new Uint8Array(data.buffer, data.byteOffset + levelReader._nextUint64(), levelReader._nextUint64()),
3848
- uncompressedByteLength: levelReader._nextUint64()
3849
- });
3850
- }
3851
- ///////////////////////////////////////////////////
3852
- // Data Format Descriptor (DFD).
3853
- ///////////////////////////////////////////////////
3854
- const dfdReader = new BufferReader(data, dfdByteOffset, dfdByteLength, true);
3855
- const dfd = {
3856
- vendorId: dfdReader._skip(4 /* totalSize */)._nextUint16(),
3857
- descriptorType: dfdReader._nextUint16(),
3858
- versionNumber: dfdReader._nextUint16(),
3859
- descriptorBlockSize: dfdReader._nextUint16(),
3860
- colorModel: dfdReader._nextUint8(),
3861
- colorPrimaries: dfdReader._nextUint8(),
3862
- transferFunction: dfdReader._nextUint8(),
3863
- flags: dfdReader._nextUint8(),
3864
- texelBlockDimension: [dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8()],
3865
- bytesPlane: [dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8()],
3866
- samples: []
3867
- };
3868
- const sampleStart = 6;
3869
- const sampleWords = 4;
3870
- const numSamples = (dfd.descriptorBlockSize / 4 - sampleStart) / sampleWords;
3871
- for (let i = 0; i < numSamples; i++) {
3872
- const sample = {
3873
- bitOffset: dfdReader._nextUint16(),
3874
- bitLength: dfdReader._nextUint8(),
3875
- channelType: dfdReader._nextUint8(),
3876
- samplePosition: [dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8()],
3877
- sampleLower: -Infinity,
3878
- sampleUpper: Infinity
3879
- };
3880
- if (sample.channelType & KHR_DF_SAMPLE_DATATYPE_SIGNED) {
3881
- sample.sampleLower = dfdReader._nextInt32();
3882
- sample.sampleUpper = dfdReader._nextInt32();
3883
- } else {
3884
- sample.sampleLower = dfdReader._nextUint32();
3885
- sample.sampleUpper = dfdReader._nextUint32();
3886
- }
3887
- dfd.samples[i] = sample;
3888
- }
3889
- container.dataFormatDescriptor.length = 0;
3890
- container.dataFormatDescriptor.push(dfd);
3891
- ///////////////////////////////////////////////////
3892
- // Key/Value Data (KVD).
3893
- ///////////////////////////////////////////////////
3894
- const kvdReader = new BufferReader(data, kvdByteOffset, kvdByteLength, true);
3895
- while (kvdReader._offset < kvdByteLength) {
3896
- const keyValueByteLength = kvdReader._nextUint32();
3897
- const keyData = kvdReader._scan(keyValueByteLength);
3898
- const key = decodeText(keyData);
3899
- container.keyValue[key] = kvdReader._nextUint8Array(keyValueByteLength - keyData.byteLength - 1);
3900
- if (key.match(/^ktx/i)) {
3901
- const text = decodeText(container.keyValue[key]);
3902
- container.keyValue[key] = text.substring(0, text.lastIndexOf('\x00'));
3608
+ var HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)
3609
+ var COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()
3610
+ //const COMPRESSED_3D = 1; // uses a gl.compressedTexImage3D()
3611
+ var TEX_2D = 2; // uses a gl.texImage2D()
3612
+ //const TEX_3D = 3; // uses a gl.texImage3D()
3613
+ var KhronosTextureContainer = /** @class */ (function () {
3614
+ function KhronosTextureContainer(arrayBuffer, facesExpected, baseOffset) {
3615
+ if (baseOffset === void 0) { baseOffset = 0; }
3616
+ this.arrayBuffer = arrayBuffer;
3617
+ this.baseOffset = baseOffset;
3618
+ // Test that it is a ktx formatted file, based on the first 12 bytes, character representation is:
3619
+ // '´', 'K', 'T', 'X', ' ', '1', '1', 'ª', '\r', '\n', '\x1A', '\n'
3620
+ // 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
3621
+ var identifier = new Uint8Array(this.arrayBuffer, this.baseOffset, 12);
3622
+ if (identifier[0] !== 0xab ||
3623
+ identifier[1] !== 0x4b ||
3624
+ identifier[2] !== 0x54 ||
3625
+ identifier[3] !== 0x58 ||
3626
+ identifier[4] !== 0x20 ||
3627
+ identifier[5] !== 0x31 ||
3628
+ identifier[6] !== 0x31 ||
3629
+ identifier[7] !== 0xbb ||
3630
+ identifier[8] !== 0x0d ||
3631
+ identifier[9] !== 0x0a ||
3632
+ identifier[10] !== 0x1a ||
3633
+ identifier[11] !== 0x0a) {
3634
+ throw Error('texture missing KTX identifier');
3635
+ }
3636
+ // load the reset of the header in native 32 bit uint
3637
+ var dataSize = Uint32Array.BYTES_PER_ELEMENT;
3638
+ var headerDataView = new DataView(this.arrayBuffer, this.baseOffset + 12, 13 * dataSize);
3639
+ var endianness = headerDataView.getUint32(0, true);
3640
+ var littleEndian = endianness === 0x04030201;
3641
+ this.glType = headerDataView.getUint32(1 * dataSize, littleEndian); // must be 0 for compressed textures
3642
+ this.glTypeSize = headerDataView.getUint32(2 * dataSize, littleEndian); // must be 1 for compressed textures
3643
+ this.glFormat = headerDataView.getUint32(3 * dataSize, littleEndian); // must be 0 for compressed textures
3644
+ this.glInternalFormat = headerDataView.getUint32(4 * dataSize, littleEndian); // the value of arg passed to gl.compressedTexImage2D(,,x,,,,)
3645
+ this.glBaseInternalFormat = headerDataView.getUint32(5 * dataSize, littleEndian); // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only)
3646
+ this.pixelWidth = headerDataView.getUint32(6 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,)
3647
+ this.pixelHeight = headerDataView.getUint32(7 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,)
3648
+ this.pixelDepth = headerDataView.getUint32(8 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,)
3649
+ this.numberOfArrayElements = headerDataView.getUint32(9 * dataSize, littleEndian); // used for texture arrays
3650
+ this.numberOfFaces = headerDataView.getUint32(10 * dataSize, littleEndian); // used for cubemap textures, should either be 1 or 6
3651
+ this.numberOfMipmapLevels = headerDataView.getUint32(11 * dataSize, littleEndian); // number of levels; disregard possibility of 0 for compressed textures
3652
+ this.bytesOfKeyValueData = headerDataView.getUint32(12 * dataSize, littleEndian); // the amount of space after the header for meta-data
3653
+ // value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.
3654
+ this.numberOfMipmapLevels = Math.max(1, this.numberOfMipmapLevels);
3655
+ if (this.pixelHeight === 0 || this.pixelDepth !== 0) {
3656
+ //consoleWarn('only 2D textures currently supported');
3657
+ return;
3658
+ }
3659
+ if (this.numberOfArrayElements !== 0) {
3660
+ //consoleWarn('texture arrays not currently supported');
3661
+ return;
3662
+ }
3663
+ if (this.numberOfFaces !== facesExpected) {
3664
+ //consoleWarn('number of faces expected' + facesExpected + ', but found ' + this.numberOfFaces);
3665
+ return;
3666
+ }
3667
+ // we now have a completely validated file, so could use existence of loadType as success
3668
+ // would need to make this more elaborate & adjust checks above to support more than one load type
3669
+ if (this.glType === 0) {
3670
+ this.loadType = COMPRESSED_2D;
3671
+ }
3672
+ else {
3673
+ this.loadType = TEX_2D;
3674
+ }
3903
3675
  }
3904
- const kvPadding = keyValueByteLength % 4 ? 4 - keyValueByteLength % 4 : 0; // align(4)
3905
- // 4-byte alignment.
3906
- kvdReader._skip(kvPadding);
3907
- }
3908
- ///////////////////////////////////////////////////
3909
- // Supercompression Global Data (SGD).
3910
- ///////////////////////////////////////////////////
3911
- if (sgdByteLength <= 0) return container;
3912
- const sgdReader = new BufferReader(data, sgdByteOffset, sgdByteLength, true);
3913
- const endpointCount = sgdReader._nextUint16();
3914
- const selectorCount = sgdReader._nextUint16();
3915
- const endpointsByteLength = sgdReader._nextUint32();
3916
- const selectorsByteLength = sgdReader._nextUint32();
3917
- const tablesByteLength = sgdReader._nextUint32();
3918
- const extendedByteLength = sgdReader._nextUint32();
3919
- const imageDescs = [];
3920
- for (let i = 0; i < levelCount; i++) {
3921
- imageDescs.push({
3922
- imageFlags: sgdReader._nextUint32(),
3923
- rgbSliceByteOffset: sgdReader._nextUint32(),
3924
- rgbSliceByteLength: sgdReader._nextUint32(),
3925
- alphaSliceByteOffset: sgdReader._nextUint32(),
3926
- alphaSliceByteLength: sgdReader._nextUint32()
3927
- });
3928
- }
3929
- const endpointsByteOffset = sgdByteOffset + sgdReader._offset;
3930
- const selectorsByteOffset = endpointsByteOffset + endpointsByteLength;
3931
- const tablesByteOffset = selectorsByteOffset + selectorsByteLength;
3932
- const extendedByteOffset = tablesByteOffset + tablesByteLength;
3933
- const endpointsData = new Uint8Array(data.buffer, data.byteOffset + endpointsByteOffset, endpointsByteLength);
3934
- const selectorsData = new Uint8Array(data.buffer, data.byteOffset + selectorsByteOffset, selectorsByteLength);
3935
- const tablesData = new Uint8Array(data.buffer, data.byteOffset + tablesByteOffset, tablesByteLength);
3936
- const extendedData = new Uint8Array(data.buffer, data.byteOffset + extendedByteOffset, extendedByteLength);
3937
- container.globalData = {
3938
- endpointCount,
3939
- selectorCount,
3940
- imageDescs,
3941
- endpointsData,
3942
- selectorsData,
3943
- tablesData,
3944
- extendedData
3945
- };
3946
- return container;
3947
- }
3948
-
3949
- var _a$2;
3950
- var formatMap = (_a$2 = {},
3951
- _a$2[VK_FORMAT_ASTC_4x4_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR],
3952
- _a$2[VK_FORMAT_ASTC_4x4_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_4x4_KHR],
3953
- _a$2[VK_FORMAT_ASTC_6x6_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR],
3954
- _a$2[VK_FORMAT_ASTC_6x6_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_6x6_KHR],
3955
- _a$2[VK_FORMAT_ASTC_8x8_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR],
3956
- _a$2[VK_FORMAT_ASTC_8x8_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_8x8_KHR],
3957
- _a$2[VK_FORMAT_ASTC_10x10_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR],
3958
- _a$2[VK_FORMAT_ASTC_10x10_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_10x10_KHR],
3959
- _a$2[VK_FORMAT_ASTC_12x12_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR],
3960
- _a$2[VK_FORMAT_ASTC_12x12_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_12x12_KHR],
3961
- _a$2[VK_FORMAT_ASTC_5x5_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR],
3962
- _a$2[VK_FORMAT_ASTC_5x5_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_5x5_KHR],
3963
- _a$2[VK_FORMAT_ASTC_5x4_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR],
3964
- _a$2[VK_FORMAT_ASTC_5x4_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_5x4_KHR],
3965
- _a$2[VK_FORMAT_ASTC_6x5_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR],
3966
- _a$2[VK_FORMAT_ASTC_6x5_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_6x5_KHR],
3967
- _a$2[VK_FORMAT_ASTC_10x5_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR],
3968
- _a$2[VK_FORMAT_ASTC_10x5_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_10x5_KHR],
3969
- _a$2[VK_FORMAT_ASTC_8x6_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR],
3970
- _a$2[VK_FORMAT_ASTC_8x6_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_8x6_KHR],
3971
- _a$2[VK_FORMAT_ASTC_10x6_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR],
3972
- _a$2[VK_FORMAT_ASTC_10x6_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_10x6_KHR],
3973
- _a$2[VK_FORMAT_ASTC_8x5_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR],
3974
- _a$2[VK_FORMAT_ASTC_8x5_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_8x5_KHR],
3975
- _a$2[VK_FORMAT_ASTC_12x10_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR],
3976
- _a$2[VK_FORMAT_ASTC_12x10_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_12x10_KHR],
3977
- _a$2[VK_FORMAT_ASTC_10x8_SRGB_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR],
3978
- _a$2[VK_FORMAT_ASTC_10x8_UNORM_BLOCK] = [constants.UNSIGNED_BYTE, constants.COMPRESSED_RGBA_ASTC_10x8_KHR],
3979
- _a$2);
3676
+ KhronosTextureContainer.prototype.mipmaps = function (loadMipmaps) {
3677
+ var mipmaps = [];
3678
+ // initialize width & height for level 1
3679
+ var dataOffset = HEADER_LEN + this.bytesOfKeyValueData;
3680
+ var width = this.pixelWidth;
3681
+ var height = this.pixelHeight;
3682
+ var mipmapCount = loadMipmaps ? this.numberOfMipmapLevels : 1;
3683
+ for (var level = 0; level < mipmapCount; level++) {
3684
+ var imageSize = new Int32Array(this.arrayBuffer, this.baseOffset + dataOffset, 1)[0]; // size per face, since not supporting array cubemaps
3685
+ for (var face = 0; face < this.numberOfFaces; face++) {
3686
+ var byteArray = new Uint8Array(this.arrayBuffer, this.baseOffset + dataOffset + 4, imageSize);
3687
+ mipmaps.push({
3688
+ data: byteArray,
3689
+ width: width,
3690
+ height: height,
3691
+ });
3692
+ dataOffset += imageSize + 4; // size of the image + 4 for the imageSize field
3693
+ dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image
3694
+ }
3695
+ width = Math.max(1.0, width * 0.5);
3696
+ height = Math.max(1.0, height * 0.5);
3697
+ }
3698
+ return mipmaps;
3699
+ };
3700
+ return KhronosTextureContainer;
3701
+ }());
3980
3702
  function getCompressedTextureOptions(data) {
3981
- var container = read(data);
3982
- var width = container.pixelWidth;
3983
- var height = container.pixelHeight;
3984
- var pair = formatMap[container.vkFormat];
3703
+ var ktx = new KhronosTextureContainer(data, 1);
3704
+ var useMipmaps = ktx.numberOfMipmapLevels >= Math.floor(Math.log2(Math.max(ktx.pixelWidth, ktx.pixelHeight)) + 1);
3985
3705
  return {
3986
3706
  sourceType: exports.TextureSourceType.compressed,
3987
- target: container.faceCount === 6 ? constants.TEXTURE_CUBE_MAP : constants.TEXTURE_2D,
3988
- format: pair[1],
3989
- internalFormat: pair[1],
3990
- type: pair[0],
3991
- mipmaps: container.levels.map(function (level, i) { return ({
3992
- data: level.levelData,
3993
- width: width >> i,
3994
- height: height >> i,
3995
- }); }),
3707
+ type: constants.UNSIGNED_BYTE,
3708
+ target: ktx.numberOfFaces === 6 ? constants.TEXTURE_CUBE_MAP : constants.TEXTURE_2D,
3709
+ format: ktx.glInternalFormat,
3710
+ internalFormat: ktx.glInternalFormat,
3711
+ mipmaps: ktx.mipmaps(useMipmaps),
3996
3712
  };
3997
3713
  }
3998
3714
 
@@ -4083,7 +3799,7 @@ var MarsTextureFactory = /** @class */ (function () {
4083
3799
  }
4084
3800
  else if (sourceFrom.type === exports.TextureSourceType.compressed) {
4085
3801
  return this.requestBinaryAsync(sourceFrom.url).then(function (arrayBuffer) {
4086
- return Object.assign(getCompressedTextureOptions(new Uint8Array(arrayBuffer)), config, {
3802
+ return Object.assign(getCompressedTextureOptions(arrayBuffer), config, {
4087
3803
  sourceFrom: { url: sourceFrom.url, type: exports.TextureSourceType.compressed },
4088
3804
  });
4089
3805
  }, catchError);
@@ -4182,7 +3898,7 @@ var MarsTextureFactory = /** @class */ (function () {
4182
3898
  return Promise.all(map.map(function (key) { return _this.loadImageAsync(key); }));
4183
3899
  };
4184
3900
  MarsTextureFactory.prototype.loadCompressedTextureFromArrayBuffer = function (arrayBuffer, options) {
4185
- return Object.assign(getCompressedTextureOptions(new Uint8Array(arrayBuffer)), options);
3901
+ return Object.assign(getCompressedTextureOptions(arrayBuffer), options);
4186
3902
  };
4187
3903
  MarsTextureFactory.prototype.reloadTextureAsync = function (texture) {
4188
3904
  var _this = this;
@@ -6181,7 +5897,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
6181
5897
  return MarsSharedGeometry;
6182
5898
  }(MarsGeometry));
6183
5899
 
6184
- consoleLog('version: ' + "0.3.0-beta.196");
5900
+ consoleLog('version: ' + "0.3.0-beta.197");
6185
5901
  var ModuleMsg = 'RI Package: @predy-js/render-interface';
6186
5902
 
6187
5903
  var RI = /*#__PURE__*/Object.freeze({