@luma.gl/core 9.0.0-alpha.9 → 9.0.0-beta.2
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/LICENSE +3 -1
- package/README.md +4 -4
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts +52 -0
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +1 -0
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +130 -0
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +1 -0
- package/dist/adapter/canvas-context.d.ts +109 -0
- package/dist/adapter/canvas-context.d.ts.map +1 -0
- package/dist/adapter/canvas-context.js +254 -0
- package/dist/adapter/canvas-context.js.map +1 -0
- package/dist/adapter/device.d.ts +219 -0
- package/dist/adapter/device.d.ts.map +1 -0
- package/dist/adapter/device.js +99 -0
- package/dist/adapter/device.js.map +1 -0
- package/dist/adapter/resources/buffer.d.ts +56 -0
- package/dist/adapter/resources/buffer.d.ts.map +1 -0
- package/dist/adapter/resources/buffer.js +62 -0
- package/dist/adapter/resources/buffer.js.map +1 -0
- package/dist/adapter/resources/command-buffer.d.ts +12 -0
- package/dist/adapter/resources/command-buffer.d.ts.map +1 -0
- package/dist/adapter/resources/command-buffer.js +15 -0
- package/dist/adapter/resources/command-buffer.js.map +1 -0
- package/dist/adapter/resources/command-encoder.d.ts +113 -0
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -0
- package/dist/adapter/resources/command-encoder.js +19 -0
- package/dist/adapter/resources/command-encoder.js.map +1 -0
- package/dist/adapter/resources/compute-pass.d.ts +31 -0
- package/dist/adapter/resources/compute-pass.d.ts.map +1 -0
- package/dist/adapter/resources/compute-pass.js +15 -0
- package/dist/adapter/resources/compute-pass.js.map +1 -0
- package/dist/adapter/resources/compute-pipeline.d.ts +24 -0
- package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/compute-pipeline.js +20 -0
- package/dist/adapter/resources/compute-pipeline.js.map +1 -0
- package/dist/adapter/resources/external-texture.d.ts +12 -0
- package/dist/adapter/resources/external-texture.d.ts.map +1 -0
- package/dist/adapter/resources/external-texture.js +17 -0
- package/dist/adapter/resources/external-texture.js.map +1 -0
- package/dist/adapter/resources/framebuffer.d.ts +50 -0
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -0
- package/dist/adapter/resources/framebuffer.js +102 -0
- package/dist/adapter/resources/framebuffer.js.map +1 -0
- package/dist/adapter/resources/render-pass.d.ts +51 -0
- package/dist/adapter/resources/render-pass.d.ts.map +1 -0
- package/dist/adapter/resources/render-pass.js +23 -0
- package/dist/adapter/resources/render-pass.js.map +1 -0
- package/dist/adapter/resources/render-pipeline.d.ts +89 -0
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -0
- package/dist/adapter/resources/render-pipeline.js +36 -0
- package/dist/adapter/resources/render-pipeline.js.map +1 -0
- package/dist/adapter/resources/resource.d.ts +73 -0
- package/dist/adapter/resources/resource.d.ts.map +1 -0
- package/dist/adapter/resources/resource.js +101 -0
- package/dist/adapter/resources/resource.js.map +1 -0
- package/dist/adapter/resources/sampler.d.ts +42 -0
- package/dist/adapter/resources/sampler.d.ts.map +1 -0
- package/dist/adapter/resources/sampler.js +26 -0
- package/dist/adapter/resources/sampler.js.map +1 -0
- package/dist/adapter/resources/shader.d.ts +45 -0
- package/dist/adapter/resources/shader.d.ts.map +1 -0
- package/dist/adapter/resources/shader.js +90 -0
- package/dist/adapter/resources/shader.js.map +1 -0
- package/dist/adapter/resources/texture.d.ts +90 -0
- package/dist/adapter/resources/texture.d.ts.map +1 -0
- package/dist/adapter/resources/texture.js +45 -0
- package/dist/adapter/resources/texture.js.map +1 -0
- package/dist/adapter/resources/transform-feedback.d.ts +30 -0
- package/dist/adapter/resources/transform-feedback.d.ts.map +1 -0
- package/dist/adapter/resources/transform-feedback.js +17 -0
- package/dist/adapter/resources/transform-feedback.js.map +1 -0
- package/dist/adapter/resources/vertex-array.d.ts +40 -0
- package/dist/adapter/resources/vertex-array.d.ts.map +1 -0
- package/dist/adapter/resources/vertex-array.js +24 -0
- package/dist/adapter/resources/vertex-array.js.map +1 -0
- package/dist/adapter/type-utils/decode-attribute-type.d.ts +20 -0
- package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-attribute-type.js +60 -0
- package/dist/adapter/type-utils/decode-attribute-type.js.map +1 -0
- package/dist/adapter/type-utils/decode-data-type.d.ts +16 -0
- package/dist/adapter/type-utils/decode-data-type.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-data-type.js +43 -0
- package/dist/adapter/type-utils/decode-data-type.js.map +1 -0
- package/dist/adapter/type-utils/decode-shader-types.d.ts +9 -0
- package/dist/adapter/type-utils/decode-shader-types.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-shader-types.js +103 -0
- package/dist/adapter/type-utils/decode-shader-types.js.map +1 -0
- package/dist/adapter/type-utils/decode-texture-format.d.ts +19 -0
- package/dist/adapter/type-utils/decode-texture-format.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-texture-format.js +101 -0
- package/dist/adapter/type-utils/decode-texture-format.js.map +1 -0
- package/dist/adapter/type-utils/decode-vertex-format.d.ts +22 -0
- package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +1 -0
- package/dist/adapter/type-utils/decode-vertex-format.js +25 -0
- package/dist/adapter/type-utils/decode-vertex-format.js.map +1 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts +10 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +1 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.js +76 -0
- package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +1 -0
- package/dist/adapter/type-utils/wgsl-utils.d.ts +4 -0
- package/dist/adapter/type-utils/wgsl-utils.d.ts.map +1 -0
- package/dist/adapter/type-utils/wgsl-utils.js +15 -0
- package/dist/adapter/type-utils/wgsl-utils.js.map +1 -0
- package/dist/adapter/types/accessor.d.ts +23 -0
- package/dist/adapter/types/accessor.d.ts.map +1 -0
- package/dist/adapter/types/accessor.js +2 -0
- package/dist/adapter/types/accessor.js.map +1 -0
- package/dist/adapter/types/buffer-layout.d.ts +59 -0
- package/dist/adapter/types/buffer-layout.d.ts.map +1 -0
- package/dist/adapter/types/buffer-layout.js +2 -0
- package/dist/adapter/types/buffer-layout.js.map +1 -0
- package/dist/adapter/types/parameters.d.ts +97 -0
- package/dist/adapter/types/parameters.d.ts.map +1 -0
- package/dist/adapter/types/parameters.js +28 -0
- package/dist/adapter/types/parameters.js.map +1 -0
- package/dist/adapter/types/shader-layout.d.ts +145 -0
- package/dist/adapter/types/shader-layout.d.ts.map +1 -0
- package/dist/adapter/types/shader-layout.js +2 -0
- package/dist/adapter/types/shader-layout.js.map +1 -0
- package/dist/adapter/types/shader-types.d.ts +21 -0
- package/dist/adapter/types/shader-types.d.ts.map +1 -0
- package/dist/adapter/types/shader-types.js +2 -0
- package/dist/adapter/types/shader-types.js.map +1 -0
- package/dist/adapter/types/texture-formats.d.ts +12 -0
- package/dist/adapter/types/texture-formats.d.ts.map +1 -0
- package/dist/adapter/types/texture-formats.js +2 -0
- package/dist/adapter/types/texture-formats.js.map +1 -0
- package/dist/adapter/types/types.d.ts +90 -0
- package/dist/adapter/types/types.d.ts.map +1 -0
- package/dist/adapter/types/types.js +2 -0
- package/dist/adapter/types/types.js.map +1 -0
- package/dist/adapter/types/vertex-formats.d.ts +14 -0
- package/dist/adapter/types/vertex-formats.d.ts.map +1 -0
- package/dist/adapter/types/vertex-formats.js +2 -0
- package/dist/adapter/types/vertex-formats.js.map +1 -0
- package/dist/dist.dev.js +2976 -0
- package/dist/index.cjs +2445 -0
- package/dist/index.d.ts +81 -128
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -18
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +5 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +24 -0
- package/dist/init.js.map +1 -0
- package/dist/lib/compiler-log/compiler-message.d.ts +8 -0
- package/dist/lib/compiler-log/compiler-message.d.ts.map +1 -0
- package/dist/lib/compiler-log/compiler-message.js +2 -0
- package/dist/lib/compiler-log/compiler-message.js.map +1 -0
- package/dist/lib/compiler-log/format-compiler-log.d.ts +8 -0
- package/dist/lib/compiler-log/format-compiler-log.d.ts.map +1 -0
- package/dist/lib/compiler-log/format-compiler-log.js +64 -0
- package/dist/lib/compiler-log/format-compiler-log.js.map +1 -0
- package/dist/lib/compiler-log/get-shader-info.d.ts +9 -0
- package/dist/lib/compiler-log/get-shader-info.d.ts.map +1 -0
- package/dist/lib/compiler-log/get-shader-info.js +25 -0
- package/dist/lib/compiler-log/get-shader-info.js.map +1 -0
- package/dist/lib/luma.d.ts +22 -0
- package/dist/lib/luma.d.ts.map +1 -0
- package/dist/lib/luma.js +63 -0
- package/dist/lib/luma.js.map +1 -0
- package/dist/lib/uniforms/uniform-block.d.ts +29 -0
- package/dist/lib/uniforms/uniform-block.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform-block.js +48 -0
- package/dist/lib/uniforms/uniform-block.js.map +1 -0
- package/dist/lib/uniforms/uniform-buffer-layout.d.ts +27 -0
- package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform-buffer-layout.js +76 -0
- package/dist/lib/uniforms/uniform-buffer-layout.js.map +1 -0
- package/dist/lib/uniforms/uniform-store.d.ts +62 -0
- package/dist/lib/uniforms/uniform-store.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform-store.js +89 -0
- package/dist/lib/uniforms/uniform-store.js.map +1 -0
- package/dist/lib/uniforms/uniform.d.ts +10 -0
- package/dist/lib/uniforms/uniform.d.ts.map +1 -0
- package/dist/lib/uniforms/uniform.js +20 -0
- package/dist/lib/uniforms/uniform.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/array-equal.d.ts +5 -0
- package/dist/utils/array-equal.d.ts.map +1 -0
- package/dist/utils/array-equal.js +28 -0
- package/dist/utils/array-equal.js.map +1 -0
- package/dist/utils/array-utils-flat.d.ts +10 -0
- package/dist/utils/array-utils-flat.d.ts.map +1 -0
- package/dist/utils/array-utils-flat.js +36 -0
- package/dist/utils/array-utils-flat.js.map +1 -0
- package/dist/utils/assert.d.ts +2 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +6 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/cast.d.ts +3 -0
- package/dist/utils/cast.d.ts.map +1 -0
- package/dist/utils/cast.js +4 -0
- package/dist/utils/cast.js.map +1 -0
- package/dist/utils/check-props.d.ts +7 -0
- package/dist/utils/check-props.d.ts.map +1 -0
- package/dist/utils/check-props.js +32 -0
- package/dist/utils/check-props.js.map +1 -0
- package/dist/utils/deep-equal.d.ts +9 -0
- package/dist/utils/deep-equal.d.ts.map +1 -0
- package/dist/utils/deep-equal.js +40 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/format-value.d.ts +7 -0
- package/dist/utils/format-value.d.ts.map +1 -0
- package/dist/utils/format-value.js +42 -0
- package/dist/utils/format-value.js.map +1 -0
- package/dist/utils/is-array.d.ts +16 -0
- package/dist/utils/is-array.d.ts.map +1 -0
- package/dist/utils/is-array.js +10 -0
- package/dist/utils/is-array.js.map +1 -0
- package/dist/utils/load-file.d.ts +35 -0
- package/dist/utils/load-file.d.ts.map +1 -0
- package/dist/utils/load-file.js +48 -0
- package/dist/utils/load-file.js.map +1 -0
- package/dist/utils/log.d.ts +4 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +5 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/random.d.ts +5 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +14 -0
- package/dist/utils/random.js.map +1 -0
- package/dist/utils/request-animation-frame.d.ts +3 -0
- package/dist/utils/request-animation-frame.d.ts.map +1 -0
- package/dist/utils/request-animation-frame.js +7 -0
- package/dist/utils/request-animation-frame.js.map +1 -0
- package/dist/utils/stats-manager.d.ts +12 -0
- package/dist/utils/stats-manager.d.ts.map +1 -0
- package/dist/utils/stats-manager.js +19 -0
- package/dist/utils/stats-manager.js.map +1 -0
- package/dist/utils/stub-methods.d.ts +2 -0
- package/dist/utils/stub-methods.d.ts.map +1 -0
- package/dist/utils/stub-methods.js +16 -0
- package/dist/utils/stub-methods.js.map +1 -0
- package/dist/utils/utils.d.ts +15 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +19 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist.min.js +33 -0
- package/package.json +17 -12
- package/src/adapter/attribute-utils/get-attribute-from-layouts.ts +259 -0
- package/src/adapter/canvas-context.ts +433 -0
- package/src/adapter/device.ts +435 -0
- package/src/adapter/resources/buffer.ts +106 -0
- package/src/adapter/resources/command-buffer.ts +38 -0
- package/src/adapter/resources/command-encoder.ts +172 -0
- package/src/adapter/resources/compute-pass.ts +52 -0
- package/src/adapter/resources/compute-pipeline.ts +39 -0
- package/src/adapter/resources/external-texture.ts +20 -0
- package/src/adapter/resources/framebuffer.ts +230 -0
- package/src/adapter/resources/render-pass.ts +117 -0
- package/src/adapter/resources/render-pipeline.ts +133 -0
- package/src/adapter/resources/resource.ts +176 -0
- package/src/adapter/resources/sampler.ts +69 -0
- package/src/adapter/resources/shader.ts +143 -0
- package/src/adapter/resources/texture.ts +140 -0
- package/src/adapter/resources/transform-feedback.ts +45 -0
- package/src/adapter/resources/vertex-array.ts +65 -0
- package/src/adapter/type-utils/decode-attribute-type.ts +82 -0
- package/src/adapter/type-utils/decode-data-type.ts +62 -0
- package/src/adapter/type-utils/decode-shader-types.ts +48 -0
- package/src/adapter/type-utils/decode-texture-format.ts +190 -0
- package/src/adapter/type-utils/decode-vertex-format.ts +49 -0
- package/src/adapter/type-utils/vertex-format-from-attribute.ts +103 -0
- package/src/adapter/type-utils/wgsl-utils.ts +18 -0
- package/src/adapter/types/accessor.ts +34 -0
- package/src/adapter/types/buffer-layout.ts +62 -0
- package/src/adapter/types/parameters.ts +250 -0
- package/src/adapter/types/shader-layout.ts +193 -0
- package/src/adapter/types/shader-types.ts +77 -0
- package/src/adapter/types/texture-formats.ts +168 -0
- package/src/adapter/types/types.ts +109 -0
- package/src/adapter/types/vertex-formats.ts +91 -0
- package/src/index.ts +160 -92
- package/src/init.ts +47 -0
- package/src/lib/compiler-log/compiler-message.ts +10 -0
- package/src/lib/compiler-log/format-compiler-log.ts +113 -0
- package/src/lib/compiler-log/get-shader-info.ts +41 -0
- package/src/lib/luma.ts +84 -0
- package/src/lib/uniforms/uniform-block.ts +80 -0
- package/src/lib/uniforms/uniform-buffer-layout.ts +109 -0
- package/src/lib/uniforms/uniform-store.ts +173 -0
- package/src/lib/uniforms/uniform.ts +25 -0
- package/src/types.ts +33 -0
- package/src/utils/array-equal.ts +33 -0
- package/src/utils/array-utils-flat.ts +43 -0
- package/src/utils/assert.ts +7 -0
- package/src/utils/cast.ts +4 -0
- package/src/utils/check-props.ts +74 -0
- package/src/utils/deep-equal.ts +47 -0
- package/src/utils/format-value.ts +40 -0
- package/src/utils/is-array.ts +24 -0
- package/src/utils/load-file.ts +89 -0
- package/src/utils/log.ts +4 -0
- package/src/utils/random.ts +17 -0
- package/src/utils/request-animation-frame.ts +15 -0
- package/src/utils/stats-manager.ts +23 -0
- package/src/utils/stub-methods.ts +20 -0
- package/src/utils/utils.ts +36 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/src/bundle.ts +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"luma.d.ts","sourceRoot":"","sources":["../../src/lib/luma.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAQpD;;;;GAIG;AACH,qBAAa,IAAI;IACf,mCAAmC;IACnC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAa;IAEvC,iBAAiB;IACjB,MAAM,CAAC,GAAG,EAAE,GAAG,CAAO;IAEtB,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,GAAyB,IAAI;IAOxE,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAKtC,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAItD,wCAAwC;WAC3B,YAAY,CAAC,KAAK,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;CAmCpE"}
|
package/dist/lib/luma.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Device } from "../adapter/device.js";
|
|
2
|
+
import { lumaStats } from "../utils/stats-manager.js";
|
|
3
|
+
import { log } from "../utils/log.js";
|
|
4
|
+
import { assert } from "../utils/assert.js";
|
|
5
|
+
const deviceList = new Map();
|
|
6
|
+
export class luma {
|
|
7
|
+
static registerDevices(deviceClasses) {
|
|
8
|
+
for (const deviceClass of deviceClasses) {
|
|
9
|
+
assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);
|
|
10
|
+
deviceList.set(deviceClass.type, deviceClass);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
static getAvailableDevices() {
|
|
14
|
+
return Array.from(deviceList).map(Device => Device.type);
|
|
15
|
+
}
|
|
16
|
+
static getSupportedDevices() {
|
|
17
|
+
return Array.from(deviceList).filter(Device => Device.isSupported()).map(Device => Device.type);
|
|
18
|
+
}
|
|
19
|
+
static setDefaultDeviceProps(props) {
|
|
20
|
+
Object.assign(Device.defaultProps, props);
|
|
21
|
+
}
|
|
22
|
+
static async createDevice() {
|
|
23
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
+
props = {
|
|
25
|
+
...Device.defaultProps,
|
|
26
|
+
...props
|
|
27
|
+
};
|
|
28
|
+
if (props.gl) {
|
|
29
|
+
props.type = 'webgl';
|
|
30
|
+
}
|
|
31
|
+
let DeviceClass;
|
|
32
|
+
switch (props.type) {
|
|
33
|
+
case 'webgpu':
|
|
34
|
+
DeviceClass = deviceList.get('webgpu');
|
|
35
|
+
if (DeviceClass) {
|
|
36
|
+
return await DeviceClass.create(props);
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
case 'webgl':
|
|
40
|
+
case 'webgl1':
|
|
41
|
+
case 'webgl2':
|
|
42
|
+
DeviceClass = deviceList.get('webgl');
|
|
43
|
+
if (DeviceClass) {
|
|
44
|
+
return await DeviceClass.create(props);
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case 'best-available':
|
|
48
|
+
DeviceClass = deviceList.get('webgpu');
|
|
49
|
+
if (DeviceClass && DeviceClass.isSupported()) {
|
|
50
|
+
return await DeviceClass.create(props);
|
|
51
|
+
}
|
|
52
|
+
DeviceClass = deviceList.get('webgl');
|
|
53
|
+
if (DeviceClass && DeviceClass.isSupported()) {
|
|
54
|
+
return await DeviceClass.create(props);
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
luma.stats = lumaStats;
|
|
62
|
+
luma.log = log;
|
|
63
|
+
//# sourceMappingURL=luma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"luma.js","names":["Device","lumaStats","log","assert","deviceList","Map","luma","registerDevices","deviceClasses","deviceClass","type","isSupported","create","set","getAvailableDevices","Array","from","map","getSupportedDevices","filter","setDefaultDeviceProps","props","Object","assign","defaultProps","createDevice","arguments","length","undefined","gl","DeviceClass","get","Error","stats"],"sources":["../../src/lib/luma.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {Log} from '@probe.gl/log';\nimport type {DeviceProps} from '../adapter/device';\nimport {Device} from '../adapter/device';\nimport {StatsManager} from '../utils/stats-manager';\nimport {lumaStats} from '../utils/stats-manager';\nimport {log} from '../utils/log';\nimport {assert} from '../utils/assert';\n\n\nconst deviceList = new Map<string, typeof Device>();\n\n/**\n * Entry point to the luma.gl GPU abstraction\n * Register WebGPU and/or WebGL devices (controls application bundle size)\n * Run-time selection of the first available Device\n */\nexport class luma {\n /** Global stats for all devices */\n static stats: StatsManager = lumaStats;\n\n /** Global log */\n static log: Log = log;\n\n static registerDevices(deviceClasses: any[] /* : typeof Device */): void {\n for (const deviceClass of deviceClasses) {\n assert(deviceClass.type && deviceClass.isSupported && deviceClass.create);\n deviceList.set(deviceClass.type, deviceClass);\n }\n }\n\n static getAvailableDevices(): string[] {\n // @ts-expect-error\n return Array.from(deviceList).map(Device => Device.type);\n }\n\n static getSupportedDevices(): string[] {\n // @ts-expect-error\n return Array.from(deviceList).filter(Device => Device.isSupported()).map(Device => Device.type);\n }\n\n static setDefaultDeviceProps(props: DeviceProps): void {\n Object.assign(Device.defaultProps, props);\n }\n\n /** Creates a device. Asynchronously. */\n static async createDevice(props: DeviceProps = {}): Promise<Device> {\n props = {...Device.defaultProps, ...props}\n if (props.gl) {\n props.type = 'webgl';\n }\n\n let DeviceClass: any;\n switch (props.type) {\n case 'webgpu':\n DeviceClass = deviceList.get('webgpu');\n if (DeviceClass) {\n return await DeviceClass.create(props);\n }\n break;\n case 'webgl':\n case 'webgl1':\n case 'webgl2':\n DeviceClass = deviceList.get('webgl');\n if (DeviceClass) {\n return await DeviceClass.create(props);\n }\n break;\n case 'best-available':\n DeviceClass = deviceList.get('webgpu');\n if (DeviceClass && DeviceClass.isSupported()) {\n return await DeviceClass.create(props);\n }\n DeviceClass = deviceList.get('webgl');\n if (DeviceClass && DeviceClass.isSupported()) {\n return await DeviceClass.create(props);\n }\n break;\n }\n throw new Error('No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.');\n }\n}\n"],"mappings":"SAKQA,MAAM;AAAA,SAENC,SAAS;AAAA,SACTC,GAAG;AAAA,SACHC,MAAM;AAGd,MAAMC,UAAU,GAAG,IAAIC,GAAG,CAAwB,CAAC;AAOnD,OAAO,MAAMC,IAAI,CAAC;EAOhB,OAAOC,eAAeA,CAACC,aAAoB,EAA8B;IACvE,KAAK,MAAMC,WAAW,IAAID,aAAa,EAAE;MACvCL,MAAM,CAACM,WAAW,CAACC,IAAI,IAAID,WAAW,CAACE,WAAW,IAAIF,WAAW,CAACG,MAAM,CAAC;MACzER,UAAU,CAACS,GAAG,CAACJ,WAAW,CAACC,IAAI,EAAED,WAAW,CAAC;IAC/C;EACF;EAEA,OAAOK,mBAAmBA,CAAA,EAAa;IAErC,OAAOC,KAAK,CAACC,IAAI,CAACZ,UAAU,CAAC,CAACa,GAAG,CAACjB,MAAM,IAAIA,MAAM,CAACU,IAAI,CAAC;EAC1D;EAEA,OAAOQ,mBAAmBA,CAAA,EAAa;IAErC,OAAOH,KAAK,CAACC,IAAI,CAACZ,UAAU,CAAC,CAACe,MAAM,CAACnB,MAAM,IAAIA,MAAM,CAACW,WAAW,CAAC,CAAC,CAAC,CAACM,GAAG,CAACjB,MAAM,IAAIA,MAAM,CAACU,IAAI,CAAC;EACjG;EAEA,OAAOU,qBAAqBA,CAACC,KAAkB,EAAQ;IACrDC,MAAM,CAACC,MAAM,CAACvB,MAAM,CAACwB,YAAY,EAAEH,KAAK,CAAC;EAC3C;EAGA,aAAaI,YAAYA,CAAA,EAA2C;IAAA,IAA1CJ,KAAkB,GAAAK,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAA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ter/types/shader-types';
|
|
2
|
+
import type { UniformValue } from '../../adapter/types/types';
|
|
3
|
+
import { ShaderLayout, UniformInfo } from '../../adapter/types/shader-layout';
|
|
4
|
+
/**
|
|
5
|
+
* A uniform block holds values of the of uniform values for one uniform block / buffer.
|
|
6
|
+
* It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.
|
|
7
|
+
* @todo - Track changes to individual uniforms (for WebGL1)
|
|
8
|
+
*/
|
|
9
|
+
export declare class UniformBlock<TUniforms extends Record<string, UniformValue> = Record<string, UniformValue>> {
|
|
10
|
+
name: string;
|
|
11
|
+
uniforms: Record<keyof TUniforms, UniformValue>;
|
|
12
|
+
modifiedUniforms: Record<keyof TUniforms, boolean>;
|
|
13
|
+
modified: boolean;
|
|
14
|
+
readonly bindingLayout: Record<string, UniformInfo>;
|
|
15
|
+
needsRedraw: string | false;
|
|
16
|
+
constructor(props?: {
|
|
17
|
+
name?: string;
|
|
18
|
+
shaderLayout?: ShaderLayout;
|
|
19
|
+
uniformTypes?: Record<keyof TUniforms, Record<string, ShaderUniformType>>;
|
|
20
|
+
});
|
|
21
|
+
/** Set a map of uniforms */
|
|
22
|
+
setUniforms(uniforms: Partial<TUniforms>): void;
|
|
23
|
+
setNeedsRedraw(reason: string): void;
|
|
24
|
+
/** Returns all uniforms */
|
|
25
|
+
getAllUniforms(): Record<string, UniformValue>;
|
|
26
|
+
/** Set a single uniform */
|
|
27
|
+
private _setUniform;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=uniform-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-block.d.ts","sourceRoot":"","sources":["../../../src/lib/uniforms/uniform-block.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,WAAW,EAEZ,MAAM,mCAAmC,CAAC;AAG3C;;;;GAIG;AACH,qBAAa,YAAY,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IACrG,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,YAAY,CAAC,CAA+C;IAC9F,gBAAgB,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,OAAO,CAAC,CAA0C;IAC5F,QAAQ,EAAE,OAAO,CAAQ;IAEzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAM;IACzD,WAAW,EAAE,MAAM,GAAG,KAAK,CAAiB;gBAEhC,KAAK,CAAC,EAAE;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,YAAY,CAAC;QAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;KAC3E;IAmBD,4BAA4B;IAC5B,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAS/C,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIpC,2BAA2B;IAC3B,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC;IAO9C,2BAA2B;IAC3B,OAAO,CAAC,WAAW;CAQpB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { arrayEqual, arrayCopy } from "../../utils/array-equal.js";
|
|
2
|
+
export class UniformBlock {
|
|
3
|
+
constructor(props) {
|
|
4
|
+
this.name = void 0;
|
|
5
|
+
this.uniforms = {};
|
|
6
|
+
this.modifiedUniforms = {};
|
|
7
|
+
this.modified = true;
|
|
8
|
+
this.bindingLayout = {};
|
|
9
|
+
this.needsRedraw = 'initialized';
|
|
10
|
+
this.name = props === null || props === void 0 ? void 0 : props.name;
|
|
11
|
+
if (props !== null && props !== void 0 && props.name && props !== null && props !== void 0 && props.shaderLayout) {
|
|
12
|
+
var _props$shaderLayout$b;
|
|
13
|
+
const binding = props === null || props === void 0 || (_props$shaderLayout$b = props.shaderLayout.bindings) === null || _props$shaderLayout$b === void 0 ? void 0 : _props$shaderLayout$b.find(binding => binding.type === 'uniform' && binding.name === (props === null || props === void 0 ? void 0 : props.name));
|
|
14
|
+
if (!binding) {
|
|
15
|
+
throw new Error(props === null || props === void 0 ? void 0 : props.name);
|
|
16
|
+
}
|
|
17
|
+
const uniformBlock = binding;
|
|
18
|
+
for (const uniform of uniformBlock.uniforms || []) {
|
|
19
|
+
this.bindingLayout[uniform.name] = uniform;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
setUniforms(uniforms) {
|
|
24
|
+
for (const [key, value] of Object.entries(uniforms)) {
|
|
25
|
+
this._setUniform(key, value);
|
|
26
|
+
if (!this.needsRedraw) {
|
|
27
|
+
this.setNeedsRedraw(`${this.name}.${key}=${value}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
setNeedsRedraw(reason) {
|
|
32
|
+
this.needsRedraw = this.needsRedraw || reason;
|
|
33
|
+
}
|
|
34
|
+
getAllUniforms() {
|
|
35
|
+
this.modifiedUniforms = {};
|
|
36
|
+
this.needsRedraw = false;
|
|
37
|
+
return this.uniforms || {};
|
|
38
|
+
}
|
|
39
|
+
_setUniform(key, value) {
|
|
40
|
+
if (arrayEqual(this.uniforms[key], value)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.uniforms[key] = arrayCopy(value);
|
|
44
|
+
this.modifiedUniforms[key] = true;
|
|
45
|
+
this.modified = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=uniform-block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-block.js","names":["arrayEqual","arrayCopy","UniformBlock","constructor","props","name","uniforms","modifiedUniforms","modified","bindingLayout","needsRedraw","shaderLayout","_props$shaderLayout$b","binding","bindings","find","type","Error","uniformBlock","uniform","setUniforms","key","value","Object","entries","_setUniform","setNeedsRedraw","reason","getAllUniforms"],"sources":["../../../src/lib/uniforms/uniform-block.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {ShaderUniformType} from '../../adapter/types/shader-types';\nimport type {UniformValue} from '../../adapter/types/types';\nimport {\n ShaderLayout,\n UniformInfo,\n UniformBufferBindingLayout\n} from '../../adapter/types/shader-layout';\nimport {arrayEqual, arrayCopy} from '../../utils/array-equal';\n\n/**\n * A uniform block holds values of the of uniform values for one uniform block / buffer.\n * It also does some book keeping on what has changed, to minimize unnecessary writes to uniform buffers.\n * @todo - Track changes to individual uniforms (for WebGL1)\n */\nexport class UniformBlock<TUniforms extends Record<string, UniformValue> = Record<string, UniformValue>> {\n name: string;\n\n uniforms: Record<keyof TUniforms, UniformValue> = {} as Record<keyof TUniforms, UniformValue>;\n modifiedUniforms: Record<keyof TUniforms, boolean> = {} as Record<keyof TUniforms, boolean>;\n modified: boolean = true;\n\n readonly bindingLayout: Record<string, UniformInfo> = {};\n needsRedraw: string | false = 'initialized';\n\n constructor(props?: {\n name?: string;\n shaderLayout?: ShaderLayout;\n uniformTypes?: Record<keyof TUniforms, Record<string, ShaderUniformType>>;\n }) {\n this.name = props?.name;\n\n // TODO - Extract uniform layout from the shaderLayout object\n if (props?.name && props?.shaderLayout) {\n const binding = props?.shaderLayout.bindings?.find(\n binding => binding.type === 'uniform' && binding.name === props?.name\n );\n if (!binding) {\n throw new Error(props?.name);\n }\n\n const uniformBlock = binding as UniformBufferBindingLayout;\n for (const uniform of uniformBlock.uniforms || []) {\n this.bindingLayout[uniform.name] = uniform;\n }\n }\n }\n\n /** Set a map of uniforms */\n setUniforms(uniforms: Partial<TUniforms>): void {\n for (const [key, value] of Object.entries(uniforms)) {\n this._setUniform(key, value);\n if (!this.needsRedraw) {\n this.setNeedsRedraw(`${this.name}.${key}=${value}`);\n }\n }\n }\n\n setNeedsRedraw(reason: string): void {\n this.needsRedraw = this.needsRedraw || reason;\n }\n\n /** Returns all uniforms */\n getAllUniforms(): Record<string, UniformValue> {\n // @ts-expect-error\n this.modifiedUniforms = {};\n this.needsRedraw = false;\n return (this.uniforms || {}) as Record<string, UniformValue>;\n }\n\n /** Set a single uniform */\n private _setUniform(key: keyof TUniforms, value: UniformValue) {\n if (arrayEqual(this.uniforms[key], value)) {\n return;\n }\n this.uniforms[key] = arrayCopy(value);\n this.modifiedUniforms[key] = true;\n this.modified = true;\n }\n}\n"],"mappings":"SAQQA,UAAU,EAAEC,SAAS;AAO7B,OAAO,MAAMC,YAAY,CAAgF;EAUvGC,WAAWA,CAACC,KAIX,EAAE;IAAA,KAbHC,IAAI;IAAA,KAEJC,QAAQ,GAA0C,CAAC,CAAC;IAAA,KACpDC,gBAAgB,GAAqC,CAAC,CAAC;IAAA,KACvDC,QAAQ,GAAY,IAAI;IAAA,KAEfC,aAAa,GAAgC,CAAC,CAAC;IAAA,KACxDC,WAAW,GAAmB,aAAa;IAOzC,IAAI,CAACL,IAAI,GAAGD,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,IAAI;IAGvB,IAAID,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEC,IAAI,IAAID,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEO,YAAY,EAAE;MAAA,IAAAC,qBAAA;MACtC,MAAMC,OAAO,GAAGT,KAAK,aAALA,KAAK,gBAAAQ,qBAAA,GAALR,KAAK,CAAEO,YAAY,CAACG,QAAQ,cAAAF,qBAAA,uBAA5BA,qBAAA,CAA8BG,IAAI,CAChDF,OAAO,IAAIA,OAAO,CAACG,IAAI,KAAK,SAAS,IAAIH,OAAO,CAACR,IAAI,MAAKD,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,IAAI,CACvE,CAAC;MACD,IAAI,CAACQ,OAAO,EA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B;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ShaderUniformType, ShaderDataType } from '../../adapter/types/shader-types';
|
|
2
|
+
import type { UniformValue } from '../../adapter/types/types';
|
|
3
|
+
/**
|
|
4
|
+
* Std140 layout for uniform buffers
|
|
5
|
+
* Supports manual listing of uniforms
|
|
6
|
+
*/
|
|
7
|
+
export declare class UniformBufferLayout {
|
|
8
|
+
readonly layout: Record<string, {
|
|
9
|
+
offset: number;
|
|
10
|
+
size: number;
|
|
11
|
+
type: ShaderDataType;
|
|
12
|
+
}>;
|
|
13
|
+
/** number of bytes needed for buffer allocation */
|
|
14
|
+
readonly byteLength: number;
|
|
15
|
+
/** Create a new UniformBufferLayout given a map of attributes. */
|
|
16
|
+
constructor(uniformTypes: Record<string, ShaderUniformType>);
|
|
17
|
+
/** Get the data for the complete buffer */
|
|
18
|
+
getData(uniformValues: Record<string, UniformValue>): Uint8Array;
|
|
19
|
+
/** Does this layout have a field with specified name */
|
|
20
|
+
has(name: string): boolean;
|
|
21
|
+
/** Get offset and size for a field with specified name */
|
|
22
|
+
get(name: string): {
|
|
23
|
+
offset: number;
|
|
24
|
+
size: number;
|
|
25
|
+
} | undefined;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=uniform-buffer-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-buffer-layout.d.ts","sourceRoot":"","sources":["../../../src/lib/uniforms/uniform-buffer-layout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAE,cAAc,EAAC,MAAM,kCAAkC,CAAC;AACxF,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAY5D;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,cAAc,CAAA;KAAC,CAAC,CAAM;IAE3F,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAG5B,kEAAkE;gBACtD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC;IAsB3D,2CAA2C;IAC3C,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,UAAU;IAiDhE,wDAAwD;IACxD,GAAG,CAAC,IAAI,EAAE,MAAM;IAIhB,0DAA0D;IAC1D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,GAAG,SAAS;CAI9D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { decodeShaderUniformType, alignTo } from "../../adapter/type-utils/decode-shader-types.js";
|
|
2
|
+
import { getScratchArrayBuffer } from "../../utils/array-utils-flat.js";
|
|
3
|
+
import { isNumberArray } from "../../utils/is-array.js";
|
|
4
|
+
import { log } from "../../utils/log.js";
|
|
5
|
+
const minBufferSize = 1024;
|
|
6
|
+
export class UniformBufferLayout {
|
|
7
|
+
constructor(uniformTypes) {
|
|
8
|
+
this.layout = {};
|
|
9
|
+
this.byteLength = void 0;
|
|
10
|
+
let size = 0;
|
|
11
|
+
for (const [key, uniformType] of Object.entries(uniformTypes)) {
|
|
12
|
+
const typeAndComponents = decodeShaderUniformType(uniformType);
|
|
13
|
+
const {
|
|
14
|
+
type,
|
|
15
|
+
components: count
|
|
16
|
+
} = typeAndComponents;
|
|
17
|
+
size = alignTo(size, count);
|
|
18
|
+
const offset = size;
|
|
19
|
+
size += count;
|
|
20
|
+
this.layout[key] = {
|
|
21
|
+
type,
|
|
22
|
+
size: count,
|
|
23
|
+
offset
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
size += (4 - size % 4) % 4;
|
|
27
|
+
const actualByteLength = size * 4;
|
|
28
|
+
this.byteLength = Math.max(actualByteLength, minBufferSize);
|
|
29
|
+
}
|
|
30
|
+
getData(uniformValues) {
|
|
31
|
+
const bufferSize = Math.max(this.byteLength, minBufferSize);
|
|
32
|
+
const arrayBuffer = getScratchArrayBuffer(bufferSize);
|
|
33
|
+
const typedArrays = {
|
|
34
|
+
i32: new Int32Array(arrayBuffer),
|
|
35
|
+
u32: new Uint32Array(arrayBuffer),
|
|
36
|
+
f32: new Float32Array(arrayBuffer),
|
|
37
|
+
f16: new Uint16Array(arrayBuffer)
|
|
38
|
+
};
|
|
39
|
+
for (const [name, value] of Object.entries(uniformValues)) {
|
|
40
|
+
const uniformLayout = this.layout[name];
|
|
41
|
+
if (!uniformLayout) {
|
|
42
|
+
log.warn(`Supplied uniform value ${name} not present in uniform block layout`)();
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const {
|
|
46
|
+
type,
|
|
47
|
+
size,
|
|
48
|
+
offset
|
|
49
|
+
} = uniformLayout;
|
|
50
|
+
const typedArray = typedArrays[type];
|
|
51
|
+
if (size === 1) {
|
|
52
|
+
if (typeof value !== 'number' && typeof value !== 'boolean') {
|
|
53
|
+
log.warn(`Supplied value for single component uniform ${name} is not a number: ${value}`)();
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
typedArray[offset] = Number(value);
|
|
57
|
+
} else {
|
|
58
|
+
const numericArray = isNumberArray(value);
|
|
59
|
+
if (!numericArray) {
|
|
60
|
+
log.warn(`Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}`)();
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
typedArray.set(numericArray, offset);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return new Uint8Array(arrayBuffer);
|
|
67
|
+
}
|
|
68
|
+
has(name) {
|
|
69
|
+
return Boolean(this.layout[name]);
|
|
70
|
+
}
|
|
71
|
+
get(name) {
|
|
72
|
+
const layout = this.layout[name];
|
|
73
|
+
return layout;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=uniform-buffer-layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-buffer-layout.js","names":["decodeShaderUniformType","alignTo","getScratchArrayBuffer","isNumberArray","log","minBufferSize","UniformBufferLayout","constructor","uniformTypes","layout","byteLength","size","key","uniformType","Object","entries","typeAndComponents","type","components","count","offset","actualByteLength","Math","max","getData","uniformValues","bufferSize","arrayBuffer","typedArrays","i32","Int32Array","u32","Uint32Array","f32","Float32Array","f16","Uint16Array","name","value","uniformLayout","warn","typedArray","Number","numericArray","set","Uint8Array","has","Boolean","get"],"sources":["../../../src/lib/uniforms/uniform-buffer-layout.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {ShaderUniformType, ShaderDataType} from '../../adapter/types/shader-types';\nimport type {UniformValue} from '../../adapter/types/types';\nimport {decodeShaderUniformType, alignTo} from '../../adapter/type-utils/decode-shader-types';\nimport {getScratchArrayBuffer} from '../../utils/array-utils-flat';\nimport {isNumberArray} from '../../utils/is-array';\nimport { log } from '../../utils/log';\n\n/** \n * Smallest buffer size that can be used for uniform buffers.\n * TODO - does this depend on device?\n */\nconst minBufferSize: number = 1024;\n\n/**\n * Std140 layout for uniform buffers\n * Supports manual listing of uniforms\n */\nexport class UniformBufferLayout {\n readonly layout: Record<string, {offset: number, size: number, type: ShaderDataType}> = {};\n\n /** number of bytes needed for buffer allocation */\n readonly byteLength: number;\n\n\n /** Create a new UniformBufferLayout given a map of attributes. */\n constructor(uniformTypes: Record<string, ShaderUniformType>) {\n /** number of 4 byte slots taken */\n let size: number = 0;\n\n // Add layout (type, size and offset) definitions for each uniform in the layout\n for (const [key, uniformType] of Object.entries(uniformTypes)) {\n const typeAndComponents = decodeShaderUniformType(uniformType);\n const {type, components: count} = typeAndComponents;\n // First, align (bump) current offset to an even multiple of current object (1, 2, 4)\n size = alignTo(size, count);\n // Use the aligned size as the offset of the current uniform.\n const offset = size;\n // Then, add our object's padded size ((1, 2, multiple of 4) to the current offset\n size += count;\n this.layout[key] = {type, size: count, offset};\n }\n size += (4 - (size % 4)) % 4;\n\n const actualByteLength = size * 4;\n this.byteLength = Math.max(actualByteLength, minBufferSize);\n }\n\n /** Get the data for the complete buffer */\n getData(uniformValues: Record<string, UniformValue>): Uint8Array {\n const bufferSize = Math.max(this.byteLength, minBufferSize);\n\n // Allocate three typed arrays pointing at same memory\n const arrayBuffer = getScratchArrayBuffer(bufferSize);\n const typedArrays = {\n i32: new Int32Array(arrayBuffer),\n u32: new Uint32Array(arrayBuffer),\n f32: new Float32Array(arrayBuffer),\n // TODO not implemented\n f16: new Uint16Array(arrayBuffer)\n };\n // TODO is this needed?\n // typedArrays.i32.fill(0);\n \n for (const [name, value] of Object.entries(uniformValues)) {\n const uniformLayout = this.layout[name];\n if (!uniformLayout) {\n log.warn(`Supplied uniform value ${name} not present in uniform block layout`)();\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const {type, size, offset} = uniformLayout;\n const typedArray = typedArrays[type];\n if (size === 1) {\n if (typeof value !== 'number' && typeof value !== 'boolean') {\n log.warn(`Supplied value for single component uniform ${name} is not a number: ${value}`)();\n // eslint-disable-next-line no-continue\n continue;\n }\n // single value -> just set it\n typedArray[offset] = Number(value);\n } else {\n const numericArray = isNumberArray(value);\n if (!numericArray) {\n log.warn(`Supplied value for multi component / array uniform ${name} is not a numeric array: ${value}`)();\n // eslint-disable-next-line no-continue\n continue;\n }\n // vector/matrix -> copy the supplied (typed) array, starting from offset\n // TODO: we should limit or check size in case the supplied data overflows\n typedArray.set(numericArray, offset);\n }\n }\n\n return new Uint8Array(arrayBuffer);\n } \n\n /** Does this layout have a field with specified name */\n has(name: string) {\n return Boolean(this.layout[name]);\n }\n\n /** Get offset and size for a field with specified name */\n get(name: string): {offset: number, size: number} | undefined {\n const layout = this.layout[name];\n return layout;\n }\n}\n"],"mappings":"SAGQA,uBAAuB,EAAEC,OAAO;AAAA,SAChCC,qBAAqB;AAAA,SACrBC,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AC5D,MAAM5B,MAAM,GAAG,IAAI,CAACA,MAAM,CAAC4B,IAAI,CAAC;IAChC,OAAO5B,MAAM;EACf;AACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ShaderUniformType } from '../../adapter/types/shader-types';
|
|
2
|
+
import type { UniformValue } from '../../adapter/types/types';
|
|
3
|
+
import type { Device } from '../../adapter/device';
|
|
4
|
+
import { Buffer } from '../../adapter/resources/buffer';
|
|
5
|
+
import { UniformBlock } from './uniform-block';
|
|
6
|
+
import { UniformBufferLayout } from './uniform-buffer-layout';
|
|
7
|
+
export type ShaderModuleInputs = {
|
|
8
|
+
uniformTypes?: Record<string, ShaderUniformType>;
|
|
9
|
+
defaultProps?: Record<string, unknown>;
|
|
10
|
+
defaultUniforms?: Record<string, UniformValue>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A uniform store holds a uniform values for one or more uniform blocks,
|
|
14
|
+
* - It can generate binary data for any uniform buffer
|
|
15
|
+
* - It can manage a uniform buffer for each block
|
|
16
|
+
* - It can update managed uniform buffers with a single call
|
|
17
|
+
* - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.
|
|
18
|
+
*/
|
|
19
|
+
export declare class UniformStore<TPropGroups extends Record<string, Record<string, unknown>> = Record<string, Record<string, unknown>>> {
|
|
20
|
+
/** Stores the uniform values for each uniform block */
|
|
21
|
+
uniformBlocks: Map<keyof TPropGroups, UniformBlock<Record<string, UniformValue>>>;
|
|
22
|
+
/** Can generate data for a uniform buffer for each block from data */
|
|
23
|
+
uniformBufferLayouts: Map<keyof TPropGroups, UniformBufferLayout>;
|
|
24
|
+
/** Actual buffer for the blocks */
|
|
25
|
+
uniformBuffers: Map<keyof TPropGroups, Buffer>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new UniformStore instance
|
|
28
|
+
* @param blocks
|
|
29
|
+
*/
|
|
30
|
+
constructor(blocks: Record<keyof TPropGroups, {
|
|
31
|
+
uniformTypes?: Record<string, ShaderUniformType>;
|
|
32
|
+
defaultProps?: Record<string, unknown>;
|
|
33
|
+
defaultUniforms?: Record<string, UniformValue>;
|
|
34
|
+
}>);
|
|
35
|
+
/** Destroy any managed uniform buffers */
|
|
36
|
+
destroy(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Set uniforms
|
|
39
|
+
* Makes all properties partial
|
|
40
|
+
*/
|
|
41
|
+
setUniforms(uniforms: Partial<{
|
|
42
|
+
[group in keyof TPropGroups]: Partial<TPropGroups[group]>;
|
|
43
|
+
}>): void;
|
|
44
|
+
/** Get the required minimum length of the uniform buffer */
|
|
45
|
+
getUniformBufferByteLength(uniformBufferName: keyof TPropGroups): number;
|
|
46
|
+
/** Get formatted binary memory that can be uploaded to a buffer */
|
|
47
|
+
getUniformBufferData(uniformBufferName: keyof TPropGroups): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* Creates an unmanaged uniform buffer (umnanaged means that application is responsible for destroying it)
|
|
50
|
+
* The new buffer is initialized with current / supplied values
|
|
51
|
+
*/
|
|
52
|
+
createUniformBuffer(device: Device, uniformBufferName: keyof TPropGroups, uniforms?: Partial<{
|
|
53
|
+
[group in keyof TPropGroups]: Partial<TPropGroups[group]>;
|
|
54
|
+
}>): Buffer;
|
|
55
|
+
/** Get the managed uniform buffer. "managed" resources are destroyed when the uniformStore is destroyed. */
|
|
56
|
+
getManagedUniformBuffer(device: Device, uniformBufferName: keyof TPropGroups): Buffer;
|
|
57
|
+
/** Updates all uniform buffers where values have changed */
|
|
58
|
+
updateUniformBuffers(): false | string;
|
|
59
|
+
/** Update one uniform buffer. Only updates if values have changed */
|
|
60
|
+
updateUniformBuffer(uniformBufferName: keyof TPropGroups): false | string;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=uniform-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-store.d.ts","sourceRoot":"","sources":["../../../src/lib/uniforms/uniform-store.ts"],"names":[],"mappings":"AACA,OA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AAC;SAAE,KAAK,IAAI,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;KAAC,CAAC,GAC7E,IAAI;IAUP,4DAA4D;IAC5D,0BAA0B,CAAC,iBAAiB,EAAE,MAAM,WAAW,GAAG,MAAM;IAIxE,mEAAmE;IACnE,oBAAoB,CAAC,iBAAiB,EAAE,MAAM,WAAW,GAAG,UAAU;IAKtE;;;OAGG;IACH,mBAAmB,CACjB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM,WAAW,EACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;SAAE,KAAK,IAAI,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;KAAC,CAAC,GAC9E,MAAM;IAeT,4GAA4G;IAC5G,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,WAAW,GAAG,MAAM;IAarF,4DAA4D;IAC5D,oBAAoB,IAAI,KAAK,GAAG,MAAM;IAYtC,qEAAqE;IACrE,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM;CAwB1E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Buffer } from "../../adapter/resources/buffer.js";
|
|
2
|
+
import { UniformBlock } from "./uniform-block.js";
|
|
3
|
+
import { UniformBufferLayout } from "./uniform-buffer-layout.js";
|
|
4
|
+
import { log } from "../../utils/log.js";
|
|
5
|
+
export class UniformStore {
|
|
6
|
+
constructor(blocks) {
|
|
7
|
+
this.uniformBlocks = new Map();
|
|
8
|
+
this.uniformBufferLayouts = new Map();
|
|
9
|
+
this.uniformBuffers = new Map();
|
|
10
|
+
for (const [bufferName, block] of Object.entries(blocks)) {
|
|
11
|
+
const uniformBufferName = bufferName;
|
|
12
|
+
const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {});
|
|
13
|
+
this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
|
|
14
|
+
const uniformBlock = new UniformBlock({
|
|
15
|
+
name: bufferName
|
|
16
|
+
});
|
|
17
|
+
uniformBlock.setUniforms(block.defaultUniforms || {});
|
|
18
|
+
this.uniformBlocks.set(uniformBufferName, uniformBlock);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
destroy() {
|
|
22
|
+
for (const uniformBuffer of Object.values(this.uniformBuffers)) {
|
|
23
|
+
uniformBuffer.destroy();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
setUniforms(uniforms) {
|
|
27
|
+
for (const [blockName, uniformValues] of Object.entries(uniforms)) {
|
|
28
|
+
this.uniformBlocks.get(blockName).setUniforms(uniformValues);
|
|
29
|
+
}
|
|
30
|
+
this.updateUniformBuffers();
|
|
31
|
+
}
|
|
32
|
+
getUniformBufferByteLength(uniformBufferName) {
|
|
33
|
+
return this.uniformBufferLayouts.get(uniformBufferName).byteLength;
|
|
34
|
+
}
|
|
35
|
+
getUniformBufferData(uniformBufferName) {
|
|
36
|
+
const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
|
|
37
|
+
return this.uniformBufferLayouts.get(uniformBufferName).getData(uniformValues);
|
|
38
|
+
}
|
|
39
|
+
createUniformBuffer(device, uniformBufferName, uniforms) {
|
|
40
|
+
if (uniforms) {
|
|
41
|
+
this.setUniforms(uniforms);
|
|
42
|
+
}
|
|
43
|
+
const byteLength = this.getUniformBufferByteLength(uniformBufferName);
|
|
44
|
+
const uniformBuffer = device.createBuffer({
|
|
45
|
+
usage: Buffer.UNIFORM | Buffer.COPY_DST,
|
|
46
|
+
byteLength
|
|
47
|
+
});
|
|
48
|
+
const uniformBufferData = this.getUniformBufferData(uniformBufferName);
|
|
49
|
+
uniformBuffer.write(uniformBufferData);
|
|
50
|
+
return uniformBuffer;
|
|
51
|
+
}
|
|
52
|
+
getManagedUniformBuffer(device, uniformBufferName) {
|
|
53
|
+
if (!this.uniformBuffers.get(uniformBufferName)) {
|
|
54
|
+
const byteLength = this.getUniformBufferByteLength(uniformBufferName);
|
|
55
|
+
const uniformBuffer = device.createBuffer({
|
|
56
|
+
usage: Buffer.UNIFORM | Buffer.COPY_DST,
|
|
57
|
+
byteLength
|
|
58
|
+
});
|
|
59
|
+
this.uniformBuffers.set(uniformBufferName, uniformBuffer);
|
|
60
|
+
}
|
|
61
|
+
return this.uniformBuffers.get(uniformBufferName);
|
|
62
|
+
}
|
|
63
|
+
updateUniformBuffers() {
|
|
64
|
+
let reason = false;
|
|
65
|
+
for (const uniformBufferName of this.uniformBlocks.keys()) {
|
|
66
|
+
const bufferReason = this.updateUniformBuffer(uniformBufferName);
|
|
67
|
+
reason || (reason = bufferReason);
|
|
68
|
+
}
|
|
69
|
+
if (reason) {
|
|
70
|
+
log.log(3, `UniformStore.updateUniformBuffers(): ${reason}`)();
|
|
71
|
+
}
|
|
72
|
+
return reason;
|
|
73
|
+
}
|
|
74
|
+
updateUniformBuffer(uniformBufferName) {
|
|
75
|
+
const uniformBlock = this.uniformBlocks.get(uniformBufferName);
|
|
76
|
+
const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
|
|
77
|
+
let reason = false;
|
|
78
|
+
if (uniformBuffer && uniformBlock.needsRedraw) {
|
|
79
|
+
reason || (reason = uniformBlock.needsRedraw);
|
|
80
|
+
const uniformBufferData = this.getUniformBufferData(uniformBufferName);
|
|
81
|
+
const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
|
|
82
|
+
uniformBuffer.write(uniformBufferData);
|
|
83
|
+
const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
|
|
84
|
+
log.log(4, `Writing to uniform buffer ${String(uniformBufferName)}`, uniformBufferData, uniformValues)();
|
|
85
|
+
}
|
|
86
|
+
return reason;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=uniform-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform-store.js","names":["Buffer","UniformBlock","UniformBufferLayout","log","UniformStore","constructor","blocks","uniformBlocks","Map","uniformBufferLayouts","uniformBuffers","bufferName","block","Object","entries","uniformBufferName","uniformBufferLayout","uniformTypes","set","uniformBlock","name","setUniforms","defaultUniforms","destroy","uniformBuffer","values","uniforms","blockName","uniformValues","get","updateUniformBuffers","getUniformBufferByteLength","byteLength","getUniformBufferData","getAllUniforms","getData","createUniformBuffer","device","createBuffer","usage","UNIFORM","COPY_DST","uniformBufferData","write","getManagedUniformBuffer","reason","keys","bufferReason","updateUniformBuffer","needsRedraw","String"],"sources":["../../../src/lib/uniforms/uniform-store.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {ShaderUniformType} from '../../adapter/types/shader-types';\nimport type {UniformValue} from '../../adapter/types/types';\nimport type {Device} from '../../adapter/device';\nimport {Buffer} from '../../adapter/resources/buffer';\nimport {UniformBlock} from './uniform-block';\nimport {UniformBufferLayout} from './uniform-buffer-layout';\nimport {log} from '../../utils/log';\n\nexport type ShaderModuleInputs = {\n uniformTypes?: Record<string, ShaderUniformType>;\n defaultProps?: Record<string, unknown>;\n defaultUniforms?: Record<string, UniformValue>;\n};\n\n/**\n * A uniform store holds a uniform values for one or more uniform blocks,\n * - It can generate binary data for any uniform buffer\n * - It can manage a uniform buffer for each block\n * - It can update managed uniform buffers with a single call\n * - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.\n */\nexport class UniformStore<\n TPropGroups extends Record<string, Record<string, unknown>> = Record<\n string,\n Record<string, unknown>\n >\n> {\n /** Stores the uniform values for each uniform block */\n uniformBlocks = new Map<keyof TPropGroups, UniformBlock>();\n /** Can generate data for a uniform buffer for each block from data */\n uniformBufferLayouts = new Map<keyof TPropGroups, UniformBufferLayout>();\n /** Actual buffer for the blocks */\n uniformBuffers = new Map<keyof TPropGroups, Buffer>();\n\n /**\n * Create a new UniformStore instance\n * @param blocks\n */\n constructor(\n blocks: Record<\n keyof TPropGroups,\n {\n uniformTypes?: Record<string, ShaderUniformType>;\n defaultProps?: Record<string, unknown>;\n defaultUniforms?: Record<string, UniformValue>;\n }\n >\n ) {\n for (const [bufferName, block] of Object.entries(blocks)) {\n const uniformBufferName = bufferName as keyof TPropGroups;\n\n // Create a layout object to help us generate correctly formatted binary uniform buffers\n const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {});\n this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);\n\n // Create a Uniform block to store the uniforms for each buffer.\n const uniformBlock = new UniformBlock({name: bufferName});\n uniformBlock.setUniforms(block.defaultUniforms || {});\n this.uniformBlocks.set(uniformBufferName, uniformBlock);\n }\n }\n\n /** Destroy any managed uniform buffers */\n destroy(): void {\n for (const uniformBuffer of Object.values(this.uniformBuffers)) {\n uniformBuffer.destroy();\n }\n }\n\n /**\n * Set uniforms\n * Makes all properties partial\n */\n setUniforms(\n uniforms: Partial<{[group in keyof TPropGroups]: Partial<TPropGroups[group]>}>\n ): void {\n for (const [blockName, uniformValues] of Object.entries(uniforms)) {\n this.uniformBlocks.get(blockName).setUniforms(uniformValues);\n // We leverage logging in updateUniformBuffers(), even though slightly less efficient\n // this.updateUniformBuffer(blockName);\n }\n\n this.updateUniformBuffers();\n }\n\n /** Get the required minimum length of the uniform buffer */\n getUniformBufferByteLength(uniformBufferName: keyof TPropGroups): number {\n return this.uniformBufferLayouts.get(uniformBufferName).byteLength;\n }\n\n /** Get formatted binary memory that can be uploaded to a buffer */\n getUniformBufferData(uniformBufferName: keyof TPropGroups): Uint8Array {\n const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();\n return this.uniformBufferLayouts.get(uniformBufferName).getData(uniformValues);\n }\n\n /**\n * Creates an unmanaged uniform buffer (umnanaged means that application is responsible for destroying it)\n * The new buffer is initialized with current / supplied values\n */\n createUniformBuffer(\n device: Device,\n uniformBufferName: keyof TPropGroups,\n uniforms?: Partial<{[group in keyof TPropGroups]: Partial<TPropGroups[group]>}>\n ): Buffer {\n if (uniforms) {\n this.setUniforms(uniforms);\n }\n const byteLength = this.getUniformBufferByteLength(uniformBufferName);\n const uniformBuffer = device.createBuffer({\n usage: Buffer.UNIFORM | Buffer.COPY_DST,\n byteLength\n });\n // Note that this clears the needs redraw flag\n const uniformBufferData = this.getUniformBufferData(uniformBufferName);\n uniformBuffer.write(uniformBufferData);\n return uniformBuffer;\n }\n\n /** Get the managed uniform buffer. \"managed\" resources are destroyed when the uniformStore is destroyed. */\n getManagedUniformBuffer(device: Device, uniformBufferName: keyof TPropGroups): Buffer {\n if (!this.uniformBuffers.get(uniformBufferName)) {\n const byteLength = this.getUniformBufferByteLength(uniformBufferName);\n const uniformBuffer = device.createBuffer({\n usage: Buffer.UNIFORM | Buffer.COPY_DST,\n byteLength\n });\n this.uniformBuffers.set(uniformBufferName, uniformBuffer);\n }\n // this.updateUniformBuffers();\n return this.uniformBuffers.get(uniformBufferName);\n }\n\n /** Updates all uniform buffers where values have changed */\n updateUniformBuffers(): false | string {\n let reason: false | string = false;\n for (const uniformBufferName of this.uniformBlocks.keys()) {\n const bufferReason = this.updateUniformBuffer(uniformBufferName);\n reason ||= bufferReason;\n }\n if (reason) {\n log.log(3, `UniformStore.updateUniformBuffers(): ${reason}`)();\n }\n return reason;\n }\n\n /** Update one uniform buffer. Only updates if values have changed */\n updateUniformBuffer(uniformBufferName: keyof TPropGroups): false | string {\n const uniformBlock = this.uniformBlocks.get(uniformBufferName);\n const uniformBuffer = this.uniformBuffers.get(uniformBufferName);\n\n let reason: false | string = false;\n if (uniformBuffer && uniformBlock.needsRedraw) {\n reason ||= uniformBlock.needsRedraw;\n // This clears the needs redraw flag\n const uniformBufferData = this.getUniformBufferData(uniformBufferName);\n\n const uniformBuffer = this.uniformBuffers.get(uniformBufferName);\n uniformBuffer.write(uniformBufferData);\n\n // logging - TODO - don't query the values unnecessarily\n const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();\n log.log(\n 4,\n `Writing to uniform buffer ${String(uniformBufferName)}`,\n uniformBufferData,\n uniformValues\n )();\n }\n return reason;\n }\n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AACA,GAAG,CACL,CAAC,EACA,6BAA4B+C,MAAM,CAACnC,iBAAiB,CAAE,EAAC,EACxD2B,iBAAiB,EACjBd,aACF,CAAC,CAAC,CAAC;IACL;IACA,OAAOiB,MAAM;EACf;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UniformValue } from '../../adapter/types/types';
|
|
2
|
+
import type { Binding } from '../../adapter/types/shader-layout';
|
|
3
|
+
export declare function isUniformValue(value: unknown): boolean;
|
|
4
|
+
type UniformsAndBindings = {
|
|
5
|
+
bindings: Record<string, Binding>;
|
|
6
|
+
uniforms: Record<string, UniformValue>;
|
|
7
|
+
};
|
|
8
|
+
export declare function splitUniformsAndBindings(uniforms: Record<string, Binding | UniformValue>): UniformsAndBindings;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=uniform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform.d.ts","sourceRoot":"","sources":["../../../src/lib/uniforms/uniform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,mCAAmC,CAAC;AAG/D,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACvC,CAAC;AACF,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAAC,GAAG,mBAAmB,CAY9G"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isNumberArray } from "../../utils/is-array.js";
|
|
2
|
+
export function isUniformValue(value) {
|
|
3
|
+
return isNumberArray(value) !== null || typeof value === 'number' || typeof value === 'boolean';
|
|
4
|
+
}
|
|
5
|
+
export function splitUniformsAndBindings(uniforms) {
|
|
6
|
+
const result = {
|
|
7
|
+
bindings: {},
|
|
8
|
+
uniforms: {}
|
|
9
|
+
};
|
|
10
|
+
Object.keys(uniforms).forEach(name => {
|
|
11
|
+
const uniform = uniforms[name];
|
|
12
|
+
if (isUniformValue(uniform)) {
|
|
13
|
+
result.uniforms[name] = uniform;
|
|
14
|
+
} else {
|
|
15
|
+
result.bindings[name] = uniform;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=uniform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniform.js","names":["isNumberArray","isUniformValue","value","splitUniformsAndBindings","uniforms","result","bindings","Object","keys","forEach","name","uniform"],"sources":["../../../src/lib/uniforms/uniform.ts"],"sourcesContent":["import type {UniformValue} from '../../adapter/types/types';\nimport type {Binding} from '../../adapter/types/shader-layout';\nimport {isNumberArray} from '../../utils/is-array';\n\nexport function isUniformValue(value: unknown): boolean {\n return isNumberArray(value) !== null || (typeof value === 'number') || (typeof value === 'boolean');\n}\n\ntype UniformsAndBindings = {\n bindings: Record<string, Binding>,\n uniforms: Record<string, UniformValue>\n};\nexport function splitUniformsAndBindings(uniforms: Record<string, Binding | UniformValue>): UniformsAndBindings {\n const result: UniformsAndBindings = { bindings: {}, uniforms: {} } \n Object.keys(uniforms).forEach(name => {\n const uniform = uniforms[name];\n if(isUniformValue(uniform)) {\n result.uniforms[name] = uniform as UniformValue;\n } else {\n result.bindings[name] = uniform as Binding;\n }\n });\n\n return result;\n}\n"],"mappings":"SAEQA,aAAa;AAErB,OAAO,SAASC,cAAcA,CAACC,KAAc,EAAW;EACtD,OAAOF,aAAa,CAACE,KAAK,CAAC,KAAK,IAAI,IAAK,OAAOA,KAAK,KAAK,QAAS,IAAK,OAAOA,KAAK,KAAK,SAAU;AACrG;AAMA,OAAO,SAASC,wBAAwBA,CAACC,QAAgD,EAAuB;EAC9G,MAAMC,MAA2B,GAAG;IAAEC,QAAQ,EAAE,CAAC,CAAC;IAAEF,QAAQ,EAAE,CAAC;EAAE,CAAC;EAClEG,MAAM,CAACC,IAAI,CAACJ,QAAQ,CAAC,CAACK,OAAO,CAACC,IAAI,IAAI;IACpC,MAAMC,OAAO,GAAGP,QAAQ,CAACM,IAAI,CAAC;IAC9B,IAAGT,cAAc,CAACU,OAAO,CAAC,EAAE;MAC1BN,MAAM,CAACD,QAAQ,CAACM,IAAI,CAAC,GAAGC,OAAuB;IACjD,CAAC,MAAM;MACLN,MAAM,CAACC,QAAQ,CAACI,IAAI,CAAC,GAAGC,OAAkB;IAC5C;EACF,CAAC,CAAC;EAEF,OAAON,MAAM;AACf"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** TypeScript type covering all typed arrays */
|
|
2
|
+
import { TypedArray, NumberArray } from '@math.gl/types';
|
|
3
|
+
export { TypedArray, NumberArray };
|
|
4
|
+
/** TypeScript type covering constructors of any of the typed arrays */
|
|
5
|
+
export type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Uint8ClampedArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor;
|
|
6
|
+
/** Keep big int arrays separate as they are still problematic, can't be indexed and don't work well on Safari */
|
|
7
|
+
export type BigIntTypedArray = BigInt64Array | BigUint64Array;
|
|
8
|
+
export type BigIntOrNumberArray = NumberArray | BigIntTypedArray;
|
|
9
|
+
/** Get the constructor type of a type */
|
|
10
|
+
export interface ConstructorOf<T> {
|
|
11
|
+
new (...args: unknown[]): T;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Make specific fields in a type optional. Granular version of `Partial<T>`
|
|
15
|
+
* @example
|
|
16
|
+
* type PartialProps = PartialBy<Required<DeviceProps>, 'device' | 'canvas'>
|
|
17
|
+
*/
|
|
18
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAC,UAAU,EAAE,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC;AAEjC,uEAAuE;AACvE,MAAM,MAAM,qBAAqB,GAC7B,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,4BAA4B,GAC5B,uBAAuB,GACvB,uBAAuB,CAAC;AAE5B,iHAAiH;AACjH,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,cAAc,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AAEjE,yCAAyC;AACzC,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":["TypedArray","NumberArray"],"sources":["../src/types.ts"],"sourcesContent":["/** TypeScript type covering all typed arrays */\nimport {TypedArray, NumberArray} from '@math.gl/types';\n\nexport {TypedArray, NumberArray};\n\n/** TypeScript type covering constructors of any of the typed arrays */\nexport type TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Uint8ClampedArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\n/** Keep big int arrays separate as they are still problematic, can't be indexed and don't work well on Safari */\nexport type BigIntTypedArray = BigInt64Array | BigUint64Array;\n\nexport type BigIntOrNumberArray = NumberArray | BigIntTypedArray;\n\n/** Get the constructor type of a type */\nexport interface ConstructorOf<T> {\n new (...args: unknown[]): T;\n}\n\n/** \n * Make specific fields in a type optional. Granular version of `Partial<T>` \n * @example \n * type PartialProps = PartialBy<Required<DeviceProps>, 'device' | 'canvas'>\n */\nexport type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n"],"mappings":"AACA,SAAQA,UAAU,EAAEC,WAAW,QAAO,gBAAgB;AAEtD,SAAQD,UAAU,EAAEC,WAAW"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Test if two arrays are deep equal, with a length limit that defaults to 16 */
|
|
2
|
+
export declare function arrayEqual(a: unknown, b: unknown, limit?: number): boolean;
|
|
3
|
+
/** Copy a value */
|
|
4
|
+
export declare function arrayCopy<T>(a: T): T;
|
|
5
|
+
//# sourceMappingURL=array-equal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-equal.d.ts","sourceRoot":"","sources":["../../src/utils/array-equal.ts"],"names":[],"mappings":"AAKA,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,GAAE,MAAW,WAiBpE;AAED,mBAAmB;AACnB,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAMpC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isNumberArray } from "./is-array.js";
|
|
2
|
+
export function arrayEqual(a, b) {
|
|
3
|
+
let limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 16;
|
|
4
|
+
if (a !== b) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const arrayA = isNumberArray(a);
|
|
8
|
+
if (!arrayA) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const arrayB = isNumberArray(b);
|
|
12
|
+
if (arrayB && arrayA.length === arrayB.length) {
|
|
13
|
+
for (let i = 0; i < arrayA.length; ++i) {
|
|
14
|
+
if (arrayB[i] !== arrayA[i]) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
export function arrayCopy(a) {
|
|
22
|
+
const numberArray = isNumberArray(a);
|
|
23
|
+
if (numberArray) {
|
|
24
|
+
return numberArray.slice();
|
|
25
|
+
}
|
|
26
|
+
return a;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=array-equal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-equal.js","names":["isNumberArray","arrayEqual","a","b","limit","arguments","length","undefined","arrayA","arrayB","i","arrayCopy","numberArray","slice"],"sources":["../../src/utils/array-equal.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {isNumberArray} from './is-array';\n\n/** Test if two arrays are deep equal, with a length limit that defaults to 16 */\nexport function arrayEqual(a: unknown, b: unknown, limit: number = 16) {\n if (a !== b) {\n return false;\n }\n const arrayA = isNumberArray(a);\n if (!arrayA) {\n return false;\n }\n const arrayB = isNumberArray(b);\n if (arrayB && arrayA.length === arrayB.length) {\n for (let i = 0; i < arrayA.length; ++i) {\n if (arrayB[i] !== arrayA[i]) {\n return false;\n }\n }\n }\n return true;\n}\n\n/** Copy a value */\nexport function arrayCopy<T>(a: T): T {\n const numberArray = isNumberArray(a);\n if (numberArray) {\n return numberArray.slice() as T;\n }\n return a;\n}\n"],"mappings":"SAGQA,aAAa;AAGrB,OAAO,SAASC,UAAUA,CAACC,CAAU,EAAEC,CAAU,EAAsB;EAAA,IAApBC,KAAa,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EACnE,IAAIH,CAAC,KAAKC,CAAC,EAAE;IACX,OAAO,KAAK;EACd;EACA,MAAMK,MAAM,GAAGR,aAAa,CAACE,CAAC,CAAC;EAC/B,IAAI,CAACM,MAAM,EAAE;IACX,OAAO,KAAK;EACd;EACA,MAAMC,MAAM,GAAGT,aAAa,CAACG,CAAC,CAAC;EAC/B,IAAIM,MAAM,IAAID,MAAM,CAACF,MAAM,KAAKG,MAAM,CAACH,MAAM,EAAE;IAC7C,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,MAAM,CAACF,MAAM,EAAE,EAAEI,CAAC,EAAE;MACtC,IAAID,MAAM,CAACC,CAAC,CAAC,KAAKF,MAAM,CAACE,CAAC,CAAC,EAAE;QAC3B,OAAO,KAAK;MACd;IACF;EACF;EACA,OAAO,IAAI;AACb;AAGA,OAAO,SAASC,SAASA,CAAIT,CAAI,EAAK;EACpC,MAAMU,WAAW,GAAGZ,aAAa,CAACE,CAAC,CAAC;EACpC,IAAIU,WAAW,EAAE;IACf,OAAOA,WAAW,CAACC,KAAK,CAAC,CAAC;EAC5B;EACA,OAAOX,CAAC;AACV"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TypedArray, NumberArray } from '../types';
|
|
2
|
+
export declare function getScratchArrayBuffer(byteLength: number): ArrayBuffer;
|
|
3
|
+
export declare function getScratchArray(Type: any, length: number): TypedArray;
|
|
4
|
+
export declare function fillArray(options: {
|
|
5
|
+
target: NumberArray;
|
|
6
|
+
source: NumberArray;
|
|
7
|
+
start?: number;
|
|
8
|
+
count?: number;
|
|
9
|
+
}): NumberArray;
|
|
10
|
+
//# sourceMappingURL=array-utils-flat.d.ts.map
|