@loaders.gl/textures 3.1.0-alpha.5 → 3.1.0-beta.5
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/basis-loader.d.ts +1 -0
- package/dist/basis-loader.d.ts.map +1 -0
- package/dist/basis-loader.js +40 -0
- package/dist/basis-worker.js +675 -2
- package/dist/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2107 -0
- package/dist/compressed-texture-loader.d.ts +1 -0
- package/dist/compressed-texture-loader.d.ts.map +1 -0
- package/dist/compressed-texture-loader.js +64 -0
- package/dist/compressed-texture-worker.js +1179 -2
- package/dist/compressed-texture-writer.d.ts +1 -0
- package/dist/compressed-texture-writer.d.ts.map +1 -0
- package/dist/compressed-texture-writer.js +28 -0
- package/dist/crunch-loader.d.ts +1 -0
- package/dist/crunch-loader.d.ts.map +1 -0
- package/dist/crunch-loader.js +25 -0
- package/dist/crunch-worker.js +486 -2
- package/dist/es5/index.js +3 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/{gl-constants.js → gl-extensions.js} +4 -4
- package/dist/es5/lib/gl-extensions.js.map +1 -0
- package/dist/es5/lib/parsers/basis-module-loader.js +1 -1
- package/dist/es5/lib/parsers/basis-module-loader.js.map +1 -1
- package/dist/es5/lib/parsers/crunch-module-loader.js.map +1 -1
- package/dist/es5/lib/parsers/parse-basis.js +9 -9
- package/dist/es5/lib/parsers/parse-basis.js.map +1 -1
- package/dist/es5/lib/parsers/parse-crunch.js +4 -4
- package/dist/es5/lib/parsers/parse-crunch.js.map +1 -1
- package/dist/es5/lib/parsers/parse-dds.js +23 -23
- package/dist/es5/lib/parsers/parse-dds.js.map +1 -1
- package/dist/es5/lib/parsers/parse-ktx.js +2 -2
- package/dist/es5/lib/parsers/parse-ktx.js.map +1 -1
- package/dist/es5/lib/parsers/parse-npy.js +3 -1
- package/dist/es5/lib/parsers/parse-npy.js.map +1 -1
- package/dist/es5/lib/parsers/parse-pvr.js +28 -28
- package/dist/es5/lib/parsers/parse-pvr.js.map +1 -1
- package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -1
- package/dist/es5/lib/texture-api/deep-load.js.map +1 -1
- package/dist/es5/lib/texture-api/generate-url.js +4 -12
- package/dist/es5/lib/texture-api/generate-url.js.map +1 -1
- package/dist/es5/lib/texture-api/load-image-array.js.map +1 -1
- package/dist/es5/lib/texture-api/load-image-cube.js.map +1 -1
- package/dist/es5/lib/texture-api/load-image.js +2 -5
- package/dist/es5/lib/texture-api/load-image.js.map +1 -1
- package/dist/es5/lib/texture-api/texture-api-types.js +2 -0
- package/dist/es5/lib/texture-api/texture-api-types.js.map +1 -0
- package/dist/es5/lib/utils/extract-mipmap-images.js.map +1 -1
- package/dist/es5/lib/utils/ktx-format-helper.js +67 -67
- package/dist/es5/lib/utils/ktx-format-helper.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/libs/README.md +2 -2
- package/dist/es5/libs/basis_encoder.js +1 -1
- package/dist/es5/libs/basis_transcoder.js +1 -1
- package/dist/es5/libs/crunch.js +1 -0
- package/dist/es5/npy-loader.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/{gl-constants.js → gl-extensions.js} +2 -2
- package/dist/esm/lib/gl-extensions.js.map +1 -0
- package/dist/esm/lib/parsers/basis-module-loader.js +1 -1
- package/dist/esm/lib/parsers/basis-module-loader.js.map +1 -1
- package/dist/esm/lib/parsers/crunch-module-loader.js.map +1 -1
- package/dist/esm/lib/parsers/parse-basis.js +8 -8
- package/dist/esm/lib/parsers/parse-basis.js.map +1 -1
- package/dist/esm/lib/parsers/parse-crunch.js +4 -4
- package/dist/esm/lib/parsers/parse-crunch.js.map +1 -1
- package/dist/esm/lib/parsers/parse-dds.js +23 -23
- package/dist/esm/lib/parsers/parse-dds.js.map +1 -1
- package/dist/esm/lib/parsers/parse-ktx.js +2 -2
- package/dist/esm/lib/parsers/parse-ktx.js.map +1 -1
- package/dist/esm/lib/parsers/parse-npy.js +3 -1
- package/dist/esm/lib/parsers/parse-npy.js.map +1 -1
- package/dist/esm/lib/parsers/parse-pvr.js +28 -28
- package/dist/esm/lib/parsers/parse-pvr.js.map +1 -1
- package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -1
- package/dist/esm/lib/texture-api/deep-load.js.map +1 -1
- package/dist/esm/lib/texture-api/generate-url.js +5 -13
- package/dist/esm/lib/texture-api/generate-url.js.map +1 -1
- package/dist/esm/lib/texture-api/load-image-array.js.map +1 -1
- package/dist/esm/lib/texture-api/load-image-cube.js.map +1 -1
- package/dist/esm/lib/texture-api/load-image.js +2 -5
- package/dist/esm/lib/texture-api/load-image.js.map +1 -1
- package/dist/esm/lib/texture-api/texture-api-types.js +2 -0
- package/dist/esm/lib/texture-api/texture-api-types.js.map +1 -0
- package/dist/esm/lib/utils/extract-mipmap-images.js.map +1 -1
- package/dist/esm/lib/utils/ktx-format-helper.js +67 -67
- package/dist/esm/lib/utils/ktx-format-helper.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/esm/libs/README.md +2 -2
- package/dist/esm/libs/basis_encoder.js +1 -1
- package/dist/esm/libs/basis_transcoder.js +1 -1
- package/dist/esm/libs/crunch.js +1 -0
- package/dist/esm/npy-loader.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/ktx2-basis-universal-texture-writer.d.ts +1 -0
- package/dist/ktx2-basis-universal-texture-writer.d.ts.map +1 -0
- package/dist/ktx2-basis-universal-texture-writer.js +25 -0
- package/dist/lib/encoders/encode-ktx.d.ts +1 -0
- package/dist/lib/encoders/encode-ktx.d.ts.map +1 -0
- package/dist/lib/encoders/encode-ktx.js +10 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +1 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.js +41 -0
- package/dist/lib/encoders/encode-texture.d.ts +1 -0
- package/dist/lib/encoders/encode-texture.d.ts.map +1 -0
- package/dist/lib/encoders/encode-texture.js +30 -0
- package/dist/lib/{gl-constants.d.ts → gl-extensions.d.ts} +2 -1
- package/dist/lib/gl-extensions.d.ts.map +1 -0
- package/dist/lib/gl-extensions.js +72 -0
- package/dist/lib/parsers/basis-module-loader.d.ts +1 -0
- package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -0
- package/dist/lib/parsers/basis-module-loader.js +114 -0
- package/dist/lib/parsers/crunch-module-loader.d.ts +1 -0
- package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -0
- package/dist/lib/parsers/crunch-module-loader.js +35 -0
- package/dist/lib/parsers/parse-basis.d.ts +1 -0
- package/dist/lib/parsers/parse-basis.d.ts.map +1 -0
- package/dist/lib/parsers/parse-basis.js +245 -0
- package/dist/lib/parsers/parse-compressed-texture.d.ts +1 -0
- package/dist/lib/parsers/parse-compressed-texture.d.ts.map +1 -0
- package/dist/lib/parsers/parse-compressed-texture.js +26 -0
- package/dist/lib/parsers/parse-crunch.d.ts +1 -0
- package/dist/lib/parsers/parse-crunch.d.ts.map +1 -0
- package/dist/lib/parsers/parse-crunch.js +105 -0
- package/dist/lib/parsers/parse-dds.d.ts +1 -0
- package/dist/lib/parsers/parse-dds.d.ts.map +1 -0
- package/dist/lib/parsers/parse-dds.js +108 -0
- package/dist/lib/parsers/parse-ktx.d.ts +3 -2
- package/dist/lib/parsers/parse-ktx.d.ts.map +1 -0
- package/dist/lib/parsers/parse-ktx.js +46 -0
- package/dist/lib/parsers/parse-npy.d.ts +8 -2
- package/dist/lib/parsers/parse-npy.d.ts.map +1 -0
- package/dist/lib/parsers/parse-npy.js +85 -0
- package/dist/lib/parsers/parse-pvr.d.ts +1 -0
- package/dist/lib/parsers/parse-pvr.d.ts.map +1 -0
- package/dist/lib/parsers/parse-pvr.js +250 -0
- package/dist/lib/texture-api/async-deep-map.d.ts +5 -2
- package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
- package/dist/lib/texture-api/async-deep-map.js +41 -0
- package/dist/lib/texture-api/deep-load.d.ts +5 -2
- package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
- package/dist/lib/texture-api/deep-load.js +16 -0
- package/dist/lib/texture-api/generate-url.d.ts +3 -1
- package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
- package/dist/lib/texture-api/generate-url.js +17 -0
- package/dist/lib/texture-api/load-image-array.d.ts +4 -2
- package/dist/lib/texture-api/load-image-array.d.ts.map +1 -0
- package/dist/lib/texture-api/load-image-array.js +21 -0
- package/dist/lib/texture-api/load-image-cube.d.ts +12 -2
- package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -0
- package/dist/lib/texture-api/load-image-cube.js +47 -0
- package/dist/lib/texture-api/load-image.d.ts +7 -5
- package/dist/lib/texture-api/load-image.d.ts.map +1 -0
- package/dist/lib/texture-api/load-image.js +43 -0
- package/dist/lib/texture-api/texture-api-types.d.ts +10 -0
- package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -0
- package/dist/lib/texture-api/texture-api-types.js +3 -0
- package/dist/lib/utils/extract-mipmap-images.d.ts +2 -1
- package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -0
- package/dist/lib/utils/extract-mipmap-images.js +50 -0
- package/dist/lib/utils/ktx-format-helper.d.ts +4 -3
- package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -0
- package/dist/lib/utils/ktx-format-helper.js +125 -0
- package/dist/lib/utils/texture-formats.d.ts +1 -0
- package/dist/lib/utils/texture-formats.d.ts.map +1 -0
- package/dist/lib/utils/texture-formats.js +51 -0
- package/dist/lib/utils/version.d.ts +1 -0
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +8 -0
- package/dist/libs/README.md +2 -2
- package/dist/libs/basis_encoder.js +1 -1
- package/dist/libs/basis_transcoder.js +1 -1
- package/dist/libs/crunch.js +1 -0
- package/dist/npy-loader.d.ts +7 -3
- package/dist/npy-loader.d.ts.map +1 -0
- package/dist/npy-loader.js +34 -0
- package/dist/npy-worker.js +240 -2
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/workers/basis-worker.d.ts +1 -0
- package/dist/workers/basis-worker.d.ts.map +1 -0
- package/dist/workers/basis-worker.js +5 -0
- package/dist/workers/compressed-texture-worker.d.ts +1 -0
- package/dist/workers/compressed-texture-worker.d.ts.map +1 -0
- package/dist/workers/compressed-texture-worker.js +5 -0
- package/dist/workers/crunch-worker.d.ts +1 -0
- package/dist/workers/crunch-worker.d.ts.map +1 -0
- package/dist/workers/crunch-worker.js +14 -0
- package/dist/workers/npy-worker.d.ts +1 -0
- package/dist/workers/npy-worker.d.ts.map +1 -0
- package/dist/workers/npy-worker.js +5 -0
- package/package.json +10 -11
- package/src/index.ts +1 -1
- package/src/lib/{gl-constants.ts → gl-extensions.ts} +1 -1
- package/src/lib/parsers/crunch-module-loader.ts +1 -0
- package/src/lib/parsers/parse-basis.js +32 -8
- package/src/lib/parsers/parse-crunch.ts +4 -4
- package/src/lib/parsers/parse-dds.ts +29 -26
- package/src/lib/parsers/parse-ktx.js +3 -6
- package/src/lib/parsers/parse-ktx.ts +47 -0
- package/src/lib/parsers/parse-npy.js +3 -17
- package/src/lib/parsers/parse-npy.ts +98 -0
- package/src/lib/parsers/parse-pvr.ts +90 -48
- package/src/lib/texture-api/async-deep-map.ts +15 -8
- package/src/lib/texture-api/deep-load.ts +7 -3
- package/src/lib/texture-api/generate-url.ts +10 -8
- package/src/lib/texture-api/load-image-array.ts +8 -2
- package/src/lib/texture-api/load-image-cube.ts +18 -4
- package/src/lib/texture-api/load-image.ts +15 -5
- package/src/lib/texture-api/texture-api-types.ts +12 -0
- package/src/lib/utils/extract-mipmap-images.ts +16 -3
- package/src/lib/utils/ktx-format-helper.ts +71 -71
- package/src/libs/README.md +2 -2
- package/src/libs/basis_encoder.js +1 -1
- package/src/libs/basis_transcoder.js +1 -1
- package/src/libs/crunch.js +1 -0
- package/src/npy-loader.ts +2 -2
- package/dist/basis-worker.js.map +0 -1
- package/dist/compressed-texture-worker.js.map +0 -1
- package/dist/crunch-worker.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/es5/lib/gl-constants.js.map +0 -1
- package/dist/esm/lib/gl-constants.js.map +0 -1
- package/dist/npy-worker.js.map +0 -1
|
@@ -2,10 +2,10 @@ import {TextureLevel} from '../../types';
|
|
|
2
2
|
/* eslint-disable camelcase */
|
|
3
3
|
// Forked from PicoGL: https://github.com/tsherif/picogl.js/blob/master/examples/utils/utils.js
|
|
4
4
|
// Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
|
|
5
|
-
import {
|
|
5
|
+
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
6
6
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
7
7
|
|
|
8
|
-
const PVR_CONSTANTS = {
|
|
8
|
+
const PVR_CONSTANTS: Record<string, number> = {
|
|
9
9
|
MAGIC_NUMBER: 0x03525650,
|
|
10
10
|
MAGIC_NUMBER_EXTRA: 0x50565203,
|
|
11
11
|
HEADER_LENGTH: 13,
|
|
@@ -19,37 +19,79 @@ const PVR_CONSTANTS = {
|
|
|
19
19
|
METADATA_SIZE_INDEX: 12
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const PVR_PIXEL_FORMATS = {
|
|
23
|
-
0: [
|
|
24
|
-
1: [
|
|
25
|
-
2: [
|
|
26
|
-
3: [
|
|
27
|
-
6: [
|
|
28
|
-
7: [
|
|
29
|
-
9: [
|
|
30
|
-
11: [
|
|
31
|
-
22: [
|
|
32
|
-
23: [
|
|
33
|
-
24: [
|
|
34
|
-
25: [
|
|
35
|
-
26: [
|
|
36
|
-
27: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
22
|
+
const PVR_PIXEL_FORMATS: Record<number, number[]> = {
|
|
23
|
+
0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
|
|
24
|
+
1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
|
|
25
|
+
2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
|
|
26
|
+
3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
|
|
27
|
+
6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
|
|
28
|
+
7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
|
|
29
|
+
9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
|
|
30
|
+
11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
|
|
31
|
+
22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
|
|
32
|
+
23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
|
|
33
|
+
24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
|
|
34
|
+
25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
|
|
35
|
+
26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
|
|
36
|
+
27: [
|
|
37
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
|
|
38
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
|
|
39
|
+
],
|
|
40
|
+
28: [
|
|
41
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
|
|
42
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
|
|
43
|
+
],
|
|
44
|
+
29: [
|
|
45
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
|
|
46
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
|
|
47
|
+
],
|
|
48
|
+
30: [
|
|
49
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
|
|
50
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
|
|
51
|
+
],
|
|
52
|
+
31: [
|
|
53
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
|
|
54
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
|
|
55
|
+
],
|
|
56
|
+
32: [
|
|
57
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
|
|
58
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
|
|
59
|
+
],
|
|
60
|
+
33: [
|
|
61
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
|
|
62
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
|
|
63
|
+
],
|
|
64
|
+
34: [
|
|
65
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
|
|
66
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
|
|
67
|
+
],
|
|
68
|
+
35: [
|
|
69
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
|
|
70
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
|
|
71
|
+
],
|
|
72
|
+
36: [
|
|
73
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
|
|
74
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
|
|
75
|
+
],
|
|
76
|
+
37: [
|
|
77
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
|
|
78
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
|
|
79
|
+
],
|
|
80
|
+
38: [
|
|
81
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
|
|
82
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
|
|
83
|
+
],
|
|
84
|
+
39: [
|
|
85
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
|
|
86
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
|
|
87
|
+
],
|
|
88
|
+
40: [
|
|
89
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
|
|
90
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
|
|
91
|
+
]
|
|
50
92
|
};
|
|
51
93
|
|
|
52
|
-
const PVR_SIZE_FUNCTIONS = {
|
|
94
|
+
const PVR_SIZE_FUNCTIONS: Record<number, (width: number, height: number) => number> = {
|
|
53
95
|
0: pvrtc2bppSize,
|
|
54
96
|
1: pvrtc2bppSize,
|
|
55
97
|
2: pvrtc4bppSize,
|
|
@@ -126,7 +168,7 @@ export function parsePVR(data: ArrayBuffer): TextureLevel[] {
|
|
|
126
168
|
}
|
|
127
169
|
|
|
128
170
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
|
|
129
|
-
function pvrtc2bppSize(width, height) {
|
|
171
|
+
function pvrtc2bppSize(width: number, height: number): number {
|
|
130
172
|
width = Math.max(width, 16);
|
|
131
173
|
height = Math.max(height, 8);
|
|
132
174
|
|
|
@@ -134,7 +176,7 @@ function pvrtc2bppSize(width, height) {
|
|
|
134
176
|
}
|
|
135
177
|
|
|
136
178
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/
|
|
137
|
-
function pvrtc4bppSize(width, height) {
|
|
179
|
+
function pvrtc4bppSize(width: number, height: number): number {
|
|
138
180
|
width = Math.max(width, 8);
|
|
139
181
|
height = Math.max(height, 8);
|
|
140
182
|
|
|
@@ -151,7 +193,7 @@ function pvrtc4bppSize(width, height) {
|
|
|
151
193
|
// COMPRESSED_SRGB8_ETC2
|
|
152
194
|
// COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
|
|
153
195
|
// COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
|
|
154
|
-
function dxtEtcSmallSize(width, height) {
|
|
196
|
+
function dxtEtcSmallSize(width: number, height: number): number {
|
|
155
197
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 8;
|
|
156
198
|
}
|
|
157
199
|
|
|
@@ -166,71 +208,71 @@ function dxtEtcSmallSize(width, height) {
|
|
|
166
208
|
// COMPRESSED_RGBA8_ETC2_EAC
|
|
167
209
|
// COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
|
|
168
210
|
// COMPRESSED_RGBA_ASTC_4x4_KHR
|
|
169
|
-
function dxtEtcAstcBigSize(width, height) {
|
|
211
|
+
function dxtEtcAstcBigSize(width: number, height: number): number {
|
|
170
212
|
return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
|
|
171
213
|
}
|
|
172
214
|
|
|
173
215
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
174
|
-
function atc5x4Size(width, height) {
|
|
216
|
+
function atc5x4Size(width: number, height: number): number {
|
|
175
217
|
return Math.floor((width + 4) / 5) * Math.floor((height + 3) / 4) * 16;
|
|
176
218
|
}
|
|
177
219
|
|
|
178
220
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
179
|
-
function atc5x5Size(width, height) {
|
|
221
|
+
function atc5x5Size(width: number, height: number): number {
|
|
180
222
|
return Math.floor((width + 4) / 5) * Math.floor((height + 4) / 5) * 16;
|
|
181
223
|
}
|
|
182
224
|
|
|
183
225
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
184
|
-
function atc6x5Size(width, height) {
|
|
226
|
+
function atc6x5Size(width: number, height: number): number {
|
|
185
227
|
return Math.floor((width + 5) / 6) * Math.floor((height + 4) / 5) * 16;
|
|
186
228
|
}
|
|
187
229
|
|
|
188
230
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
189
|
-
function atc6x6Size(width, height) {
|
|
231
|
+
function atc6x6Size(width: number, height: number): number {
|
|
190
232
|
return Math.floor((width + 5) / 6) * Math.floor((height + 5) / 6) * 16;
|
|
191
233
|
}
|
|
192
234
|
|
|
193
235
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
194
|
-
function atc8x5Size(width, height) {
|
|
236
|
+
function atc8x5Size(width: number, height: number): number {
|
|
195
237
|
return Math.floor((width + 7) / 8) * Math.floor((height + 4) / 5) * 16;
|
|
196
238
|
}
|
|
197
239
|
|
|
198
240
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
199
|
-
function atc8x6Size(width, height) {
|
|
241
|
+
function atc8x6Size(width: number, height: number): number {
|
|
200
242
|
return Math.floor((width + 7) / 8) * Math.floor((height + 5) / 6) * 16;
|
|
201
243
|
}
|
|
202
244
|
|
|
203
245
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
204
|
-
function atc8x8Size(width, height) {
|
|
246
|
+
function atc8x8Size(width: number, height: number): number {
|
|
205
247
|
return Math.floor((width + 7) / 8) * Math.floor((height + 7) / 8) * 16;
|
|
206
248
|
}
|
|
207
249
|
|
|
208
250
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
209
|
-
function atc10x5Size(width, height) {
|
|
251
|
+
function atc10x5Size(width: number, height: number): number {
|
|
210
252
|
return Math.floor((width + 9) / 10) * Math.floor((height + 4) / 5) * 16;
|
|
211
253
|
}
|
|
212
254
|
|
|
213
255
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
214
|
-
function atc10x6Size(width, height) {
|
|
256
|
+
function atc10x6Size(width: number, height: number): number {
|
|
215
257
|
return Math.floor((width + 9) / 10) * Math.floor((height + 5) / 6) * 16;
|
|
216
258
|
}
|
|
217
259
|
|
|
218
260
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
219
|
-
function atc10x8Size(width, height) {
|
|
261
|
+
function atc10x8Size(width: number, height: number): number {
|
|
220
262
|
return Math.floor((width + 9) / 10) * Math.floor((height + 7) / 8) * 16;
|
|
221
263
|
}
|
|
222
264
|
|
|
223
265
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
224
|
-
function atc10x10Size(width, height) {
|
|
266
|
+
function atc10x10Size(width: number, height: number): number {
|
|
225
267
|
return Math.floor((width + 9) / 10) * Math.floor((height + 9) / 10) * 16;
|
|
226
268
|
}
|
|
227
269
|
|
|
228
270
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
229
|
-
function atc12x10Size(width, height) {
|
|
271
|
+
function atc12x10Size(width: number, height: number): number {
|
|
230
272
|
return Math.floor((width + 11) / 12) * Math.floor((height + 9) / 10) * 16;
|
|
231
273
|
}
|
|
232
274
|
|
|
233
275
|
// https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
|
|
234
|
-
function atc12x12Size(width, height) {
|
|
276
|
+
function atc12x12Size(width: number, height: number): number {
|
|
235
277
|
return Math.floor((width + 11) / 12) * Math.floor((height + 11) / 12) * 16;
|
|
236
278
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
/*
|
|
2
3
|
Asynchronously maps a deep structure of values (e.g. objects and arrays of urls).
|
|
3
4
|
|
|
@@ -13,35 +14,41 @@ E.g. a mipmapped cubemap
|
|
|
13
14
|
]
|
|
14
15
|
}
|
|
15
16
|
*/
|
|
17
|
+
export type Options = Record<string, any>;
|
|
18
|
+
export type Func = (url: string, options: Options) => unknown;
|
|
16
19
|
|
|
17
|
-
const isObject = (value) => value && typeof value === 'object';
|
|
20
|
+
const isObject = (value: any): boolean => value && typeof value === 'object';
|
|
18
21
|
|
|
19
22
|
// Loads a deep structure of urls (objects and arrays of urls)
|
|
20
23
|
// Returns an object with six key-value pairs containing the images (or image mip arrays)
|
|
21
24
|
// for each cube face
|
|
22
|
-
export async function asyncDeepMap(tree, func, options = {}) {
|
|
25
|
+
export async function asyncDeepMap(tree: unknown, func: Func, options: Options = {}) {
|
|
23
26
|
return await mapSubtree(tree, func, options);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
export async function mapSubtree(object, func, options) {
|
|
29
|
+
export async function mapSubtree(object: unknown, func: Func, options: Options) {
|
|
27
30
|
if (Array.isArray(object)) {
|
|
28
31
|
return await mapArray(object, func, options);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
if (isObject(object)) {
|
|
32
|
-
return await mapObject(object, func, options);
|
|
35
|
+
return await mapObject(object as object, func, options);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
// TODO - ignore non-urls, non-arraybuffers?
|
|
36
|
-
const url = object;
|
|
39
|
+
const url = object as string;
|
|
37
40
|
return await func(url, options);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
// HELPERS
|
|
41
44
|
|
|
42
|
-
async function mapObject(
|
|
45
|
+
async function mapObject(
|
|
46
|
+
object: Record<string, any>,
|
|
47
|
+
func: Func,
|
|
48
|
+
options: Options
|
|
49
|
+
): Promise<Record<string, any>> {
|
|
43
50
|
const promises: Promise<any>[] = [];
|
|
44
|
-
const values = {};
|
|
51
|
+
const values: Record<string, any> = {};
|
|
45
52
|
|
|
46
53
|
for (const key in object) {
|
|
47
54
|
const url = object[key];
|
|
@@ -56,7 +63,7 @@ async function mapObject(object, func, options) {
|
|
|
56
63
|
return values;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
async function mapArray(urlArray, func, options = {}) {
|
|
66
|
+
async function mapArray(urlArray: string[], func: Func, options = {}): Promise<any[]> {
|
|
60
67
|
const promises = urlArray.map((url) => mapSubtree(url, func, options));
|
|
61
68
|
return await Promise.all(promises);
|
|
62
69
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
import {asyncDeepMap} from './async-deep-map';
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
|
|
4
|
+
export type LoadOptions = Record<string, any>;
|
|
5
|
+
export type Load = (data: ArrayBuffer, options: Record<string, any>) => Promise<any>;
|
|
6
|
+
|
|
7
|
+
export async function deepLoad(urlTree: unknown, load: Load, options: LoadOptions) {
|
|
8
|
+
return await asyncDeepMap(urlTree, (url: string) => shallowLoad(url, load, options));
|
|
5
9
|
}
|
|
6
10
|
|
|
7
|
-
export async function shallowLoad(url, load, options) {
|
|
11
|
+
export async function shallowLoad(url: string, load: Load, options: LoadOptions): Promise<any> {
|
|
8
12
|
// console.error('loading', url);
|
|
9
13
|
const response = await fetch(url, options.fetch);
|
|
10
14
|
const arrayBuffer = await response.arrayBuffer();
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
import {resolvePath} from '@loaders.gl/loader-utils';
|
|
3
|
+
import type {GetUrl, UrlOptions} from './texture-api-types';
|
|
2
4
|
|
|
3
5
|
// Generate a url by calling getUrl with mix of options, applying options.baseUrl
|
|
4
|
-
export function generateUrl(
|
|
6
|
+
export function generateUrl(
|
|
7
|
+
getUrl: string | GetUrl,
|
|
8
|
+
options: UrlOptions,
|
|
9
|
+
urlOptions: Record<string, any>
|
|
10
|
+
): string {
|
|
5
11
|
// Get url
|
|
6
|
-
let url = getUrl;
|
|
7
|
-
if (typeof getUrl === 'function') {
|
|
8
|
-
url = getUrl({...options, ...urlOptions});
|
|
9
|
-
}
|
|
10
|
-
assert(typeof url === 'string');
|
|
12
|
+
let url = typeof getUrl === 'function' ? getUrl({...options, ...urlOptions}) : getUrl;
|
|
11
13
|
|
|
12
14
|
// Apply options.baseUrl
|
|
13
|
-
const
|
|
15
|
+
const baseUrl = options.baseUrl;
|
|
14
16
|
if (baseUrl) {
|
|
15
17
|
url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`;
|
|
16
18
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
import {ImageLoader} from '@loaders.gl/images';
|
|
3
|
+
import type {GetUrl} from './texture-api-types';
|
|
2
4
|
import {getImageUrls} from './load-image';
|
|
3
5
|
import {deepLoad} from './deep-load';
|
|
4
6
|
|
|
5
|
-
export async function loadImageTextureArray(
|
|
7
|
+
export async function loadImageTextureArray(
|
|
8
|
+
count: number,
|
|
9
|
+
getUrl: GetUrl,
|
|
10
|
+
options = {}
|
|
11
|
+
): Promise<any> {
|
|
6
12
|
const imageUrls = await getImageArrayUrls(count, getUrl, options);
|
|
7
13
|
return await deepLoad(imageUrls, ImageLoader.parse, options);
|
|
8
14
|
}
|
|
9
15
|
|
|
10
|
-
export async function getImageArrayUrls(count, getUrl, options = {}) {
|
|
16
|
+
export async function getImageArrayUrls(count: number, getUrl: GetUrl, options = {}): Promise<any> {
|
|
11
17
|
const promises: Promise<any>[] = [];
|
|
12
18
|
for (let index = 0; index < count; index++) {
|
|
13
19
|
const promise = getImageUrls(getUrl, options, {index});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
import {ImageLoader} from '@loaders.gl/images';
|
|
3
|
+
import type {GetUrl, UrlOptions} from './texture-api-types';
|
|
2
4
|
import {getImageUrls} from './load-image';
|
|
3
5
|
import {deepLoad} from './deep-load';
|
|
4
6
|
|
|
@@ -19,11 +21,20 @@ const CUBE_FACES = [
|
|
|
19
21
|
{face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, direction: 'back', axis: 'z', sign: 'negative'}
|
|
20
22
|
];
|
|
21
23
|
|
|
24
|
+
export type ImageCubeTexture = {
|
|
25
|
+
GL_TEXTURE_CUBE_MAP_POSITIVE_X: any;
|
|
26
|
+
GL_TEXTURE_CUBE_MAP_NEGATIVE_X: any;
|
|
27
|
+
GL_TEXTURE_CUBE_MAP_POSITIVE_Y: any;
|
|
28
|
+
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: any;
|
|
29
|
+
GL_TEXTURE_CUBE_MAP_POSITIVE_Z: any;
|
|
30
|
+
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: any;
|
|
31
|
+
};
|
|
32
|
+
|
|
22
33
|
// Returns an object with six key-value pairs containing the urls (or url mip arrays)
|
|
23
34
|
// for each cube face
|
|
24
|
-
export async function getImageCubeUrls(getUrl, options) {
|
|
35
|
+
export async function getImageCubeUrls(getUrl: GetUrl, options: UrlOptions) {
|
|
25
36
|
// Calculate URLs
|
|
26
|
-
const urls = {};
|
|
37
|
+
const urls: Record<number, string | string[]> = {};
|
|
27
38
|
const promises: Promise<any>[] = [];
|
|
28
39
|
|
|
29
40
|
let index = 0;
|
|
@@ -42,7 +53,10 @@ export async function getImageCubeUrls(getUrl, options) {
|
|
|
42
53
|
|
|
43
54
|
// Returns an object with six key-value pairs containing the images (or image mip arrays)
|
|
44
55
|
// for each cube face
|
|
45
|
-
export async function loadImageTextureCube(
|
|
56
|
+
export async function loadImageTextureCube(
|
|
57
|
+
getUrl: GetUrl,
|
|
58
|
+
options = {}
|
|
59
|
+
): Promise<ImageCubeTexture> {
|
|
46
60
|
const urls = await getImageCubeUrls(getUrl, options);
|
|
47
|
-
return await deepLoad(urls, ImageLoader.parse, options);
|
|
61
|
+
return (await deepLoad(urls, ImageLoader.parse, options)) as ImageCubeTexture;
|
|
48
62
|
}
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import {assert} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {ImageLoader, getImageSize} from '@loaders.gl/images';
|
|
3
|
+
import type {GetUrl, UrlOptions} from './texture-api-types';
|
|
3
4
|
import {generateUrl} from './generate-url';
|
|
4
5
|
import {deepLoad, shallowLoad} from './deep-load';
|
|
5
6
|
|
|
6
|
-
export async function loadImageTexture(getUrl, options = {}) {
|
|
7
|
+
export async function loadImageTexture(getUrl: string | GetUrl, options = {}): Promise<any> {
|
|
7
8
|
const imageUrls = await getImageUrls(getUrl, options);
|
|
8
9
|
return await deepLoad(imageUrls, ImageLoader.parse, options);
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export async function getImageUrls(
|
|
12
|
+
export async function getImageUrls(
|
|
13
|
+
getUrl: string | GetUrl,
|
|
14
|
+
options: any,
|
|
15
|
+
urlOptions: UrlOptions = {}
|
|
16
|
+
): Promise<any> {
|
|
12
17
|
const mipLevels = (options && options.image && options.image.mipLevels) || 0;
|
|
13
18
|
return mipLevels !== 0
|
|
14
19
|
? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)
|
|
15
20
|
: generateUrl(getUrl, options, urlOptions);
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
async function getMipmappedImageUrls(
|
|
23
|
+
async function getMipmappedImageUrls(
|
|
24
|
+
getUrl: string | GetUrl,
|
|
25
|
+
mipLevels: number | 'auto',
|
|
26
|
+
options: any,
|
|
27
|
+
urlOptions: UrlOptions
|
|
28
|
+
): Promise<string[]> {
|
|
19
29
|
const urls: string[] = [];
|
|
20
30
|
|
|
21
31
|
// If no mip levels supplied, we need to load the level 0 image and calculate based on size
|
|
@@ -42,6 +52,6 @@ async function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions): Pr
|
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
// Calculates number of mipmaps based on texture size (log2)
|
|
45
|
-
export function getMipLevels({width
|
|
46
|
-
return 1 + Math.floor(Math.log2(Math.max(width, height)));
|
|
55
|
+
export function getMipLevels(size: {width: number; height: number}): number {
|
|
56
|
+
return 1 + Math.floor(Math.log2(Math.max(size.width, size.height)));
|
|
47
57
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
export type {ImageType} from '@loaders.gl/images';
|
|
4
|
+
|
|
5
|
+
export type UrlOptions = {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
index?: number;
|
|
8
|
+
face?: number;
|
|
9
|
+
lod?: number;
|
|
10
|
+
direction?: string;
|
|
11
|
+
};
|
|
12
|
+
export type GetUrl = (options: UrlOptions) => string;
|
|
@@ -11,7 +11,7 @@ import {CompressedTextureExtractOptions, TextureLevel} from '../../types';
|
|
|
11
11
|
* @returns Array of the texture levels
|
|
12
12
|
*/
|
|
13
13
|
export function extractMipmapImages(
|
|
14
|
-
data: Uint8Array |
|
|
14
|
+
data: Uint8Array | object[],
|
|
15
15
|
options: CompressedTextureExtractOptions
|
|
16
16
|
): TextureLevel[] {
|
|
17
17
|
const images = new Array(options.mipMapLevels);
|
|
@@ -21,7 +21,9 @@ export function extractMipmapImages(
|
|
|
21
21
|
let offset = 0;
|
|
22
22
|
|
|
23
23
|
for (let i = 0; i < options.mipMapLevels; ++i) {
|
|
24
|
+
// @ts-expect-error
|
|
24
25
|
const levelSize = getLevelSize(options, levelWidth, levelHeight, data, i);
|
|
26
|
+
// @ts-expect-error
|
|
25
27
|
const levelData = getLevelData(data, i, offset, levelSize);
|
|
26
28
|
|
|
27
29
|
images[i] = {
|
|
@@ -41,7 +43,12 @@ export function extractMipmapImages(
|
|
|
41
43
|
return images;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
function getLevelData(
|
|
46
|
+
function getLevelData(
|
|
47
|
+
data: Uint8Array,
|
|
48
|
+
index: number,
|
|
49
|
+
offset: number,
|
|
50
|
+
levelSize: number
|
|
51
|
+
): Uint8Array {
|
|
45
52
|
if (!Array.isArray(data)) {
|
|
46
53
|
return new Uint8Array(data.buffer, data.byteOffset + offset, levelSize);
|
|
47
54
|
}
|
|
@@ -49,7 +56,13 @@ function getLevelData(data, index, offset, levelSize) {
|
|
|
49
56
|
return data[index].levelData;
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
function getLevelSize(
|
|
59
|
+
function getLevelSize(
|
|
60
|
+
options: CompressedTextureExtractOptions,
|
|
61
|
+
levelWidth: number,
|
|
62
|
+
levelHeight: number,
|
|
63
|
+
data: Uint8Array[] | object[],
|
|
64
|
+
index: number
|
|
65
|
+
): number {
|
|
53
66
|
if (!Array.isArray(data)) {
|
|
54
67
|
return options.sizeFunction(levelWidth, levelHeight);
|
|
55
68
|
}
|