@loaders.gl/textures 4.0.0-alpha.4 → 4.0.0-alpha.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 +50 -0
- package/dist/basis-loader.d.ts.map +1 -0
- package/dist/basis-worker.js +116 -60
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/compressed-texture-loader.d.ts +49 -0
- package/dist/compressed-texture-loader.d.ts.map +1 -0
- package/dist/compressed-texture-loader.js +1 -1
- package/dist/compressed-texture-loader.js.map +1 -1
- package/dist/compressed-texture-worker.js +221 -123
- package/dist/compressed-texture-writer.d.ts +25 -0
- package/dist/compressed-texture-writer.d.ts.map +1 -0
- package/dist/crunch-loader.d.ts +21 -0
- package/dist/crunch-loader.d.ts.map +1 -0
- package/dist/crunch-worker.js +59 -26
- package/dist/dist.min.js +2123 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ktx2-basis-universal-texture-writer.d.ts +22 -0
- package/dist/ktx2-basis-universal-texture-writer.d.ts.map +1 -0
- package/dist/lib/encoders/encode-ktx.d.ts +2 -0
- package/dist/lib/encoders/encode-ktx.d.ts.map +1 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts +10 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.d.ts.map +1 -0
- package/dist/lib/encoders/encode-ktx2-basis-texture.js +1 -1
- package/dist/lib/encoders/encode-ktx2-basis-texture.js.map +1 -1
- package/dist/lib/encoders/encode-texture.d.ts +4 -0
- package/dist/lib/encoders/encode-texture.d.ts.map +1 -0
- package/dist/lib/encoders/encode-texture.js +2 -5
- package/dist/lib/encoders/encode-texture.js.map +1 -1
- package/dist/lib/gl-extensions.d.ts +61 -0
- package/dist/lib/gl-extensions.d.ts.map +1 -0
- package/dist/lib/{gl-constants.js → gl-extensions.js} +2 -2
- package/dist/lib/gl-extensions.js.map +1 -0
- package/dist/lib/parsers/basis-module-loader.d.ts +13 -0
- package/dist/lib/parsers/basis-module-loader.d.ts.map +1 -0
- package/dist/lib/parsers/basis-module-loader.js +1 -1
- package/dist/lib/parsers/crunch-module-loader.d.ts +7 -0
- package/dist/lib/parsers/crunch-module-loader.d.ts.map +1 -0
- package/dist/lib/parsers/crunch-module-loader.js +1 -1
- package/dist/lib/parsers/crunch-module-loader.js.map +1 -1
- package/dist/lib/parsers/parse-basis.d.ts +18 -0
- package/dist/lib/parsers/parse-basis.d.ts.map +1 -0
- package/dist/lib/parsers/parse-basis.js +16 -16
- package/dist/lib/parsers/parse-basis.js.map +1 -1
- package/dist/lib/parsers/parse-compressed-texture.d.ts +8 -0
- package/dist/lib/parsers/parse-compressed-texture.d.ts.map +1 -0
- package/dist/lib/parsers/parse-compressed-texture.js.map +1 -1
- package/dist/lib/parsers/parse-crunch.d.ts +9 -0
- package/dist/lib/parsers/parse-crunch.d.ts.map +1 -0
- package/dist/lib/parsers/parse-crunch.js +14 -13
- package/dist/lib/parsers/parse-crunch.js.map +1 -1
- package/dist/lib/parsers/parse-dds.d.ts +28 -0
- package/dist/lib/parsers/parse-dds.d.ts.map +1 -0
- package/dist/lib/parsers/parse-dds.js +7 -7
- package/dist/lib/parsers/parse-dds.js.map +1 -1
- package/dist/lib/parsers/parse-ktx.d.ts +4 -0
- package/dist/lib/parsers/parse-ktx.d.ts.map +1 -0
- package/dist/lib/parsers/parse-ktx.js.map +1 -1
- package/dist/lib/parsers/parse-npy.d.ts +10 -0
- package/dist/lib/parsers/parse-npy.d.ts.map +1 -0
- package/dist/lib/parsers/parse-npy.js.map +1 -1
- package/dist/lib/parsers/parse-pvr.d.ts +15 -0
- package/dist/lib/parsers/parse-pvr.d.ts.map +1 -0
- package/dist/lib/parsers/parse-pvr.js +28 -28
- package/dist/lib/parsers/parse-pvr.js.map +1 -1
- package/dist/lib/texture-api/async-deep-map.d.ts +5 -0
- package/dist/lib/texture-api/async-deep-map.d.ts.map +1 -0
- package/dist/lib/texture-api/deep-load.d.ts +5 -0
- package/dist/lib/texture-api/deep-load.d.ts.map +1 -0
- package/dist/lib/texture-api/generate-url.d.ts +3 -0
- package/dist/lib/texture-api/generate-url.d.ts.map +1 -0
- package/dist/lib/texture-api/load-image-array.d.ts +4 -0
- package/dist/lib/texture-api/load-image-array.d.ts.map +1 -0
- package/dist/lib/texture-api/load-image-cube.d.ts +12 -0
- package/dist/lib/texture-api/load-image-cube.d.ts.map +1 -0
- package/dist/lib/texture-api/load-image.d.ts +8 -0
- package/dist/lib/texture-api/load-image.d.ts.map +1 -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/utils/extract-mipmap-images.d.ts +20 -0
- package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -0
- package/dist/lib/utils/extract-mipmap-images.js.map +1 -1
- package/dist/lib/utils/ktx-format-helper.d.ts +9 -0
- package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -0
- package/dist/lib/utils/ktx-format-helper.js +67 -67
- package/dist/lib/utils/ktx-format-helper.js.map +1 -1
- package/dist/lib/utils/texture-formats.d.ts +8 -0
- package/dist/lib/utils/texture-formats.d.ts.map +1 -0
- package/dist/lib/utils/texture-formats.js.map +1 -1
- package/dist/lib/utils/version.d.ts +2 -0
- package/dist/lib/utils/version.d.ts.map +1 -0
- package/dist/lib/utils/version.js +1 -1
- 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/libs/libs/README.md +9 -0
- package/dist/libs/libs/basis_encoder.js +22 -0
- package/dist/libs/libs/basis_encoder.wasm +0 -0
- package/dist/libs/libs/basis_transcoder.js +21 -0
- package/dist/libs/libs/basis_transcoder.wasm +0 -0
- package/dist/libs/libs/crunch.js +136 -0
- package/dist/npy-loader.d.ts +45 -0
- package/dist/npy-loader.d.ts.map +1 -0
- package/dist/npy-worker.js +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -1
- package/dist/workers/basis-worker.d.ts +2 -0
- package/dist/workers/basis-worker.d.ts.map +1 -0
- package/dist/workers/compressed-texture-worker.d.ts +2 -0
- package/dist/workers/compressed-texture-worker.d.ts.map +1 -0
- package/dist/workers/crunch-worker.d.ts +21 -0
- package/dist/workers/crunch-worker.d.ts.map +1 -0
- package/dist/workers/npy-worker.d.ts +2 -0
- package/dist/workers/npy-worker.d.ts.map +1 -0
- package/package.json +12 -11
- package/src/compressed-texture-loader.ts +1 -1
- package/src/index.ts +2 -2
- package/src/lib/encoders/encode-ktx2-basis-texture.ts +2 -2
- package/src/lib/encoders/encode-texture.ts +6 -6
- package/src/lib/{gl-constants.ts → gl-extensions.ts} +1 -1
- package/src/lib/parsers/crunch-module-loader.ts +1 -1
- package/src/lib/parsers/{parse-basis.js → parse-basis.ts} +100 -44
- package/src/lib/parsers/parse-compressed-texture.ts +1 -1
- package/src/lib/parsers/parse-crunch.ts +16 -15
- package/src/lib/parsers/parse-dds.ts +8 -8
- package/src/lib/parsers/parse-ktx.ts +2 -1
- package/src/lib/parsers/parse-npy.ts +2 -0
- package/src/lib/parsers/parse-pvr.ts +72 -29
- package/src/lib/utils/extract-mipmap-images.ts +9 -1
- package/src/lib/utils/ktx-format-helper.ts +67 -67
- package/src/lib/utils/texture-formats.ts +1 -1
- 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/types.ts +0 -30
- package/dist/lib/gl-constants.js.map +0 -1
- package/src/lib/parsers/parse-ktx.js +0 -45
- package/src/lib/parsers/parse-npy.js +0 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/textures",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.5",
|
|
4
4
|
"description": "Framework-independent loaders for compressed and super compressed (basis) textures ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"ETC",
|
|
22
22
|
"basis"
|
|
23
23
|
],
|
|
24
|
-
"types": "
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
25
|
"main": "dist/index.js",
|
|
26
26
|
"module": "dist/index.js",
|
|
27
27
|
"sideEffects": false,
|
|
@@ -34,19 +34,20 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"pre-build": "npm run copy-libs && npm run build-worker && npm run build-bundle",
|
|
36
36
|
"copy-libs": "cp -rf ./src/libs ./dist/libs",
|
|
37
|
-
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/
|
|
37
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
|
|
38
38
|
"build-worker": "npm run build-basis-worker && npm run build-npy-worker && npm run build-compressed-texture-worker && npm run build-crunch-worker",
|
|
39
|
-
"build-basis-worker": "esbuild src/workers/basis-worker.ts --bundle --outfile=dist/basis-worker.js",
|
|
40
|
-
"build-npy-worker": "esbuild src/workers/npy-worker.ts --bundle --outfile=dist/npy-worker.js",
|
|
41
|
-
"build-compressed-texture-worker": "esbuild src/workers/compressed-texture-worker.ts --bundle --outfile=dist/compressed-texture-worker.js",
|
|
42
|
-
"build-crunch-worker": "esbuild src/workers/crunch-worker.ts --bundle --outfile=dist/crunch-worker.js"
|
|
39
|
+
"build-basis-worker": "esbuild src/workers/basis-worker.ts --bundle --outfile=dist/basis-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
|
|
40
|
+
"build-npy-worker": "esbuild src/workers/npy-worker.ts --bundle --outfile=dist/npy-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
|
|
41
|
+
"build-compressed-texture-worker": "esbuild src/workers/compressed-texture-worker.ts --bundle --outfile=dist/compressed-texture-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"",
|
|
42
|
+
"build-crunch-worker": "esbuild src/workers/crunch-worker.ts --bundle --outfile=dist/crunch-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@loaders.gl/images": "4.0.0-alpha.
|
|
46
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
47
|
-
"@loaders.gl/
|
|
45
|
+
"@loaders.gl/images": "4.0.0-alpha.5",
|
|
46
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.5",
|
|
47
|
+
"@loaders.gl/schema": "4.0.0-alpha.5",
|
|
48
|
+
"@loaders.gl/worker-utils": "4.0.0-alpha.5",
|
|
48
49
|
"ktx-parse": "^0.0.4",
|
|
49
50
|
"texture-compressor": "^1.0.2"
|
|
50
51
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
|
|
52
53
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Types
|
|
2
|
-
export type {GPUTextureFormat} from '
|
|
2
|
+
export type {GPUTextureFormat} from '@loaders.gl/schema';
|
|
3
3
|
export type {TextureLoaderOptions} from './compressed-texture-loader';
|
|
4
4
|
|
|
5
5
|
// Loaders
|
|
@@ -18,7 +18,7 @@ export {loadImageTextureArray} from './lib/texture-api/load-image-array';
|
|
|
18
18
|
export {loadImageTextureCube} from './lib/texture-api/load-image-cube';
|
|
19
19
|
|
|
20
20
|
// Utilities
|
|
21
|
-
export {
|
|
21
|
+
export {GL_EXTENSIONS_CONSTANTS} from './lib/gl-extensions';
|
|
22
22
|
export {selectSupportedBasisFormat} from './lib/parsers/parse-basis';
|
|
23
23
|
export {getSupportedGPUTextureFormats} from './lib/utils/texture-formats';
|
|
24
24
|
|
|
@@ -11,7 +11,7 @@ import {loadBasisEncoderModule} from '../parsers/basis-module-loader';
|
|
|
11
11
|
export async function encodeKTX2BasisTexture(
|
|
12
12
|
image: ImageDataType,
|
|
13
13
|
options: any = {}
|
|
14
|
-
): Promise<
|
|
14
|
+
): Promise<ArrayBuffer> {
|
|
15
15
|
// TODO remove default values after writer options will be normalized like it done in load module.
|
|
16
16
|
const {useSRGB = false, qualityLevel = 10, encodeUASTC = false, mipmaps = false} = options;
|
|
17
17
|
const {BasisEncoder} = await loadBasisEncoderModule(options);
|
|
@@ -32,7 +32,7 @@ export async function encodeKTX2BasisTexture(
|
|
|
32
32
|
|
|
33
33
|
const numOutputBytes = basisEncoder.encode(basisFileData);
|
|
34
34
|
|
|
35
|
-
const actualKTX2FileData =
|
|
35
|
+
const actualKTX2FileData = basisFileData.subarray(0, numOutputBytes).buffer;
|
|
36
36
|
return actualKTX2FileData;
|
|
37
37
|
} catch (error) {
|
|
38
38
|
// eslint-disable-next-line no-console
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {ChildProcessProxy} from '@loaders.gl/worker-utils';
|
|
2
2
|
|
|
3
|
-
const MODULE_ROOT = `${__dirname}/../../..`;
|
|
4
|
-
|
|
5
3
|
/*
|
|
6
4
|
* @see https://github.com/TimvanScherpenzeel/texture-compressor
|
|
7
5
|
*/
|
|
8
|
-
export async function encodeImageURLToCompressedTextureURL(
|
|
6
|
+
export async function encodeImageURLToCompressedTextureURL(
|
|
7
|
+
inputUrl: string,
|
|
8
|
+
outputUrl: string,
|
|
9
|
+
options?: {cwd?: string}
|
|
10
|
+
): Promise<string> {
|
|
9
11
|
// prettier-ignore
|
|
10
12
|
const args = [
|
|
11
13
|
// Note: our actual executable is `npx`, so `texture-compressor` is an argument
|
|
@@ -20,9 +22,7 @@ export async function encodeImageURLToCompressedTextureURL(inputUrl, outputUrl)
|
|
|
20
22
|
await childProcess.start({
|
|
21
23
|
command: 'npx',
|
|
22
24
|
arguments: args,
|
|
23
|
-
spawn:
|
|
24
|
-
cwd: MODULE_ROOT
|
|
25
|
-
}
|
|
25
|
+
spawn: options
|
|
26
26
|
});
|
|
27
27
|
return outputUrl;
|
|
28
28
|
}
|
|
@@ -31,7 +31,7 @@ async function loadCrunch(options) {
|
|
|
31
31
|
|
|
32
32
|
// Depends on how import happened...
|
|
33
33
|
// @ts-ignore TS2339: Property does not exist on type
|
|
34
|
-
loadCrunchDecoder = loadCrunchDecoder || globalThis.
|
|
34
|
+
loadCrunchDecoder = loadCrunchDecoder || globalThis.LoadCrunchDecoder;
|
|
35
35
|
crunchModule = loadCrunchDecoder();
|
|
36
36
|
return crunchModule;
|
|
37
37
|
}
|
|
@@ -1,20 +1,71 @@
|
|
|
1
|
+
/* eslint-disable indent */
|
|
2
|
+
import type {TextureLevel} from '@loaders.gl/schema';
|
|
1
3
|
import {loadBasisEncoderModule, loadBasisTrascoderModule} from './basis-module-loader';
|
|
2
|
-
import {
|
|
3
|
-
import {getSupportedGPUTextureFormats} from '
|
|
4
|
+
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
5
|
+
import {getSupportedGPUTextureFormats} from '../utils/texture-formats';
|
|
4
6
|
import {isKTX} from './parse-ktx';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
etc1
|
|
8
|
+
export type BasisFormat =
|
|
9
|
+
| 'etc1'
|
|
10
|
+
| 'etc2'
|
|
11
|
+
| 'bc1'
|
|
12
|
+
| 'bc3'
|
|
13
|
+
| 'bc4'
|
|
14
|
+
| 'bc5'
|
|
15
|
+
| 'bc7-m6-opaque-only'
|
|
16
|
+
| 'bc7-m5'
|
|
17
|
+
| 'pvrtc1-4-rgb'
|
|
18
|
+
| 'pvrtc1-4-rgba'
|
|
19
|
+
| 'astc-4x4'
|
|
20
|
+
| 'atc-rgb'
|
|
21
|
+
| 'atc-rgba-interpolated-alpha'
|
|
22
|
+
| 'rgba32'
|
|
23
|
+
| 'rgb565'
|
|
24
|
+
| 'bgr565'
|
|
25
|
+
| 'rgba4444';
|
|
26
|
+
|
|
27
|
+
type BasisOutputOptions = {
|
|
28
|
+
basisFormat: number;
|
|
29
|
+
compressed: boolean;
|
|
30
|
+
format?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const OutputFormat: Record<string, BasisOutputOptions> = {
|
|
34
|
+
etc1: {
|
|
35
|
+
basisFormat: 0,
|
|
36
|
+
compressed: true,
|
|
37
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
|
|
38
|
+
},
|
|
8
39
|
etc2: {basisFormat: 1, compressed: true},
|
|
9
|
-
bc1: {
|
|
10
|
-
|
|
40
|
+
bc1: {
|
|
41
|
+
basisFormat: 2,
|
|
42
|
+
compressed: true,
|
|
43
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
|
|
44
|
+
},
|
|
45
|
+
bc3: {
|
|
46
|
+
basisFormat: 3,
|
|
47
|
+
compressed: true,
|
|
48
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
|
|
49
|
+
},
|
|
11
50
|
bc4: {basisFormat: 4, compressed: true},
|
|
12
51
|
bc5: {basisFormat: 5, compressed: true},
|
|
13
52
|
'bc7-m6-opaque-only': {basisFormat: 6, compressed: true},
|
|
14
53
|
'bc7-m5': {basisFormat: 7, compressed: true},
|
|
15
|
-
'pvrtc1-4-rgb': {
|
|
16
|
-
|
|
17
|
-
|
|
54
|
+
'pvrtc1-4-rgb': {
|
|
55
|
+
basisFormat: 8,
|
|
56
|
+
compressed: true,
|
|
57
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
|
|
58
|
+
},
|
|
59
|
+
'pvrtc1-4-rgba': {
|
|
60
|
+
basisFormat: 9,
|
|
61
|
+
compressed: true,
|
|
62
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
|
|
63
|
+
},
|
|
64
|
+
'astc-4x4': {
|
|
65
|
+
basisFormat: 10,
|
|
66
|
+
compressed: true,
|
|
67
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
|
|
68
|
+
},
|
|
18
69
|
'atc-rgb': {basisFormat: 11, compressed: true},
|
|
19
70
|
'atc-rgba-interpolated-alpha': {basisFormat: 12, compressed: true},
|
|
20
71
|
rgba32: {basisFormat: 13, compressed: false},
|
|
@@ -25,11 +76,11 @@ const OutputFormat = {
|
|
|
25
76
|
|
|
26
77
|
/**
|
|
27
78
|
* parse data with a Binomial Basis_Universal module
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
79
|
+
* @param data
|
|
80
|
+
* @param options
|
|
30
81
|
* @returns compressed texture data
|
|
31
82
|
*/
|
|
32
|
-
export default async function parseBasis(data, options) {
|
|
83
|
+
export default async function parseBasis(data: ArrayBuffer, options): Promise<TextureLevel[][]> {
|
|
33
84
|
if (options.basis.containerFormat === 'auto') {
|
|
34
85
|
if (isKTX(data)) {
|
|
35
86
|
const fileConstructors = await loadBasisEncoderModule(options);
|
|
@@ -57,25 +108,25 @@ export default async function parseBasis(data, options) {
|
|
|
57
108
|
|
|
58
109
|
/**
|
|
59
110
|
* Parse *.basis file data
|
|
60
|
-
* @param
|
|
61
|
-
* @param
|
|
62
|
-
* @param
|
|
111
|
+
* @param BasisFile - initialized transcoder module
|
|
112
|
+
* @param data
|
|
113
|
+
* @param options
|
|
63
114
|
* @returns compressed texture data
|
|
64
115
|
*/
|
|
65
|
-
function parseBasisFile(BasisFile, data, options) {
|
|
116
|
+
function parseBasisFile(BasisFile, data, options): TextureLevel[][] {
|
|
66
117
|
const basisFile = new BasisFile(new Uint8Array(data));
|
|
67
118
|
|
|
68
119
|
try {
|
|
69
120
|
if (!basisFile.startTranscoding()) {
|
|
70
|
-
|
|
121
|
+
throw new Error('Failed to start basis transcoding');
|
|
71
122
|
}
|
|
72
123
|
|
|
73
124
|
const imageCount = basisFile.getNumImages();
|
|
74
|
-
const images = [];
|
|
125
|
+
const images: TextureLevel[][] = [];
|
|
75
126
|
|
|
76
127
|
for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
|
|
77
128
|
const levelsCount = basisFile.getNumLevels(imageIndex);
|
|
78
|
-
const levels = [];
|
|
129
|
+
const levels: TextureLevel[] = [];
|
|
79
130
|
|
|
80
131
|
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
|
|
81
132
|
levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
|
|
@@ -93,13 +144,13 @@ function parseBasisFile(BasisFile, data, options) {
|
|
|
93
144
|
|
|
94
145
|
/**
|
|
95
146
|
* Parse the particular level image of a basis file
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
147
|
+
* @param basisFile
|
|
148
|
+
* @param imageIndex
|
|
149
|
+
* @param levelIndex
|
|
150
|
+
* @param options
|
|
100
151
|
* @returns compressed texture data
|
|
101
152
|
*/
|
|
102
|
-
function transcodeImage(basisFile, imageIndex, levelIndex, options) {
|
|
153
|
+
function transcodeImage(basisFile, imageIndex, levelIndex, options): TextureLevel {
|
|
103
154
|
const width = basisFile.getImageWidth(imageIndex, levelIndex);
|
|
104
155
|
const height = basisFile.getImageHeight(imageIndex, levelIndex);
|
|
105
156
|
|
|
@@ -113,7 +164,7 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options) {
|
|
|
113
164
|
const decodedData = new Uint8Array(decodedSize);
|
|
114
165
|
|
|
115
166
|
if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
|
|
116
|
-
|
|
167
|
+
throw new Error('failed to start Basis transcoding');
|
|
117
168
|
}
|
|
118
169
|
|
|
119
170
|
return {
|
|
@@ -122,37 +173,37 @@ function transcodeImage(basisFile, imageIndex, levelIndex, options) {
|
|
|
122
173
|
height,
|
|
123
174
|
data: decodedData,
|
|
124
175
|
compressed,
|
|
176
|
+
format,
|
|
125
177
|
|
|
126
178
|
// Additional fields
|
|
127
179
|
// Add levelSize field.
|
|
128
|
-
hasAlpha
|
|
129
|
-
format
|
|
180
|
+
hasAlpha
|
|
130
181
|
};
|
|
131
182
|
}
|
|
132
183
|
|
|
133
184
|
/**
|
|
134
185
|
* Parse *.ktx2 file data
|
|
135
|
-
* @param
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
186
|
+
* @param KTX2File
|
|
187
|
+
* @param data
|
|
188
|
+
* @param options
|
|
138
189
|
* @returns compressed texture data
|
|
139
190
|
*/
|
|
140
|
-
function parseKTX2File(KTX2File, data, options) {
|
|
191
|
+
function parseKTX2File(KTX2File, data: ArrayBuffer, options): TextureLevel[][] {
|
|
141
192
|
const ktx2File = new KTX2File(new Uint8Array(data));
|
|
142
193
|
|
|
143
194
|
try {
|
|
144
195
|
if (!ktx2File.startTranscoding()) {
|
|
145
|
-
|
|
196
|
+
throw new Error('failed to start KTX2 transcoding');
|
|
146
197
|
}
|
|
147
198
|
const levelsCount = ktx2File.getLevels();
|
|
148
|
-
const levels = [];
|
|
199
|
+
const levels: TextureLevel[] = [];
|
|
149
200
|
|
|
150
201
|
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
|
|
151
202
|
levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
|
|
152
203
|
break; // texture app can only show one level for some reason
|
|
153
204
|
}
|
|
154
205
|
|
|
155
|
-
return levels;
|
|
206
|
+
return [levels];
|
|
156
207
|
} finally {
|
|
157
208
|
ktx2File.close();
|
|
158
209
|
ktx2File.delete();
|
|
@@ -161,12 +212,12 @@ function parseKTX2File(KTX2File, data, options) {
|
|
|
161
212
|
|
|
162
213
|
/**
|
|
163
214
|
* Parse the particular level image of a ktx2 file
|
|
164
|
-
* @param
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
215
|
+
* @param ktx2File
|
|
216
|
+
* @param levelIndex
|
|
217
|
+
* @param options
|
|
167
218
|
* @returns
|
|
168
219
|
*/
|
|
169
|
-
function transcodeKTX2Image(ktx2File, levelIndex, options) {
|
|
220
|
+
function transcodeKTX2Image(ktx2File, levelIndex: number, options): TextureLevel {
|
|
170
221
|
const {alphaFlag, height, width} = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
|
|
171
222
|
|
|
172
223
|
// Check options for output format etc
|
|
@@ -192,7 +243,7 @@ function transcodeKTX2Image(ktx2File, levelIndex, options) {
|
|
|
192
243
|
-1 /* channel1 */
|
|
193
244
|
)
|
|
194
245
|
) {
|
|
195
|
-
|
|
246
|
+
throw new Error('Failed to transcode KTX2 image');
|
|
196
247
|
}
|
|
197
248
|
|
|
198
249
|
return {
|
|
@@ -204,18 +255,18 @@ function transcodeKTX2Image(ktx2File, levelIndex, options) {
|
|
|
204
255
|
|
|
205
256
|
// Additional fields
|
|
206
257
|
// Add levelSize field.
|
|
207
|
-
alphaFlag,
|
|
258
|
+
hasAlpha: alphaFlag,
|
|
208
259
|
format
|
|
209
260
|
};
|
|
210
261
|
}
|
|
211
262
|
|
|
212
263
|
/**
|
|
213
264
|
* Get BasisFormat by loader format option
|
|
214
|
-
* @param
|
|
215
|
-
* @param
|
|
265
|
+
* @param options
|
|
266
|
+
* @param hasAlpha
|
|
216
267
|
* @returns BasisFormat data
|
|
217
268
|
*/
|
|
218
|
-
function getBasisOptions(options, hasAlpha) {
|
|
269
|
+
function getBasisOptions(options, hasAlpha: boolean): BasisOutputOptions {
|
|
219
270
|
let format = options && options.basis && options.basis.format;
|
|
220
271
|
if (format === 'auto') {
|
|
221
272
|
format = selectSupportedBasisFormat();
|
|
@@ -231,7 +282,12 @@ function getBasisOptions(options, hasAlpha) {
|
|
|
231
282
|
* Select transcode format from the list of supported formats
|
|
232
283
|
* @returns key for OutputFormat map
|
|
233
284
|
*/
|
|
234
|
-
export function selectSupportedBasisFormat()
|
|
285
|
+
export function selectSupportedBasisFormat():
|
|
286
|
+
| BasisFormat
|
|
287
|
+
| {
|
|
288
|
+
alpha: BasisFormat;
|
|
289
|
+
noAlpha: BasisFormat;
|
|
290
|
+
} {
|
|
235
291
|
const supportedFormats = getSupportedGPUTextureFormats();
|
|
236
292
|
if (supportedFormats.has('astc')) {
|
|
237
293
|
return 'astc-4x4';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {TextureLevel} from '
|
|
1
|
+
import type {TextureLevel} from '@loaders.gl/schema';
|
|
2
2
|
import {loadCrunchModule} from './crunch-module-loader';
|
|
3
|
-
import {
|
|
3
|
+
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
4
4
|
import {assert} from '@loaders.gl/loader-utils';
|
|
5
5
|
import {getDxt1LevelSize, getDxtXLevelSize} from './parse-dds';
|
|
6
6
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
@@ -17,19 +17,20 @@ const CRN_FORMAT = {
|
|
|
17
17
|
// Crunch supports more formats than this.
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
const DXT_FORMAT_MAP = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
/** Mapping of Crunch formats to DXT formats. */
|
|
21
|
+
const DXT_FORMAT_MAP = {
|
|
22
|
+
[CRN_FORMAT.cCRNFmtDXT1]: {
|
|
23
|
+
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
24
|
+
sizeFunction: getDxt1LevelSize
|
|
25
|
+
},
|
|
26
|
+
[CRN_FORMAT.cCRNFmtDXT3]: {
|
|
27
|
+
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
|
28
|
+
sizeFunction: getDxtXLevelSize
|
|
29
|
+
},
|
|
30
|
+
[CRN_FORMAT.cCRNFmtDXT5]: {
|
|
31
|
+
pixelFormat: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
32
|
+
sizeFunction: getDxtXLevelSize
|
|
33
|
+
}
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
let cachedDstSize = 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {TextureLevel} from '
|
|
1
|
+
import type {TextureLevel} from '@loaders.gl/schema';
|
|
2
2
|
import {assert} from '@loaders.gl/loader-utils';
|
|
3
|
-
import {
|
|
3
|
+
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
4
4
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
5
5
|
|
|
6
6
|
const DDS_CONSTANTS = {
|
|
@@ -19,12 +19,12 @@ const DDS_CONSTANTS = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const DDS_PIXEL_FORMATS: Record<string, number> = {
|
|
22
|
-
DXT1:
|
|
23
|
-
DXT3:
|
|
24
|
-
DXT5:
|
|
25
|
-
'ATC ':
|
|
26
|
-
ATCA:
|
|
27
|
-
ATCI:
|
|
22
|
+
DXT1: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
23
|
+
DXT3: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT,
|
|
24
|
+
DXT5: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
|
|
25
|
+
'ATC ': GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ATC_WEBGL,
|
|
26
|
+
ATCA: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL,
|
|
27
|
+
ATCI: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const getATCLevelSize = getDxt1LevelSize;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {TextureLevel} from '@loaders.gl/schema';
|
|
1
2
|
import {read} from 'ktx-parse';
|
|
2
3
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
3
4
|
import {mapVkFormatToWebGL} from '../utils/ktx-format-helper';
|
|
@@ -29,7 +30,7 @@ export function isKTX(data: ArrayBuffer) {
|
|
|
29
30
|
return !notKTX;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export function parseKTX(arrayBuffer: ArrayBuffer) {
|
|
33
|
+
export function parseKTX(arrayBuffer: ArrayBuffer): TextureLevel[] {
|
|
33
34
|
const uint8Array = new Uint8Array(arrayBuffer);
|
|
34
35
|
const ktx = read(uint8Array);
|
|
35
36
|
const mipMapLevels = Math.max(1, ktx.levels.length);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {TextureLevel} from '../../types';
|
|
2
1
|
/* eslint-disable camelcase */
|
|
3
2
|
// Forked from PicoGL: https://github.com/tsherif/picogl.js/blob/master/examples/utils/utils.js
|
|
4
3
|
// Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
import type {TextureLevel} from '@loaders.gl/schema';
|
|
6
|
+
import {GL_EXTENSIONS_CONSTANTS} from '../gl-extensions';
|
|
6
7
|
import {extractMipmapImages} from '../utils/extract-mipmap-images';
|
|
7
8
|
|
|
8
9
|
const PVR_CONSTANTS: Record<string, number> = {
|
|
@@ -20,33 +21,75 @@ const PVR_CONSTANTS: Record<string, number> = {
|
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
const PVR_PIXEL_FORMATS: Record<number, number[]> = {
|
|
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
|
-
|
|
24
|
+
0: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_2BPPV1_IMG],
|
|
25
|
+
1: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG],
|
|
26
|
+
2: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG],
|
|
27
|
+
3: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG],
|
|
28
|
+
6: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL],
|
|
29
|
+
7: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT],
|
|
30
|
+
9: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT3_EXT],
|
|
31
|
+
11: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT],
|
|
32
|
+
22: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_ETC2],
|
|
33
|
+
23: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA8_ETC2_EAC],
|
|
34
|
+
24: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2],
|
|
35
|
+
25: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_R11_EAC],
|
|
36
|
+
26: [GL_EXTENSIONS_CONSTANTS.COMPRESSED_RG11_EAC],
|
|
37
|
+
27: [
|
|
38
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR,
|
|
39
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR
|
|
40
|
+
],
|
|
41
|
+
28: [
|
|
42
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X4_KHR,
|
|
43
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR
|
|
44
|
+
],
|
|
45
|
+
29: [
|
|
46
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_5X5_KHR,
|
|
47
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR
|
|
48
|
+
],
|
|
49
|
+
30: [
|
|
50
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X5_KHR,
|
|
51
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR
|
|
52
|
+
],
|
|
53
|
+
31: [
|
|
54
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_6X6_KHR,
|
|
55
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR
|
|
56
|
+
],
|
|
57
|
+
32: [
|
|
58
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X5_KHR,
|
|
59
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR
|
|
60
|
+
],
|
|
61
|
+
33: [
|
|
62
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X6_KHR,
|
|
63
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR
|
|
64
|
+
],
|
|
65
|
+
34: [
|
|
66
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_8X8_KHR,
|
|
67
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR
|
|
68
|
+
],
|
|
69
|
+
35: [
|
|
70
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X5_KHR,
|
|
71
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR
|
|
72
|
+
],
|
|
73
|
+
36: [
|
|
74
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X6_KHR,
|
|
75
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR
|
|
76
|
+
],
|
|
77
|
+
37: [
|
|
78
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X8_KHR,
|
|
79
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR
|
|
80
|
+
],
|
|
81
|
+
38: [
|
|
82
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_10X10_KHR,
|
|
83
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR
|
|
84
|
+
],
|
|
85
|
+
39: [
|
|
86
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X10_KHR,
|
|
87
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR
|
|
88
|
+
],
|
|
89
|
+
40: [
|
|
90
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_12X12_KHR,
|
|
91
|
+
GL_EXTENSIONS_CONSTANTS.COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR
|
|
92
|
+
]
|
|
50
93
|
};
|
|
51
94
|
|
|
52
95
|
const PVR_SIZE_FUNCTIONS: Record<number, (width: number, height: number) => number> = {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {TextureLevel} from '@loaders.gl/schema';
|
|
2
|
+
|
|
3
|
+
export type CompressedTextureExtractOptions = {
|
|
4
|
+
mipMapLevels: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
sizeFunction: Function;
|
|
8
|
+
internalFormat: number;
|
|
9
|
+
};
|
|
2
10
|
|
|
3
11
|
/**
|
|
4
12
|
* Extract mipmap images from compressed texture buffer
|