@luma.gl/engine 9.0.0-beta.1 → 9.0.0-beta.10

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.
Files changed (154) hide show
  1. package/dist/animation/key-frames.js +54 -54
  2. package/dist/animation/timeline.d.ts.map +1 -1
  3. package/dist/animation/timeline.js +95 -100
  4. package/dist/animation-loop/animation-loop-template.d.ts +1 -1
  5. package/dist/animation-loop/animation-loop-template.d.ts.map +1 -1
  6. package/dist/animation-loop/animation-loop-template.js +19 -5
  7. package/dist/animation-loop/animation-loop.d.ts +2 -2
  8. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  9. package/dist/animation-loop/animation-loop.js +433 -356
  10. package/dist/animation-loop/animation-props.d.ts +2 -2
  11. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  12. package/dist/animation-loop/animation-props.js +0 -1
  13. package/dist/animation-loop/make-animation-loop.d.ts +2 -2
  14. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  15. package/dist/animation-loop/make-animation-loop.js +28 -24
  16. package/dist/computation.d.ts +95 -0
  17. package/dist/computation.d.ts.map +1 -0
  18. package/dist/computation.js +248 -0
  19. package/dist/debug/copy-texture-to-image.d.ts.map +1 -1
  20. package/dist/debug/copy-texture-to-image.js +39 -42
  21. package/dist/debug/debug-framebuffer.d.ts.map +1 -1
  22. package/dist/debug/debug-framebuffer.js +43 -40
  23. package/dist/debug/debug-shader-layout.js +24 -25
  24. package/dist/debug/pixel-data-utils.d.ts.map +1 -1
  25. package/dist/debug/pixel-data-utils.js +34 -36
  26. package/dist/dist.dev.js +2538 -3027
  27. package/dist/dist.min.js +102 -0
  28. package/dist/geometries/cone-geometry.d.ts +1 -1
  29. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  30. package/dist/geometries/cone-geometry.js +11 -17
  31. package/dist/geometries/cube-geometry.d.ts +1 -1
  32. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  33. package/dist/geometries/cube-geometry.js +190 -61
  34. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  35. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  36. package/dist/geometries/cylinder-geometry.js +9 -14
  37. package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  39. package/dist/geometries/ico-sphere-geometry.js +141 -160
  40. package/dist/geometries/plane-geometry.d.ts +1 -1
  41. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  42. package/dist/geometries/plane-geometry.js +92 -110
  43. package/dist/geometries/sphere-geometry.d.ts +1 -1
  44. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  45. package/dist/geometries/sphere-geometry.js +76 -95
  46. package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
  47. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  48. package/dist/geometries/truncated-cone-geometry.js +99 -117
  49. package/dist/geometry/geometry-table.d.ts.map +1 -1
  50. package/dist/geometry/geometry-table.js +3 -1
  51. package/dist/geometry/geometry-utils.js +35 -32
  52. package/dist/geometry/geometry.d.ts.map +1 -1
  53. package/dist/geometry/geometry.js +80 -71
  54. package/dist/geometry/gpu-geometry.d.ts +1 -1
  55. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  56. package/dist/geometry/gpu-geometry.js +79 -99
  57. package/dist/geometry/gpu-table.js +41 -1
  58. package/dist/index.cjs +725 -409
  59. package/dist/index.cjs.map +7 -0
  60. package/dist/index.d.ts +43 -40
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +6 -1
  63. package/dist/lib/clip-space.d.ts +2 -2
  64. package/dist/lib/clip-space.d.ts.map +1 -1
  65. package/dist/lib/clip-space.js +28 -34
  66. package/dist/lib/pipeline-factory.d.ts +13 -14
  67. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  68. package/dist/lib/pipeline-factory.js +86 -85
  69. package/dist/lib/shader-factory.d.ts +17 -0
  70. package/dist/lib/shader-factory.d.ts.map +1 -0
  71. package/dist/lib/shader-factory.js +46 -0
  72. package/dist/model/model.d.ts +59 -46
  73. package/dist/model/model.d.ts.map +1 -1
  74. package/dist/model/model.js +635 -411
  75. package/dist/scenegraph/group-node.d.ts +1 -1
  76. package/dist/scenegraph/group-node.d.ts.map +1 -1
  77. package/dist/scenegraph/group-node.js +73 -83
  78. package/dist/scenegraph/model-node.d.ts +3 -3
  79. package/dist/scenegraph/model-node.d.ts.map +1 -1
  80. package/dist/scenegraph/model-node.js +31 -24
  81. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  82. package/dist/scenegraph/scenegraph-node.js +136 -124
  83. package/dist/shader-inputs.d.ts.map +1 -1
  84. package/dist/shader-inputs.js +99 -58
  85. package/dist/transform/buffer-transform.d.ts +1 -1
  86. package/dist/transform/buffer-transform.d.ts.map +1 -1
  87. package/dist/transform/buffer-transform.js +65 -57
  88. package/dist/transform/texture-transform.d.ts +1 -1
  89. package/dist/transform/texture-transform.d.ts.map +1 -1
  90. package/dist/transform/texture-transform.js +109 -114
  91. package/dist.min.js +3 -271
  92. package/package.json +10 -9
  93. package/src/animation/timeline.ts +20 -20
  94. package/src/animation-loop/animation-loop-template.ts +10 -8
  95. package/src/animation-loop/animation-loop.ts +20 -10
  96. package/src/animation-loop/animation-props.ts +1 -1
  97. package/src/animation-loop/make-animation-loop.ts +17 -8
  98. package/src/computation.ts +346 -0
  99. package/src/debug/copy-texture-to-image.ts +9 -11
  100. package/src/debug/debug-framebuffer.ts +16 -3
  101. package/src/debug/debug-shader-layout.ts +1 -1
  102. package/src/debug/pixel-data-utils.ts +3 -6
  103. package/src/geometries/cube-geometry.ts +17 -13
  104. package/src/geometries/ico-sphere-geometry.ts +1 -1
  105. package/src/geometries/plane-geometry.ts +1 -1
  106. package/src/geometries/sphere-geometry.ts +1 -1
  107. package/src/geometries/truncated-cone-geometry.ts +2 -1
  108. package/src/geometry/geometry-table.ts +9 -6
  109. package/src/geometry/geometry-utils.ts +16 -0
  110. package/src/geometry/geometry.ts +9 -6
  111. package/src/geometry/gpu-geometry.ts +18 -11
  112. package/src/index.ts +4 -1
  113. package/src/lib/clip-space.ts +16 -19
  114. package/src/lib/pipeline-factory.ts +71 -64
  115. package/src/lib/shader-factory.ts +57 -0
  116. package/src/model/model.ts +255 -146
  117. package/src/scenegraph/group-node.ts +14 -10
  118. package/src/scenegraph/model-node.ts +2 -2
  119. package/src/scenegraph/scenegraph-node.ts +2 -2
  120. package/src/shader-inputs.ts +19 -12
  121. package/src/transform/buffer-transform.ts +16 -8
  122. package/src/transform/texture-transform.ts +14 -15
  123. package/dist/animation/key-frames.js.map +0 -1
  124. package/dist/animation/timeline.js.map +0 -1
  125. package/dist/animation-loop/animation-loop-template.js.map +0 -1
  126. package/dist/animation-loop/animation-loop.js.map +0 -1
  127. package/dist/animation-loop/animation-props.js.map +0 -1
  128. package/dist/animation-loop/make-animation-loop.js.map +0 -1
  129. package/dist/debug/copy-texture-to-image.js.map +0 -1
  130. package/dist/debug/debug-framebuffer.js.map +0 -1
  131. package/dist/debug/debug-shader-layout.js.map +0 -1
  132. package/dist/debug/pixel-data-utils.js.map +0 -1
  133. package/dist/geometries/cone-geometry.js.map +0 -1
  134. package/dist/geometries/cube-geometry.js.map +0 -1
  135. package/dist/geometries/cylinder-geometry.js.map +0 -1
  136. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  137. package/dist/geometries/plane-geometry.js.map +0 -1
  138. package/dist/geometries/sphere-geometry.js.map +0 -1
  139. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  140. package/dist/geometry/geometry-table.js.map +0 -1
  141. package/dist/geometry/geometry-utils.js.map +0 -1
  142. package/dist/geometry/geometry.js.map +0 -1
  143. package/dist/geometry/gpu-geometry.js.map +0 -1
  144. package/dist/geometry/gpu-table.js.map +0 -1
  145. package/dist/index.js.map +0 -1
  146. package/dist/lib/clip-space.js.map +0 -1
  147. package/dist/lib/pipeline-factory.js.map +0 -1
  148. package/dist/model/model.js.map +0 -1
  149. package/dist/scenegraph/group-node.js.map +0 -1
  150. package/dist/scenegraph/model-node.js.map +0 -1
  151. package/dist/scenegraph/scenegraph-node.js.map +0 -1
  152. package/dist/shader-inputs.js.map +0 -1
  153. package/dist/transform/buffer-transform.js.map +0 -1
  154. package/dist/transform/texture-transform.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { Device } from '@luma.gl/core';
