@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,2976 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['luma'] = factory();
6
+ else root['luma'] = factory();})(globalThis, function () {
7
+ "use strict";
8
+ var __exports__ = (() => {
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __export = (target, all) => {
15
+ for (var name2 in all)
16
+ __defProp(target, name2, { get: all[name2], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var __publicField = (obj, key, value) => {
28
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
29
+ return value;
30
+ };
31
+
32
+ // src/index.ts
33
+ var src_exports = {};
34
+ __export(src_exports, {
35
+ Buffer: () => Buffer2,
36
+ CanvasContext: () => CanvasContext,
37
+ CommandBuffer: () => CommandBuffer,
38
+ CommandEncoder: () => CommandEncoder,
39
+ ComputePass: () => ComputePass,
40
+ ComputePipeline: () => ComputePipeline,
41
+ Device: () => Device,
42
+ ExternalTexture: () => ExternalTexture,
43
+ Framebuffer: () => Framebuffer,
44
+ RenderPass: () => RenderPass,
45
+ RenderPipeline: () => RenderPipeline,
46
+ Resource: () => Resource,
47
+ Sampler: () => Sampler,
48
+ Shader: () => Shader,
49
+ StatsManager: () => StatsManager,
50
+ Texture: () => Texture,
51
+ TransformFeedback: () => TransformFeedback,
52
+ UniformBlock: () => UniformBlock,
53
+ UniformBufferLayout: () => UniformBufferLayout,
54
+ UniformStore: () => UniformStore,
55
+ VERSION: () => VERSION2,
56
+ VertexArray: () => VertexArray,
57
+ assert: () => assert2,
58
+ cancelAnimationFrame: () => cancelAnimationFrame,
59
+ cast: () => cast,
60
+ checkProps: () => checkProps,
61
+ decodeShaderAttributeType: () => decodeShaderAttributeType,
62
+ decodeShaderUniformType: () => decodeShaderUniformType,
63
+ decodeTextureFormat: () => decodeTextureFormat,
64
+ decodeVertexFormat: () => decodeVertexFormat,
65
+ deepEqual: () => deepEqual,
66
+ fillArray: () => fillArray,
67
+ formatCompilerLog: () => formatCompilerLog,
68
+ formatValue: () => formatValue,
69
+ getAttributeInfosFromLayouts: () => getAttributeInfosFromLayouts,
70
+ getDataTypeFromTypedArray: () => getDataTypeFromTypedArray,
71
+ getScratchArray: () => getScratchArray,
72
+ getScratchArrayBuffer: () => getScratchArrayBuffer,
73
+ getTypedArrayFromDataType: () => getTypedArrayFromDataType,
74
+ getVertexFormatFromAttribute: () => getVertexFormatFromAttribute,
75
+ glsl: () => glsl,
76
+ isNumberArray: () => isNumberArray,
77
+ isObjectEmpty: () => isObjectEmpty,
78
+ isPowerOfTwo: () => isPowerOfTwo,
79
+ isTypedArray: () => isTypedArray,
80
+ isUniformValue: () => isUniformValue,
81
+ loadFile: () => loadFile,
82
+ loadImage: () => loadImage,
83
+ loadImageBitmap: () => loadImageBitmap,
84
+ loadScript: () => loadScript,
85
+ log: () => log,
86
+ luma: () => luma,
87
+ makeRandomNumberGenerator: () => makeRandomNumberGenerator,
88
+ mergeShaderLayout: () => mergeShaderLayout,
89
+ random: () => random,
90
+ requestAnimationFrame: () => requestAnimationFrame,
91
+ setPathPrefix: () => setPathPrefix,
92
+ splitUniformsAndBindings: () => splitUniformsAndBindings,
93
+ stubRemovedMethods: () => stubRemovedMethods,
94
+ uid: () => uid
95
+ });
96
+
97
+ // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
98
+ function isElectron(mockUserAgent) {
99
+ if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
100
+ return true;
101
+ }
102
+ if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
103
+ return true;
104
+ }
105
+ const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
106
+ const userAgent = mockUserAgent || realUserAgent;
107
+ if (userAgent && userAgent.indexOf("Electron") >= 0) {
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+
113
+ // ../../node_modules/@probe.gl/env/dist/lib/is-browser.js
114
+ function isBrowser() {
115
+ const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
116
+ return !isNode || isElectron();
117
+ }
118
+
119
+ // ../../node_modules/@probe.gl/env/dist/lib/globals.js
120
+ var self_ = globalThis.self || globalThis.window || globalThis.global;
121
+ var window_ = globalThis.window || globalThis.self || globalThis.global;
122
+ var document_ = globalThis.document || {};
123
+ var process_ = globalThis.process || {};
124
+ var console_ = globalThis.console;
125
+ var navigator_ = globalThis.navigator || {};
126
+
127
+ // ../../node_modules/@probe.gl/env/dist/utils/globals.js
128
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "untranspiled source";
129
+ var isBrowser2 = isBrowser();
130
+
131
+ // ../../node_modules/@probe.gl/log/dist/utils/local-storage.js
132
+ function getStorage(type) {
133
+ try {
134
+ const storage = window[type];
135
+ const x = "__storage_test__";
136
+ storage.setItem(x, x);
137
+ storage.removeItem(x);
138
+ return storage;
139
+ } catch (e) {
140
+ return null;
141
+ }
142
+ }
143
+ var LocalStorage = class {
144
+ constructor(id, defaultConfig) {
145
+ let type = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "sessionStorage";
146
+ this.storage = void 0;
147
+ this.id = void 0;
148
+ this.config = void 0;
149
+ this.storage = getStorage(type);
150
+ this.id = id;
151
+ this.config = defaultConfig;
152
+ this._loadConfiguration();
153
+ }
154
+ getConfiguration() {
155
+ return this.config;
156
+ }
157
+ setConfiguration(configuration) {
158
+ Object.assign(this.config, configuration);
159
+ if (this.storage) {
160
+ const serialized = JSON.stringify(this.config);
161
+ this.storage.setItem(this.id, serialized);
162
+ }
163
+ }
164
+ _loadConfiguration() {
165
+ let configuration = {};
166
+ if (this.storage) {
167
+ const serializedConfiguration = this.storage.getItem(this.id);
168
+ configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
169
+ }
170
+ Object.assign(this.config, configuration);
171
+ return this;
172
+ }
173
+ };
174
+
175
+ // ../../node_modules/@probe.gl/log/dist/utils/formatters.js
176
+ function formatTime(ms) {
177
+ let formatted;
178
+ if (ms < 10) {
179
+ formatted = "".concat(ms.toFixed(2), "ms");
180
+ } else if (ms < 100) {
181
+ formatted = "".concat(ms.toFixed(1), "ms");
182
+ } else if (ms < 1e3) {
183
+ formatted = "".concat(ms.toFixed(0), "ms");
184
+ } else {
185
+ formatted = "".concat((ms / 1e3).toFixed(2), "s");
186
+ }
187
+ return formatted;
188
+ }
189
+ function leftPad(string) {
190
+ let length = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 8;
191
+ const padLength = Math.max(length - string.length, 0);
192
+ return "".concat(" ".repeat(padLength)).concat(string);
193
+ }
194
+ function formatImage(image, message, scale) {
195
+ let maxWidth = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 600;
196
+ const imageUrl = image.src.replace(/\(/g, "%28").replace(/\)/g, "%29");
197
+ if (image.width > maxWidth) {
198
+ scale = Math.min(scale, maxWidth / image.width);
199
+ }
200
+ const width = image.width * scale;
201
+ const height = image.height * scale;
202
+ const style = ["font-size:1px;", "padding:".concat(Math.floor(height / 2), "px ").concat(Math.floor(width / 2), "px;"), "line-height:".concat(height, "px;"), "background:url(".concat(imageUrl, ");"), "background-size:".concat(width, "px ").concat(height, "px;"), "color:transparent;"].join("");
203
+ return ["".concat(message, " %c+"), style];
204
+ }
205
+
206
+ // ../../node_modules/@probe.gl/log/dist/utils/color.js
207
+ var COLOR;
208
+ (function(COLOR2) {
209
+ COLOR2[COLOR2["BLACK"] = 30] = "BLACK";
210
+ COLOR2[COLOR2["RED"] = 31] = "RED";
211
+ COLOR2[COLOR2["GREEN"] = 32] = "GREEN";
212
+ COLOR2[COLOR2["YELLOW"] = 33] = "YELLOW";
213
+ COLOR2[COLOR2["BLUE"] = 34] = "BLUE";
214
+ COLOR2[COLOR2["MAGENTA"] = 35] = "MAGENTA";
215
+ COLOR2[COLOR2["CYAN"] = 36] = "CYAN";
216
+ COLOR2[COLOR2["WHITE"] = 37] = "WHITE";
217
+ COLOR2[COLOR2["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
218
+ COLOR2[COLOR2["BRIGHT_RED"] = 91] = "BRIGHT_RED";
219
+ COLOR2[COLOR2["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
220
+ COLOR2[COLOR2["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
221
+ COLOR2[COLOR2["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
222
+ COLOR2[COLOR2["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
223
+ COLOR2[COLOR2["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
224
+ COLOR2[COLOR2["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
225
+ })(COLOR || (COLOR = {}));
226
+ var BACKGROUND_INCREMENT = 10;
227
+ function getColor(color) {
228
+ if (typeof color !== "string") {
229
+ return color;
230
+ }
231
+ color = color.toUpperCase();
232
+ return COLOR[color] || COLOR.WHITE;
233
+ }
234
+ function addColor(string, color, background) {
235
+ if (!isBrowser && typeof string === "string") {
236
+ if (color) {
237
+ const colorCode = getColor(color);
238
+ string = "\x1B[".concat(colorCode, "m").concat(string, "\x1B[39m");
239
+ }
240
+ if (background) {
241
+ const colorCode = getColor(background);
242
+ string = "\x1B[".concat(colorCode + BACKGROUND_INCREMENT, "m").concat(string, "\x1B[49m");
243
+ }
244
+ }
245
+ return string;
246
+ }
247
+
248
+ // ../../node_modules/@probe.gl/log/dist/utils/autobind.js
249
+ function autobind(obj) {
250
+ let predefined = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["constructor"];
251
+ const proto = Object.getPrototypeOf(obj);
252
+ const propNames = Object.getOwnPropertyNames(proto);
253
+ const object = obj;
254
+ for (const key of propNames) {
255
+ const value = object[key];
256
+ if (typeof value === "function") {
257
+ if (!predefined.find((name2) => key === name2)) {
258
+ object[key] = value.bind(obj);
259
+ }
260
+ }
261
+ }
262
+ }
263
+
264
+ // ../../node_modules/@probe.gl/log/dist/utils/assert.js
265
+ function assert(condition, message) {
266
+ if (!condition) {
267
+ throw new Error(message || "Assertion failed");
268
+ }
269
+ }
270
+
271
+ // ../../node_modules/@probe.gl/log/dist/utils/hi-res-timestamp.js
272
+ function getHiResTimestamp() {
273
+ let timestamp;
274
+ if (isBrowser() && window_.performance) {
275
+ var _window$performance, _window$performance$n;
276
+ timestamp = window_ === null || window_ === void 0 ? void 0 : (_window$performance = window_.performance) === null || _window$performance === void 0 ? void 0 : (_window$performance$n = _window$performance.now) === null || _window$performance$n === void 0 ? void 0 : _window$performance$n.call(_window$performance);
277
+ } else if ("hrtime" in process_) {
278
+ var _process$hrtime;
279
+ const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
280
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
281
+ } else {
282
+ timestamp = Date.now();
283
+ }
284
+ return timestamp;
285
+ }
286
+
287
+ // ../../node_modules/@probe.gl/log/dist/log.js
288
+ var originalConsole = {
289
+ debug: isBrowser() ? console.debug || console.log : console.log,
290
+ log: console.log,
291
+ info: console.info,
292
+ warn: console.warn,
293
+ error: console.error
294
+ };
295
+ var DEFAULT_LOG_CONFIGURATION = {
296
+ enabled: true,
297
+ level: 0
298
+ };
299
+ function noop() {
300
+ }
301
+ var cache = {};
302
+ var ONCE = {
303
+ once: true
304
+ };
305
+ var Log = class {
306
+ constructor() {
307
+ let {
308
+ id
309
+ } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
310
+ id: ""
311
+ };
312
+ this.id = void 0;
313
+ this.VERSION = VERSION;
314
+ this._startTs = getHiResTimestamp();
315
+ this._deltaTs = getHiResTimestamp();
316
+ this._storage = void 0;
317
+ this.userData = {};
318
+ this.LOG_THROTTLE_TIMEOUT = 0;
319
+ this.id = id;
320
+ this.userData = {};
321
+ this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_LOG_CONFIGURATION);
322
+ this.timeStamp("".concat(this.id, " started"));
323
+ autobind(this);
324
+ Object.seal(this);
325
+ }
326
+ set level(newLevel) {
327
+ this.setLevel(newLevel);
328
+ }
329
+ get level() {
330
+ return this.getLevel();
331
+ }
332
+ isEnabled() {
333
+ return this._storage.config.enabled;
334
+ }
335
+ getLevel() {
336
+ return this._storage.config.level;
337
+ }
338
+ getTotal() {
339
+ return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
340
+ }
341
+ getDelta() {
342
+ return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
343
+ }
344
+ set priority(newPriority) {
345
+ this.level = newPriority;
346
+ }
347
+ get priority() {
348
+ return this.level;
349
+ }
350
+ getPriority() {
351
+ return this.level;
352
+ }
353
+ enable() {
354
+ let enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
355
+ this._storage.setConfiguration({
356
+ enabled
357
+ });
358
+ return this;
359
+ }
360
+ setLevel(level) {
361
+ this._storage.setConfiguration({
362
+ level
363
+ });
364
+ return this;
365
+ }
366
+ get(setting) {
367
+ return this._storage.config[setting];
368
+ }
369
+ set(setting, value) {
370
+ this._storage.setConfiguration({
371
+ [setting]: value
372
+ });
373
+ }
374
+ settings() {
375
+ if (console.table) {
376
+ console.table(this._storage.config);
377
+ } else {
378
+ console.log(this._storage.config);
379
+ }
380
+ }
381
+ assert(condition, message) {
382
+ assert(condition, message);
383
+ }
384
+ warn(message) {
385
+ return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
386
+ }
387
+ error(message) {
388
+ return this._getLogFunction(0, message, originalConsole.error, arguments);
389
+ }
390
+ deprecated(oldUsage, newUsage) {
391
+ return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
392
+ }
393
+ removed(oldUsage, newUsage) {
394
+ return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
395
+ }
396
+ probe(logLevel, message) {
397
+ return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
398
+ time: true,
399
+ once: true
400
+ });
401
+ }
402
+ log(logLevel, message) {
403
+ return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
404
+ }
405
+ info(logLevel, message) {
406
+ return this._getLogFunction(logLevel, message, console.info, arguments);
407
+ }
408
+ once(logLevel, message) {
409
+ return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
410
+ }
411
+ table(logLevel, table, columns) {
412
+ if (table) {
413
+ return this._getLogFunction(logLevel, table, console.table || noop, columns && [columns], {
414
+ tag: getTableHeader(table)
415
+ });
416
+ }
417
+ return noop;
418
+ }
419
+ image(_ref) {
420
+ let {
421
+ logLevel,
422
+ priority,
423
+ image,
424
+ message = "",
425
+ scale = 1
426
+ } = _ref;
427
+ if (!this._shouldLog(logLevel || priority)) {
428
+ return noop;
429
+ }
430
+ return isBrowser() ? logImageInBrowser({
431
+ image,
432
+ message,
433
+ scale
434
+ }) : logImageInNode({
435
+ image,
436
+ message,
437
+ scale
438
+ });
439
+ }
440
+ time(logLevel, message) {
441
+ return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
442
+ }
443
+ timeEnd(logLevel, message) {
444
+ return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
445
+ }
446
+ timeStamp(logLevel, message) {
447
+ return this._getLogFunction(logLevel, message, console.timeStamp || noop);
448
+ }
449
+ group(logLevel, message) {
450
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
451
+ collapsed: false
452
+ };
453
+ const options = normalizeArguments({
454
+ logLevel,
455
+ message,
456
+ opts
457
+ });
458
+ const {
459
+ collapsed
460
+ } = opts;
461
+ options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
462
+ return this._getLogFunction(options);
463
+ }
464
+ groupCollapsed(logLevel, message) {
465
+ let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
466
+ return this.group(logLevel, message, Object.assign({}, opts, {
467
+ collapsed: true
468
+ }));
469
+ }
470
+ groupEnd(logLevel) {
471
+ return this._getLogFunction(logLevel, "", console.groupEnd || noop);
472
+ }
473
+ withGroup(logLevel, message, func) {
474
+ this.group(logLevel, message)();
475
+ try {
476
+ func();
477
+ } finally {
478
+ this.groupEnd(logLevel)();
479
+ }
480
+ }
481
+ trace() {
482
+ if (console.trace) {
483
+ console.trace();
484
+ }
485
+ }
486
+ _shouldLog(logLevel) {
487
+ return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
488
+ }
489
+ _getLogFunction(logLevel, message, method, args, opts) {
490
+ if (this._shouldLog(logLevel)) {
491
+ opts = normalizeArguments({
492
+ logLevel,
493
+ message,
494
+ args,
495
+ opts
496
+ });
497
+ method = method || opts.method;
498
+ assert(method);
499
+ opts.total = this.getTotal();
500
+ opts.delta = this.getDelta();
501
+ this._deltaTs = getHiResTimestamp();
502
+ const tag = opts.tag || opts.message;
503
+ if (opts.once && tag) {
504
+ if (!cache[tag]) {
505
+ cache[tag] = getHiResTimestamp();
506
+ } else {
507
+ return noop;
508
+ }
509
+ }
510
+ message = decorateMessage(this.id, opts.message, opts);
511
+ return method.bind(console, message, ...opts.args);
512
+ }
513
+ return noop;
514
+ }
515
+ };
516
+ Log.VERSION = VERSION;
517
+ function normalizeLogLevel(logLevel) {
518
+ if (!logLevel) {
519
+ return 0;
520
+ }
521
+ let resolvedLevel;
522
+ switch (typeof logLevel) {
523
+ case "number":
524
+ resolvedLevel = logLevel;
525
+ break;
526
+ case "object":
527
+ resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
528
+ break;
529
+ default:
530
+ return 0;
531
+ }
532
+ assert(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
533
+ return resolvedLevel;
534
+ }
535
+ function normalizeArguments(opts) {
536
+ const {
537
+ logLevel,
538
+ message
539
+ } = opts;
540
+ opts.logLevel = normalizeLogLevel(logLevel);
541
+ const args = opts.args ? Array.from(opts.args) : [];
542
+ while (args.length && args.shift() !== message) {
543
+ }
544
+ switch (typeof logLevel) {
545
+ case "string":
546
+ case "function":
547
+ if (message !== void 0) {
548
+ args.unshift(message);
549
+ }
550
+ opts.message = logLevel;
551
+ break;
552
+ case "object":
553
+ Object.assign(opts, logLevel);
554
+ break;
555
+ default:
556
+ }
557
+ if (typeof opts.message === "function") {
558
+ opts.message = opts.message();
559
+ }
560
+ const messageType = typeof opts.message;
561
+ assert(messageType === "string" || messageType === "object");
562
+ return Object.assign(opts, {
563
+ args
564
+ }, opts.opts);
565
+ }
566
+ function decorateMessage(id, message, opts) {
567
+ if (typeof message === "string") {
568
+ const time = opts.time ? leftPad(formatTime(opts.total)) : "";
569
+ message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
570
+ message = addColor(message, opts.color, opts.background);
571
+ }
572
+ return message;
573
+ }
574
+ function logImageInNode(_ref2) {
575
+ let {
576
+ image,
577
+ message = "",
578
+ scale = 1
579
+ } = _ref2;
580
+ console.warn("removed");
581
+ return noop;
582
+ }
583
+ function logImageInBrowser(_ref3) {
584
+ let {
585
+ image,
586
+ message = "",
587
+ scale = 1
588
+ } = _ref3;
589
+ if (typeof image === "string") {
590
+ const img = new Image();
591
+ img.onload = () => {
592
+ const args = formatImage(img, message, scale);
593
+ console.log(...args);
594
+ };
595
+ img.src = image;
596
+ return noop;
597
+ }
598
+ const element = image.nodeName || "";
599
+ if (element.toLowerCase() === "img") {
600
+ console.log(...formatImage(image, message, scale));
601
+ return noop;
602
+ }
603
+ if (element.toLowerCase() === "canvas") {
604
+ const img = new Image();
605
+ img.onload = () => console.log(...formatImage(img, message, scale));
606
+ img.src = image.toDataURL();
607
+ return noop;
608
+ }
609
+ return noop;
610
+ }
611
+ function getTableHeader(table) {
612
+ for (const key in table) {
613
+ for (const title in table[key]) {
614
+ return title || "untitled";
615
+ }
616
+ }
617
+ return "empty";
618
+ }
619
+
620
+ // ../../node_modules/@probe.gl/log/dist/index.js
621
+ var dist_default = new Log({
622
+ id: "@probe.gl/log"
623
+ });
624
+
625
+ // src/utils/log.ts
626
+ var log = new Log({
627
+ id: "luma.gl"
628
+ });
629
+
630
+ // ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
631
+ function getHiResTimestamp2() {
632
+ let timestamp;
633
+ if (typeof window !== "undefined" && window.performance) {
634
+ timestamp = window.performance.now();
635
+ } else if (typeof process !== "undefined" && process.hrtime) {
636
+ const timeParts = process.hrtime();
637
+ timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
638
+ } else {
639
+ timestamp = Date.now();
640
+ }
641
+ return timestamp;
642
+ }
643
+
644
+ // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
645
+ var Stat = class {
646
+ constructor(name2, type) {
647
+ this.name = void 0;
648
+ this.type = void 0;
649
+ this.sampleSize = 1;
650
+ this.time = 0;
651
+ this.count = 0;
652
+ this.samples = 0;
653
+ this.lastTiming = 0;
654
+ this.lastSampleTime = 0;
655
+ this.lastSampleCount = 0;
656
+ this._count = 0;
657
+ this._time = 0;
658
+ this._samples = 0;
659
+ this._startTime = 0;
660
+ this._timerPending = false;
661
+ this.name = name2;
662
+ this.type = type;
663
+ this.reset();
664
+ }
665
+ reset() {
666
+ this.time = 0;
667
+ this.count = 0;
668
+ this.samples = 0;
669
+ this.lastTiming = 0;
670
+ this.lastSampleTime = 0;
671
+ this.lastSampleCount = 0;
672
+ this._count = 0;
673
+ this._time = 0;
674
+ this._samples = 0;
675
+ this._startTime = 0;
676
+ this._timerPending = false;
677
+ return this;
678
+ }
679
+ setSampleSize(samples) {
680
+ this.sampleSize = samples;
681
+ return this;
682
+ }
683
+ incrementCount() {
684
+ this.addCount(1);
685
+ return this;
686
+ }
687
+ decrementCount() {
688
+ this.subtractCount(1);
689
+ return this;
690
+ }
691
+ addCount(value) {
692
+ this._count += value;
693
+ this._samples++;
694
+ this._checkSampling();
695
+ return this;
696
+ }
697
+ subtractCount(value) {
698
+ this._count -= value;
699
+ this._samples++;
700
+ this._checkSampling();
701
+ return this;
702
+ }
703
+ addTime(time) {
704
+ this._time += time;
705
+ this.lastTiming = time;
706
+ this._samples++;
707
+ this._checkSampling();
708
+ return this;
709
+ }
710
+ timeStart() {
711
+ this._startTime = getHiResTimestamp2();
712
+ this._timerPending = true;
713
+ return this;
714
+ }
715
+ timeEnd() {
716
+ if (!this._timerPending) {
717
+ return this;
718
+ }
719
+ this.addTime(getHiResTimestamp2() - this._startTime);
720
+ this._timerPending = false;
721
+ this._checkSampling();
722
+ return this;
723
+ }
724
+ getSampleAverageCount() {
725
+ return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
726
+ }
727
+ getSampleAverageTime() {
728
+ return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
729
+ }
730
+ getSampleHz() {
731
+ return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
732
+ }
733
+ getAverageCount() {
734
+ return this.samples > 0 ? this.count / this.samples : 0;
735
+ }
736
+ getAverageTime() {
737
+ return this.samples > 0 ? this.time / this.samples : 0;
738
+ }
739
+ getHz() {
740
+ return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
741
+ }
742
+ _checkSampling() {
743
+ if (this._samples === this.sampleSize) {
744
+ this.lastSampleTime = this._time;
745
+ this.lastSampleCount = this._count;
746
+ this.count += this._count;
747
+ this.time += this._time;
748
+ this.samples += this._samples;
749
+ this._time = 0;
750
+ this._count = 0;
751
+ this._samples = 0;
752
+ }
753
+ }
754
+ };
755
+
756
+ // ../../node_modules/@probe.gl/stats/dist/lib/stats.js
757
+ var Stats = class {
758
+ constructor(options) {
759
+ this.id = void 0;
760
+ this.stats = {};
761
+ this.id = options.id;
762
+ this.stats = {};
763
+ this._initializeStats(options.stats);
764
+ Object.seal(this);
765
+ }
766
+ get(name2) {
767
+ let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
768
+ return this._getOrCreate({
769
+ name: name2,
770
+ type
771
+ });
772
+ }
773
+ get size() {
774
+ return Object.keys(this.stats).length;
775
+ }
776
+ reset() {
777
+ for (const stat of Object.values(this.stats)) {
778
+ stat.reset();
779
+ }
780
+ return this;
781
+ }
782
+ forEach(fn) {
783
+ for (const stat of Object.values(this.stats)) {
784
+ fn(stat);
785
+ }
786
+ }
787
+ getTable() {
788
+ const table = {};
789
+ this.forEach((stat) => {
790
+ table[stat.name] = {
791
+ time: stat.time || 0,
792
+ count: stat.count || 0,
793
+ average: stat.getAverageTime() || 0,
794
+ hz: stat.getHz() || 0
795
+ };
796
+ });
797
+ return table;
798
+ }
799
+ _initializeStats() {
800
+ let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
801
+ stats.forEach((stat) => this._getOrCreate(stat));
802
+ }
803
+ _getOrCreate(stat) {
804
+ const {
805
+ name: name2,
806
+ type
807
+ } = stat;
808
+ let result = this.stats[name2];
809
+ if (!result) {
810
+ if (stat instanceof Stat) {
811
+ result = stat;
812
+ } else {
813
+ result = new Stat(name2, type);
814
+ }
815
+ this.stats[name2] = result;
816
+ }
817
+ return result;
818
+ }
819
+ };
820
+
821
+ // src/utils/stats-manager.ts
822
+ var StatsManager = class {
823
+ stats = /* @__PURE__ */ new Map();
824
+ getStats(name2) {
825
+ return this.get(name2);
826
+ }
827
+ get(name2) {
828
+ if (!this.stats.has(name2)) {
829
+ this.stats.set(name2, new Stats({
830
+ id: name2
831
+ }));
832
+ }
833
+ return this.stats.get(name2);
834
+ }
835
+ };
836
+ var lumaStats = new StatsManager();
837
+
838
+ // src/init.ts
839
+ function initializeLuma() {
840
+ const VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "running from source";
841
+ const STARTUP_MESSAGE = "set luma.log.level=1 (or higher) to trace rendering";
842
+ if (globalThis.luma && globalThis.luma.VERSION !== VERSION3) {
843
+ throw new Error(`luma.gl - multiple VERSIONs detected: ${globalThis.luma.VERSION} vs ${VERSION3}`);
844
+ }
845
+ if (!globalThis.luma) {
846
+ if (isBrowser()) {
847
+ log.log(1, `${VERSION3} - ${STARTUP_MESSAGE}`)();
848
+ }
849
+ globalThis.luma = globalThis.luma || {
850
+ VERSION: VERSION3,
851
+ version: VERSION3,
852
+ log,
853
+ stats: lumaStats
854
+ };
855
+ }
856
+ return VERSION3;
857
+ }
858
+ var VERSION2 = initializeLuma();
859
+
860
+ // src/utils/is-array.ts
861
+ function isTypedArray(value) {
862
+ return ArrayBuffer.isView(value) && !(value instanceof DataView) ? value : null;
863
+ }
864
+ function isNumberArray(value) {
865
+ if (Array.isArray(value)) {
866
+ return value.length === 0 || typeof value[0] === "number" ? value : null;
867
+ }
868
+ return isTypedArray(value);
869
+ }
870
+
871
+ // src/utils/utils.ts
872
+ var uidCounters = {};
873
+ function uid(id = "id") {
874
+ uidCounters[id] = uidCounters[id] || 1;
875
+ const count = uidCounters[id]++;
876
+ return `${id}-${count}`;
877
+ }
878
+ function isPowerOfTwo(n) {
879
+ return n > 0 && (n & n - 1) === 0;
880
+ }
881
+ function isObjectEmpty(obj) {
882
+ let isEmpty = true;
883
+ for (const key in obj) {
884
+ isEmpty = false;
885
+ break;
886
+ }
887
+ return isEmpty;
888
+ }
889
+
890
+ // src/adapter/resources/resource.ts
891
+ var Resource = class {
892
+ userData = {};
893
+ destroyed = false;
894
+ allocatedBytes = 0;
895
+ _attachedResources = /* @__PURE__ */ new Set();
896
+ constructor(device, props, defaultProps) {
897
+ if (!device) {
898
+ throw new Error("no device");
899
+ }
900
+ this._device = device;
901
+ this.props = selectivelyMerge(props, defaultProps);
902
+ const id = this.props.id !== "undefined" ? this.props.id : uid(this[Symbol.toStringTag]);
903
+ this.props.id = id;
904
+ this.id = id;
905
+ this.userData = this.props.userData || {};
906
+ this.addStats();
907
+ }
908
+ destroy() {
909
+ this.destroyResource();
910
+ }
911
+ delete() {
912
+ this.destroy();
913
+ return this;
914
+ }
915
+ toString() {
916
+ return `${this[Symbol.toStringTag] || this.constructor.name}(${this.id})`;
917
+ }
918
+ getProps() {
919
+ return this.props;
920
+ }
921
+ attachResource(resource) {
922
+ this._attachedResources.add(resource);
923
+ }
924
+ detachResource(resource) {
925
+ this._attachedResources.delete(resource);
926
+ }
927
+ destroyAttachedResource(resource) {
928
+ if (this._attachedResources.delete(resource)) {
929
+ resource.destroy();
930
+ }
931
+ }
932
+ destroyAttachedResources() {
933
+ for (const resource of Object.values(this._attachedResources)) {
934
+ resource.destroy();
935
+ }
936
+ this._attachedResources = /* @__PURE__ */ new Set();
937
+ }
938
+ destroyResource() {
939
+ this.destroyAttachedResources();
940
+ this.removeStats();
941
+ this.destroyed = true;
942
+ }
943
+ removeStats() {
944
+ const stats = this._device.statsManager.getStats("Resource Counts");
945
+ const name2 = this[Symbol.toStringTag];
946
+ stats.get(`${name2}s Active`).decrementCount();
947
+ }
948
+ trackAllocatedMemory(bytes, name2 = this[Symbol.toStringTag]) {
949
+ const stats = this._device.statsManager.getStats("Resource Counts");
950
+ stats.get("GPU Memory").addCount(bytes);
951
+ stats.get(`${name2} Memory`).addCount(bytes);
952
+ this.allocatedBytes = bytes;
953
+ }
954
+ trackDeallocatedMemory(name2 = this[Symbol.toStringTag]) {
955
+ const stats = this._device.statsManager.getStats("Resource Counts");
956
+ stats.get("GPU Memory").subtractCount(this.allocatedBytes);
957
+ stats.get(`${name2} Memory`).subtractCount(this.allocatedBytes);
958
+ this.allocatedBytes = 0;
959
+ }
960
+ addStats() {
961
+ const stats = this._device.statsManager.getStats("Resource Counts");
962
+ const name2 = this[Symbol.toStringTag];
963
+ stats.get("Resources Created").incrementCount();
964
+ stats.get(`${name2}s Created`).incrementCount();
965
+ stats.get(`${name2}s Active`).incrementCount();
966
+ }
967
+ };
968
+ __publicField(Resource, "defaultProps", {
969
+ id: "undefined",
970
+ handle: void 0,
971
+ userData: void 0
972
+ });
973
+ function selectivelyMerge(props, defaultProps) {
974
+ const mergedProps = {
975
+ ...defaultProps
976
+ };
977
+ for (const key in props) {
978
+ if (props[key] !== void 0) {
979
+ mergedProps[key] = props[key];
980
+ }
981
+ }
982
+ return mergedProps;
983
+ }
984
+
985
+ // src/adapter/resources/buffer.ts
986
+ var _Buffer = class extends Resource {
987
+ get [Symbol.toStringTag]() {
988
+ return "Buffer";
989
+ }
990
+ constructor(device, props) {
991
+ const deducedProps = {
992
+ ...props
993
+ };
994
+ if ((props.usage || 0) & _Buffer.INDEX && !props.indexType) {
995
+ if (props.data instanceof Uint32Array) {
996
+ deducedProps.indexType = "uint32";
997
+ } else if (props.data instanceof Uint16Array) {
998
+ deducedProps.indexType = "uint16";
999
+ }
1000
+ }
1001
+ super(device, deducedProps, _Buffer.defaultProps);
1002
+ this.usage = props.usage || 0;
1003
+ this.indexType = deducedProps.indexType;
1004
+ }
1005
+ readSyncWebGL2(byteOffset, byteLength) {
1006
+ throw new Error("not implemented");
1007
+ }
1008
+ debugData = new ArrayBuffer(0);
1009
+ _setDebugData(data, byteOffset, byteLength) {
1010
+ const buffer = ArrayBuffer.isView(data) ? data.buffer : data;
1011
+ const debugDataLength = Math.min(data ? data.byteLength : byteLength, _Buffer.DEBUG_DATA_MAX_LENGTH);
1012
+ if (data === null) {
1013
+ this.debugData = new ArrayBuffer(debugDataLength);
1014
+ } else if (byteOffset === 0 && byteLength === data.byteLength) {
1015
+ this.debugData = buffer.slice(0, debugDataLength);
1016
+ } else {
1017
+ this.debugData = buffer.slice(byteOffset, byteOffset + debugDataLength);
1018
+ }
1019
+ }
1020
+ };
1021
+ var Buffer2 = _Buffer;
1022
+ __publicField(Buffer2, "defaultProps", {
1023
+ ...Resource.defaultProps,
1024
+ usage: 0,
1025
+ byteLength: 0,
1026
+ byteOffset: 0,
1027
+ data: null,
1028
+ indexType: "uint16",
1029
+ mappedAtCreation: false
1030
+ });
1031
+ __publicField(Buffer2, "MAP_READ", 1);
1032
+ __publicField(Buffer2, "MAP_WRITE", 2);
1033
+ __publicField(Buffer2, "COPY_SRC", 4);
1034
+ __publicField(Buffer2, "COPY_DST", 8);
1035
+ __publicField(Buffer2, "INDEX", 16);
1036
+ __publicField(Buffer2, "VERTEX", 32);
1037
+ __publicField(Buffer2, "UNIFORM", 64);
1038
+ __publicField(Buffer2, "STORAGE", 128);
1039
+ __publicField(Buffer2, "INDIRECT", 256);
1040
+ __publicField(Buffer2, "QUERY_RESOLVE", 512);
1041
+ __publicField(Buffer2, "DEBUG_DATA_MAX_LENGTH", 32);
1042
+
1043
+ // src/adapter/device.ts
1044
+ var _Device = class {
1045
+ get [Symbol.toStringTag]() {
1046
+ return "Device";
1047
+ }
1048
+ constructor(props) {
1049
+ this.props = {
1050
+ ..._Device.defaultProps,
1051
+ ...props
1052
+ };
1053
+ this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
1054
+ }
1055
+ statsManager = lumaStats;
1056
+ userData = {};
1057
+ _lumaData = {};
1058
+ loseDevice() {
1059
+ return false;
1060
+ }
1061
+ getCanvasContext() {
1062
+ if (!this.canvasContext) {
1063
+ throw new Error("Device has no CanvasContext");
1064
+ }
1065
+ return this.canvasContext;
1066
+ }
1067
+ createTexture(props) {
1068
+ if (props instanceof Promise || typeof props === "string") {
1069
+ props = {
1070
+ data: props
1071
+ };
1072
+ }
1073
+ return this._createTexture(props);
1074
+ }
1075
+ createCommandEncoder(props = {}) {
1076
+ throw new Error("not implemented");
1077
+ }
1078
+ readPixelsToArrayWebGL(source, options) {
1079
+ throw new Error("not implemented");
1080
+ }
1081
+ readPixelsToBufferWebGL2(source, options) {
1082
+ throw new Error("not implemented");
1083
+ }
1084
+ setParametersWebGL(parameters) {
1085
+ throw new Error("not implemented");
1086
+ }
1087
+ withParametersWebGL(parameters, func) {
1088
+ throw new Error("not implemented");
1089
+ }
1090
+ clearWebGL(options) {
1091
+ throw new Error("not implemented");
1092
+ }
1093
+ _getBufferProps(props) {
1094
+ if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
1095
+ props = {
1096
+ data: props
1097
+ };
1098
+ }
1099
+ const newProps = {
1100
+ ...props
1101
+ };
1102
+ if ((props.usage || 0) & Buffer2.INDEX && !props.indexType) {
1103
+ if (props.data instanceof Uint32Array) {
1104
+ newProps.indexType = "uint32";
1105
+ } else if (props.data instanceof Uint16Array) {
1106
+ newProps.indexType = "uint16";
1107
+ } else {
1108
+ log.warn("indices buffer content must be of integer type")();
1109
+ }
1110
+ }
1111
+ return newProps;
1112
+ }
1113
+ };
1114
+ var Device = _Device;
1115
+ __publicField(Device, "defaultProps", {
1116
+ id: null,
1117
+ type: "best-available",
1118
+ canvas: null,
1119
+ container: null,
1120
+ webgl2: true,
1121
+ webgl1: true,
1122
+ manageState: true,
1123
+ width: 800,
1124
+ height: 600,
1125
+ debug: Boolean(log.get("debug")),
1126
+ break: [],
1127
+ gl: null
1128
+ });
1129
+ __publicField(Device, "VERSION", VERSION2);
1130
+
1131
+ // src/utils/assert.ts
1132
+ function assert2(condition, message) {
1133
+ if (!condition) {
1134
+ throw new Error(message || "luma.gl: assertion failed.");
1135
+ }
1136
+ }
1137
+
1138
+ // src/lib/luma.ts
1139
+ var deviceList = /* @__PURE__ */ new Map();
1140
+ var luma = class {
1141
+ static registerDevices(deviceClasses) {
1142
+ for (const deviceClass of deviceClasses) {
1143
+ assert2(deviceClass.type && deviceClass.isSupported && deviceClass.create);
1144
+ deviceList.set(deviceClass.type, deviceClass);
1145
+ }
1146
+ }
1147
+ static getAvailableDevices() {
1148
+ return Array.from(deviceList).map((Device2) => Device2.type);
1149
+ }
1150
+ static getSupportedDevices() {
1151
+ return Array.from(deviceList).filter((Device2) => Device2.isSupported()).map((Device2) => Device2.type);
1152
+ }
1153
+ static setDefaultDeviceProps(props) {
1154
+ Object.assign(Device.defaultProps, props);
1155
+ }
1156
+ static async createDevice(props = {}) {
1157
+ props = {
1158
+ ...Device.defaultProps,
1159
+ ...props
1160
+ };
1161
+ if (props.gl) {
1162
+ props.type = "webgl";
1163
+ }
1164
+ let DeviceClass;
1165
+ switch (props.type) {
1166
+ case "webgpu":
1167
+ DeviceClass = deviceList.get("webgpu");
1168
+ if (DeviceClass) {
1169
+ return await DeviceClass.create(props);
1170
+ }
1171
+ break;
1172
+ case "webgl":
1173
+ case "webgl1":
1174
+ case "webgl2":
1175
+ DeviceClass = deviceList.get("webgl");
1176
+ if (DeviceClass) {
1177
+ return await DeviceClass.create(props);
1178
+ }
1179
+ break;
1180
+ case "best-available":
1181
+ DeviceClass = deviceList.get("webgpu");
1182
+ if (DeviceClass && DeviceClass.isSupported()) {
1183
+ return await DeviceClass.create(props);
1184
+ }
1185
+ DeviceClass = deviceList.get("webgl");
1186
+ if (DeviceClass && DeviceClass.isSupported()) {
1187
+ return await DeviceClass.create(props);
1188
+ }
1189
+ break;
1190
+ }
1191
+ throw new Error("No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.");
1192
+ }
1193
+ };
1194
+ __publicField(luma, "stats", lumaStats);
1195
+ __publicField(luma, "log", log);
1196
+
1197
+ // src/adapter/canvas-context.ts
1198
+ var isPage = isBrowser() && typeof document !== "undefined";
1199
+ var isPageLoaded = () => isPage && document.readyState === "complete";
1200
+ var DEFAULT_CANVAS_CONTEXT_PROPS = {
1201
+ canvas: null,
1202
+ width: 800,
1203
+ height: 600,
1204
+ useDevicePixels: true,
1205
+ autoResize: true,
1206
+ container: null,
1207
+ visible: true,
1208
+ colorSpace: "srgb",
1209
+ alphaMode: "opaque"
1210
+ };
1211
+ var CanvasContext = class {
1212
+ width = 1;
1213
+ height = 1;
1214
+ _canvasSizeInfo = {
1215
+ clientWidth: 0,
1216
+ clientHeight: 0,
1217
+ devicePixelRatio: 1
1218
+ };
1219
+ static get isPageLoaded() {
1220
+ return isPageLoaded();
1221
+ }
1222
+ constructor(props) {
1223
+ this.props = {
1224
+ ...DEFAULT_CANVAS_CONTEXT_PROPS,
1225
+ ...props
1226
+ };
1227
+ props = this.props;
1228
+ if (!isBrowser()) {
1229
+ this.id = "node-canvas-context";
1230
+ this.type = "node";
1231
+ this.width = this.props.width;
1232
+ this.height = this.props.height;
1233
+ this.canvas = null;
1234
+ return;
1235
+ }
1236
+ if (!props.canvas) {
1237
+ const canvas = createCanvas(props);
1238
+ const container = getContainer(props?.container || null);
1239
+ container.insertBefore(canvas, container.firstChild);
1240
+ this.canvas = canvas;
1241
+ if (!props?.visible) {
1242
+ this.canvas.style.visibility = "hidden";
1243
+ }
1244
+ } else if (typeof props.canvas === "string") {
1245
+ this.canvas = getCanvasFromDOM(props.canvas);
1246
+ } else {
1247
+ this.canvas = props.canvas;
1248
+ }
1249
+ if (this.canvas instanceof HTMLCanvasElement) {
1250
+ this.id = this.canvas.id;
1251
+ this.type = "html-canvas";
1252
+ this.htmlCanvas = this.canvas;
1253
+ } else {
1254
+ this.id = "offscreen-canvas";
1255
+ this.type = "offscreen-canvas";
1256
+ this.offscreenCanvas = this.canvas;
1257
+ }
1258
+ if (this.canvas instanceof HTMLCanvasElement && props.autoResize) {
1259
+ this.resizeObserver = new ResizeObserver((entries) => {
1260
+ for (const entry of entries) {
1261
+ if (entry.target === this.canvas) {
1262
+ this.update();
1263
+ }
1264
+ }
1265
+ });
1266
+ this.resizeObserver.observe(this.canvas);
1267
+ }
1268
+ }
1269
+ getDevicePixelRatio(useDevicePixels) {
1270
+ if (typeof OffscreenCanvas !== "undefined" && this.canvas instanceof OffscreenCanvas) {
1271
+ return 1;
1272
+ }
1273
+ useDevicePixels = useDevicePixels === void 0 ? this.props.useDevicePixels : useDevicePixels;
1274
+ if (!useDevicePixels || useDevicePixels <= 0) {
1275
+ return 1;
1276
+ }
1277
+ if (useDevicePixels === true) {
1278
+ const dpr = typeof window !== "undefined" && window.devicePixelRatio;
1279
+ return dpr || 1;
1280
+ }
1281
+ return useDevicePixels;
1282
+ }
1283
+ getPixelSize() {
1284
+ switch (this.type) {
1285
+ case "node":
1286
+ return [this.width, this.height];
1287
+ case "offscreen-canvas":
1288
+ return [this.canvas.width, this.canvas.height];
1289
+ case "html-canvas":
1290
+ const dpr = this.getDevicePixelRatio();
1291
+ const canvas = this.canvas;
1292
+ return canvas.parentElement ? [canvas.clientWidth * dpr, canvas.clientHeight * dpr] : [this.canvas.width, this.canvas.height];
1293
+ default:
1294
+ throw new Error(this.type);
1295
+ }
1296
+ }
1297
+ getAspect() {
1298
+ const [width, height] = this.getPixelSize();
1299
+ return width / height;
1300
+ }
1301
+ cssToDeviceRatio() {
1302
+ try {
1303
+ const [drawingBufferWidth] = this.getDrawingBufferSize();
1304
+ const {
1305
+ clientWidth
1306
+ } = this._canvasSizeInfo;
1307
+ return clientWidth ? drawingBufferWidth / clientWidth : 1;
1308
+ } catch {
1309
+ return 1;
1310
+ }
1311
+ }
1312
+ cssToDevicePixels(cssPixel, yInvert = true) {
1313
+ const ratio = this.cssToDeviceRatio();
1314
+ const [width, height] = this.getDrawingBufferSize();
1315
+ return scalePixels(cssPixel, ratio, width, height, yInvert);
1316
+ }
1317
+ setDevicePixelRatio(devicePixelRatio, options = {}) {
1318
+ if (!this.htmlCanvas) {
1319
+ return;
1320
+ }
1321
+ let clientWidth = "width" in options ? options.width : this.htmlCanvas.clientWidth;
1322
+ let clientHeight = "height" in options ? options.height : this.htmlCanvas.clientHeight;
1323
+ if (!clientWidth || !clientHeight) {
1324
+ log.log(1, "Canvas clientWidth/clientHeight is 0")();
1325
+ devicePixelRatio = 1;
1326
+ clientWidth = this.htmlCanvas.width || 1;
1327
+ clientHeight = this.htmlCanvas.height || 1;
1328
+ }
1329
+ const cachedSize = this._canvasSizeInfo;
1330
+ if (cachedSize.clientWidth !== clientWidth || cachedSize.clientHeight !== clientHeight || cachedSize.devicePixelRatio !== devicePixelRatio) {
1331
+ let clampedPixelRatio = devicePixelRatio;
1332
+ const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);
1333
+ const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);
1334
+ this.htmlCanvas.width = canvasWidth;
1335
+ this.htmlCanvas.height = canvasHeight;
1336
+ const [drawingBufferWidth, drawingBufferHeight] = this.getDrawingBufferSize();
1337
+ if (drawingBufferWidth !== canvasWidth || drawingBufferHeight !== canvasHeight) {
1338
+ clampedPixelRatio = Math.min(drawingBufferWidth / clientWidth, drawingBufferHeight / clientHeight);
1339
+ this.htmlCanvas.width = Math.floor(clientWidth * clampedPixelRatio);
1340
+ this.htmlCanvas.height = Math.floor(clientHeight * clampedPixelRatio);
1341
+ log.warn("Device pixel ratio clamped")();
1342
+ }
1343
+ this._canvasSizeInfo.clientWidth = clientWidth;
1344
+ this._canvasSizeInfo.clientHeight = clientHeight;
1345
+ this._canvasSizeInfo.devicePixelRatio = devicePixelRatio;
1346
+ }
1347
+ }
1348
+ getDrawingBufferSize() {
1349
+ const gl = this.device.gl;
1350
+ if (!gl) {
1351
+ throw new Error("canvas size");
1352
+ }
1353
+ return [gl.drawingBufferWidth, gl.drawingBufferHeight];
1354
+ }
1355
+ _setAutoCreatedCanvasId(id) {
1356
+ if (this.htmlCanvas?.id === "lumagl-auto-created-canvas") {
1357
+ this.htmlCanvas.id = id;
1358
+ }
1359
+ }
1360
+ };
1361
+ __publicField(CanvasContext, "pageLoaded", getPageLoadPromise());
1362
+ function getPageLoadPromise() {
1363
+ if (isPageLoaded() || typeof window === "undefined") {
1364
+ return Promise.resolve();
1365
+ }
1366
+ return new Promise((resolve) => {
1367
+ window.addEventListener("load", () => resolve());
1368
+ });
1369
+ }
1370
+ function getContainer(container) {
1371
+ if (typeof container === "string") {
1372
+ const element = document.getElementById(container);
1373
+ if (!element && !isPageLoaded()) {
1374
+ throw new Error(`Accessing '${container}' before page was loaded`);
1375
+ }
1376
+ if (!element) {
1377
+ throw new Error(`${container} is not an HTML element`);
1378
+ }
1379
+ return element;
1380
+ } else if (container) {
1381
+ return container;
1382
+ }
1383
+ return document.body;
1384
+ }
1385
+ function getCanvasFromDOM(canvasId) {
1386
+ const canvas = document.getElementById(canvasId);
1387
+ if (!canvas && !isPageLoaded()) {
1388
+ throw new Error(`Accessing '${canvasId}' before page was loaded`);
1389
+ }
1390
+ if (!(canvas instanceof HTMLCanvasElement)) {
1391
+ throw new Error("Object is not a canvas element");
1392
+ }
1393
+ return canvas;
1394
+ }
1395
+ function createCanvas(props) {
1396
+ const {
1397
+ width,
1398
+ height
1399
+ } = props;
1400
+ const targetCanvas = document.createElement("canvas");
1401
+ targetCanvas.id = "lumagl-auto-created-canvas";
1402
+ targetCanvas.width = width || 1;
1403
+ targetCanvas.height = height || 1;
1404
+ targetCanvas.style.width = Number.isFinite(width) ? `${width}px` : "100%";
1405
+ targetCanvas.style.height = Number.isFinite(height) ? `${height}px` : "100%";
1406
+ return targetCanvas;
1407
+ }
1408
+ function scalePixels(pixel, ratio, width, height, yInvert) {
1409
+ const point = pixel;
1410
+ const x = scaleX(point[0], ratio, width);
1411
+ let y = scaleY(point[1], ratio, height, yInvert);
1412
+ let t = scaleX(point[0] + 1, ratio, width);
1413
+ const xHigh = t === width - 1 ? t : t - 1;
1414
+ t = scaleY(point[1] + 1, ratio, height, yInvert);
1415
+ let yHigh;
1416
+ if (yInvert) {
1417
+ t = t === 0 ? t : t + 1;
1418
+ yHigh = y;
1419
+ y = t;
1420
+ } else {
1421
+ yHigh = t === height - 1 ? t : t - 1;
1422
+ }
1423
+ return {
1424
+ x,
1425
+ y,
1426
+ width: Math.max(xHigh - x + 1, 1),
1427
+ height: Math.max(yHigh - y + 1, 1)
1428
+ };
1429
+ }
1430
+ function scaleX(x, ratio, width) {
1431
+ const r = Math.min(Math.round(x * ratio), width - 1);
1432
+ return r;
1433
+ }
1434
+ function scaleY(y, ratio, height, yInvert) {
1435
+ return yInvert ? Math.max(0, height - 1 - Math.round(y * ratio)) : Math.min(Math.round(y * ratio), height - 1);
1436
+ }
1437
+
1438
+ // src/adapter/resources/texture.ts
1439
+ var _Texture = class extends Resource {
1440
+ get [Symbol.toStringTag]() {
1441
+ return "Texture";
1442
+ }
1443
+ constructor(device, props, defaultProps = _Texture.defaultProps) {
1444
+ super(device, props, defaultProps);
1445
+ this.dimension = this.props.dimension;
1446
+ this.format = this.props.format;
1447
+ this.width = this.props.width;
1448
+ this.height = this.props.height;
1449
+ this.depth = this.props.depth;
1450
+ }
1451
+ };
1452
+ var Texture = _Texture;
1453
+ __publicField(Texture, "defaultProps", {
1454
+ ...Resource.defaultProps,
1455
+ data: null,
1456
+ dimension: "2d",
1457
+ format: "rgba8unorm",
1458
+ width: void 0,
1459
+ height: void 0,
1460
+ depth: 1,
1461
+ mipmaps: true,
1462
+ sampler: {},
1463
+ compressed: false,
1464
+ usage: 0,
1465
+ mipLevels: void 0,
1466
+ samples: void 0,
1467
+ type: void 0
1468
+ });
1469
+ __publicField(Texture, "COPY_SRC", 1);
1470
+ __publicField(Texture, "COPY_DST", 2);
1471
+ __publicField(Texture, "TEXTURE_BINDING", 4);
1472
+ __publicField(Texture, "STORAGE_BINDING", 8);
1473
+ __publicField(Texture, "RENDER_ATTACHMENT", 16);
1474
+
1475
+ // src/adapter/resources/external-texture.ts
1476
+ var _ExternalTexture = class extends Resource {
1477
+ get [Symbol.toStringTag]() {
1478
+ return "ExternalTexture";
1479
+ }
1480
+ constructor(device, props) {
1481
+ super(device, props, _ExternalTexture.defaultProps);
1482
+ }
1483
+ };
1484
+ var ExternalTexture = _ExternalTexture;
1485
+ __publicField(ExternalTexture, "defaultProps", {
1486
+ ...Resource.defaultProps,
1487
+ source: null,
1488
+ colorSpace: "srgb"
1489
+ });
1490
+
1491
+ // src/lib/compiler-log/format-compiler-log.ts
1492
+ function formatCompilerLog(shaderLog, source, options) {
1493
+ let formattedLog = "";
1494
+ const lines = source.split(/\r?\n/);
1495
+ const log2 = shaderLog.slice().sort((a, b) => a.lineNum - b.lineNum);
1496
+ switch (options?.showSourceCode || "no") {
1497
+ case "all":
1498
+ let currentMessage = 0;
1499
+ for (let lineNum = 1; lineNum <= lines.length; lineNum++) {
1500
+ formattedLog += getNumberedLine(lines[lineNum - 1], lineNum, options);
1501
+ while (log2.length > currentMessage && log2[currentMessage].lineNum === lineNum) {
1502
+ const message = log2[currentMessage++];
1503
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
1504
+ ...options,
1505
+ inlineSource: false
1506
+ });
1507
+ }
1508
+ }
1509
+ return formattedLog;
1510
+ case "issues":
1511
+ case "no":
1512
+ for (const message of shaderLog) {
1513
+ formattedLog += formatCompilerMessage(message, lines, message.lineNum, {
1514
+ inlineSource: options?.showSourceCode !== "no"
1515
+ });
1516
+ }
1517
+ return formattedLog;
1518
+ }
1519
+ }
1520
+ function formatCompilerMessage(message, lines, lineNum, options) {
1521
+ if (options?.inlineSource) {
1522
+ const numberedLines = getNumberedLines(lines, lineNum);
1523
+ const positionIndicator = message.linePos > 0 ? `${" ".repeat(message.linePos + 5)}^^^
1524
+ ` : "";
1525
+ return `
1526
+ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.message}
1527
+
1528
+ `;
1529
+ }
1530
+ return options?.html ? `<div class='luma-compiler-log-error' style="color:red;"><b> ${message.type.toUpperCase()}: ${message.message}</b></div>` : `${message.type.toUpperCase()}: ${message.message}`;
1531
+ }
1532
+ function getNumberedLines(lines, lineNum, options) {
1533
+ let numberedLines = "";
1534
+ for (let lineIndex = lineNum - 2; lineIndex <= lineNum; lineIndex++) {
1535
+ const sourceLine = lines[lineIndex - 1];
1536
+ if (sourceLine !== void 0) {
1537
+ numberedLines += getNumberedLine(sourceLine, lineNum, options);
1538
+ }
1539
+ }
1540
+ return numberedLines;
1541
+ }
1542
+ function getNumberedLine(line, lineNum, options) {
1543
+ const escapedLine = options?.html ? escapeHTML(line) : line;
1544
+ return `${padLeft(String(lineNum), 4)}: ${escapedLine}${options?.html ? "<br/>" : "\n"}`;
1545
+ }
1546
+ function padLeft(string, paddedLength) {
1547
+ let result = "";
1548
+ for (let i = string.length; i < paddedLength; ++i) {
1549
+ result += " ";
1550
+ }
1551
+ return result + string;
1552
+ }
1553
+ function escapeHTML(unsafe) {
1554
+ return unsafe.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#039;");
1555
+ }
1556
+
1557
+ // src/lib/compiler-log/get-shader-info.ts
1558
+ function getShaderInfo(source, defaultName) {
1559
+ return {
1560
+ name: getShaderName(source, defaultName),
1561
+ language: "glsl",
1562
+ version: getShaderVersion(source)
1563
+ };
1564
+ }
1565
+ function getShaderName(shader, defaultName = "unnamed") {
1566
+ const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
1567
+ const match = SHADER_NAME_REGEXP.exec(shader);
1568
+ return match ? match[1] : defaultName;
1569
+ }
1570
+ function getShaderVersion(source) {
1571
+ let version = 100;
1572
+ const words = source.match(/[^\s]+/g);
1573
+ if (words && words.length >= 2 && words[0] === "#version") {
1574
+ const v = parseInt(words[1], 10);
1575
+ if (Number.isFinite(v)) {
1576
+ version = v;
1577
+ }
1578
+ }
1579
+ return version;
1580
+ }
1581
+
1582
+ // src/adapter/resources/shader.ts
1583
+ var _Shader = class extends Resource {
1584
+ get [Symbol.toStringTag]() {
1585
+ return "Shader";
1586
+ }
1587
+ compilationStatus = "pending";
1588
+ constructor(device, props) {
1589
+ super(device, {
1590
+ id: getShaderIdFromProps(props),
1591
+ ...props
1592
+ }, _Shader.defaultProps);
1593
+ this.stage = this.props.stage;
1594
+ this.source = this.props.source;
1595
+ }
1596
+ getCompilationInfoSync() {
1597
+ return null;
1598
+ }
1599
+ async debugShader() {
1600
+ switch (this.props.debug) {
1601
+ case "never":
1602
+ return;
1603
+ case "errors":
1604
+ if (this.compilationStatus === "success") {
1605
+ return;
1606
+ }
1607
+ break;
1608
+ case "warnings":
1609
+ case "always":
1610
+ break;
1611
+ }
1612
+ const messages = await this.getCompilationInfo();
1613
+ if (this.props.debug === "warnings" && messages?.length === 0) {
1614
+ return;
1615
+ }
1616
+ this._displayShaderLog(messages);
1617
+ }
1618
+ _displayShaderLog(messages) {
1619
+ if (typeof document === "undefined" || !document?.createElement) {
1620
+ return;
1621
+ }
1622
+ const shaderName = getShaderInfo(this.source).name;
1623
+ const shaderTitle = `${this.stage} ${shaderName}`;
1624
+ const htmlLog = formatCompilerLog(messages, this.source, {
1625
+ showSourceCode: "all",
1626
+ html: true
1627
+ });
1628
+ const button = document.createElement("Button");
1629
+ button.innerHTML = `
1630
+ <h1>Shader Compilation Error in ${shaderTitle}</h1><br /><br />
1631
+ <code style="user-select:text;"><pre>
1632
+ ${htmlLog}
1633
+ </pre></code>`;
1634
+ button.style.top = "10px";
1635
+ button.style.left = "10px";
1636
+ button.style.position = "absolute";
1637
+ button.style.zIndex = "9999";
1638
+ button.style.width = "100%";
1639
+ button.style.textAlign = "left";
1640
+ document.body.appendChild(button);
1641
+ const errors = document.getElementsByClassName("luma-compiler-log-error");
1642
+ if (errors[0]?.scrollIntoView) {
1643
+ errors[0].scrollIntoView();
1644
+ }
1645
+ button.onclick = () => {
1646
+ const dataURI = `data:text/plain,${encodeURIComponent(this.source)}`;
1647
+ navigator.clipboard.writeText(dataURI);
1648
+ };
1649
+ }
1650
+ };
1651
+ var Shader = _Shader;
1652
+ __publicField(Shader, "defaultProps", {
1653
+ ...Resource.defaultProps,
1654
+ language: "auto",
1655
+ stage: "vertex",
1656
+ source: "",
1657
+ sourceMap: null,
1658
+ entryPoint: "main",
1659
+ debug: "errors"
1660
+ });
1661
+ function getShaderIdFromProps(props) {
1662
+ return getShaderInfo(props.source).name || props.id || uid(`unnamed ${props.stage}-shader`);
1663
+ }
1664
+
1665
+ // src/adapter/resources/sampler.ts
1666
+ var _Sampler = class extends Resource {
1667
+ get [Symbol.toStringTag]() {
1668
+ return "Sampler";
1669
+ }
1670
+ constructor(device, props) {
1671
+ super(device, props, _Sampler.defaultProps);
1672
+ }
1673
+ };
1674
+ var Sampler = _Sampler;
1675
+ __publicField(Sampler, "defaultProps", {
1676
+ ...Resource.defaultProps,
1677
+ type: "color-sampler",
1678
+ addressModeU: "clamp-to-edge",
1679
+ addressModeV: "clamp-to-edge",
1680
+ addressModeW: "clamp-to-edge",
1681
+ magFilter: "nearest",
1682
+ minFilter: "nearest",
1683
+ mipmapFilter: "nearest",
1684
+ lodMinClamp: 0,
1685
+ lodMaxClamp: 32,
1686
+ compare: "less-equal",
1687
+ maxAnisotropy: 1
1688
+ });
1689
+
1690
+ // src/adapter/resources/framebuffer.ts
1691
+ var _Framebuffer = class extends Resource {
1692
+ get [Symbol.toStringTag]() {
1693
+ return "Framebuffer";
1694
+ }
1695
+ colorAttachments = [];
1696
+ depthStencilAttachment = null;
1697
+ constructor(device, props = {}) {
1698
+ super(device, props, _Framebuffer.defaultProps);
1699
+ this.width = this.props.width;
1700
+ this.height = this.props.height;
1701
+ }
1702
+ resize(size) {
1703
+ let updateSize = !size;
1704
+ if (size) {
1705
+ const [width, height] = Array.isArray(size) ? size : [size.width, size.height];
1706
+ updateSize = updateSize || height !== this.height || width !== this.width;
1707
+ this.width = width;
1708
+ this.height = height;
1709
+ }
1710
+ if (updateSize) {
1711
+ log.log(2, `Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)();
1712
+ this.resizeAttachments(this.width, this.height);
1713
+ }
1714
+ }
1715
+ autoCreateAttachmentTextures() {
1716
+ this.colorAttachments = this.props.colorAttachments.map((attachment) => {
1717
+ if (typeof attachment === "string") {
1718
+ const texture = this.createColorTexture(attachment);
1719
+ this.attachResource(texture);
1720
+ return texture;
1721
+ }
1722
+ return attachment;
1723
+ });
1724
+ if (this.props.depthStencilAttachment) {
1725
+ if (typeof this.props.depthStencilAttachment === "string") {
1726
+ const texture = this.createDepthStencilTexture(this.props.depthStencilAttachment);
1727
+ this.attachResource(texture);
1728
+ this.depthStencilAttachment = texture;
1729
+ } else {
1730
+ this.depthStencilAttachment = this.props.depthStencilAttachment;
1731
+ }
1732
+ }
1733
+ }
1734
+ createColorTexture(format) {
1735
+ return this.device.createTexture({
1736
+ id: "color-attachment",
1737
+ usage: Texture.RENDER_ATTACHMENT,
1738
+ format,
1739
+ width: this.width,
1740
+ height: this.height
1741
+ });
1742
+ }
1743
+ createDepthStencilTexture(format) {
1744
+ return this.device.createTexture({
1745
+ id: "depth-stencil-attachment",
1746
+ usage: Texture.RENDER_ATTACHMENT,
1747
+ format,
1748
+ width: this.width,
1749
+ height: this.height
1750
+ });
1751
+ }
1752
+ resizeAttachments(width, height) {
1753
+ for (let i = 0; i < this.colorAttachments.length; ++i) {
1754
+ if (this.colorAttachments[i]) {
1755
+ const resizedTexture = this.device._createTexture({
1756
+ ...this.colorAttachments[i].props,
1757
+ width,
1758
+ height
1759
+ });
1760
+ this.destroyAttachedResource(this.colorAttachments[i]);
1761
+ this.colorAttachments[i] = resizedTexture;
1762
+ this.attachResource(resizedTexture);
1763
+ }
1764
+ }
1765
+ if (this.depthStencilAttachment) {
1766
+ const resizedTexture = this.device._createTexture({
1767
+ ...this.depthStencilAttachment.props,
1768
+ width,
1769
+ height
1770
+ });
1771
+ this.destroyAttachedResource(this.depthStencilAttachment);
1772
+ this.depthStencilAttachment = resizedTexture;
1773
+ this.attachResource(resizedTexture);
1774
+ }
1775
+ }
1776
+ };
1777
+ var Framebuffer = _Framebuffer;
1778
+ __publicField(Framebuffer, "defaultProps", {
1779
+ ...Resource.defaultProps,
1780
+ width: 1,
1781
+ height: 1,
1782
+ colorAttachments: [],
1783
+ depthStencilAttachment: null
1784
+ });
1785
+
1786
+ // src/adapter/resources/render-pipeline.ts
1787
+ var _RenderPipeline = class extends Resource {
1788
+ get [Symbol.toStringTag]() {
1789
+ return "RenderPipeline";
1790
+ }
1791
+ hash = "";
1792
+ constructor(device, props) {
1793
+ super(device, props, _RenderPipeline.defaultProps);
1794
+ this.shaderLayout = this.props.shaderLayout;
1795
+ this.bufferLayout = this.props.bufferLayout || [];
1796
+ }
1797
+ };
1798
+ var RenderPipeline = _RenderPipeline;
1799
+ __publicField(RenderPipeline, "defaultProps", {
1800
+ ...Resource.defaultProps,
1801
+ vs: null,
1802
+ vsEntryPoint: "",
1803
+ vsConstants: {},
1804
+ fs: null,
1805
+ fsEntryPoint: "",
1806
+ fsConstants: {},
1807
+ shaderLayout: null,
1808
+ bufferLayout: [],
1809
+ topology: "triangle-list",
1810
+ parameters: {},
1811
+ vertexCount: 0,
1812
+ instanceCount: 0,
1813
+ bindings: {},
1814
+ uniforms: {}
1815
+ });
1816
+
1817
+ // src/adapter/resources/compute-pipeline.ts
1818
+ var _ComputePipeline = class extends Resource {
1819
+ get [Symbol.toStringTag]() {
1820
+ return "ComputePipeline";
1821
+ }
1822
+ hash = "";
1823
+ constructor(device, props) {
1824
+ super(device, props, _ComputePipeline.defaultProps);
1825
+ }
1826
+ };
1827
+ var ComputePipeline = _ComputePipeline;
1828
+ __publicField(ComputePipeline, "defaultProps", {
1829
+ ...Resource.defaultProps,
1830
+ cs: void 0,
1831
+ csEntryPoint: void 0,
1832
+ csConstants: {},
1833
+ shaderLayout: []
1834
+ });
1835
+
1836
+ // src/adapter/resources/render-pass.ts
1837
+ var _RenderPass = class extends Resource {
1838
+ get [Symbol.toStringTag]() {
1839
+ return "RenderPass";
1840
+ }
1841
+ constructor(device, props) {
1842
+ super(device, props, _RenderPass.defaultProps);
1843
+ }
1844
+ };
1845
+ var RenderPass = _RenderPass;
1846
+ __publicField(RenderPass, "defaultProps", {
1847
+ ...Resource.defaultProps,
1848
+ framebuffer: null,
1849
+ parameters: void 0,
1850
+ clearColor: [0, 0, 0, 0],
1851
+ clearDepth: 1,
1852
+ clearStencil: 0,
1853
+ depthReadOnly: false,
1854
+ stencilReadOnly: false,
1855
+ discard: false
1856
+ });
1857
+
1858
+ // src/adapter/resources/compute-pass.ts
1859
+ var ComputePass = class extends Resource {
1860
+ get [Symbol.toStringTag]() {
1861
+ return "ComputePass";
1862
+ }
1863
+ constructor(device, props) {
1864
+ super(device, props, Resource.defaultProps);
1865
+ }
1866
+ };
1867
+ __publicField(ComputePass, "defaultProps", {
1868
+ ...Resource.defaultProps
1869
+ });
1870
+
1871
+ // src/adapter/resources/command-encoder.ts
1872
+ var _CommandEncoder = class extends Resource {
1873
+ get [Symbol.toStringTag]() {
1874
+ return "CommandEncoder";
1875
+ }
1876
+ constructor(device, props) {
1877
+ super(device, props, _CommandEncoder.defaultProps);
1878
+ }
1879
+ pushDebugGroup(groupLabel) {
1880
+ }
1881
+ popDebugGroup() {
1882
+ }
1883
+ insertDebugMarker(markerLabel) {
1884
+ }
1885
+ };
1886
+ var CommandEncoder = _CommandEncoder;
1887
+ __publicField(CommandEncoder, "defaultProps", {
1888
+ ...Resource.defaultProps,
1889
+ measureExecutionTime: void 0
1890
+ });
1891
+
1892
+ // src/adapter/resources/command-buffer.ts
1893
+ var _CommandBuffer = class extends Resource {
1894
+ get [Symbol.toStringTag]() {
1895
+ return "CommandBuffer";
1896
+ }
1897
+ constructor(device, props) {
1898
+ super(device, props, _CommandBuffer.defaultProps);
1899
+ }
1900
+ };
1901
+ var CommandBuffer = _CommandBuffer;
1902
+ __publicField(CommandBuffer, "defaultProps", {
1903
+ ...Resource.defaultProps
1904
+ });
1905
+
1906
+ // src/adapter/type-utils/decode-attribute-type.ts
1907
+ function decodeShaderAttributeType(attributeType) {
1908
+ const [dataType, components] = TYPE_INFO[attributeType];
1909
+ const integer = dataType === "i32" || dataType === "u32";
1910
+ const signed = dataType !== "u32";
1911
+ const byteLength = TYPE_SIZES[dataType] * components;
1912
+ const defaultVertexFormat = getCompatibleVertexFormat(dataType, components);
1913
+ return {
1914
+ dataType,
1915
+ components,
1916
+ defaultVertexFormat,
1917
+ byteLength,
1918
+ integer,
1919
+ signed
1920
+ };
1921
+ }
1922
+ function getCompatibleVertexFormat(dataType, components) {
1923
+ let vertexType;
1924
+ switch (dataType) {
1925
+ case "f32":
1926
+ vertexType = "float32";
1927
+ break;
1928
+ case "i32":
1929
+ vertexType = "sint32";
1930
+ break;
1931
+ case "u32":
1932
+ vertexType = "uint32";
1933
+ break;
1934
+ case "f16":
1935
+ return components <= 2 ? "float16x2" : "float16x4";
1936
+ }
1937
+ if (components === 1) {
1938
+ return vertexType;
1939
+ }
1940
+ return `${vertexType}x${components}`;
1941
+ }
1942
+ var TYPE_INFO = {
1943
+ f32: ["f32", 1],
1944
+ "vec2<f32>": ["f32", 2],
1945
+ "vec3<f32>": ["f32", 3],
1946
+ "vec4<f32>": ["f32", 4],
1947
+ f16: ["f16", 1],
1948
+ "vec2<f16>": ["f16", 2],
1949
+ "vec3<f16>": ["f16", 3],
1950
+ "vec4<f16>": ["f16", 4],
1951
+ i32: ["i32", 1],
1952
+ "vec2<i32>": ["i32", 2],
1953
+ "vec3<i32>": ["i32", 3],
1954
+ "vec4<i32>": ["i32", 4],
1955
+ u32: ["u32", 1],
1956
+ "vec2<u32>": ["u32", 2],
1957
+ "vec3<u32>": ["u32", 3],
1958
+ "vec4<u32>": ["u32", 4]
1959
+ };
1960
+ var TYPE_SIZES = {
1961
+ f32: 4,
1962
+ f16: 2,
1963
+ i32: 4,
1964
+ u32: 4
1965
+ };
1966
+
1967
+ // src/adapter/type-utils/decode-data-type.ts
1968
+ function decodeVertexType(type) {
1969
+ const dataType = TYPE_MAP[type];
1970
+ const bytes = getDataTypeBytes(dataType);
1971
+ const normalized = type.includes("norm");
1972
+ const integer = !normalized && !type.startsWith("float");
1973
+ const signed = type.startsWith("s");
1974
+ return {
1975
+ dataType: TYPE_MAP[type],
1976
+ byteLength: bytes,
1977
+ integer,
1978
+ signed,
1979
+ normalized
1980
+ };
1981
+ }
1982
+ function getDataTypeBytes(type) {
1983
+ const bytes = TYPE_SIZES2[type];
1984
+ return bytes;
1985
+ }
1986
+ var TYPE_MAP = {
1987
+ uint8: "uint8",
1988
+ sint8: "sint8",
1989
+ unorm8: "uint8",
1990
+ snorm8: "sint8",
1991
+ uint16: "uint16",
1992
+ sint16: "sint16",
1993
+ unorm16: "uint16",
1994
+ snorm16: "sint16",
1995
+ float16: "float16",
1996
+ float32: "float32",
1997
+ uint32: "uint32",
1998
+ sint32: "sint32"
1999
+ };
2000
+ var TYPE_SIZES2 = {
2001
+ uint8: 1,
2002
+ sint8: 1,
2003
+ uint16: 2,
2004
+ sint16: 2,
2005
+ float16: 2,
2006
+ float32: 4,
2007
+ uint32: 4,
2008
+ sint32: 4
2009
+ };
2010
+
2011
+ // src/adapter/type-utils/decode-vertex-format.ts
2012
+ function decodeVertexFormat(format) {
2013
+ let webglOnly;
2014
+ if (format.endsWith("-webgl")) {
2015
+ format.replace("-webgl", "");
2016
+ webglOnly = true;
2017
+ }
2018
+ const [type_, count] = format.split("x");
2019
+ const type = type_;
2020
+ const components = count ? parseInt(count) : 1;
2021
+ const decodedType = decodeVertexType(type);
2022
+ const result = {
2023
+ type,
2024
+ components,
2025
+ byteLength: decodedType.byteLength * components,
2026
+ integer: decodedType.integer,
2027
+ signed: decodedType.signed,
2028
+ normalized: decodedType.normalized
2029
+ };
2030
+ if (webglOnly) {
2031
+ result.webglOnly = true;
2032
+ }
2033
+ return result;
2034
+ }
2035
+
2036
+ // src/adapter/attribute-utils/get-attribute-from-layouts.ts
2037
+ function getAttributeInfosFromLayouts(shaderLayout, bufferLayout) {
2038
+ const attributeInfos = {};
2039
+ for (const attribute of shaderLayout.attributes) {
2040
+ attributeInfos[attribute.name] = getAttributeInfoFromLayouts(shaderLayout, bufferLayout, attribute.name);
2041
+ }
2042
+ return attributeInfos;
2043
+ }
2044
+ function getAttributeInfosByLocation(shaderLayout, bufferLayout, maxVertexAttributes = 16) {
2045
+ const attributeInfos = getAttributeInfosFromLayouts(shaderLayout, bufferLayout);
2046
+ const locationInfos = new Array(maxVertexAttributes).fill(null);
2047
+ for (const attributeInfo of Object.values(attributeInfos)) {
2048
+ locationInfos[attributeInfo.location] = attributeInfo;
2049
+ }
2050
+ return locationInfos;
2051
+ }
2052
+ function getAttributeInfoFromLayouts(shaderLayout, bufferLayout, name2) {
2053
+ const shaderDeclaration = getAttributeFromShaderLayout(shaderLayout, name2);
2054
+ const bufferMapping = getAttributeFromBufferLayout(bufferLayout, name2);
2055
+ if (!shaderDeclaration) {
2056
+ return null;
2057
+ }
2058
+ const attributeTypeInfo = decodeShaderAttributeType(shaderDeclaration.type);
2059
+ const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
2060
+ const vertexFormatInfo = decodeVertexFormat(vertexFormat);
2061
+ return {
2062
+ attributeName: bufferMapping?.attributeName || shaderDeclaration.name,
2063
+ bufferName: bufferMapping?.bufferName || shaderDeclaration.name,
2064
+ location: shaderDeclaration.location,
2065
+ shaderType: shaderDeclaration.type,
2066
+ shaderDataType: attributeTypeInfo.dataType,
2067
+ shaderComponents: attributeTypeInfo.components,
2068
+ vertexFormat,
2069
+ bufferDataType: vertexFormatInfo.type,
2070
+ bufferComponents: vertexFormatInfo.components,
2071
+ normalized: vertexFormatInfo.normalized,
2072
+ integer: attributeTypeInfo.integer,
2073
+ stepMode: bufferMapping?.stepMode || shaderDeclaration.stepMode,
2074
+ byteOffset: bufferMapping?.byteOffset || 0,
2075
+ byteStride: bufferMapping?.byteStride || 0
2076
+ };
2077
+ }
2078
+ function getAttributeFromShaderLayout(shaderLayout, name2) {
2079
+ const attribute = shaderLayout.attributes.find((attr) => attr.name === name2);
2080
+ if (!attribute) {
2081
+ log.warn(`shader layout attribute "${name2}" not present in shader`);
2082
+ }
2083
+ return attribute || null;
2084
+ }
2085
+ function getAttributeFromBufferLayout(bufferLayouts, name2) {
2086
+ checkBufferLayouts(bufferLayouts);
2087
+ let bufferLayoutInfo = getAttributeFromShortHand(bufferLayouts, name2);
2088
+ if (bufferLayoutInfo) {
2089
+ return bufferLayoutInfo;
2090
+ }
2091
+ bufferLayoutInfo = getAttributeFromAttributesList(bufferLayouts, name2);
2092
+ if (bufferLayoutInfo) {
2093
+ return bufferLayoutInfo;
2094
+ }
2095
+ log.warn(`layout for attribute "${name2}" not present in buffer layout`);
2096
+ return null;
2097
+ }
2098
+ function checkBufferLayouts(bufferLayouts) {
2099
+ for (const bufferLayout of bufferLayouts) {
2100
+ if (bufferLayout.attributes && bufferLayout.format || !bufferLayout.attributes && !bufferLayout.format) {
2101
+ log.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`);
2102
+ }
2103
+ }
2104
+ }
2105
+ function getAttributeFromShortHand(bufferLayouts, name2) {
2106
+ for (const bufferLayout of bufferLayouts) {
2107
+ if (bufferLayout.format && bufferLayout.name === name2) {
2108
+ return {
2109
+ attributeName: bufferLayout.name,
2110
+ bufferName: name2,
2111
+ stepMode: bufferLayout.stepMode,
2112
+ vertexFormat: bufferLayout.format,
2113
+ byteOffset: 0,
2114
+ byteStride: bufferLayout.byteStride || 0
2115
+ };
2116
+ }
2117
+ }
2118
+ return null;
2119
+ }
2120
+ function getAttributeFromAttributesList(bufferLayouts, name2) {
2121
+ for (const bufferLayout of bufferLayouts) {
2122
+ let byteStride = bufferLayout.byteStride;
2123
+ if (typeof bufferLayout.byteStride !== "number") {
2124
+ for (const attributeMapping2 of bufferLayout.attributes || []) {
2125
+ const info = decodeVertexFormat(attributeMapping2.format);
2126
+ byteStride += info.byteLength;
2127
+ }
2128
+ }
2129
+ const attributeMapping = bufferLayout.attributes?.find((mapping) => mapping.attribute === name2);
2130
+ if (attributeMapping) {
2131
+ return {
2132
+ attributeName: attributeMapping.attribute,
2133
+ bufferName: bufferLayout.name,
2134
+ stepMode: bufferLayout.stepMode,
2135
+ vertexFormat: attributeMapping.format,
2136
+ byteOffset: attributeMapping.byteOffset,
2137
+ byteStride
2138
+ };
2139
+ }
2140
+ }
2141
+ return null;
2142
+ }
2143
+ function mergeShaderLayout(baseLayout, overrideLayout) {
2144
+ const mergedLayout = {
2145
+ ...baseLayout,
2146
+ attributes: baseLayout.attributes.map((attribute) => ({
2147
+ ...attribute
2148
+ }))
2149
+ };
2150
+ for (const attribute of overrideLayout?.attributes || []) {
2151
+ const baseAttribute = mergedLayout.attributes.find((attr) => attr.name === attribute.name);
2152
+ if (!baseAttribute) {
2153
+ log.warn(`shader layout attribute ${attribute.name} not present in shader`);
2154
+ } else {
2155
+ baseAttribute.type = attribute.type || baseAttribute.type;
2156
+ baseAttribute.stepMode = attribute.stepMode || baseAttribute.stepMode;
2157
+ }
2158
+ }
2159
+ return mergedLayout;
2160
+ }
2161
+
2162
+ // src/adapter/resources/vertex-array.ts
2163
+ var _VertexArray = class extends Resource {
2164
+ get [Symbol.toStringTag]() {
2165
+ return "VertexArray";
2166
+ }
2167
+ indexBuffer = null;
2168
+ constructor(device, props) {
2169
+ super(device, props, _VertexArray.defaultProps);
2170
+ this.maxVertexAttributes = device.limits.maxVertexAttributes;
2171
+ this.attributes = new Array(this.maxVertexAttributes).fill(null);
2172
+ this.attributeInfos = getAttributeInfosByLocation(props.renderPipeline.shaderLayout, props.renderPipeline.bufferLayout, this.maxVertexAttributes);
2173
+ }
2174
+ };
2175
+ var VertexArray = _VertexArray;
2176
+ __publicField(VertexArray, "defaultProps", {
2177
+ ...Resource.defaultProps,
2178
+ renderPipeline: null
2179
+ });
2180
+
2181
+ // src/adapter/resources/transform-feedback.ts
2182
+ var _TransformFeedback = class extends Resource {
2183
+ get [Symbol.toStringTag]() {
2184
+ return "TransformFeedback";
2185
+ }
2186
+ constructor(device, props) {
2187
+ super(device, props, _TransformFeedback.defaultProps);
2188
+ }
2189
+ };
2190
+ var TransformFeedback = _TransformFeedback;
2191
+ __publicField(TransformFeedback, "defaultProps", {
2192
+ ...Resource.defaultProps,
2193
+ layout: void 0,
2194
+ buffers: {}
2195
+ });
2196
+
2197
+ // src/adapter/type-utils/decode-shader-types.ts
2198
+ var UNIFORM_FORMATS = {
2199
+ "f32": {
2200
+ type: "f32",
2201
+ components: 1
2202
+ },
2203
+ "i32": {
2204
+ type: "i32",
2205
+ components: 1
2206
+ },
2207
+ "u32": {
2208
+ type: "u32",
2209
+ components: 1
2210
+ },
2211
+ "vec2<f32>": {
2212
+ type: "f32",
2213
+ components: 2
2214
+ },
2215
+ "vec3<f32>": {
2216
+ type: "f32",
2217
+ components: 3
2218
+ },
2219
+ "vec4<f32>": {
2220
+ type: "f32",
2221
+ components: 4
2222
+ },
2223
+ "vec2<i32>": {
2224
+ type: "i32",
2225
+ components: 2
2226
+ },
2227
+ "vec3<i32>": {
2228
+ type: "i32",
2229
+ components: 3
2230
+ },
2231
+ "vec4<i32>": {
2232
+ type: "i32",
2233
+ components: 4
2234
+ },
2235
+ "vec2<u32>": {
2236
+ type: "u32",
2237
+ components: 2
2238
+ },
2239
+ "vec3<u32>": {
2240
+ type: "u32",
2241
+ components: 3
2242
+ },
2243
+ "vec4<u32>": {
2244
+ type: "u32",
2245
+ components: 4
2246
+ },
2247
+ "mat2x2<f32>": {
2248
+ type: "f32",
2249
+ components: 4
2250
+ },
2251
+ "mat2x3<f32>": {
2252
+ type: "f32",
2253
+ components: 6
2254
+ },
2255
+ "mat2x4<f32>": {
2256
+ type: "f32",
2257
+ components: 8
2258
+ },
2259
+ "mat3x2<f32>": {
2260
+ type: "f32",
2261
+ components: 6
2262
+ },
2263
+ "mat3x3<f32>": {
2264
+ type: "f32",
2265
+ components: 9
2266
+ },
2267
+ "mat3x4<f32>": {
2268
+ type: "f32",
2269
+ components: 12
2270
+ },
2271
+ "mat4x2<f32>": {
2272
+ type: "f32",
2273
+ components: 8
2274
+ },
2275
+ "mat4x3<f32>": {
2276
+ type: "f32",
2277
+ components: 12
2278
+ },
2279
+ "mat4x4<f32>": {
2280
+ type: "f32",
2281
+ components: 16
2282
+ }
2283
+ };
2284
+ function decodeShaderUniformType(format) {
2285
+ const decoded = UNIFORM_FORMATS[format];
2286
+ assert2(format);
2287
+ return decoded;
2288
+ }
2289
+ function alignTo(size, count) {
2290
+ switch (count) {
2291
+ case 1:
2292
+ return size;
2293
+ case 2:
2294
+ return size + size % 2;
2295
+ default:
2296
+ return size + (4 - size % 4) % 4;
2297
+ }
2298
+ }
2299
+
2300
+ // src/utils/array-utils-flat.ts
2301
+ var arrayBuffer;
2302
+ function getScratchArrayBuffer(byteLength) {
2303
+ if (!arrayBuffer || arrayBuffer.byteLength < byteLength) {
2304
+ arrayBuffer = new ArrayBuffer(byteLength);
2305
+ }
2306
+ return arrayBuffer;
2307
+ }
2308
+ function getScratchArray(Type, length) {
2309
+ const scratchArrayBuffer = getScratchArrayBuffer(Type.BYTES_PER_ELEMENT * length);
2310
+ return new Type(scratchArrayBuffer, 0, length);
2311
+ }
2312
+ function fillArray(options) {
2313
+ const {
2314
+ target,
2315
+ source,
2316
+ start = 0,
2317
+ count = 1
2318
+ } = options;
2319
+ const length = source.length;
2320
+ const total = count * length;
2321
+ let copied = 0;
2322
+ for (let i = start; copied < length; copied++) {
2323
+ target[i++] = source[copied];
2324
+ }
2325
+ while (copied < total) {
2326
+ if (copied < total - copied) {
2327
+ target.copyWithin(start + copied, start, start + copied);
2328
+ copied *= 2;
2329
+ } else {
2330
+ target.copyWithin(start + copied, start, start + total - copied);
2331
+ copied = total;
2332
+ }
2333
+ }
2334
+ return options.target;
2335
+ }
2336
+
2337
+ // src/lib/uniforms/uniform-buffer-layout.ts
2338
+ var minBufferSize = 1024;
2339
+ var UniformBufferLayout = class {
2340
+ layout = {};
2341
+ constructor(uniformTypes) {
2342
+ let size = 0;
2343
+ for (const [key, uniformType] of Object.entries(uniformTypes)) {
2344
+ const typeAndComponents = decodeShaderUniformType(uniformType);
2345
+ const {
2346
+ type,
2347
+ components: count
2348
+ } = typeAndComponents;
2349
+ size = alignTo(size, count);
2350
+ const offset = size;
2351
+ size += count;
2352
+ this.layout[key] = {
2353
+ type,
2354
+ size: count,
2355
+ offset
2356
+ };
2357
+ }
2358
+ size += (4 - size % 4) % 4;
2359
+ const actualByteLength = size * 4;
2360
+ this.byteLength = Math.max(actualByteLength, minBufferSize);
2361
+ }
2362
+ getData(uniformValues) {
2363
+ const bufferSize = Math.max(this.byteLength, minBufferSize);
2364
+ const arrayBuffer2 = getScratchArrayBuffer(bufferSize);
2365
+ const typedArrays = {
2366
+ i32: new Int32Array(arrayBuffer2),
2367
+ u32: new Uint32Array(arrayBuffer2),
2368
+ f32: new Float32Array(arrayBuffer2),
2369
+ f16: new Uint16Array(arrayBuffer2)
2370
+ };
2371
+ for (const [name2, value] of Object.entries(uniformValues)) {
2372
+ const uniformLayout = this.layout[name2];
2373
+ if (!uniformLayout) {
2374
+ log.warn(`Supplied uniform value ${name2} not present in uniform block layout`)();
2375
+ continue;
2376
+ }
2377
+ const {
2378
+ type,
2379
+ size,
2380
+ offset
2381
+ } = uniformLayout;
2382
+ const typedArray = typedArrays[type];
2383
+ if (size === 1) {
2384
+ if (typeof value !== "number" && typeof value !== "boolean") {
2385
+ log.warn(`Supplied value for single component uniform ${name2} is not a number: ${value}`)();
2386
+ continue;
2387
+ }
2388
+ typedArray[offset] = Number(value);
2389
+ } else {
2390
+ const numericArray = isNumberArray(value);
2391
+ if (!numericArray) {
2392
+ log.warn(`Supplied value for multi component / array uniform ${name2} is not a numeric array: ${value}`)();
2393
+ continue;
2394
+ }
2395
+ typedArray.set(numericArray, offset);
2396
+ }
2397
+ }
2398
+ return new Uint8Array(arrayBuffer2);
2399
+ }
2400
+ has(name2) {
2401
+ return Boolean(this.layout[name2]);
2402
+ }
2403
+ get(name2) {
2404
+ const layout = this.layout[name2];
2405
+ return layout;
2406
+ }
2407
+ };
2408
+
2409
+ // src/utils/array-equal.ts
2410
+ function arrayEqual(a, b, limit = 16) {
2411
+ if (a !== b) {
2412
+ return false;
2413
+ }
2414
+ const arrayA = isNumberArray(a);
2415
+ if (!arrayA) {
2416
+ return false;
2417
+ }
2418
+ const arrayB = isNumberArray(b);
2419
+ if (arrayB && arrayA.length === arrayB.length) {
2420
+ for (let i = 0; i < arrayA.length; ++i) {
2421
+ if (arrayB[i] !== arrayA[i]) {
2422
+ return false;
2423
+ }
2424
+ }
2425
+ }
2426
+ return true;
2427
+ }
2428
+ function arrayCopy(a) {
2429
+ const numberArray = isNumberArray(a);
2430
+ if (numberArray) {
2431
+ return numberArray.slice();
2432
+ }
2433
+ return a;
2434
+ }
2435
+
2436
+ // src/lib/uniforms/uniform-block.ts
2437
+ var UniformBlock = class {
2438
+ uniforms = {};
2439
+ modifiedUniforms = {};
2440
+ modified = true;
2441
+ bindingLayout = {};
2442
+ needsRedraw = "initialized";
2443
+ constructor(props) {
2444
+ this.name = props?.name;
2445
+ if (props?.name && props?.shaderLayout) {
2446
+ const binding = props?.shaderLayout.bindings?.find((binding2) => binding2.type === "uniform" && binding2.name === props?.name);
2447
+ if (!binding) {
2448
+ throw new Error(props?.name);
2449
+ }
2450
+ const uniformBlock = binding;
2451
+ for (const uniform of uniformBlock.uniforms || []) {
2452
+ this.bindingLayout[uniform.name] = uniform;
2453
+ }
2454
+ }
2455
+ }
2456
+ setUniforms(uniforms) {
2457
+ for (const [key, value] of Object.entries(uniforms)) {
2458
+ this._setUniform(key, value);
2459
+ if (!this.needsRedraw) {
2460
+ this.setNeedsRedraw(`${this.name}.${key}=${value}`);
2461
+ }
2462
+ }
2463
+ }
2464
+ setNeedsRedraw(reason) {
2465
+ this.needsRedraw = this.needsRedraw || reason;
2466
+ }
2467
+ getAllUniforms() {
2468
+ this.modifiedUniforms = {};
2469
+ this.needsRedraw = false;
2470
+ return this.uniforms || {};
2471
+ }
2472
+ _setUniform(key, value) {
2473
+ if (arrayEqual(this.uniforms[key], value)) {
2474
+ return;
2475
+ }
2476
+ this.uniforms[key] = arrayCopy(value);
2477
+ this.modifiedUniforms[key] = true;
2478
+ this.modified = true;
2479
+ }
2480
+ };
2481
+
2482
+ // src/lib/uniforms/uniform-store.ts
2483
+ var UniformStore = class {
2484
+ uniformBlocks = /* @__PURE__ */ new Map();
2485
+ uniformBufferLayouts = /* @__PURE__ */ new Map();
2486
+ uniformBuffers = /* @__PURE__ */ new Map();
2487
+ constructor(blocks) {
2488
+ for (const [bufferName, block] of Object.entries(blocks)) {
2489
+ const uniformBufferName = bufferName;
2490
+ const uniformBufferLayout = new UniformBufferLayout(block.uniformTypes || {});
2491
+ this.uniformBufferLayouts.set(uniformBufferName, uniformBufferLayout);
2492
+ const uniformBlock = new UniformBlock({
2493
+ name: bufferName
2494
+ });
2495
+ uniformBlock.setUniforms(block.defaultUniforms || {});
2496
+ this.uniformBlocks.set(uniformBufferName, uniformBlock);
2497
+ }
2498
+ }
2499
+ destroy() {
2500
+ for (const uniformBuffer of Object.values(this.uniformBuffers)) {
2501
+ uniformBuffer.destroy();
2502
+ }
2503
+ }
2504
+ setUniforms(uniforms) {
2505
+ for (const [blockName, uniformValues] of Object.entries(uniforms)) {
2506
+ this.uniformBlocks.get(blockName).setUniforms(uniformValues);
2507
+ }
2508
+ this.updateUniformBuffers();
2509
+ }
2510
+ getUniformBufferByteLength(uniformBufferName) {
2511
+ return this.uniformBufferLayouts.get(uniformBufferName).byteLength;
2512
+ }
2513
+ getUniformBufferData(uniformBufferName) {
2514
+ const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
2515
+ return this.uniformBufferLayouts.get(uniformBufferName).getData(uniformValues);
2516
+ }
2517
+ createUniformBuffer(device, uniformBufferName, uniforms) {
2518
+ if (uniforms) {
2519
+ this.setUniforms(uniforms);
2520
+ }
2521
+ const byteLength = this.getUniformBufferByteLength(uniformBufferName);
2522
+ const uniformBuffer = device.createBuffer({
2523
+ usage: Buffer2.UNIFORM | Buffer2.COPY_DST,
2524
+ byteLength
2525
+ });
2526
+ const uniformBufferData = this.getUniformBufferData(uniformBufferName);
2527
+ uniformBuffer.write(uniformBufferData);
2528
+ return uniformBuffer;
2529
+ }
2530
+ getManagedUniformBuffer(device, uniformBufferName) {
2531
+ if (!this.uniformBuffers.get(uniformBufferName)) {
2532
+ const byteLength = this.getUniformBufferByteLength(uniformBufferName);
2533
+ const uniformBuffer = device.createBuffer({
2534
+ usage: Buffer2.UNIFORM | Buffer2.COPY_DST,
2535
+ byteLength
2536
+ });
2537
+ this.uniformBuffers.set(uniformBufferName, uniformBuffer);
2538
+ }
2539
+ return this.uniformBuffers.get(uniformBufferName);
2540
+ }
2541
+ updateUniformBuffers() {
2542
+ let reason = false;
2543
+ for (const uniformBufferName of this.uniformBlocks.keys()) {
2544
+ const bufferReason = this.updateUniformBuffer(uniformBufferName);
2545
+ reason ||= bufferReason;
2546
+ }
2547
+ if (reason) {
2548
+ log.log(3, `UniformStore.updateUniformBuffers(): ${reason}`)();
2549
+ }
2550
+ return reason;
2551
+ }
2552
+ updateUniformBuffer(uniformBufferName) {
2553
+ const uniformBlock = this.uniformBlocks.get(uniformBufferName);
2554
+ const uniformBuffer = this.uniformBuffers.get(uniformBufferName);
2555
+ let reason = false;
2556
+ if (uniformBuffer && uniformBlock.needsRedraw) {
2557
+ reason ||= uniformBlock.needsRedraw;
2558
+ const uniformBufferData = this.getUniformBufferData(uniformBufferName);
2559
+ const uniformBuffer2 = this.uniformBuffers.get(uniformBufferName);
2560
+ uniformBuffer2.write(uniformBufferData);
2561
+ const uniformValues = this.uniformBlocks.get(uniformBufferName).getAllUniforms();
2562
+ log.log(4, `Writing to uniform buffer ${String(uniformBufferName)}`, uniformBufferData, uniformValues)();
2563
+ }
2564
+ return reason;
2565
+ }
2566
+ };
2567
+
2568
+ // src/adapter/type-utils/decode-texture-format.ts
2569
+ var REGEX = /^(rg?b?a?)([0-9]*)([a-z]*)(-srgb)?(-webgl|-unsized)?$/;
2570
+ function decodeTextureFormat(format) {
2571
+ const matches = REGEX.exec(format);
2572
+ if (matches) {
2573
+ const [, format2, length, type, srgb, suffix] = matches;
2574
+ if (format2) {
2575
+ const dataType = `${type}${length}`;
2576
+ const decodedType = decodeVertexType(dataType);
2577
+ return {
2578
+ format: format2,
2579
+ components: format2.length,
2580
+ srgb: srgb === "-srgb",
2581
+ unsized: suffix === "-unsized",
2582
+ webgl: suffix === "-webgl",
2583
+ ...decodedType
2584
+ };
2585
+ }
2586
+ }
2587
+ return decodeNonStandardFormat(format);
2588
+ }
2589
+ var EXCEPTIONS = {
2590
+ "rgba4unorm-webgl": {
2591
+ format: "rgba",
2592
+ bpp: 2
2593
+ },
2594
+ "rgb565unorm-webgl": {
2595
+ format: "rgb",
2596
+ bpp: 2
2597
+ },
2598
+ "rgb5a1unorm-webgl": {
2599
+ format: "rgba",
2600
+ bbp: 2
2601
+ },
2602
+ "rgb9e5ufloat": {
2603
+ format: "rgb",
2604
+ bbp: 4
2605
+ },
2606
+ "rg11b10ufloat": {
2607
+ format: "rgb",
2608
+ bbp: 4
2609
+ },
2610
+ "rgb10a2unorm": {
2611
+ format: "rgba",
2612
+ bbp: 4
2613
+ },
2614
+ "rgb10a2unorm-webgl": {
2615
+ format: "rgba",
2616
+ bbp: 4
2617
+ },
2618
+ "stencil8": {
2619
+ components: 1,
2620
+ bpp: 1,
2621
+ a: "stencil"
2622
+ },
2623
+ "depth16unorm": {
2624
+ components: 1,
2625
+ bpp: 2,
2626
+ a: "depth"
2627
+ },
2628
+ "depth24plus": {
2629
+ components: 1,
2630
+ bpp: 3,
2631
+ a: "depth"
2632
+ },
2633
+ "depth32float": {
2634
+ components: 1,
2635
+ bpp: 4,
2636
+ a: "depth"
2637
+ },
2638
+ "depth24plus-stencil8": {
2639
+ components: 2,
2640
+ bpp: 4,
2641
+ a: "depth-stencil"
2642
+ },
2643
+ "depth24unorm-stencil8": {
2644
+ components: 2,
2645
+ bpp: 4,
2646
+ a: "depth-stencil"
2647
+ },
2648
+ "depth32float-stencil8": {
2649
+ components: 2,
2650
+ bpp: 4,
2651
+ a: "depth-stencil"
2652
+ }
2653
+ };
2654
+ function decodeNonStandardFormat(format) {
2655
+ const data = EXCEPTIONS[format];
2656
+ if (!data) {
2657
+ throw new Error(`Unknown format ${format}`);
2658
+ }
2659
+ return {
2660
+ format: data.format || "",
2661
+ components: data.components || data.format?.length || 1,
2662
+ byteLength: data.bpp || 1,
2663
+ srgb: false,
2664
+ unsized: false
2665
+ };
2666
+ }
2667
+
2668
+ // src/adapter/type-utils/vertex-format-from-attribute.ts
2669
+ function getDataTypeFromTypedArray(arrayOrType) {
2670
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
2671
+ switch (type) {
2672
+ case Float32Array:
2673
+ return "float32";
2674
+ case Uint16Array:
2675
+ return "uint16";
2676
+ case Uint32Array:
2677
+ return "uint32";
2678
+ case Uint8Array:
2679
+ case Uint8ClampedArray:
2680
+ return "uint8";
2681
+ case Int8Array:
2682
+ return "sint8";
2683
+ case Int16Array:
2684
+ return "sint16";
2685
+ case Int32Array:
2686
+ return "sint32";
2687
+ default:
2688
+ throw new Error(type.constructor.name);
2689
+ }
2690
+ }
2691
+ function getTypedArrayFromDataType(dataType) {
2692
+ switch (dataType) {
2693
+ case "float32":
2694
+ return Float32Array;
2695
+ case "uint32":
2696
+ return Uint32Array;
2697
+ case "sint32":
2698
+ return Int32Array;
2699
+ case "uint16":
2700
+ case "unorm16":
2701
+ return Uint16Array;
2702
+ case "sint16":
2703
+ case "snorm16":
2704
+ return Int16Array;
2705
+ case "uint8":
2706
+ case "unorm8":
2707
+ return Uint8Array;
2708
+ case "sint8":
2709
+ case "snorm8":
2710
+ return Int8Array;
2711
+ default:
2712
+ throw new Error(dataType);
2713
+ }
2714
+ }
2715
+ function getVertexFormatFromAttribute(typedArray, size, normalized) {
2716
+ if (!size || size > 4) {
2717
+ throw new Error(`size ${size}`);
2718
+ }
2719
+ const components = size;
2720
+ let dataType = getDataTypeFromTypedArray(typedArray);
2721
+ if (dataType === "uint8" || dataType === "sint8") {
2722
+ if (components === 1 || components === 3) {
2723
+ throw new Error(`size: ${size}`);
2724
+ }
2725
+ if (normalized) {
2726
+ dataType = dataType.replace("int", "norm");
2727
+ }
2728
+ return `${dataType}x${components}`;
2729
+ }
2730
+ if (dataType === "uint16" || dataType === "sint16") {
2731
+ if (components === 1 || components === 3) {
2732
+ throw new Error(`size: ${size}`);
2733
+ }
2734
+ if (normalized) {
2735
+ dataType = dataType.replace("int", "norm");
2736
+ }
2737
+ return `${dataType}x${components}`;
2738
+ }
2739
+ if (components === 1) {
2740
+ return dataType;
2741
+ }
2742
+ return `${dataType}x${components}`;
2743
+ }
2744
+
2745
+ // src/utils/cast.ts
2746
+ function cast(value) {
2747
+ return value;
2748
+ }
2749
+
2750
+ // src/lib/uniforms/uniform.ts
2751
+ function isUniformValue(value) {
2752
+ return isNumberArray(value) !== null || typeof value === "number" || typeof value === "boolean";
2753
+ }
2754
+ function splitUniformsAndBindings(uniforms) {
2755
+ const result = {
2756
+ bindings: {},
2757
+ uniforms: {}
2758
+ };
2759
+ Object.keys(uniforms).forEach((name2) => {
2760
+ const uniform = uniforms[name2];
2761
+ if (isUniformValue(uniform)) {
2762
+ result.uniforms[name2] = uniform;
2763
+ } else {
2764
+ result.bindings[name2] = uniform;
2765
+ }
2766
+ });
2767
+ return result;
2768
+ }
2769
+
2770
+ // src/utils/format-value.ts
2771
+ function formatArrayValue(v, opts = {}) {
2772
+ const {
2773
+ maxElts = 16,
2774
+ size = 1
2775
+ } = opts;
2776
+ let string = "[";
2777
+ for (let i = 0; i < v.length && i < maxElts; ++i) {
2778
+ if (i > 0) {
2779
+ string += `,${i % size === 0 ? " " : ""}`;
2780
+ }
2781
+ string += formatValue(v[i], opts);
2782
+ }
2783
+ const terminator = v.length > maxElts ? "..." : "]";
2784
+ return `${string}${terminator}`;
2785
+ }
2786
+ function formatValue(v, opts = {}) {
2787
+ const EPSILON = 1e-16;
2788
+ const {
2789
+ isInteger = false
2790
+ } = opts;
2791
+ if (Array.isArray(v) || ArrayBuffer.isView(v)) {
2792
+ return formatArrayValue(v, opts);
2793
+ }
2794
+ if (typeof v !== "number") {
2795
+ return String(v);
2796
+ }
2797
+ if (Math.abs(v) < EPSILON) {
2798
+ return isInteger ? "0" : "0.";
2799
+ }
2800
+ if (isInteger) {
2801
+ return v.toFixed(0);
2802
+ }
2803
+ if (Math.abs(v) > 100 && Math.abs(v) < 1e4) {
2804
+ return v.toFixed(0);
2805
+ }
2806
+ const string = v.toPrecision(2);
2807
+ const decimal = string.indexOf(".0");
2808
+ return decimal === string.length - 2 ? string.slice(0, -1) : string;
2809
+ }
2810
+
2811
+ // src/utils/stub-methods.ts
2812
+ function stubRemovedMethods(instance, className, version, methodNames) {
2813
+ const upgradeMessage = `See luma.gl ${version} Upgrade Guide at https://luma.gl/docs/upgrade-guide`;
2814
+ const prototype = Object.getPrototypeOf(instance);
2815
+ methodNames.forEach((methodName) => {
2816
+ if (prototype.methodName) {
2817
+ return;
2818
+ }
2819
+ prototype[methodName] = () => {
2820
+ log.removed(`Calling removed method ${className}.${methodName}: `, upgradeMessage)();
2821
+ throw new Error(methodName);
2822
+ };
2823
+ });
2824
+ }
2825
+
2826
+ // src/utils/check-props.ts
2827
+ function checkProps(className, props, propChecks) {
2828
+ const {
2829
+ removedProps = {},
2830
+ deprecatedProps = {},
2831
+ replacedProps = {}
2832
+ } = propChecks;
2833
+ for (const propName in removedProps) {
2834
+ if (propName in props) {
2835
+ const replacementProp = removedProps[propName];
2836
+ const replacement = replacementProp ? `${className}.${removedProps[propName]}` : "N/A";
2837
+ log.removed(`${className}.${propName}`, replacement)();
2838
+ }
2839
+ }
2840
+ for (const propName in deprecatedProps) {
2841
+ if (propName in props) {
2842
+ const replacementProp = deprecatedProps[propName];
2843
+ log.deprecated(`${className}.${propName}`, `${className}.${replacementProp}`)();
2844
+ }
2845
+ }
2846
+ let newProps = null;
2847
+ for (const [propName, replacementProp] of Object.entries(replacedProps)) {
2848
+ if (propName in props) {
2849
+ log.deprecated(`${className}.${propName}`, `${className}.${replacementProp}`)();
2850
+ newProps = newProps || Object.assign({}, props);
2851
+ newProps[replacementProp] = props[propName];
2852
+ delete newProps[propName];
2853
+ }
2854
+ }
2855
+ return newProps || props;
2856
+ }
2857
+
2858
+ // src/utils/load-file.ts
2859
+ var pathPrefix = "";
2860
+ function setPathPrefix(prefix) {
2861
+ pathPrefix = prefix;
2862
+ }
2863
+ async function loadFile(url, options) {
2864
+ url = url.startsWith("http") ? url : pathPrefix + url;
2865
+ const dataType = options?.dataType || "text";
2866
+ const response = await fetch(url, options);
2867
+ return await response[dataType]();
2868
+ }
2869
+ async function loadImageBitmap(url, opts) {
2870
+ const image = new Image();
2871
+ image.crossOrigin = opts?.crossOrigin || "anonymous";
2872
+ image.src = url.startsWith("http") ? url : pathPrefix + url;
2873
+ await image.decode();
2874
+ return await createImageBitmap(image);
2875
+ }
2876
+ async function loadImage(url, opts) {
2877
+ return new Promise((resolve, reject) => {
2878
+ try {
2879
+ const image = new Image();
2880
+ image.onload = () => resolve(image);
2881
+ image.onerror = () => reject(new Error(`Could not load image ${url}.`));
2882
+ image.crossOrigin = opts?.crossOrigin || "anonymous";
2883
+ image.src = url.startsWith("http") ? url : pathPrefix + url;
2884
+ } catch (error) {
2885
+ reject(error);
2886
+ }
2887
+ });
2888
+ }
2889
+ async function loadScript(scriptUrl, scriptId) {
2890
+ const head = document.getElementsByTagName("head")[0];
2891
+ if (!head) {
2892
+ throw new Error("loadScript");
2893
+ }
2894
+ const script = document.createElement("script");
2895
+ script.setAttribute("type", "text/javascript");
2896
+ script.setAttribute("src", scriptUrl);
2897
+ if (scriptId) {
2898
+ script.id = scriptId;
2899
+ }
2900
+ return new Promise((resolve, reject) => {
2901
+ script.onload = resolve;
2902
+ script.onerror = (error) => reject(new Error(`Unable to load script '${scriptUrl}': ${error}`));
2903
+ head.appendChild(script);
2904
+ });
2905
+ }
2906
+
2907
+ // src/utils/random.ts
2908
+ function makeRandomNumberGenerator() {
2909
+ let s = 1;
2910
+ let c = 1;
2911
+ return () => {
2912
+ s = Math.sin(c * 17.23);
2913
+ c = Math.cos(s * 27.92);
2914
+ return fract(Math.abs(s * c) * 1432.71);
2915
+ };
2916
+ }
2917
+ function fract(n) {
2918
+ return n - Math.floor(n);
2919
+ }
2920
+ var random = makeRandomNumberGenerator();
2921
+
2922
+ // src/utils/deep-equal.ts
2923
+ function deepEqual(a, b, depth) {
2924
+ if (a === b) {
2925
+ return true;
2926
+ }
2927
+ if (!depth || !a || !b) {
2928
+ return false;
2929
+ }
2930
+ if (Array.isArray(a)) {
2931
+ if (!Array.isArray(b) || a.length !== b.length) {
2932
+ return false;
2933
+ }
2934
+ for (let i = 0; i < a.length; i++) {
2935
+ if (!deepEqual(a[i], b[i], depth - 1)) {
2936
+ return false;
2937
+ }
2938
+ }
2939
+ return true;
2940
+ }
2941
+ if (Array.isArray(b)) {
2942
+ return false;
2943
+ }
2944
+ if (typeof a === "object" && typeof b === "object") {
2945
+ const aKeys = Object.keys(a);
2946
+ const bKeys = Object.keys(b);
2947
+ if (aKeys.length !== bKeys.length) {
2948
+ return false;
2949
+ }
2950
+ for (const key of aKeys) {
2951
+ if (!b.hasOwnProperty(key)) {
2952
+ return false;
2953
+ }
2954
+ if (!deepEqual(a[key], b[key], depth - 1)) {
2955
+ return false;
2956
+ }
2957
+ }
2958
+ return true;
2959
+ }
2960
+ return false;
2961
+ }
2962
+
2963
+ // src/utils/request-animation-frame.ts
2964
+ function requestAnimationFrame(callback) {
2965
+ return typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame(callback) : setTimeout(callback, 1e3 / 60);
2966
+ }
2967
+ function cancelAnimationFrame(timerId) {
2968
+ return typeof window !== "undefined" && window.cancelAnimationFrame ? window.cancelAnimationFrame(timerId) : clearTimeout(timerId);
2969
+ }
2970
+
2971
+ // src/index.ts
2972
+ var glsl = (x) => `${x}`;
2973
+ return __toCommonJS(src_exports);
2974
+ })();
2975
+ return __exports__;
2976
+ });