@luma.gl/core 9.0.0-beta.4 → 9.0.0-beta.6
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/attribute-utils/get-attribute-from-layouts.d.ts +4 -4
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +1 -1
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +138 -106
- package/dist/adapter/canvas-context.d.ts +2 -2
- package/dist/adapter/canvas-context.d.ts.map +1 -1
- package/dist/adapter/canvas-context.js +306 -232
- package/dist/adapter/device.d.ts +112 -69
- package/dist/adapter/device.d.ts.map +1 -1
- package/dist/adapter/device.js +145 -94
- package/dist/adapter/resources/buffer.d.ts +3 -3
- package/dist/adapter/resources/buffer.d.ts.map +1 -1
- package/dist/adapter/resources/buffer.js +70 -56
- package/dist/adapter/resources/command-buffer.d.ts +2 -2
- package/dist/adapter/resources/command-buffer.d.ts.map +1 -1
- package/dist/adapter/resources/command-buffer.js +15 -12
- package/dist/adapter/resources/command-encoder.d.ts +22 -7
- package/dist/adapter/resources/command-encoder.d.ts.map +1 -1
- package/dist/adapter/resources/command-encoder.js +16 -16
- package/dist/adapter/resources/compute-pass.d.ts +16 -5
- package/dist/adapter/resources/compute-pass.d.ts.map +1 -1
- package/dist/adapter/resources/compute-pass.js +15 -12
- package/dist/adapter/resources/compute-pipeline.d.ts +4 -4
- package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/compute-pipeline.js +20 -17
- package/dist/adapter/resources/external-texture.d.ts +2 -2
- package/dist/adapter/resources/external-texture.d.ts.map +1 -1
- package/dist/adapter/resources/external-texture.js +14 -14
- package/dist/adapter/resources/framebuffer.d.ts +9 -8
- package/dist/adapter/resources/framebuffer.d.ts.map +1 -1
- package/dist/adapter/resources/framebuffer.js +191 -91
- package/dist/adapter/resources/query-set.d.ts +26 -0
- package/dist/adapter/resources/query-set.d.ts.map +1 -0
- package/dist/adapter/resources/query-set.js +18 -0
- package/dist/adapter/resources/render-pass.d.ts +22 -9
- package/dist/adapter/resources/render-pass.d.ts.map +1 -1
- package/dist/adapter/resources/render-pass.js +34 -20
- package/dist/adapter/resources/render-pipeline.d.ts +22 -18
- package/dist/adapter/resources/render-pipeline.d.ts.map +1 -1
- package/dist/adapter/resources/render-pipeline.js +50 -33
- package/dist/adapter/resources/resource.d.ts +1 -1
- package/dist/adapter/resources/resource.d.ts.map +1 -1
- package/dist/adapter/resources/resource.js +133 -92
- package/dist/adapter/resources/sampler.d.ts +3 -3
- package/dist/adapter/resources/sampler.d.ts.map +1 -1
- package/dist/adapter/resources/sampler.js +24 -23
- package/dist/adapter/resources/shader.d.ts +8 -6
- package/dist/adapter/resources/shader.d.ts.map +1 -1
- package/dist/adapter/resources/shader.js +98 -74
- package/dist/adapter/resources/texture-view.d.ts +32 -0
- package/dist/adapter/resources/texture-view.d.ts.map +1 -0
- package/dist/adapter/resources/texture-view.js +24 -0
- package/dist/adapter/resources/texture.d.ts +10 -15
- package/dist/adapter/resources/texture.d.ts.map +1 -1
- package/dist/adapter/resources/texture.js +54 -42
- package/dist/adapter/resources/transform-feedback.d.ts +7 -7
- package/dist/adapter/resources/transform-feedback.d.ts.map +1 -1
- package/dist/adapter/resources/transform-feedback.js +15 -14
- package/dist/adapter/resources/vertex-array.d.ts +9 -9
- package/dist/adapter/resources/vertex-array.d.ts.map +1 -1
- package/dist/adapter/resources/vertex-array.js +36 -20
- package/dist/adapter/type-utils/decode-attribute-type.d.ts +2 -2
- package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +1 -1
- package/dist/adapter/type-utils/decode-attribute-type.js +59 -52
- package/dist/adapter/type-utils/decode-data-type.d.ts +1 -1
- package/dist/adapter/type-utils/decode-data-type.d.ts.map +1 -1
- package/dist/adapter/type-utils/decode-data-type.js +39 -35
- package/dist/adapter/type-utils/decode-shader-types.d.ts +1 -1
- package/dist/adapter/type-utils/decode-shader-types.d.ts.map +1 -1
- package/dist/adapter/type-utils/decode-shader-types.js +36 -96
- package/dist/adapter/type-utils/decode-texture-format.d.ts +6 -2
- package/dist/adapter/type-utils/decode-texture-format.d.ts.map +1 -1
- package/dist/adapter/type-utils/decode-texture-format.js +172 -92
- package/dist/adapter/type-utils/decode-vertex-format.d.ts +1 -1
- package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +1 -1
- package/dist/adapter/type-utils/decode-vertex-format.js +30 -22
- package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts +2 -2
- package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +1 -1
- package/dist/adapter/type-utils/vertex-format-from-attribute.js +72 -65
- package/dist/adapter/type-utils/wgsl-utils.d.ts +1 -1
- package/dist/adapter/type-utils/wgsl-utils.d.ts.map +1 -1
- package/dist/adapter/type-utils/wgsl-utils.js +17 -13
- package/dist/adapter/types/accessor.d.ts +1 -1
- package/dist/adapter/types/accessor.d.ts.map +1 -1
- package/dist/adapter/types/accessor.js +3 -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/buffer-layout.js +3 -1
- package/dist/adapter/types/parameters.d.ts +28 -6
- package/dist/adapter/types/parameters.d.ts.map +1 -1
- package/dist/adapter/types/parameters.js +46 -26
- package/dist/adapter/types/shader-layout.d.ts +8 -7
- package/dist/adapter/types/shader-layout.d.ts.map +1 -1
- package/dist/adapter/types/shader-layout.js +3 -1
- package/dist/adapter/types/shader-types.d.ts.map +1 -1
- package/dist/adapter/types/shader-types.js +3 -1
- package/dist/adapter/types/texture-formats.d.ts +2 -2
- package/dist/adapter/types/texture-formats.d.ts.map +1 -1
- package/dist/adapter/types/texture-formats.js +3 -1
- package/dist/adapter/types/types.d.ts +4 -4
- package/dist/adapter/types/types.d.ts.map +1 -1
- package/dist/adapter/types/types.js +3 -1
- package/dist/adapter/types/vertex-formats.d.ts.map +1 -1
- package/dist/adapter/types/vertex-formats.js +3 -1
- package/dist/dist.dev.js +614 -406
- package/dist/index.cjs +344 -369
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +80 -76
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -5
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +30 -17
- package/dist/lib/compiler-log/compiler-message.d.ts.map +1 -1
- package/dist/lib/compiler-log/compiler-message.js +3 -1
- package/dist/lib/compiler-log/format-compiler-log.d.ts +1 -1
- package/dist/lib/compiler-log/format-compiler-log.d.ts.map +1 -1
- package/dist/lib/compiler-log/format-compiler-log.js +69 -48
- package/dist/lib/compiler-log/get-shader-info.d.ts.map +1 -1
- package/dist/lib/compiler-log/get-shader-info.js +23 -19
- package/dist/lib/luma.d.ts +3 -3
- package/dist/lib/luma.d.ts.map +1 -1
- package/dist/lib/luma.js +60 -51
- package/dist/lib/uniforms/uniform-block.d.ts +3 -4
- package/dist/lib/uniforms/uniform-block.d.ts.map +1 -1
- package/dist/lib/uniforms/uniform-block.js +52 -42
- package/dist/lib/uniforms/uniform-buffer-layout.d.ts +2 -2
- package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +1 -1
- package/dist/lib/uniforms/uniform-buffer-layout.js +86 -66
- package/dist/lib/uniforms/uniform-store.d.ts +6 -6
- package/dist/lib/uniforms/uniform-store.d.ts.map +1 -1
- package/dist/lib/uniforms/uniform-store.js +111 -75
- package/dist/lib/uniforms/uniform.d.ts +2 -2
- package/dist/lib/uniforms/uniform.d.ts.map +1 -1
- package/dist/lib/uniforms/uniform.js +15 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -3
- package/dist/utils/array-equal.d.ts.map +1 -1
- package/dist/utils/array-equal.js +25 -22
- package/dist/utils/array-utils-flat.d.ts +1 -1
- package/dist/utils/array-utils-flat.d.ts.map +1 -1
- package/dist/utils/array-utils-flat.js +29 -28
- package/dist/utils/assert.d.ts.map +1 -1
- package/dist/utils/assert.js +8 -4
- package/dist/utils/cast.d.ts.map +1 -1
- package/dist/utils/cast.js +5 -2
- package/dist/utils/check-props.d.ts.map +1 -1
- package/dist/utils/check-props.js +30 -26
- package/dist/utils/deep-equal.d.ts.map +1 -1
- package/dist/utils/deep-equal.js +42 -32
- package/dist/utils/format-value.d.ts +1 -1
- package/dist/utils/format-value.d.ts.map +1 -1
- package/dist/utils/format-value.js +36 -39
- package/dist/utils/is-array.d.ts +1 -1
- package/dist/utils/is-array.d.ts.map +1 -1
- package/dist/utils/is-array.js +20 -6
- package/dist/utils/load-file.d.ts.map +1 -1
- package/dist/utils/load-file.js +63 -37
- package/dist/utils/log.d.ts.map +1 -1
- package/dist/utils/log.js +5 -4
- package/dist/utils/random.d.ts.map +1 -1
- package/dist/utils/random.js +13 -9
- package/dist/utils/request-animation-frame.d.ts.map +1 -1
- package/dist/utils/request-animation-frame.js +12 -3
- package/dist/utils/stats-manager.d.ts.map +1 -1
- package/dist/utils/stats-manager.js +16 -14
- package/dist/utils/stub-methods.d.ts.map +1 -1
- package/dist/utils/stub-methods.js +15 -12
- package/dist/utils/utils.d.ts +0 -6
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +21 -15
- package/dist.min.js +8 -23
- package/package.json +6 -6
- package/src/adapter/attribute-utils/get-attribute-from-layouts.ts +6 -5
- package/src/adapter/canvas-context.ts +8 -5
- package/src/adapter/device.ts +181 -127
- package/src/adapter/resources/buffer.ts +19 -6
- package/src/adapter/resources/command-buffer.ts +7 -5
- package/src/adapter/resources/command-encoder.ts +40 -29
- package/src/adapter/resources/compute-pass.ts +23 -9
- package/src/adapter/resources/compute-pipeline.ts +5 -2
- package/src/adapter/resources/external-texture.ts +8 -2
- package/src/adapter/resources/framebuffer.ts +115 -102
- package/src/adapter/resources/query-set.ts +41 -0
- package/src/adapter/resources/render-pass.ts +48 -54
- package/src/adapter/resources/render-pipeline.ts +22 -9
- package/src/adapter/resources/resource.ts +13 -10
- package/src/adapter/resources/sampler.ts +4 -3
- package/src/adapter/resources/shader.ts +19 -7
- package/src/adapter/resources/texture-view.ts +51 -0
- package/src/adapter/resources/texture.ts +28 -26
- package/src/adapter/resources/transform-feedback.ts +6 -3
- package/src/adapter/resources/vertex-array.ts +11 -3
- package/src/adapter/type-utils/decode-attribute-type.ts +24 -10
- package/src/adapter/type-utils/decode-data-type.ts +5 -1
- package/src/adapter/type-utils/decode-shader-types.ts +12 -9
- package/src/adapter/type-utils/decode-texture-format.ts +28 -12
- package/src/adapter/type-utils/decode-vertex-format.ts +4 -0
- package/src/adapter/type-utils/vertex-format-from-attribute.ts +4 -1
- package/src/adapter/type-utils/wgsl-utils.ts +6 -2
- package/src/adapter/types/accessor.ts +5 -2
- package/src/adapter/types/buffer-layout.ts +11 -8
- package/src/adapter/types/parameters.ts +98 -93
- package/src/adapter/types/shader-layout.ts +11 -2
- package/src/adapter/types/shader-types.ts +2 -1
- package/src/adapter/types/texture-formats.ts +130 -129
- package/src/adapter/types/types.ts +12 -6
- package/src/adapter/types/vertex-formats.ts +4 -5
- package/src/index.ts +30 -15
- package/src/init.ts +10 -4
- package/src/lib/compiler-log/compiler-message.ts +3 -2
- package/src/lib/compiler-log/format-compiler-log.ts +8 -3
- package/src/lib/compiler-log/get-shader-info.ts +2 -1
- package/src/lib/luma.ts +13 -8
- package/src/lib/uniforms/uniform-block.ts +7 -3
- package/src/lib/uniforms/uniform-buffer-layout.ts +16 -10
- package/src/lib/uniforms/uniform-store.ts +4 -1
- package/src/lib/uniforms/uniform.ts +12 -6
- package/src/types.ts +7 -3
- package/src/utils/array-equal.ts +2 -1
- package/src/utils/array-utils-flat.ts +9 -3
- package/src/utils/assert.ts +4 -0
- package/src/utils/cast.ts +4 -0
- package/src/utils/check-props.ts +9 -1
- package/src/utils/deep-equal.ts +4 -0
- package/src/utils/format-value.ts +9 -2
- package/src/utils/is-array.ts +4 -0
- package/src/utils/load-file.ts +5 -3
- package/src/utils/log.ts +4 -0
- package/src/utils/random.ts +4 -0
- package/src/utils/request-animation-frame.ts +4 -0
- package/src/utils/stats-manager.ts +6 -2
- package/src/utils/stub-methods.ts +10 -1
- package/src/utils/utils.ts +2 -10
- package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +0 -1
- package/dist/adapter/canvas-context.js.map +0 -1
- package/dist/adapter/device.js.map +0 -1
- package/dist/adapter/resources/buffer.js.map +0 -1
- package/dist/adapter/resources/command-buffer.js.map +0 -1
- package/dist/adapter/resources/command-encoder.js.map +0 -1
- package/dist/adapter/resources/compute-pass.js.map +0 -1
- package/dist/adapter/resources/compute-pipeline.js.map +0 -1
- package/dist/adapter/resources/external-texture.js.map +0 -1
- package/dist/adapter/resources/framebuffer.js.map +0 -1
- package/dist/adapter/resources/render-pass.js.map +0 -1
- package/dist/adapter/resources/render-pipeline.js.map +0 -1
- package/dist/adapter/resources/resource.js.map +0 -1
- package/dist/adapter/resources/sampler.js.map +0 -1
- package/dist/adapter/resources/shader.js.map +0 -1
- package/dist/adapter/resources/texture.js.map +0 -1
- package/dist/adapter/resources/transform-feedback.js.map +0 -1
- package/dist/adapter/resources/vertex-array.js.map +0 -1
- package/dist/adapter/type-utils/decode-attribute-type.js.map +0 -1
- package/dist/adapter/type-utils/decode-data-type.js.map +0 -1
- package/dist/adapter/type-utils/decode-shader-types.js.map +0 -1
- package/dist/adapter/type-utils/decode-texture-format.js.map +0 -1
- package/dist/adapter/type-utils/decode-vertex-format.js.map +0 -1
- package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +0 -1
- package/dist/adapter/type-utils/wgsl-utils.js.map +0 -1
- package/dist/adapter/types/accessor.js.map +0 -1
- package/dist/adapter/types/buffer-layout.js.map +0 -1
- package/dist/adapter/types/parameters.js.map +0 -1
- package/dist/adapter/types/shader-layout.js.map +0 -1
- package/dist/adapter/types/shader-types.js.map +0 -1
- package/dist/adapter/types/texture-formats.js.map +0 -1
- package/dist/adapter/types/types.js.map +0 -1
- package/dist/adapter/types/vertex-formats.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/init.js.map +0 -1
- package/dist/lib/compiler-log/compiler-message.js.map +0 -1
- package/dist/lib/compiler-log/format-compiler-log.js.map +0 -1
- package/dist/lib/compiler-log/get-shader-info.js.map +0 -1
- package/dist/lib/luma.js.map +0 -1
- package/dist/lib/uniforms/uniform-block.js.map +0 -1
- package/dist/lib/uniforms/uniform-buffer-layout.js.map +0 -1
- package/dist/lib/uniforms/uniform-store.js.map +0 -1
- package/dist/lib/uniforms/uniform.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/array-equal.js.map +0 -1
- package/dist/utils/array-utils-flat.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/cast.js.map +0 -1
- package/dist/utils/check-props.js.map +0 -1
- package/dist/utils/deep-equal.js.map +0 -1
- package/dist/utils/format-value.js.map +0 -1
- package/dist/utils/is-array.js.map +0 -1
- package/dist/utils/load-file.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/random.js.map +0 -1
- package/dist/utils/request-animation-frame.js.map +0 -1
- package/dist/utils/stats-manager.js.map +0 -1
- package/dist/utils/stub-methods.js.map +0 -1
- package/dist/utils/utils.js.map +0 -1
|
@@ -1,101 +1,142 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { uid } from "../../utils/utils.js";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for GPU (WebGPU/WebGL) Resources
|
|
7
|
+
*/
|
|
2
8
|
export class Resource {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
/** Default properties for resource */
|
|
10
|
+
static defaultProps = {
|
|
11
|
+
id: 'undefined',
|
|
12
|
+
handle: undefined,
|
|
13
|
+
userData: undefined
|
|
14
|
+
};
|
|
15
|
+
/** props.id, for debugging. */
|
|
16
|
+
id;
|
|
17
|
+
props;
|
|
18
|
+
userData = {};
|
|
19
|
+
_device;
|
|
20
|
+
/** Whether this resource has been destroyed */
|
|
21
|
+
destroyed = false;
|
|
22
|
+
/** For resources that allocate GPU memory */
|
|
23
|
+
allocatedBytes = 0;
|
|
24
|
+
/** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
|
|
25
|
+
_attachedResources = new Set();
|
|
26
|
+
/**
|
|
27
|
+
* Create a new Resource. Called from Subclass
|
|
28
|
+
*/
|
|
29
|
+
constructor(device, props, defaultProps) {
|
|
30
|
+
if (!device) {
|
|
31
|
+
throw new Error('no device');
|
|
32
|
+
}
|
|
33
|
+
this._device = device;
|
|
34
|
+
this.props = selectivelyMerge(props, defaultProps);
|
|
35
|
+
const id = this.props.id !== 'undefined' ? this.props.id : uid(this[Symbol.toStringTag]);
|
|
36
|
+
this.props.id = id;
|
|
37
|
+
this.id = id;
|
|
38
|
+
this.userData = this.props.userData || {};
|
|
39
|
+
this.addStats();
|
|
14
40
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.userData = this.props.userData || {};
|
|
21
|
-
this.addStats();
|
|
22
|
-
}
|
|
23
|
-
destroy() {
|
|
24
|
-
this.destroyResource();
|
|
25
|
-
}
|
|
26
|
-
delete() {
|
|
27
|
-
this.destroy();
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
toString() {
|
|
31
|
-
return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
|
|
32
|
-
}
|
|
33
|
-
getProps() {
|
|
34
|
-
return this.props;
|
|
35
|
-
}
|
|
36
|
-
attachResource(resource) {
|
|
37
|
-
this._attachedResources.add(resource);
|
|
38
|
-
}
|
|
39
|
-
detachResource(resource) {
|
|
40
|
-
this._attachedResources.delete(resource);
|
|
41
|
-
}
|
|
42
|
-
destroyAttachedResource(resource) {
|
|
43
|
-
if (this._attachedResources.delete(resource)) {
|
|
44
|
-
resource.destroy();
|
|
41
|
+
/**
|
|
42
|
+
* destroy can be called on any resource to release it before it is garbage collected.
|
|
43
|
+
*/
|
|
44
|
+
destroy() {
|
|
45
|
+
this.destroyResource();
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
/** @deprecated Use destroy() */
|
|
48
|
+
delete() {
|
|
49
|
+
this.destroy();
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
toString() {
|
|
53
|
+
return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Combines a map of user props and default props, only including props from defaultProps
|
|
57
|
+
* @returns returns a map of overridden default props
|
|
58
|
+
*/
|
|
59
|
+
getProps() {
|
|
60
|
+
return this.props;
|
|
61
|
+
}
|
|
62
|
+
// ATTACHED RESOURCES
|
|
63
|
+
/**
|
|
64
|
+
* Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
|
|
65
|
+
* Called automatically when sub resources are auto created but can be called by application
|
|
66
|
+
*/
|
|
67
|
+
attachResource(resource) {
|
|
68
|
+
this._attachedResources.add(resource);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
|
|
72
|
+
*/
|
|
73
|
+
detachResource(resource) {
|
|
74
|
+
this._attachedResources.delete(resource);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
|
|
78
|
+
*/
|
|
79
|
+
destroyAttachedResource(resource) {
|
|
80
|
+
if (this._attachedResources.delete(resource)) {
|
|
81
|
+
resource.destroy();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
|
|
85
|
+
destroyAttachedResources() {
|
|
86
|
+
for (const resource of Object.values(this._attachedResources)) {
|
|
87
|
+
resource.destroy();
|
|
88
|
+
}
|
|
89
|
+
// don't remove while we are iterating
|
|
90
|
+
this._attachedResources = new Set();
|
|
91
|
+
}
|
|
92
|
+
// PROTECTED METHODS
|
|
93
|
+
/** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
|
|
94
|
+
destroyResource() {
|
|
95
|
+
this.destroyAttachedResources();
|
|
96
|
+
this.removeStats();
|
|
97
|
+
this.destroyed = true;
|
|
98
|
+
}
|
|
99
|
+
/** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
|
|
100
|
+
removeStats() {
|
|
101
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
102
|
+
const name = this[Symbol.toStringTag];
|
|
103
|
+
stats.get(`${name}s Active`).decrementCount();
|
|
104
|
+
}
|
|
105
|
+
/** Called by subclass to track memory allocations */
|
|
106
|
+
trackAllocatedMemory(bytes, name = this[Symbol.toStringTag]) {
|
|
107
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
108
|
+
stats.get('GPU Memory').addCount(bytes);
|
|
109
|
+
stats.get(`${name} Memory`).addCount(bytes);
|
|
110
|
+
this.allocatedBytes = bytes;
|
|
111
|
+
}
|
|
112
|
+
/** Called by subclass to track memory deallocations */
|
|
113
|
+
trackDeallocatedMemory(name = this[Symbol.toStringTag]) {
|
|
114
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
115
|
+
stats.get('GPU Memory').subtractCount(this.allocatedBytes);
|
|
116
|
+
stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
|
|
117
|
+
this.allocatedBytes = 0;
|
|
118
|
+
}
|
|
119
|
+
/** Called by resource constructor to track object creation */
|
|
120
|
+
addStats() {
|
|
121
|
+
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
122
|
+
const name = this[Symbol.toStringTag];
|
|
123
|
+
stats.get('Resources Created').incrementCount();
|
|
124
|
+
stats.get(`${name}s Created`).incrementCount();
|
|
125
|
+
stats.get(`${name}s Active`).incrementCount();
|
|
50
126
|
}
|
|
51
|
-
this._attachedResources = new Set();
|
|
52
|
-
}
|
|
53
|
-
destroyResource() {
|
|
54
|
-
this.destroyAttachedResources();
|
|
55
|
-
this.removeStats();
|
|
56
|
-
this.destroyed = true;
|
|
57
|
-
}
|
|
58
|
-
removeStats() {
|
|
59
|
-
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
60
|
-
const name = this[Symbol.toStringTag];
|
|
61
|
-
stats.get(`${name}s Active`).decrementCount();
|
|
62
|
-
}
|
|
63
|
-
trackAllocatedMemory(bytes) {
|
|
64
|
-
let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this[Symbol.toStringTag];
|
|
65
|
-
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
66
|
-
stats.get('GPU Memory').addCount(bytes);
|
|
67
|
-
stats.get(`${name} Memory`).addCount(bytes);
|
|
68
|
-
this.allocatedBytes = bytes;
|
|
69
|
-
}
|
|
70
|
-
trackDeallocatedMemory() {
|
|
71
|
-
let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this[Symbol.toStringTag];
|
|
72
|
-
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
73
|
-
stats.get('GPU Memory').subtractCount(this.allocatedBytes);
|
|
74
|
-
stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);
|
|
75
|
-
this.allocatedBytes = 0;
|
|
76
|
-
}
|
|
77
|
-
addStats() {
|
|
78
|
-
const stats = this._device.statsManager.getStats('Resource Counts');
|
|
79
|
-
const name = this[Symbol.toStringTag];
|
|
80
|
-
stats.get('Resources Created').incrementCount();
|
|
81
|
-
stats.get(`${name}s Created`).incrementCount();
|
|
82
|
-
stats.get(`${name}s Active`).incrementCount();
|
|
83
|
-
}
|
|
84
127
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Combines a map of user props and default props, only including props from defaultProps
|
|
130
|
+
* @param props
|
|
131
|
+
* @param defaultProps
|
|
132
|
+
* @returns returns a map of overridden default props
|
|
133
|
+
*/
|
|
90
134
|
function selectivelyMerge(props, defaultProps) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
mergedProps[key] = props[key];
|
|
135
|
+
const mergedProps = { ...defaultProps };
|
|
136
|
+
for (const key in props) {
|
|
137
|
+
if (props[key] !== undefined) {
|
|
138
|
+
mergedProps[key] = props[key];
|
|
139
|
+
}
|
|
97
140
|
}
|
|
98
|
-
|
|
99
|
-
return mergedProps;
|
|
141
|
+
return mergedProps;
|
|
100
142
|
}
|
|
101
|
-
//# sourceMappingURL=resource.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Device } from
|
|
2
|
-
import { CompareFunction } from
|
|
3
|
-
import { Resource, ResourceProps } from
|
|
1
|
+
import type { Device } from "../device.js";
|
|
2
|
+
import { CompareFunction } from "../types/parameters.js";
|
|
3
|
+
import { Resource, ResourceProps } from "./resource.js";
|
|
4
4
|
/** Edge values sampling mode */
|
|
5
5
|
export type SamplerAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
6
6
|
/** Sampler filtering mode */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/sampler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/sampler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,qBAAkB;AACtC,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,sBAAmB;AAEnD,gCAAgC;AAChC,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG,QAAQ,GAAG,eAAe,CAAC;AAE9E,6BAA6B;AAC7B,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IACzC,iGAAiG;IACjG,IAAI,CAAC,EAAE,eAAe,GAAG,oBAAoB,CAAC;IAC9C,yCAAyC;IACzC,YAAY,CAAC,EAAE,eAAe,GAAG,QAAQ,GAAG,eAAe,CAAC;IAC5D,yCAAyC;IACzC,YAAY,CAAC,EAAE,eAAe,GAAG,QAAQ,GAAG,eAAe,CAAC;IAC5D,yCAAyC;IACzC,YAAY,CAAC,EAAE,eAAe,GAAG,QAAQ,GAAG,eAAe,CAAC;IAE5D,uFAAuF;IACvF,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjC,qFAAqF;IACrF,SAAS,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjC,iHAAiH;IACjH,YAAY,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACpC,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8FAA8F;IAC9F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iHAAiH;IACjH,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,aAAa,CAAC,CAAC;AAExE,+BAA+B;AAC/B,8BAAsB,OAAQ,SAAQ,QAAQ,CAAC,YAAY,CAAC;IAC1D,OAAgB,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,CAalD;IAEF,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;gBAEW,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY;CAGhD"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
2
4
|
import { Resource } from "./resource.js";
|
|
3
|
-
|
|
5
|
+
/** Immutable Sampler object */
|
|
4
6
|
export class Sampler extends Resource {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
static defaultProps = {
|
|
8
|
+
...Resource.defaultProps,
|
|
9
|
+
type: 'color-sampler',
|
|
10
|
+
addressModeU: 'clamp-to-edge',
|
|
11
|
+
addressModeV: 'clamp-to-edge',
|
|
12
|
+
addressModeW: 'clamp-to-edge',
|
|
13
|
+
magFilter: 'nearest',
|
|
14
|
+
minFilter: 'nearest',
|
|
15
|
+
mipmapFilter: 'nearest',
|
|
16
|
+
lodMinClamp: 0,
|
|
17
|
+
lodMaxClamp: 32, // Per WebGPU spec
|
|
18
|
+
compare: 'less-equal',
|
|
19
|
+
maxAnisotropy: 1
|
|
20
|
+
};
|
|
21
|
+
get [Symbol.toStringTag]() {
|
|
22
|
+
return 'Sampler';
|
|
23
|
+
}
|
|
24
|
+
constructor(device, props) {
|
|
25
|
+
super(device, props, Sampler.defaultProps);
|
|
26
|
+
}
|
|
11
27
|
}
|
|
12
|
-
Sampler.defaultProps = {
|
|
13
|
-
...Resource.defaultProps,
|
|
14
|
-
type: 'color-sampler',
|
|
15
|
-
addressModeU: 'clamp-to-edge',
|
|
16
|
-
addressModeV: 'clamp-to-edge',
|
|
17
|
-
addressModeW: 'clamp-to-edge',
|
|
18
|
-
magFilter: 'nearest',
|
|
19
|
-
minFilter: 'nearest',
|
|
20
|
-
mipmapFilter: 'nearest',
|
|
21
|
-
lodMinClamp: 0,
|
|
22
|
-
lodMaxClamp: 32,
|
|
23
|
-
compare: 'less-equal',
|
|
24
|
-
maxAnisotropy: 1
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=sampler.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Device } from
|
|
2
|
-
import { Resource, ResourceProps } from
|
|
3
|
-
import { CompilerMessage } from
|
|
1
|
+
import type { Device } from "../device.js";
|
|
2
|
+
import { Resource, ResourceProps } from "./resource.js";
|
|
3
|
+
import { CompilerMessage } from "../../lib/compiler-log/compiler-message.js";
|
|
4
4
|
/**
|
|
5
5
|
* Properties for a Shader
|
|
6
6
|
*/
|
|
@@ -29,16 +29,18 @@ export declare abstract class Shader extends Resource<ShaderProps> {
|
|
|
29
29
|
readonly stage: 'vertex' | 'fragment' | 'compute';
|
|
30
30
|
/** The source code of this shader */
|
|
31
31
|
readonly source: string;
|
|
32
|
-
/** The compilation status of
|
|
33
|
-
compilationStatus: '
|
|
32
|
+
/** The compilation status of the shader. 'pending' if compilation is asynchronous, and on production */
|
|
33
|
+
compilationStatus: 'pending' | 'success' | 'error';
|
|
34
34
|
/** Create a new Shader instance */
|
|
35
35
|
constructor(device: Device, props: ShaderProps);
|
|
36
36
|
/** Get compiler log asynchronously */
|
|
37
37
|
abstract getCompilationInfo(): Promise<readonly CompilerMessage[]>;
|
|
38
38
|
/** Get compiler log synchronously (WebGL only) */
|
|
39
39
|
getCompilationInfoSync(): readonly CompilerMessage[] | null;
|
|
40
|
+
/** Get translated shader source in host platform's native language (HLSL, GLSL, and even GLSL ES), if available */
|
|
41
|
+
getTranslatedSource(): string | null;
|
|
40
42
|
/** In browser logging of errors */
|
|
41
|
-
debugShader(): Promise<void>;
|
|
43
|
+
debugShader(trigger?: "never" | "errors" | "warnings" | "always"): Promise<void>;
|
|
42
44
|
/** In-browser UI logging of errors */
|
|
43
45
|
protected _displayShaderLog(messages: readonly CompilerMessage[]): void;
|
|
44
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/shader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/shader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,qBAAkB;AACtC,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,sBAAmB;AAGnD,OAAO,EAAC,eAAe,EAAC,mDAAgD;AAIxE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG;IACxC,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACpC,0EAA0E;IAC1E,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IACzC,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,8BAAsB,MAAO,SAAQ,QAAQ,CAAC,WAAW,CAAC;IACxD,OAAgB,YAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,CAQjD;IAEF,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,+BAA+B;IAC/B,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;IAClD,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wGAAwG;IACxG,iBAAiB,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAa;IAE/D,mCAAmC;gBACvB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAM9C,sCAAsC;IACtC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IAElE,kDAAkD;IAClD,sBAAsB,IAAI,SAAS,eAAe,EAAE,GAAG,IAAI;IAI3D,mHAAmH;IACnH,mBAAmB,IAAI,MAAM,GAAG,IAAI;IAMpC,mCAAmC;IAC7B,WAAW,CAAC,OAAO,6CAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB5D,sCAAsC;IACtC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,IAAI;CA2CxE"}
|
|
@@ -1,90 +1,114 @@
|
|
|
1
|
-
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
2
4
|
import { Resource } from "./resource.js";
|
|
5
|
+
// import { log } from '../../utils/log';
|
|
3
6
|
import { uid } from "../../utils/utils.js";
|
|
4
7
|
import { formatCompilerLog } from "../../lib/compiler-log/format-compiler-log.js";
|
|
5
8
|
import { getShaderInfo } from "../../lib/compiler-log/get-shader-info.js";
|
|
6
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Immutable Shader object
|
|
11
|
+
* In WebGPU the handle can be copied between threads
|
|
12
|
+
*/
|
|
7
13
|
export class Shader extends Resource {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
case 'warnings':
|
|
35
|
-
case 'always':
|
|
36
|
-
break;
|
|
14
|
+
static defaultProps = {
|
|
15
|
+
...Resource.defaultProps,
|
|
16
|
+
language: 'auto',
|
|
17
|
+
stage: 'vertex',
|
|
18
|
+
source: '',
|
|
19
|
+
sourceMap: null,
|
|
20
|
+
entryPoint: 'main',
|
|
21
|
+
debug: 'errors'
|
|
22
|
+
};
|
|
23
|
+
get [Symbol.toStringTag]() {
|
|
24
|
+
return 'Shader';
|
|
25
|
+
}
|
|
26
|
+
/** The stage of this shader */
|
|
27
|
+
stage;
|
|
28
|
+
/** The source code of this shader */
|
|
29
|
+
source;
|
|
30
|
+
/** The compilation status of the shader. 'pending' if compilation is asynchronous, and on production */
|
|
31
|
+
compilationStatus = 'pending';
|
|
32
|
+
/** Create a new Shader instance */
|
|
33
|
+
constructor(device, props) {
|
|
34
|
+
super(device, { id: getShaderIdFromProps(props), ...props }, Shader.defaultProps);
|
|
35
|
+
this.stage = this.props.stage;
|
|
36
|
+
this.source = this.props.source;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
/** Get compiler log synchronously (WebGL only) */
|
|
39
|
+
getCompilationInfoSync() {
|
|
40
|
+
return null;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
/** Get translated shader source in host platform's native language (HLSL, GLSL, and even GLSL ES), if available */
|
|
43
|
+
getTranslatedSource() {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
// PORTABLE HELPERS
|
|
47
|
+
/** In browser logging of errors */
|
|
48
|
+
async debugShader(trigger = this.props.debug) {
|
|
49
|
+
switch (trigger) {
|
|
50
|
+
case 'never':
|
|
51
|
+
return;
|
|
52
|
+
case 'errors':
|
|
53
|
+
// On WebGL - Don't extract the log unless errors
|
|
54
|
+
if (this.compilationStatus === 'success') {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'warnings':
|
|
59
|
+
case 'always':
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
const messages = await this.getCompilationInfo();
|
|
63
|
+
if (this.props.debug === 'warnings' && messages?.length === 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this._displayShaderLog(messages);
|
|
48
67
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
// PRIVATE
|
|
69
|
+
/** In-browser UI logging of errors */
|
|
70
|
+
_displayShaderLog(messages) {
|
|
71
|
+
// Return if under Node.js / incomplete `document` polyfills
|
|
72
|
+
if (typeof document === 'undefined' || !document?.createElement) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const shaderName = getShaderInfo(this.source).name;
|
|
76
|
+
const shaderTitle = `${this.stage} ${shaderName}`;
|
|
77
|
+
let htmlLog = formatCompilerLog(messages, this.source, { showSourceCode: 'all', html: true });
|
|
78
|
+
// Show translated source if available
|
|
79
|
+
const translatedSource = this.getTranslatedSource();
|
|
80
|
+
if (translatedSource) {
|
|
81
|
+
htmlLog += `<br /><br /><h1>Translated Source</h1><br /><br /><code style="user-select:text;"><pre>${translatedSource}</pre></code>`;
|
|
82
|
+
}
|
|
83
|
+
// Make it clickable so we can copy to clipboard
|
|
84
|
+
const button = document.createElement('Button');
|
|
85
|
+
button.innerHTML = `
|
|
57
86
|
<h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
|
|
58
87
|
<code style="user-select:text;"><pre>
|
|
59
88
|
${htmlLog}
|
|
60
89
|
</pre></code>`;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
90
|
+
button.style.top = '10px';
|
|
91
|
+
button.style.left = '10px';
|
|
92
|
+
button.style.position = 'absolute';
|
|
93
|
+
button.style.zIndex = '9999';
|
|
94
|
+
button.style.width = '100%';
|
|
95
|
+
button.style.textAlign = 'left';
|
|
96
|
+
document.body.appendChild(button);
|
|
97
|
+
const errors = document.getElementsByClassName('luma-compiler-log-error');
|
|
98
|
+
if (errors[0]?.scrollIntoView) {
|
|
99
|
+
errors[0].scrollIntoView();
|
|
100
|
+
}
|
|
101
|
+
// TODO - add a small embedded copy button (instead of main button)
|
|
102
|
+
button.onclick = () => {
|
|
103
|
+
// const source = this.source.replaceAll('\n', '<br />');
|
|
104
|
+
const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
|
|
105
|
+
navigator.clipboard.writeText(dataURI);
|
|
106
|
+
};
|
|
107
|
+
// TODO - add a small embedded close button
|
|
71
108
|
}
|
|
72
|
-
button.onclick = () => {
|
|
73
|
-
const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
|
|
74
|
-
navigator.clipboard.writeText(dataURI);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
109
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
language: 'auto',
|
|
81
|
-
stage: 'vertex',
|
|
82
|
-
source: '',
|
|
83
|
-
sourceMap: null,
|
|
84
|
-
entryPoint: 'main',
|
|
85
|
-
debug: 'errors'
|
|
86
|
-
};
|
|
110
|
+
// HELPERS
|
|
111
|
+
/** Deduce an id, from shader source, or supplied id, or shader type */
|
|
87
112
|
function getShaderIdFromProps(props) {
|
|
88
|
-
|
|
113
|
+
return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
|
|
89
114
|
}
|
|
90
|
-
//# sourceMappingURL=shader.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Device } from "../device.js";
|
|
2
|
+
import type { Texture } from "./texture.js";
|
|
3
|
+
import type { TextureFormat } from "../types/texture-formats.js";
|
|
4
|
+
import { Resource, ResourceProps } from "./resource.js";
|
|
5
|
+
/** Properties for initializing a texture view */
|
|
6
|
+
export type TextureViewProps = ResourceProps & {
|
|
7
|
+
/** The format of the texture view. Must be either the format of the texture or one of the viewFormats specified during its creation. */
|
|
8
|
+
format?: TextureFormat;
|
|
9
|
+
/** The dimension to view the texture as. */
|
|
10
|
+
dimension?: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
11
|
+
/** Which aspect(s) of the texture are accessible to the texture view. default "all"*/
|
|
12
|
+
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
13
|
+
/** The first (most detailed) mipmap level accessible to the texture view. default 0*/
|
|
14
|
+
baseMipLevel?: number;
|
|
15
|
+
/** How many mipmap levels, starting with baseMipLevel, are accessible to the texture view. */
|
|
16
|
+
mipLevelCount: number;
|
|
17
|
+
/** The index of the first array layer accessible to the texture view. default 0 */
|
|
18
|
+
baseArrayLayer?: number;
|
|
19
|
+
/** How many array layers, starting with baseArrayLayer, are accessible to the texture view. */
|
|
20
|
+
arrayLayerCount: number;
|
|
21
|
+
};
|
|
22
|
+
/** Immutable TextureView object */
|
|
23
|
+
export declare abstract class TextureView extends Resource<TextureViewProps> {
|
|
24
|
+
static defaultProps: Required<TextureViewProps>;
|
|
25
|
+
abstract texture: Texture;
|
|
26
|
+
get [Symbol.toStringTag](): string;
|
|
27
|
+
/** Should not be constructed directly. Use `texture.createView(props)` */
|
|
28
|
+
constructor(device: Device, props: TextureViewProps & {
|
|
29
|
+
texture: Texture;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=texture-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-view.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/texture-view.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,qBAAkB;AACtC,OAAO,KAAK,EAAC,OAAO,EAAC,qBAAkB;AACvC,OAAO,KAAK,EAAC,aAAa,EAAC,oCAAiC;AAC5D,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,sBAAmB;AAEnD,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,wIAAwI;IACxI,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;IACpE,sFAAsF;IACtF,MAAM,CAAC,EAAE,KAAK,GAAG,cAAc,GAAG,YAAY,CAAC;IAC/C,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,aAAa,EAAE,MAAM,CAAC;IACtB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+FAA+F;IAC/F,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,mCAAmC;AACnC,8BAAsB,WAAY,SAAQ,QAAQ,CAAC,gBAAgB,CAAC;IAClE,OAAgB,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAStD;IAEF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,IAAa,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAE1C;IAED,0EAA0E;gBAC9D,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC;CAGzE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Resource } from "./resource.js";
|
|
5
|
+
/** Immutable TextureView object */
|
|
6
|
+
export class TextureView extends Resource {
|
|
7
|
+
static defaultProps = {
|
|
8
|
+
...Resource.defaultProps,
|
|
9
|
+
format: undefined,
|
|
10
|
+
dimension: undefined,
|
|
11
|
+
aspect: 'all',
|
|
12
|
+
baseMipLevel: 0,
|
|
13
|
+
mipLevelCount: undefined,
|
|
14
|
+
baseArrayLayer: 0,
|
|
15
|
+
arrayLayerCount: undefined
|
|
16
|
+
};
|
|
17
|
+
get [Symbol.toStringTag]() {
|
|
18
|
+
return 'TextureView';
|
|
19
|
+
}
|
|
20
|
+
/** Should not be constructed directly. Use `texture.createView(props)` */
|
|
21
|
+
constructor(device, props) {
|
|
22
|
+
super(device, props, TextureView.defaultProps);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { Device } from
|
|
3
|
-
import type { TypedArray } from
|
|
4
|
-
import type { TextureFormat } from
|
|
5
|
-
import { Resource, ResourceProps } from
|
|
6
|
-
import { Sampler, SamplerProps } from
|
|
2
|
+
import type { Device } from "../device.js";
|
|
3
|
+
import type { TypedArray } from "../../types.js";
|
|
4
|
+
import type { TextureFormat } from "../types/texture-formats.js";
|
|
5
|
+
import { Resource, ResourceProps } from "./resource.js";
|
|
6
|
+
import { Sampler, SamplerProps } from "./sampler.js";
|
|
7
|
+
import { TextureView, TextureViewProps } from "./texture-view.js";
|
|
7
8
|
/** Data types that can be used to initialize textures */
|
|
8
9
|
export type TextureData = TypedArray | ArrayBuffer | Buffer | ImageBitmap | HTMLImageElement;
|
|
9
10
|
export type CubeTextureData = Record<string, TextureData> | Record<string, Promise<TextureData>>;
|
|
@@ -18,11 +19,12 @@ export type TextureProps = ResourceProps & {
|
|
|
18
19
|
usage?: number;
|
|
19
20
|
data?: TextureData | Promise<TextureData> | CubeTextureData | string | HTMLVideoElement | null;
|
|
20
21
|
mipmaps?: boolean;
|
|
21
|
-
sampler?: Sampler | SamplerProps;
|
|
22
22
|
mipLevels?: number;
|
|
23
23
|
samples?: number;
|
|
24
24
|
type?: number;
|
|
25
25
|
compressed?: boolean;
|
|
26
|
+
sampler?: Sampler | SamplerProps;
|
|
27
|
+
view?: TextureViewProps;
|
|
26
28
|
};
|
|
27
29
|
export type WebGPUTextureProps = ResourceProps & {
|
|
28
30
|
width: number;
|
|
@@ -31,15 +33,6 @@ export type WebGPUTextureProps = ResourceProps & {
|
|
|
31
33
|
mipLevels?: number;
|
|
32
34
|
format?: string;
|
|
33
35
|
};
|
|
34
|
-
export type TextureViewProps = {
|
|
35
|
-
format: string;
|
|
36
|
-
dimension: '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
|
|
37
|
-
aspect?: 'all' | 'stencil-only' | 'depth-only';
|
|
38
|
-
arrayLayerCount: number;
|
|
39
|
-
baseArrayLayer?: number;
|
|
40
|
-
mipLevels?: number;
|
|
41
|
-
baseMipLevel?: number;
|
|
42
|
-
};
|
|
43
36
|
/**
|
|
44
37
|
* @deprecated
|
|
45
38
|
* @todo remove, are these even used anymore?
|
|
@@ -85,6 +78,8 @@ export declare abstract class Texture<Props extends TextureProps = TextureProps>
|
|
|
85
78
|
readonly depth: number;
|
|
86
79
|
/** Default sampler for this texture */
|
|
87
80
|
abstract sampler: Sampler;
|
|
81
|
+
/** Default view for this texture */
|
|
82
|
+
abstract view: TextureView;
|
|
88
83
|
constructor(device: Device, props: Props, defaultProps?: Required<Props>);
|
|
89
84
|
}
|
|
90
85
|
//# sourceMappingURL=texture.d.ts.map
|