@loaders.gl/textures 4.4.0-alpha.18 → 4.4.0-alpha.19
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 +153 -1
- package/dist/basis-worker-node.js +44 -28
- package/dist/basis-worker.js +43 -27
- package/dist/compressed-texture-worker.js +110 -77
- package/dist/crunch-worker.js +24 -10
- package/dist/dist.dev.js +1323 -239
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +1024 -151
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/ktx2-basis-writer-worker-node.js +2 -2
- package/dist/ktx2-basis-writer-worker.js +2 -2
- 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/gl-extensions.d.ts +2 -0
- package/dist/lib/gl-extensions.d.ts.map +1 -1
- package/dist/lib/gl-extensions.js +2 -0
- package/dist/lib/gl-extensions.js.map +1 -1
- 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/parse-basis.d.ts +9 -1
- package/dist/lib/parsers/parse-basis.d.ts.map +1 -1
- package/dist/lib/parsers/parse-basis.js +48 -25
- package/dist/lib/parsers/parse-basis.js.map +1 -1
- package/dist/lib/parsers/parse-crunch.d.ts.map +1 -1
- package/dist/lib/parsers/parse-crunch.js +4 -5
- package/dist/lib/parsers/parse-crunch.js.map +1 -1
- package/dist/lib/parsers/parse-dds.d.ts.map +1 -1
- package/dist/lib/parsers/parse-dds.js +10 -11
- package/dist/lib/parsers/parse-dds.js.map +1 -1
- 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 +5 -5
- package/dist/lib/parsers/parse-ktx.js.map +1 -1
- package/dist/lib/parsers/parse-pvr.d.ts.map +1 -1
- package/dist/lib/parsers/parse-pvr.js +31 -32
- package/dist/lib/parsers/parse-pvr.js.map +1 -1
- package/dist/lib/texture-api/generate-url.d.ts.map +1 -1
- package/dist/lib/texture-api/generate-url.js +2 -10
- package/dist/lib/texture-api/generate-url.js.map +1 -1
- 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 +5 -3
- package/dist/lib/texture-api/load-image-array.js.map +1 -1
- 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 +8 -20
- package/dist/lib/texture-api/load-image-cube.js.map +1 -1
- 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 +8 -4
- package/dist/lib/texture-api/load-image.js.map +1 -1
- 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/utils/detect-supported-texture-formats.js +4 -4
- package/dist/lib/utils/extract-mipmap-images.d.ts +5 -1
- package/dist/lib/utils/extract-mipmap-images.d.ts.map +1 -1
- package/dist/lib/utils/extract-mipmap-images.js +4 -3
- package/dist/lib/utils/extract-mipmap-images.js.map +1 -1
- package/dist/lib/utils/ktx-format-helper.d.ts +8 -1
- package/dist/lib/utils/ktx-format-helper.d.ts.map +1 -1
- package/dist/lib/utils/ktx-format-helper.js +9 -0
- package/dist/lib/utils/ktx-format-helper.js.map +1 -1
- package/dist/lib/utils/texture-format-map.d.ts +8 -1
- package/dist/lib/utils/texture-format-map.d.ts.map +1 -1
- package/dist/lib/utils/texture-format-map.js +19 -3
- package/dist/lib/utils/texture-format-map.js.map +1 -1
- package/dist/lib/utils/version.js +1 -1
- package/dist/npy-worker.js +1 -1
- 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/package.json +6 -6
- package/src/index.ts +19 -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/gl-extensions.ts +2 -0
- package/src/lib/gl-types.ts +136 -0
- package/src/lib/parsers/parse-basis.ts +54 -26
- package/src/lib/parsers/parse-crunch.ts +6 -11
- package/src/lib/parsers/parse-dds.ts +11 -19
- package/src/lib/parsers/parse-hdr.ts +426 -0
- package/src/lib/parsers/parse-ktx.ts +6 -6
- 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 +4 -4
- package/src/lib/utils/extract-mipmap-images.ts +12 -4
- package/src/lib/utils/ktx-format-helper.ts +12 -1
- package/src/lib/utils/texture-format-map.ts +30 -3
- 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
|
@@ -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
|
+
};
|
|
@@ -27,7 +27,7 @@ const WEBGL_TEXTURE_FORMATS: {[key: string]: TextureFormat[]} = {
|
|
|
27
27
|
'bc7-rgba-unorm',
|
|
28
28
|
'bc7-rgba-unorm-srgb'
|
|
29
29
|
],
|
|
30
|
-
WEBGL_compressed_texture_etc1: ['etc1-
|
|
30
|
+
WEBGL_compressed_texture_etc1: ['etc1-rgb-unorm-webgl'],
|
|
31
31
|
WEBGL_compressed_texture_etc: [
|
|
32
32
|
'etc2-rgb8unorm',
|
|
33
33
|
'etc2-rgb8unorm-srgb',
|
|
@@ -43,7 +43,7 @@ const WEBGL_TEXTURE_FORMATS: {[key: string]: TextureFormat[]} = {
|
|
|
43
43
|
WEBGL_compressed_texture_pvrtc: [
|
|
44
44
|
'pvrtc-rgb4unorm-webgl',
|
|
45
45
|
'pvrtc-rgba4unorm-webgl',
|
|
46
|
-
'pvrtc-
|
|
46
|
+
'pvrtc-rgb2unorm-webgl',
|
|
47
47
|
'pvrtc-rgba2unorm-webgl'
|
|
48
48
|
],
|
|
49
49
|
WEBGL_compressed_texture_atc: [
|
|
@@ -92,7 +92,7 @@ const GPU_TEXTURE_FORMATS: {[key in GPUTextureFormat]: TextureFormat[]} = {
|
|
|
92
92
|
'bc2-rgba-unorm-srgb',
|
|
93
93
|
'bc3-rgba-unorm-srgb'
|
|
94
94
|
],
|
|
95
|
-
etc1: ['etc1-
|
|
95
|
+
etc1: ['etc1-rgb-unorm-webgl'],
|
|
96
96
|
etc2: [
|
|
97
97
|
'etc2-rgb8unorm',
|
|
98
98
|
'etc2-rgb8unorm-srgb',
|
|
@@ -108,7 +108,7 @@ const GPU_TEXTURE_FORMATS: {[key in GPUTextureFormat]: TextureFormat[]} = {
|
|
|
108
108
|
pvrtc: [
|
|
109
109
|
'pvrtc-rgb4unorm-webgl',
|
|
110
110
|
'pvrtc-rgba4unorm-webgl',
|
|
111
|
-
'pvrtc-
|
|
111
|
+
'pvrtc-rgb2unorm-webgl',
|
|
112
112
|
'pvrtc-rgba2unorm-webgl'
|
|
113
113
|
],
|
|
114
114
|
atc: ['atc-rgb-unorm-webgl', 'atc-rgba-unorm-webgl', 'atc-rgbai-unorm-webgl'],
|
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
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';
|
|
7
11
|
|
|
8
12
|
export type CompressedTextureExtractOptions = {
|
|
9
13
|
mipMapLevels: number;
|
|
@@ -11,6 +15,8 @@ export type CompressedTextureExtractOptions = {
|
|
|
11
15
|
height: number;
|
|
12
16
|
sizeFunction: Function;
|
|
13
17
|
internalFormat?: GLTextureFormat;
|
|
18
|
+
/** Canonical loaders.gl texture format for the mip levels being extracted. */
|
|
19
|
+
textureFormat?: TextureFormat;
|
|
14
20
|
};
|
|
15
21
|
|
|
16
22
|
/**
|
|
@@ -21,6 +27,7 @@ export type CompressedTextureExtractOptions = {
|
|
|
21
27
|
* @param options.height - height of 0 - level
|
|
22
28
|
* @param options.sizeFunction - format-related function to calculate level size in bytes
|
|
23
29
|
* @param options.internalFormat - WebGL compatible format code
|
|
30
|
+
* @param options.textureFormat - canonical loaders.gl texture format
|
|
24
31
|
* @returns Array of the texture levels
|
|
25
32
|
*/
|
|
26
33
|
export function extractMipmapImages(
|
|
@@ -28,8 +35,9 @@ export function extractMipmapImages(
|
|
|
28
35
|
options: CompressedTextureExtractOptions
|
|
29
36
|
): TextureLevel[] {
|
|
30
37
|
const images = new Array(options.mipMapLevels);
|
|
31
|
-
const
|
|
32
|
-
|
|
38
|
+
const textureFormat =
|
|
39
|
+
options.textureFormat || getTextureFormatFromWebGLFormat(options.internalFormat);
|
|
40
|
+
const format = options.internalFormat || getWebGLFormatFromTextureFormat(options.textureFormat);
|
|
33
41
|
|
|
34
42
|
let levelWidth = options.width;
|
|
35
43
|
let levelHeight = options.height;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
|
-
import type {
|
|
6
|
+
import type {TextureFormat} from '@loaders.gl/schema';
|
|
7
|
+
import type {GLTextureFormat} from '../gl-types';
|
|
7
8
|
import {
|
|
8
9
|
GL_COMPRESSED_R11_EAC,
|
|
9
10
|
GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
|
|
@@ -58,6 +59,7 @@ import {
|
|
|
58
59
|
GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
|
|
59
60
|
GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
|
|
60
61
|
} from '../gl-extensions';
|
|
62
|
+
import {getTextureFormatFromWebGLFormat} from './texture-format-map';
|
|
61
63
|
|
|
62
64
|
const VULKAN_TO_WEBGL_FORMAT_MAP: Record<number, GLTextureFormat> = {
|
|
63
65
|
131: GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
|
|
@@ -138,3 +140,12 @@ const VULKAN_TO_WEBGL_FORMAT_MAP: Record<number, GLTextureFormat> = {
|
|
|
138
140
|
export function mapVkFormatToWebGL(vkFormat: number): GLTextureFormat | undefined {
|
|
139
141
|
return VULKAN_TO_WEBGL_FORMAT_MAP[vkFormat];
|
|
140
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Returns the canonical loaders.gl texture format corresponding to a Vulkan `vkFormat` value.
|
|
146
|
+
* @param vkFormat - Vulkan format constant from the KTX container.
|
|
147
|
+
* @returns Canonical texture format string, if known.
|
|
148
|
+
*/
|
|
149
|
+
export function mapVkFormatToTextureFormat(vkFormat: number): TextureFormat | undefined {
|
|
150
|
+
return getTextureFormatFromWebGLFormat(mapVkFormatToWebGL(vkFormat));
|
|
151
|
+
}
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
import type {TextureFormat} from '@loaders.gl/schema';
|
|
7
|
+
import type {GLTextureFormat} from '../gl-types';
|
|
7
8
|
import {
|
|
9
|
+
GL_RGBA32F,
|
|
8
10
|
GL_COMPRESSED_R11_EAC,
|
|
9
11
|
GL_COMPRESSED_RED_GREEN_RGTC2_EXT,
|
|
10
12
|
GL_COMPRESSED_RED_RGTC1_EXT,
|
|
@@ -66,6 +68,7 @@ import {
|
|
|
66
68
|
} from '../gl-extensions';
|
|
67
69
|
|
|
68
70
|
const WEBGL_TO_TEXTURE_FORMAT: Record<number, TextureFormat> = {
|
|
71
|
+
[GL_RGBA32F]: 'rgba32float',
|
|
69
72
|
[GL_COMPRESSED_RGB_S3TC_DXT1_EXT]: 'bc1-rgb-unorm-webgl',
|
|
70
73
|
[GL_COMPRESSED_SRGB_S3TC_DXT1_EXT]: 'bc1-rgb-unorm-srgb-webgl',
|
|
71
74
|
[GL_COMPRESSED_RGBA_S3TC_DXT1_EXT]: 'bc1-rgba-unorm',
|
|
@@ -118,18 +121,42 @@ const WEBGL_TO_TEXTURE_FORMAT: Record<number, TextureFormat> = {
|
|
|
118
121
|
[GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR]: 'astc-12x12-unorm-srgb',
|
|
119
122
|
[GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG]: 'pvrtc-rgb4unorm-webgl',
|
|
120
123
|
[GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG]: 'pvrtc-rgba4unorm-webgl',
|
|
121
|
-
[GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG]: 'pvrtc-
|
|
124
|
+
[GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG]: 'pvrtc-rgb2unorm-webgl',
|
|
122
125
|
[GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG]: 'pvrtc-rgba2unorm-webgl',
|
|
123
|
-
[GL_COMPRESSED_RGB_ETC1_WEBGL]: 'etc1-
|
|
126
|
+
[GL_COMPRESSED_RGB_ETC1_WEBGL]: 'etc1-rgb-unorm-webgl',
|
|
124
127
|
[GL_COMPRESSED_RGB_ATC_WEBGL]: 'atc-rgb-unorm-webgl',
|
|
125
128
|
[GL_COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL]: 'atc-rgba-unorm-webgl',
|
|
126
129
|
[GL_COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL]: 'atc-rgbai-unorm-webgl'
|
|
127
130
|
};
|
|
128
131
|
|
|
129
|
-
|
|
132
|
+
const TEXTURE_FORMAT_TO_WEBGL = Object.fromEntries(
|
|
133
|
+
Object.entries(WEBGL_TO_TEXTURE_FORMAT).map(([format, textureFormat]) => [
|
|
134
|
+
textureFormat,
|
|
135
|
+
Number(format)
|
|
136
|
+
])
|
|
137
|
+
) as Partial<Record<TextureFormat, GLTextureFormat>>;
|
|
138
|
+
|
|
139
|
+
export function getTextureFormatFromWebGLFormat(
|
|
140
|
+
format?: GLTextureFormat
|
|
141
|
+
): TextureFormat | undefined {
|
|
130
142
|
if (format === undefined) {
|
|
131
143
|
return undefined;
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
return WEBGL_TO_TEXTURE_FORMAT[format];
|
|
135
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Returns the WebGL/OpenGL compressed texture constant for a canonical loaders.gl texture format.
|
|
151
|
+
* @param textureFormat - Canonical texture format string.
|
|
152
|
+
* @returns Matching WebGL/OpenGL constant, if known.
|
|
153
|
+
*/
|
|
154
|
+
export function getWebGLFormatFromTextureFormat(
|
|
155
|
+
textureFormat?: TextureFormat
|
|
156
|
+
): GLTextureFormat | undefined {
|
|
157
|
+
if (textureFormat === undefined) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return TEXTURE_FORMAT_TO_WEBGL[textureFormat];
|
|
162
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {LoaderWithParser, StrictLoaderOptions} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {Texture} from '@loaders.gl/schema';
|
|
7
|
+
import {VERSION} from './lib/utils/version';
|
|
8
|
+
import type {RadianceHDRMetadata} from './lib/parsers/parse-hdr';
|
|
9
|
+
import {isHDR, parseHDR} from './lib/parsers/parse-hdr';
|
|
10
|
+
|
|
11
|
+
export type RadianceHDRLoaderOptions = StrictLoaderOptions & {
|
|
12
|
+
hdr?: {};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const RadianceHDRLoader = {
|
|
16
|
+
dataType: null as unknown as Texture<RadianceHDRMetadata>,
|
|
17
|
+
batchType: null as never,
|
|
18
|
+
|
|
19
|
+
name: 'Radiance HDR',
|
|
20
|
+
id: 'hdr',
|
|
21
|
+
module: 'textures',
|
|
22
|
+
version: VERSION,
|
|
23
|
+
extensions: ['hdr'],
|
|
24
|
+
mimeTypes: ['image/vnd.radiance', 'image/x-hdr', 'application/octet-stream'],
|
|
25
|
+
binary: true,
|
|
26
|
+
tests: [isHDR],
|
|
27
|
+
options: {
|
|
28
|
+
hdr: {}
|
|
29
|
+
},
|
|
30
|
+
parseSync: parseHDR,
|
|
31
|
+
parse: async (arrayBuffer: ArrayBuffer) => parseHDR(arrayBuffer)
|
|
32
|
+
} as const satisfies LoaderWithParser<
|
|
33
|
+
Texture<RadianceHDRMetadata>,
|
|
34
|
+
never,
|
|
35
|
+
RadianceHDRLoaderOptions
|
|
36
|
+
>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {LoaderContext, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {Texture} from '@loaders.gl/schema';
|
|
7
|
+
import type {TextureLoaderOptions as TextureApiLoaderOptions} from './lib/texture-api/texture-api-types';
|
|
8
|
+
import {VERSION} from './lib/utils/version';
|
|
9
|
+
import {
|
|
10
|
+
parseCompositeImageManifest,
|
|
11
|
+
testCompositeImageManifestShape,
|
|
12
|
+
type ImageTextureArrayManifest
|
|
13
|
+
} from './lib/composite-image/parse-composite-image';
|
|
14
|
+
|
|
15
|
+
export type TextureArrayLoaderOptions = TextureApiLoaderOptions;
|
|
16
|
+
export type {ImageTextureArrayManifest as TextureArrayManifest};
|
|
17
|
+
|
|
18
|
+
export const TextureArrayLoader = {
|
|
19
|
+
dataType: null as unknown as Texture,
|
|
20
|
+
batchType: null as never,
|
|
21
|
+
id: 'texture-array',
|
|
22
|
+
name: 'Texture Array',
|
|
23
|
+
module: 'textures',
|
|
24
|
+
version: VERSION,
|
|
25
|
+
extensions: [],
|
|
26
|
+
mimeTypes: [],
|
|
27
|
+
text: true,
|
|
28
|
+
worker: false,
|
|
29
|
+
testText: (text: string) => testCompositeImageManifestShape(text, 'image-texture-array'),
|
|
30
|
+
options: {
|
|
31
|
+
image: {}
|
|
32
|
+
},
|
|
33
|
+
parse: async (
|
|
34
|
+
arrayBuffer: ArrayBuffer,
|
|
35
|
+
options?: TextureArrayLoaderOptions,
|
|
36
|
+
context?: LoaderContext
|
|
37
|
+
) =>
|
|
38
|
+
await parseCompositeImageManifest(
|
|
39
|
+
new TextDecoder().decode(arrayBuffer),
|
|
40
|
+
'image-texture-array',
|
|
41
|
+
options,
|
|
42
|
+
context
|
|
43
|
+
),
|
|
44
|
+
parseText: async (text: string, options?: TextureArrayLoaderOptions, context?: LoaderContext) =>
|
|
45
|
+
await parseCompositeImageManifest(text, 'image-texture-array', options, context)
|
|
46
|
+
} as const satisfies LoaderWithParser<Texture, never, TextureArrayLoaderOptions>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {LoaderContext, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {Texture} from '@loaders.gl/schema';
|
|
7
|
+
import type {TextureLoaderOptions as TextureApiLoaderOptions} from './lib/texture-api/texture-api-types';
|
|
8
|
+
import {VERSION} from './lib/utils/version';
|
|
9
|
+
import {
|
|
10
|
+
parseCompositeImageManifest,
|
|
11
|
+
testCompositeImageManifestShape,
|
|
12
|
+
type ImageTextureCubeArrayManifest
|
|
13
|
+
} from './lib/composite-image/parse-composite-image';
|
|
14
|
+
|
|
15
|
+
export type TextureCubeArrayLoaderOptions = TextureApiLoaderOptions;
|
|
16
|
+
export type {ImageTextureCubeArrayManifest as TextureCubeArrayManifest};
|
|
17
|
+
|
|
18
|
+
export const TextureCubeArrayLoader = {
|
|
19
|
+
dataType: null as unknown as Texture,
|
|
20
|
+
batchType: null as never,
|
|
21
|
+
id: 'texture-cube-array',
|
|
22
|
+
name: 'Texture Cube Array',
|
|
23
|
+
module: 'textures',
|
|
24
|
+
version: VERSION,
|
|
25
|
+
extensions: [],
|
|
26
|
+
mimeTypes: [],
|
|
27
|
+
text: true,
|
|
28
|
+
worker: false,
|
|
29
|
+
testText: (text: string) => testCompositeImageManifestShape(text, 'image-texture-cube-array'),
|
|
30
|
+
options: {
|
|
31
|
+
image: {}
|
|
32
|
+
},
|
|
33
|
+
parse: async (
|
|
34
|
+
arrayBuffer: ArrayBuffer,
|
|
35
|
+
options?: TextureCubeArrayLoaderOptions,
|
|
36
|
+
context?: LoaderContext
|
|
37
|
+
) =>
|
|
38
|
+
await parseCompositeImageManifest(
|
|
39
|
+
new TextDecoder().decode(arrayBuffer),
|
|
40
|
+
'image-texture-cube-array',
|
|
41
|
+
options,
|
|
42
|
+
context
|
|
43
|
+
),
|
|
44
|
+
parseText: async (
|
|
45
|
+
text: string,
|
|
46
|
+
options?: TextureCubeArrayLoaderOptions,
|
|
47
|
+
context?: LoaderContext
|
|
48
|
+
) => await parseCompositeImageManifest(text, 'image-texture-cube-array', options, context)
|
|
49
|
+
} as const satisfies LoaderWithParser<Texture, never, TextureCubeArrayLoaderOptions>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {LoaderContext, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {Texture} from '@loaders.gl/schema';
|
|
7
|
+
import type {TextureLoaderOptions as TextureApiLoaderOptions} from './lib/texture-api/texture-api-types';
|
|
8
|
+
import {VERSION} from './lib/utils/version';
|
|
9
|
+
import {
|
|
10
|
+
parseCompositeImageManifest,
|
|
11
|
+
testCompositeImageManifestShape,
|
|
12
|
+
type ImageTextureCubeManifest
|
|
13
|
+
} from './lib/composite-image/parse-composite-image';
|
|
14
|
+
|
|
15
|
+
export type TextureCubeLoaderOptions = TextureApiLoaderOptions;
|
|
16
|
+
export type {ImageTextureCubeManifest as TextureCubeManifest};
|
|
17
|
+
|
|
18
|
+
export const TextureCubeLoader = {
|
|
19
|
+
dataType: null as unknown as Texture,
|
|
20
|
+
batchType: null as never,
|
|
21
|
+
id: 'texture-cube',
|
|
22
|
+
name: 'Texture Cube',
|
|
23
|
+
module: 'textures',
|
|
24
|
+
version: VERSION,
|
|
25
|
+
extensions: [],
|
|
26
|
+
mimeTypes: [],
|
|
27
|
+
text: true,
|
|
28
|
+
worker: false,
|
|
29
|
+
testText: (text: string) => testCompositeImageManifestShape(text, 'image-texture-cube'),
|
|
30
|
+
options: {
|
|
31
|
+
image: {}
|
|
32
|
+
},
|
|
33
|
+
parse: async (
|
|
34
|
+
arrayBuffer: ArrayBuffer,
|
|
35
|
+
options?: TextureCubeLoaderOptions,
|
|
36
|
+
context?: LoaderContext
|
|
37
|
+
) =>
|
|
38
|
+
await parseCompositeImageManifest(
|
|
39
|
+
new TextDecoder().decode(arrayBuffer),
|
|
40
|
+
'image-texture-cube',
|
|
41
|
+
options,
|
|
42
|
+
context
|
|
43
|
+
),
|
|
44
|
+
parseText: async (text: string, options?: TextureCubeLoaderOptions, context?: LoaderContext) =>
|
|
45
|
+
await parseCompositeImageManifest(text, 'image-texture-cube', options, context)
|
|
46
|
+
} as const satisfies LoaderWithParser<Texture, never, TextureCubeLoaderOptions>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {LoaderContext, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {Texture} from '@loaders.gl/schema';
|
|
7
|
+
import type {TextureLoaderOptions as TextureApiLoaderOptions} from './lib/texture-api/texture-api-types';
|
|
8
|
+
import {VERSION} from './lib/utils/version';
|
|
9
|
+
import {
|
|
10
|
+
parseCompositeImageManifest,
|
|
11
|
+
testCompositeImageManifestShape,
|
|
12
|
+
type ImageTextureManifest
|
|
13
|
+
} from './lib/composite-image/parse-composite-image';
|
|
14
|
+
|
|
15
|
+
export type TextureManifestLoaderOptions = TextureApiLoaderOptions;
|
|
16
|
+
export type {ImageTextureManifest as TextureManifest};
|
|
17
|
+
|
|
18
|
+
export const TextureLoader = {
|
|
19
|
+
dataType: null as unknown as Texture,
|
|
20
|
+
batchType: null as never,
|
|
21
|
+
id: 'texture',
|
|
22
|
+
name: 'Texture',
|
|
23
|
+
module: 'textures',
|
|
24
|
+
version: VERSION,
|
|
25
|
+
extensions: [],
|
|
26
|
+
mimeTypes: [],
|
|
27
|
+
text: true,
|
|
28
|
+
worker: false,
|
|
29
|
+
testText: (text: string) => testCompositeImageManifestShape(text, 'image-texture'),
|
|
30
|
+
options: {
|
|
31
|
+
image: {}
|
|
32
|
+
},
|
|
33
|
+
parse: async (
|
|
34
|
+
arrayBuffer: ArrayBuffer,
|
|
35
|
+
options?: TextureManifestLoaderOptions,
|
|
36
|
+
context?: LoaderContext
|
|
37
|
+
) =>
|
|
38
|
+
await parseCompositeImageManifest(
|
|
39
|
+
new TextDecoder().decode(arrayBuffer),
|
|
40
|
+
'image-texture',
|
|
41
|
+
options,
|
|
42
|
+
context
|
|
43
|
+
),
|
|
44
|
+
parseText: async (
|
|
45
|
+
text: string,
|
|
46
|
+
options?: TextureManifestLoaderOptions,
|
|
47
|
+
context?: LoaderContext
|
|
48
|
+
) => await parseCompositeImageManifest(text, 'image-texture', options, context)
|
|
49
|
+
} as const satisfies LoaderWithParser<Texture, never, TextureManifestLoaderOptions>;
|