@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,47 +2,27 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
loadCompositeImageUrlTree,
|
|
7
|
+
normalizeCompositeImageOptions
|
|
8
|
+
} from '../composite-image/parse-composite-image';
|
|
9
|
+
import {
|
|
10
|
+
IMAGE_TEXTURE_CUBE_FACES,
|
|
11
|
+
type ImageCubeTexture
|
|
12
|
+
} from '../composite-image/image-texture-cube';
|
|
13
|
+
import type {GetUrl, TextureLoaderOptions} from './texture-api-types';
|
|
7
14
|
import {getImageUrls} from './load-image';
|
|
8
|
-
import {deepLoad} from './deep-load';
|
|
9
|
-
|
|
10
|
-
// Returned map will be have keys corresponding to GL cubemap constants
|
|
11
|
-
const GL_TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515;
|
|
12
|
-
const GL_TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516;
|
|
13
|
-
const GL_TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517;
|
|
14
|
-
const GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518;
|
|
15
|
-
const GL_TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519;
|
|
16
|
-
const GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851a;
|
|
17
|
-
|
|
18
|
-
const CUBE_FACES = [
|
|
19
|
-
{face: GL_TEXTURE_CUBE_MAP_POSITIVE_X, direction: 'right', axis: 'x', sign: 'positive'},
|
|
20
|
-
{face: GL_TEXTURE_CUBE_MAP_NEGATIVE_X, direction: 'left', axis: 'x', sign: 'negative'},
|
|
21
|
-
{face: GL_TEXTURE_CUBE_MAP_POSITIVE_Y, direction: 'top', axis: 'y', sign: 'positive'},
|
|
22
|
-
{face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, direction: 'bottom', axis: 'y', sign: 'negative'},
|
|
23
|
-
{face: GL_TEXTURE_CUBE_MAP_POSITIVE_Z, direction: 'front', axis: 'z', sign: 'positive'},
|
|
24
|
-
{face: GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, direction: 'back', axis: 'z', sign: 'negative'}
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
export type ImageCubeTexture = {
|
|
28
|
-
GL_TEXTURE_CUBE_MAP_POSITIVE_X: any;
|
|
29
|
-
GL_TEXTURE_CUBE_MAP_NEGATIVE_X: any;
|
|
30
|
-
GL_TEXTURE_CUBE_MAP_POSITIVE_Y: any;
|
|
31
|
-
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: any;
|
|
32
|
-
GL_TEXTURE_CUBE_MAP_POSITIVE_Z: any;
|
|
33
|
-
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: any;
|
|
34
|
-
};
|
|
35
15
|
|
|
36
16
|
// Returns an object with six key-value pairs containing the urls (or url mip arrays)
|
|
37
17
|
// for each cube face
|
|
38
|
-
export async function getImageCubeUrls(getUrl: GetUrl, options:
|
|
18
|
+
export async function getImageCubeUrls(getUrl: GetUrl, options: TextureLoaderOptions) {
|
|
39
19
|
// Calculate URLs
|
|
40
20
|
const urls: Record<number, string | string[]> = {};
|
|
41
21
|
const promises: Promise<any>[] = [];
|
|
42
22
|
|
|
43
23
|
let index = 0;
|
|
44
|
-
for (let i = 0; i <
|
|
45
|
-
const face =
|
|
24
|
+
for (let i = 0; i < IMAGE_TEXTURE_CUBE_FACES.length; ++i) {
|
|
25
|
+
const face = IMAGE_TEXTURE_CUBE_FACES[index];
|
|
46
26
|
const promise = getImageUrls(getUrl, options, {...face, index: index++}).then((url) => {
|
|
47
27
|
urls[face.face] = url;
|
|
48
28
|
});
|
|
@@ -56,10 +36,16 @@ export async function getImageCubeUrls(getUrl: GetUrl, options: UrlOptions) {
|
|
|
56
36
|
|
|
57
37
|
// Returns an object with six key-value pairs containing the images (or image mip arrays)
|
|
58
38
|
// for each cube face
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use `load(url, TextureCubeLoader)` for manifest-driven loading.
|
|
41
|
+
*/
|
|
59
42
|
export async function loadImageTextureCube(
|
|
60
43
|
getUrl: GetUrl,
|
|
61
|
-
options = {}
|
|
44
|
+
options: TextureLoaderOptions = {}
|
|
62
45
|
): Promise<ImageCubeTexture> {
|
|
63
46
|
const urls = await getImageCubeUrls(getUrl, options);
|
|
64
|
-
return (await
|
|
47
|
+
return (await loadCompositeImageUrlTree(
|
|
48
|
+
urls,
|
|
49
|
+
normalizeCompositeImageOptions(options)
|
|
50
|
+
)) as ImageCubeTexture;
|
|
65
51
|
}
|
|
@@ -3,19 +3,29 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {assert} from '@loaders.gl/loader-utils';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import {getImageSize} from '@loaders.gl/images';
|
|
7
|
+
import {
|
|
8
|
+
loadCompositeImageMember,
|
|
9
|
+
loadCompositeImageUrlTree,
|
|
10
|
+
normalizeCompositeImageOptions
|
|
11
|
+
} from '../composite-image/parse-composite-image';
|
|
12
|
+
import type {GetUrl, TextureLoaderOptions, UrlOptions} from './texture-api-types';
|
|
8
13
|
import {generateUrl} from './generate-url';
|
|
9
|
-
import {deepLoad, shallowLoad} from './deep-load';
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `load(url, TextureLoader)` for manifest-driven loading.
|
|
17
|
+
*/
|
|
18
|
+
export async function loadImageTexture(
|
|
19
|
+
getUrl: string | GetUrl,
|
|
20
|
+
options: TextureLoaderOptions = {}
|
|
21
|
+
): Promise<any> {
|
|
12
22
|
const imageUrls = await getImageUrls(getUrl, options);
|
|
13
|
-
return await
|
|
23
|
+
return await loadCompositeImageUrlTree(imageUrls, normalizeCompositeImageOptions(options));
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
export async function getImageUrls(
|
|
17
27
|
getUrl: string | GetUrl,
|
|
18
|
-
options:
|
|
28
|
+
options: TextureLoaderOptions,
|
|
19
29
|
urlOptions: UrlOptions = {}
|
|
20
30
|
): Promise<any> {
|
|
21
31
|
const mipLevels = (options && options.image && options.image.mipLevels) || 0;
|
|
@@ -27,15 +37,16 @@ export async function getImageUrls(
|
|
|
27
37
|
async function getMipmappedImageUrls(
|
|
28
38
|
getUrl: string | GetUrl,
|
|
29
39
|
mipLevels: number | 'auto',
|
|
30
|
-
options:
|
|
40
|
+
options: TextureLoaderOptions,
|
|
31
41
|
urlOptions: UrlOptions
|
|
32
42
|
): Promise<string[]> {
|
|
33
43
|
const urls: string[] = [];
|
|
44
|
+
const normalizedOptions = normalizeCompositeImageOptions(options);
|
|
34
45
|
|
|
35
46
|
// If no mip levels supplied, we need to load the level 0 image and calculate based on size
|
|
36
47
|
if (mipLevels === 'auto') {
|
|
37
48
|
const url = generateUrl(getUrl, options, {...urlOptions, lod: 0});
|
|
38
|
-
const image = await
|
|
49
|
+
const image = await loadCompositeImageMember(url, normalizedOptions);
|
|
39
50
|
|
|
40
51
|
const {width, height} = getImageSize(image);
|
|
41
52
|
mipLevels = getMipLevels({width, height});
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import type {LoaderOptions} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {ImageLoaderOptions} from '@loaders.gl/images';
|
|
7
|
+
|
|
5
8
|
export type {ImageType} from '@loaders.gl/images';
|
|
6
9
|
|
|
7
10
|
export type UrlOptions = {
|
|
@@ -12,3 +15,15 @@ export type UrlOptions = {
|
|
|
12
15
|
direction?: string;
|
|
13
16
|
};
|
|
14
17
|
export type GetUrl = (options: UrlOptions) => string;
|
|
18
|
+
|
|
19
|
+
export type TextureLoaderOptions = LoaderOptions & {
|
|
20
|
+
core?: NonNullable<LoaderOptions['core']> & {
|
|
21
|
+
/** Base URL for resolving composite image members when no loader context URL is available */
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
};
|
|
24
|
+
/** @deprecated Legacy helper alias kept for loadImageTexture* compatibility */
|
|
25
|
+
baseUrl?: string;
|
|
26
|
+
image?: NonNullable<ImageLoaderOptions['image']> & {
|
|
27
|
+
mipLevels?: number | 'auto';
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {GPUTextureFormat, TextureFormat} from '@loaders.gl/schema';
|
|
6
|
+
|
|
7
|
+
const BROWSER_PREFIXES = ['', 'WEBKIT_', 'MOZ_'];
|
|
8
|
+
|
|
9
|
+
const WEBGL_TEXTURE_FORMATS: {[key: string]: TextureFormat[]} = {
|
|
10
|
+
/* eslint-disable camelcase */
|
|
11
|
+
WEBGL_compressed_texture_s3tc: [
|
|
12
|
+
'bc1-rgb-unorm-webgl',
|
|
13
|
+
'bc1-rgba-unorm',
|
|
14
|
+
'bc2-rgba-unorm',
|
|
15
|
+
'bc3-rgba-unorm'
|
|
16
|
+
],
|
|
17
|
+
WEBGL_compressed_texture_s3tc_srgb: [
|
|
18
|
+
'bc1-rgb-unorm-srgb-webgl',
|
|
19
|
+
'bc1-rgba-unorm-srgb',
|
|
20
|
+
'bc2-rgba-unorm-srgb',
|
|
21
|
+
'bc3-rgba-unorm-srgb'
|
|
22
|
+
],
|
|
23
|
+
EXT_texture_compression_rgtc: ['bc4-r-unorm', 'bc4-r-snorm', 'bc5-rg-unorm', 'bc5-rg-snorm'],
|
|
24
|
+
EXT_texture_compression_bptc: [
|
|
25
|
+
'bc6h-rgb-ufloat',
|
|
26
|
+
'bc6h-rgb-float',
|
|
27
|
+
'bc7-rgba-unorm',
|
|
28
|
+
'bc7-rgba-unorm-srgb'
|
|
29
|
+
],
|
|
30
|
+
WEBGL_compressed_texture_etc1: ['etc1-rgb-unorm-webgl'],
|
|
31
|
+
WEBGL_compressed_texture_etc: [
|
|
32
|
+
'etc2-rgb8unorm',
|
|
33
|
+
'etc2-rgb8unorm-srgb',
|
|
34
|
+
'etc2-rgb8a1unorm',
|
|
35
|
+
'etc2-rgb8a1unorm-srgb',
|
|
36
|
+
'etc2-rgba8unorm',
|
|
37
|
+
'etc2-rgba8unorm-srgb',
|
|
38
|
+
'eac-r11unorm',
|
|
39
|
+
'eac-r11snorm',
|
|
40
|
+
'eac-rg11unorm',
|
|
41
|
+
'eac-rg11snorm'
|
|
42
|
+
],
|
|
43
|
+
WEBGL_compressed_texture_pvrtc: [
|
|
44
|
+
'pvrtc-rgb4unorm-webgl',
|
|
45
|
+
'pvrtc-rgba4unorm-webgl',
|
|
46
|
+
'pvrtc-rgb2unorm-webgl',
|
|
47
|
+
'pvrtc-rgba2unorm-webgl'
|
|
48
|
+
],
|
|
49
|
+
WEBGL_compressed_texture_atc: [
|
|
50
|
+
'atc-rgb-unorm-webgl',
|
|
51
|
+
'atc-rgba-unorm-webgl',
|
|
52
|
+
'atc-rgbai-unorm-webgl'
|
|
53
|
+
],
|
|
54
|
+
WEBGL_compressed_texture_astc: [
|
|
55
|
+
'astc-4x4-unorm',
|
|
56
|
+
'astc-4x4-unorm-srgb',
|
|
57
|
+
'astc-5x4-unorm',
|
|
58
|
+
'astc-5x4-unorm-srgb',
|
|
59
|
+
'astc-5x5-unorm',
|
|
60
|
+
'astc-5x5-unorm-srgb',
|
|
61
|
+
'astc-6x5-unorm',
|
|
62
|
+
'astc-6x5-unorm-srgb',
|
|
63
|
+
'astc-6x6-unorm',
|
|
64
|
+
'astc-6x6-unorm-srgb',
|
|
65
|
+
'astc-8x5-unorm',
|
|
66
|
+
'astc-8x5-unorm-srgb',
|
|
67
|
+
'astc-8x6-unorm',
|
|
68
|
+
'astc-8x6-unorm-srgb',
|
|
69
|
+
'astc-8x8-unorm',
|
|
70
|
+
'astc-8x8-unorm-srgb',
|
|
71
|
+
'astc-10x5-unorm',
|
|
72
|
+
'astc-10x5-unorm-srgb',
|
|
73
|
+
'astc-10x6-unorm',
|
|
74
|
+
'astc-10x6-unorm-srgb',
|
|
75
|
+
'astc-10x8-unorm',
|
|
76
|
+
'astc-10x8-unorm-srgb',
|
|
77
|
+
'astc-10x10-unorm',
|
|
78
|
+
'astc-10x10-unorm-srgb',
|
|
79
|
+
'astc-12x10-unorm',
|
|
80
|
+
'astc-12x10-unorm-srgb',
|
|
81
|
+
'astc-12x12-unorm',
|
|
82
|
+
'astc-12x12-unorm-srgb'
|
|
83
|
+
]
|
|
84
|
+
/* eslint-enable camelcase */
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const GPU_TEXTURE_FORMATS: {[key in GPUTextureFormat]: TextureFormat[]} = {
|
|
88
|
+
dxt: ['bc1-rgb-unorm-webgl', 'bc1-rgba-unorm', 'bc2-rgba-unorm', 'bc3-rgba-unorm'],
|
|
89
|
+
'dxt-srgb': [
|
|
90
|
+
'bc1-rgb-unorm-srgb-webgl',
|
|
91
|
+
'bc1-rgba-unorm-srgb',
|
|
92
|
+
'bc2-rgba-unorm-srgb',
|
|
93
|
+
'bc3-rgba-unorm-srgb'
|
|
94
|
+
],
|
|
95
|
+
etc1: ['etc1-rgb-unorm-webgl'],
|
|
96
|
+
etc2: [
|
|
97
|
+
'etc2-rgb8unorm',
|
|
98
|
+
'etc2-rgb8unorm-srgb',
|
|
99
|
+
'etc2-rgb8a1unorm',
|
|
100
|
+
'etc2-rgb8a1unorm-srgb',
|
|
101
|
+
'etc2-rgba8unorm',
|
|
102
|
+
'etc2-rgba8unorm-srgb',
|
|
103
|
+
'eac-r11unorm',
|
|
104
|
+
'eac-r11snorm',
|
|
105
|
+
'eac-rg11unorm',
|
|
106
|
+
'eac-rg11snorm'
|
|
107
|
+
],
|
|
108
|
+
pvrtc: [
|
|
109
|
+
'pvrtc-rgb4unorm-webgl',
|
|
110
|
+
'pvrtc-rgba4unorm-webgl',
|
|
111
|
+
'pvrtc-rgb2unorm-webgl',
|
|
112
|
+
'pvrtc-rgba2unorm-webgl'
|
|
113
|
+
],
|
|
114
|
+
atc: ['atc-rgb-unorm-webgl', 'atc-rgba-unorm-webgl', 'atc-rgbai-unorm-webgl'],
|
|
115
|
+
astc: [
|
|
116
|
+
'astc-4x4-unorm',
|
|
117
|
+
'astc-4x4-unorm-srgb',
|
|
118
|
+
'astc-5x4-unorm',
|
|
119
|
+
'astc-5x4-unorm-srgb',
|
|
120
|
+
'astc-5x5-unorm',
|
|
121
|
+
'astc-5x5-unorm-srgb',
|
|
122
|
+
'astc-6x5-unorm',
|
|
123
|
+
'astc-6x5-unorm-srgb',
|
|
124
|
+
'astc-6x6-unorm',
|
|
125
|
+
'astc-6x6-unorm-srgb',
|
|
126
|
+
'astc-8x5-unorm',
|
|
127
|
+
'astc-8x5-unorm-srgb',
|
|
128
|
+
'astc-8x6-unorm',
|
|
129
|
+
'astc-8x6-unorm-srgb',
|
|
130
|
+
'astc-8x8-unorm',
|
|
131
|
+
'astc-8x8-unorm-srgb',
|
|
132
|
+
'astc-10x5-unorm',
|
|
133
|
+
'astc-10x5-unorm-srgb',
|
|
134
|
+
'astc-10x6-unorm',
|
|
135
|
+
'astc-10x6-unorm-srgb',
|
|
136
|
+
'astc-10x8-unorm',
|
|
137
|
+
'astc-10x8-unorm-srgb',
|
|
138
|
+
'astc-10x10-unorm',
|
|
139
|
+
'astc-10x10-unorm-srgb',
|
|
140
|
+
'astc-12x10-unorm',
|
|
141
|
+
'astc-12x10-unorm-srgb',
|
|
142
|
+
'astc-12x12-unorm',
|
|
143
|
+
'astc-12x12-unorm-srgb'
|
|
144
|
+
],
|
|
145
|
+
rgtc: ['bc4-r-unorm', 'bc4-r-snorm', 'bc5-rg-unorm', 'bc5-rg-snorm']
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
let formats: Set<GPUTextureFormat> | null = null;
|
|
149
|
+
let textureFormats: Set<TextureFormat> | null = null;
|
|
150
|
+
|
|
151
|
+
// DEPRECATED
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated Pass `basis.supportedTextureFormats` to Basis loaders instead of relying on global detection.
|
|
154
|
+
*/
|
|
155
|
+
export function detectSupportedTextureFormats(gl?: WebGLRenderingContext): Set<TextureFormat> {
|
|
156
|
+
if (!textureFormats) {
|
|
157
|
+
gl = gl || getWebGLContext() || undefined;
|
|
158
|
+
textureFormats = new Set<TextureFormat>();
|
|
159
|
+
|
|
160
|
+
for (const prefix of BROWSER_PREFIXES) {
|
|
161
|
+
for (const extension in WEBGL_TEXTURE_FORMATS) {
|
|
162
|
+
if (gl && gl.getExtension(`${prefix}${extension}`)) {
|
|
163
|
+
for (const textureFormat of WEBGL_TEXTURE_FORMATS[extension]) {
|
|
164
|
+
textureFormats.add(textureFormat);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return textureFormats;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// DEPRECATED
|
|
175
|
+
/**
|
|
176
|
+
* Returns a list of formats.
|
|
177
|
+
* Creates a temporary WebGLRenderingContext if none is provided.
|
|
178
|
+
*
|
|
179
|
+
* @deprecated Pass `basis.supportedTextureFormats` to Basis loaders instead of relying on global detection.
|
|
180
|
+
* @param gl - Optional context.
|
|
181
|
+
*/
|
|
182
|
+
export function detectSupportedGPUTextureFormats(gl?: WebGLRenderingContext): Set<string> {
|
|
183
|
+
if (!formats) {
|
|
184
|
+
formats = new Set<GPUTextureFormat>();
|
|
185
|
+
const supportedTextureFormats = detectSupportedTextureFormats(gl);
|
|
186
|
+
|
|
187
|
+
for (const gpuTextureFormat in GPU_TEXTURE_FORMATS) {
|
|
188
|
+
const textureFormatsForGroup = GPU_TEXTURE_FORMATS[gpuTextureFormat as GPUTextureFormat];
|
|
189
|
+
if (
|
|
190
|
+
textureFormatsForGroup.some((textureFormat) => supportedTextureFormats.has(textureFormat))
|
|
191
|
+
) {
|
|
192
|
+
formats.add(gpuTextureFormat as GPUTextureFormat);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return formats;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @returns {WebGLRenderingContext?}
|
|
202
|
+
*/
|
|
203
|
+
function getWebGLContext() {
|
|
204
|
+
try {
|
|
205
|
+
const canvas = document.createElement('canvas');
|
|
206
|
+
return canvas.getContext('webgl');
|
|
207
|
+
} catch (error) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -2,14 +2,21 @@
|
|
|
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
|
+
import type {GLTextureFormat} from '../gl-types';
|
|
7
|
+
import {
|
|
8
|
+
getTextureFormatFromWebGLFormat,
|
|
9
|
+
getWebGLFormatFromTextureFormat
|
|
10
|
+
} from './texture-format-map';
|
|
6
11
|
|
|
7
12
|
export type CompressedTextureExtractOptions = {
|
|
8
13
|
mipMapLevels: number;
|
|
9
14
|
width: number;
|
|
10
15
|
height: number;
|
|
11
16
|
sizeFunction: Function;
|
|
12
|
-
internalFormat
|
|
17
|
+
internalFormat?: GLTextureFormat;
|
|
18
|
+
/** Canonical loaders.gl texture format for the mip levels being extracted. */
|
|
19
|
+
textureFormat?: TextureFormat;
|
|
13
20
|
};
|
|
14
21
|
|
|
15
22
|
/**
|
|
@@ -20,6 +27,7 @@ export type CompressedTextureExtractOptions = {
|
|
|
20
27
|
* @param options.height - height of 0 - level
|
|
21
28
|
* @param options.sizeFunction - format-related function to calculate level size in bytes
|
|
22
29
|
* @param options.internalFormat - WebGL compatible format code
|
|
30
|
+
* @param options.textureFormat - canonical loaders.gl texture format
|
|
23
31
|
* @returns Array of the texture levels
|
|
24
32
|
*/
|
|
25
33
|
export function extractMipmapImages(
|
|
@@ -27,6 +35,9 @@ export function extractMipmapImages(
|
|
|
27
35
|
options: CompressedTextureExtractOptions
|
|
28
36
|
): TextureLevel[] {
|
|
29
37
|
const images = new Array(options.mipMapLevels);
|
|
38
|
+
const textureFormat =
|
|
39
|
+
options.textureFormat || getTextureFormatFromWebGLFormat(options.internalFormat);
|
|
40
|
+
const format = options.internalFormat || getWebGLFormatFromTextureFormat(options.textureFormat);
|
|
30
41
|
|
|
31
42
|
let levelWidth = options.width;
|
|
32
43
|
let levelHeight = options.height;
|
|
@@ -38,15 +49,23 @@ export function extractMipmapImages(
|
|
|
38
49
|
// @ts-expect-error
|
|
39
50
|
const levelData = getLevelData(data, i, offset, levelSize);
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
const image: TextureLevel = {
|
|
53
|
+
shape: 'texture-level',
|
|
42
54
|
compressed: true,
|
|
43
|
-
format: options.internalFormat,
|
|
44
55
|
data: levelData,
|
|
45
56
|
width: levelWidth,
|
|
46
57
|
height: levelHeight,
|
|
47
58
|
levelSize
|
|
48
59
|
};
|
|
49
60
|
|
|
61
|
+
if (format !== undefined) {
|
|
62
|
+
image.format = format;
|
|
63
|
+
}
|
|
64
|
+
if (textureFormat) {
|
|
65
|
+
image.textureFormat = textureFormat;
|
|
66
|
+
}
|
|
67
|
+
images[i] = image;
|
|
68
|
+
|
|
50
69
|
levelWidth = Math.max(1, levelWidth >> 1);
|
|
51
70
|
levelHeight = Math.max(1, levelHeight >> 1);
|
|
52
71
|
|