UNPKG

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