@loaders.gl/textures 4.4.0-alpha.2 → 4.4.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 +197 -1
- package/dist/basis-loader.d.ts +15 -10
- package/dist/basis-loader.d.ts.map +1 -1
- package/dist/basis-loader.js +1 -1
- package/dist/basis-loader.js.map +1 -0
- package/dist/basis-worker-node.js +932 -10040
- package/dist/basis-worker.d.ts +2 -0
- package/dist/basis-worker.d.ts.map +1 -0
- package/dist/basis-worker.js +337 -151
- package/dist/basis-worker.js.map +1 -0
- package/dist/compressed-texture-loader.d.ts +2 -5
- package/dist/compressed-texture-loader.d.ts.map +1 -1
- package/dist/compressed-texture-loader.js +2 -3
- package/dist/compressed-texture-loader.js.map +1 -0
- package/dist/compressed-texture-worker.d.ts +2 -0
- package/dist/compressed-texture-worker.d.ts.map +1 -0
- package/dist/compressed-texture-worker.js +1148 -365
- package/dist/compressed-texture-worker.js.map +1 -0
- package/dist/compressed-texture-writer.js +1 -0
- package/dist/compressed-texture-writer.js.map +1 -0
- package/dist/crunch-loader.d.ts +1 -5
- package/dist/crunch-loader.d.ts.map +1 -1
- package/dist/crunch-loader.js +2 -3
- package/dist/crunch-loader.js.map +1 -0
- package/dist/crunch-worker.d.ts +2 -0
- package/dist/crunch-worker.d.ts.map +1 -0
- package/dist/crunch-worker.js +204 -92
- package/dist/crunch-worker.js.map +1 -0
- package/dist/dist.dev.js +2687 -677
- package/dist/dist.min.js +1 -2
- package/dist/index.cjs +1644 -428
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -0
- package/dist/ktx2-basis-writer-worker-node.js +574 -9832
- package/dist/ktx2-basis-writer-worker.d.ts +2 -0
- package/dist/ktx2-basis-writer-worker.d.ts.map +1 -0
- package/dist/ktx2-basis-writer-worker.js +45 -7
- package/dist/ktx2-basis-writer-worker.js.map +1 -0
- package/dist/ktx2-basis-writer.js +1 -0
- package/dist/ktx2-basis-writer.js.map +1 -0
- package/dist/lib/composite-image/image-texture-cube.d.ts +47 -0
- package/dist/lib/composite-image/image-texture-cube.d.ts.map +1 -0
- package/dist/lib/composite-image/image-texture-cube.js +42 -0
- package/dist/lib/composite-image/image-texture-cube.js.map +1 -0
- package/dist/lib/composite-image/parse-composite-image.d.ts +43 -0
- package/dist/lib/composite-image/parse-composite-image.d.ts.map +1 -0
- package/dist/lib/composite-image/parse-composite-image.js +437 -0
- package/dist/lib/composite-image/parse-composite-image.js.map +1 -0
- package/dist/lib/encoders/encode-ktx.d.ts +1 -1
- package/dist/lib/encoders/encode-ktx.d.ts.map +1 -1
- package/dist/lib/encoders/encode-ktx.js +1 -0
- package/dist/lib/encoders/encode-ktx.js.map +1 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +2 -1
- package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -1
- package/dist/lib/encoders/encode-ktx2-basis-texture.js +3 -1
- package/dist/lib/encoders/encode-ktx2-basis-texture.js.map +1 -0
- package/dist/lib/encoders/encode-texture.js +1 -0
- package/dist/lib/encoders/encode-texture.js.map +1 -0
- package/dist/lib/gl-extensions.d.ts +166 -58
- package/dist/lib/gl-extensions.d.ts.map +1 -1
- package/dist/lib/gl-extensions.js +178 -66
- package/dist/lib/gl-extensions.js.map +1 -0
- package/dist/lib/gl-types.d.ts +4 -0
- package/dist/lib/gl-types.d.ts.map +1 -0
- package/dist/lib/gl-types.js +5 -0
- package/dist/lib/gl-types.js.map +1 -0
- package/dist/lib/parsers/basis-module-loader.d.ts +3 -2
- package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -1
- package/dist/lib/parsers/basis-module-loader.js +1 -0
- package/dist/lib/parsers/basis-module-loader.js.map +1 -0
- package/dist/lib/parsers/crunch-module-loader.d.ts +2 -2
- package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -1
- package/dist/lib/parsers/crunch-module-loader.js +1 -0
- package/dist/lib/parsers/crunch-module-loader.js.map +1 -0
- package/dist/lib/parsers/parse-basis.d.ts +34 -2
- package/dist/lib/parsers/parse-basis.d.ts.map +1 -1
- package/dist/lib/parsers/parse-basis.js +265 -64
- package/dist/lib/parsers/parse-basis.js.map +1 -0
- package/dist/lib/parsers/parse-compressed-texture.js +1 -0
- package/dist/lib/parsers/parse-compressed-texture.js.map +1 -0
- package/dist/lib/parsers/parse-crunch.d.ts.map +1 -1
- package/dist/lib/parsers/parse-crunch.js +7 -6
- package/dist/lib/parsers/parse-crunch.js.map +1 -0
- package/dist/lib/parsers/parse-dds.d.ts.map +1 -1
- package/dist/lib/parsers/parse-dds.js +11 -11
- package/dist/lib/parsers/parse-dds.js.map +1 -0
- package/dist/lib/parsers/parse-hdr.d.ts +21 -0
- package/dist/lib/parsers/parse-hdr.d.ts.map +1 -0
- package/dist/lib/parsers/parse-hdr.js +305 -0
- package/dist/lib/parsers/parse-hdr.js.map +1 -0
- package/dist/lib/parsers/parse-ktx.d.ts.map +1 -1
- package/dist/lib/parsers/parse-ktx.js +11 -3
- package/dist/lib/parsers/parse-ktx.js.map +1 -0
- package/dist/lib/parsers/parse-npy.js +1 -0
- package/dist/lib/parsers/parse-npy.js.map +1 -0
- package/dist/lib/parsers/parse-pvr.d.ts.map +1 -1
- package/dist/lib/parsers/parse-pvr.js +32 -74
- package/dist/lib/parsers/parse-pvr.js.map +1 -0
- package/dist/lib/texture-api/async-deep-map.js +1 -0
- package/dist/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/lib/texture-api/deep-load.js +1 -0
- package/dist/lib/texture-api/deep-load.js.map +1 -0
- package/dist/lib/texture-api/generate-url.d.ts.map +1 -1
- package/dist/lib/texture-api/generate-url.js +3 -10
- package/dist/lib/texture-api/generate-url.js.map +1 -0
- package/dist/lib/texture-api/load-image-array.d.ts +6 -3
- package/dist/lib/texture-api/load-image-array.d.ts.map +1 -1
- package/dist/lib/texture-api/load-image-array.js +6 -3
- package/dist/lib/texture-api/load-image-array.js.map +1 -0
- package/dist/lib/texture-api/load-image-cube.d.ts +7 -11
- package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -1
- package/dist/lib/texture-api/load-image-cube.js +9 -20
- package/dist/lib/texture-api/load-image-cube.js.map +1 -0
- package/dist/lib/texture-api/load-image.d.ts +6 -3
- package/dist/lib/texture-api/load-image.d.ts.map +1 -1
- package/dist/lib/texture-api/load-image.js +9 -4
- package/dist/lib/texture-api/load-image.js.map +1 -0
- package/dist/lib/texture-api/texture-api-types.d.ts +13 -0
- package/dist/lib/texture-api/texture-api-types.d.ts.map +1 -1
- package/dist/lib/texture-api/texture-api-types.js +1 -0
- package/dist/lib/texture-api/texture-api-types.js.map +1 -0
- package/dist/lib/utils/detect-supported-texture-formats.d.ts +14 -0
- package/dist/lib/utils/detect-supported-texture-formats.d.ts.map +1 -0
- package/dist/lib/utils/detect-supported-texture-formats.js +197 -0
- package/dist/lib/utils/detect-supported-texture-formats.js.map +1 -0
- package/dist/lib/utils/extract-mipmap-images.d.ts +6 -2
- package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -1
- package/dist/lib/utils/extract-mipmap-images.js +14 -2
- package/dist/lib/utils/extract-mipmap-images.js.map +1 -0
- package/dist/lib/utils/ktx-format-helper.d.ts +9 -1
- package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -1
- package/dist/lib/utils/ktx-format-helper.js +77 -109
- package/dist/lib/utils/ktx-format-helper.js.map +1 -0
- package/dist/lib/utils/texture-format-map.d.ts +10 -0
- package/dist/lib/utils/texture-format-map.d.ts.map +1 -0
- package/dist/lib/utils/texture-format-map.js +87 -0
- package/dist/lib/utils/texture-format-map.js.map +1 -0
- package/dist/lib/utils/version.js +2 -1
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/libs/libs/README.md +9 -0
- package/dist/libs/libs/basis_encoder.js +21 -0
- package/dist/libs/libs/basis_encoder.wasm +0 -0
- package/dist/libs/libs/basis_transcoder.js +22 -0
- package/dist/libs/libs/basis_transcoder.wasm +0 -0
- package/dist/libs/libs/crunch.js +136 -0
- package/dist/npy-loader.d.ts +2 -2
- package/dist/npy-loader.js +1 -0
- package/dist/npy-loader.js.map +1 -0
- package/dist/npy-worker.d.ts +2 -0
- package/dist/npy-worker.d.ts.map +1 -0
- package/dist/npy-worker.js +5 -2
- package/dist/npy-worker.js.map +1 -0
- package/dist/radiance-hdr-loader.d.ts +25 -0
- package/dist/radiance-hdr-loader.d.ts.map +1 -0
- package/dist/radiance-hdr-loader.js +23 -0
- package/dist/radiance-hdr-loader.js.map +1 -0
- package/dist/texture-array-loader.d.ts +25 -0
- package/dist/texture-array-loader.d.ts.map +1 -0
- package/dist/texture-array-loader.js +24 -0
- package/dist/texture-array-loader.js.map +1 -0
- package/dist/texture-cube-array-loader.d.ts +25 -0
- package/dist/texture-cube-array-loader.d.ts.map +1 -0
- package/dist/texture-cube-array-loader.js +24 -0
- package/dist/texture-cube-array-loader.js.map +1 -0
- package/dist/texture-cube-loader.d.ts +25 -0
- package/dist/texture-cube-loader.d.ts.map +1 -0
- package/dist/texture-cube-loader.js +24 -0
- package/dist/texture-cube-loader.js.map +1 -0
- package/dist/texture-loader.d.ts +25 -0
- package/dist/texture-loader.d.ts.map +1 -0
- package/dist/texture-loader.js +24 -0
- package/dist/texture-loader.js.map +1 -0
- package/dist/workers/basis-worker-node.js +1 -0
- package/dist/workers/basis-worker-node.js.map +1 -0
- package/dist/workers/basis-worker.js +1 -0
- package/dist/workers/basis-worker.js.map +1 -0
- package/dist/workers/compressed-texture-worker.js +1 -1
- package/dist/workers/compressed-texture-worker.js.map +1 -0
- package/dist/workers/crunch-worker.d.ts +1 -3
- package/dist/workers/crunch-worker.d.ts.map +1 -1
- package/dist/workers/crunch-worker.js +1 -0
- package/dist/workers/crunch-worker.js.map +1 -0
- package/dist/workers/ktx2-basis-writer-worker-node.js +1 -0
- package/dist/workers/ktx2-basis-writer-worker-node.js.map +1 -0
- package/dist/workers/ktx2-basis-writer-worker.js +1 -0
- package/dist/workers/ktx2-basis-writer-worker.js.map +1 -0
- package/dist/workers/npy-worker.js +1 -0
- package/dist/workers/npy-worker.js.map +1 -0
- package/package.json +27 -6
- package/src/basis-loader.ts +19 -9
- package/src/basis-worker.ts +7 -0
- package/src/compressed-texture-loader.ts +3 -7
- package/src/compressed-texture-worker.ts +6 -0
- package/src/crunch-loader.ts +1 -5
- package/src/crunch-worker.ts +6 -0
- package/src/index.ts +21 -4
- package/src/ktx2-basis-writer-worker.ts +6 -0
- package/src/lib/composite-image/image-texture-cube.ts +49 -0
- package/src/lib/composite-image/parse-composite-image.ts +699 -0
- package/src/lib/encoders/encode-ktx.ts +1 -1
- package/src/lib/encoders/encode-ktx2-basis-texture.ts +4 -2
- package/src/lib/gl-extensions.ts +188 -81
- package/src/lib/gl-types.ts +136 -0
- package/src/lib/parsers/basis-module-loader.ts +5 -5
- package/src/lib/parsers/crunch-module-loader.ts +4 -4
- package/src/lib/parsers/parse-basis.ts +358 -66
- package/src/lib/parsers/parse-crunch.ts +11 -8
- package/src/lib/parsers/parse-dds.ts +11 -12
- package/src/lib/parsers/parse-hdr.ts +426 -0
- package/src/lib/parsers/parse-ktx.ts +13 -3
- package/src/lib/parsers/parse-pvr.ts +33 -75
- package/src/lib/texture-api/generate-url.ts +2 -12
- package/src/lib/texture-api/load-image-array.ts +15 -6
- package/src/lib/texture-api/load-image-cube.ts +20 -34
- package/src/lib/texture-api/load-image.ts +19 -8
- package/src/lib/texture-api/texture-api-types.ts +15 -0
- package/src/lib/utils/detect-supported-texture-formats.ts +210 -0
- package/src/lib/utils/extract-mipmap-images.ts +23 -4
- package/src/lib/utils/ktx-format-helper.ts +135 -111
- package/src/lib/utils/texture-format-map.ts +162 -0
- package/src/npy-worker.ts +6 -0
- package/src/radiance-hdr-loader.ts +36 -0
- package/src/texture-array-loader.ts +46 -0
- package/src/texture-cube-array-loader.ts +49 -0
- package/src/texture-cube-loader.ts +46 -0
- package/src/texture-loader.ts +49 -0
- package/src/workers/compressed-texture-worker.ts +0 -1
- package/dist/lib/utils/texture-formats.d.ts +0 -8
- package/dist/lib/utils/texture-formats.d.ts.map +0 -1
- package/dist/lib/utils/texture-formats.js +0 -50
- package/src/lib/utils/texture-formats.ts +0 -59
|
@@ -2,13 +2,35 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
/* eslint-disable camelcase */
|
|
5
6
|
/* eslint-disable indent */
|
|
6
|
-
import type {TextureLevel} from '@loaders.gl/schema';
|
|
7
|
+
import type {TextureFormat, TextureLevel} from '@loaders.gl/schema';
|
|
8
|
+
import {extractLoadLibraryOptions} from '@loaders.gl/worker-utils';
|
|
7
9
|
import {loadBasisEncoderModule, loadBasisTranscoderModule} from './basis-module-loader';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
+
import type {GLTextureFormat} from '../gl-types';
|
|
11
|
+
import {
|
|
12
|
+
GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
|
|
13
|
+
GL_COMPRESSED_RED_RGTC1_EXT,
|
|
14
|
+
GL_COMPRESSED_RGB_ATC_WEBGL,
|
|
15
|
+
GL_COMPRESSED_RGB_ETC1_WEBGL,
|
|
16
|
+
GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
|
17
|
+
GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
18
|
+
GL_COMPRESSED_RGBA8_ETC2_EAC,
|
|
19
|
+
GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
|
|
20
|
+
GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
|
|
21
|
+
GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
22
|
+
GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
|
23
|
+
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
24
|
+
GL_RGB565,
|
|
25
|
+
GL_RGBA4,
|
|
26
|
+
GL_RGBA8
|
|
27
|
+
} from '../gl-extensions';
|
|
28
|
+
import {detectSupportedTextureFormats} from '../utils/detect-supported-texture-formats';
|
|
10
29
|
import {isKTX} from './parse-ktx';
|
|
11
30
|
|
|
31
|
+
// TODO - circular type import
|
|
32
|
+
import type {BasisLoaderOptions} from '../../basis-loader';
|
|
33
|
+
|
|
12
34
|
export type BasisFormat =
|
|
13
35
|
| 'etc1'
|
|
14
36
|
| 'etc2'
|
|
@@ -31,83 +53,189 @@ export type BasisFormat =
|
|
|
31
53
|
type BasisOutputOptions = {
|
|
32
54
|
basisFormat: number;
|
|
33
55
|
compressed: boolean;
|
|
34
|
-
format?:
|
|
56
|
+
format?: GLTextureFormat;
|
|
57
|
+
textureFormat?: TextureFormat;
|
|
35
58
|
};
|
|
36
59
|
|
|
37
|
-
|
|
60
|
+
let basisTranscodingLock: Promise<void> = Promise.resolve();
|
|
61
|
+
|
|
62
|
+
export const BASIS_FORMAT_TO_OUTPUT_OPTIONS: Record<BasisFormat, BasisOutputOptions> = {
|
|
38
63
|
etc1: {
|
|
39
64
|
basisFormat: 0,
|
|
40
65
|
compressed: true,
|
|
41
|
-
format:
|
|
66
|
+
format: GL_COMPRESSED_RGB_ETC1_WEBGL,
|
|
67
|
+
textureFormat: 'etc1-rgb-unorm-webgl'
|
|
68
|
+
},
|
|
69
|
+
etc2: {
|
|
70
|
+
basisFormat: 1,
|
|
71
|
+
compressed: true,
|
|
72
|
+
format: GL_COMPRESSED_RGBA8_ETC2_EAC,
|
|
73
|
+
textureFormat: 'etc2-rgba8unorm'
|
|
42
74
|
},
|
|
43
|
-
etc2: {basisFormat: 1, compressed: true},
|
|
44
75
|
bc1: {
|
|
45
76
|
basisFormat: 2,
|
|
46
77
|
compressed: true,
|
|
47
|
-
format:
|
|
78
|
+
format: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
79
|
+
textureFormat: 'bc1-rgb-unorm-webgl'
|
|
48
80
|
},
|
|
49
81
|
bc3: {
|
|
50
82
|
basisFormat: 3,
|
|
51
83
|
compressed: true,
|
|
52
|
-
format:
|
|
84
|
+
format: GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
85
|
+
textureFormat: 'bc3-rgba-unorm'
|
|
86
|
+
},
|
|
87
|
+
bc4: {
|
|
88
|
+
basisFormat: 4,
|
|
89
|
+
compressed: true,
|
|
90
|
+
format: GL_COMPRESSED_RED_RGTC1_EXT,
|
|
91
|
+
textureFormat: 'bc4-r-unorm'
|
|
92
|
+
},
|
|
93
|
+
bc5: {
|
|
94
|
+
basisFormat: 5,
|
|
95
|
+
compressed: true,
|
|
96
|
+
format: GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
|
|
97
|
+
textureFormat: 'bc5-rg-unorm'
|
|
98
|
+
},
|
|
99
|
+
'bc7-m6-opaque-only': {
|
|
100
|
+
basisFormat: 6,
|
|
101
|
+
compressed: true,
|
|
102
|
+
format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
103
|
+
textureFormat: 'bc7-rgba-unorm'
|
|
104
|
+
},
|
|
105
|
+
'bc7-m5': {
|
|
106
|
+
basisFormat: 7,
|
|
107
|
+
compressed: true,
|
|
108
|
+
format: GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,
|
|
109
|
+
textureFormat: 'bc7-rgba-unorm'
|
|
53
110
|
},
|
|
54
|
-
bc4: {basisFormat: 4, compressed: true},
|
|
55
|
-
bc5: {basisFormat: 5, compressed: true},
|
|
56
|
-
'bc7-m6-opaque-only': {basisFormat: 6, compressed: true},
|
|
57
|
-
'bc7-m5': {basisFormat: 7, compressed: true},
|
|
58
111
|
'pvrtc1-4-rgb': {
|
|
59
112
|
basisFormat: 8,
|
|
60
113
|
compressed: true,
|
|
61
|
-
format:
|
|
114
|
+
format: GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
|
|
115
|
+
textureFormat: 'pvrtc-rgb4unorm-webgl'
|
|
62
116
|
},
|
|
63
117
|
'pvrtc1-4-rgba': {
|
|
64
118
|
basisFormat: 9,
|
|
65
119
|
compressed: true,
|
|
66
|
-
format:
|
|
120
|
+
format: GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,
|
|
121
|
+
textureFormat: 'pvrtc-rgba4unorm-webgl'
|
|
67
122
|
},
|
|
68
123
|
'astc-4x4': {
|
|
69
124
|
basisFormat: 10,
|
|
70
125
|
compressed: true,
|
|
71
|
-
format:
|
|
126
|
+
format: GL_COMPRESSED_RGBA_ASTC_4x4_KHR,
|
|
127
|
+
textureFormat: 'astc-4x4-unorm'
|
|
128
|
+
},
|
|
129
|
+
'atc-rgb': {
|
|
130
|
+
basisFormat: 11,
|
|
131
|
+
compressed: true,
|
|
132
|
+
format: GL_COMPRESSED_RGB_ATC_WEBGL,
|
|
133
|
+
textureFormat: 'atc-rgb-unorm-webgl'
|
|
134
|
+
},
|
|
135
|
+
'atc-rgba-interpolated-alpha': {
|
|
136
|
+
basisFormat: 12,
|
|
137
|
+
compressed: true,
|
|
138
|
+
format: GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL,
|
|
139
|
+
textureFormat: 'atc-rgbai-unorm-webgl'
|
|
72
140
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
141
|
+
rgba32: {
|
|
142
|
+
basisFormat: 13,
|
|
143
|
+
compressed: false,
|
|
144
|
+
format: GL_RGBA8,
|
|
145
|
+
textureFormat: 'rgba8unorm'
|
|
146
|
+
},
|
|
147
|
+
rgb565: {
|
|
148
|
+
basisFormat: 14,
|
|
149
|
+
compressed: false,
|
|
150
|
+
format: GL_RGB565,
|
|
151
|
+
textureFormat: 'rgb565unorm-webgl'
|
|
152
|
+
},
|
|
153
|
+
bgr565: {
|
|
154
|
+
basisFormat: 15,
|
|
155
|
+
compressed: false,
|
|
156
|
+
format: GL_RGB565,
|
|
157
|
+
textureFormat: 'rgb565unorm-webgl'
|
|
158
|
+
},
|
|
159
|
+
rgba4444: {
|
|
160
|
+
basisFormat: 16,
|
|
161
|
+
compressed: false,
|
|
162
|
+
format: GL_RGBA4,
|
|
163
|
+
textureFormat: 'rgba4unorm-webgl'
|
|
164
|
+
}
|
|
79
165
|
};
|
|
80
166
|
|
|
167
|
+
export const BASIS_FORMATS = Object.freeze(
|
|
168
|
+
Object.keys(BASIS_FORMAT_TO_OUTPUT_OPTIONS) as BasisFormat[]
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
export type ParseBasisOptions = {
|
|
172
|
+
format: 'auto' | BasisFormat | {alpha: BasisFormat; noAlpha: BasisFormat};
|
|
173
|
+
containerFormat: 'auto' | 'ktx2' | 'basis';
|
|
174
|
+
module: 'transcoder' | 'encoder';
|
|
175
|
+
supportedTextureFormats?: TextureFormat[];
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Serializes access to the Basis transcoder so concurrent callers do not enter the non-reentrant
|
|
180
|
+
* decoder path at the same time.
|
|
181
|
+
* @param transcode - Transcode operation to run with exclusive access.
|
|
182
|
+
* @returns The transcode result.
|
|
183
|
+
*/
|
|
184
|
+
export async function withBasisTranscodingLock<T>(transcode: () => Promise<T> | T): Promise<T> {
|
|
185
|
+
const previousLock = basisTranscodingLock;
|
|
186
|
+
let releaseLock!: () => void;
|
|
187
|
+
|
|
188
|
+
basisTranscodingLock = new Promise((resolve) => {
|
|
189
|
+
releaseLock = resolve;
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await previousLock;
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
return await transcode();
|
|
196
|
+
} finally {
|
|
197
|
+
releaseLock();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
81
201
|
/**
|
|
82
202
|
* parse data with a Binomial Basis_Universal module
|
|
83
203
|
* @param data
|
|
84
204
|
* @param options
|
|
85
205
|
* @returns compressed texture data
|
|
86
206
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
switch (options.basis.containerFormat) {
|
|
100
|
-
case 'ktx2':
|
|
101
|
-
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
102
|
-
case 'basis':
|
|
103
|
-
default:
|
|
104
|
-
return parseBasisFile(fileConstructors.BasisFile, data, options);
|
|
207
|
+
// eslint-disable-next-line complexity
|
|
208
|
+
export async function parseBasis(
|
|
209
|
+
data: ArrayBuffer,
|
|
210
|
+
options: BasisLoaderOptions = {}
|
|
211
|
+
): Promise<TextureLevel[][]> {
|
|
212
|
+
const loadLibraryOptions = extractLoadLibraryOptions(options);
|
|
213
|
+
|
|
214
|
+
return await withBasisTranscodingLock(async () => {
|
|
215
|
+
if (!options.basis?.containerFormat || options.basis.containerFormat === 'auto') {
|
|
216
|
+
if (isKTX(data)) {
|
|
217
|
+
const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
|
|
218
|
+
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
105
219
|
}
|
|
106
|
-
|
|
107
|
-
default:
|
|
108
|
-
const {BasisFile} = await loadBasisTranscoderModule(options);
|
|
220
|
+
const {BasisFile} = await loadBasisTranscoderModule(loadLibraryOptions);
|
|
109
221
|
return parseBasisFile(BasisFile, data, options);
|
|
110
|
-
|
|
222
|
+
}
|
|
223
|
+
switch (options.basis.module) {
|
|
224
|
+
case 'encoder':
|
|
225
|
+
const fileConstructors = await loadBasisEncoderModule(loadLibraryOptions);
|
|
226
|
+
switch (options.basis.containerFormat) {
|
|
227
|
+
case 'ktx2':
|
|
228
|
+
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
229
|
+
case 'basis':
|
|
230
|
+
default:
|
|
231
|
+
return parseBasisFile(fileConstructors.BasisFile, data, options);
|
|
232
|
+
}
|
|
233
|
+
case 'transcoder':
|
|
234
|
+
default:
|
|
235
|
+
const {BasisFile} = await loadBasisTranscoderModule(loadLibraryOptions);
|
|
236
|
+
return parseBasisFile(BasisFile, data, options);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
111
239
|
}
|
|
112
240
|
|
|
113
241
|
/**
|
|
@@ -117,7 +245,11 @@ export async function parseBasis(data: ArrayBuffer, options): Promise<TextureLev
|
|
|
117
245
|
* @param options
|
|
118
246
|
* @returns compressed texture data
|
|
119
247
|
*/
|
|
120
|
-
function parseBasisFile(
|
|
248
|
+
function parseBasisFile(
|
|
249
|
+
BasisFile,
|
|
250
|
+
data: ArrayBuffer,
|
|
251
|
+
options: BasisLoaderOptions
|
|
252
|
+
): TextureLevel[][] {
|
|
121
253
|
const basisFile = new BasisFile(new Uint8Array(data));
|
|
122
254
|
|
|
123
255
|
try {
|
|
@@ -154,7 +286,12 @@ function parseBasisFile(BasisFile, data, options): TextureLevel[][] {
|
|
|
154
286
|
* @param options
|
|
155
287
|
* @returns compressed texture data
|
|
156
288
|
*/
|
|
157
|
-
function transcodeImage(
|
|
289
|
+
function transcodeImage(
|
|
290
|
+
basisFile,
|
|
291
|
+
imageIndex: number,
|
|
292
|
+
levelIndex: number,
|
|
293
|
+
options: BasisLoaderOptions
|
|
294
|
+
): TextureLevel {
|
|
158
295
|
const width = basisFile.getImageWidth(imageIndex, levelIndex);
|
|
159
296
|
const height = basisFile.getImageHeight(imageIndex, levelIndex);
|
|
160
297
|
|
|
@@ -162,7 +299,7 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options): TextureLeve
|
|
|
162
299
|
const hasAlpha = basisFile.getHasAlpha(/* imageIndex, levelIndex */);
|
|
163
300
|
|
|
164
301
|
// Check options for output format etc
|
|
165
|
-
const {compressed, format, basisFormat} = getBasisOptions(options, hasAlpha);
|
|
302
|
+
const {compressed, format, basisFormat, textureFormat} = getBasisOptions(options, hasAlpha);
|
|
166
303
|
|
|
167
304
|
const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
|
|
168
305
|
const decodedData = new Uint8Array(decodedSize);
|
|
@@ -173,11 +310,13 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options): TextureLeve
|
|
|
173
310
|
|
|
174
311
|
return {
|
|
175
312
|
// standard loaders.gl image category payload
|
|
313
|
+
shape: 'texture-level',
|
|
176
314
|
width,
|
|
177
315
|
height,
|
|
178
316
|
data: decodedData,
|
|
179
317
|
compressed,
|
|
180
|
-
format,
|
|
318
|
+
...(format !== undefined ? {format} : {}),
|
|
319
|
+
...(textureFormat !== undefined ? {textureFormat} : {}),
|
|
181
320
|
|
|
182
321
|
// Additional fields
|
|
183
322
|
// Add levelSize field.
|
|
@@ -192,7 +331,7 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options): TextureLeve
|
|
|
192
331
|
* @param options
|
|
193
332
|
* @returns compressed texture data
|
|
194
333
|
*/
|
|
195
|
-
function parseKTX2File(KTX2File, data: ArrayBuffer, options): TextureLevel[][] {
|
|
334
|
+
function parseKTX2File(KTX2File, data: ArrayBuffer, options: BasisLoaderOptions): TextureLevel[][] {
|
|
196
335
|
const ktx2File = new KTX2File(new Uint8Array(data));
|
|
197
336
|
|
|
198
337
|
try {
|
|
@@ -220,11 +359,15 @@ function parseKTX2File(KTX2File, data: ArrayBuffer, options): TextureLevel[][] {
|
|
|
220
359
|
* @param options
|
|
221
360
|
* @returns
|
|
222
361
|
*/
|
|
223
|
-
function transcodeKTX2Image(
|
|
362
|
+
function transcodeKTX2Image(
|
|
363
|
+
ktx2File,
|
|
364
|
+
levelIndex: number,
|
|
365
|
+
options: BasisLoaderOptions
|
|
366
|
+
): TextureLevel {
|
|
224
367
|
const {alphaFlag, height, width} = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
|
|
225
368
|
|
|
226
369
|
// Check options for output format etc
|
|
227
|
-
const {compressed, format, basisFormat} = getBasisOptions(options, alphaFlag);
|
|
370
|
+
const {compressed, format, basisFormat, textureFormat} = getBasisOptions(options, alphaFlag);
|
|
228
371
|
|
|
229
372
|
const decodedSize = ktx2File.getImageTranscodedSizeInBytes(
|
|
230
373
|
levelIndex,
|
|
@@ -251,15 +394,17 @@ function transcodeKTX2Image(ktx2File, levelIndex: number, options): TextureLevel
|
|
|
251
394
|
|
|
252
395
|
return {
|
|
253
396
|
// standard loaders.gl image category payload
|
|
397
|
+
shape: 'texture-level',
|
|
254
398
|
width,
|
|
255
399
|
height,
|
|
256
400
|
data: decodedData,
|
|
257
401
|
compressed,
|
|
402
|
+
...(format !== undefined ? {format} : {}),
|
|
403
|
+
...(textureFormat !== undefined ? {textureFormat} : {}),
|
|
258
404
|
|
|
259
405
|
// Additional fields
|
|
260
406
|
levelSize: decodedSize,
|
|
261
|
-
hasAlpha: alphaFlag
|
|
262
|
-
format
|
|
407
|
+
hasAlpha: alphaFlag
|
|
263
408
|
};
|
|
264
409
|
}
|
|
265
410
|
|
|
@@ -269,16 +414,22 @@ function transcodeKTX2Image(ktx2File, levelIndex: number, options): TextureLevel
|
|
|
269
414
|
* @param hasAlpha
|
|
270
415
|
* @returns BasisFormat data
|
|
271
416
|
*/
|
|
272
|
-
function getBasisOptions(options, hasAlpha: boolean): BasisOutputOptions {
|
|
273
|
-
let format = options
|
|
417
|
+
function getBasisOptions(options: BasisLoaderOptions, hasAlpha: boolean): BasisOutputOptions {
|
|
418
|
+
let format = options.basis?.format || 'auto';
|
|
274
419
|
if (format === 'auto') {
|
|
275
|
-
format =
|
|
420
|
+
format = options.basis?.supportedTextureFormats
|
|
421
|
+
? selectSupportedBasisFormat(options.basis.supportedTextureFormats)
|
|
422
|
+
: selectSupportedBasisFormat();
|
|
276
423
|
}
|
|
277
424
|
if (typeof format === 'object') {
|
|
278
425
|
format = hasAlpha ? format.alpha : format.noAlpha;
|
|
279
426
|
}
|
|
280
|
-
|
|
281
|
-
|
|
427
|
+
const normalizedFormat = format.toLowerCase() as BasisFormat;
|
|
428
|
+
const basisOutputOptions = BASIS_FORMAT_TO_OUTPUT_OPTIONS[normalizedFormat];
|
|
429
|
+
if (!basisOutputOptions) {
|
|
430
|
+
throw new Error(`Unknown Basis format ${format}`);
|
|
431
|
+
}
|
|
432
|
+
return basisOutputOptions;
|
|
282
433
|
}
|
|
283
434
|
|
|
284
435
|
/**
|
|
@@ -290,24 +441,165 @@ export function selectSupportedBasisFormat():
|
|
|
290
441
|
| {
|
|
291
442
|
alpha: BasisFormat;
|
|
292
443
|
noAlpha: BasisFormat;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
444
|
+
};
|
|
445
|
+
export function selectSupportedBasisFormat(supportedTextureFormats?: Iterable<TextureFormat>):
|
|
446
|
+
| BasisFormat
|
|
447
|
+
| {
|
|
448
|
+
alpha: BasisFormat;
|
|
449
|
+
noAlpha: BasisFormat;
|
|
450
|
+
};
|
|
451
|
+
export function selectSupportedBasisFormat(
|
|
452
|
+
supportedTextureFormats: Iterable<TextureFormat> = detectSupportedTextureFormats()
|
|
453
|
+
): BasisFormat | {alpha: BasisFormat; noAlpha: BasisFormat} {
|
|
454
|
+
const textureFormats = new Set(supportedTextureFormats);
|
|
455
|
+
|
|
456
|
+
if (hasSupportedTextureFormat(textureFormats, ['astc-4x4-unorm', 'astc-4x4-unorm-srgb'])) {
|
|
296
457
|
return 'astc-4x4';
|
|
297
|
-
} else if (
|
|
458
|
+
} else if (hasSupportedTextureFormat(textureFormats, ['bc7-rgba-unorm', 'bc7-rgba-unorm-srgb'])) {
|
|
459
|
+
return {
|
|
460
|
+
alpha: 'bc7-m5',
|
|
461
|
+
noAlpha: 'bc7-m6-opaque-only'
|
|
462
|
+
};
|
|
463
|
+
} else if (
|
|
464
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
465
|
+
'bc1-rgb-unorm-webgl',
|
|
466
|
+
'bc1-rgb-unorm-srgb-webgl',
|
|
467
|
+
'bc1-rgba-unorm',
|
|
468
|
+
'bc1-rgba-unorm-srgb',
|
|
469
|
+
'bc2-rgba-unorm',
|
|
470
|
+
'bc2-rgba-unorm-srgb',
|
|
471
|
+
'bc3-rgba-unorm',
|
|
472
|
+
'bc3-rgba-unorm-srgb'
|
|
473
|
+
])
|
|
474
|
+
) {
|
|
298
475
|
return {
|
|
299
476
|
alpha: 'bc3',
|
|
300
477
|
noAlpha: 'bc1'
|
|
301
478
|
};
|
|
302
|
-
} else if (
|
|
479
|
+
} else if (
|
|
480
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
481
|
+
'pvrtc-rgb4unorm-webgl',
|
|
482
|
+
'pvrtc-rgba4unorm-webgl',
|
|
483
|
+
'pvrtc-rgb2unorm-webgl',
|
|
484
|
+
'pvrtc-rgba2unorm-webgl'
|
|
485
|
+
])
|
|
486
|
+
) {
|
|
303
487
|
return {
|
|
304
488
|
alpha: 'pvrtc1-4-rgba',
|
|
305
489
|
noAlpha: 'pvrtc1-4-rgb'
|
|
306
490
|
};
|
|
307
|
-
} else if (
|
|
308
|
-
|
|
309
|
-
|
|
491
|
+
} else if (
|
|
492
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
493
|
+
'etc2-rgb8unorm',
|
|
494
|
+
'etc2-rgb8unorm-srgb',
|
|
495
|
+
'etc2-rgb8a1unorm',
|
|
496
|
+
'etc2-rgb8a1unorm-srgb',
|
|
497
|
+
'etc2-rgba8unorm',
|
|
498
|
+
'etc2-rgba8unorm-srgb',
|
|
499
|
+
'eac-r11unorm',
|
|
500
|
+
'eac-r11snorm',
|
|
501
|
+
'eac-rg11unorm',
|
|
502
|
+
'eac-rg11snorm'
|
|
503
|
+
])
|
|
504
|
+
) {
|
|
310
505
|
return 'etc2';
|
|
506
|
+
} else if (textureFormats.has('etc1-rgb-unorm-webgl')) {
|
|
507
|
+
return 'etc1';
|
|
508
|
+
} else if (
|
|
509
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
510
|
+
'atc-rgb-unorm-webgl',
|
|
511
|
+
'atc-rgba-unorm-webgl',
|
|
512
|
+
'atc-rgbai-unorm-webgl'
|
|
513
|
+
])
|
|
514
|
+
) {
|
|
515
|
+
return {
|
|
516
|
+
alpha: 'atc-rgba-interpolated-alpha',
|
|
517
|
+
noAlpha: 'atc-rgb'
|
|
518
|
+
};
|
|
311
519
|
}
|
|
312
520
|
return 'rgb565';
|
|
313
521
|
}
|
|
522
|
+
|
|
523
|
+
export function getSupportedBasisFormats(
|
|
524
|
+
supportedTextureFormats: Iterable<TextureFormat> = detectSupportedTextureFormats()
|
|
525
|
+
): BasisFormat[] {
|
|
526
|
+
const textureFormats = new Set(supportedTextureFormats);
|
|
527
|
+
const basisFormats: BasisFormat[] = [];
|
|
528
|
+
|
|
529
|
+
if (hasSupportedTextureFormat(textureFormats, ['astc-4x4-unorm', 'astc-4x4-unorm-srgb'])) {
|
|
530
|
+
basisFormats.push('astc-4x4');
|
|
531
|
+
}
|
|
532
|
+
if (
|
|
533
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
534
|
+
'bc1-rgb-unorm-webgl',
|
|
535
|
+
'bc1-rgb-unorm-srgb-webgl',
|
|
536
|
+
'bc1-rgba-unorm',
|
|
537
|
+
'bc1-rgba-unorm-srgb',
|
|
538
|
+
'bc2-rgba-unorm',
|
|
539
|
+
'bc2-rgba-unorm-srgb',
|
|
540
|
+
'bc3-rgba-unorm',
|
|
541
|
+
'bc3-rgba-unorm-srgb'
|
|
542
|
+
])
|
|
543
|
+
) {
|
|
544
|
+
basisFormats.push('bc1', 'bc3');
|
|
545
|
+
}
|
|
546
|
+
if (hasSupportedTextureFormat(textureFormats, ['bc4-r-unorm', 'bc4-r-snorm'])) {
|
|
547
|
+
basisFormats.push('bc4');
|
|
548
|
+
}
|
|
549
|
+
if (hasSupportedTextureFormat(textureFormats, ['bc5-rg-unorm', 'bc5-rg-snorm'])) {
|
|
550
|
+
basisFormats.push('bc5');
|
|
551
|
+
}
|
|
552
|
+
if (hasSupportedTextureFormat(textureFormats, ['bc7-rgba-unorm', 'bc7-rgba-unorm-srgb'])) {
|
|
553
|
+
basisFormats.push('bc7-m5', 'bc7-m6-opaque-only');
|
|
554
|
+
}
|
|
555
|
+
if (
|
|
556
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
557
|
+
'pvrtc-rgb4unorm-webgl',
|
|
558
|
+
'pvrtc-rgba4unorm-webgl',
|
|
559
|
+
'pvrtc-rgb2unorm-webgl',
|
|
560
|
+
'pvrtc-rgba2unorm-webgl'
|
|
561
|
+
])
|
|
562
|
+
) {
|
|
563
|
+
basisFormats.push('pvrtc1-4-rgb', 'pvrtc1-4-rgba');
|
|
564
|
+
}
|
|
565
|
+
if (
|
|
566
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
567
|
+
'etc2-rgb8unorm',
|
|
568
|
+
'etc2-rgb8unorm-srgb',
|
|
569
|
+
'etc2-rgb8a1unorm',
|
|
570
|
+
'etc2-rgb8a1unorm-srgb',
|
|
571
|
+
'etc2-rgba8unorm',
|
|
572
|
+
'etc2-rgba8unorm-srgb',
|
|
573
|
+
'eac-r11unorm',
|
|
574
|
+
'eac-r11snorm',
|
|
575
|
+
'eac-rg11unorm',
|
|
576
|
+
'eac-rg11snorm'
|
|
577
|
+
])
|
|
578
|
+
) {
|
|
579
|
+
basisFormats.push('etc2');
|
|
580
|
+
}
|
|
581
|
+
if (textureFormats.has('etc1-rgb-unorm-webgl')) {
|
|
582
|
+
basisFormats.push('etc1');
|
|
583
|
+
}
|
|
584
|
+
if (
|
|
585
|
+
hasSupportedTextureFormat(textureFormats, [
|
|
586
|
+
'atc-rgb-unorm-webgl',
|
|
587
|
+
'atc-rgba-unorm-webgl',
|
|
588
|
+
'atc-rgbai-unorm-webgl'
|
|
589
|
+
])
|
|
590
|
+
) {
|
|
591
|
+
basisFormats.push('atc-rgb', 'atc-rgba-interpolated-alpha');
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
basisFormats.push('rgba32', 'rgb565', 'bgr565', 'rgba4444');
|
|
595
|
+
return basisFormats;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function hasSupportedTextureFormat(
|
|
599
|
+
supportedTextureFormats: Set<TextureFormat>,
|
|
600
|
+
candidateTextureFormats: TextureFormat[]
|
|
601
|
+
): boolean {
|
|
602
|
+
return candidateTextureFormats.some((textureFormat) =>
|
|
603
|
+
supportedTextureFormats.has(textureFormat)
|
|
604
|
+
);
|
|
605
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {TextureLevel} from '@loaders.gl/schema';
|
|
5
|
+
import type {TextureFormat, TextureLevel} from '@loaders.gl/schema';
|
|
6
6
|
import {loadCrunchModule} from './crunch-module-loader';
|
|
7
|
-
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
8
7
|
import {assert} from '@loaders.gl/loader-utils';
|
|
8
|
+
import {extractLoadLibraryOptions} from '@loaders.gl/worker-utils';
|
|
9
9
|
import {getDxt1LevelSize, getDxtXLevelSize} from './parse-dds';
|
|
10
10
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
11
11
|
|
|
@@ -22,17 +22,20 @@ const CRN_FORMAT = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
/** Mapping of Crunch formats to DXT formats. */
|
|
25
|
-
const DXT_FORMAT_MAP
|
|
25
|
+
const DXT_FORMAT_MAP: Record<
|
|
26
|
+
number,
|
|
27
|
+
{textureFormat: TextureFormat; sizeFunction: (width: number, height: number) => number}
|
|
28
|
+
> = {
|
|
26
29
|
[CRN_FORMAT.cCRNFmtDXT1]: {
|
|
27
|
-
|
|
30
|
+
textureFormat: 'bc1-rgb-unorm-webgl',
|
|
28
31
|
sizeFunction: getDxt1LevelSize
|
|
29
32
|
},
|
|
30
33
|
[CRN_FORMAT.cCRNFmtDXT3]: {
|
|
31
|
-
|
|
34
|
+
textureFormat: 'bc2-rgba-unorm',
|
|
32
35
|
sizeFunction: getDxtXLevelSize
|
|
33
36
|
},
|
|
34
37
|
[CRN_FORMAT.cCRNFmtDXT5]: {
|
|
35
|
-
|
|
38
|
+
textureFormat: 'bc3-rgba-unorm',
|
|
36
39
|
sizeFunction: getDxtXLevelSize
|
|
37
40
|
}
|
|
38
41
|
};
|
|
@@ -47,7 +50,7 @@ let dst: number;
|
|
|
47
50
|
* @returns Promise of Array of the texture levels
|
|
48
51
|
*/
|
|
49
52
|
export async function parseCrunch(data, options: any): Promise<TextureLevel[]> {
|
|
50
|
-
const crunchModule = await loadCrunchModule(options);
|
|
53
|
+
const crunchModule = await loadCrunchModule(extractLoadLibraryOptions(options));
|
|
51
54
|
|
|
52
55
|
// Copy the contents of the arrayBuffer into emscriptens heap.
|
|
53
56
|
const srcSize = data.byteLength;
|
|
@@ -95,7 +98,7 @@ export async function parseCrunch(data, options: any): Promise<TextureLevel[]> {
|
|
|
95
98
|
width,
|
|
96
99
|
height,
|
|
97
100
|
sizeFunction,
|
|
98
|
-
|
|
101
|
+
textureFormat: DXT_FORMAT_MAP[format].textureFormat
|
|
99
102
|
});
|
|
100
103
|
}
|
|
101
104
|
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {TextureLevel} from '@loaders.gl/schema';
|
|
5
|
+
import type {TextureFormat, TextureLevel} from '@loaders.gl/schema';
|
|
6
6
|
import {assert} from '@loaders.gl/loader-utils';
|
|
7
|
-
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
8
7
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
9
8
|
|
|
10
9
|
const DDS_CONSTANTS = {
|
|
@@ -22,13 +21,13 @@ const DDS_CONSTANTS = {
|
|
|
22
21
|
DDPF_FOURCC: 0x4
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
const
|
|
26
|
-
DXT1:
|
|
27
|
-
DXT3:
|
|
28
|
-
DXT5:
|
|
29
|
-
'ATC ':
|
|
30
|
-
ATCA:
|
|
31
|
-
ATCI:
|
|
24
|
+
const DDS_TEXTURE_FORMATS: Record<string, TextureFormat> = {
|
|
25
|
+
DXT1: 'bc1-rgb-unorm-webgl',
|
|
26
|
+
DXT3: 'bc2-rgba-unorm',
|
|
27
|
+
DXT5: 'bc3-rgba-unorm',
|
|
28
|
+
'ATC ': 'atc-rgb-unorm-webgl',
|
|
29
|
+
ATCA: 'atc-rgba-unorm-webgl',
|
|
30
|
+
ATCI: 'atc-rgbai-unorm-webgl'
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
const getATCLevelSize = getDxt1LevelSize;
|
|
@@ -68,9 +67,9 @@ export function parseDDS(data: ArrayBuffer): TextureLevel[] {
|
|
|
68
67
|
'DDS: Unsupported format, must contain a FourCC code'
|
|
69
68
|
);
|
|
70
69
|
const fourCC = int32ToFourCC(pixelFormatNumber);
|
|
71
|
-
const
|
|
70
|
+
const textureFormat = DDS_TEXTURE_FORMATS[fourCC];
|
|
72
71
|
const sizeFunction = DDS_SIZE_FUNCTIONS[fourCC];
|
|
73
|
-
assert(
|
|
72
|
+
assert(textureFormat && sizeFunction, `DDS: Unknown pixel format ${pixelFormatNumber}`);
|
|
74
73
|
|
|
75
74
|
let mipMapLevels = 1;
|
|
76
75
|
if (header[DDS_CONSTANTS.HEADER_FLAGS_INDEX] & DDS_CONSTANTS.DDSD_MIPMAPCOUNT) {
|
|
@@ -86,7 +85,7 @@ export function parseDDS(data: ArrayBuffer): TextureLevel[] {
|
|
|
86
85
|
width,
|
|
87
86
|
height,
|
|
88
87
|
sizeFunction,
|
|
89
|
-
|
|
88
|
+
textureFormat
|
|
90
89
|
});
|
|
91
90
|
}
|
|
92
91
|
|