@luma.gl/engine
Version:
3D Engine Components for luma.gl
144 lines • 6.21 kB
TypeScript
import type { TypedArray, TextureFormat, ExternalImage } from '@luma.gl/core';
export type TextureImageSource = ExternalImage;
/**
* One mip level
* Basic data structure is similar to `ImageData`
* additional optional fields can describe compressed texture data.
*/
export type TextureImageData = {
/** Preferred WebGPU style format string. */
textureFormat?: TextureFormat;
/** WebGPU style format string. Defaults to 'rgba8unorm' */
format?: TextureFormat;
/** Typed Array with the bytes of the image. @note beware row byte alignment requirements */
data: TypedArray;
/** Width of the image, in pixels, @note beware row byte alignment requirements */
width: number;
/** Height of the image, in rows */
height: number;
};
/**
* A single mip-level can be initialized by data or an ImageBitmap etc
* @note in the WebGPU spec a mip-level is called a subresource
*/
export type TextureMipLevelData = TextureImageData | TextureImageSource;
/**
* Texture data for one image "slice" (which can consist of multiple miplevels)
* Thus data for one slice be a single mip level or an array of miplevels
* @note in the WebGPU spec each cross-section image in a 3D texture is called a "slice",
* in a array texture each image in the array is called an array "layer"
* luma.gl calls one image in a GPU texture a "slice" regardless of context.
*/
export type TextureSliceData = TextureMipLevelData | TextureMipLevelData[];
/** Names of cube texture faces */
export type TextureCubeFace = '+X' | '-X' | '+Y' | '-Y' | '+Z' | '-Z';
/** Array of cube texture faces. @note: index in array is the face index */
export declare const TEXTURE_CUBE_FACES: readonly ["+X", "-X", "+Y", "-Y", "+Z", "-Z"];
/** Map of cube texture face names to face indexes */
export declare const TEXTURE_CUBE_FACE_MAP: {
readonly '+X': 0;
readonly '-X': 1;
readonly '+Y': 2;
readonly '-Y': 3;
readonly '+Z': 4;
readonly '-Z': 5;
};
/** @todo - Define what data type is supported for 1D textures. TextureImageData with height = 1 */
export type Texture1DData = TextureSliceData;
/** Texture data can be one or more mip levels */
export type Texture2DData = TextureSliceData;
/** 6 face textures */
export type TextureCubeData = Record<TextureCubeFace, TextureSliceData>;
/** Array of textures */
export type Texture3DData = TextureSliceData[];
/** Array of textures */
export type TextureArrayData = TextureSliceData[];
/** Array of 6 face textures */
export type TextureCubeArrayData = Record<TextureCubeFace, TextureSliceData>[];
type TextureData = Texture1DData | Texture3DData | TextureArrayData | TextureCubeArrayData | TextureCubeData;
/** Sync data props */
export type TextureDataProps = {
dimension: '1d';
data: Texture1DData | null;
} | {
dimension?: '2d';
data: Texture2DData | null;
} | {
dimension: '3d';
data: Texture3DData | null;
} | {
dimension: '2d-array';
data: TextureArrayData | null;
} | {
dimension: 'cube';
data: TextureCubeData | null;
} | {
dimension: 'cube-array';
data: TextureCubeArrayData | null;
};
/** Async data props */
export type TextureDataAsyncProps = {
dimension: '1d';
data?: Promise<Texture1DData> | Texture1DData | null;
} | {
dimension?: '2d';
data?: Promise<Texture2DData> | Texture2DData | null;
} | {
dimension: '3d';
data?: Promise<Texture3DData> | Texture3DData | null;
} | {
dimension: '2d-array';
data?: Promise<TextureArrayData> | TextureArrayData | null;
} | {
dimension: 'cube';
data?: Promise<TextureCubeData> | TextureCubeData | null;
} | {
dimension: 'cube-array';
data?: Promise<TextureCubeArrayData> | TextureCubeArrayData | null;
};
/** Describes data for one sub resource (one mip level of one slice (depth or array layer)) */
export type TextureSubresource = {
/** slice (depth or array layer)) */
z: number;
/** mip level (0 - max mip levels) */
mipLevel: number;
} & ({
type: 'external-image';
image: ExternalImage;
/** @deprecated is this an appropriate place for this flag? */
flipY?: boolean;
} | {
type: 'texture-data';
data: TextureImageData;
textureFormat?: TextureFormat;
});
/** Check if texture data is a typed array */
export declare function isTextureSliceData(data: TextureData): data is TextureImageData;
export declare function getFirstMipLevel(layer: TextureSliceData | null): TextureMipLevelData | null;
export declare function getTextureSizeFromData(props: TextureDataProps): {
width: number;
height: number;
} | null;
export declare function resolveTextureImageFormat(data: TextureImageData): TextureFormat | undefined;
/** Resolve size for a single mip-level datum */
/** Convert cube face label to depth index */
export declare function getCubeFaceIndex(face: TextureCubeFace): number;
/** Convert cube face label to texture slice index. Index can be used with `setTexture2DData()`. */
export declare function getCubeArrayFaceIndex(cubeIndex: number, face: TextureCubeFace): number;
/** Experimental: Set multiple mip levels (1D) */
export declare function getTexture1DSubresources(data: Texture1DData): TextureSubresource[];
/** Experimental: Set multiple mip levels (2D), optionally at `z` (depth/array index) */
export declare function getTexture2DSubresources(slice: number, lodData: Texture2DData, baseLevelSize?: {
width: number;
height: number;
}, textureFormat?: TextureFormat): TextureSubresource[];
/** 3D: multiple depth slices, each may carry multiple mip levels */
export declare function getTexture3DSubresources(data: Texture3DData): TextureSubresource[];
/** 2D array: multiple layers, each may carry multiple mip levels */
export declare function getTextureArraySubresources(data: TextureArrayData): TextureSubresource[];
/** Cube: 6 faces, each may carry multiple mip levels */
export declare function getTextureCubeSubresources(data: TextureCubeData): TextureSubresource[];
/** Cube array: multiple cubes (faces×layers), each face may carry multiple mips */
export declare function getTextureCubeArraySubresources(data: TextureCubeArrayData): TextureSubresource[];
export {};
//# sourceMappingURL=texture-data.d.ts.map