@luma.gl/core 9.3.0-alpha.4 → 9.3.0-alpha.8
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 -182
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +5 -481
- 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 +76 -11
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +180 -9
- package/dist/adapter/device.js.map +1 -1
- package/dist/adapter/luma.js +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 +1 -1
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +14 -6
- 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 +25 -2
- 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 +1 -1
- package/dist/adapter/resources/fence.d.ts.map +1 -1
- package/dist/adapter/resources/fence.js +3 -1
- package/dist/adapter/resources/fence.js.map +1 -1
- package/dist/adapter/resources/framebuffer.d.ts +1 -1
- package/dist/adapter/resources/framebuffer.d.ts.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 +8 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -1
- package/dist/adapter/resources/resource.js +240 -14
- package/dist/adapter/resources/resource.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 +82 -15
- package/dist/adapter/resources/texture.d.ts.map +1 -1
- package/dist/adapter/resources/texture.js +186 -33
- 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/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 +1934 -415
- package/dist/dist.min.js +6 -6
- 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 +1858 -409
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +25 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -9
- package/dist/index.js.map +1 -1
- package/dist/portable/uniform-block.d.ts +1 -1
- package/dist/portable/uniform-block.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.d.ts +20 -15
- package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.js +188 -43
- package/dist/portable/uniform-buffer-layout.js.map +1 -1
- package/dist/portable/uniform-store.d.ts +5 -6
- package/dist/portable/uniform-store.d.ts.map +1 -1
- package/dist/portable/uniform-store.js +6 -3
- 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/{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-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/texture-types/pixel-utils.js.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/texture-format-decoder.d.ts +1 -0
- package/dist/shadertypes/texture-types/texture-format-decoder.d.ts.map +1 -0
- package/dist/shadertypes/{textures → texture-types}/texture-format-decoder.js +55 -9
- 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 +10 -3
- 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/{textures → texture-types}/texture-layout.d.ts +1 -1
- package/dist/shadertypes/texture-types/texture-layout.d.ts.map +1 -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/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 +3 -3
- package/src/adapter/canvas-context.ts +7 -623
- package/src/adapter/canvas-observer.ts +130 -0
- package/src/adapter/canvas-surface.ts +521 -0
- package/src/adapter/device.ts +287 -21
- package/src/adapter/presentation-context.ts +16 -0
- package/src/adapter/resources/buffer.ts +13 -5
- package/src/adapter/resources/command-buffer.ts +3 -1
- package/src/adapter/resources/command-encoder.ts +94 -3
- package/src/adapter/resources/compute-pipeline.ts +2 -2
- package/src/adapter/resources/fence.ts +3 -1
- package/src/adapter/resources/framebuffer.ts +1 -1
- package/src/adapter/resources/query-set.ts +17 -1
- package/src/adapter/resources/render-pipeline.ts +52 -16
- package/src/adapter/resources/resource.ts +284 -14
- 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 +273 -43
- 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/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 +54 -26
- package/src/portable/uniform-block.ts +1 -1
- package/src/portable/uniform-buffer-layout.ts +269 -62
- package/src/portable/uniform-store.ts +14 -11
- package/src/shadertypes/data-types/data-type-decoder.ts +105 -0
- package/src/shadertypes/data-types/data-types.ts +100 -48
- package/src/{image-utils → shadertypes/image-types}/image-types.ts +0 -7
- 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}/texture-format-decoder.ts +75 -9
- 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 +20 -3
- 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/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/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 -43
- 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.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/textures/texture-layout.d.ts.map +0 -1
- package/dist/shadertypes/textures/texture-layout.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/shadertypes/data-types/shader-types.ts +0 -94
- 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}/pixel-utils.js +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/{textures → texture-types}/texture-layout.js +0 -0
- /package/dist/shadertypes/{vertex-arrays → vertex-types}/vertex-formats.js +0 -0
- /package/src/shadertypes/{textures → texture-types}/pixel-utils.ts +0 -0
- /package/src/shadertypes/{textures → texture-types}/texture-layout.ts +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {NormalizedDataType} from '../data-types/data-types';
|
|
6
|
-
import {
|
|
6
|
+
import {dataTypeDecoder} from '../data-types/data-type-decoder';
|
|
7
7
|
import type {
|
|
8
8
|
TextureFormat,
|
|
9
9
|
TextureFormatCompressed,
|
|
@@ -72,6 +72,7 @@ export class TextureFormatDecoder {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/** Decoder for luma.gl texture types */
|
|
75
76
|
export const textureFormatDecoder = new TextureFormatDecoder();
|
|
76
77
|
|
|
77
78
|
// HELPERS - MEMORY LAYOUT
|
|
@@ -84,11 +85,20 @@ function computeTextureMemoryLayout({
|
|
|
84
85
|
depth,
|
|
85
86
|
byteAlignment
|
|
86
87
|
}: TextureMemoryLayoutOptions): TextureMemoryLayout {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const formatInfo = textureFormatDecoder.getInfo(format);
|
|
89
|
+
const {
|
|
90
|
+
bytesPerPixel,
|
|
91
|
+
bytesPerBlock = bytesPerPixel,
|
|
92
|
+
blockWidth = 1,
|
|
93
|
+
blockHeight = 1,
|
|
94
|
+
compressed = false
|
|
95
|
+
} = formatInfo;
|
|
96
|
+
const blockColumns = compressed ? Math.ceil(width / blockWidth) : width;
|
|
97
|
+
const blockRows = compressed ? Math.ceil(height / blockHeight) : height;
|
|
98
|
+
// byteAlignment comes from the backend/call site. WebGPU buffer copies use 256, queue.writeTexture uses 1.
|
|
99
|
+
const unpaddedBytesPerRow = blockColumns * bytesPerBlock;
|
|
90
100
|
const bytesPerRow = Math.ceil(unpaddedBytesPerRow / byteAlignment) * byteAlignment;
|
|
91
|
-
const rowsPerImage =
|
|
101
|
+
const rowsPerImage = blockRows;
|
|
92
102
|
const byteLength = bytesPerRow * rowsPerImage * depth;
|
|
93
103
|
|
|
94
104
|
return {
|
|
@@ -120,9 +130,10 @@ function getTextureFormatCapabilities(format: TextureFormat): TextureFormatCapab
|
|
|
120
130
|
const isSigned = formatInfo?.signed;
|
|
121
131
|
const isInteger = formatInfo?.integer;
|
|
122
132
|
const isWebGLSpecific = formatInfo?.webgl;
|
|
133
|
+
const isCompressed = Boolean(formatInfo?.compressed);
|
|
123
134
|
|
|
124
|
-
//
|
|
125
|
-
formatCapabilities.render &&= !
|
|
135
|
+
// Only uncompressed color formats can be used as color-renderable attachments.
|
|
136
|
+
formatCapabilities.render &&= !isDepthStencil && !isCompressed;
|
|
126
137
|
// signed and integer formats are not filterable
|
|
127
138
|
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
128
139
|
|
|
@@ -143,6 +154,7 @@ export function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
|
|
|
143
154
|
formatInfo.bytesPerPixel = 1;
|
|
144
155
|
formatInfo.srgb = false;
|
|
145
156
|
formatInfo.compressed = true;
|
|
157
|
+
formatInfo.bytesPerBlock = getCompressedTextureBlockByteLength(format);
|
|
146
158
|
|
|
147
159
|
const blockSize = getCompressedTextureBlockSize(format);
|
|
148
160
|
if (blockSize) {
|
|
@@ -152,11 +164,11 @@ export function getTextureFormatInfo(format: TextureFormat): TextureFormatInfo {
|
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
// Fill in missing information that can be derived from the format string
|
|
155
|
-
const matches = RGB_FORMAT_REGEX.exec(format as string);
|
|
167
|
+
const matches = !formatInfo.packed ? RGB_FORMAT_REGEX.exec(format as string) : null;
|
|
156
168
|
if (matches) {
|
|
157
169
|
const [, channels, length, type, srgb, suffix] = matches;
|
|
158
170
|
const dataType = `${type}${length}` as NormalizedDataType;
|
|
159
|
-
const decodedType = getDataTypeInfo(dataType);
|
|
171
|
+
const decodedType = dataTypeDecoder.getDataTypeInfo(dataType);
|
|
160
172
|
const bits = decodedType.byteLength * 8;
|
|
161
173
|
const components = (channels?.length ?? 1) as 1 | 2 | 3 | 4;
|
|
162
174
|
const bitsPerChannel: [number, number, number, number] = [
|
|
@@ -245,9 +257,63 @@ function getCompressedTextureBlockSize(
|
|
|
245
257
|
const [, blockWidth, blockHeight] = matches;
|
|
246
258
|
return {blockWidth: Number(blockWidth), blockHeight: Number(blockHeight)};
|
|
247
259
|
}
|
|
260
|
+
|
|
261
|
+
if (
|
|
262
|
+
format.startsWith('bc') ||
|
|
263
|
+
format.startsWith('etc1') ||
|
|
264
|
+
format.startsWith('etc2') ||
|
|
265
|
+
format.startsWith('eac') ||
|
|
266
|
+
format.startsWith('atc')
|
|
267
|
+
) {
|
|
268
|
+
return {blockWidth: 4, blockHeight: 4};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (format.startsWith('pvrtc-rgb4') || format.startsWith('pvrtc-rgba4')) {
|
|
272
|
+
return {blockWidth: 4, blockHeight: 4};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (format.startsWith('pvrtc-rgb2') || format.startsWith('pvrtc-rgba2')) {
|
|
276
|
+
return {blockWidth: 8, blockHeight: 4};
|
|
277
|
+
}
|
|
278
|
+
|
|
248
279
|
return null;
|
|
249
280
|
}
|
|
250
281
|
|
|
282
|
+
function getCompressedTextureBlockByteLength(format: TextureFormatCompressed): number {
|
|
283
|
+
if (
|
|
284
|
+
format.startsWith('bc1') ||
|
|
285
|
+
format.startsWith('bc4') ||
|
|
286
|
+
format.startsWith('etc1') ||
|
|
287
|
+
format.startsWith('etc2-rgb8') ||
|
|
288
|
+
format.startsWith('etc2-rgb8a1') ||
|
|
289
|
+
format.startsWith('eac-r11') ||
|
|
290
|
+
format === 'atc-rgb-unorm-webgl'
|
|
291
|
+
) {
|
|
292
|
+
return 8;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (
|
|
296
|
+
format.startsWith('bc2') ||
|
|
297
|
+
format.startsWith('bc3') ||
|
|
298
|
+
format.startsWith('bc5') ||
|
|
299
|
+
format.startsWith('bc6h') ||
|
|
300
|
+
format.startsWith('bc7') ||
|
|
301
|
+
format.startsWith('etc2-rgba8') ||
|
|
302
|
+
format.startsWith('eac-rg11') ||
|
|
303
|
+
format.startsWith('astc') ||
|
|
304
|
+
format === 'atc-rgba-unorm-webgl' ||
|
|
305
|
+
format === 'atc-rgbai-unorm-webgl'
|
|
306
|
+
) {
|
|
307
|
+
return 16;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (format.startsWith('pvrtc')) {
|
|
311
|
+
return 8;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return 16;
|
|
315
|
+
}
|
|
316
|
+
|
|
251
317
|
/*
|
|
252
318
|
'r8unorm': {s: "float"}, // ✓ ✓ ✓ },
|
|
253
319
|
'r8snorm': {s: "float"}, // ✓ },
|
|
@@ -8,54 +8,8 @@ import {
|
|
|
8
8
|
type TextureFormatCompressed
|
|
9
9
|
} from './texture-formats';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type TextureFormatTypedArray<T extends TextureFormat> = DataTypeArray<
|
|
14
|
-
TextureFormatDataType<T>
|
|
15
|
-
>;
|
|
16
|
-
|
|
17
|
-
export type TextureFormatNormalizedTypedArray<T extends TextureFormat> = NormalizedDataTypeArray<
|
|
18
|
-
TextureFormatDataType<T>
|
|
19
|
-
>;
|
|
20
|
-
|
|
21
|
-
/** A numeric array of length matching the number of components in the texture format */
|
|
22
|
-
export type TextureFormatPixel<T extends TextureFormat> =
|
|
23
|
-
TextureFormatPackedComponents<T> extends 1
|
|
24
|
-
? [number]
|
|
25
|
-
: TextureFormatPackedComponents<T> extends 2
|
|
26
|
-
? [number, number]
|
|
27
|
-
: TextureFormatPackedComponents<T> extends 3
|
|
28
|
-
? [number, number, number]
|
|
29
|
-
: TextureFormatPackedComponents<T> extends 4
|
|
30
|
-
? [number, number, number, number]
|
|
31
|
-
: never;
|
|
32
|
-
|
|
33
|
-
/** @note packed formats have only one component. Use TextureFormatPackedComponents */
|
|
34
|
-
export type TextureFormatComponents<T extends TextureFormat> = T extends
|
|
35
|
-
| TextureFormatR
|
|
36
|
-
| TextureFormatPackedRGB
|
|
37
|
-
| TextureFormatPackedRGBA
|
|
38
|
-
? 1
|
|
39
|
-
: T extends TextureFormatRG
|
|
40
|
-
? 2
|
|
41
|
-
: T extends TextureFormatRGB
|
|
42
|
-
? 3
|
|
43
|
-
: T extends TextureFormatRGBA
|
|
44
|
-
? 4
|
|
45
|
-
: never;
|
|
46
|
-
|
|
47
|
-
export type TextureFormatPackedComponents<T extends TextureFormat> = T extends TextureFormatR
|
|
48
|
-
? 1
|
|
49
|
-
: T extends TextureFormatRG
|
|
50
|
-
? 2
|
|
51
|
-
: T extends TextureFormatRGB | TextureFormatPackedRGB
|
|
52
|
-
? 3
|
|
53
|
-
: T extends TextureFormatRGBA | TextureFormatPackedRGBA
|
|
54
|
-
? 4
|
|
55
|
-
: never;
|
|
56
|
-
|
|
57
|
-
/** Get the data type for a texture format */
|
|
58
|
-
export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFormatUint8
|
|
11
|
+
/** @type data type for a texture format */
|
|
12
|
+
export type TextureFormatDataTypeT<T extends TextureFormat> = T extends TextureFormatUint8
|
|
59
13
|
? 'uint8'
|
|
60
14
|
: T extends TextureFormatSint8
|
|
61
15
|
? 'sint8'
|
|
@@ -89,6 +43,46 @@ export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFo
|
|
|
89
43
|
? 'uint32'
|
|
90
44
|
: never;
|
|
91
45
|
|
|
46
|
+
/** @type A numeric array of length matching the number of components in the texture format */
|
|
47
|
+
export type TextureFormatPixelT<T extends TextureFormat> =
|
|
48
|
+
TextureFormatPackedComponentsT<T> extends 1
|
|
49
|
+
? [number]
|
|
50
|
+
: TextureFormatPackedComponentsT<T> extends 2
|
|
51
|
+
? [number, number]
|
|
52
|
+
: TextureFormatPackedComponentsT<T> extends 3
|
|
53
|
+
? [number, number, number]
|
|
54
|
+
: TextureFormatPackedComponentsT<T> extends 4
|
|
55
|
+
? [number, number, number, number]
|
|
56
|
+
: never;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @type number - the number of components in a texture format
|
|
60
|
+
* @note packed formats have only one component. Use TextureFormatPackedComponentsT
|
|
61
|
+
*/
|
|
62
|
+
export type TextureFormatComponentsT<T extends TextureFormat> = T extends
|
|
63
|
+
| TextureFormatR
|
|
64
|
+
| TextureFormatPackedRGB
|
|
65
|
+
| TextureFormatPackedRGBA
|
|
66
|
+
? 1
|
|
67
|
+
: T extends TextureFormatRG
|
|
68
|
+
? 2
|
|
69
|
+
: T extends TextureFormatRGB
|
|
70
|
+
? 3
|
|
71
|
+
: T extends TextureFormatRGBA
|
|
72
|
+
? 4
|
|
73
|
+
: never;
|
|
74
|
+
|
|
75
|
+
/** @type number - the number of components in a packed texture format */
|
|
76
|
+
export type TextureFormatPackedComponentsT<T extends TextureFormat> = T extends TextureFormatR
|
|
77
|
+
? 1
|
|
78
|
+
: T extends TextureFormatRG
|
|
79
|
+
? 2
|
|
80
|
+
: T extends TextureFormatRGB | TextureFormatPackedRGB
|
|
81
|
+
? 3
|
|
82
|
+
: T extends TextureFormatRGBA | TextureFormatPackedRGBA
|
|
83
|
+
? 4
|
|
84
|
+
: never;
|
|
85
|
+
|
|
92
86
|
// Component groups
|
|
93
87
|
|
|
94
88
|
type TextureFormatR =
|
|
@@ -24,6 +24,7 @@ const float32_renderable: TextureFeature = 'float32-renderable-webgl';
|
|
|
24
24
|
const float16_renderable: TextureFeature = 'float16-renderable-webgl';
|
|
25
25
|
const rgb9e5ufloat_renderable: TextureFeature = 'rgb9e5ufloat-renderable-webgl';
|
|
26
26
|
const snorm8_renderable: TextureFeature = 'snorm8-renderable-webgl';
|
|
27
|
+
const norm16_webgl: TextureFeature = 'norm16-webgl';
|
|
27
28
|
const norm16_renderable: TextureFeature = 'norm16-renderable-webgl';
|
|
28
29
|
const snorm16_renderable: TextureFeature = 'snorm16-renderable-webgl';
|
|
29
30
|
|
|
@@ -93,15 +94,15 @@ const TEXTURE_FORMAT_COLOR_DEPTH_TABLE: Readonly<Record<TextureFormatColorUncomp
|
|
|
93
94
|
'bgra8unorm-srgb': {},
|
|
94
95
|
|
|
95
96
|
|
|
96
|
-
'r16unorm': {f: norm16_renderable},
|
|
97
|
-
'rg16unorm': {render: norm16_renderable},
|
|
98
|
-
'rgb16unorm-webgl': {f:
|
|
99
|
-
'rgba16unorm': {render: norm16_renderable},
|
|
97
|
+
'r16unorm': {f: norm16_webgl, render: norm16_renderable},
|
|
98
|
+
'rg16unorm': {f: norm16_webgl, render: norm16_renderable},
|
|
99
|
+
'rgb16unorm-webgl': {f: norm16_webgl, render: false}, // rgb not renderable
|
|
100
|
+
'rgba16unorm': {f: norm16_webgl, render: norm16_renderable},
|
|
100
101
|
|
|
101
|
-
'r16snorm': {f: snorm16_renderable},
|
|
102
|
-
'rg16snorm': {render: snorm16_renderable},
|
|
103
|
-
'rgb16snorm-webgl': {f:
|
|
104
|
-
'rgba16snorm': {render: snorm16_renderable},
|
|
102
|
+
'r16snorm': {f: norm16_webgl, render: snorm16_renderable},
|
|
103
|
+
'rg16snorm': {f: norm16_webgl, render: snorm16_renderable},
|
|
104
|
+
'rgb16snorm-webgl': {f: norm16_webgl, render: false}, // rgb not renderable
|
|
105
|
+
'rgba16snorm': {f: norm16_webgl, render: snorm16_renderable},
|
|
105
106
|
|
|
106
107
|
'r16uint': {},
|
|
107
108
|
'rg16uint': {},
|
|
@@ -225,7 +226,7 @@ const TEXTURE_FORMAT_COMPRESSED_TABLE: Readonly<Record<TextureFormatCompressed,
|
|
|
225
226
|
|
|
226
227
|
'pvrtc-rgb4unorm-webgl': {f: texture_compression_pvrtc_webgl},
|
|
227
228
|
'pvrtc-rgba4unorm-webgl': {f: texture_compression_pvrtc_webgl},
|
|
228
|
-
'pvrtc-
|
|
229
|
+
'pvrtc-rgb2unorm-webgl': {f: texture_compression_pvrtc_webgl},
|
|
229
230
|
'pvrtc-rgba2unorm-webgl': {f: texture_compression_pvrtc_webgl},
|
|
230
231
|
|
|
231
232
|
// WEBGL_compressed_texture_etc1
|
|
@@ -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 */
|
|
@@ -116,6 +122,7 @@ export type TextureFeature =
|
|
|
116
122
|
| 'float16-renderable-webgl'
|
|
117
123
|
| 'rgb9e5ufloat-renderable-webgl'
|
|
118
124
|
| 'snorm8-renderable-webgl'
|
|
125
|
+
| 'norm16-webgl'
|
|
119
126
|
| 'norm16-renderable-webgl'
|
|
120
127
|
| 'snorm16-renderable-webgl'
|
|
121
128
|
| 'float32-filterable'
|
|
@@ -199,13 +206,12 @@ export type TextureFormatPacked32 =
|
|
|
199
206
|
| 'rg11b10ufloat'
|
|
200
207
|
| 'rgb10a2unorm'
|
|
201
208
|
| 'rgb10a2uint';
|
|
202
|
-
|
|
203
209
|
export type TextureFormatCompressed =
|
|
204
210
|
| 'bc1-rgb-unorm-webgl'
|
|
205
211
|
| 'bc1-rgb-unorm-srgb-webgl'
|
|
206
212
|
| 'pvrtc-rgb4unorm-webgl'
|
|
207
213
|
| 'pvrtc-rgba4unorm-webgl'
|
|
208
|
-
| 'pvrtc-
|
|
214
|
+
| 'pvrtc-rgb2unorm-webgl'
|
|
209
215
|
| 'pvrtc-rgba2unorm-webgl'
|
|
210
216
|
| 'etc1-rbg-unorm-webgl'
|
|
211
217
|
| 'atc-rgb-unorm-webgl'
|
|
@@ -274,6 +280,8 @@ export type TextureFormatCompressed =
|
|
|
274
280
|
| 'astc-12x12-unorm'
|
|
275
281
|
| 'astc-12x12-unorm-srgb';
|
|
276
282
|
|
|
283
|
+
export type CompressedTextureFormat = TextureFormatCompressed;
|
|
284
|
+
|
|
277
285
|
// Texture format helper types
|
|
278
286
|
|
|
279
287
|
export type TextureFormatTypedArray<T extends TextureFormat> = DataTypeArray<
|
|
@@ -318,6 +326,15 @@ export type TextureFormatDataType<T extends TextureFormat> = T extends TextureFo
|
|
|
318
326
|
? 'uint32'
|
|
319
327
|
: never;
|
|
320
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
|
+
|
|
321
338
|
/*
|
|
322
339
|
export type TextureFormatColorWebGPU =
|
|
323
340
|
// 8-bit formats
|
|
@@ -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';
|