@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.
Files changed (306) hide show
  1. package/LICENSE +3 -1
  2. package/README.md +4 -4
  3. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts +52 -0
  4. package/dist/adapter/attribute-utils/get-attribute-from-layouts.d.ts.map +1 -0
  5. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js +130 -0
  6. package/dist/adapter/attribute-utils/get-attribute-from-layouts.js.map +1 -0
  7. package/dist/adapter/canvas-context.d.ts +109 -0
  8. package/dist/adapter/canvas-context.d.ts.map +1 -0
  9. package/dist/adapter/canvas-context.js +254 -0
  10. package/dist/adapter/canvas-context.js.map +1 -0
  11. package/dist/adapter/device.d.ts +219 -0
  12. package/dist/adapter/device.d.ts.map +1 -0
  13. package/dist/adapter/device.js +99 -0
  14. package/dist/adapter/device.js.map +1 -0
  15. package/dist/adapter/resources/buffer.d.ts +56 -0
  16. package/dist/adapter/resources/buffer.d.ts.map +1 -0
  17. package/dist/adapter/resources/buffer.js +62 -0
  18. package/dist/adapter/resources/buffer.js.map +1 -0
  19. package/dist/adapter/resources/command-buffer.d.ts +12 -0
  20. package/dist/adapter/resources/command-buffer.d.ts.map +1 -0
  21. package/dist/adapter/resources/command-buffer.js +15 -0
  22. package/dist/adapter/resources/command-buffer.js.map +1 -0
  23. package/dist/adapter/resources/command-encoder.d.ts +113 -0
  24. package/dist/adapter/resources/command-encoder.d.ts.map +1 -0
  25. package/dist/adapter/resources/command-encoder.js +19 -0
  26. package/dist/adapter/resources/command-encoder.js.map +1 -0
  27. package/dist/adapter/resources/compute-pass.d.ts +31 -0
  28. package/dist/adapter/resources/compute-pass.d.ts.map +1 -0
  29. package/dist/adapter/resources/compute-pass.js +15 -0
  30. package/dist/adapter/resources/compute-pass.js.map +1 -0
  31. package/dist/adapter/resources/compute-pipeline.d.ts +24 -0
  32. package/dist/adapter/resources/compute-pipeline.d.ts.map +1 -0
  33. package/dist/adapter/resources/compute-pipeline.js +20 -0
  34. package/dist/adapter/resources/compute-pipeline.js.map +1 -0
  35. package/dist/adapter/resources/external-texture.d.ts +12 -0
  36. package/dist/adapter/resources/external-texture.d.ts.map +1 -0
  37. package/dist/adapter/resources/external-texture.js +17 -0
  38. package/dist/adapter/resources/external-texture.js.map +1 -0
  39. package/dist/adapter/resources/framebuffer.d.ts +50 -0
  40. package/dist/adapter/resources/framebuffer.d.ts.map +1 -0
  41. package/dist/adapter/resources/framebuffer.js +102 -0
  42. package/dist/adapter/resources/framebuffer.js.map +1 -0
  43. package/dist/adapter/resources/render-pass.d.ts +51 -0
  44. package/dist/adapter/resources/render-pass.d.ts.map +1 -0
  45. package/dist/adapter/resources/render-pass.js +23 -0
  46. package/dist/adapter/resources/render-pass.js.map +1 -0
  47. package/dist/adapter/resources/render-pipeline.d.ts +89 -0
  48. package/dist/adapter/resources/render-pipeline.d.ts.map +1 -0
  49. package/dist/adapter/resources/render-pipeline.js +36 -0
  50. package/dist/adapter/resources/render-pipeline.js.map +1 -0
  51. package/dist/adapter/resources/resource.d.ts +73 -0
  52. package/dist/adapter/resources/resource.d.ts.map +1 -0
  53. package/dist/adapter/resources/resource.js +101 -0
  54. package/dist/adapter/resources/resource.js.map +1 -0
  55. package/dist/adapter/resources/sampler.d.ts +42 -0
  56. package/dist/adapter/resources/sampler.d.ts.map +1 -0
  57. package/dist/adapter/resources/sampler.js +26 -0
  58. package/dist/adapter/resources/sampler.js.map +1 -0
  59. package/dist/adapter/resources/shader.d.ts +45 -0
  60. package/dist/adapter/resources/shader.d.ts.map +1 -0
  61. package/dist/adapter/resources/shader.js +90 -0
  62. package/dist/adapter/resources/shader.js.map +1 -0
  63. package/dist/adapter/resources/texture.d.ts +90 -0
  64. package/dist/adapter/resources/texture.d.ts.map +1 -0
  65. package/dist/adapter/resources/texture.js +45 -0
  66. package/dist/adapter/resources/texture.js.map +1 -0
  67. package/dist/adapter/resources/transform-feedback.d.ts +30 -0
  68. package/dist/adapter/resources/transform-feedback.d.ts.map +1 -0
  69. package/dist/adapter/resources/transform-feedback.js +17 -0
  70. package/dist/adapter/resources/transform-feedback.js.map +1 -0
  71. package/dist/adapter/resources/vertex-array.d.ts +40 -0
  72. package/dist/adapter/resources/vertex-array.d.ts.map +1 -0
  73. package/dist/adapter/resources/vertex-array.js +24 -0
  74. package/dist/adapter/resources/vertex-array.js.map +1 -0
  75. package/dist/adapter/type-utils/decode-attribute-type.d.ts +20 -0
  76. package/dist/adapter/type-utils/decode-attribute-type.d.ts.map +1 -0
  77. package/dist/adapter/type-utils/decode-attribute-type.js +60 -0
  78. package/dist/adapter/type-utils/decode-attribute-type.js.map +1 -0
  79. package/dist/adapter/type-utils/decode-data-type.d.ts +16 -0
  80. package/dist/adapter/type-utils/decode-data-type.d.ts.map +1 -0
  81. package/dist/adapter/type-utils/decode-data-type.js +43 -0
  82. package/dist/adapter/type-utils/decode-data-type.js.map +1 -0
  83. package/dist/adapter/type-utils/decode-shader-types.d.ts +9 -0
  84. package/dist/adapter/type-utils/decode-shader-types.d.ts.map +1 -0
  85. package/dist/adapter/type-utils/decode-shader-types.js +103 -0
  86. package/dist/adapter/type-utils/decode-shader-types.js.map +1 -0
  87. package/dist/adapter/type-utils/decode-texture-format.d.ts +19 -0
  88. package/dist/adapter/type-utils/decode-texture-format.d.ts.map +1 -0
  89. package/dist/adapter/type-utils/decode-texture-format.js +101 -0
  90. package/dist/adapter/type-utils/decode-texture-format.js.map +1 -0
  91. package/dist/adapter/type-utils/decode-vertex-format.d.ts +22 -0
  92. package/dist/adapter/type-utils/decode-vertex-format.d.ts.map +1 -0
  93. package/dist/adapter/type-utils/decode-vertex-format.js +25 -0
  94. package/dist/adapter/type-utils/decode-vertex-format.js.map +1 -0
  95. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts +10 -0
  96. package/dist/adapter/type-utils/vertex-format-from-attribute.d.ts.map +1 -0
  97. package/dist/adapter/type-utils/vertex-format-from-attribute.js +76 -0
  98. package/dist/adapter/type-utils/vertex-format-from-attribute.js.map +1 -0
  99. package/dist/adapter/type-utils/wgsl-utils.d.ts +4 -0
  100. package/dist/adapter/type-utils/wgsl-utils.d.ts.map +1 -0
  101. package/dist/adapter/type-utils/wgsl-utils.js +15 -0
  102. package/dist/adapter/type-utils/wgsl-utils.js.map +1 -0
  103. package/dist/adapter/types/accessor.d.ts +23 -0
  104. package/dist/adapter/types/accessor.d.ts.map +1 -0
  105. package/dist/adapter/types/accessor.js +2 -0
  106. package/dist/adapter/types/accessor.js.map +1 -0
  107. package/dist/adapter/types/buffer-layout.d.ts +59 -0
  108. package/dist/adapter/types/buffer-layout.d.ts.map +1 -0
  109. package/dist/adapter/types/buffer-layout.js +2 -0
  110. package/dist/adapter/types/buffer-layout.js.map +1 -0
  111. package/dist/adapter/types/parameters.d.ts +97 -0
  112. package/dist/adapter/types/parameters.d.ts.map +1 -0
  113. package/dist/adapter/types/parameters.js +28 -0
  114. package/dist/adapter/types/parameters.js.map +1 -0
  115. package/dist/adapter/types/shader-layout.d.ts +145 -0
  116. package/dist/adapter/types/shader-layout.d.ts.map +1 -0
  117. package/dist/adapter/types/shader-layout.js +2 -0
  118. package/dist/adapter/types/shader-layout.js.map +1 -0
  119. package/dist/adapter/types/shader-types.d.ts +21 -0
  120. package/dist/adapter/types/shader-types.d.ts.map +1 -0
  121. package/dist/adapter/types/shader-types.js +2 -0
  122. package/dist/adapter/types/shader-types.js.map +1 -0
  123. package/dist/adapter/types/texture-formats.d.ts +12 -0
  124. package/dist/adapter/types/texture-formats.d.ts.map +1 -0
  125. package/dist/adapter/types/texture-formats.js +2 -0
  126. package/dist/adapter/types/texture-formats.js.map +1 -0
  127. package/dist/adapter/types/types.d.ts +90 -0
  128. package/dist/adapter/types/types.d.ts.map +1 -0
  129. package/dist/adapter/types/types.js +2 -0
  130. package/dist/adapter/types/types.js.map +1 -0
  131. package/dist/adapter/types/vertex-formats.d.ts +14 -0
  132. package/dist/adapter/types/vertex-formats.d.ts.map +1 -0
  133. package/dist/adapter/types/vertex-formats.js +2 -0
  134. package/dist/adapter/types/vertex-formats.js.map +1 -0
  135. package/dist/dist.dev.js +2976 -0
  136. package/dist/index.cjs +2445 -0
  137. package/dist/index.d.ts +81 -128
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +45 -18
  140. package/dist/index.js.map +1 -1
  141. package/dist/init.d.ts +5 -0
  142. package/dist/init.d.ts.map +1 -0
  143. package/dist/init.js +24 -0
  144. package/dist/init.js.map +1 -0
  145. package/dist/lib/compiler-log/compiler-message.d.ts +8 -0
  146. package/dist/lib/compiler-log/compiler-message.d.ts.map +1 -0
  147. package/dist/lib/compiler-log/compiler-message.js +2 -0
  148. package/dist/lib/compiler-log/compiler-message.js.map +1 -0
  149. package/dist/lib/compiler-log/format-compiler-log.d.ts +8 -0
  150. package/dist/lib/compiler-log/format-compiler-log.d.ts.map +1 -0
  151. package/dist/lib/compiler-log/format-compiler-log.js +64 -0
  152. package/dist/lib/compiler-log/format-compiler-log.js.map +1 -0
  153. package/dist/lib/compiler-log/get-shader-info.d.ts +9 -0
  154. package/dist/lib/compiler-log/get-shader-info.d.ts.map +1 -0
  155. package/dist/lib/compiler-log/get-shader-info.js +25 -0
  156. package/dist/lib/compiler-log/get-shader-info.js.map +1 -0
  157. package/dist/lib/luma.d.ts +22 -0
  158. package/dist/lib/luma.d.ts.map +1 -0
  159. package/dist/lib/luma.js +63 -0
  160. package/dist/lib/luma.js.map +1 -0
  161. package/dist/lib/uniforms/uniform-block.d.ts +29 -0
  162. package/dist/lib/uniforms/uniform-block.d.ts.map +1 -0
  163. package/dist/lib/uniforms/uniform-block.js +48 -0
  164. package/dist/lib/uniforms/uniform-block.js.map +1 -0
  165. package/dist/lib/uniforms/uniform-buffer-layout.d.ts +27 -0
  166. package/dist/lib/uniforms/uniform-buffer-layout.d.ts.map +1 -0
  167. package/dist/lib/uniforms/uniform-buffer-layout.js +76 -0
  168. package/dist/lib/uniforms/uniform-buffer-layout.js.map +1 -0
  169. package/dist/lib/uniforms/uniform-store.d.ts +62 -0
  170. package/dist/lib/uniforms/uniform-store.d.ts.map +1 -0
  171. package/dist/lib/uniforms/uniform-store.js +89 -0
  172. package/dist/lib/uniforms/uniform-store.js.map +1 -0
  173. package/dist/lib/uniforms/uniform.d.ts +10 -0
  174. package/dist/lib/uniforms/uniform.d.ts.map +1 -0
  175. package/dist/lib/uniforms/uniform.js +20 -0
  176. package/dist/lib/uniforms/uniform.js.map +1 -0
  177. package/dist/types.d.ts +19 -0
  178. package/dist/types.d.ts.map +1 -0
  179. package/dist/types.js +3 -0
  180. package/dist/types.js.map +1 -0
  181. package/dist/utils/array-equal.d.ts +5 -0
  182. package/dist/utils/array-equal.d.ts.map +1 -0
  183. package/dist/utils/array-equal.js +28 -0
  184. package/dist/utils/array-equal.js.map +1 -0
  185. package/dist/utils/array-utils-flat.d.ts +10 -0
  186. package/dist/utils/array-utils-flat.d.ts.map +1 -0
  187. package/dist/utils/array-utils-flat.js +36 -0
  188. package/dist/utils/array-utils-flat.js.map +1 -0
  189. package/dist/utils/assert.d.ts +2 -0
  190. package/dist/utils/assert.d.ts.map +1 -0
  191. package/dist/utils/assert.js +6 -0
  192. package/dist/utils/assert.js.map +1 -0
  193. package/dist/utils/cast.d.ts +3 -0
  194. package/dist/utils/cast.d.ts.map +1 -0
  195. package/dist/utils/cast.js +4 -0
  196. package/dist/utils/cast.js.map +1 -0
  197. package/dist/utils/check-props.d.ts +7 -0
  198. package/dist/utils/check-props.d.ts.map +1 -0
  199. package/dist/utils/check-props.js +32 -0
  200. package/dist/utils/check-props.js.map +1 -0
  201. package/dist/utils/deep-equal.d.ts +9 -0
  202. package/dist/utils/deep-equal.d.ts.map +1 -0
  203. package/dist/utils/deep-equal.js +40 -0
  204. package/dist/utils/deep-equal.js.map +1 -0
  205. package/dist/utils/format-value.d.ts +7 -0
  206. package/dist/utils/format-value.d.ts.map +1 -0
  207. package/dist/utils/format-value.js +42 -0
  208. package/dist/utils/format-value.js.map +1 -0
  209. package/dist/utils/is-array.d.ts +16 -0
  210. package/dist/utils/is-array.d.ts.map +1 -0
  211. package/dist/utils/is-array.js +10 -0
  212. package/dist/utils/is-array.js.map +1 -0
  213. package/dist/utils/load-file.d.ts +35 -0
  214. package/dist/utils/load-file.d.ts.map +1 -0
  215. package/dist/utils/load-file.js +48 -0
  216. package/dist/utils/load-file.js.map +1 -0
  217. package/dist/utils/log.d.ts +4 -0
  218. package/dist/utils/log.d.ts.map +1 -0
  219. package/dist/utils/log.js +5 -0
  220. package/dist/utils/log.js.map +1 -0
  221. package/dist/utils/random.d.ts +5 -0
  222. package/dist/utils/random.d.ts.map +1 -0
  223. package/dist/utils/random.js +14 -0
  224. package/dist/utils/random.js.map +1 -0
  225. package/dist/utils/request-animation-frame.d.ts +3 -0
  226. package/dist/utils/request-animation-frame.d.ts.map +1 -0
  227. package/dist/utils/request-animation-frame.js +7 -0
  228. package/dist/utils/request-animation-frame.js.map +1 -0
  229. package/dist/utils/stats-manager.d.ts +12 -0
  230. package/dist/utils/stats-manager.d.ts.map +1 -0
  231. package/dist/utils/stats-manager.js +19 -0
  232. package/dist/utils/stats-manager.js.map +1 -0
  233. package/dist/utils/stub-methods.d.ts +2 -0
  234. package/dist/utils/stub-methods.d.ts.map +1 -0
  235. package/dist/utils/stub-methods.js +16 -0
  236. package/dist/utils/stub-methods.js.map +1 -0
  237. package/dist/utils/utils.d.ts +15 -0
  238. package/dist/utils/utils.d.ts.map +1 -0
  239. package/dist/utils/utils.js +19 -0
  240. package/dist/utils/utils.js.map +1 -0
  241. package/dist.min.js +33 -0
  242. package/package.json +17 -12
  243. package/src/adapter/attribute-utils/get-attribute-from-layouts.ts +259 -0
  244. package/src/adapter/canvas-context.ts +433 -0
  245. package/src/adapter/device.ts +435 -0
  246. package/src/adapter/resources/buffer.ts +106 -0
  247. package/src/adapter/resources/command-buffer.ts +38 -0
  248. package/src/adapter/resources/command-encoder.ts +172 -0
  249. package/src/adapter/resources/compute-pass.ts +52 -0
  250. package/src/adapter/resources/compute-pipeline.ts +39 -0
  251. package/src/adapter/resources/external-texture.ts +20 -0
  252. package/src/adapter/resources/framebuffer.ts +230 -0
  253. package/src/adapter/resources/render-pass.ts +117 -0
  254. package/src/adapter/resources/render-pipeline.ts +133 -0
  255. package/src/adapter/resources/resource.ts +176 -0
  256. package/src/adapter/resources/sampler.ts +69 -0
  257. package/src/adapter/resources/shader.ts +143 -0
  258. package/src/adapter/resources/texture.ts +140 -0
  259. package/src/adapter/resources/transform-feedback.ts +45 -0
  260. package/src/adapter/resources/vertex-array.ts +65 -0
  261. package/src/adapter/type-utils/decode-attribute-type.ts +82 -0
  262. package/src/adapter/type-utils/decode-data-type.ts +62 -0
  263. package/src/adapter/type-utils/decode-shader-types.ts +48 -0
  264. package/src/adapter/type-utils/decode-texture-format.ts +190 -0
  265. package/src/adapter/type-utils/decode-vertex-format.ts +49 -0
  266. package/src/adapter/type-utils/vertex-format-from-attribute.ts +103 -0
  267. package/src/adapter/type-utils/wgsl-utils.ts +18 -0
  268. package/src/adapter/types/accessor.ts +34 -0
  269. package/src/adapter/types/buffer-layout.ts +62 -0
  270. package/src/adapter/types/parameters.ts +250 -0
  271. package/src/adapter/types/shader-layout.ts +193 -0
  272. package/src/adapter/types/shader-types.ts +77 -0
  273. package/src/adapter/types/texture-formats.ts +168 -0
  274. package/src/adapter/types/types.ts +109 -0
  275. package/src/adapter/types/vertex-formats.ts +91 -0
  276. package/src/index.ts +160 -92
  277. package/src/init.ts +47 -0
  278. package/src/lib/compiler-log/compiler-message.ts +10 -0
  279. package/src/lib/compiler-log/format-compiler-log.ts +113 -0
  280. package/src/lib/compiler-log/get-shader-info.ts +41 -0
  281. package/src/lib/luma.ts +84 -0
  282. package/src/lib/uniforms/uniform-block.ts +80 -0
  283. package/src/lib/uniforms/uniform-buffer-layout.ts +109 -0
  284. package/src/lib/uniforms/uniform-store.ts +173 -0
  285. package/src/lib/uniforms/uniform.ts +25 -0
  286. package/src/types.ts +33 -0
  287. package/src/utils/array-equal.ts +33 -0
  288. package/src/utils/array-utils-flat.ts +43 -0
  289. package/src/utils/assert.ts +7 -0
  290. package/src/utils/cast.ts +4 -0
  291. package/src/utils/check-props.ts +74 -0
  292. package/src/utils/deep-equal.ts +47 -0
  293. package/src/utils/format-value.ts +40 -0
  294. package/src/utils/is-array.ts +24 -0
  295. package/src/utils/load-file.ts +89 -0
  296. package/src/utils/log.ts +4 -0
  297. package/src/utils/random.ts +17 -0
  298. package/src/utils/request-animation-frame.ts +15 -0
  299. package/src/utils/stats-manager.ts +23 -0
  300. package/src/utils/stub-methods.ts +20 -0
  301. package/src/utils/utils.ts +36 -0
  302. package/dist/bundle.d.ts +0 -2
  303. package/dist/bundle.d.ts.map +0 -1
  304. package/dist/bundle.js +0 -5
  305. package/dist/bundle.js.map +0 -1
  306. package/src/bundle.ts +0 -4
