@luma.gl/core 9.2.0-alpha.1 → 9.2.0-alpha.3
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 +17 -3
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +48 -2
- package/dist/adapter/canvas-context.js.map +1 -1
- package/dist/adapter/device.d.ts +56 -11
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +78 -22
- package/dist/adapter/device.js.map +1 -1
- package/dist/adapter/luma.js +1 -1
- package/dist/adapter/resources/buffer.d.ts +13 -7
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +1 -5
- package/dist/adapter/resources/buffer.js.map +1 -1
- package/dist/adapter/resources/command-encoder.d.ts +0 -1
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/command-encoder.js.map +1 -1
- package/dist/adapter/resources/framebuffer.d.ts +3 -3
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/pipeline-layout.d.ts +13 -0
- package/dist/adapter/resources/pipeline-layout.d.ts.map +1 -0
- package/dist/adapter/resources/pipeline-layout.js +21 -0
- package/dist/adapter/resources/pipeline-layout.js.map +1 -0
- package/dist/adapter/resources/render-pipeline.d.ts +4 -4
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/resource.d.ts +1 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -1
- package/dist/adapter/resources/resource.js.map +1 -1
- 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 +1 -1
- package/dist/adapter/resources/texture.d.ts.map +1 -1
- package/dist/adapter/resources/vertex-array.js +1 -1
- package/dist/adapter/resources/vertex-array.js.map +1 -1
- package/dist/adapter/types/attachments.d.ts +3 -3
- 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 +2 -2
- package/dist/adapter/types/parameters.d.ts.map +1 -1
- package/dist/adapter/types/shader-layout.d.ts +5 -6
- package/dist/adapter/types/shader-layout.d.ts.map +1 -1
- package/dist/adapter-utils/get-attribute-from-layouts.d.ts +3 -3
- package/dist/adapter-utils/get-attribute-from-layouts.d.ts.map +1 -1
- package/dist/adapter-utils/get-attribute-from-layouts.js +2 -2
- package/dist/adapter-utils/get-attribute-from-layouts.js.map +1 -1
- package/dist/dist.dev.js +417 -267
- package/dist/dist.min.js +5 -4
- package/dist/index.cjs +416 -266
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +18 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -7
- 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 +2 -2
- package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.js +2 -2
- package/dist/portable/uniform-buffer-layout.js.map +1 -1
- package/dist/portable/uniform-store.d.ts +1 -1
- package/dist/portable/uniform-store.d.ts.map +1 -1
- package/dist/shadertypes/{data-types.d.ts → data-types/data-types.d.ts} +4 -0
- package/dist/shadertypes/data-types/data-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/data-types.js.map +1 -0
- package/dist/shadertypes/{utils → data-types}/decode-data-types.d.ts +4 -4
- package/dist/shadertypes/data-types/decode-data-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/decode-data-types.js +74 -0
- package/dist/shadertypes/data-types/decode-data-types.js.map +1 -0
- package/dist/shadertypes/{utils → data-types}/decode-shader-types.d.ts +2 -2
- package/dist/shadertypes/data-types/decode-shader-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/decode-shader-types.js.map +1 -0
- package/dist/shadertypes/data-types/shader-types.d.ts.map +1 -0
- package/dist/shadertypes/data-types/shader-types.js.map +1 -0
- package/dist/shadertypes/textures/pixel-utils.d.ts +112 -0
- package/dist/shadertypes/textures/pixel-utils.d.ts.map +1 -0
- package/dist/shadertypes/textures/pixel-utils.js +193 -0
- package/dist/shadertypes/textures/pixel-utils.js.map +1 -0
- package/dist/shadertypes/textures/texture-format-decoder.d.ts +18 -0
- package/dist/shadertypes/textures/texture-format-decoder.d.ts.map +1 -0
- package/dist/shadertypes/{utils/decode-texture-format.js → textures/texture-format-decoder.js} +48 -35
- package/dist/shadertypes/textures/texture-format-decoder.js.map +1 -0
- package/dist/shadertypes/textures/texture-format-generics.d.ts +33 -0
- package/dist/shadertypes/textures/texture-format-generics.d.ts.map +1 -0
- package/dist/shadertypes/{texture-formats.js → textures/texture-format-generics.js} +1 -1
- package/dist/shadertypes/textures/texture-format-generics.js.map +1 -0
- package/dist/shadertypes/{utils → textures}/texture-format-table.d.ts +2 -1
- package/dist/shadertypes/textures/texture-format-table.d.ts.map +1 -0
- package/dist/shadertypes/{utils → textures}/texture-format-table.js +41 -42
- package/dist/shadertypes/textures/texture-format-table.js.map +1 -0
- package/dist/shadertypes/textures/texture-formats.d.ts +90 -0
- package/dist/shadertypes/textures/texture-formats.d.ts.map +1 -0
- package/dist/shadertypes/textures/texture-formats.js +58 -0
- package/dist/shadertypes/textures/texture-formats.js.map +1 -0
- package/dist/shadertypes/{utils → vertex-arrays}/decode-vertex-format.d.ts +2 -2
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.d.ts.map +1 -0
- package/dist/shadertypes/{utils → vertex-arrays}/decode-vertex-format.js +4 -4
- package/dist/shadertypes/vertex-arrays/decode-vertex-format.js.map +1 -0
- package/dist/shadertypes/{vertex-formats.d.ts → vertex-arrays/vertex-formats.d.ts} +5 -3
- package/dist/shadertypes/vertex-arrays/vertex-formats.d.ts.map +1 -0
- package/dist/shadertypes/vertex-arrays/vertex-formats.js.map +1 -0
- package/package.json +2 -2
- package/src/adapter/canvas-context.ts +60 -5
- package/src/adapter/device.ts +132 -47
- package/src/adapter/resources/buffer.ts +30 -14
- package/src/adapter/resources/command-encoder.ts +0 -2
- package/src/adapter/resources/framebuffer.ts +5 -5
- package/src/adapter/resources/pipeline-layout.ts +30 -0
- package/src/adapter/resources/render-pipeline.ts +6 -6
- package/src/adapter/resources/resource.ts +1 -0
- package/src/adapter/resources/texture-view.ts +1 -1
- package/src/adapter/resources/texture.ts +1 -1
- package/src/adapter/resources/vertex-array.ts +1 -1
- package/src/adapter/types/attachments.ts +5 -5
- package/src/adapter/types/buffer-layout.ts +1 -1
- package/src/adapter/types/parameters.ts +2 -2
- package/src/adapter/types/shader-layout.ts +8 -5
- package/src/adapter-utils/get-attribute-from-layouts.ts +5 -5
- package/src/index.ts +60 -36
- package/src/portable/uniform-block.ts +1 -1
- package/src/portable/uniform-buffer-layout.ts +4 -4
- package/src/portable/uniform-store.ts +1 -1
- package/src/shadertypes/data-types/data-types.ts +96 -0
- package/src/shadertypes/data-types/decode-data-types.ts +91 -0
- package/src/shadertypes/{utils → data-types}/decode-shader-types.ts +2 -2
- package/src/shadertypes/textures/pixel-utils.ts +239 -0
- package/src/shadertypes/{utils/decode-texture-format.ts → textures/texture-format-decoder.ts} +63 -47
- package/src/shadertypes/textures/texture-format-generics.ts +190 -0
- package/src/shadertypes/{utils → textures}/texture-format-table.ts +62 -52
- package/src/shadertypes/{texture-formats.ts → textures/texture-formats.ts} +229 -147
- package/src/shadertypes/{utils → vertex-arrays}/decode-vertex-format.ts +6 -10
- package/src/shadertypes/{vertex-formats.ts → vertex-arrays/vertex-formats.ts} +20 -6
- package/dist/adapter-utils/buffer-layout-helper.d.ts +0 -11
- package/dist/adapter-utils/buffer-layout-helper.d.ts.map +0 -1
- package/dist/adapter-utils/buffer-layout-helper.js +0 -33
- package/dist/adapter-utils/buffer-layout-helper.js.map +0 -1
- package/dist/shadertypes/data-types.d.ts.map +0 -1
- package/dist/shadertypes/data-types.js.map +0 -1
- package/dist/shadertypes/shader-types.d.ts.map +0 -1
- package/dist/shadertypes/shader-types.js.map +0 -1
- package/dist/shadertypes/texture-formats.d.ts +0 -74
- package/dist/shadertypes/texture-formats.d.ts.map +0 -1
- package/dist/shadertypes/texture-formats.js.map +0 -1
- package/dist/shadertypes/utils/decode-data-types.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-data-types.js +0 -114
- package/dist/shadertypes/utils/decode-data-types.js.map +0 -1
- package/dist/shadertypes/utils/decode-shader-types.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-shader-types.js.map +0 -1
- package/dist/shadertypes/utils/decode-texture-format.d.ts +0 -15
- package/dist/shadertypes/utils/decode-texture-format.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-texture-format.js.map +0 -1
- package/dist/shadertypes/utils/decode-vertex-format.d.ts.map +0 -1
- package/dist/shadertypes/utils/decode-vertex-format.js.map +0 -1
- package/dist/shadertypes/utils/texture-format-table.d.ts.map +0 -1
- package/dist/shadertypes/utils/texture-format-table.js.map +0 -1
- package/dist/shadertypes/vertex-formats.d.ts.map +0 -1
- package/dist/shadertypes/vertex-formats.js.map +0 -1
- package/src/adapter-utils/buffer-layout-helper.ts +0 -41
- package/src/shadertypes/data-types.ts +0 -42
- package/src/shadertypes/utils/decode-data-types.ts +0 -131
- /package/dist/shadertypes/{data-types.js → data-types/data-types.js} +0 -0
- /package/dist/shadertypes/{utils → data-types}/decode-shader-types.js +0 -0
- /package/dist/shadertypes/{shader-types.d.ts → data-types/shader-types.d.ts} +0 -0
- /package/dist/shadertypes/{shader-types.js → data-types/shader-types.js} +0 -0
- /package/dist/shadertypes/{vertex-formats.js → vertex-arrays/vertex-formats.js} +0 -0
- /package/src/shadertypes/{shader-types.ts → data-types/shader-types.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(dist_exports, {
|
|
|
37
37
|
DeviceLimits: () => DeviceLimits,
|
|
38
38
|
ExternalTexture: () => ExternalTexture,
|
|
39
39
|
Framebuffer: () => Framebuffer,
|
|
40
|
+
PipelineLayout: () => PipelineLayout,
|
|
40
41
|
QuerySet: () => QuerySet,
|
|
41
42
|
RenderPass: () => RenderPass,
|
|
42
43
|
RenderPipeline: () => RenderPipeline,
|
|
@@ -44,30 +45,31 @@ __export(dist_exports, {
|
|
|
44
45
|
Sampler: () => Sampler,
|
|
45
46
|
Shader: () => Shader,
|
|
46
47
|
Texture: () => Texture,
|
|
48
|
+
TextureFormatDecoder: () => TextureFormatDecoder,
|
|
47
49
|
TextureView: () => TextureView,
|
|
48
50
|
TransformFeedback: () => TransformFeedback,
|
|
49
51
|
UniformBlock: () => UniformBlock,
|
|
50
52
|
UniformBufferLayout: () => UniformBufferLayout,
|
|
51
53
|
UniformStore: () => UniformStore,
|
|
52
54
|
VertexArray: () => VertexArray,
|
|
53
|
-
_BufferLayoutHelper: () => BufferLayoutHelper,
|
|
54
55
|
_getTextureFormatDefinition: () => getTextureFormatDefinition,
|
|
55
56
|
_getTextureFormatTable: () => getTextureFormatTable,
|
|
56
57
|
getAttributeInfosFromLayouts: () => getAttributeInfosFromLayouts,
|
|
57
58
|
getAttributeShaderTypeInfo: () => getAttributeShaderTypeInfo,
|
|
58
|
-
|
|
59
|
+
getDataType: () => getDataType,
|
|
59
60
|
getDataTypeInfo: () => getDataTypeInfo,
|
|
61
|
+
getNormalizedDataType: () => getNormalizedDataType,
|
|
60
62
|
getScratchArray: () => getScratchArray,
|
|
61
|
-
|
|
62
|
-
getTextureFormatInfo: () => getTextureFormatInfo,
|
|
63
|
-
getTypedArrayFromDataType: () => getTypedArrayFromDataType,
|
|
63
|
+
getTypedArrayConstructor: () => getTypedArrayConstructor,
|
|
64
64
|
getVariableShaderTypeInfo: () => getVariableShaderTypeInfo,
|
|
65
65
|
getVertexFormatFromAttribute: () => getVertexFormatFromAttribute,
|
|
66
66
|
getVertexFormatInfo: () => getVertexFormatInfo,
|
|
67
67
|
log: () => log,
|
|
68
68
|
luma: () => luma,
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
makeVertexFormat: () => makeVertexFormat,
|
|
70
|
+
readPixel: () => readPixel,
|
|
71
|
+
textureFormatDecoder: () => textureFormatDecoder,
|
|
72
|
+
writePixel: () => writePixel
|
|
71
73
|
});
|
|
72
74
|
module.exports = __toCommonJS(dist_exports);
|
|
73
75
|
|
|
@@ -262,10 +264,6 @@ var _Buffer = class extends Resource {
|
|
|
262
264
|
clone(props) {
|
|
263
265
|
return this.device.createBuffer({ ...this.props, ...props });
|
|
264
266
|
}
|
|
265
|
-
/** Read data synchronously. @note WebGL2 only */
|
|
266
|
-
readSyncWebGL(byteOffset, byteLength) {
|
|
267
|
-
throw new Error("not implemented");
|
|
268
|
-
}
|
|
269
267
|
/** A partial CPU-side copy of the data in this buffer, for debugging purposes */
|
|
270
268
|
debugData = new ArrayBuffer(0);
|
|
271
269
|
/** This doesn't handle partial non-zero offset updates correctly */
|
|
@@ -308,10 +306,10 @@ __publicField(Buffer2, "defaultProps", {
|
|
|
308
306
|
byteOffset: 0,
|
|
309
307
|
data: null,
|
|
310
308
|
indexType: "uint16",
|
|
311
|
-
|
|
309
|
+
onMapped: void 0
|
|
312
310
|
});
|
|
313
311
|
|
|
314
|
-
// dist/shadertypes/
|
|
312
|
+
// dist/shadertypes/data-types/decode-data-types.js
|
|
315
313
|
function getDataTypeInfo(type) {
|
|
316
314
|
const [signedType, primitiveType, byteLength] = NORMALIZED_TYPE_MAP[type];
|
|
317
315
|
const normalized = type.includes("norm");
|
|
@@ -326,7 +324,7 @@ function getDataTypeInfo(type) {
|
|
|
326
324
|
signed
|
|
327
325
|
};
|
|
328
326
|
}
|
|
329
|
-
function
|
|
327
|
+
function getNormalizedDataType(signedDataType) {
|
|
330
328
|
const dataType = signedDataType;
|
|
331
329
|
switch (dataType) {
|
|
332
330
|
case "uint8":
|
|
@@ -351,72 +349,117 @@ function alignTo(size, count) {
|
|
|
351
349
|
return size + (4 - size % 4) % 4;
|
|
352
350
|
}
|
|
353
351
|
}
|
|
354
|
-
function
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
return "uint32";
|
|
363
|
-
case Uint8Array:
|
|
364
|
-
case Uint8ClampedArray:
|
|
365
|
-
return "uint8";
|
|
366
|
-
case Int8Array:
|
|
367
|
-
return "sint8";
|
|
368
|
-
case Int16Array:
|
|
369
|
-
return "sint16";
|
|
370
|
-
case Int32Array:
|
|
371
|
-
return "sint32";
|
|
372
|
-
default:
|
|
373
|
-
throw new Error(type.constructor.name);
|
|
352
|
+
function getDataType(arrayOrType) {
|
|
353
|
+
const Constructor = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
|
|
354
|
+
if (Constructor === Uint8ClampedArray) {
|
|
355
|
+
return "uint8";
|
|
356
|
+
}
|
|
357
|
+
const info = Object.values(NORMALIZED_TYPE_MAP).find((entry) => Constructor === entry[4]);
|
|
358
|
+
if (!info) {
|
|
359
|
+
throw new Error(Constructor.name);
|
|
374
360
|
}
|
|
361
|
+
return info[0];
|
|
375
362
|
}
|
|
376
|
-
function
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
363
|
+
function getTypedArrayConstructor(type) {
|
|
364
|
+
const [, , , , Constructor] = NORMALIZED_TYPE_MAP[type];
|
|
365
|
+
return Constructor;
|
|
366
|
+
}
|
|
367
|
+
var NORMALIZED_TYPE_MAP = {
|
|
368
|
+
uint8: ["uint8", "u32", 1, false, Uint8Array],
|
|
369
|
+
sint8: ["sint8", "i32", 1, false, Int8Array],
|
|
370
|
+
unorm8: ["uint8", "f32", 1, true, Uint8Array],
|
|
371
|
+
snorm8: ["sint8", "f32", 1, true, Int8Array],
|
|
372
|
+
uint16: ["uint16", "u32", 2, false, Uint16Array],
|
|
373
|
+
sint16: ["sint16", "i32", 2, false, Int16Array],
|
|
374
|
+
unorm16: ["uint16", "u32", 2, true, Uint16Array],
|
|
375
|
+
snorm16: ["sint16", "i32", 2, true, Int16Array],
|
|
376
|
+
float16: ["float16", "f16", 2, false, Uint16Array],
|
|
377
|
+
float32: ["float32", "f32", 4, false, Float32Array],
|
|
378
|
+
uint32: ["uint32", "u32", 4, false, Uint32Array],
|
|
379
|
+
sint32: ["sint32", "i32", 4, false, Int32Array]
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// dist/shadertypes/vertex-arrays/decode-vertex-format.js
|
|
383
|
+
function getVertexFormatInfo(format) {
|
|
384
|
+
let webglOnly;
|
|
385
|
+
if (format.endsWith("-webgl")) {
|
|
386
|
+
format.replace("-webgl", "");
|
|
387
|
+
webglOnly = true;
|
|
388
|
+
}
|
|
389
|
+
const [type_, count] = format.split("x");
|
|
390
|
+
const type = type_;
|
|
391
|
+
const components = count ? parseInt(count) : 1;
|
|
392
|
+
const decodedType = getDataTypeInfo(type);
|
|
393
|
+
const result = {
|
|
394
|
+
type,
|
|
395
|
+
components,
|
|
396
|
+
byteLength: decodedType.byteLength * components,
|
|
397
|
+
integer: decodedType.integer,
|
|
398
|
+
signed: decodedType.signed,
|
|
399
|
+
normalized: decodedType.normalized
|
|
400
|
+
};
|
|
401
|
+
if (webglOnly) {
|
|
402
|
+
result.webglOnly = true;
|
|
403
|
+
}
|
|
404
|
+
return result;
|
|
405
|
+
}
|
|
406
|
+
function makeVertexFormat(signedDataType, components, normalized) {
|
|
407
|
+
const dataType = normalized ? getNormalizedDataType(signedDataType) : signedDataType;
|
|
408
|
+
switch (dataType) {
|
|
409
|
+
case "unorm8":
|
|
410
|
+
if (components === 1) {
|
|
411
|
+
return "unorm8";
|
|
412
|
+
}
|
|
413
|
+
if (components === 3) {
|
|
414
|
+
return "unorm8x3-webgl";
|
|
415
|
+
}
|
|
416
|
+
return `${dataType}x${components}`;
|
|
417
|
+
case "snorm8":
|
|
418
|
+
case "uint8":
|
|
419
|
+
case "sint8":
|
|
387
420
|
case "uint16":
|
|
388
|
-
case "unorm16":
|
|
389
|
-
return Uint16Array;
|
|
390
421
|
case "sint16":
|
|
422
|
+
case "unorm16":
|
|
391
423
|
case "snorm16":
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
case "snorm8":
|
|
398
|
-
return Int8Array;
|
|
399
|
-
case "f16":
|
|
424
|
+
case "float16":
|
|
425
|
+
if (components === 1 || components === 3) {
|
|
426
|
+
throw new Error(`size: ${components}`);
|
|
427
|
+
}
|
|
428
|
+
return `${dataType}x${components}`;
|
|
400
429
|
default:
|
|
401
|
-
|
|
430
|
+
return components === 1 ? dataType : `${dataType}x${components}`;
|
|
402
431
|
}
|
|
403
432
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
433
|
+
function getVertexFormatFromAttribute(typedArray, size, normalized) {
|
|
434
|
+
if (!size || size > 4) {
|
|
435
|
+
throw new Error(`size ${size}`);
|
|
436
|
+
}
|
|
437
|
+
const components = size;
|
|
438
|
+
const signedDataType = getDataType(typedArray);
|
|
439
|
+
return makeVertexFormat(signedDataType, components, normalized);
|
|
440
|
+
}
|
|
441
|
+
function getCompatibleVertexFormat(opts) {
|
|
442
|
+
let vertexType;
|
|
443
|
+
switch (opts.primitiveType) {
|
|
444
|
+
case "f32":
|
|
445
|
+
vertexType = "float32";
|
|
446
|
+
break;
|
|
447
|
+
case "i32":
|
|
448
|
+
vertexType = "sint32";
|
|
449
|
+
break;
|
|
450
|
+
case "u32":
|
|
451
|
+
vertexType = "uint32";
|
|
452
|
+
break;
|
|
453
|
+
case "f16":
|
|
454
|
+
return opts.components <= 2 ? "float16x2" : "float16x4";
|
|
455
|
+
}
|
|
456
|
+
if (opts.components === 1) {
|
|
457
|
+
return vertexType;
|
|
458
|
+
}
|
|
459
|
+
return `${vertexType}x${opts.components}`;
|
|
460
|
+
}
|
|
418
461
|
|
|
419
|
-
// dist/shadertypes/
|
|
462
|
+
// dist/shadertypes/textures/texture-format-table.js
|
|
420
463
|
var texture_compression_bc = "texture-compression-bc";
|
|
421
464
|
var texture_compression_astc = "texture-compression-astc";
|
|
422
465
|
var texture_compression_etc2 = "texture-compression-etc2";
|
|
@@ -441,73 +484,65 @@ function getTextureFormatDefinition(format) {
|
|
|
441
484
|
function getTextureFormatTable() {
|
|
442
485
|
return TEXTURE_FORMAT_TABLE;
|
|
443
486
|
}
|
|
444
|
-
var
|
|
487
|
+
var TEXTURE_FORMAT_COLOR_DEPTH_TABLE = {
|
|
445
488
|
// 8-bit formats
|
|
446
489
|
"r8unorm": {},
|
|
447
|
-
"r8snorm": { render: snorm8_renderable },
|
|
448
|
-
"r8uint": {},
|
|
449
|
-
"r8sint": {},
|
|
450
|
-
// 16-bit formats
|
|
451
490
|
"rg8unorm": {},
|
|
452
|
-
"rg8snorm": { render: snorm8_renderable },
|
|
453
|
-
"rg8uint": {},
|
|
454
|
-
"rg8sint": {},
|
|
455
|
-
"r16uint": {},
|
|
456
|
-
"r16sint": {},
|
|
457
|
-
"r16float": { render: float16_renderable, filter: "float16-filterable-webgl" },
|
|
458
|
-
"r16unorm-webgl": { f: norm16_renderable },
|
|
459
|
-
"r16snorm-webgl": { f: snorm16_renderable },
|
|
460
|
-
// Packed 16-bit formats
|
|
461
|
-
"rgba4unorm-webgl": { channels: "rgba", bitsPerChannel: [4, 4, 4, 4], packed: true },
|
|
462
|
-
"rgb565unorm-webgl": { channels: "rgb", bitsPerChannel: [5, 6, 5, 0], packed: true },
|
|
463
|
-
"rgb5a1unorm-webgl": { channels: "rgba", bitsPerChannel: [5, 5, 5, 1], packed: true },
|
|
464
|
-
// 24-bit formats
|
|
465
491
|
"rgb8unorm-webgl": {},
|
|
466
|
-
"rgb8snorm-webgl": {},
|
|
467
|
-
// 32-bit formats
|
|
468
492
|
"rgba8unorm": {},
|
|
469
493
|
"rgba8unorm-srgb": {},
|
|
494
|
+
"r8snorm": { render: snorm8_renderable },
|
|
495
|
+
"rg8snorm": { render: snorm8_renderable },
|
|
496
|
+
"rgb8snorm-webgl": {},
|
|
470
497
|
"rgba8snorm": { render: snorm8_renderable },
|
|
498
|
+
"r8uint": {},
|
|
499
|
+
"rg8uint": {},
|
|
471
500
|
"rgba8uint": {},
|
|
501
|
+
"r8sint": {},
|
|
502
|
+
"rg8sint": {},
|
|
472
503
|
"rgba8sint": {},
|
|
473
|
-
// 32-bit, reverse colors, webgpu only
|
|
474
504
|
"bgra8unorm": {},
|
|
475
505
|
"bgra8unorm-srgb": {},
|
|
506
|
+
"r16unorm": { f: norm16_renderable },
|
|
507
|
+
"rg16unorm": { render: norm16_renderable },
|
|
508
|
+
"rgb16unorm-webgl": { f: norm16_renderable },
|
|
509
|
+
// rgb not renderable
|
|
510
|
+
"rgba16unorm": { render: norm16_renderable },
|
|
511
|
+
"r16snorm": { f: snorm16_renderable },
|
|
512
|
+
"rg16snorm": { render: snorm16_renderable },
|
|
513
|
+
"rgb16snorm-webgl": { f: norm16_renderable },
|
|
514
|
+
// rgb not renderable
|
|
515
|
+
"rgba16snorm": { render: snorm16_renderable },
|
|
516
|
+
"r16uint": {},
|
|
476
517
|
"rg16uint": {},
|
|
518
|
+
"rgba16uint": {},
|
|
519
|
+
"r16sint": {},
|
|
477
520
|
"rg16sint": {},
|
|
521
|
+
"rgba16sint": {},
|
|
522
|
+
"r16float": { render: float16_renderable, filter: "float16-filterable-webgl" },
|
|
478
523
|
"rg16float": { render: float16_renderable, filter: float16_filterable },
|
|
479
|
-
"
|
|
480
|
-
"rg16snorm-webgl": { render: snorm16_renderable },
|
|
524
|
+
"rgba16float": { render: float16_renderable, filter: float16_filterable },
|
|
481
525
|
"r32uint": {},
|
|
526
|
+
"rg32uint": {},
|
|
527
|
+
"rgba32uint": {},
|
|
482
528
|
"r32sint": {},
|
|
529
|
+
"rg32sint": {},
|
|
530
|
+
"rgba32sint": {},
|
|
483
531
|
"r32float": { render: float32_renderable, filter: float32_filterable },
|
|
532
|
+
"rg32float": { render: false, filter: float32_filterable },
|
|
533
|
+
"rgb32float-webgl": { render: float32_renderable, filter: float32_filterable },
|
|
534
|
+
"rgba32float": { render: float32_renderable, filter: float32_filterable },
|
|
535
|
+
// Packed 16-bit formats
|
|
536
|
+
"rgba4unorm-webgl": { channels: "rgba", bitsPerChannel: [4, 4, 4, 4], packed: true },
|
|
537
|
+
"rgb565unorm-webgl": { channels: "rgb", bitsPerChannel: [5, 6, 5, 0], packed: true },
|
|
538
|
+
"rgb5a1unorm-webgl": { channels: "rgba", bitsPerChannel: [5, 5, 5, 1], packed: true },
|
|
484
539
|
// Packed 32 bit formats
|
|
485
540
|
"rgb9e5ufloat": { channels: "rgb", packed: true, render: rgb9e5ufloat_renderable },
|
|
486
541
|
// , filter: true},
|
|
487
542
|
"rg11b10ufloat": { channels: "rgb", bitsPerChannel: [11, 11, 10, 0], packed: true, p: 1, render: float32_renderable },
|
|
488
543
|
"rgb10a2unorm": { channels: "rgba", bitsPerChannel: [10, 10, 10, 2], packed: true, p: 1 },
|
|
489
544
|
"rgb10a2uint": { channels: "rgba", bitsPerChannel: [10, 10, 10, 2], packed: true, p: 1 },
|
|
490
|
-
//
|
|
491
|
-
"rgb16unorm-webgl": { f: norm16_renderable },
|
|
492
|
-
// rgb not renderable
|
|
493
|
-
"rgb16snorm-webgl": { f: norm16_renderable },
|
|
494
|
-
// rgb not renderable
|
|
495
|
-
// 64-bit formats
|
|
496
|
-
"rg32uint": {},
|
|
497
|
-
"rg32sint": {},
|
|
498
|
-
"rg32float": { render: false, filter: float32_filterable },
|
|
499
|
-
"rgba16uint": {},
|
|
500
|
-
"rgba16sint": {},
|
|
501
|
-
"rgba16float": { render: float16_renderable, filter: float16_filterable },
|
|
502
|
-
"rgba16unorm-webgl": { render: norm16_renderable },
|
|
503
|
-
"rgba16snorm-webgl": { render: snorm16_renderable },
|
|
504
|
-
// 96-bit formats (deprecated!)
|
|
505
|
-
"rgb32float-webgl": { render: float32_renderable, filter: float32_filterable },
|
|
506
|
-
// 128-bit formats
|
|
507
|
-
"rgba32uint": {},
|
|
508
|
-
"rgba32sint": {},
|
|
509
|
-
"rgba32float": { render: float32_renderable, filter: float32_filterable },
|
|
510
|
-
// Depth/stencil
|
|
545
|
+
// Depth/stencil Formats
|
|
511
546
|
// Depth and stencil formats
|
|
512
547
|
stencil8: { attachment: "stencil", bitsPerChannel: [8, 0, 0, 0], dataType: "uint8" },
|
|
513
548
|
"depth16unorm": { attachment: "depth", bitsPerChannel: [16, 0, 0, 0], dataType: "uint16" },
|
|
@@ -516,7 +551,9 @@ var TEXTURE_FORMAT_TABLE = {
|
|
|
516
551
|
// The depth component of the "depth24plus" and "depth24plus-stencil8" formats may be implemented as either a 24-bit depth value or a "depth32float" value.
|
|
517
552
|
"depth24plus-stencil8": { attachment: "depth-stencil", bitsPerChannel: [24, 8, 0, 0], packed: true },
|
|
518
553
|
// "depth32float-stencil8" feature
|
|
519
|
-
"depth32float-stencil8": { attachment: "depth-stencil", bitsPerChannel: [32, 8, 0, 0], packed: true }
|
|
554
|
+
"depth32float-stencil8": { attachment: "depth-stencil", bitsPerChannel: [32, 8, 0, 0], packed: true }
|
|
555
|
+
};
|
|
556
|
+
var TEXTURE_FORMAT_COMPRESSED_TABLE = {
|
|
520
557
|
// BC compressed formats: check device.features.has("texture-compression-bc");
|
|
521
558
|
"bc1-rgb-unorm-webgl": { f: texture_compression_bc },
|
|
522
559
|
"bc1-rgb-unorm-srgb-webgl": { f: texture_compression_bc },
|
|
@@ -587,8 +624,12 @@ var TEXTURE_FORMAT_TABLE = {
|
|
|
587
624
|
"atc-rgba-unorm-webgl": { f: texture_compression_atc_webgl },
|
|
588
625
|
"atc-rgbai-unorm-webgl": { f: texture_compression_atc_webgl }
|
|
589
626
|
};
|
|
627
|
+
var TEXTURE_FORMAT_TABLE = {
|
|
628
|
+
...TEXTURE_FORMAT_COLOR_DEPTH_TABLE,
|
|
629
|
+
...TEXTURE_FORMAT_COMPRESSED_TABLE
|
|
630
|
+
};
|
|
590
631
|
|
|
591
|
-
// dist/shadertypes/
|
|
632
|
+
// dist/shadertypes/textures/texture-format-decoder.js
|
|
592
633
|
var COMPRESSED_TEXTURE_FORMAT_PREFIXES = [
|
|
593
634
|
"bc1",
|
|
594
635
|
"bc2",
|
|
@@ -605,12 +646,51 @@ var COMPRESSED_TEXTURE_FORMAT_PREFIXES = [
|
|
|
605
646
|
"pvrtc"
|
|
606
647
|
];
|
|
607
648
|
var RGB_FORMAT_REGEX = /^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/;
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
649
|
+
var TextureFormatDecoder = class {
|
|
650
|
+
/** Returns information about a texture format, e.g. attatchment type, components, byte length and flags (integer, signed, normalized) */
|
|
651
|
+
getInfo(format) {
|
|
652
|
+
return getTextureFormatInfo(format);
|
|
653
|
+
}
|
|
654
|
+
/** Checks if a texture format is color */
|
|
655
|
+
isColor(format) {
|
|
656
|
+
return format.startsWith("rgba") || format.startsWith("bgra") || format.startsWith("rgb");
|
|
657
|
+
}
|
|
658
|
+
/** Checks if a texture format is depth or stencil */
|
|
659
|
+
isDepthStencil(format) {
|
|
660
|
+
return format.startsWith("depth") || format.startsWith("stencil");
|
|
661
|
+
}
|
|
662
|
+
/** Checks if a texture format is compressed */
|
|
663
|
+
isCompressed(format) {
|
|
664
|
+
return COMPRESSED_TEXTURE_FORMAT_PREFIXES.some((prefix) => format.startsWith(prefix));
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Returns the "static" capabilities of a texture format.
|
|
668
|
+
* @note Needs to be checked against current device
|
|
669
|
+
*/
|
|
670
|
+
getCapabilities(format) {
|
|
671
|
+
const info = getTextureFormatDefinition(format);
|
|
672
|
+
const formatCapabilities = {
|
|
673
|
+
format,
|
|
674
|
+
create: info.f ?? true,
|
|
675
|
+
render: info.render ?? true,
|
|
676
|
+
filter: info.filter ?? true,
|
|
677
|
+
blend: info.blend ?? true,
|
|
678
|
+
store: info.store ?? true
|
|
679
|
+
};
|
|
680
|
+
const formatInfo = getTextureFormatInfo(format);
|
|
681
|
+
const isDepthStencil = format.startsWith("depth") || format.startsWith("stencil");
|
|
682
|
+
const isSigned = formatInfo == null ? void 0 : formatInfo.signed;
|
|
683
|
+
const isInteger = formatInfo == null ? void 0 : formatInfo.integer;
|
|
684
|
+
const isWebGLSpecific = formatInfo == null ? void 0 : formatInfo.webgl;
|
|
685
|
+
formatCapabilities.render &&= !isSigned;
|
|
686
|
+
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
687
|
+
return formatCapabilities;
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
var textureFormatDecoder = new TextureFormatDecoder();
|
|
611
691
|
function getTextureFormatInfo(format) {
|
|
612
692
|
let formatInfo = getTextureFormatInfoUsingTable(format);
|
|
613
|
-
if (
|
|
693
|
+
if (textureFormatDecoder.isCompressed(format)) {
|
|
614
694
|
formatInfo.channels = "rgb";
|
|
615
695
|
formatInfo.components = 3;
|
|
616
696
|
formatInfo.bytesPerPixel = 1;
|
|
@@ -664,25 +744,6 @@ function getTextureFormatInfo(format) {
|
|
|
664
744
|
}
|
|
665
745
|
return formatInfo;
|
|
666
746
|
}
|
|
667
|
-
function getTextureFormatCapabilities(format) {
|
|
668
|
-
const info = getTextureFormatDefinition(format);
|
|
669
|
-
const formatCapabilities = {
|
|
670
|
-
format,
|
|
671
|
-
create: info.f ?? true,
|
|
672
|
-
render: info.render ?? true,
|
|
673
|
-
filter: info.filter ?? true,
|
|
674
|
-
blend: info.blend ?? true,
|
|
675
|
-
store: info.store ?? true
|
|
676
|
-
};
|
|
677
|
-
const formatInfo = getTextureFormatInfo(format);
|
|
678
|
-
const isDepthStencil = format.startsWith("depth") || format.startsWith("stencil");
|
|
679
|
-
const isSigned = formatInfo == null ? void 0 : formatInfo.signed;
|
|
680
|
-
const isInteger = formatInfo == null ? void 0 : formatInfo.integer;
|
|
681
|
-
const isWebGLSpecific = formatInfo == null ? void 0 : formatInfo.webgl;
|
|
682
|
-
formatCapabilities.render &&= !isSigned;
|
|
683
|
-
formatCapabilities.filter &&= !isDepthStencil && !isSigned && !isInteger && !isWebGLSpecific;
|
|
684
|
-
return formatCapabilities;
|
|
685
|
-
}
|
|
686
747
|
function getTextureFormatInfoUsingTable(format) {
|
|
687
748
|
var _a;
|
|
688
749
|
const info = getTextureFormatDefinition(format);
|
|
@@ -766,9 +827,8 @@ var _Device = class {
|
|
|
766
827
|
get [Symbol.toStringTag]() {
|
|
767
828
|
return "Device";
|
|
768
829
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
|
|
830
|
+
toString() {
|
|
831
|
+
return `Device(${this.id})`;
|
|
772
832
|
}
|
|
773
833
|
/** id of this device, primarily for debugging */
|
|
774
834
|
id;
|
|
@@ -780,12 +840,24 @@ var _Device = class {
|
|
|
780
840
|
statsManager = lumaStats;
|
|
781
841
|
/** An abstract timestamp used for change tracking */
|
|
782
842
|
timestamp = 0;
|
|
843
|
+
/** True if this device has been reused during device creation (app has multiple references) */
|
|
844
|
+
_reused = false;
|
|
783
845
|
/** Used by other luma.gl modules to store data on the device */
|
|
784
846
|
_lumaData = {};
|
|
785
847
|
_textureCaps = {};
|
|
848
|
+
constructor(props) {
|
|
849
|
+
this.props = { ..._Device.defaultProps, ...props };
|
|
850
|
+
this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
|
|
851
|
+
}
|
|
852
|
+
getVertexFormatInfo(format) {
|
|
853
|
+
return getVertexFormatInfo(format);
|
|
854
|
+
}
|
|
855
|
+
isVertexFormatSupported(format) {
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
786
858
|
/** Returns information about a texture format, such as data type, channels, bits per channel, compression etc */
|
|
787
859
|
getTextureFormatInfo(format) {
|
|
788
|
-
return
|
|
860
|
+
return textureFormatDecoder.getInfo(format);
|
|
789
861
|
}
|
|
790
862
|
/** Determines what operations are supported on a texture format on this particular device (checks against supported device features) */
|
|
791
863
|
getTextureFormatCapabilities(format) {
|
|
@@ -824,7 +896,7 @@ var _Device = class {
|
|
|
824
896
|
}
|
|
825
897
|
/** Check if a specific texture format is GPU compressed */
|
|
826
898
|
isTextureFormatCompressed(format) {
|
|
827
|
-
return
|
|
899
|
+
return textureFormatDecoder.isCompressed(format);
|
|
828
900
|
}
|
|
829
901
|
// DEBUG METHODS
|
|
830
902
|
pushDebugGroup(groupLabel) {
|
|
@@ -850,12 +922,40 @@ var _Device = class {
|
|
|
850
922
|
incrementTimestamp() {
|
|
851
923
|
return this.timestamp++;
|
|
852
924
|
}
|
|
853
|
-
/**
|
|
854
|
-
|
|
925
|
+
/**
|
|
926
|
+
* Reports Device errors in a way that optimizes for developer experience / debugging.
|
|
927
|
+
* - Logs so that the console error links directly to the source code that generated the error.
|
|
928
|
+
* - Includes the object that reported the error in the log message, even if the error is asynchronous.
|
|
929
|
+
*
|
|
930
|
+
* Conventions when calling reportError():
|
|
931
|
+
* - Always call the returned function - to ensure error is logged, at the error site
|
|
932
|
+
* - Follow with a call to device.debug() - to ensure that the debugger breaks at the error site
|
|
933
|
+
*
|
|
934
|
+
* @param error - the error to report. If needed, just create a new Error object with the appropriate message.
|
|
935
|
+
* @param context - pass `this` as context, otherwise it may not be available in the debugger for async errors.
|
|
936
|
+
* @returns the logger function returned by device.props.onError() so that it can be called from the error site.
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* device.reportError(new Error(...), this)();
|
|
940
|
+
* device.debug();
|
|
941
|
+
*/
|
|
942
|
+
reportError(error, context, ...args) {
|
|
943
|
+
const isHandled = this.props.onError(error, context);
|
|
944
|
+
if (!isHandled) {
|
|
945
|
+
return log.error(error.message, context, ...args);
|
|
946
|
+
}
|
|
947
|
+
return () => {
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
/** Break in the debugger - if device.props.debug is true */
|
|
951
|
+
debug() {
|
|
855
952
|
if (this.props.debug) {
|
|
856
953
|
debugger;
|
|
954
|
+
} else {
|
|
955
|
+
const message = `'Type luma.log.set({debug: true}) in console to enable debug breakpoints',
|
|
956
|
+
or create a device with the 'debug: true' prop.`;
|
|
957
|
+
log.once(0, message)();
|
|
857
958
|
}
|
|
858
|
-
this.props.onError(error, context);
|
|
859
959
|
}
|
|
860
960
|
/** Returns the default / primary canvas context. Throws an error if no canvas context is available (a WebGPU compute device) */
|
|
861
961
|
getDefaultCanvasContext() {
|
|
@@ -908,8 +1008,12 @@ var _Device = class {
|
|
|
908
1008
|
throw new Error("not implemented");
|
|
909
1009
|
}
|
|
910
1010
|
// IMPLEMENTATION
|
|
1011
|
+
/** Helper to get the canvas context props */
|
|
1012
|
+
static _getCanvasContextProps(props) {
|
|
1013
|
+
return props.createCanvasContext === true ? {} : props.createCanvasContext;
|
|
1014
|
+
}
|
|
911
1015
|
_getDeviceTextureFormatCapabilities(format) {
|
|
912
|
-
const genericCapabilities =
|
|
1016
|
+
const genericCapabilities = textureFormatDecoder.getCapabilities(format);
|
|
913
1017
|
const checkFeature = (feature) => (typeof feature === "string" ? this.features.has(feature) : feature) ?? true;
|
|
914
1018
|
const supported = checkFeature(genericCapabilities.create);
|
|
915
1019
|
return {
|
|
@@ -927,13 +1031,17 @@ var _Device = class {
|
|
|
927
1031
|
props = { data: props };
|
|
928
1032
|
}
|
|
929
1033
|
const newProps = { ...props };
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1034
|
+
const usage = props.usage || 0;
|
|
1035
|
+
if (usage & Buffer2.INDEX) {
|
|
1036
|
+
if (!props.indexType) {
|
|
1037
|
+
if (props.data instanceof Uint32Array) {
|
|
1038
|
+
newProps.indexType = "uint32";
|
|
1039
|
+
} else if (props.data instanceof Uint16Array) {
|
|
1040
|
+
newProps.indexType = "uint16";
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (!newProps.indexType) {
|
|
1044
|
+
throw new Error("indices buffer content must be of type uint16 or uint32");
|
|
937
1045
|
}
|
|
938
1046
|
}
|
|
939
1047
|
return newProps;
|
|
@@ -948,11 +1056,16 @@ __publicField(Device, "defaultProps", {
|
|
|
948
1056
|
// WebGL specific
|
|
949
1057
|
webgl: {},
|
|
950
1058
|
// Callbacks
|
|
951
|
-
|
|
1059
|
+
// eslint-disable-next-line handle-callback-err
|
|
1060
|
+
onError: (error, context) => {
|
|
1061
|
+
},
|
|
952
1062
|
onResize: (context, info) => {
|
|
953
1063
|
const [width, height] = context.getDevicePixelSize();
|
|
954
|
-
|
|
955
|
-
|
|
1064
|
+
log.log(1, `${context} resized => ${width}x${height}px`)();
|
|
1065
|
+
},
|
|
1066
|
+
onPositionChange: (context, info) => {
|
|
1067
|
+
const [left, top] = context.getPosition();
|
|
1068
|
+
log.log(1, `${context} repositioned => ${left},${top}`)();
|
|
956
1069
|
},
|
|
957
1070
|
onVisibilityChange: (context) => log.log(1, `${context} Visibility changed ${context.isVisible}`)(),
|
|
958
1071
|
onDevicePixelRatioChange: (context, info) => log.log(1, `${context} DPR changed ${info.oldRatio} => ${context.devicePixelRatio}`)(),
|
|
@@ -966,6 +1079,7 @@ __publicField(Device, "defaultProps", {
|
|
|
966
1079
|
// Note: log setting is queried by the spector.js code
|
|
967
1080
|
debugSpectorJSUrl: void 0,
|
|
968
1081
|
// Experimental
|
|
1082
|
+
_reuseDevices: false,
|
|
969
1083
|
_requestMaxLimits: true,
|
|
970
1084
|
_cacheShaders: false,
|
|
971
1085
|
_cachePipelines: false,
|
|
@@ -997,7 +1111,7 @@ var _Luma = class {
|
|
|
997
1111
|
VERSION = (
|
|
998
1112
|
// Version detection using build plugin
|
|
999
1113
|
// @ts-expect-error no-undef
|
|
1000
|
-
true ? "9.2.0-alpha.
|
|
1114
|
+
true ? "9.2.0-alpha.3" : "running from source"
|
|
1001
1115
|
);
|
|
1002
1116
|
spector;
|
|
1003
1117
|
preregisteredAdapters = /* @__PURE__ */ new Map();
|
|
@@ -1214,6 +1328,8 @@ var _CanvasContext = class {
|
|
|
1214
1328
|
_initializedResolvers = withResolvers();
|
|
1215
1329
|
_resizeObserver;
|
|
1216
1330
|
_intersectionObserver;
|
|
1331
|
+
_position;
|
|
1332
|
+
destroyed = false;
|
|
1217
1333
|
toString() {
|
|
1218
1334
|
return `${this[Symbol.toStringTag]}(${this.id})`;
|
|
1219
1335
|
}
|
|
@@ -1250,6 +1366,7 @@ var _CanvasContext = class {
|
|
|
1250
1366
|
this.drawingBufferWidth = this.canvas.width;
|
|
1251
1367
|
this.drawingBufferHeight = this.canvas.height;
|
|
1252
1368
|
this.devicePixelRatio = globalThis.devicePixelRatio || 1;
|
|
1369
|
+
this._position = [0, 0];
|
|
1253
1370
|
if (_CanvasContext.isHTMLCanvas(this.canvas)) {
|
|
1254
1371
|
this._intersectionObserver = new IntersectionObserver((entries) => this._handleIntersection(entries));
|
|
1255
1372
|
this._intersectionObserver.observe(this.canvas);
|
|
@@ -1260,8 +1377,14 @@ var _CanvasContext = class {
|
|
|
1260
1377
|
this._resizeObserver.observe(this.canvas, { box: "content-box" });
|
|
1261
1378
|
}
|
|
1262
1379
|
setTimeout(() => this._observeDevicePixelRatio(), 0);
|
|
1380
|
+
if (this.props.trackPosition) {
|
|
1381
|
+
this._trackPosition();
|
|
1382
|
+
}
|
|
1263
1383
|
}
|
|
1264
1384
|
}
|
|
1385
|
+
destroy() {
|
|
1386
|
+
this.destroyed = true;
|
|
1387
|
+
}
|
|
1265
1388
|
// SIZE METHODS
|
|
1266
1389
|
/**
|
|
1267
1390
|
* Returns the size covered by the canvas in CSS pixels
|
|
@@ -1271,6 +1394,9 @@ var _CanvasContext = class {
|
|
|
1271
1394
|
getCSSSize() {
|
|
1272
1395
|
return [this.cssWidth, this.cssHeight];
|
|
1273
1396
|
}
|
|
1397
|
+
getPosition() {
|
|
1398
|
+
return this._position;
|
|
1399
|
+
}
|
|
1274
1400
|
/**
|
|
1275
1401
|
* Returns the size covered by the canvas in actual device pixels.
|
|
1276
1402
|
* @note This can be different from the 'CSS' size of a canvas due to DPR scaling, and rounding to integer pixels
|
|
@@ -1388,15 +1514,46 @@ var _CanvasContext = class {
|
|
|
1388
1514
|
}
|
|
1389
1515
|
this._initializedResolvers.resolve();
|
|
1390
1516
|
this.isInitialized = true;
|
|
1517
|
+
this.updatePosition();
|
|
1391
1518
|
this.device.props.onResize(this, { oldPixelSize });
|
|
1392
1519
|
}
|
|
1393
1520
|
/** Monitor DPR changes */
|
|
1394
1521
|
_observeDevicePixelRatio() {
|
|
1395
1522
|
const oldRatio = this.devicePixelRatio;
|
|
1396
1523
|
this.devicePixelRatio = window.devicePixelRatio;
|
|
1524
|
+
this.updatePosition();
|
|
1397
1525
|
this.device.props.onDevicePixelRatioChange(this, { oldRatio });
|
|
1398
1526
|
matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change", () => this._observeDevicePixelRatio(), { once: true });
|
|
1399
1527
|
}
|
|
1528
|
+
/** Start tracking positions with a timer */
|
|
1529
|
+
_trackPosition(intervalMs = 100) {
|
|
1530
|
+
const intervalId = setInterval(() => {
|
|
1531
|
+
if (this.destroyed) {
|
|
1532
|
+
clearInterval(intervalId);
|
|
1533
|
+
} else {
|
|
1534
|
+
this.updatePosition();
|
|
1535
|
+
}
|
|
1536
|
+
}, intervalMs);
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Calculated the absolute position of the canvas
|
|
1540
|
+
* @note - getBoundingClientRect() is normally cheap but can be expensive
|
|
1541
|
+
* if called before browser has finished a reflow. Should not be the case here.
|
|
1542
|
+
*/
|
|
1543
|
+
updatePosition() {
|
|
1544
|
+
var _a, _b, _c;
|
|
1545
|
+
const newRect = (_a = this.htmlCanvas) == null ? void 0 : _a.getBoundingClientRect();
|
|
1546
|
+
if (newRect) {
|
|
1547
|
+
const position = [newRect.left, newRect.top];
|
|
1548
|
+
this._position ??= position;
|
|
1549
|
+
const positionChanged = position[0] !== this._position[0] || position[1] !== this._position[1];
|
|
1550
|
+
if (positionChanged) {
|
|
1551
|
+
const oldPosition = this._position;
|
|
1552
|
+
this._position = position;
|
|
1553
|
+
(_c = (_b = this.device.props).onPositionChange) == null ? void 0 : _c.call(_b, this, { oldPosition });
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1400
1557
|
};
|
|
1401
1558
|
var CanvasContext = _CanvasContext;
|
|
1402
1559
|
__publicField(CanvasContext, "defaultProps", {
|
|
@@ -1409,7 +1566,8 @@ __publicField(CanvasContext, "defaultProps", {
|
|
|
1409
1566
|
container: null,
|
|
1410
1567
|
visible: true,
|
|
1411
1568
|
alphaMode: "opaque",
|
|
1412
|
-
colorSpace: "srgb"
|
|
1569
|
+
colorSpace: "srgb",
|
|
1570
|
+
trackPosition: false
|
|
1413
1571
|
});
|
|
1414
1572
|
function getContainer(container) {
|
|
1415
1573
|
if (typeof container === "string") {
|
|
@@ -2194,7 +2352,7 @@ __publicField(CommandBuffer, "defaultProps", {
|
|
|
2194
2352
|
...Resource.defaultProps
|
|
2195
2353
|
});
|
|
2196
2354
|
|
|
2197
|
-
// dist/shadertypes/
|
|
2355
|
+
// dist/shadertypes/data-types/decode-shader-types.js
|
|
2198
2356
|
function getVariableShaderTypeInfo(format) {
|
|
2199
2357
|
const decoded = UNIFORM_FORMATS[format];
|
|
2200
2358
|
return decoded;
|
|
@@ -2347,86 +2505,6 @@ var WGSL_VARIABLE_TYPE_ALIAS_MAP = {
|
|
|
2347
2505
|
mat4x4h: "mat4x4<f16>"
|
|
2348
2506
|
};
|
|
2349
2507
|
|
|
2350
|
-
// dist/shadertypes/utils/decode-vertex-format.js
|
|
2351
|
-
function getVertexFormatInfo(format) {
|
|
2352
|
-
let webglOnly;
|
|
2353
|
-
if (format.endsWith("-webgl")) {
|
|
2354
|
-
format.replace("-webgl", "");
|
|
2355
|
-
webglOnly = true;
|
|
2356
|
-
}
|
|
2357
|
-
const [type_, count] = format.split("x");
|
|
2358
|
-
const type = type_;
|
|
2359
|
-
const components = count ? parseInt(count) : 1;
|
|
2360
|
-
const decodedType = getDataTypeInfo(type);
|
|
2361
|
-
const result = {
|
|
2362
|
-
type,
|
|
2363
|
-
components,
|
|
2364
|
-
byteLength: decodedType.byteLength * components,
|
|
2365
|
-
integer: decodedType.integer,
|
|
2366
|
-
signed: decodedType.signed,
|
|
2367
|
-
normalized: decodedType.normalized
|
|
2368
|
-
};
|
|
2369
|
-
if (webglOnly) {
|
|
2370
|
-
result.webglOnly = true;
|
|
2371
|
-
}
|
|
2372
|
-
return result;
|
|
2373
|
-
}
|
|
2374
|
-
function makeVertexFormat(signedDataType, components, normalized) {
|
|
2375
|
-
const dataType = normalized ? makeNormalizedDataType(signedDataType) : signedDataType;
|
|
2376
|
-
switch (dataType) {
|
|
2377
|
-
case "unorm8":
|
|
2378
|
-
if (components === 1) {
|
|
2379
|
-
return "unorm8-webgl";
|
|
2380
|
-
}
|
|
2381
|
-
if (components === 3) {
|
|
2382
|
-
return "unorm8x3-webgl";
|
|
2383
|
-
}
|
|
2384
|
-
return `${dataType}x${components}`;
|
|
2385
|
-
case "snorm8":
|
|
2386
|
-
case "uint8":
|
|
2387
|
-
case "sint8":
|
|
2388
|
-
case "uint16":
|
|
2389
|
-
case "sint16":
|
|
2390
|
-
case "unorm16":
|
|
2391
|
-
case "snorm16":
|
|
2392
|
-
case "float16":
|
|
2393
|
-
if (components === 1 || components === 3) {
|
|
2394
|
-
throw new Error(`size: ${components}`);
|
|
2395
|
-
}
|
|
2396
|
-
return `${dataType}x${components}`;
|
|
2397
|
-
default:
|
|
2398
|
-
return components === 1 ? dataType : `${dataType}x${components}`;
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
|
-
function getVertexFormatFromAttribute(typedArray, size, normalized) {
|
|
2402
|
-
if (!size || size > 4) {
|
|
2403
|
-
throw new Error(`size ${size}`);
|
|
2404
|
-
}
|
|
2405
|
-
const components = size;
|
|
2406
|
-
const signedDataType = getDataTypeFromTypedArray(typedArray);
|
|
2407
|
-
return makeVertexFormat(signedDataType, components, normalized);
|
|
2408
|
-
}
|
|
2409
|
-
function getCompatibleVertexFormat(opts) {
|
|
2410
|
-
let vertexType;
|
|
2411
|
-
switch (opts.primitiveType) {
|
|
2412
|
-
case "f32":
|
|
2413
|
-
vertexType = "float32";
|
|
2414
|
-
break;
|
|
2415
|
-
case "i32":
|
|
2416
|
-
vertexType = "sint32";
|
|
2417
|
-
break;
|
|
2418
|
-
case "u32":
|
|
2419
|
-
vertexType = "uint32";
|
|
2420
|
-
break;
|
|
2421
|
-
case "f16":
|
|
2422
|
-
return opts.components <= 2 ? "float16x2" : "float16x4";
|
|
2423
|
-
}
|
|
2424
|
-
if (opts.components === 1) {
|
|
2425
|
-
return vertexType;
|
|
2426
|
-
}
|
|
2427
|
-
return `${vertexType}x${opts.components}`;
|
|
2428
|
-
}
|
|
2429
|
-
|
|
2430
2508
|
// dist/adapter-utils/get-attribute-from-layouts.js
|
|
2431
2509
|
function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
|
|
2432
2510
|
const attributeInfos = {};
|
|
@@ -2566,7 +2644,7 @@ var _VertexArray = class extends Resource {
|
|
|
2566
2644
|
// DEPRECATED METHODS
|
|
2567
2645
|
/** @deprecated Set constant attributes (WebGL only) */
|
|
2568
2646
|
setConstantWebGL(location, value) {
|
|
2569
|
-
|
|
2647
|
+
this.device.reportError(new Error("constant attributes not supported"), this)();
|
|
2570
2648
|
}
|
|
2571
2649
|
};
|
|
2572
2650
|
var VertexArray = _VertexArray;
|
|
@@ -2608,6 +2686,24 @@ __publicField(QuerySet, "defaultProps", {
|
|
|
2608
2686
|
count: void 0
|
|
2609
2687
|
});
|
|
2610
2688
|
|
|
2689
|
+
// dist/adapter/resources/pipeline-layout.js
|
|
2690
|
+
var _PipelineLayout = class extends Resource {
|
|
2691
|
+
get [Symbol.toStringTag]() {
|
|
2692
|
+
return "PipelineLayout";
|
|
2693
|
+
}
|
|
2694
|
+
constructor(device, props) {
|
|
2695
|
+
super(device, props, _PipelineLayout.defaultProps);
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
var PipelineLayout = _PipelineLayout;
|
|
2699
|
+
__publicField(PipelineLayout, "defaultProps", {
|
|
2700
|
+
...Resource.defaultProps,
|
|
2701
|
+
shaderLayout: {
|
|
2702
|
+
attributes: [],
|
|
2703
|
+
bindings: []
|
|
2704
|
+
}
|
|
2705
|
+
});
|
|
2706
|
+
|
|
2611
2707
|
// dist/utils/array-utils-flat.js
|
|
2612
2708
|
var arrayBuffer;
|
|
2613
2709
|
function getScratchArrayBuffer(byteLength) {
|
|
@@ -2885,31 +2981,85 @@ var UniformStore = class {
|
|
|
2885
2981
|
}
|
|
2886
2982
|
};
|
|
2887
2983
|
|
|
2888
|
-
// dist/
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2984
|
+
// dist/shadertypes/textures/pixel-utils.js
|
|
2985
|
+
function readPixel(pixelData, x, y, bitsPerChannel) {
|
|
2986
|
+
if (x < 0 || x >= pixelData.width || y < 0 || y >= pixelData.height) {
|
|
2987
|
+
throw new Error("Coordinates out of bounds.");
|
|
2988
|
+
}
|
|
2989
|
+
const byteOffset = y * pixelData.bytesPerRow + x * pixelData.bytesPerPixel;
|
|
2990
|
+
const pixelDataView = new DataView(pixelData.arrayBuffer, byteOffset, pixelData.bytesPerPixel);
|
|
2991
|
+
let bitOffsetWithinPixel = 0;
|
|
2992
|
+
const channels = [];
|
|
2993
|
+
for (let i = 0; i < 4; i++) {
|
|
2994
|
+
const bits = bitsPerChannel[i];
|
|
2995
|
+
if (bits <= 0) {
|
|
2996
|
+
channels.push(0);
|
|
2997
|
+
} else {
|
|
2998
|
+
const channelValue = readBitsFromDataView(pixelDataView, bitOffsetWithinPixel, bits);
|
|
2999
|
+
channels.push(channelValue);
|
|
3000
|
+
bitOffsetWithinPixel += bits;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
return [channels[0], channels[1], channels[2], channels[3]];
|
|
3004
|
+
}
|
|
3005
|
+
function writePixel(dataView, bitOffset, bitsPerChannel, pixel) {
|
|
3006
|
+
let currentBitOffset = bitOffset;
|
|
3007
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
3008
|
+
const bits = bitsPerChannel[channel];
|
|
3009
|
+
const maxValue = (1 << bits) - 1;
|
|
3010
|
+
const channelValue = pixel[channel] & maxValue;
|
|
3011
|
+
writeBitsToDataView(dataView, currentBitOffset, bits, channelValue);
|
|
3012
|
+
currentBitOffset += bits;
|
|
2893
3013
|
}
|
|
2894
|
-
|
|
2895
|
-
|
|
3014
|
+
}
|
|
3015
|
+
function readBitsFromDataView(dataView, bitOffset, bitCount) {
|
|
3016
|
+
if (bitOffset % 8 === 0) {
|
|
3017
|
+
const byteOffset = bitOffset / 8;
|
|
3018
|
+
if (bitCount === 8 && byteOffset + 1 <= dataView.byteLength) {
|
|
3019
|
+
return dataView.getUint8(byteOffset);
|
|
3020
|
+
} else if (bitCount === 16 && byteOffset + 2 <= dataView.byteLength) {
|
|
3021
|
+
return dataView.getUint16(byteOffset, false);
|
|
3022
|
+
} else if (bitCount === 32 && byteOffset + 4 <= dataView.byteLength) {
|
|
3023
|
+
return dataView.getUint32(byteOffset, false);
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
let value = 0;
|
|
3027
|
+
for (let i = 0; i < bitCount; i++) {
|
|
3028
|
+
const overallBitIndex = bitOffset + i;
|
|
3029
|
+
const byteIndex = Math.floor(overallBitIndex / 8);
|
|
3030
|
+
const bitIndex = overallBitIndex % 8;
|
|
3031
|
+
const byteValue = dataView.getUint8(byteIndex);
|
|
3032
|
+
const bit = byteValue >> 7 - bitIndex & 1;
|
|
3033
|
+
value = value << 1 | bit;
|
|
2896
3034
|
}
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
3035
|
+
return value;
|
|
3036
|
+
}
|
|
3037
|
+
function writeBitsToDataView(dataView, bitOffset, bitCount, value) {
|
|
3038
|
+
if (bitOffset % 8 === 0) {
|
|
3039
|
+
const byteOffset = bitOffset / 8;
|
|
3040
|
+
if (bitCount === 8 && byteOffset + 1 <= dataView.byteLength) {
|
|
3041
|
+
dataView.setUint8(byteOffset, value & 255);
|
|
3042
|
+
return;
|
|
3043
|
+
} else if (bitCount === 16 && byteOffset + 2 <= dataView.byteLength) {
|
|
3044
|
+
dataView.setUint16(byteOffset, value & 65535, false);
|
|
3045
|
+
return;
|
|
3046
|
+
} else if (bitCount === 32 && byteOffset + 4 <= dataView.byteLength) {
|
|
3047
|
+
dataView.setUint32(byteOffset, value, false);
|
|
3048
|
+
return;
|
|
2911
3049
|
}
|
|
2912
|
-
return mergedLayouts;
|
|
2913
3050
|
}
|
|
2914
|
-
|
|
3051
|
+
for (let i = 0; i < bitCount; i++) {
|
|
3052
|
+
const overallBitIndex = bitOffset + i;
|
|
3053
|
+
const byteIndex = Math.floor(overallBitIndex / 8);
|
|
3054
|
+
const bitIndex = overallBitIndex % 8;
|
|
3055
|
+
const mask = 1 << 7 - bitIndex;
|
|
3056
|
+
const bitValue = value >> bitCount - 1 - i & 1;
|
|
3057
|
+
let currentByte = dataView.getUint8(byteIndex);
|
|
3058
|
+
currentByte &= ~mask;
|
|
3059
|
+
if (bitValue) {
|
|
3060
|
+
currentByte |= mask;
|
|
3061
|
+
}
|
|
3062
|
+
dataView.setUint8(byteIndex, currentByte);
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
2915
3065
|
//# sourceMappingURL=index.cjs.map
|