2
- import { Timeline } from '../animation/timeline';
3
- import type { AnimationLoop } from './animation-loop';
2
+ import { Timeline } from "../animation/timeline.js";
3
+ import type { AnimationLoop } from "./animation-loop.js";
4
4
  /** Properties passed to every render frame */
5
5
  export type AnimationProps = {
6
6
  device: Device;
@@ -1 +1 @@
1
- {"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/animation-loop/animation-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEpD,+CAA+C;AAC/C,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAE7B,oCAAoC;IACpC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAC5C,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAE7B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAG1B,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/animation-loop/animation-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,QAAQ,EAAC,iCAA8B;AAC/C,OAAO,KAAK,EAAC,aAAa,EAAC,4BAAyB;AAEpD,+CAA+C;AAC/C,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAE7B,oCAAoC;IACpC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAC5C,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAE7B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAG1B,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC1C,CAAC"}
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=animation-props.js.map
@@ -1,5 +1,5 @@
1
- import { AnimationLoopTemplate } from './animation-loop-template';
2
- import { AnimationLoop, AnimationLoopProps } from './animation-loop';
1
+ import { AnimationLoopTemplate } from "./animation-loop-template.js";
2
+ import { AnimationLoop, AnimationLoopProps } from "./animation-loop.js";
3
3
  export type MakeAnimationLoopProps = Omit<AnimationLoopProps, 'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize'>;
4
4
  /** Instantiates and runs the render loop */
5
5
  export declare function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoopTemplate, props?: MakeAnimationLoopProps): AnimationLoop;
