UNPKG

5.56 kBTypeScriptView Raw
1export declare type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>;
2export declare type NumericArray = number[] | TypedArray;
3export declare type TypedArray = Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
4export declare type FloatArray = Float32Array | Float64Array;
5export declare type IntArray = Int8Array | Int16Array | Int32Array;
6export declare type UIntArray = Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
7export declare type FloatArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor;
8export declare type IntArrayConstructor = Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
9export declare type UIntArrayConstructor = Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor;
10export declare type TypedArrayConstructor = FloatArrayConstructor | IntArrayConstructor | UIntArrayConstructor;
11/**
12 * Type IDs for typed array backed buffers and generally describing binary data
13 * values.
14 *
15 * {@link GLType} {@link GL2TYPE} {@link TYPE2GL}
16 */
17export declare type Type = "u8" | "u8c" | "i8" | "u16" | "i16" | "u32" | "i32" | "f32" | "f64";
18export declare type UintType = "u8" | "u8c" | "u16" | "u32";
19export declare type IntType = "i8" | "i16" | "i32";
20export declare type FloatType = "f32" | "f64";
21/**
22 * WebGL numeric type constants. Use {@link GL2TYPE} to convert, if needed.
23 *
24 * {@link Type}
25 * {@link GL2TYPE}
26 * {@link TYPE2GL}
27 */
28export declare enum GLType {
29 I8 = 5120,
30 U8 = 5121,
31 I16 = 5122,
32 U16 = 5123,
33 I32 = 5124,
34 U32 = 5125,
35 F32 = 5126
36}
37/**
38 * Conversion from {@link GLType} to {@link Type} enums.
39 */
40export declare const GL2TYPE: Record<GLType, Type>;
41/**
42 * Potentially lossy conversion from {@link Type} to {@link GLType} enums.
43 *
44 * Not all enums are mappable:
45 *
46 * - `F64` maps to `undefined`, since unsupported by WebGL
47 * - `U8C` maps to "u8"
48 */
49export declare const TYPE2GL: Record<Type, GLType | undefined>;
50/**
51 * Size information (in bytes) for {@link Type}. Also see {@link sizeOf}.
52 */
53export declare const SIZEOF: {
54 u8: number;
55 u8c: number;
56 i8: number;
57 u16: number;
58 i16: number;
59 u32: number;
60 i32: number;
61 f32: number;
62 f64: number;
63};
64export declare const FLOAT_ARRAY_CTORS: Record<FloatType, FloatArrayConstructor>;
65export declare const INT_ARRAY_CTORS: Record<IntType, IntArrayConstructor>;
66export declare const UINT_ARRAY_CTORS: Record<UintType, UIntArrayConstructor>;
67export declare const TYPEDARRAY_CTORS: Record<Type, TypedArrayConstructor>;
68export interface TypedArrayTypeMap extends Record<Type | GLType, TypedArray> {
69 u8: Uint8Array;
70 u8c: Uint8ClampedArray;
71 i8: Int8Array;
72 u16: Uint16Array;
73 i16: Int16Array;
74 u32: Uint32Array;
75 i32: Int32Array;
76 f32: Float32Array;
77 f64: Float64Array;
78 [GLType.U8]: Uint8Array;
79 [GLType.I8]: Int8Array;
80 [GLType.U16]: Uint16Array;
81 [GLType.I16]: Int16Array;
82 [GLType.U32]: Uint32Array;
83 [GLType.I32]: Int32Array;
84 [GLType.F32]: Float32Array;
85}
86/**
87 * Returns canonical {@link Type} value of `type` by first
88 * attempting to resolve it as {@link GLType} enum.
89 *
90 * @example
91 * ```ts
92 * asNativeType(GLType.F32) => "f32"
93 * asNativeType("f32") => "f32"
94 * ```
95 *
96 * @param type -
97 */
98export declare const asNativeType: (type: GLType | Type) => Type;
99/**
100 * Returns suitable {@link GLType} enum of `type`.
101 *
102 * @example
103 * ```ts
104 * asGLType("f32") => GLType.F32
105 * asGLType(GLType.F32) => GLType.F32
106 * ```
107 *
108 * @param type -
109 */
110export declare const asGLType: (type: GLType | Type) => GLType;
111/**
112 * Coerces given numeric args to integer values.
113 */
114export declare const asInt: (...args: number[]) => number[];
115/**
116 * Returns byte size for given {@link Type} ID or {@link GLType} enum.
117 *
118 * @param type -
119 */
120export declare const sizeOf: (type: GLType | Type) => number;
121/**
122 * Constructs new typed array of given {@link Type}/{@link GLType}. Supports all
123 * arities of standard typed array ctors.
124 *
125 * @param type - array type enum
126 */
127export declare function typedArray<T extends Type | GLType>(type: T, length: number): TypedArrayTypeMap[T];
128export declare function typedArray<T extends Type | GLType>(type: T, src: ArrayLike<number> | ArrayBufferLike): TypedArrayTypeMap[T];
129export declare function typedArray<T extends Type | GLType>(type: T, buf: ArrayBufferLike, byteOffset: number, length?: number): TypedArrayTypeMap[T];
130/**
131 * Takes an {@link NumericArray} and returns its corresponding {@link Type} ID.
132 * Standard JS arrays will default to {@link "f64"}.
133 *
134 * @param x -
135 */
136export declare const typedArrayType: (x: NumericArray) => Type;
137/**
138 * Returns the smallest possible *unsigned* int type enum for given `x`.
139 * E.g. if `x <= 256`, the function returns `"u8"`.
140 *
141 * @param x - value to classify
142 */
143export declare const uintTypeForSize: (x: number) => UintType;
144/**
145 * Returns the smallest possible *signed* int type enum for given `x`.
146 * E.g. if `x >= -128 && x < 128`, the function returns `"i8"`.
147 *
148 * @param x - value to classify
149 */
150export declare const intTypeForSize: (x: number) => IntType;
151/**
152 * Returns suitable {@link UintType} for given bit size (`[0,32]` range)
153 *
154 * @param x -
155 */
156export declare const uintTypeForBits: (x: number) => UintType;
157/**
158 * Returns suitable {@link IntType} for given bit size (`[0,32]` range)
159 *
160 * @param x -
161 */
162export declare const intTypeForBits: (x: number) => IntType;
163//# sourceMappingURL=typedarray.d.ts.map
\No newline at end of file