@luma.gl/core 9.2.0-alpha.1 → 9.2.0-alpha.5
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 +19 -5
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +53 -3
- 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 +430 -274
- package/dist/dist.min.js +5 -4
- package/dist/index.cjs +426 -273
- 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 +3 -3
- package/dist/portable/uniform-buffer-layout.d.ts.map +1 -1
- package/dist/portable/uniform-buffer-layout.js +8 -9
- package/dist/portable/uniform-buffer-layout.js.map +1 -1
- package/dist/portable/uniform-store.d.ts +2 -1
- package/dist/portable/uniform-store.d.ts.map +1 -1
- package/dist/portable/uniform-store.js +1 -1
- package/dist/portable/uniform-store.js.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 +66 -8
- 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 +13 -12
- package/src/portable/uniform-store.ts +6 -2
- 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.5" : "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
|
|
@@ -1379,7 +1505,10 @@ var _CanvasContext = class {
|
|
|
1379
1505
|
this.devicePixelWidth = Math.max(1, Math.min(devicePixelWidth, maxDevicePixelWidth));
|
|
1380
1506
|
this.devicePixelHeight = Math.max(1, Math.min(devicePixelHeight, maxDevicePixelHeight));
|
|
1381
1507
|
if (this.props.autoResize) {
|
|
1382
|
-
if (this.props.useDevicePixels) {
|
|
1508
|
+
if (typeof this.props.useDevicePixels === "number") {
|
|
1509
|
+
const dpr = this.props.useDevicePixels;
|
|
1510
|
+
this.setDrawingBufferSize(this.cssWidth * dpr, this.cssHeight * dpr);
|
|
1511
|
+
} else if (this.props.useDevicePixels) {
|
|
1383
1512
|
this.setDrawingBufferSize(this.devicePixelWidth, this.devicePixelHeight);
|
|
1384
1513
|
} else {
|
|
1385
1514
|
this.setDrawingBufferSize(this.cssWidth, this.cssHeight);
|
|
@@ -1388,15 +1517,46 @@ var _CanvasContext = class {
|
|
|
1388
1517
|
}
|
|
1389
1518
|
this._initializedResolvers.resolve();
|
|
1390
1519
|
this.isInitialized = true;
|
|
1520
|
+
this.updatePosition();
|
|
1391
1521
|
this.device.props.onResize(this, { oldPixelSize });
|
|
1392
1522
|
}
|
|
1393
1523
|
/** Monitor DPR changes */
|
|
1394
1524
|
_observeDevicePixelRatio() {
|
|
1395
1525
|
const oldRatio = this.devicePixelRatio;
|
|
1396
1526
|
this.devicePixelRatio = window.devicePixelRatio;
|
|
1527
|
+
this.updatePosition();
|
|
1397
1528
|
this.device.props.onDevicePixelRatioChange(this, { oldRatio });
|
|
1398
1529
|
matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change", () => this._observeDevicePixelRatio(), { once: true });
|
|
1399
1530
|
}
|
|
1531
|
+
/** Start tracking positions with a timer */
|
|
1532
|
+
_trackPosition(intervalMs = 100) {
|
|
1533
|
+
const intervalId = setInterval(() => {
|
|
1534
|
+
if (this.destroyed) {
|
|
1535
|
+
clearInterval(intervalId);
|
|
1536
|
+
} else {
|
|
1537
|
+
this.updatePosition();
|
|
1538
|
+
}
|
|
1539
|
+
}, intervalMs);
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Calculated the absolute position of the canvas
|
|
1543
|
+
* @note - getBoundingClientRect() is normally cheap but can be expensive
|
|
1544
|
+
* if called before browser has finished a reflow. Should not be the case here.
|
|
1545
|
+
*/
|
|
1546
|
+
updatePosition() {
|
|
1547
|
+
var _a, _b, _c;
|
|
1548
|
+
const newRect = (_a = this.htmlCanvas) == null ? void 0 : _a.getBoundingClientRect();
|
|
1549
|
+
if (newRect) {
|
|
1550
|
+
const position = [newRect.left, newRect.top];
|
|
1551
|
+
this._position ??= position;
|
|
1552
|
+
const positionChanged = position[0] !== this._position[0] || position[1] !== this._position[1];
|
|
1553
|
+
if (positionChanged) {
|
|
1554
|
+
const oldPosition = this._position;
|
|
1555
|
+
this._position = position;
|
|
1556
|
+
(_c = (_b = this.device.props).onPositionChange) == null ? void 0 : _c.call(_b, this, { oldPosition });
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1400
1560
|
};
|
|
1401
1561
|
var CanvasContext = _CanvasContext;
|
|
1402
1562
|
__publicField(CanvasContext, "defaultProps", {
|
|
@@ -1409,7 +1569,8 @@ __publicField(CanvasContext, "defaultProps", {
|
|
|
1409
1569
|
container: null,
|
|
1410
1570
|
visible: true,
|
|
1411
1571
|
alphaMode: "opaque",
|
|
1412
|
-
colorSpace: "srgb"
|
|
1572
|
+
colorSpace: "srgb",
|
|
1573
|
+
trackPosition: false
|
|
1413
1574
|
});
|
|
1414
1575
|
function getContainer(container) {
|
|
1415
1576
|
if (typeof container === "string") {
|
|
@@ -2194,7 +2355,7 @@ __publicField(CommandBuffer, "defaultProps", {
|
|
|
2194
2355
|
...Resource.defaultProps
|
|
2195
2356
|
});
|
|
2196
2357
|
|
|
2197
|
-
// dist/shadertypes/
|
|
2358
|
+
// dist/shadertypes/data-types/decode-shader-types.js
|
|
2198
2359
|
function getVariableShaderTypeInfo(format) {
|
|
2199
2360
|
const decoded = UNIFORM_FORMATS[format];
|
|
2200
2361
|
return decoded;
|
|
@@ -2347,86 +2508,6 @@ var WGSL_VARIABLE_TYPE_ALIAS_MAP = {
|
|
|
2347
2508
|
mat4x4h: "mat4x4<f16>"
|
|
2348
2509
|
};
|
|
2349
2510
|
|
|
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
2511
|
// dist/adapter-utils/get-attribute-from-layouts.js
|
|
2431
2512
|
function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
|
|
2432
2513
|
const attributeInfos = {};
|
|
@@ -2566,7 +2647,7 @@ var _VertexArray = class extends Resource {
|
|
|
2566
2647
|
// DEPRECATED METHODS
|
|
2567
2648
|
/** @deprecated Set constant attributes (WebGL only) */
|
|
2568
2649
|
setConstantWebGL(location, value) {
|
|
2569
|
-
|
|
2650
|
+
this.device.reportError(new Error("constant attributes not supported"), this)();
|
|
2570
2651
|
}
|
|
2571
2652
|
};
|
|
2572
2653
|
var VertexArray = _VertexArray;
|
|
@@ -2608,6 +2689,24 @@ __publicField(QuerySet, "defaultProps", {
|
|
|
2608
2689
|
count: void 0
|
|
2609
2690
|
});
|
|
2610
2691
|
|
|
2692
|
+
// dist/adapter/resources/pipeline-layout.js
|
|
2693
|
+
var _PipelineLayout = class extends Resource {
|
|
2694
|
+
get [Symbol.toStringTag]() {
|
|
2695
|
+
return "PipelineLayout";
|
|
2696
|
+
}
|
|
2697
|
+
constructor(device, props) {
|
|
2698
|
+
super(device, props, _PipelineLayout.defaultProps);
|
|
2699
|
+
}
|
|
2700
|
+
};
|
|
2701
|
+
var PipelineLayout = _PipelineLayout;
|
|
2702
|
+
__publicField(PipelineLayout, "defaultProps", {
|
|
2703
|
+
...Resource.defaultProps,
|
|
2704
|
+
shaderLayout: {
|
|
2705
|
+
attributes: [],
|
|
2706
|
+
bindings: []
|
|
2707
|
+
}
|
|
2708
|
+
});
|
|
2709
|
+
|
|
2611
2710
|
// dist/utils/array-utils-flat.js
|
|
2612
2711
|
var arrayBuffer;
|
|
2613
2712
|
function getScratchArrayBuffer(byteLength) {
|
|
@@ -2639,11 +2738,12 @@ var UniformBufferLayout = class {
|
|
|
2639
2738
|
/** number of bytes needed for buffer allocation */
|
|
2640
2739
|
byteLength;
|
|
2641
2740
|
/** Create a new UniformBufferLayout given a map of attributes. */
|
|
2642
|
-
constructor(uniformTypes) {
|
|
2741
|
+
constructor(uniformTypes, uniformSizes = {}) {
|
|
2643
2742
|
let size = 0;
|
|
2644
2743
|
for (const [key, uniformType] of Object.entries(uniformTypes)) {
|
|
2645
2744
|
const typeAndComponents = getVariableShaderTypeInfo(uniformType);
|
|
2646
|
-
const { type, components
|
|
2745
|
+
const { type, components } = typeAndComponents;
|
|
2746
|
+
const count = components * ((uniformSizes == null ? void 0 : uniformSizes[key]) ?? 1);
|
|
2647
2747
|
size = alignTo(size, count);
|
|
2648
2748
|
const offset = size;
|
|
2649
2749
|
size += count;
|
|
@@ -2655,8 +2755,7 @@ var UniformBufferLayout = class {
|
|
|
2655
2755
|
}
|
|
2656
2756
|
/** Get the data for the complete buffer */
|
|
2657
2757
|
getData(uniformValues) {
|
|
2658
|
-
const
|
|
2659
|
-
const arrayBuffer2 = getScratchArrayBuffer(bufferSize);
|
|
2758
|
+
const arrayBuffer2 = getScratchArrayBuffer(this.byteLength);
|
|
2660
2759
|
const typedArrays = {
|
|
2661
2760
|
i32: new Int32Array(arrayBuffer2),
|
|
2662
2761
|
u32: new Uint32Array(arrayBuffer2),
|
|
@@ -2686,7 +2785,7 @@ var UniformBufferLayout = class {
|
|
|
2686
2785
|
typedArray.set(value, offset);
|
|
2687
2786
|
}
|
|
2688
2787
|
}
|
|
2689
|
-
return new Uint8Array(arrayBuffer2);
|
|
2788
|
+
return new Uint8Array(arrayBuffer2, 0, this.byteLength);
|
|
2690
2789
|
}
|
|
2691
2790
|
/** Does this layout have a field with specified name */
|
|
2692
2791
|
has(name2) {
|
|
@@ -2791,7 +2890,7 @@ var UniformStore = class {
|
|
|
2791
2890
|
constructor(blocks) {
|
|
2792
2891
|
for (const [bufferName, block] of Object.entries(blocks)) {
|
|
2793
2892
|
const uniformBufferName = bufferName;
|
|
2794
|
-
const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes
|
|
2893
|
+
const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes ?? {}, block.uniformSizes ?? {});
|
|
2795
2894
|
this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
|
|
2796
2895
|
const uniformBlock = new UniformBlock({ name: bufferName });
|
|
2797
2896
|
uniformBlock.setUniforms(block.defaultUniforms || {});
|
|
@@ -2885,31 +2984,85 @@ var UniformStore = class {
|
|
|
2885
2984
|
}
|
|
2886
2985
|
};
|
|
2887
2986
|
|
|
2888
|
-
// dist/
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2987
|
+
// dist/shadertypes/textures/pixel-utils.js
|
|
2988
|
+
function readPixel(pixelData, x, y, bitsPerChannel) {
|
|
2989
|
+
if (x < 0 || x >= pixelData.width || y < 0 || y >= pixelData.height) {
|
|
2990
|
+
throw new Error("Coordinates out of bounds.");
|
|
2991
|
+
}
|
|
2992
|
+
const byteOffset = y * pixelData.bytesPerRow + x * pixelData.bytesPerPixel;
|
|
2993
|
+
const pixelDataView = new DataView(pixelData.arrayBuffer, byteOffset, pixelData.bytesPerPixel);
|
|
2994
|
+
let bitOffsetWithinPixel = 0;
|
|
2995
|
+
const channels = [];
|
|
2996
|
+
for (let i = 0; i < 4; i++) {
|
|
2997
|
+
const bits = bitsPerChannel[i];
|
|
2998
|
+
if (bits <= 0) {
|
|
2999
|
+
channels.push(0);
|
|
3000
|
+
} else {
|
|
3001
|
+
const channelValue = readBitsFromDataView(pixelDataView, bitOffsetWithinPixel, bits);
|
|
3002
|
+
channels.push(channelValue);
|
|
3003
|
+
bitOffsetWithinPixel += bits;
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
return [channels[0], channels[1], channels[2], channels[3]];
|
|
3007
|
+
}
|
|
3008
|
+
function writePixel(dataView, bitOffset, bitsPerChannel, pixel) {
|
|
3009
|
+
let currentBitOffset = bitOffset;
|
|
3010
|
+
for (let channel = 0; channel < 4; channel++) {
|
|
3011
|
+
const bits = bitsPerChannel[channel];
|
|
3012
|
+
const maxValue = (1 << bits) - 1;
|
|
3013
|
+
const channelValue = pixel[channel] & maxValue;
|
|
3014
|
+
writeBitsToDataView(dataView, currentBitOffset, bits, channelValue);
|
|
3015
|
+
currentBitOffset += bits;
|
|
2893
3016
|
}
|
|
2894
|
-
|
|
2895
|
-
|
|
3017
|
+
}
|
|
3018
|
+
function readBitsFromDataView(dataView, bitOffset, bitCount) {
|
|
3019
|
+
if (bitOffset % 8 === 0) {
|
|
3020
|
+
const byteOffset = bitOffset / 8;
|
|
3021
|
+
if (bitCount === 8 && byteOffset + 1 <= dataView.byteLength) {
|
|
3022
|
+
return dataView.getUint8(byteOffset);
|
|
3023
|
+
} else if (bitCount === 16 && byteOffset + 2 <= dataView.byteLength) {
|
|
3024
|
+
return dataView.getUint16(byteOffset, false);
|
|
3025
|
+
} else if (bitCount === 32 && byteOffset + 4 <= dataView.byteLength) {
|
|
3026
|
+
return dataView.getUint32(byteOffset, false);
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
let value = 0;
|
|
3030
|
+
for (let i = 0; i < bitCount; i++) {
|
|
3031
|
+
const overallBitIndex = bitOffset + i;
|
|
3032
|
+
const byteIndex = Math.floor(overallBitIndex / 8);
|
|
3033
|
+
const bitIndex = overallBitIndex % 8;
|
|
3034
|
+
const byteValue = dataView.getUint8(byteIndex);
|
|
3035
|
+
const bit = byteValue >> 7 - bitIndex & 1;
|
|
3036
|
+
value = value << 1 | bit;
|
|
2896
3037
|
}
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
3038
|
+
return value;
|
|
3039
|
+
}
|
|
3040
|
+
function writeBitsToDataView(dataView, bitOffset, bitCount, value) {
|
|
3041
|
+
if (bitOffset % 8 === 0) {
|
|
3042
|
+
const byteOffset = bitOffset / 8;
|
|
3043
|
+
if (bitCount === 8 && byteOffset + 1 <= dataView.byteLength) {
|
|
3044
|
+
dataView.setUint8(byteOffset, value & 255);
|
|
3045
|
+
return;
|
|
3046
|
+
} else if (bitCount === 16 && byteOffset + 2 <= dataView.byteLength) {
|
|
3047
|
+
dataView.setUint16(byteOffset, value & 65535, false);
|
|
3048
|
+
return;
|
|
3049
|
+
} else if (bitCount === 32 && byteOffset + 4 <= dataView.byteLength) {
|
|
3050
|
+
dataView.setUint32(byteOffset, value, false);
|
|
3051
|
+
return;
|
|
2911
3052
|
}
|
|
2912
|
-
return mergedLayouts;
|
|
2913
3053
|
}
|
|
2914
|
-
|
|
3054
|
+
for (let i = 0; i < bitCount; i++) {
|
|
3055
|
+
const overallBitIndex = bitOffset + i;
|
|
3056
|
+
const byteIndex = Math.floor(overallBitIndex / 8);
|
|
3057
|
+
const bitIndex = overallBitIndex % 8;
|
|
3058
|
+
const mask = 1 << 7 - bitIndex;
|
|
3059
|
+
const bitValue = value >> bitCount - 1 - i & 1;
|
|
3060
|
+
let currentByte = dataView.getUint8(byteIndex);
|
|
3061
|
+
currentByte &= ~mask;
|
|
3062
|
+
if (bitValue) {
|
|
3063
|
+
currentByte |= mask;
|
|
3064
|
+
}
|
|
3065
|
+
dataView.setUint8(byteIndex, currentByte);
|
|
3066
|
+
}
|
|
3067
|
+
}
|
|
2915
3068
|
//# sourceMappingURL=index.cjs.map
|