@@ -1 +1 @@
1
- {"version":3,"file":"make-animation-loop.d.ts","sourceRoot":"","sources":["../../src/animation-loop/make-animation-loop.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,MAAM,kBAAkB,CAAA;AAGlE,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,kBAAkB,EAAE,gBAAgB,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAAC,CAAC;AAE7H,4CAA4C;AAC5C,wBAAgB,iBAAiB,CAAC,yBAAyB,EAAE,OAAO,qBAAqB,EAAE,KAAK,CAAC,EAAE,sBAAsB,GAAG,aAAa,CAkCxI"}
1
+ {"version":3,"file":"make-animation-loop.d.ts","sourceRoot":"","sources":["../../src/animation-loop/make-animation-loop.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,qBAAqB,EAAC,qCAAkC;AAChE,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,4BAAyB;AAGnE,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,kBAAkB,EAClB,gBAAgB,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAC9D,CAAC;AAEF,4CAA4C;AAC5C,wBAAgB,iBAAiB,CAC/B,yBAAyB,EAAE,OAAO,qBAAqB,EACvD,KAAK,CAAC,EAAE,sBAAsB,GAC7B,aAAa,CAkCf"}
@@ -1,28 +1,32 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { luma } from '@luma.gl/core';
2
5
  import { AnimationLoop } from "./animation-loop.js";
6
+ /** Instantiates and runs the render loop */
3
7
  export function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
4
- let renderLoop = null;
5
- const device = (props === null || props === void 0 ? void 0 : props.device) || luma.createDevice();
6
- const animationLoop = new AnimationLoop({
7
- ...props,
8
- device,
9
- async onInitialize(animationProps) {
10
- var _renderLoop;
11
- renderLoop = new AnimationLoopTemplateCtor(animationProps);
12
- return await ((_renderLoop = renderLoop) === null || _renderLoop === void 0 ? void 0 : _renderLoop.onInitialize(animationProps));
13
- },
14
- onRender: animationProps => {
15
- var _renderLoop2;
16
- return (_renderLoop2 = renderLoop) === null || _renderLoop2 === void 0 ? void 0 : _renderLoop2.onRender(animationProps);
17
- },
18
- onFinalize: animationProps => {
19
- var _renderLoop3;
20
- return (_renderLoop3 = renderLoop) === null || _renderLoop3 === void 0 ? void 0 : _renderLoop3.onFinalize(animationProps);
21
- }
22
- });
23
- animationLoop.getInfo = () => {
24
- return this.AnimationLoopTemplateCtor.info;
25
- };
26
- return animationLoop;
8
+ let renderLoop = null;
9
+ const device = props?.device || luma.createDevice();
10
+ // Create an animation loop;
11
+ const animationLoop = new AnimationLoop({
12
+ ...props,
13
+ device,
14
+ async onInitialize(animationProps) {
15
+ // @ts-expect-error abstract to prevent instantiation
16
+ renderLoop = new AnimationLoopTemplateCtor(animationProps);
17
+ // Any async loading can be handled here
18
+ return await renderLoop?.onInitialize(animationProps);
19
+ },
20
+ onRender: (animationProps) => renderLoop?.onRender(animationProps),
21
+ onFinalize: (animationProps) => renderLoop?.onFinalize(animationProps)
22
+ });
23
+ // @ts-expect-error Hack: adds info for the website to find
24
+ animationLoop.getInfo = () => {
25
+ // @ts-ignore
26
+ // eslint-disable-next-line no-invalid-this
27
+ return this.AnimationLoopTemplateCtor.info;
28
+ };
29
+ // Start the loop automatically
30
+ // animationLoop.start();
31
+ return animationLoop;
27
32
  }
28
- //# sourceMappingURL=make-animation-loop.js.map
@@ -0,0 +1,95 @@
1
+ import type { TypedArray } from '@luma.gl/core';
2
+ import type { ComputePipelineProps, Shader, Binding } from '@luma.gl/core';
3
+ import { Device, Buffer, ComputePipeline, ComputePass, UniformStore } from '@luma.gl/core';
4
+ import type { ShaderModule, PlatformInfo } from '@luma.gl/shadertools';
5
+ import { ShaderAssembler } from '@luma.gl/shadertools';
6
+ import { ShaderInputs } from "./shader-inputs.js";
7
+ import { PipelineFactory } from "./lib/pipeline-factory.js";
8
+ import { ShaderFactory } from "./lib/shader-factory.js";
9
+ export type ComputationProps = Omit<ComputePipelineProps, 'shader'> & {
10
+ source?: string;
11
+ /** shadertool shader modules (added to shader code) */
12
+ modules?: ShaderModule[];
13
+ /** Shadertool module defines (configures shader code)*/
14
+ defines?: Record<string, string | number | boolean>;
15
+ /** Shader inputs, used to generated uniform buffers and bindings */
16
+ shaderInputs?: ShaderInputs;
17
+ /** Bindings */
18
+ bindings?: Record<string, Binding>;
19
+ /** Show shader source in browser? */
20
+ debugShaders?: 'never' | 'errors' | 'warnings' | 'always';
21
+ /** Factory used to create a {@link ComputePipeline}. Defaults to {@link Device} default factory. */
22
+ pipelineFactory?: PipelineFactory;
23
+ /** Factory used to create a {@link Shader}. Defaults to {@link Device} default factory. */
24
+ shaderFactory?: ShaderFactory;
25
+ /** Shader assembler. Defaults to the ShaderAssembler.getShaderAssembler() */
26
+ shaderAssembler?: ShaderAssembler;
27
+ };
28
+ /**
29
+ * v9 Model API
30
+ * A model
31
+ * - automatically reuses pipelines (programs) when possible
32
+ * - automatically rebuilds pipelines if necessary to accommodate changed settings
33
+ * shadertools integration
34
+ * - accepts modules and performs shader transpilation
35
+ */
36
+ export declare class Computation {
37
+ static defaultProps: Required<ComputationProps>;
38
+ readonly device: Device;
39
+ readonly id: string;
40
+ readonly pipelineFactory: PipelineFactory;
41
+ readonly shaderFactory: ShaderFactory;
42
+ userData: {
43
+ [key: string]: any;
44
+ };
45
+ /** Bindings (textures, samplers, uniform buffers) */
46
+ bindings: Record<string, Binding>;
47
+ /** The underlying GPU "program". @note May be recreated if parameters change */
48
+ pipeline: ComputePipeline;
49
+ /** the underlying compiled compute shader */
50
+ shader: Shader;
51
+ source: string;
52
+ /** ShaderInputs instance */
53
+ shaderInputs: ShaderInputs;
54
+ _uniformStore: UniformStore;
55
+ _pipelineNeedsUpdate: string | false;
56
+ private _getModuleUniforms;
57
+ private props;
58
+ private _destroyed;
59
+ constructor(device: Device, props: ComputationProps);
60
+ destroy(): void;
61
+ predraw(): void;
62
+ dispatch(computePass: ComputePass, x: number, y?: number, z?: number): void;
63
+ /**
64
+ * Updates the vertex count (used in draw calls)
65
+ * @note Any attributes with stepMode=vertex need to be at least this big
66
+ */
67
+ setVertexCount(vertexCount: number): void;
68
+ /**
69
+ * Updates the instance count (used in draw calls)
70
+ * @note Any attributes with stepMode=instance need to be at least this big
71
+ */
72
+ setInstanceCount(instanceCount: number): void;
73
+ setShaderInputs(shaderInputs: ShaderInputs): void;
74
+ /**
75
+ * Updates shader module settings (which results in uniforms being set)
76
+ */
77
+ setShaderModuleProps(props: Record<string, any>): void;
78
+ updateShaderInputs(): void;
79
+ /**
80
+ * Sets bindings (textures, samplers, uniform buffers)
81
+ */
82
+ setBindings(bindings: Record<string, Binding>): void;
83
+ _setPipelineNeedsUpdate(reason: string): void;
84
+ _updatePipeline(): ComputePipeline;
85
+ /** Throttle draw call logging */
86
+ _lastLogTime: number;
87
+ _logOpen: boolean;
88
+ _logDrawCallStart(): void;
89
+ _logDrawCallEnd(): void;
90
+ protected _drawCount: number;
91
+ _getBufferOrConstantValues(attribute: Buffer | TypedArray, dataType: any): string;
92
+ }
93
+ /** Create a shadertools platform info from the Device */
94
+ export declare function getPlatformInfo(device: Device): PlatformInfo;
95
+ //# sourceMappingURL=computation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computation.d.ts","sourceRoot":"","sources":["../src/computation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAgB,oBAAoB,EAAE,MAAM,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAGzF,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAC,eAAe,EAA0B,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,eAAe,EAAC,kCAA+B;AACvD,OAAO,EAAC,aAAa,EAAC,gCAA6B;AAMnD,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,GAAG;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uDAAuD;IACvD,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IAGpD,oEAAoE;IACpE,YAAY,CAAC,EAAE,YAAY,CAAC;IAE5B,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;IAE1D,oGAAoG;IACpG,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,2FAA2F;IAC3F,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,6EAA6E;IAC7E,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAkB7C;IAEF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAEtC,QAAQ,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAM;IAEpC,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAEvC,gFAAgF;IAChF,QAAQ,EAAE,eAAe,CAAC;IAC1B,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAEf,4BAA4B;IAC5B,YAAY,EAAE,YAAY,CAAC;IAE3B,aAAa,EAAE,YAAY,CAAC;IAE5B,oBAAoB,EAAE,MAAM,GAAG,KAAK,CAAmB;IAEvD,OAAO,CAAC,kBAAkB,CAAuE;IACjG,OAAO,CAAC,KAAK,CAA6B;IAE1C,OAAO,CAAC,UAAU,CAAS;gBAEf,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB;IAwDnD,OAAO,IAAI,IAAI;IAUf,OAAO;IAKP,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAyB3E;;;OAGG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAIzC;;;OAGG;IACH,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI;IAI7C,eAAe,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI;IAUjD;;OAEG;IACH,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAgBtD,kBAAkB,IAAI,IAAI;IAI1B;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIpD,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI7C,eAAe,IAAI,eAAe;IAgClC,iCAAiC;IACjC,YAAY,SAAK;IACjB,QAAQ,UAAS;IAEjB,iBAAiB,IAAI,IAAI;IAazB,eAAe,IAAI,IAAI;IAgBvB,SAAS,CAAC,UAAU,SAAK;IAGzB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,EAAE,GAAG,GAAG,MAAM;CAMlF;AAED,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAS5D"}
@@ -0,0 +1,248 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { Buffer, ComputePipeline, UniformStore } from '@luma.gl/core';
5
+ import { log, uid, isNumberArray } from '@luma.gl/core';
6
+ import { getTypedArrayFromDataType } from '@luma.gl/core';
7
+ import { ShaderAssembler, getShaderLayoutFromWGSL } from '@luma.gl/shadertools';
8
+ import { ShaderInputs } from "./shader-inputs.js";
9
+ import { PipelineFactory } from "./lib/pipeline-factory.js";
10
+ import { ShaderFactory } from "./lib/shader-factory.js";
11
+ // import {getDebugTableForShaderLayout} from '../debug/debug-shader-layout';
12
+ const LOG_DRAW_PRIORITY = 2;
13
+ const LOG_DRAW_TIMEOUT = 10000;
14
+ /**
15
+ * v9 Model API
16
+ * A model
17
+ * - automatically reuses pipelines (programs) when possible
18
+ * - automatically rebuilds pipelines if necessary to accommodate changed settings
19
+ * shadertools integration
20
+ * - accepts modules and performs shader transpilation
21
+ */
22
+ export class Computation {
23
+ static defaultProps = {
24
+ ...ComputePipeline.defaultProps,
25
+ id: 'unnamed',
26
+ handle: undefined,
27
+ userData: {},
28
+ source: '',
29
+ modules: [],
30
+ defines: {},
31
+ bindings: undefined,
32
+ shaderInputs: undefined,
33
+ pipelineFactory: undefined,
34
+ shaderFactory: undefined,
35
+ shaderAssembler: ShaderAssembler.getDefaultShaderAssembler(),
36
+ debugShaders: undefined
37
+ };
38
+ device;
39
+ id;
40
+ pipelineFactory;
41
+ shaderFactory;
42
+ userData = {};
43
+ /** Bindings (textures, samplers, uniform buffers) */
44
+ bindings = {};
45
+ /** The underlying GPU "program". @note May be recreated if parameters change */
46
+ pipeline;
47
+ /** the underlying compiled compute shader */
48
+ shader;
49
+ source;
50
+ /** ShaderInputs instance */
51
+ shaderInputs;
52
+ _uniformStore;
53
+ _pipelineNeedsUpdate = 'newly created';
54
+ _getModuleUniforms;
55
+ props;
56
+ _destroyed = false;
57
+ constructor(device, props) {
58
+ if (device.type !== 'webgpu') {
59
+ throw new Error('Computation is only supported in WebGPU');
60
+ }
61
+ this.props = { ...Computation.defaultProps, ...props };
62
+ props = this.props;
63
+ this.id = props.id || uid('model');
64
+ this.device = device;
65
+ Object.assign(this.userData, props.userData);
66
+ // Setup shader module inputs
67
+ const moduleMap = Object.fromEntries(this.props.modules?.map(module => [module.name, module]) || []);
68
+ this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
69
+ // Support WGSL shader layout introspection
70
+ // TODO - Don't modify props!!
71
+ this.props.shaderLayout ||= getShaderLayoutFromWGSL(this.props.source);
72
+ // Setup shader assembler
73
+ const platformInfo = getPlatformInfo(device);
74
+ // Extract modules from shader inputs if not supplied
75
+ const modules = (this.props.modules?.length > 0 ? this.props.modules : this.shaderInputs?.getModules()) || [];
76
+ this.pipelineFactory =
77
+ props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
78
+ this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
79
+ const { source, getUniforms } = this.props.shaderAssembler.assembleShader({
80
+ platformInfo,
81
+ ...this.props,
82
+ modules
83
+ });
84
+ this.source = source;
85
+ this._getModuleUniforms = getUniforms;
86
+ // Create the pipeline
87
+ // @note order is important
88
+ this.pipeline = this._updatePipeline();
89
+ // Apply any dynamic settings that will not trigger pipeline change
90
+ if (props.bindings) {
91
+ this.setBindings(props.bindings);
92
+ }
93
+ // Catch any access to non-standard props
94
+ Object.seal(this);
95
+ }
96
+ destroy() {
97
+ if (this._destroyed)
98
+ return;
99
+ this.pipelineFactory.release(this.pipeline);
100
+ this.shaderFactory.release(this.shader);
101
+ this._uniformStore.destroy();
102
+ this._destroyed = true;
103
+ }
104
+ // Draw call
105
+ predraw() {
106
+ // Update uniform buffers if needed
107
+ this.updateShaderInputs();
108
+ }
109
+ dispatch(computePass, x, y, z) {
110
+ try {
111
+ this._logDrawCallStart();
112
+ // Check if the pipeline is invalidated
113
+ // TODO - this is likely the worst place to do this from performance perspective. Perhaps add a predraw()?
114
+ this.pipeline = this._updatePipeline();
115
+ // Set pipeline state, we may be sharing a pipeline so we need to set all state on every draw
116
+ // Any caching needs to be done inside the pipeline functions
117
+ this.pipeline.setBindings(this.bindings);
118
+ computePass.setPipeline(this.pipeline);
119
+ // @ts-expect-error
120
+ computePass.setBindings([]);
121
+ computePass.dispatch(x, y, z);
122
+ }
123
+ finally {
124
+ this._logDrawCallEnd();
125
+ }
126
+ }
127
+ // Update fixed fields (can trigger pipeline rebuild)
128
+ // Update dynamic fields
129
+ /**
130
+ * Updates the vertex count (used in draw calls)
131
+ * @note Any attributes with stepMode=vertex need to be at least this big
132
+ */
133
+ setVertexCount(vertexCount) {
134
+ // this.vertexCount = vertexCount;
135
+ }
136
+ /**
137
+ * Updates the instance count (used in draw calls)
138
+ * @note Any attributes with stepMode=instance need to be at least this big
139
+ */
140
+ setInstanceCount(instanceCount) {
141
+ // this.instanceCount = instanceCount;
142
+ }
143
+ setShaderInputs(shaderInputs) {
144
+ this.shaderInputs = shaderInputs;
145
+ this._uniformStore = new UniformStore(this.shaderInputs.modules);
146
+ // Create uniform buffer bindings for all modules
147
+ for (const moduleName of Object.keys(this.shaderInputs.modules)) {
148
+ const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
149
+ this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
150
+ }
151
+ }
152
+ /**
153
+ * Updates shader module settings (which results in uniforms being set)
154
+ */
155
+ setShaderModuleProps(props) {
156
+ const uniforms = this._getModuleUniforms(props);
157
+ // Extract textures & framebuffers set by the modules
158
+ // TODO better way to extract bindings
159
+ const keys = Object.keys(uniforms).filter(k => {
160
+ const uniform = uniforms[k];
161
+ return !isNumberArray(uniform) && typeof uniform !== 'number' && typeof uniform !== 'boolean';
162
+ });
163
+ const bindings = {};
164
+ for (const k of keys) {
165
+ bindings[k] = uniforms[k];
166
+ delete uniforms[k];
167
+ }
168
+ }
169
+ updateShaderInputs() {
170
+ this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
171
+ }
172
+ /**
173
+ * Sets bindings (textures, samplers, uniform buffers)
174
+ */
175
+ setBindings(bindings) {
176
+ Object.assign(this.bindings, bindings);
177
+ }
178
+ _setPipelineNeedsUpdate(reason) {
179
+ this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
180
+ }
181
+ _updatePipeline() {
182
+ if (this._pipelineNeedsUpdate) {
183
+ let prevShader = null;
184
+ if (this.pipeline) {
185
+ log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
186
+ prevShader = this.shader;
187
+ }
188
+ this._pipelineNeedsUpdate = false;
189
+ this.shader = this.shaderFactory.createShader({
190
+ id: `${this.id}-fragment`,
191
+ stage: 'compute',
192
+ source: this.source,
193
+ debug: this.props.debugShaders
194
+ });
195
+ this.pipeline = this.pipelineFactory.createComputePipeline({
196
+ ...this.props,
197
+ shader: this.shader
198
+ });
199
+ if (prevShader) {
200
+ this.shaderFactory.release(prevShader);
201
+ }
202
+ }
203
+ return this.pipeline;
204
+ }
205
+ /** Throttle draw call logging */
206
+ _lastLogTime = 0;
207
+ _logOpen = false;
208
+ _logDrawCallStart() {
209
+ // IF level is 4 or higher, log every frame.
210
+ const logDrawTimeout = log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
211
+ if (log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
212
+ return;
213
+ }
214
+ this._lastLogTime = Date.now();
215
+ this._logOpen = true;
216
+ log.group(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`, { collapsed: log.level <= 2 })();
217
+ }
218
+ _logDrawCallEnd() {
219
+ if (this._logOpen) {
220
+ // const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.props.shaderLayout, this.id);
221
+ // log.table(logLevel, attributeTable)();
222
+ // log.table(logLevel, uniformTable)();
223
+ // log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
224
+ const uniformTable = this.shaderInputs.getDebugTable();
225
+ log.table(LOG_DRAW_PRIORITY, uniformTable)();
226
+ log.groupEnd(LOG_DRAW_PRIORITY)();
227
+ this._logOpen = false;
228
+ }
229
+ }
230
+ _drawCount = 0;
231
+ // TODO - fix typing of luma data types
232
+ _getBufferOrConstantValues(attribute, dataType) {
233
+ const TypedArrayConstructor = getTypedArrayFromDataType(dataType);
234
+ const typedArray = attribute instanceof Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
235
+ return typedArray.toString();
236
+ }
237
+ }
238
+ /** Create a shadertools platform info from the Device */
239
+ export function getPlatformInfo(device) {
240
+ return {
241
+ type: device.type,
242
+ shaderLanguage: device.info.shadingLanguage,
243
+ shaderLanguageVersion: device.info.shadingLanguageVersion,
244
+ gpu: device.info.gpu,
245
+ // HACK - we pretend that the DeviceFeatures is a Set, it has a similar API
246
+ features: device.features
247
+ };
248
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"copy-texture-to-image.d.ts","sourceRoot":"","sources":["../../src/debug/copy-texture-to-image.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAInD;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,GAAG,WAAW,EAC7B,OAAO,CAAC,EAAE,yBAAyB,GAClC,gBAAgB,CAOlB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GAAG,WAAW,EAC7B,OAAO,GAAE,yBAA8B,GACtC,MAAM,CA4BR"}
1
+ {"version":3,"file":"copy-texture-to-image.d.ts","sourceRoot":"","sources":["../../src/debug/copy-texture-to-image.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAGnD;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,GAAG,WAAW,EAC7B,OAAO,CAAC,EAAE,yBAAyB,GAClC,gBAAgB,CAMlB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,OAAO,GAAG,WAAW,EAC7B,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAyBR"}
@@ -1,46 +1,43 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { flipRows, scalePixels } from "./pixel-data-utils.js";
5
+ /**
6
+ * Reads pixels from a Framebuffer or Texture object into an HTML Image
7
+ * @todo - can we move this to @luma.gl/core?
8
+ * @param source
9
+ * @param options options passed to copyToDataUrl
10
+ * @returns
11
+ */
2
12
  export function copyTextureToImage(source, options) {
3
- const dataUrl = copyTextureToDataUrl(source, options);
4
- const targetImage = (options === null || options === void 0 ? void 0 : options.targetImage) || new Image();
5
- targetImage.src = dataUrl;
6
- return targetImage;
13
+ const dataUrl = copyTextureToDataUrl(source, options);
14
+ const targetImage = options?.targetImage || new Image();
15
+ targetImage.src = dataUrl;
16
+ return targetImage;
7
17
  }
8
- export function copyTextureToDataUrl(source) {
9
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
- const {
11
- sourceAttachment = 36064,
12
- targetMaxHeight = Number.MAX_SAFE_INTEGER
13
- } = options;
14
- let data = source.device.readPixelsToArrayWebGL(source, {
15
- sourceAttachment
16
- });
17
- let {
18
- width,
19
- height
20
- } = source;
21
- while (height > targetMaxHeight) {
22
- ({
23
- data,
24
- width,
25
- height
26
- } = scalePixels({
27
- data,
28
- width,
29
- height
30
- }));
31
- }
32
- flipRows({
33
- data,
34
- width,
35
- height
36
- });
37
- const canvas = document.createElement('canvas');
38
- canvas.width = width;
39
- canvas.height = height;
40
- const context = canvas.getContext('2d');
41
- const imageData = context.createImageData(width, height);
42
- imageData.data.set(data);
43
- context.putImageData(imageData, 0, 0);
44
- return canvas.toDataURL('image/png');
18
+ /**
19
+ * Reads pixels from a Framebuffer or Texture object to a dataUrl
20
+ * @todo - can we move this to @luma.gl/core?
21
+ * @param source texture or framebuffer to read from
22
+ * @param options
23
+ */
24
+ export function copyTextureToDataUrl(source, options = {}) {
25
+ const { sourceAttachment, targetMaxHeight = Number.MAX_SAFE_INTEGER } = options;
26
+ let data = source.device.readPixelsToArrayWebGL(source, { sourceAttachment });
27
+ // Scale down
28
+ let { width, height } = source;
29
+ while (height > targetMaxHeight) {
30
+ ({ data, width, height } = scalePixels({ data, width, height }));
31
+ }
32
+ // Flip to top down coordinate system
33
+ flipRows({ data, width, height });
34
+ const canvas = document.createElement('canvas');
35
+ canvas.width = width;
36
+ canvas.height = height;
37
+ const context = canvas.getContext('2d');
38
+ // Copy the pixels to a 2D canvas
39
+ const imageData = context.createImageData(width, height);
40
+ imageData.data.set(data);
41
+ context.putImageData(imageData, 0, 0);
42
+ return canvas.toDataURL('image/png');
45
43
  }
46
- //# sourceMappingURL=copy-texture-to-image.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug-framebuffer.d.ts","sourceRoot":"","sources":["../../src/debug/debug-framebuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAQxD,qDAAqD;AAErD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,GAAG,OAAO,EAC1B,EAAC,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAS,EAAE,IAAU,EAAE,SAAa,EAAC,EAAE;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,QA4ChK"}
1
+ {"version":3,"file":"debug-framebuffer.d.ts","sourceRoot":"","sources":["../../src/debug/debug-framebuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAQxD,qDAAqD;AAErD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,GAAG,OAAO,EAC1B,EACE,EAAE,EACF,OAAO,EACP,MAAM,EACN,GAAS,EACT,IAAU,EACV,SAAa,EACd,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,QA2CF"}
@@ -1,43 +1,46 @@
1
+ // import {copyTextureToImage} from '../debug/copy-texture-to-image';
2
+ /** Only works with 1st device? */
1
3
  let canvas = null;
2
4
  let ctx = null;
3
- export function debugFramebuffer(fbo, _ref) {
4
- let {
5
- id,
6
- minimap,
7
- opaque,
8
- top = '0',
9
- left = '0',
10
- rgbaScale = 1
11
- } = _ref;
12
- if (!canvas) {
13
- canvas = document.createElement('canvas');
14
- canvas.id = id;
15
- canvas.title = id;
16
- canvas.style.zIndex = '100';
17
- canvas.style.position = 'absolute';
18
- canvas.style.top = top;
19
- canvas.style.left = left;
20
- canvas.style.border = 'blue 1px solid';
21
- canvas.style.transform = 'scaleY(-1)';
22
- document.body.appendChild(canvas);
23
- ctx = canvas.getContext('2d');
24
- }
25
- if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
26
- canvas.width = fbo.width / 2;
27
- canvas.height = fbo.height / 2;
28
- canvas.style.width = '400px';
29
- canvas.style.height = '400px';
30
- }
31
- const color = fbo.device.readPixelsToArrayWebGL(fbo);
32
- const imageData = ctx.createImageData(fbo.width, fbo.height);
33
- const offset = 0;
34
- for (let i = 0; i < color.length; i += 4) {
35
- imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
36
- imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
37
- imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
38
- imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
39
- }
40
- ctx.putImageData(imageData, 0, 0);
5
+ // let targetImage: HTMLImageElement | null = null;
6
+ /** Debug utility to draw FBO contents onto screen */
7
+ // eslint-disable-next-line
8
+ export function debugFramebuffer(fbo, { id, minimap, opaque, top = '0', left = '0', rgbaScale = 1 }) {
9
+ if (!canvas) {
10
+ canvas = document.createElement('canvas');
11
+ canvas.id = id;
12
+ canvas.title = id;
13
+ canvas.style.zIndex = '100';
14
+ canvas.style.position = 'absolute';
15
+ canvas.style.top = top; // ⚠️
16
+ canvas.style.left = left; // ⚠️
17
+ canvas.style.border = 'blue 1px solid';
18
+ canvas.style.transform = 'scaleY(-1)';
19
+ document.body.appendChild(canvas);
20
+ ctx = canvas.getContext('2d');
21
+ // targetImage = new Image();
22
+ }
23
+ // const canvasHeight = (minimap ? 2 : 1) * fbo.height;
24
+ if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
25
+ canvas.width = fbo.width / 2;
26
+ canvas.height = fbo.height / 2;
27
+ canvas.style.width = '400px';
28
+ canvas.style.height = '400px';
29
+ }
30
+ // const image = copyTextureToImage(fbo, {targetMaxHeight: 100, targetImage});
31
+ // ctx.drawImage(image, 0, 0);
32
+ const color = fbo.device.readPixelsToArrayWebGL(fbo);
33
+ const imageData = ctx.createImageData(fbo.width, fbo.height);
34
+ // Full map
35
+ const offset = 0;
36
+ // if (color.some((v) => v > 0)) {
37
+ // console.error('THERE IS NON-ZERO DATA IN THE FBO!');
38
+ // }
39
+ for (let i = 0; i < color.length; i += 4) {
40
+ imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
41
+ imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
42
+ imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
43
+ imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
44
+ }
45
+ ctx.putImageData(imageData, 0, 0);
41
46
  }
42
- ;
43
- //# sourceMappingURL=debug-framebuffer.js.map