@@ -0,0 +1,89 @@
1
+ import type { Device } from '../device';
2
+ import type { UniformValue } from '../types/types';
3
+ import type { PrimitiveTopology, RenderPipelineParameters } from '../types/parameters';
4
+ import type { ShaderLayout, Binding } from '../types/shader-layout';
5
+ import type { BufferLayout } from '../types/buffer-layout';
6
+ import { Resource, ResourceProps } from './resource';
7
+ import type { Shader } from './shader';
8
+ import type { RenderPass } from './render-pass';
9
+ import { VertexArray } from './vertex-array';
10
+ import { TransformFeedback } from './transform-feedback';
11
+ export type RenderPipelineProps = ResourceProps & {
12
+ /** Compiled vertex shader */
13
+ vs?: Shader | null;
14
+ /** Vertex shader entry point (defaults to 'main'). WGSL only */
15
+ vsEntryPoint?: string;
16
+ /** Constants to apply to compiled vertex shader (WGSL only) */
17
+ vsConstants?: Record<string, number>;
18
+ /** Compiled fragment shader */
19
+ fs?: Shader | null;
20
+ /** Fragment shader entry point (defaults to 'main'). WGSL only */
21
+ fsEntryPoint?: string;
22
+ /** Constants to apply to compiled fragment shader (WGSL only) */
23
+ fsConstants?: Record<string, number>;
24
+ /** Describes the attributes and bindings exposed by the pipeline shader(s). */
25
+ shaderLayout?: ShaderLayout | null;
26
+ /**
27
+ * Describes the buffers accepted by this pipeline and how they are mapped to shader attributes.
28
+ * A default mapping of one buffer per attribute is always created.
29
+ */
30
+ bufferLayout?: BufferLayout[];
31
+ /** Determines how vertices are read from the 'vertex' attributes */
32
+ topology?: PrimitiveTopology;
33
+ /** Parameters that are controlled by pipeline */
34
+ parameters?: RenderPipelineParameters;
35
+ /** Number of vertices */
36
+ vertexCount?: number;
37
+ /** Number of instances */
38
+ instanceCount?: number;
39
+ /** Buffers, Textures, Samplers for the shader bindings */
40
+ bindings?: Record<string, Binding>;
41
+ /** @deprecated uniforms (WebGL only) */
42
+ uniforms?: Record<string, UniformValue>;
43
+ };
44
+ /**
45
+ * A compiled and linked shader program
46
+ */
47
+ export declare abstract class RenderPipeline extends Resource<RenderPipelineProps> {
48
+ static defaultProps: Required<RenderPipelineProps>;
49
+ get [Symbol.toStringTag](): string;
50
+ hash: string;
51
+ abstract readonly vs: Shader;
52
+ abstract readonly fs: Shader | null;
53
+ /** The merged layout */
54
+ shaderLayout: ShaderLayout;
55
+ /** Buffer map describing buffer interleaving etc */
56
+ readonly bufferLayout: BufferLayout[];
57
+ constructor(device: Device, props: RenderPipelineProps);
58
+ /** Set bindings (stored on pipeline and set before each call) */
59
+ abstract setBindings(bindings: Record<string, Binding>): void;
60
+ /** Uniforms
61
+ * @deprecated Only supported on WebGL devices.
62
+ * @note textures, samplers and uniform buffers should be set via `setBindings()`, these are not considered uniforms.
63
+ * @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.
64
+ */
65
+ abstract setUniforms(bindings: Record<string, UniformValue>): void;
66
+ /** Draw call */
67
+ abstract draw(options: {
68
+ /** Render pass to draw into (targeting screen or framebuffer) */
69
+ renderPass?: RenderPass;
70
+ /** vertex attributes */
71
+ vertexArray: VertexArray;
72
+ /** Number of "rows" in index buffer */
73
+ indexCount?: number;
74
+ /** Number of "rows" in 'vertex' buffers */
75
+ vertexCount?: number;
76
+ /** Number of "rows" in 'instance' buffers */
77
+ instanceCount?: number;
78
+ /** First vertex to draw from */
79
+ firstVertex?: number;
80
+ /** First index to draw from */
81
+ firstIndex?: number;
82
+ /** First instance to draw from */
83
+ firstInstance?: number;
84
+ baseVertex?: number;
85
+ /** Transform feedback. WebGL 2 only. */
86
+ transformFeedback?: TransformFeedback;
87
+ }): void;
88
+ }
89
+ //# sourceMappingURL=render-pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-pipeline.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/render-pipeline.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAC,iBAAiB,EAAE,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAC,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG;IAGhD,6BAA6B;IAC7B,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,gEAAgE;IAChE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,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iEAAiE;IACjE,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAC7D;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,IAAI;IAElE,gBAAgB;IAChB,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE;QACrB,iEAAiE;QACjE,UAAU,CAAC,EAAE,UAAU,CAAC;QACxB,wBAAwB;QACxB,WAAW,EAAE,WAAW,CAAC;QACzB,uCAAuC;QACvC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,2CAA2C;QAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,6CAA6C;QAC7C,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gCAAgC;QAChC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,+BAA+B;QAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kCAAkC;QAClC,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,wCAAwC;QACxC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;KACvC,GAAG,IAAI;CACT"}
@@ -0,0 +1,36 @@
1
+ let _Symbol$toStringTag;
2
+ import { Resource } from "./resource.js";
3
+ _Symbol$toStringTag = Symbol.toStringTag;
4
+ export class RenderPipeline extends Resource {
5
+ get [_Symbol$toStringTag]() {
6
+ return 'RenderPipeline';
7
+ }
8
+ constructor(device, props) {
9
+ super(device, props, RenderPipeline.defaultProps);
10
+ this.hash = '';
11
+ this.vs = void 0;
12
+ this.fs = void 0;
13
+ this.shaderLayout = void 0;
14
+ this.bufferLayout = void 0;
15
+ this.shaderLayout = this.props.shaderLayout;
16
+ this.bufferLayout = this.props.bufferLayout || [];
17
+ }
18
+ }
19
+ RenderPipeline.defaultProps = {
20
+ ...Resource.defaultProps,
21
+ vs: null,
22
+ vsEntryPoint: '',
23
+ vsConstants: {},
24
+ fs: null,
25
+ fsEntryPoint: '',
26
+ fsConstants: {},
27
+ shaderLayout: null,
28
+ bufferLayout: [],
29
+ topology: 'triangle-list',
30
+ parameters: {},
31
+ vertexCount: 0,
32
+ instanceCount: 0,
33
+ bindings: {},
34
+ uniforms: {}
35
+ };
36
+ //# sourceMappingURL=render-pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-pipeline.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","RenderPipeline","constructor","device","props","defaultProps","hash","vs","fs","shaderLayout","bufferLayout","vsEntryPoint","vsConstants","fsEntryPoint","fsConstants","topology","parameters","vertexCount","instanceCount","bindings","uniforms"],"sources":["../../../src/adapter/resources/render-pipeline.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {Device} from '../device';\nimport type {UniformValue} from '../types/types';\nimport type {PrimitiveTopology, RenderPipelineParameters} from '../types/parameters';\nimport type {ShaderLayout, Binding} from '../types/shader-layout';\nimport type {BufferLayout} from '../types/buffer-layout';\n// import {normalizeAttributeMap} from '../helpers/attribute-bindings';\nimport {Resource, ResourceProps} from './resource';\nimport type {Shader} from './shader';\nimport type {RenderPass} from './render-pass';\nimport {VertexArray} from './vertex-array';\nimport {TransformFeedback} from './transform-feedback';\n\nexport type RenderPipelineProps = ResourceProps & {\n // Shaders and shader layout\n\n /** Compiled vertex shader */\n vs?: Shader | null;\n /** Vertex shader entry point (defaults to 'main'). WGSL only */\n vsEntryPoint?: string; //\n /** Constants to apply to compiled vertex shader (WGSL only) */\n vsConstants?: Record<string, number>; // WGSL only\n /** Compiled fragment shader */\n fs?: Shader | null;\n /** Fragment shader entry point (defaults to 'main'). WGSL only */\n fsEntryPoint?: string; // WGSL only\n /** Constants to apply to compiled fragment shader (WGSL only) */\n fsConstants?: Record<string, number>;\n\n /** Describes the attributes and bindings exposed by the pipeline shader(s). */\n shaderLayout?: ShaderLayout | null;\n /**\n * Describes the buffers accepted by this pipeline and how they are mapped to shader attributes.\n * A default mapping of one buffer per attribute is always created.\n */\n bufferLayout?: BufferLayout[]; // Record<string, Omit<BufferLayout, 'name'>\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: PrimitiveTopology;\n /** Parameters that are controlled by pipeline */\n parameters?: RenderPipelineParameters;\n\n // Can be changed after creation\n // TODO make pipeline immutable? these could be supplied to draw as parameters, in WebGPU they are set on the render pass\n\n /** Number of vertices */\n vertexCount?: number;\n /** Number of instances */\n instanceCount?: number;\n\n /** Buffers, Textures, Samplers for the shader bindings */\n bindings?: Record<string, Binding>;\n /** @deprecated uniforms (WebGL only) */\n uniforms?: Record<string, UniformValue>;\n};\n\n/**\n * A compiled and linked shader program\n */\nexport abstract class RenderPipeline extends Resource<RenderPipelineProps> {\n static override defaultProps: Required<RenderPipelineProps> = {\n ...Resource.defaultProps,\n\n vs: null,\n vsEntryPoint: '', // main\n vsConstants: {},\n\n fs: null,\n fsEntryPoint: '', // main\n fsConstants: {},\n\n shaderLayout: null,\n bufferLayout: [],\n topology: 'triangle-list',\n parameters: {},\n\n vertexCount: 0,\n instanceCount: 0,\n\n bindings: {},\n uniforms: {}\n };\n\n override get [Symbol.toStringTag](): string {\n return 'RenderPipeline';\n }\n\n hash: string = '';\n abstract readonly vs: Shader;\n abstract readonly fs: Shader | null;\n /** The merged layout */\n shaderLayout: ShaderLayout;\n /** Buffer map describing buffer interleaving etc */\n readonly bufferLayout: BufferLayout[];\n\n constructor(device: Device, props: RenderPipelineProps) {\n super(device, props, RenderPipeline.defaultProps);\n this.shaderLayout = this.props.shaderLayout;\n this.bufferLayout = this.props.bufferLayout || [];\n }\n\n /** Set bindings (stored on pipeline and set before each call) */\n abstract setBindings(bindings: Record<string, Binding>): void;\n /** Uniforms\n * @deprecated Only supported on WebGL devices.\n * @note textures, samplers and uniform buffers should be set via `setBindings()`, these are not considered uniforms.\n * @note In WebGL uniforms have a performance penalty, they are reset before each call to enable pipeline sharing.\n */\n abstract setUniforms(bindings: Record<string, UniformValue>): void;\n\n /** Draw call */\n abstract draw(options: {\n /** Render pass to draw into (targeting screen or framebuffer) */\n renderPass?: RenderPass;\n /** vertex attributes */\n vertexArray: VertexArray;\n /** Number of \"rows\" in index buffer */\n indexCount?: number;\n /** Number of \"rows\" in 'vertex' buffers */\n vertexCount?: number;\n /** Number of \"rows\" in 'instance' buffers */\n instanceCount?: number;\n /** First vertex to draw from */\n firstVertex?: number;\n /** First index to draw from */\n firstIndex?: number;\n /** First instance to draw from */\n firstInstance?: number;\n baseVertex?: number;\n /** Transform feedback. WebGL 2 only. */\n transformFeedback?: TransformFeedback;\n }): void;\n}\n"],"mappings":";SAOQA,QAAQ;AAAAC,mBAAA,GA4EAC,MAAM,CAACC,WAAW;AAxBlC,OAAO,MAAeC,cAAc,SAASJ,QAAQ,CAAsB;EAwBzE,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,gBAAgB;EACzB;EAUAI,WAAWA,CAACC,MAAc,EAAEC,KAA0B,EAAE;IACtD,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,cAAc,CAACI,YAAY,CAAC;IAAC,KATpDC,IAAI,GAAW,EAAE;IAAA,KACCC,EAAE;IAAA,KACFC,EAAE;IAAA,KAEpBC,YAAY;IAAA,KAEHC,YAAY;IAInB,IAAI,CAACD,YAAY,GAAG,IAAI,CAACL,KAAK,CAACK,YAAY;IAC3C,IAAI,CAACC,YAAY,GAAG,IAAI,CAACN,KAAK,CAACM,YAAY,IAAI,EAAE;EACnD;AAiCF;AAzEsBT,cAAc,CAClBI,YAAY,GAAkC;EAC5D,GAAGR,QAAQ,CAACQ,YAAY;EAExBE,EAAE,EAAE,IAAI;EACRI,YAAY,EAAE,EAAE;EAChBC,WAAW,EAAE,CAAC,CAAC;EAEfJ,EAAE,EAAE,IAAI;EACRK,YAAY,EAAE,EAAE;EAChBC,WAAW,EAAE,CAAC,CAAC;EAEfL,YAAY,EAAE,IAAI;EAClBC,YAAY,EAAE,EAAE;EAChBK,QAAQ,EAAE,eAAe;EACzBC,UAAU,EAAE,CAAC,CAAC;EAEdC,WAAW,EAAE,CAAC;EACdC,aAAa,EAAE,CAAC;EAEhBC,QAAQ,EAAE,CAAC,CAAC;EACZC,QAAQ,EAAE,CAAC;AACb,CAAC"}
@@ -0,0 +1,73 @@
1
+ import type { Device } from '../device';
2
+ export type ResourceProps = {
3
+ /** Name of resource, mainly for debugging purposes. A unique name will be assigned if not provided */
4
+ id?: string;
5
+ /** Handle for the underlying resources (WebGL object or WebGPU handle) */
6
+ handle?: any;
7
+ /** User provided data stored on this resource */
8
+ userData?: {
9
+ [key: string]: any;
10
+ };
11
+ };
12
+ /**
13
+ * Base class for GPU (WebGPU/WebGL) Resources
14
+ */
15
+ export declare abstract class Resource<Props extends ResourceProps> {
16
+ /** Default properties for resource */
17
+ static defaultProps: Required<ResourceProps>;
18
+ abstract get [Symbol.toStringTag](): string;
19
+ /** props.id, for debugging. */
20
+ id: string;
21
+ readonly props: Required<Props>;
22
+ readonly userData: Record<string, unknown>;
23
+ abstract readonly device: Device;
24
+ private _device;
25
+ /** Whether this resource has been destroyed */
26
+ destroyed: boolean;
27
+ /** For resources that allocate GPU memory */
28
+ private allocatedBytes;
29
+ /** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created "sub" resources. */
30
+ private _attachedResources;
31
+ /**
32
+ * Create a new Resource. Called from Subclass
33
+ */
34
+ constructor(device: Device, props: Props, defaultProps: Required<Props>);
35
+ /**
36
+ * destroy can be called on any resource to release it before it is garbage collected.
37
+ */
38
+ destroy(): void;
39
+ /** @deprecated Use destroy() */
40
+ delete(): this;
41
+ toString(): string;
42
+ /**
43
+ * Combines a map of user props and default props, only including props from defaultProps
44
+ * @returns returns a map of overridden default props
45
+ */
46
+ getProps(): object;
47
+ /**
48
+ * Attaches a resource. Attached resources are auto destroyed when this resource is destroyed
49
+ * Called automatically when sub resources are auto created but can be called by application
50
+ */
51
+ attachResource(resource: Resource<unknown>): void;
52
+ /**
53
+ * Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.
54
+ */
55
+ detachResource(resource: Resource<unknown>): void;
56
+ /**
57
+ * Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.
58
+ */
59
+ destroyAttachedResource(resource: Resource<unknown>): void;
60
+ /** Destroy all owned resources. Make sure the resources are no longer needed before calling. */
61
+ destroyAttachedResources(): void;
62
+ /** Perform all destroy steps. Can be called by derived resources when overriding destroy() */
63
+ protected destroyResource(): void;
64
+ /** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */
65
+ protected removeStats(): void;
66
+ /** Called by subclass to track memory allocations */
67
+ protected trackAllocatedMemory(bytes: number, name?: string): void;
68
+ /** Called by subclass to track memory deallocations */
69
+ protected trackDeallocatedMemory(name?: string): void;
70
+ /** Called by resource constructor to track object creation */
71
+ private addStats;
72
+ }
73
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/resource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AAGtC,MAAM,MAAM,aAAa,GAAG;IAC1B,sGAAsG;IACtG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,kDAAkD;IAClD,QAAQ,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;CACjC,CAAA;AAED;;GAEG;AACH,8BAAsB,QAAQ,CAAC,KAAK,SAAS,aAAa;IACxD,sCAAsC;IACtC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,aAAa,CAAC,CAI1C;IAEF,QAAQ,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC;IAE5C,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,KAAK,EAAE,QAAQ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ils.js";
2
+ export class Resource {
3
+ constructor(device, props, defaultProps) {
4
+ this.id = void 0;
5
+ this.props = void 0;
6
+ this.userData = {};
7
+ this.device = void 0;
8
+ this._device = void 0;
9
+ this.destroyed = false;
10
+ this.allocatedBytes = 0;
11
+ this._attachedResources = new Set();
12
+ if (!device) {
13
+ throw new Error('no device');
14
+ }
15
+ this._device = device;
16
+ this.props = selectivelyMerge(props, defaultProps);
17
+ const id = this.props.id !== 'undefined' ? this.props.id : uid(this[Symbol.toStringTag]);
18
+ this.props.id = id;
19
+ this.id = id;
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();
45
+ }
46
+ }
47
+ destroyAttachedResources() {
48
+ for (const resource of Object.values(this._attachedResources)) {
49
+ resource.destroy();
50
+ }
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
+ }
85
+ Resource.defaultProps = {
86
+ id: 'undefined',
87
+ handle: undefined,
88
+ userData: undefined
89
+ };
90
+ function selectivelyMerge(props, defaultProps) {
91
+ const mergedProps = {
92
+ ...defaultProps
93
+ };
94
+ for (const key in props) {
95
+ if (props[key] !== undefined) {
96
+ mergedProps[key] = props[key];
97
+ }
98
+ }
99
+ return mergedProps;
100
+ }
101
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","names":["uid","Resource","constructor","device","props","defaultProps","id","userData","_device","destroyed","allocatedBytes","_attachedResources","Set","Error","selectivelyMerge","Symbol","toStringTag","addStats","destroy","destroyResource","delete","toString","name","getProps","attachResource","resource","add","detachResource","destroyAttachedResource","destroyAttachedResources","Object","values","removeStats","stats","statsManager","getStats","get","decrementCount","trackAllocatedMemory","bytes","arguments","length","undefined","addCount","trackDeallocatedMemory","subtractCount","incrementCount","handle","mergedProps","key"],"sources":["../../../src/adapter/resources/resource.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {Device} from '../device';\nimport {uid} from '../../utils/utils';\n\nexport type ResourceProps = {\n /** Name of resource, mainly for debugging purposes. A unique name will be assigned if not provided */\n id?: string;\n /** Handle for the underlying resources (WebGL object or WebGPU handle) */\n handle?: any;\n /** User provided data stored on this resource */\n userData?: {[key: string]: any};\n}\n\n/**\n * Base class for GPU (WebGPU/WebGL) Resources\n */\nexport abstract class Resource<Props extends ResourceProps> {\n /** Default properties for resource */\n static defaultProps: Required<ResourceProps> = {\n id: 'undefined',\n handle: undefined,\n userData: undefined,\n };\n \n abstract get [Symbol.toStringTag](): string;\n\n /** props.id, for debugging. */\n id: string;\n readonly props: Required<Props>;\n readonly userData: Record<string, unknown> = {};\n abstract readonly device: Device;\n private _device: Device;\n\n /** Whether this resource has been destroyed */\n destroyed: boolean = false;\n /** For resources that allocate GPU memory */\n private allocatedBytes: number = 0;\n /** Attached resources will be destroyed when this resource is destroyed. Tracks auto-created \"sub\" resources. */\n private _attachedResources = new Set<Resource<unknown>>();\n\n\n /**\n * Create a new Resource. Called from Subclass\n */\n constructor(device: Device, props: Props, defaultProps: Required<Props>) {\n if (!device) {\n throw new Error('no device');\n }\n this._device = device;\n this.props = selectivelyMerge<Props>(props, defaultProps);\n\n const id = this.props.id !== 'undefined' ? this.props.id as string : uid(this[Symbol.toStringTag]);\n this.props.id = id;\n this.id = id;\n this.userData = this.props.userData || {};\n\n this.addStats();\n }\n\n /**\n * destroy can be called on any resource to release it before it is garbage collected.\n */\n destroy(): void {\n this.destroyResource();\n }\n\n /** @deprecated Use destroy() */\n delete(): this {\n this.destroy();\n return this;\n }\n\n toString(): string {\n return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;\n }\n\n /**\n * Combines a map of user props and default props, only including props from defaultProps\n * @returns returns a map of overridden default props\n */\n getProps(): object {\n return this.props;\n }\n\n // ATTACHED RESOURCES\n\n /** \n * Attaches a resource. Attached resources are auto destroyed when this resource is destroyed\n * Called automatically when sub resources are auto created but can be called by application\n */\n attachResource(resource: Resource<unknown>): void {\n this._attachedResources.add(resource);\n }\n\n /** \n * Detach an attached resource. The resource will no longer be auto-destroyed when this resource is destroyed.\n */\n detachResource(resource: Resource<unknown>): void {\n this._attachedResources.delete(resource);\n }\n \n /** \n * Destroys a resource (only if owned), and removes from the owned (auto-destroy) list for this resource.\n */\n destroyAttachedResource(resource: Resource<unknown>): void {\n if (this._attachedResources.delete(resource)) {\n resource.destroy();\n }\n }\n\n /** Destroy all owned resources. Make sure the resources are no longer needed before calling. */\n destroyAttachedResources(): void {\n for (const resource of Object.values(this._attachedResources)) {\n resource.destroy();\n }\n // don't remove while we are iterating\n this._attachedResources = new Set<Resource<unknown>>();\n }\n\n // PROTECTED METHODS\n\n /** Perform all destroy steps. Can be called by derived resources when overriding destroy() */\n protected destroyResource(): void {\n this.destroyAttachedResources();\n this.removeStats();\n this.destroyed = true;\n }\n\n /** Called by .destroy() to track object destruction. Subclass must call if overriding destroy() */\n protected removeStats(): void {\n const stats = this._device.statsManager.getStats('Resource Counts');\n const name = this[Symbol.toStringTag];\n stats.get(`${name}s Active`).decrementCount();\n }\n\n /** Called by subclass to track memory allocations */\n protected trackAllocatedMemory(bytes: number, name = this[Symbol.toStringTag]): void {\n const stats = this._device.statsManager.getStats('Resource Counts');\n stats.get('GPU Memory').addCount(bytes);\n stats.get(`${name} Memory`).addCount(bytes);\n this.allocatedBytes = bytes;\n }\n\n /** Called by subclass to track memory deallocations */\n protected trackDeallocatedMemory(name = this[Symbol.toStringTag]): void {\n const stats = this._device.statsManager.getStats('Resource Counts');\n stats.get('GPU Memory').subtractCount(this.allocatedBytes);\n stats.get(`${name} Memory`).subtractCount(this.allocatedBytes);\n this.allocatedBytes = 0;\n }\n\n /** Called by resource constructor to track object creation */\n private addStats(): void {\n const stats = this._device.statsManager.getStats('Resource Counts');\n const name = this[Symbol.toStringTag];\n stats.get('Resources Created').incrementCount();\n stats.get(`${name}s Created`).incrementCount();\n stats.get(`${name}s Active`).incrementCount();\n }\n}\n\n/**\n * Combines a map of user props and default props, only including props from defaultProps\n * @param props\n * @param defaultProps\n * @returns returns a map of overridden default props\n */\nfunction selectivelyMerge<Props>(props: Props, defaultProps: Required<Props>): Required<Props> {\n const mergedProps = {...defaultProps};\n for (const key in props) {\n if (props[key] !== undefined) {\n mergedProps[key] = props[key];\n }\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ACwB,cAAc,CAAC,CAAC;EAC/C;AACF;AA/IsB7C,QAAQ,CAErBI,YAAY,GAA4B;EAC7CC,EAAE,EAAE,WAAW;EACfyC,MAAM,EAAEL,SAAS;EACjBnC,QAAQ,EAAEmC;AACZ,CAAC;AAiJH,SAAS5B,gBAAgBA,CAAQV,KAAY,EAAEC,YAA6B,EAAmB;EAC7F,MAAM2C,WAAW,GAAG;IAAC,GAAG3C;EAAY,CAAC;EACrC,KAAK,MAAM4C,GAAG,IAAI7C,KAAK,EAAE;IACvB,IAAIA,KAAK,CAAC6C,GAAG,CAAC,KAAKP,SAAS,EAAE;MAC5BM,WAAW,CAACC,GAAG,CAAC,GAAG7C,KAAK,CAAC6C,GAAG,CAAC;IAC/B;EACF;EACA,OAAOD,WAAW;AACpB"}
@@ -0,0 +1,42 @@
1
+ import type { Device } from '../device';
2
+ import { CompareFunction } from '../types/parameters';
3
+ import { Resource, ResourceProps } from './resource';
4
+ /** Edge values sampling mode */
5
+ export type SamplerAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
6
+ /** Sampler filtering mode */
7
+ export type SamplerFilterMode = 'nearest' | 'linear';
8
+ /**
9
+ * Properties for initializing a sampler
10
+ */
11
+ export type SamplerProps = ResourceProps & {
12
+ /** Comparison / shadow samplers are used with depth textures. See the `Sampler.compare` field */
13
+ type?: 'color-sampler' | 'comparison-sampler';
14
+ /** Edge value sampling in X direction */
15
+ addressModeU?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
16
+ /** Edge value sampling in Y direction */
17
+ addressModeV?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
18
+ /** Edge value sampling in Z direction */
19
+ addressModeW?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
20
+ /** Magnification: the area of the fragment in texture space is smaller than a texel */
21
+ magFilter?: 'nearest' | 'linear';
22
+ /** Minification: the area of the fragment in texture space is larger than a texel */
23
+ minFilter?: 'nearest' | 'linear';
24
+ /** mipmapping: select between multiple mipmaps based on angle and size of the texture relative to the screen. */
25
+ mipmapFilter?: 'nearest' | 'linear';
26
+ /** Affects the mipmap image selection */
27
+ lodMinClamp?: number;
28
+ /** Affects the mipmap image selection */
29
+ lodMaxClamp?: number;
30
+ /** Maximum number of samples that can be taken of the texture during any one texture fetch */
31
+ maxAnisotropy?: number;
32
+ /** How to compare reference values provided in shader shadow sampler calls with those pulled from the texture */
33
+ compare?: CompareFunction;
34
+ };
35
+ export type SamplerParameters = Omit<SamplerProps, keyof ResourceProps>;
36
+ /** Immutable Sampler object */
37
+ export declare abstract class Sampler extends Resource<SamplerProps> {
38
+ static defaultProps: Required<SamplerProps>;
39
+ get [Symbol.toStringTag](): string;
40
+ constructor(device: Device, props: SamplerProps);
41
+ }
42
+ //# sourceMappingURL=sampler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/sampler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;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"}
@@ -0,0 +1,26 @@
1
+ let _Symbol$toStringTag;
2
+ import { Resource } from "./resource.js";
3
+ _Symbol$toStringTag = Symbol.toStringTag;
4
+ export class Sampler extends Resource {
5
+ get [_Symbol$toStringTag]() {
6
+ return 'Sampler';
7
+ }
8
+ constructor(device, props) {
9
+ super(device, props, Sampler.defaultProps);
10
+ }
11
+ }
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.js","names":["Resource","_Symbol$toStringTag","Symbol","toStringTag","Sampler","constructor","device","props","defaultProps","type","addressModeU","addressModeV","addressModeW","magFilter","minFilter","mipmapFilter","lodMinClamp","lodMaxClamp","compare","maxAnisotropy"],"sources":["../../../src/adapter/resources/sampler.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {Device} from '../device';\nimport {CompareFunction} from '../types/parameters';\nimport {Resource, ResourceProps} from './resource';\n\n/** Edge values sampling mode */\nexport type SamplerAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';\n\n/** Sampler filtering mode */\nexport type SamplerFilterMode = 'nearest' | 'linear';\n\n/**\n * Properties for initializing a sampler\n */\nexport type SamplerProps = ResourceProps & {\n /** Comparison / shadow samplers are used with depth textures. See the `Sampler.compare` field */\n type?: 'color-sampler' | 'comparison-sampler';\n /** Edge value sampling in X direction */\n addressModeU?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';\n /** Edge value sampling in Y direction */\n addressModeV?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';\n /** Edge value sampling in Z direction */\n addressModeW?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';\n\n /** Magnification: the area of the fragment in texture space is smaller than a texel */\n magFilter?: 'nearest' | 'linear';\n /** Minification: the area of the fragment in texture space is larger than a texel */\n minFilter?: 'nearest' | 'linear';\n /** mipmapping: select between multiple mipmaps based on angle and size of the texture relative to the screen. */\n mipmapFilter?: 'nearest' | 'linear';\n /** Affects the mipmap image selection */\n lodMinClamp?: number;\n /** Affects the mipmap image selection */\n lodMaxClamp?: number;\n /** Maximum number of samples that can be taken of the texture during any one texture fetch */\n maxAnisotropy?: number; \n /** How to compare reference values provided in shader shadow sampler calls with those pulled from the texture */\n compare?: CompareFunction;\n};\n\nexport type SamplerParameters = Omit<SamplerProps, keyof ResourceProps>;\n\n/** Immutable Sampler object */\nexport abstract class Sampler extends Resource<SamplerProps> {\n static override defaultProps: Required<SamplerProps> = {\n ...Resource.defaultProps,\n type: 'color-sampler',\n addressModeU: 'clamp-to-edge',\n addressModeV: 'clamp-to-edge',\n addressModeW: 'clamp-to-edge',\n magFilter: 'nearest',\n minFilter: 'nearest',\n mipmapFilter: 'nearest',\n lodMinClamp: 0,\n lodMaxClamp: 32, // Per WebGPU spec\n compare: 'less-equal',\n maxAnisotropy: 1\n };\n \n override get [Symbol.toStringTag](): string {\n return 'Sampler';\n }\n\n constructor(device: Device, props: SamplerProps) {\n super(device, props, Sampler.defaultProps);\n }\n}\n"],"mappings":";SAKQA,QAAQ;AAAAC,mBAAA,GAwDAC,MAAM,CAACC,WAAW;AAhBlC,OAAO,MAAeC,OAAO,SAASJ,QAAQ,CAAe;EAgB3D,KAAAC,mBAAA,IAA4C;IAC1C,OAAO,SAAS;EAClB;EAEAI,WAAWA,CAACC,MAAc,EAAEC,KAAmB,EAAE;IAC/C,KAAK,CAACD,MAAM,EAAEC,KAAK,EAAEH,OAAO,CAACI,YAAY,CAAC;EAC5C;AACF;AAvBsBJ,OAAO,CACXI,YAAY,GAA2B;EACrD,GAAGR,QAAQ,CAACQ,YAAY;EACxBC,IAAI,EAAE,eAAe;EACrBC,YAAY,EAAE,eAAe;EAC7BC,YAAY,EAAE,eAAe;EAC7BC,YAAY,EAAE,eAAe;EAC7BC,SAAS,EAAE,SAAS;EACpBC,SAAS,EAAE,SAAS;EACpBC,YAAY,EAAE,SAAS;EACvBC,WAAW,EAAE,CAAC;EACdC,WAAW,EAAE,EAAE;EACfC,OAAO,EAAE,YAAY;EACrBC,aAAa,EAAE;AACjB,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { Device } from '../device';
2
+ import { Resource, ResourceProps } from './resource';
3
+ import { CompilerMessage } from '../../lib/compiler-log/compiler-message';
4
+ /**
5
+ * Properties for a Shader
6
+ */
7
+ export type ShaderProps = ResourceProps & {
8
+ /** Shader language (defaults to auto) */
9
+ language?: 'glsl' | 'wgsl' | 'auto';
10
+ /** Which stage are we compiling? Required by WebGL and GLSL transpiler */
11
+ stage: 'vertex' | 'fragment' | 'compute';
12
+ /** Shader source code */
13
+ source: string;
14
+ /** Optional shader source map (WebGPU only) */
15
+ sourceMap?: string | null;
16
+ /** Optional shader entry point (WebGPU only) */
17
+ entryPoint?: string;
18
+ /** Show shader source in browser? */
19
+ debug?: 'never' | 'errors' | 'warnings' | 'always';
20
+ };
21
+ /**
22
+ * Immutable Shader object
23
+ * In WebGPU the handle can be copied between threads
24
+ */
25
+ export declare abstract class Shader extends Resource<ShaderProps> {
26
+ static defaultProps: Required<ShaderProps>;
27
+ get [Symbol.toStringTag](): string;
28
+ /** The stage of this shader */
29
+ readonly stage: 'vertex' | 'fragment' | 'compute';
30
+ /** The source code of this shader */
31
+ readonly source: string;
32
+ /** The compilation status of this shader. May be 'pending' if compilation is done asynchronously */
33
+ compilationStatus: 'success' | 'error' | 'pending';
34
+ /** Create a new Shader instance */
35
+ constructor(device: Device, props: ShaderProps);
36
+ /** Get compiler log asynchronously */
37
+ abstract getCompilationInfo(): Promise<readonly CompilerMessage[]>;
38
+ /** Get compiler log synchronously (WebGL only) */
39
+ getCompilationInfoSync(): readonly CompilerMessage[] | null;
40
+ /** In browser logging of errors */
41
+ debugShader(): Promise<void>;
42
+ /** In-browser UI logging of errors */
43
+ protected _displayShaderLog(messages: readonly CompilerMessage[]): void;
44
+ }
45
+ //# sourceMappingURL=shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../../src/adapter/resources/shader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAGnD,OAAO,EAAC,eAAe,EAAC,MAAM,yCAAyC,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CAuCxE"}
@@ -0,0 +1,90 @@
1
+ let _Symbol$toStringTag;
2
+ import { Resource } from "./resource.js";
3
+ import { uid } from "../../utils/utils.js";
4
+ import { formatCompilerLog } from "../../lib/compiler-log/format-compiler-log.js";
5
+ import { getShaderInfo } from "../../lib/compiler-log/get-shader-info.js";
6
+ _Symbol$toStringTag = Symbol.toStringTag;
7
+ export class Shader extends Resource {
8
+ get [_Symbol$toStringTag]() {
9
+ return 'Shader';
10
+ }
11
+ constructor(device, props) {
12
+ super(device, {
13
+ id: getShaderIdFromProps(props),
14
+ ...props
15
+ }, Shader.defaultProps);
16
+ this.stage = void 0;
17
+ this.source = void 0;
18
+ this.compilationStatus = 'pending';
19
+ this.stage = this.props.stage;
20
+ this.source = this.props.source;
21
+ }
22
+ getCompilationInfoSync() {
23
+ return null;
24
+ }
25
+ async debugShader() {
26
+ switch (this.props.debug) {
27
+ case 'never':
28
+ return;
29
+ case 'errors':
30
+ if (this.compilationStatus === 'success') {
31
+ return;
32
+ }
33
+ break;
34
+ case 'warnings':
35
+ case 'always':
36
+ break;
37
+ }
38
+ const messages = await this.getCompilationInfo();
39
+ if (this.props.debug === 'warnings' && (messages === null || messages === void 0 ? void 0 : messages.length) === 0) {
40
+ return;
41
+ }
42
+ this._displayShaderLog(messages);
43
+ }
44
+ _displayShaderLog(messages) {
45
+ var _document, _errors$;
46
+ if (typeof document === 'undefined' || !((_document = document) !== null && _document !== void 0 && _document.createElement)) {
47
+ return;
48
+ }
49
+ const shaderName = getShaderInfo(this.source).name;
50
+ const shaderTitle = `${this.stage} ${shaderName}`;
51
+ const htmlLog = formatCompilerLog(messages, this.source, {
52
+ showSourceCode: 'all',
53
+ html: true
54
+ });
55
+ const button = document.createElement('Button');
56
+ button.innerHTML = `
57
+ <h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
58
+ <code style="user-select:text;"><pre>
59
+ ${htmlLog}
60
+ </pre></code>`;
61
+ button.style.top = '10px';
62
+ button.style.left = '10px';
63
+ button.style.position = 'absolute';
64
+ button.style.zIndex = '9999';
65
+ button.style.width = '100%';
66
+ button.style.textAlign = 'left';
67
+ document.body.appendChild(button);
68
+ const errors = document.getElementsByClassName('luma-compiler-log-error');
69
+ if ((_errors$ = errors[0]) !== null && _errors$ !== void 0 && _errors$.scrollIntoView) {
70
+ errors[0].scrollIntoView();
71
+ }
72
+ button.onclick = () => {
73
+ const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
74
+ navigator.clipboard.writeText(dataURI);
75
+ };
76
+ }
77
+ }
78
+ Shader.defaultProps = {
79
+ ...Resource.defaultProps,
80
+ language: 'auto',
81
+ stage: 'vertex',
82
+ source: '',
83
+ sourceMap: null,
84
+ entryPoint: 'main',
85
+ debug: 'errors'
86
+ };
87
+ function getShaderIdFromProps(props) {
88
+ return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
89
+ }
90
+ //# sourceMappingURL=shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shader.js","names":["Resource","uid","formatCompilerLog","getShaderInfo","_Symbol$toStringTag","Symbol","toStringTag","Shader","constructor","device","props","id","getShaderIdFromProps","defaultProps","stage","source","compilationStatus","getCompilationInfoSync","debugShader","debug","messages","getCompilationInfo","length","_displayShaderLog","_document","_errors$","document","createElement","shaderName","name","shaderTitle","htmlLog","showSourceCode","html","button","innerHTML","style","top","left","position","zIndex","width","textAlign","body","appendChild","errors","getElementsByClassName","scrollIntoView","onclick","dataURI","encodeURIComponent","navigator","clipboard","writeText","language","sourceMap","entryPoint"],"sources":["../../../src/adapter/resources/shader.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {Device} from '../device';\nimport {Resource, ResourceProps} from './resource';\n// import { log } from '../../utils/log';\nimport {uid} from '../../utils/utils';\nimport {CompilerMessage} from '../../lib/compiler-log/compiler-message';\nimport {formatCompilerLog} from '../../lib/compiler-log/format-compiler-log';\nimport {getShaderInfo} from '../../lib/compiler-log/get-shader-info';\n\n/**\n * Properties for a Shader\n */\nexport type ShaderProps = ResourceProps & {\n /** Shader language (defaults to auto) */\n language?: 'glsl' | 'wgsl' | 'auto';\n /** Which stage are we compiling? Required by WebGL and GLSL transpiler */\n stage: 'vertex' | 'fragment' | 'compute';\n /** Shader source code */\n source: string;\n /** Optional shader source map (WebGPU only) */\n sourceMap?: string | null;\n /** Optional shader entry point (WebGPU only) */\n entryPoint?: string;\n /** Show shader source in browser? */\n debug?: 'never' | 'errors' | 'warnings' | 'always';\n};\n\n/**\n * Immutable Shader object\n * In WebGPU the handle can be copied between threads\n */\nexport abstract class Shader extends Resource<ShaderProps> {\n static override defaultProps: Required<ShaderProps> = {\n ...Resource.defaultProps,\n language: 'auto',\n stage: 'vertex',\n source: '',\n sourceMap: null,\n entryPoint: 'main',\n debug: 'errors'\n };\n\n override get [Symbol.toStringTag](): string {\n return 'Shader';\n }\n\n /** The stage of this shader */\n readonly stage: 'vertex' | 'fragment' | 'compute';\n /** The source code of this shader */\n readonly source: string;\n /** The compilation status of this shader. May be 'pending' if compilation is done asynchronously */\n compilationStatus: 'success' | 'error' | 'pending' = 'pending';\n\n /** Create a new Shader instance */\n constructor(device: Device, props: ShaderProps) {\n super(device, {id: getShaderIdFromProps(props), ...props}, Shader.defaultProps);\n this.stage = this.props.stage;\n this.source = this.props.source;\n }\n\n /** Get compiler log asynchronously */\n abstract getCompilationInfo(): Promise<readonly CompilerMessage[]>;\n\n /** Get compiler log synchronously (WebGL only) */\n getCompilationInfoSync(): readonly CompilerMessage[] | null {\n return null;\n }\n\n // PORTABLE HELPERS\n\n /** In browser logging of errors */\n async debugShader(): Promise<void> {\n switch (this.props.debug) {\n case 'never':\n return;\n case 'errors':\n // On WebGL - Don't extract the log unless errors\n if (this.compilationStatus === 'success') {\n return;\n }\n break;\n case 'warnings':\n case 'always':\n break;\n }\n\n const messages = await this.getCompilationInfo();\n if (this.props.debug === 'warnings' && messages?.length === 0) {\n return;\n }\n this._displayShaderLog(messages);\n }\n\n // PRIVATE\n\n /** In-browser UI logging of errors */\n protected _displayShaderLog(messages: readonly CompilerMessage[]): void {\n // Return if under Node.js / incomplete `document` polyfills\n if (typeof document === 'undefined' || !document?.createElement) {\n return;\n }\n\n const shaderName: string = getShaderInfo(this.source).name;\n const shaderTitle: string = `${this.stage} ${shaderName}`;\n const htmlLog = formatCompilerLog(messages, this.source, {showSourceCode: 'all', html: true});\n\n // Make it clickable so we can copy to clipboard\n const button = document.createElement('Button');\n button.innerHTML = `\n<h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />\n<code style=\"user-select:text;\"><pre>\n${htmlLog}\n</pre></code>`;\n button.style.top = '10px';\n button.style.left = '10px';\n button.style.position = 'absolute';\n button.style.zIndex = '9999';\n button.style.width = '100%';\n button.style.textAlign = 'left';\n document.body.appendChild(button);\n\n const errors = document.getElementsByClassName('luma-compiler-log-error');\n if (errors[0]?.scrollIntoView) {\n errors[0].scrollIntoView();\n }\n\n // TODO - add a small embedded copy button (instead of main button)\n button.onclick = () => {\n // const source = this.source.replaceAll('\\n', '<br />');\n const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;\n navigator.clipboard.writeText(dataURI);\n };\n\n // TODO - add a small embedded close button\n }\n}\n\n// HELPERS\n\n/** Deduce an id, from shader source, or supplied id, or shader type */\nfunction getShaderIdFromProps(props: ShaderProps): string {\n return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);\n}\n"],"mappings":";SAEQA,QAAQ;AAAA,SAERC,GAAG;AAAA,SAEHC,iBAAiB;AAAA,SACjBC,aAAa;AAAAC,mBAAA,GAmCLC,MAAM,CAACC,WAAW;AAXlC,OAAO,MAAeC,MAAM,SAASP,QAAQ,CAAc;EAWzD,KAAAI,mBAAA,IAA4C;IAC1C,OAAO,QAAQ;EACjB;EAUAI,WAAWA,CAACC,MAAc,EAAEC,KAAkB,EAAE;IAC9C,KAAK,CAACD,MAAM,EAAE;MAACE,EAAE,EAAEC,oBAAoB,CAACF,KAAK,CAAC;MAAE,GAAGA;IA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