@luma.gl/core 9.2.5 → 9.3.0-alpha.10
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/dist/adapter/canvas-context.d.ts +6 -162
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +5 -419
- package/dist/adapter/canvas-context.js.map +1 -1
- package/dist/adapter/canvas-observer.d.ts +32 -0
- package/dist/adapter/canvas-observer.d.ts.map +1 -0
- package/dist/adapter/canvas-observer.js +90 -0
- package/dist/adapter/canvas-observer.js.map +1 -0
- package/dist/adapter/canvas-surface.d.ts +150 -0
- package/dist/adapter/canvas-surface.d.ts.map +1 -0
- package/dist/adapter/canvas-surface.js +392 -0
- package/dist/adapter/canvas-surface.js.map +1 -0
- package/dist/adapter/device.d.ts +81 -16
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +196 -10
- package/dist/adapter/device.js.map +1 -1
- package/dist/adapter/luma.js +1 -1
- package/dist/adapter/luma.js.map +1 -1
- package/dist/adapter/presentation-context.d.ts +11 -0
- package/dist/adapter/presentation-context.d.ts.map +1 -0
- package/dist/adapter/presentation-context.js +12 -0
- package/dist/adapter/presentation-context.js.map +1 -0
- package/dist/adapter/resources/buffer.d.ts +5 -5
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +18 -7
- package/dist/adapter/resources/buffer.js.map +1 -1
- package/dist/adapter/resources/command-buffer.d.ts +3 -1
- package/dist/adapter/resources/command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/command-buffer.js +3 -1
- package/dist/adapter/resources/command-buffer.js.map +1 -1
- package/dist/adapter/resources/command-encoder.d.ts +30 -7
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/command-encoder.js +68 -2
- package/dist/adapter/resources/command-encoder.js.map +1 -1
- package/dist/adapter/resources/compute-pipeline.d.ts +2 -2
- package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/fence.d.ts +16 -0
- package/dist/adapter/resources/fence.d.ts.map +1 -0
- package/dist/adapter/resources/fence.js +17 -0
- package/dist/adapter/resources/fence.js.map +1 -0
- package/dist/adapter/resources/framebuffer.d.ts +1 -1
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/framebuffer.js +15 -12
- package/dist/adapter/resources/framebuffer.js.map +1 -1
- package/dist/adapter/resources/query-set.d.ts +17 -1
- package/dist/adapter/resources/query-set.d.ts.map +1 -1
- package/dist/adapter/resources/query-set.js.map +1 -1
- package/dist/adapter/resources/render-pipeline.d.ts +28 -10
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/render-pipeline.js +21 -2
- package/dist/adapter/resources/render-pipeline.js.map +1 -1
- package/dist/adapter/resources/resource.d.ts +13 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -1
- package/dist/adapter/resources/resource.js +243 -14
- package/dist/adapter/resources/resource.js.map +1 -1
- package/dist/adapter/resources/shader.js +27 -25
- package/dist/adapter/resources/shader.js.map +1 -1
- package/dist/adapter/resources/shared-render-pipeline.d.ts +22 -0
- package/dist/adapter/resources/shared-render-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/shared-render-pipeline.js +25 -0
- package/dist/adapter/resources/shared-render-pipeline.js.map +1 -0
- package/dist/adapter/resources/texture-view.d.ts +1 -1
- package/dist/adapter/resources/texture-view.d.ts.map +1 -1
- package/dist/adapter/resources/texture.d.ts +168 -28
- package/dist/adapter/resources/texture.d.ts.map +1 -1
- package/dist/adapter/resources/texture.js +284 -25
- package/dist/adapter/resources/texture.js.map +1 -1
- package/dist/adapter/types/attachments.d.ts +1 -1
- package/dist/adapter/types/attachments.d.ts.map +1 -1
- package/dist/adapter/types/buffer-layout.d.ts +1 -1
- package/dist/adapter/types/buffer-layout.d.ts.map +1 -1
- package/dist/adapter/types/parameters.d.ts +3 -1
- package/dist/adapter/types/parameters.d.ts.map +1 -1
- package/dist/adapter/types/parameters.js +1 -0
- package/dist/adapter/types/parameters.js.map +1 -1
- package/dist/adapter/types/shader-layout.d.ts +10 -6
- package/dist/adapter/types/shader-layout.d.ts.map +1 -1
- package/dist/adapter/types/uniforms.d.ts +6 -0
- package/dist/adapter/types/uniforms.d.ts.map +1 -1
- package/dist/adapter-utils/bind-groups.d.ts +9 -0
- package/dist/adapter-utils/bind-groups.d.ts.map +1 -0
- package/dist/adapter-utils/bind-groups.js +41 -0
- package/dist/adapter-utils/bind-groups.js.map +1 -0
- package/dist/adapter-utils/format-compiler-log.d.ts.map +1 -1
- package/dist/adapter-utils/format-compiler-log.js +23 -15
- package/dist/adapter-utils/format-compiler-log.js.map +1 -1
- package/dist/adapter-utils/get-attribute-from-layouts.d.ts +2 -2
- package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -1
- package/dist/adapter-utils/get-attribute-from-layouts.js +6 -6
- package/dist/adapter-utils/get-attribute-from-layouts.js.map +1 -1
- package/dist/dist.dev.js +2692 -645
- package/dist/dist.min.js +10 -9
- package/dist/factories/bind-group-factory.d.ts +20 -0
- package/dist/factories/bind-group-factory.d.ts.map +1 -0
- package/dist/factories/bind-group-factory.js +79 -0
- package/dist/factories/bind-group-factory.js.map +1 -0
- package/dist/factories/core-module-state.d.ts +7 -0
- package/dist/factories/core-module-state.d.ts.map +1 -0
- package/dist/{shadertypes/data-types/shader-types.js → factories/core-module-state.js} +1 -1
- package/dist/factories/core-module-state.js.map +1 -0
- package/dist/factories/pipeline-factory.d.ts +54 -0
- package/dist/factories/pipeline-factory.d.ts.map +1 -0
- package/dist/factories/pipeline-factory.js +270 -0
- package/dist/factories/pipeline-factory.js.map +1 -0
- package/dist/factories/shader-factory.d.ts +20 -0
- package/dist/factories/shader-factory.d.ts.map +1 -0
- package/dist/factories/shader-factory.js +84 -0
- package/dist/factories/shader-factory.js.map +1 -0
- package/dist/index.cjs +2427 -554
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +30 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/portable/shader-block-writer.d.ts +51 -0
- package/dist/portable/shader-block-writer.d.ts.map +1 -0
- package/dist/portable/shader-block-writer.js +185 -0
- package/dist/portable/shader-block-writer.js.map +1 -0
- package/dist/portable/uniform-block.d.ts +1 -1
- package/dist/portable/uniform-block.d.ts.map +1 -1
- package/dist/portable/uniform-store.d.ts +55 -24
- package/dist/portable/uniform-store.d.ts.map +1 -1
- package/dist/portable/uniform-store.js +73 -25
- package/dist/portable/uniform-store.js.map +1 -1
- package/dist/shadertypes/data-types/data-type-decoder.d.ts +20 -0
- package/dist/shadertypes/data-types/data-type-decoder.d.ts.map +1 -0
- package/dist/shadertypes/data-types/data-type-decoder.js +79 -0
- package/dist/shadertypes/data-types/data-type-decoder.js.map +1 -0
- package/dist/shadertypes/data-types/data-types.d.ts +31 -12
- package/dist/shadertypes/data-types/data-types.d.ts.map +1 -1
- package/dist/shadertypes/data-types/decode-data-types.d.ts.map +1 -1
- package/dist/shadertypes/data-types/decode-data-types.js +2 -1
- package/dist/shadertypes/data-types/decode-data-types.js.map +1 -1
- package/dist/{image-utils → shadertypes/image-types}/image-types.d.ts +0 -6
- package/dist/shadertypes/image-types/image-types.d.ts.map +1 -0
- package/dist/shadertypes/image-types/image-types.js.map +1 -0
- package/dist/shadertypes/shader-types/shader-block-layout.d.ts +72 -0
- package/dist/shadertypes/shader-types/shader-block-layout.d.ts.map +1 -0
- package/dist/shadertypes/shader-types/shader-block-layout.js +209 -0
- package/dist/shadertypes/shader-types/shader-block-layout.js.map +1 -0
- package/dist/shadertypes/shader-types/shader-type-decoder.d.ts +41 -0
- package/dist/shadertypes/shader-types/shader-type-decoder.d.ts.map +1 -0
- package/dist/shadertypes/{data-types/decode-shader-types.js → shader-types/shader-type-decoder.js} +43 -4
- package/dist/shadertypes/shader-types/shader-type-decoder.js.map +1 -0
- package/dist/shadertypes/shader-types/shader-types.d.ts +101 -0
- package/dist/shadertypes/shader-types/shader-types.d.ts.map +1 -0
- package/dist/shadertypes/shader-types/shader-types.js +30 -0
- package/dist/shadertypes/shader-types/shader-types.js.map +1 -0
- package/dist/shadertypes/texture-types/pixel-utils.d.ts.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/pixel-utils.js +4 -4
- package/dist/shadertypes/texture-types/pixel-utils.js.map +1 -0
- package/dist/shadertypes/texture-types/texture-format-decoder.d.ts +36 -0
- package/dist/shadertypes/texture-types/texture-format-decoder.d.ts.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/texture-format-decoder.js +109 -37
- package/dist/shadertypes/texture-types/texture-format-decoder.js.map +1 -0
- package/dist/shadertypes/texture-types/texture-format-generics.d.ts +34 -0
- package/dist/shadertypes/texture-types/texture-format-generics.d.ts.map +1 -0
- package/dist/shadertypes/texture-types/texture-format-generics.js.map +1 -0
- package/dist/shadertypes/texture-types/texture-format-table.d.ts.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/texture-format-table.js +10 -9
- package/dist/shadertypes/texture-types/texture-format-table.js.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/texture-formats.d.ts +51 -17
- package/dist/shadertypes/texture-types/texture-formats.d.ts.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/texture-formats.js +1 -0
- package/dist/shadertypes/texture-types/texture-formats.js.map +1 -0
- package/dist/shadertypes/texture-types/texture-layout.d.ts +5 -0
- package/dist/shadertypes/texture-types/texture-layout.d.ts.map +1 -0
- package/dist/shadertypes/texture-types/texture-layout.js +41 -0
- package/dist/shadertypes/texture-types/texture-layout.js.map +1 -0
- package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts +24 -0
- package/dist/shadertypes/vertex-types/vertex-format-decoder.d.ts.map +1 -0
- package/dist/shadertypes/vertex-types/vertex-format-decoder.js +106 -0
- package/dist/shadertypes/vertex-types/vertex-format-decoder.js.map +1 -0
- package/dist/shadertypes/vertex-types/vertex-formats.d.ts +50 -0
- package/dist/shadertypes/vertex-types/vertex-formats.d.ts.map +1 -0
- package/dist/shadertypes/vertex-types/vertex-formats.js.map +1 -0
- package/dist/utils/array-equal.d.ts +1 -1
- package/dist/utils/array-equal.d.ts.map +1 -1
- package/dist/utils/array-equal.js +15 -9
- package/dist/utils/array-equal.js.map +1 -1
- package/dist/utils/assert.d.ts +5 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +17 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/stats-manager.d.ts.map +1 -1
- package/dist/utils/stats-manager.js +61 -1
- package/dist/utils/stats-manager.js.map +1 -1
- package/package.json +6 -6
- package/src/adapter/canvas-context.ts +7 -556
- package/src/adapter/canvas-observer.ts +130 -0
- package/src/adapter/canvas-surface.ts +521 -0
- package/src/adapter/device.ts +312 -24
- package/src/adapter/presentation-context.ts +16 -0
- package/src/adapter/resources/buffer.ts +19 -9
- package/src/adapter/resources/command-buffer.ts +4 -2
- package/src/adapter/resources/command-encoder.ts +101 -10
- package/src/adapter/resources/compute-pipeline.ts +2 -2
- package/src/adapter/resources/fence.ts +32 -0
- package/src/adapter/resources/framebuffer.ts +16 -13
- package/src/adapter/resources/query-set.ts +17 -1
- package/src/adapter/resources/render-pipeline.ts +52 -16
- package/src/adapter/resources/resource.ts +289 -14
- package/src/adapter/resources/shader.ts +28 -28
- package/src/adapter/resources/shared-render-pipeline.ts +40 -0
- package/src/adapter/resources/texture-view.ts +1 -1
- package/src/adapter/resources/texture.ts +427 -49
- package/src/adapter/types/attachments.ts +1 -1
- package/src/adapter/types/buffer-layout.ts +1 -1
- package/src/adapter/types/parameters.ts +4 -1
- package/src/adapter/types/shader-layout.ts +15 -9
- package/src/adapter/types/uniforms.ts +12 -0
- package/src/adapter-utils/bind-groups.ts +71 -0
- package/src/adapter-utils/format-compiler-log.ts +23 -15
- package/src/adapter-utils/get-attribute-from-layouts.ts +8 -11
- package/src/factories/bind-group-factory.ts +139 -0
- package/src/factories/core-module-state.ts +11 -0
- package/src/factories/pipeline-factory.ts +328 -0
- package/src/factories/shader-factory.ts +103 -0
- package/src/index.ts +70 -26
- package/src/portable/shader-block-writer.ts +254 -0
- package/src/portable/uniform-block.ts +1 -1
- package/src/portable/uniform-store.ts +98 -40
- package/src/shadertypes/data-types/data-type-decoder.ts +105 -0
- package/src/shadertypes/data-types/data-types.ts +100 -48
- package/src/shadertypes/data-types/decode-data-types.ts +2 -1
- package/src/{image-utils → shadertypes/image-types}/image-types.ts +0 -7
- package/src/shadertypes/shader-types/shader-block-layout.ts +340 -0
- package/src/shadertypes/{data-types/decode-shader-types.ts → shader-types/shader-type-decoder.ts} +88 -14
- package/src/shadertypes/shader-types/shader-types.ts +207 -0
- package/src/shadertypes/{textures → texture-types}/pixel-utils.ts +4 -4
- package/src/shadertypes/{textures → texture-types}/texture-format-decoder.ts +166 -45
- package/src/shadertypes/{textures → texture-types}/texture-format-generics.ts +42 -48
- package/src/shadertypes/{textures → texture-types}/texture-format-table.ts +10 -9
- package/src/shadertypes/{textures → texture-types}/texture-formats.ts +73 -17
- package/src/shadertypes/texture-types/texture-layout.ts +60 -0
- package/src/shadertypes/vertex-types/vertex-format-decoder.ts +131 -0
- package/src/shadertypes/vertex-types/vertex-formats.ts +183 -0
- package/src/utils/array-equal.ts +21 -9
- package/src/utils/assert.ts +18 -0
- package/src/utils/stats-manager.ts +76 -2
- package/dist/image-utils/image-types.d.ts.map +0 -1
- package/dist/image-utils/image-types.js.map +0 -1
- package/dist/portable/uniform-buffer-layout.d.ts +0 -28
- package/dist/portable/uniform-buffer-layout.d.ts.map +0 -1
- package/dist/portable/uniform-buffer-layout.js +0 -96
- package/dist/portable/uniform-buffer-layout.js.map +0 -1
- package/dist/shadertypes/data-types/decode-shader-types.d.ts +0 -17
- package/dist/shadertypes/data-types/decode-shader-types.d.ts.map +0 -1
- package/dist/shadertypes/data-types/decode-shader-types.js.map +0 -1
- package/dist/shadertypes/data-types/shader-types.d.ts +0 -45
- package/dist/shadertypes/data-types/shader-types.d.ts.map +0 -1
- package/dist/shadertypes/data-types/shader-types.js.map +0 -1
- package/dist/shadertypes/textures/pixel-utils.d.ts.map +0 -1
- package/dist/shadertypes/textures/pixel-utils.js.map +0 -1
- package/dist/shadertypes/textures/texture-format-decoder.d.ts +0 -18
- package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +0 -1
- package/dist/shadertypes/textures/texture-format-decoder.js.map +0 -1
- package/dist/shadertypes/textures/texture-format-generics.d.ts +0 -33
- package/dist/shadertypes/textures/texture-format-generics.d.ts.map +0 -1
- package/dist/shadertypes/textures/texture-format-generics.js.map +0 -1
- package/dist/shadertypes/textures/texture-format-table.d.ts.map +0 -1
- package/dist/shadertypes/textures/texture-format-table.js.map +0 -1
- package/dist/shadertypes/textures/texture-formats.d.ts.map +0 -1
- package/dist/shadertypes/textures/texture-formats.js.map +0 -1
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts +0 -18
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts.map +0 -1
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.js +0 -100
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.js.map +0 -1
- package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts +0 -27
- package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts.map +0 -1
- package/dist/shadertypes/vertex-arrays/vertex-formats.js.map +0 -1
- package/src/portable/uniform-buffer-layout.ts +0 -118
- package/src/shadertypes/data-types/shader-types.ts +0 -87
- package/src/shadertypes/vertex-arrays/decode-vertex-format.ts +0 -124
- package/src/shadertypes/vertex-arrays/vertex-formats.ts +0 -91
- /package/dist/{image-utils → shadertypes/image-types}/image-types.js +0 -0
- /package/dist/shadertypes/{textures → texture-types}/pixel-utils.d.ts +0 -0
- /package/dist/shadertypes/{textures → texture-types}/texture-format-generics.js +0 -0
- /package/dist/shadertypes/{textures → texture-types}/texture-format-table.d.ts +0 -0
- /package/dist/shadertypes/{vertex-arrays → vertex-types}/vertex-formats.js +0 -0
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type {
|
|
6
|
+
NormalizedDataType,
|
|
7
|
+
TypedArrayConstructorT,
|
|
8
|
+
NormalizedTypedArrayConstructorT
|
|
9
|
+
} from '../data-types/data-types';
|
|
6
10
|
|
|
7
11
|
/** Information about the structure of a texture format */
|
|
8
12
|
export type TextureFormatInfo = {
|
|
@@ -18,6 +22,8 @@ export type TextureFormatInfo = {
|
|
|
18
22
|
dataType?: NormalizedDataType;
|
|
19
23
|
/** Number of bytes per pixel */
|
|
20
24
|
bytesPerPixel: number;
|
|
25
|
+
/** Compressed formats only: Number of bytes per block */
|
|
26
|
+
bytesPerBlock?: number;
|
|
21
27
|
/** Number of bits per channel (may be unreliable for packed formats) */
|
|
22
28
|
bitsPerChannel: [number, number, number, number];
|
|
23
29
|
/** If this is a packed data type */
|
|
@@ -58,6 +64,33 @@ export type TextureFormatCapabilities = {
|
|
|
58
64
|
store: TextureFeature | boolean;
|
|
59
65
|
};
|
|
60
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Memory layout for reading/writing data to a texture's memory.
|
|
69
|
+
*
|
|
70
|
+
* @note Due to alignment, GPU texture data is typically not contiguous.
|
|
71
|
+
*
|
|
72
|
+
* @note GPU texure data must be accessed according to this layout.
|
|
73
|
+
* - On CPU, only the range of rows that are actually read or written need to be allocated.
|
|
74
|
+
* - However, space for the full, padded/aligned rows must be allocated in the buffer,
|
|
75
|
+
* even if just a partial horizontal range `{x, width}` is actually read or written.
|
|
76
|
+
*
|
|
77
|
+
* @note byteLength = bytesPerRow * rowsPerImage * depthOrArrayLayers.
|
|
78
|
+
*/
|
|
79
|
+
export type TextureMemoryLayout = {
|
|
80
|
+
/** Total length in bytes */
|
|
81
|
+
byteLength: number;
|
|
82
|
+
/** Number of images */
|
|
83
|
+
depthOrArrayLayers: number;
|
|
84
|
+
/** Stride between successive images (Use when depthOrArrayLayers > 1) */
|
|
85
|
+
bytesPerImage: number;
|
|
86
|
+
/** Number of rows per image */
|
|
87
|
+
rowsPerImage: number;
|
|
88
|
+
/** Number of bytes per row (padded) */
|
|
89
|
+
bytesPerRow: number;
|
|
90
|
+
/** Number of bytes per pixel */
|
|
91
|
+
bytesPerPixel: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
61
94
|
/**
|
|
62
95
|
* These represent the main compressed texture formats
|
|
63
96
|
* Each format typically has a number of more specific subformats
|
|
@@ -89,6 +122,7 @@ export type TextureFeature =
|
|
|
89
122
|
| 'float16-renderable-webgl'
|
|
90
123
|
| 'rgb9e5ufloat-renderable-webgl'
|
|
91
124
|
| 'snorm8-renderable-webgl'
|
|
125
|
+
| 'norm16-webgl'
|
|
92
126
|
| 'norm16-renderable-webgl'
|
|
93
127
|
| 'snorm16-renderable-webgl'
|
|
94
128
|
| 'float32-filterable'
|
|
@@ -133,7 +167,7 @@ export type TextureFormatColorUncompressed =
|
|
|
133
167
|
| TextureFormatPacked16
|
|
134
168
|
| TextureFormatPacked32;
|
|
135
169
|
|
|
136
|
-
type TextureFormatUnorm8 =
|
|
170
|
+
export type TextureFormatUnorm8 =
|
|
137
171
|
| 'r8unorm'
|
|
138
172
|
| 'rg8unorm'
|
|
139
173
|
| 'rgb8unorm-webgl'
|
|
@@ -142,39 +176,42 @@ type TextureFormatUnorm8 =
|
|
|
142
176
|
| 'bgra8unorm'
|
|
143
177
|
| 'bgra8unorm-srgb';
|
|
144
178
|
|
|
145
|
-
type TextureFormatSnorm8 = 'r8snorm' | 'rg8snorm' | 'rgb8snorm-webgl' | 'rgba8snorm';
|
|
179
|
+
export type TextureFormatSnorm8 = 'r8snorm' | 'rg8snorm' | 'rgb8snorm-webgl' | 'rgba8snorm';
|
|
146
180
|
|
|
147
|
-
type TextureFormatUint8 = 'r8uint' | 'rg8uint' | 'rgba8uint';
|
|
181
|
+
export type TextureFormatUint8 = 'r8uint' | 'rg8uint' | 'rgba8uint';
|
|
148
182
|
|
|
149
|
-
type TextureFormatSint8 = 'r8sint' | 'rg8sint' | 'rgba8sint';
|
|
183
|
+
export type TextureFormatSint8 = 'r8sint' | 'rg8sint' | 'rgba8sint';
|
|
150
184
|
|
|
151
|
-
type TextureFormatUnorm16 = 'r16unorm' | 'rg16unorm' | 'rgb16unorm-webgl' | 'rgba16unorm';
|
|
185
|
+
export type TextureFormatUnorm16 = 'r16unorm' | 'rg16unorm' | 'rgb16unorm-webgl' | 'rgba16unorm';
|
|
152
186
|
|
|
153
|
-
type TextureFormatSnorm16 = 'r16snorm' | 'rg16snorm' | 'rgb16snorm-webgl' | 'rgba16snorm';
|
|
187
|
+
export type TextureFormatSnorm16 = 'r16snorm' | 'rg16snorm' | 'rgb16snorm-webgl' | 'rgba16snorm';
|
|
154
188
|
|
|
155
|
-
type TextureFormatUint16 = 'r16uint' | 'rg16uint' | 'rgba16uint';
|
|
189
|
+
export type TextureFormatUint16 = 'r16uint' | 'rg16uint' | 'rgba16uint';
|
|
156
190
|
|
|
157
|
-
type TextureFormatSint16 = 'r16sint' | 'rg16sint' | 'rgba16sint';
|
|
191
|
+
export type TextureFormatSint16 = 'r16sint' | 'rg16sint' | 'rgba16sint';
|
|
158
192
|
|
|
159
|
-
type TextureFormatFloat16 = 'r16float' | 'rg16float' | 'rgba16float';
|
|
193
|
+
export type TextureFormatFloat16 = 'r16float' | 'rg16float' | 'rgba16float';
|
|
160
194
|
|
|
161
195
|
// 96-bit formats (deprecated!)
|
|
162
|
-
type TextureFormatUint32 = 'r32uint' | 'rg32uint' | 'rgba32uint';
|
|
196
|
+
export type TextureFormatUint32 = 'r32uint' | 'rg32uint' | 'rgba32uint';
|
|
163
197
|
|
|
164
|
-
type TextureFormatSint32 = 'r32sint' | 'rg32sint' | 'rgba32sint';
|
|
198
|
+
export type TextureFormatSint32 = 'r32sint' | 'rg32sint' | 'rgba32sint';
|
|
165
199
|
|
|
166
|
-
type TextureFormatFloat32 = 'r32float' | 'rg32float' | 'rgb32float-webgl' | 'rgba32float';
|
|
200
|
+
export type TextureFormatFloat32 = 'r32float' | 'rg32float' | 'rgb32float-webgl' | 'rgba32float';
|
|
167
201
|
|
|
168
|
-
type TextureFormatPacked16 = 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl';
|
|
169
|
-
|
|
170
|
-
type TextureFormatPacked32 = 'rgb9e5ufloat' | 'rg11b10ufloat' | 'rgb10a2unorm' | 'rgb10a2uint';
|
|
202
|
+
export type TextureFormatPacked16 = 'rgba4unorm-webgl' | 'rgb565unorm-webgl' | 'rgb5a1unorm-webgl';
|
|
171
203
|
|
|
204
|
+
export type TextureFormatPacked32 =
|
|
205
|
+
| 'rgb9e5ufloat'
|
|
206
|
+
| 'rg11b10ufloat'
|
|
207
|
+
| 'rgb10a2unorm'
|
|
208
|
+
| 'rgb10a2uint';
|
|
172
209
|
export type TextureFormatCompressed =
|
|
173
210
|
| 'bc1-rgb-unorm-webgl'
|
|
174
211
|
| 'bc1-rgb-unorm-srgb-webgl'
|
|
175
212
|
| 'pvrtc-rgb4unorm-webgl'
|
|
176
213
|
| 'pvrtc-rgba4unorm-webgl'
|
|
177
|
-
| 'pvrtc-
|
|
214
|
+
| 'pvrtc-rgb2unorm-webgl'
|
|
178
215
|
| 'pvrtc-rgba2unorm-webgl'
|
|
179
216
|
| 'etc1-rbg-unorm-webgl'
|
|
180
217
|
| 'atc-rgb-unorm-webgl'
|
|
@@ -243,8 +280,18 @@ export type TextureFormatCompressed =
|
|
|
243
280
|
| 'astc-12x12-unorm'
|
|
244
281
|
| 'astc-12x12-unorm-srgb';
|
|
245
282
|
|
|
283
|
+
export type CompressedTextureFormat = TextureFormatCompressed;
|
|
284
|
+
|
|
246
285
|
// Texture format helper types
|
|
247
286
|
|
|
287
|
+
export type TextureFormatTypedArray<T extends TextureFormat> = DataTypeArray<
|
|
288
|
+
TextureFormatDataType<T>
|
|
289
|
+
>;
|
|
290
|
+
|
|
291
|
+
export type TextureFormatNormalizedTypedArray<T extends TextureFormat> = NormalizedDataTypeArray<
|
|
292
|
+
TextureFormatDataType<T>
|
|
293
|
+
>;
|
|
294
|
+
|
|
248
295
|
export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFormatUint8
|
|
249
296
|
? 'uint8'
|
|
250
297
|
: T extends TextureFormatSint8
|
|
@@ -279,6 +326,15 @@ export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFo
|
|
|
279
326
|
? 'uint32'
|
|
280
327
|
: never;
|
|
281
328
|
|
|
329
|
+
export type TextureFormatDataTypeT<T extends TextureFormat> = TextureFormatDataType<T>;
|
|
330
|
+
|
|
331
|
+
type DataTypeArray<T extends NormalizedDataType> = InstanceType<TypedArrayConstructorT<T>>;
|
|
332
|
+
type NormalizedDataTypeArray<T extends NormalizedDataType> = InstanceType<
|
|
333
|
+
NormalizedTypedArrayConstructorT<T>
|
|
334
|
+
>;
|
|
335
|
+
|
|
336
|
+
// HELPER TYPES
|
|
337
|
+
|
|
282
338
|
/*
|
|
283
339
|
export type TextureFormatColorWebGPU =
|
|
284
340
|
// 8-bit formats
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {TypedArray} from '@math.gl/types';
|
|
6
|
+
import {type TextureFormat, type TextureMemoryLayout} from './texture-formats';
|
|
7
|
+
import {textureFormatDecoder} from './texture-format-decoder';
|
|
8
|
+
|
|
9
|
+
export function getTextureImageView<T extends TextureFormat>(
|
|
10
|
+
arrayBuffer: ArrayBuffer,
|
|
11
|
+
memoryLayout: TextureMemoryLayout,
|
|
12
|
+
format: T,
|
|
13
|
+
image = 0
|
|
14
|
+
) {
|
|
15
|
+
const formatInfo = textureFormatDecoder.getInfo(format);
|
|
16
|
+
const bytesPerComponent = formatInfo.bytesPerPixel / formatInfo.components;
|
|
17
|
+
const {bytesPerImage} = memoryLayout;
|
|
18
|
+
const offset = bytesPerImage * image;
|
|
19
|
+
const totalPixels = memoryLayout.bytesPerImage / bytesPerComponent;
|
|
20
|
+
|
|
21
|
+
switch (format) {
|
|
22
|
+
case 'rgba8unorm':
|
|
23
|
+
case 'bgra8unorm':
|
|
24
|
+
case 'rgba8uint':
|
|
25
|
+
return new Uint8Array(arrayBuffer, offset, totalPixels);
|
|
26
|
+
case 'r8unorm':
|
|
27
|
+
return new Uint8Array(arrayBuffer, offset, totalPixels);
|
|
28
|
+
case 'r16uint':
|
|
29
|
+
case 'rgba16uint':
|
|
30
|
+
return new Uint16Array(arrayBuffer, offset, totalPixels);
|
|
31
|
+
case 'r32uint':
|
|
32
|
+
case 'rgba32uint':
|
|
33
|
+
return new Uint32Array(arrayBuffer, offset, totalPixels);
|
|
34
|
+
case 'r32float':
|
|
35
|
+
return new Float32Array(arrayBuffer, offset, totalPixels);
|
|
36
|
+
case 'rgba16float':
|
|
37
|
+
return new Uint16Array(arrayBuffer, offset, totalPixels); // 4 channels
|
|
38
|
+
case 'rgba32float':
|
|
39
|
+
return new Float32Array(arrayBuffer, offset, totalPixels);
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`Unsupported format: ${format}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function setTextureImageData<T extends TextureFormat>(
|
|
46
|
+
arrayBuffer: ArrayBuffer,
|
|
47
|
+
memoryLayout: TextureMemoryLayout,
|
|
48
|
+
format: T,
|
|
49
|
+
data: TypedArray,
|
|
50
|
+
image = 0
|
|
51
|
+
): void {
|
|
52
|
+
const offset = 0; // memoryLayout.bytesPerImage * image;
|
|
53
|
+
|
|
54
|
+
const totalPixels = memoryLayout.bytesPerImage / memoryLayout.bytesPerPixel;
|
|
55
|
+
const subArray = data.subarray(0, totalPixels);
|
|
56
|
+
|
|
57
|
+
const typedArray = getTextureImageView(arrayBuffer, memoryLayout, format, image);
|
|
58
|
+
|
|
59
|
+
typedArray.set(subArray, offset);
|
|
60
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {TypedArray} from '../../types';
|
|
6
|
+
import type {NormalizedDataType, PrimitiveDataType, SignedDataType} from '../data-types/data-types';
|
|
7
|
+
import type {VertexFormat, VertexFormatInfo} from './vertex-formats';
|
|
8
|
+
import {dataTypeDecoder} from '../data-types/data-type-decoder';
|
|
9
|
+
|
|
10
|
+
export class VertexFormatDecoder {
|
|
11
|
+
/**
|
|
12
|
+
* Decodes a vertex format, returning type, components, byte length and flags (integer, signed, normalized)
|
|
13
|
+
*/
|
|
14
|
+
getVertexFormatInfo<T extends VertexFormat = VertexFormat>(format: T): VertexFormatInfo<T> {
|
|
15
|
+
// Strip the -webgl ending if present
|
|
16
|
+
let webglOnly: boolean | undefined;
|
|
17
|
+
if (format.endsWith('-webgl')) {
|
|
18
|
+
format.replace('-webgl', '');
|
|
19
|
+
webglOnly = true;
|
|
20
|
+
}
|
|
21
|
+
// split components from type
|
|
22
|
+
const [type_, count] = format.split('x');
|
|
23
|
+
const type = type_ as NormalizedDataType;
|
|
24
|
+
const components = (count ? parseInt(count) : 1) as 1 | 2 | 3 | 4;
|
|
25
|
+
// decode the type
|
|
26
|
+
const decodedType = dataTypeDecoder.getDataTypeInfo(type);
|
|
27
|
+
const result: VertexFormatInfo = {
|
|
28
|
+
type,
|
|
29
|
+
components,
|
|
30
|
+
byteLength: decodedType.byteLength * components,
|
|
31
|
+
integer: decodedType.integer,
|
|
32
|
+
signed: decodedType.signed,
|
|
33
|
+
normalized: decodedType.normalized
|
|
34
|
+
};
|
|
35
|
+
if (webglOnly) {
|
|
36
|
+
result.webglOnly = true;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Build a vertex format from a signed data type and a component */
|
|
42
|
+
makeVertexFormat(
|
|
43
|
+
signedDataType: SignedDataType,
|
|
44
|
+
components: 1 | 2 | 3 | 4,
|
|
45
|
+
normalized?: boolean
|
|
46
|
+
): VertexFormat {
|
|
47
|
+
const dataType: NormalizedDataType = normalized
|
|
48
|
+
? dataTypeDecoder.getNormalizedDataType(signedDataType)
|
|
49
|
+
: signedDataType;
|
|
50
|
+
|
|
51
|
+
switch (dataType) {
|
|
52
|
+
// TODO - Special cases for WebGL (not supported on WebGPU), overrides the check below
|
|
53
|
+
case 'unorm8':
|
|
54
|
+
if (components === 1) {
|
|
55
|
+
return 'unorm8';
|
|
56
|
+
}
|
|
57
|
+
if (components === 3) {
|
|
58
|
+
return 'unorm8x3-webgl';
|
|
59
|
+
}
|
|
60
|
+
return `${dataType}x${components}`;
|
|
61
|
+
|
|
62
|
+
case 'snorm8':
|
|
63
|
+
case 'uint8':
|
|
64
|
+
case 'sint8':
|
|
65
|
+
// WebGPU 8 bit formats must be aligned to 16 bit boundaries');
|
|
66
|
+
// fall through
|
|
67
|
+
case 'uint16':
|
|
68
|
+
case 'sint16':
|
|
69
|
+
case 'unorm16':
|
|
70
|
+
case 'snorm16':
|
|
71
|
+
case 'float16':
|
|
72
|
+
// WebGPU 16 bit formats must be aligned to 32 bit boundaries
|
|
73
|
+
if (components === 1 || components === 3) {
|
|
74
|
+
throw new Error(`size: ${components}`);
|
|
75
|
+
}
|
|
76
|
+
return `${dataType}x${components}`;
|
|
77
|
+
|
|
78
|
+
default:
|
|
79
|
+
return components === 1 ? dataType : `${dataType}x${components}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Get the vertex format for an attribute with TypedArray and size */
|
|
84
|
+
getVertexFormatFromAttribute(
|
|
85
|
+
typedArray: TypedArray,
|
|
86
|
+
size: number,
|
|
87
|
+
normalized?: boolean
|
|
88
|
+
): VertexFormat {
|
|
89
|
+
if (!size || size > 4) {
|
|
90
|
+
throw new Error(`size ${size}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const components = size as 1 | 2 | 3 | 4;
|
|
94
|
+
const signedDataType = dataTypeDecoder.getDataType(typedArray);
|
|
95
|
+
return this.makeVertexFormat(signedDataType, components, normalized);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Return a "default" vertex format for a certain shader data type
|
|
100
|
+
* The simplest vertex format that matches the shader attribute's data type
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
getCompatibleVertexFormat(opts: {
|
|
104
|
+
primitiveType: PrimitiveDataType;
|
|
105
|
+
components: 1 | 2 | 3 | 4;
|
|
106
|
+
}): VertexFormat {
|
|
107
|
+
let vertexType: NormalizedDataType;
|
|
108
|
+
switch (opts.primitiveType) {
|
|
109
|
+
case 'f32':
|
|
110
|
+
vertexType = 'float32';
|
|
111
|
+
break;
|
|
112
|
+
case 'i32':
|
|
113
|
+
vertexType = 'sint32';
|
|
114
|
+
break;
|
|
115
|
+
case 'u32':
|
|
116
|
+
vertexType = 'uint32';
|
|
117
|
+
break;
|
|
118
|
+
case 'f16':
|
|
119
|
+
return opts.components <= 2 ? 'float16x2' : 'float16x4';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// TODO logic does not work for float16
|
|
123
|
+
if (opts.components === 1) {
|
|
124
|
+
return vertexType;
|
|
125
|
+
}
|
|
126
|
+
return `${vertexType}x${opts.components}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Decoder for luma.gl vertex types */
|
|
131
|
+
export const vertexFormatDecoder = new VertexFormatDecoder();
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DataTypeIsIntegerT,
|
|
7
|
+
DataTypeIsNormalizedT,
|
|
8
|
+
DataTypeIsSignedT
|
|
9
|
+
} from '../data-types/data-types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Describes the **memory format** and interpretation (normalization) of a buffer that will be supplied to vertex attributes
|
|
13
|
+
* @note Must be compatible with the AttributeShaderType of the shaders, see documentation.
|
|
14
|
+
* @note This is a superset of WebGPU vertex formats to allow for some flexibility for WebGL only applications
|
|
15
|
+
* @todo Add device.isVertexFormatSupported() method?
|
|
16
|
+
*/
|
|
17
|
+
export type VertexFormat =
|
|
18
|
+
// 8 bit integers, note that only 16 bit aligned formats are supported in WebGPU (x2 and x4)
|
|
19
|
+
| 'uint8' // Chrome 133+
|
|
20
|
+
| 'uint8x2'
|
|
21
|
+
| 'uint8x4'
|
|
22
|
+
| 'sint8' // Chrome 133+
|
|
23
|
+
| 'sint8x2'
|
|
24
|
+
| 'sint8x4'
|
|
25
|
+
| 'unorm8' // Chrome 133+
|
|
26
|
+
| 'unorm8x2'
|
|
27
|
+
| 'unorm8x3-webgl' // Not in WebGPU
|
|
28
|
+
| 'unorm8x4'
|
|
29
|
+
| 'unorm8x4-bgra' // Chrome 133+
|
|
30
|
+
| 'unorm10-10-10-2' // Chrome 119+
|
|
31
|
+
// | 'snorm-10-10-10-2' // Not in WebGPU, DXD12 doesn't support
|
|
32
|
+
| 'snorm8' // Chrome 133+
|
|
33
|
+
| 'snorm8x2'
|
|
34
|
+
| 'snorm8x3-webgl'
|
|
35
|
+
| 'snorm8x4'
|
|
36
|
+
// 16 bit integers, that only 32 bit aligned formats are supported in WebGPU (x2 and x4)
|
|
37
|
+
| 'uint16' // Chrome 133+
|
|
38
|
+
| 'sint16' // Chrome 133+
|
|
39
|
+
| 'unorm16' // Chrome 133+
|
|
40
|
+
| 'snorm16' // Chrome 133+
|
|
41
|
+
| 'uint16x2'
|
|
42
|
+
| 'uint16x4'
|
|
43
|
+
| 'sint16x2'
|
|
44
|
+
| 'sint16x4'
|
|
45
|
+
| 'unorm16x2'
|
|
46
|
+
| 'unorm16x4'
|
|
47
|
+
| 'snorm16x2'
|
|
48
|
+
| 'snorm16x4'
|
|
49
|
+
// 32 bit integers
|
|
50
|
+
| 'uint32'
|
|
51
|
+
| 'uint32x2'
|
|
52
|
+
| 'uint32x3'
|
|
53
|
+
| 'uint32x4'
|
|
54
|
+
| 'sint32'
|
|
55
|
+
| 'sint32x2'
|
|
56
|
+
| 'sint32x3'
|
|
57
|
+
| 'sint32x4'
|
|
58
|
+
// No normalized 32 bit integers in WebGPU...
|
|
59
|
+
// | 'unorm32'
|
|
60
|
+
// | 'unorm32x2'
|
|
61
|
+
// | 'unorm32x3'
|
|
62
|
+
// | 'unorm32x4'
|
|
63
|
+
// | 'snorm32'
|
|
64
|
+
// | 'snorm32x2'
|
|
65
|
+
// | 'snorm32x3'
|
|
66
|
+
// | 'snorm32x4'
|
|
67
|
+
// floats
|
|
68
|
+
| 'float16' // Chrome 133+
|
|
69
|
+
| 'float16x2'
|
|
70
|
+
| 'float16x4'
|
|
71
|
+
| 'float32'
|
|
72
|
+
| 'float32x2'
|
|
73
|
+
| 'float32x3'
|
|
74
|
+
| 'float32x4';
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @type Information about a vertex format
|
|
78
|
+
*/
|
|
79
|
+
export type VertexFormatInfo<T extends VertexFormat = VertexFormat> = {
|
|
80
|
+
/** Type of each component */
|
|
81
|
+
type: VertexFormatDataTypeT<T>;
|
|
82
|
+
/** Number of components per vertex / row */
|
|
83
|
+
components: VertexFormatComponentsT<T>;
|
|
84
|
+
/** Is this an integer format (normalized integer formats are not integer) */
|
|
85
|
+
integer: DataTypeIsIntegerT<VertexFormatDataTypeT<T>>;
|
|
86
|
+
/** Is this a signed format? */
|
|
87
|
+
signed: DataTypeIsSignedT<VertexFormatDataTypeT<T>>;
|
|
88
|
+
/** Is this a normalized format? */
|
|
89
|
+
normalized: DataTypeIsNormalizedT<VertexFormatDataTypeT<T>>;
|
|
90
|
+
/** Length in bytes */
|
|
91
|
+
byteLength: number;
|
|
92
|
+
/** Is this a bgra format? */
|
|
93
|
+
bgra?: boolean;
|
|
94
|
+
/** Is this a webgl only format? */
|
|
95
|
+
webglOnly?: boolean;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** @type the NormalizedDataType of the components in a VertexFormat */
|
|
99
|
+
export type VertexFormatDataTypeT<T extends VertexFormat> = T extends VertexFormatUint8
|
|
100
|
+
? 'uint8'
|
|
101
|
+
: T extends VertexFormatSint8
|
|
102
|
+
? 'sint8'
|
|
103
|
+
: T extends VertexFormatUnorm8
|
|
104
|
+
? 'unorm8'
|
|
105
|
+
: T extends VertexFormatSnorm8
|
|
106
|
+
? 'snorm8'
|
|
107
|
+
: T extends VertexFormatUint16
|
|
108
|
+
? 'uint16'
|
|
109
|
+
: T extends VertexFormatSint16
|
|
110
|
+
? 'sint16'
|
|
111
|
+
: T extends VertexFormatUnorm16
|
|
112
|
+
? 'unorm16'
|
|
113
|
+
: T extends VertexFormatSnorm16
|
|
114
|
+
? 'snorm16'
|
|
115
|
+
: T extends VertexFormatUint32
|
|
116
|
+
? 'uint32'
|
|
117
|
+
: T extends VertexFormatSint32
|
|
118
|
+
? 'sint32'
|
|
119
|
+
: T extends VertexFormatFloat16
|
|
120
|
+
? 'float16'
|
|
121
|
+
: T extends VertexFormatFloat32
|
|
122
|
+
? 'float32'
|
|
123
|
+
: never;
|
|
124
|
+
|
|
125
|
+
/** @type number - the number of components in a VertexFormat */
|
|
126
|
+
export type VertexFormatComponentsT<T extends VertexFormat> = T extends VertexFormat2Components
|
|
127
|
+
? 2
|
|
128
|
+
: T extends VertexFormat3Components
|
|
129
|
+
? 3
|
|
130
|
+
: T extends VertexFormat4Components
|
|
131
|
+
? 4
|
|
132
|
+
: 1;
|
|
133
|
+
|
|
134
|
+
// Helper types for the above
|
|
135
|
+
|
|
136
|
+
type VertexFormatUint8 = 'uint8' | 'uint8x2' | 'uint8x4';
|
|
137
|
+
type VertexFormatSint8 = 'sint8' | 'sint8x2' | 'sint8x4';
|
|
138
|
+
type VertexFormatUnorm8 =
|
|
139
|
+
| 'unorm8'
|
|
140
|
+
| 'unorm8x2'
|
|
141
|
+
| 'unorm8x3-webgl'
|
|
142
|
+
| 'unorm8x4'
|
|
143
|
+
| 'unorm8x4-bgra'
|
|
144
|
+
| 'unorm10-10-10-2';
|
|
145
|
+
type VertexFormatSnorm8 = 'snorm8' | 'snorm8x2' | 'snorm8x3-webgl' | 'snorm8x4';
|
|
146
|
+
type VertexFormatUint16 = 'uint16' | 'uint16x2' | 'uint16x4';
|
|
147
|
+
type VertexFormatSint16 = 'sint16' | 'sint16x2' | 'sint16x4';
|
|
148
|
+
type VertexFormatUnorm16 = 'unorm16' | 'unorm16x2' | 'unorm16x4';
|
|
149
|
+
type VertexFormatSnorm16 = 'snorm16' | 'snorm16x2' | 'snorm16x4';
|
|
150
|
+
type VertexFormatUint32 = 'uint32' | 'uint32x2' | 'uint32x3' | 'uint32x4';
|
|
151
|
+
type VertexFormatSint32 = 'sint32' | 'sint32x2' | 'sint32x3' | 'sint32x4';
|
|
152
|
+
type VertexFormatFloat16 = 'float16' | 'float16x2' | 'float16x4';
|
|
153
|
+
type VertexFormatFloat32 = 'float32' | 'float32x2' | 'float32x3' | 'float32x4';
|
|
154
|
+
|
|
155
|
+
type VertexFormat2Components =
|
|
156
|
+
| 'uint8x2'
|
|
157
|
+
| 'sint8x2'
|
|
158
|
+
| 'unorm8x2'
|
|
159
|
+
| 'snorm8x2'
|
|
160
|
+
| 'uint16x2'
|
|
161
|
+
| 'sint16x2'
|
|
162
|
+
| 'unorm16x2'
|
|
163
|
+
| 'snorm16x2'
|
|
164
|
+
| 'uint32x2'
|
|
165
|
+
| 'sint32x2'
|
|
166
|
+
| 'float16x2'
|
|
167
|
+
| 'float32x2';
|
|
168
|
+
type VertexFormat3Components = 'unorm8x3-webgl' | 'uint32x3' | 'sint32x3' | 'float32x3';
|
|
169
|
+
type VertexFormat4Components =
|
|
170
|
+
| 'uint8x4'
|
|
171
|
+
| 'sint8x4'
|
|
172
|
+
| 'unorm8x4'
|
|
173
|
+
| 'unorm8x4-bgra'
|
|
174
|
+
| 'unorm10-10-10-2'
|
|
175
|
+
| 'snorm8x4'
|
|
176
|
+
| 'uint16x4'
|
|
177
|
+
| 'sint16x4'
|
|
178
|
+
| 'unorm16x4'
|
|
179
|
+
| 'snorm16x4'
|
|
180
|
+
| 'uint32x4'
|
|
181
|
+
| 'sint32x4'
|
|
182
|
+
| 'float16x4'
|
|
183
|
+
| 'float32x4';
|
package/src/utils/array-equal.ts
CHANGED
|
@@ -4,23 +4,35 @@
|
|
|
4
4
|
|
|
5
5
|
import {isNumberArray} from './is-array';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const MAX_ELEMENTWISE_ARRAY_COMPARE_LENGTH = 128;
|
|
8
|
+
|
|
9
|
+
/** Test if two arrays are deep equal, with a small-array length limit that defaults to 16 */
|
|
8
10
|
export function arrayEqual(a: unknown, b: unknown, limit: number = 16) {
|
|
9
|
-
if (a
|
|
10
|
-
return
|
|
11
|
+
if (a === b) {
|
|
12
|
+
return true;
|
|
11
13
|
}
|
|
14
|
+
|
|
12
15
|
const arrayA = a;
|
|
13
16
|
const arrayB = b;
|
|
14
|
-
if (!isNumberArray(arrayA)) {
|
|
17
|
+
if (!isNumberArray(arrayA) || !isNumberArray(arrayB)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (arrayA.length !== arrayB.length) {
|
|
15
22
|
return false;
|
|
16
23
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
|
|
25
|
+
const maxCompareLength = Math.min(limit, MAX_ELEMENTWISE_ARRAY_COMPARE_LENGTH);
|
|
26
|
+
if (arrayA.length > maxCompareLength) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < arrayA.length; ++i) {
|
|
31
|
+
if (arrayB[i] !== arrayA[i]) {
|
|
32
|
+
return false;
|
|
22
33
|
}
|
|
23
34
|
}
|
|
35
|
+
|
|
24
36
|
return true;
|
|
25
37
|
}
|
|
26
38
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Throws if condition is true and narrows type */
|
|
6
|
+
export function assert(condition: unknown, message?: string): asserts condition {
|
|
7
|
+
if (!condition) {
|
|
8
|
+
const error = new Error(message ?? 'luma.gl assertion failed.');
|
|
9
|
+
Error.captureStackTrace?.(error, assert);
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Throws if value is not defined, narrows type */
|
|
15
|
+
export function assertDefined<T>(value: T | undefined, message?: string): T {
|
|
16
|
+
assert(value, message);
|
|
17
|
+
return value;
|
|
18
|
+
}
|