@luma.gl/webgl 9.0.0-alpha.4 → 9.0.0-alpha.40

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 (525) hide show
  1. package/LICENSE +3 -1
  2. package/dist/adapter/converters/device-parameters.d.ts +23 -4
  3. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  4. package/dist/adapter/converters/device-parameters.js +42 -47
  5. package/dist/adapter/converters/device-parameters.js.map +1 -1
  6. package/dist/adapter/converters/sampler-parameters.d.ts +5 -5
  7. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  8. package/dist/adapter/converters/sampler-parameters.js +20 -56
  9. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  10. package/dist/adapter/converters/shader-formats.d.ts +9 -0
  11. package/dist/adapter/converters/shader-formats.d.ts.map +1 -0
  12. package/dist/adapter/converters/shader-formats.js +53 -0
  13. package/dist/adapter/converters/shader-formats.js.map +1 -0
  14. package/dist/adapter/converters/texture-formats.d.ts +32 -44
  15. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  16. package/dist/adapter/converters/texture-formats.js +165 -201
  17. package/dist/adapter/converters/texture-formats.js.map +1 -1
  18. package/dist/adapter/converters/vertex-formats.d.ts +9 -3
  19. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  20. package/dist/adapter/converters/vertex-formats.js +51 -19
  21. package/dist/adapter/converters/vertex-formats.js.map +1 -1
  22. package/dist/adapter/device-helpers/device-features.d.ts +1 -1
  23. package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
  24. package/dist/adapter/device-helpers/device-features.js +14 -21
  25. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  26. package/dist/adapter/device-helpers/device-limits.d.ts +3 -3
  27. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  28. package/dist/adapter/device-helpers/device-limits.js +2 -5
  29. package/dist/adapter/device-helpers/device-limits.js.map +1 -1
  30. package/dist/adapter/device-helpers/get-device-info.d.ts +1 -1
  31. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  32. package/dist/adapter/device-helpers/get-device-info.js +9 -11
  33. package/dist/adapter/device-helpers/get-device-info.js.map +1 -1
  34. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +1 -1
  35. package/dist/adapter/device-helpers/is-old-ie.js +2 -1
  36. package/dist/adapter/device-helpers/is-old-ie.js.map +1 -1
  37. package/dist/adapter/helpers/decode-webgl-types.d.ts +26 -0
  38. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -0
  39. package/dist/adapter/helpers/{uniforms.js → decode-webgl-types.js} +20 -29
  40. package/dist/adapter/helpers/decode-webgl-types.js.map +1 -0
  41. package/dist/adapter/helpers/get-shader-info.d.ts +9 -0
  42. package/dist/adapter/helpers/get-shader-info.d.ts.map +1 -0
  43. package/dist/adapter/helpers/get-shader-info.js +25 -0
  44. package/dist/adapter/helpers/get-shader-info.js.map +1 -0
  45. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -48
  46. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  47. package/dist/adapter/helpers/get-shader-layout.js +60 -115
  48. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  49. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts +1 -1
  50. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  51. package/dist/adapter/helpers/parse-shader-compiler-log.js +0 -7
  52. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +1 -1
  53. package/dist/adapter/helpers/set-uniform.d.ts +3 -2
  54. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  55. package/dist/adapter/helpers/set-uniform.js +27 -57
  56. package/dist/adapter/helpers/set-uniform.js.map +1 -1
  57. package/dist/adapter/helpers/webgl-topology-utils.d.ts +11 -0
  58. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -0
  59. package/dist/adapter/helpers/{attribute-utils.js → webgl-topology-utils.js} +2 -19
  60. package/dist/adapter/helpers/webgl-topology-utils.js.map +1 -0
  61. package/dist/adapter/objects/constants-to-keys.d.ts +1 -3
  62. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  63. package/dist/adapter/objects/constants-to-keys.js +2 -29
  64. package/dist/adapter/objects/constants-to-keys.js.map +1 -1
  65. package/dist/adapter/objects/webgl-renderbuffer.d.ts +15 -12
  66. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  67. package/dist/adapter/objects/webgl-renderbuffer.js +34 -41
  68. package/dist/adapter/objects/webgl-renderbuffer.js.map +1 -1
  69. package/dist/adapter/objects/webgl-resource.d.ts +6 -9
  70. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  71. package/dist/adapter/objects/webgl-resource.js +26 -83
  72. package/dist/adapter/objects/webgl-resource.js.map +1 -1
  73. package/dist/adapter/resources/webgl-buffer.d.ts +18 -10
  74. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  75. package/dist/adapter/resources/webgl-buffer.js +49 -78
  76. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  77. package/dist/adapter/resources/webgl-command-buffer.d.ts +15 -9
  78. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-command-buffer.js +169 -43
  80. package/dist/adapter/resources/webgl-command-buffer.js.map +1 -1
  81. package/dist/adapter/resources/webgl-command-encoder.d.ts +7 -6
  82. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  83. package/dist/adapter/resources/webgl-command-encoder.js +10 -20
  84. package/dist/adapter/resources/webgl-command-encoder.js.map +1 -1
  85. package/dist/adapter/resources/webgl-external-texture.js.map +1 -1
  86. package/dist/adapter/resources/webgl-framebuffer.d.ts +21 -24
  87. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  88. package/dist/adapter/resources/webgl-framebuffer.js +46 -155
  89. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  90. package/dist/adapter/resources/webgl-render-pass.d.ts +19 -4
  91. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  92. package/dist/adapter/resources/webgl-render-pass.js +91 -11
  93. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  94. package/dist/adapter/resources/webgl-render-pipeline.d.ts +53 -19
  95. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  96. package/dist/adapter/resources/webgl-render-pipeline.js +107 -230
  97. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  98. package/dist/adapter/resources/webgl-sampler.d.ts +6 -5
  99. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  100. package/dist/adapter/resources/webgl-sampler.js +10 -19
  101. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  102. package/dist/adapter/resources/webgl-shader.d.ts +3 -4
  103. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  104. package/dist/adapter/resources/webgl-shader.js +19 -31
  105. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  106. package/dist/adapter/resources/webgl-texture.d.ts +64 -44
  107. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  108. package/dist/adapter/resources/webgl-texture.js +119 -235
  109. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  110. package/dist/adapter/resources/webgl-vertex-array.d.ts +67 -0
  111. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -0
  112. package/dist/adapter/resources/webgl-vertex-array.js +166 -0
  113. package/dist/adapter/resources/webgl-vertex-array.js.map +1 -0
  114. package/dist/adapter/webgl-canvas-context.d.ts +6 -7
  115. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  116. package/dist/adapter/webgl-canvas-context.js +10 -23
  117. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  118. package/dist/adapter/webgl-device.d.ts +74 -41
  119. package/dist/adapter/webgl-device.d.ts.map +1 -1
  120. package/dist/adapter/webgl-device.js +214 -128
  121. package/dist/adapter/webgl-device.js.map +1 -1
  122. package/dist/classic/accessor.d.ts +3 -3
  123. package/dist/classic/accessor.d.ts.map +1 -1
  124. package/dist/classic/accessor.js +23 -48
  125. package/dist/classic/accessor.js.map +1 -1
  126. package/dist/classic/{buffer.d.ts → buffer-with-accessor.d.ts} +16 -29
  127. package/dist/classic/buffer-with-accessor.d.ts.map +1 -0
  128. package/dist/classic/{buffer.js → buffer-with-accessor.js} +55 -125
  129. package/dist/classic/buffer-with-accessor.js.map +1 -0
  130. package/dist/classic/clear.d.ts +22 -0
  131. package/dist/classic/clear.d.ts.map +1 -0
  132. package/dist/classic/clear.js +88 -0
  133. package/dist/classic/clear.js.map +1 -0
  134. package/dist/classic/copy-and-blit.d.ts +62 -0
  135. package/dist/classic/copy-and-blit.d.ts.map +1 -0
  136. package/dist/classic/copy-and-blit.js +200 -0
  137. package/dist/classic/copy-and-blit.js.map +1 -0
  138. package/dist/classic/format-utils.d.ts +3 -0
  139. package/dist/classic/format-utils.d.ts.map +1 -0
  140. package/dist/classic/format-utils.js +38 -0
  141. package/dist/classic/format-utils.js.map +1 -0
  142. package/dist/classic/typed-array-utils.d.ts +15 -17
  143. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  144. package/dist/classic/typed-array-utils.js +1 -21
  145. package/dist/classic/typed-array-utils.js.map +1 -1
  146. package/dist/context/context/create-browser-context.d.ts +40 -0
  147. package/dist/context/context/create-browser-context.d.ts.map +1 -0
  148. package/dist/context/context/create-browser-context.js +53 -0
  149. package/dist/context/context/create-browser-context.js.map +1 -0
  150. package/dist/context/context/create-headless-context.d.ts +9 -0
  151. package/dist/context/context/create-headless-context.d.ts.map +1 -0
  152. package/dist/context/context/create-headless-context.js +42 -0
  153. package/dist/context/context/create-headless-context.js.map +1 -0
  154. package/dist/context/context/webgl-checks.d.ts.map +1 -1
  155. package/dist/context/context/webgl-checks.js +1 -4
  156. package/dist/context/context/webgl-checks.js.map +1 -1
  157. package/dist/context/debug/spector.d.ts +1 -2
  158. package/dist/context/debug/spector.d.ts.map +1 -1
  159. package/dist/context/debug/spector.js +8 -20
  160. package/dist/context/debug/spector.js.map +1 -1
  161. package/dist/context/debug/webgl-developer-tools.d.ts +2 -2
  162. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  163. package/dist/context/debug/webgl-developer-tools.js +16 -39
  164. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  165. package/dist/context/parameters/unified-parameter-api.d.ts +9 -8
  166. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  167. package/dist/context/parameters/unified-parameter-api.js +9 -19
  168. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  169. package/dist/context/parameters/webgl-parameter-tables.d.ts +105 -106
  170. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  171. package/dist/context/parameters/webgl-parameter-tables.js +18 -36
  172. package/dist/context/parameters/webgl-parameter-tables.js.map +1 -1
  173. package/dist/context/polyfill/context-data.d.ts +13 -0
  174. package/dist/context/polyfill/context-data.d.ts.map +1 -0
  175. package/dist/context/polyfill/context-data.js +12 -0
  176. package/dist/context/polyfill/context-data.js.map +1 -0
  177. package/dist/context/polyfill/get-parameter-polyfill.d.ts +1 -1
  178. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +1 -1
  179. package/dist/context/polyfill/get-parameter-polyfill.js +4 -9
  180. package/dist/context/polyfill/get-parameter-polyfill.js.map +1 -1
  181. package/dist/context/polyfill/polyfill-context.d.ts.map +1 -1
  182. package/dist/context/polyfill/polyfill-context.js +22 -30
  183. package/dist/context/polyfill/polyfill-context.js.map +1 -1
  184. package/dist/context/polyfill/polyfill-table.d.ts +8 -8
  185. package/dist/context/polyfill/polyfill-table.d.ts.map +1 -1
  186. package/dist/context/polyfill/polyfill-table.js +10 -32
  187. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  188. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +1 -1
  189. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -70
  190. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +1 -1
  191. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  192. package/dist/context/state-tracker/deep-array-equal.js +0 -4
  193. package/dist/context/state-tracker/deep-array-equal.js.map +1 -1
  194. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  195. package/dist/context/state-tracker/track-context-state.js +26 -62
  196. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  197. package/dist/context/state-tracker/with-parameters.d.ts +2 -1
  198. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  199. package/dist/context/state-tracker/with-parameters.js +8 -10
  200. package/dist/context/state-tracker/with-parameters.js.map +1 -1
  201. package/dist/dist.dev.js +10390 -0
  202. package/dist/index.cjs +6615 -0
  203. package/dist/index.d.ts +27 -24
  204. package/dist/index.d.ts.map +1 -1
  205. package/dist/index.js +27 -26
  206. package/dist/index.js.map +1 -1
  207. package/dist/types.d.ts +3 -1
  208. package/dist/types.d.ts.map +1 -1
  209. package/dist/types.js.map +1 -1
  210. package/dist.min.js +37 -0
  211. package/package.json +21 -9
  212. package/src/adapter/converters/device-parameters.ts +124 -36
  213. package/src/adapter/converters/sampler-parameters.ts +22 -9
  214. package/src/adapter/converters/shader-formats.ts +44 -0
  215. package/src/adapter/converters/texture-formats.ts +267 -194
  216. package/src/adapter/converters/vertex-formats.ts +71 -10
  217. package/src/adapter/device-helpers/device-features.ts +13 -3
  218. package/src/adapter/device-helpers/device-limits.ts +5 -3
  219. package/src/adapter/device-helpers/get-device-info.ts +17 -10
  220. package/src/adapter/device-helpers/is-old-ie.ts +3 -0
  221. package/src/adapter/helpers/{uniforms.ts → decode-webgl-types.ts} +39 -21
  222. package/src/adapter/helpers/get-shader-info.ts +41 -0
  223. package/src/adapter/helpers/get-shader-layout.ts +121 -146
  224. package/src/adapter/helpers/parse-shader-compiler-log.ts +4 -2
  225. package/src/adapter/helpers/set-uniform.ts +39 -35
  226. package/src/adapter/helpers/{attribute-utils.ts → webgl-topology-utils.ts} +7 -5
  227. package/src/adapter/objects/constants-to-keys.ts +6 -25
  228. package/src/adapter/objects/webgl-renderbuffer.ts +43 -37
  229. package/src/adapter/objects/webgl-resource.ts +16 -23
  230. package/src/adapter/resources/webgl-buffer.ts +59 -58
  231. package/src/adapter/resources/webgl-command-buffer.ts +333 -25
  232. package/src/adapter/resources/webgl-command-encoder.ts +20 -12
  233. package/src/adapter/resources/webgl-external-texture.ts +5 -2
  234. package/src/adapter/resources/webgl-framebuffer.ts +89 -133
  235. package/src/adapter/resources/webgl-render-pass.ts +160 -4
  236. package/src/adapter/resources/webgl-render-pipeline.ts +254 -174
  237. package/src/adapter/resources/webgl-sampler.ts +15 -9
  238. package/src/adapter/resources/webgl-shader.ts +14 -11
  239. package/src/adapter/resources/webgl-texture.ts +120 -90
  240. package/src/adapter/resources/webgl-vertex-array.ts +279 -0
  241. package/src/adapter/webgl-canvas-context.ts +16 -14
  242. package/src/adapter/webgl-device.ts +321 -78
  243. package/src/classic/accessor.ts +7 -17
  244. package/src/classic/{buffer.ts → buffer-with-accessor.ts} +68 -76
  245. package/src/classic/clear.ts +113 -0
  246. package/src/classic/copy-and-blit.ts +314 -0
  247. package/src/classic/format-utils.ts +46 -0
  248. package/src/classic/typed-array-utils.ts +19 -27
  249. package/src/context/context/create-browser-context.ts +140 -0
  250. package/src/context/context/create-headless-context.ts +51 -0
  251. package/src/context/context/webgl-checks.ts +3 -1
  252. package/src/context/debug/spector.ts +9 -6
  253. package/src/context/debug/webgl-developer-tools.ts +23 -15
  254. package/src/context/parameters/unified-parameter-api.ts +23 -14
  255. package/src/context/parameters/webgl-parameter-tables.ts +120 -98
  256. package/src/context/polyfill/context-data.ts +30 -0
  257. package/src/context/polyfill/get-parameter-polyfill.ts +11 -7
  258. package/src/context/polyfill/polyfill-context.ts +10 -9
  259. package/src/context/polyfill/polyfill-table.ts +21 -16
  260. package/src/context/polyfill/polyfill-vertex-array-object.ts +5 -0
  261. package/src/context/state-tracker/deep-array-equal.ts +2 -0
  262. package/src/context/state-tracker/track-context-state.ts +20 -16
  263. package/src/context/state-tracker/with-parameters.ts +13 -4
  264. package/src/index.ts +69 -35
  265. package/src/types.ts +5 -0
  266. package/dist/adapter/converters/renderbuffer-formats.d.ts +0 -16
  267. package/dist/adapter/converters/renderbuffer-formats.d.ts.map +0 -1
  268. package/dist/adapter/converters/renderbuffer-formats.js +0 -185
  269. package/dist/adapter/converters/renderbuffer-formats.js.map +0 -1
  270. package/dist/adapter/helpers/attribute-utils.d.ts +0 -11
  271. package/dist/adapter/helpers/attribute-utils.d.ts.map +0 -1
  272. package/dist/adapter/helpers/attribute-utils.js.map +0 -1
  273. package/dist/adapter/helpers/uniforms.d.ts +0 -26
  274. package/dist/adapter/helpers/uniforms.d.ts.map +0 -1
  275. package/dist/adapter/helpers/uniforms.js.map +0 -1
  276. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +0 -27
  277. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +0 -1
  278. package/dist/adapter/objects/webgl-vertex-array-object.js +0 -84
  279. package/dist/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  280. package/dist/bundle.d.ts +0 -2
  281. package/dist/bundle.d.ts.map +0 -1
  282. package/dist/bundle.js +0 -5
  283. package/dist/bundle.js.map +0 -1
  284. package/dist/classic/buffer.d.ts.map +0 -1
  285. package/dist/classic/buffer.js.map +0 -1
  286. package/dist/context/context/context-state.d.ts +0 -18
  287. package/dist/context/context/context-state.d.ts.map +0 -1
  288. package/dist/context/context/context-state.js +0 -26
  289. package/dist/context/context/context-state.js.map +0 -1
  290. package/dist/context/context/create-context.d.ts +0 -41
  291. package/dist/context/context/create-context.d.ts.map +0 -1
  292. package/dist/context/context/create-context.js +0 -49
  293. package/dist/context/context/create-context.js.map +0 -1
  294. package/dist/context/context/device-pixels.d.ts +0 -25
  295. package/dist/context/context/device-pixels.d.ts.map +0 -1
  296. package/dist/context/context/device-pixels.js +0 -98
  297. package/dist/context/context/device-pixels.js.map +0 -1
  298. package/dist/es5/adapter/converters/device-parameters.js +0 -170
  299. package/dist/es5/adapter/converters/device-parameters.js.map +0 -1
  300. package/dist/es5/adapter/converters/renderbuffer-formats.js +0 -163
  301. package/dist/es5/adapter/converters/renderbuffer-formats.js.map +0 -1
  302. package/dist/es5/adapter/converters/sampler-parameters.js +0 -226
  303. package/dist/es5/adapter/converters/sampler-parameters.js.map +0 -1
  304. package/dist/es5/adapter/converters/texture-formats.js +0 -1031
  305. package/dist/es5/adapter/converters/texture-formats.js.map +0 -1
  306. package/dist/es5/adapter/converters/vertex-formats.js +0 -45
  307. package/dist/es5/adapter/converters/vertex-formats.js.map +0 -1
  308. package/dist/es5/adapter/device-helpers/device-features.js +0 -144
  309. package/dist/es5/adapter/device-helpers/device-features.js.map +0 -1
  310. package/dist/es5/adapter/device-helpers/device-limits.js +0 -64
  311. package/dist/es5/adapter/device-helpers/device-limits.js.map +0 -1
  312. package/dist/es5/adapter/device-helpers/get-device-info.js +0 -55
  313. package/dist/es5/adapter/device-helpers/get-device-info.js.map +0 -1
  314. package/dist/es5/adapter/device-helpers/is-old-ie.js +0 -16
  315. package/dist/es5/adapter/device-helpers/is-old-ie.js.map +0 -1
  316. package/dist/es5/adapter/helpers/attribute-utils.js +0 -91
  317. package/dist/es5/adapter/helpers/attribute-utils.js.map +0 -1
  318. package/dist/es5/adapter/helpers/get-shader-layout.js +0 -371
  319. package/dist/es5/adapter/helpers/get-shader-layout.js.map +0 -1
  320. package/dist/es5/adapter/helpers/parse-shader-compiler-log.js +0 -72
  321. package/dist/es5/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  322. package/dist/es5/adapter/helpers/set-uniform.js +0 -125
  323. package/dist/es5/adapter/helpers/set-uniform.js.map +0 -1
  324. package/dist/es5/adapter/helpers/uniforms.js +0 -112
  325. package/dist/es5/adapter/helpers/uniforms.js.map +0 -1
  326. package/dist/es5/adapter/objects/constants-to-keys.js +0 -54
  327. package/dist/es5/adapter/objects/constants-to-keys.js.map +0 -1
  328. package/dist/es5/adapter/objects/webgl-renderbuffer.js +0 -150
  329. package/dist/es5/adapter/objects/webgl-renderbuffer.js.map +0 -1
  330. package/dist/es5/adapter/objects/webgl-resource.js +0 -292
  331. package/dist/es5/adapter/objects/webgl-resource.js.map +0 -1
  332. package/dist/es5/adapter/objects/webgl-vertex-array-object.js +0 -137
  333. package/dist/es5/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  334. package/dist/es5/adapter/resources/webgl-buffer.js +0 -243
  335. package/dist/es5/adapter/resources/webgl-buffer.js.map +0 -1
  336. package/dist/es5/adapter/resources/webgl-command-buffer.js +0 -96
  337. package/dist/es5/adapter/resources/webgl-command-buffer.js.map +0 -1
  338. package/dist/es5/adapter/resources/webgl-command-encoder.js +0 -98
  339. package/dist/es5/adapter/resources/webgl-command-encoder.js.map +0 -1
  340. package/dist/es5/adapter/resources/webgl-external-texture.js +0 -2
  341. package/dist/es5/adapter/resources/webgl-external-texture.js.map +0 -1
  342. package/dist/es5/adapter/resources/webgl-framebuffer.js +0 -345
  343. package/dist/es5/adapter/resources/webgl-framebuffer.js.map +0 -1
  344. package/dist/es5/adapter/resources/webgl-render-pass.js +0 -61
  345. package/dist/es5/adapter/resources/webgl-render-pass.js.map +0 -1
  346. package/dist/es5/adapter/resources/webgl-render-pipeline.js +0 -505
  347. package/dist/es5/adapter/resources/webgl-render-pipeline.js.map +0 -1
  348. package/dist/es5/adapter/resources/webgl-sampler.js +0 -96
  349. package/dist/es5/adapter/resources/webgl-sampler.js.map +0 -1
  350. package/dist/es5/adapter/resources/webgl-shader.js +0 -149
  351. package/dist/es5/adapter/resources/webgl-shader.js.map +0 -1
  352. package/dist/es5/adapter/resources/webgl-texture.js +0 -986
  353. package/dist/es5/adapter/resources/webgl-texture.js.map +0 -1
  354. package/dist/es5/adapter/webgl-canvas-context.js +0 -97
  355. package/dist/es5/adapter/webgl-canvas-context.js.map +0 -1
  356. package/dist/es5/adapter/webgl-device.js +0 -399
  357. package/dist/es5/adapter/webgl-device.js.map +0 -1
  358. package/dist/es5/bundle.js +0 -7
  359. package/dist/es5/bundle.js.map +0 -1
  360. package/dist/es5/classic/accessor.js +0 -181
  361. package/dist/es5/classic/accessor.js.map +0 -1
  362. package/dist/es5/classic/buffer.js +0 -470
  363. package/dist/es5/classic/buffer.js.map +0 -1
  364. package/dist/es5/classic/typed-array-utils.js +0 -126
  365. package/dist/es5/classic/typed-array-utils.js.map +0 -1
  366. package/dist/es5/context/context/context-state.js +0 -31
  367. package/dist/es5/context/context/context-state.js.map +0 -1
  368. package/dist/es5/context/context/create-context.js +0 -69
  369. package/dist/es5/context/context/create-context.js.map +0 -1
  370. package/dist/es5/context/context/device-pixels.js +0 -115
  371. package/dist/es5/context/context/device-pixels.js.map +0 -1
  372. package/dist/es5/context/context/webgl-checks.js +0 -54
  373. package/dist/es5/context/context/webgl-checks.js.map +0 -1
  374. package/dist/es5/context/debug/spector.js +0 -133
  375. package/dist/es5/context/debug/spector.js.map +0 -1
  376. package/dist/es5/context/debug/webgl-developer-tools.js +0 -198
  377. package/dist/es5/context/debug/webgl-developer-tools.js.map +0 -1
  378. package/dist/es5/context/parameters/unified-parameter-api.js +0 -97
  379. package/dist/es5/context/parameters/unified-parameter-api.js.map +0 -1
  380. package/dist/es5/context/parameters/webgl-parameter-tables.js +0 -392
  381. package/dist/es5/context/parameters/webgl-parameter-tables.js.map +0 -1
  382. package/dist/es5/context/polyfill/get-parameter-polyfill.js +0 -81
  383. package/dist/es5/context/polyfill/get-parameter-polyfill.js.map +0 -1
  384. package/dist/es5/context/polyfill/polyfill-context.js +0 -135
  385. package/dist/es5/context/polyfill/polyfill-context.js.map +0 -1
  386. package/dist/es5/context/polyfill/polyfill-table.js +0 -166
  387. package/dist/es5/context/polyfill/polyfill-table.js.map +0 -1
  388. package/dist/es5/context/polyfill/polyfill-vertex-array-object.js +0 -341
  389. package/dist/es5/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  390. package/dist/es5/context/state-tracker/deep-array-equal.js +0 -28
  391. package/dist/es5/context/state-tracker/deep-array-equal.js.map +0 -1
  392. package/dist/es5/context/state-tracker/track-context-state.js +0 -211
  393. package/dist/es5/context/state-tracker/track-context-state.js.map +0 -1
  394. package/dist/es5/context/state-tracker/with-parameters.js +0 -44
  395. package/dist/es5/context/state-tracker/with-parameters.js.map +0 -1
  396. package/dist/es5/index.js +0 -276
  397. package/dist/es5/index.js.map +0 -1
  398. package/dist/es5/init.js +0 -10
  399. package/dist/es5/init.js.map +0 -1
  400. package/dist/es5/types/webgl.js +0 -6
  401. package/dist/es5/types/webgl.js.map +0 -1
  402. package/dist/es5/types.js +0 -2
  403. package/dist/es5/types.js.map +0 -1
  404. package/dist/esm/adapter/converters/device-parameters.js +0 -155
  405. package/dist/esm/adapter/converters/device-parameters.js.map +0 -1
  406. package/dist/esm/adapter/converters/renderbuffer-formats.js +0 -185
  407. package/dist/esm/adapter/converters/renderbuffer-formats.js.map +0 -1
  408. package/dist/esm/adapter/converters/sampler-parameters.js +0 -208
  409. package/dist/esm/adapter/converters/sampler-parameters.js.map +0 -1
  410. package/dist/esm/adapter/converters/texture-formats.js +0 -954
  411. package/dist/esm/adapter/converters/texture-formats.js.map +0 -1
  412. package/dist/esm/adapter/converters/vertex-formats.js +0 -35
  413. package/dist/esm/adapter/converters/vertex-formats.js.map +0 -1
  414. package/dist/esm/adapter/device-helpers/device-features.js +0 -102
  415. package/dist/esm/adapter/device-helpers/device-features.js.map +0 -1
  416. package/dist/esm/adapter/device-helpers/device-limits.js +0 -91
  417. package/dist/esm/adapter/device-helpers/device-limits.js.map +0 -1
  418. package/dist/esm/adapter/device-helpers/get-device-info.js +0 -44
  419. package/dist/esm/adapter/device-helpers/get-device-info.js.map +0 -1
  420. package/dist/esm/adapter/device-helpers/is-old-ie.js +0 -8
  421. package/dist/esm/adapter/device-helpers/is-old-ie.js.map +0 -1
  422. package/dist/esm/adapter/helpers/attribute-utils.js +0 -81
  423. package/dist/esm/adapter/helpers/attribute-utils.js.map +0 -1
  424. package/dist/esm/adapter/helpers/get-shader-layout.js +0 -306
  425. package/dist/esm/adapter/helpers/get-shader-layout.js.map +0 -1
  426. package/dist/esm/adapter/helpers/parse-shader-compiler-log.js +0 -37
  427. package/dist/esm/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  428. package/dist/esm/adapter/helpers/set-uniform.js +0 -115
  429. package/dist/esm/adapter/helpers/set-uniform.js.map +0 -1
  430. package/dist/esm/adapter/helpers/uniforms.js +0 -99
  431. package/dist/esm/adapter/helpers/uniforms.js.map +0 -1
  432. package/dist/esm/adapter/objects/constants-to-keys.js +0 -42
  433. package/dist/esm/adapter/objects/constants-to-keys.js.map +0 -1
  434. package/dist/esm/adapter/objects/webgl-renderbuffer.js +0 -94
  435. package/dist/esm/adapter/objects/webgl-renderbuffer.js.map +0 -1
  436. package/dist/esm/adapter/objects/webgl-resource.js +0 -216
  437. package/dist/esm/adapter/objects/webgl-resource.js.map +0 -1
  438. package/dist/esm/adapter/objects/webgl-vertex-array-object.js +0 -84
  439. package/dist/esm/adapter/objects/webgl-vertex-array-object.js.map +0 -1
  440. package/dist/esm/adapter/resources/webgl-buffer.js +0 -164
  441. package/dist/esm/adapter/resources/webgl-buffer.js.map +0 -1
  442. package/dist/esm/adapter/resources/webgl-command-buffer.js +0 -65
  443. package/dist/esm/adapter/resources/webgl-command-buffer.js.map +0 -1
  444. package/dist/esm/adapter/resources/webgl-command-encoder.js +0 -53
  445. package/dist/esm/adapter/resources/webgl-command-encoder.js.map +0 -1
  446. package/dist/esm/adapter/resources/webgl-external-texture.js +0 -2
  447. package/dist/esm/adapter/resources/webgl-external-texture.js.map +0 -1
  448. package/dist/esm/adapter/resources/webgl-framebuffer.js +0 -265
  449. package/dist/esm/adapter/resources/webgl-framebuffer.js.map +0 -1
  450. package/dist/esm/adapter/resources/webgl-render-pass.js +0 -19
  451. package/dist/esm/adapter/resources/webgl-render-pass.js.map +0 -1
  452. package/dist/esm/adapter/resources/webgl-render-pipeline.js +0 -400
  453. package/dist/esm/adapter/resources/webgl-render-pipeline.js.map +0 -1
  454. package/dist/esm/adapter/resources/webgl-sampler.js +0 -50
  455. package/dist/esm/adapter/resources/webgl-sampler.js.map +0 -1
  456. package/dist/esm/adapter/resources/webgl-shader.js +0 -75
  457. package/dist/esm/adapter/resources/webgl-shader.js.map +0 -1
  458. package/dist/esm/adapter/resources/webgl-texture.js +0 -831
  459. package/dist/esm/adapter/resources/webgl-texture.js.map +0 -1
  460. package/dist/esm/adapter/webgl-canvas-context.js +0 -54
  461. package/dist/esm/adapter/webgl-canvas-context.js.map +0 -1
  462. package/dist/esm/adapter/webgl-device.js +0 -280
  463. package/dist/esm/adapter/webgl-device.js.map +0 -1
  464. package/dist/esm/bundle.js +0 -5
  465. package/dist/esm/bundle.js.map +0 -1
  466. package/dist/esm/classic/accessor.js +0 -144
  467. package/dist/esm/classic/accessor.js.map +0 -1
  468. package/dist/esm/classic/buffer.js +0 -384
  469. package/dist/esm/classic/buffer.js.map +0 -1
  470. package/dist/esm/classic/typed-array-utils.js +0 -112
  471. package/dist/esm/classic/typed-array-utils.js.map +0 -1
  472. package/dist/esm/context/context/context-state.js +0 -26
  473. package/dist/esm/context/context/context-state.js.map +0 -1
  474. package/dist/esm/context/context/create-context.js +0 -49
  475. package/dist/esm/context/context/create-context.js.map +0 -1
  476. package/dist/esm/context/context/device-pixels.js +0 -98
  477. package/dist/esm/context/context/device-pixels.js.map +0 -1
  478. package/dist/esm/context/context/webgl-checks.js +0 -34
  479. package/dist/esm/context/context/webgl-checks.js.map +0 -1
  480. package/dist/esm/context/debug/spector.js +0 -76
  481. package/dist/esm/context/debug/spector.js.map +0 -1
  482. package/dist/esm/context/debug/webgl-developer-tools.js +0 -121
  483. package/dist/esm/context/debug/webgl-developer-tools.js.map +0 -1
  484. package/dist/esm/context/parameters/unified-parameter-api.js +0 -65
  485. package/dist/esm/context/parameters/unified-parameter-api.js.map +0 -1
  486. package/dist/esm/context/parameters/webgl-parameter-tables.js +0 -445
  487. package/dist/esm/context/parameters/webgl-parameter-tables.js.map +0 -1
  488. package/dist/esm/context/polyfill/get-parameter-polyfill.js +0 -91
  489. package/dist/esm/context/polyfill/get-parameter-polyfill.js.map +0 -1
  490. package/dist/esm/context/polyfill/polyfill-context.js +0 -92
  491. package/dist/esm/context/polyfill/polyfill-context.js.map +0 -1
  492. package/dist/esm/context/polyfill/polyfill-table.js +0 -160
  493. package/dist/esm/context/polyfill/polyfill-table.js.map +0 -1
  494. package/dist/esm/context/polyfill/polyfill-vertex-array-object.js +0 -335
  495. package/dist/esm/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  496. package/dist/esm/context/state-tracker/deep-array-equal.js +0 -21
  497. package/dist/esm/context/state-tracker/deep-array-equal.js.map +0 -1
  498. package/dist/esm/context/state-tracker/track-context-state.js +0 -183
  499. package/dist/esm/context/state-tracker/track-context-state.js.map +0 -1
  500. package/dist/esm/context/state-tracker/with-parameters.js +0 -36
  501. package/dist/esm/context/state-tracker/with-parameters.js.map +0 -1
  502. package/dist/esm/index.js +0 -27
  503. package/dist/esm/index.js.map +0 -1
  504. package/dist/esm/init.js +0 -4
  505. package/dist/esm/init.js.map +0 -1
  506. package/dist/esm/types/webgl.js +0 -2
  507. package/dist/esm/types/webgl.js.map +0 -1
  508. package/dist/esm/types.js +0 -2
  509. package/dist/esm/types.js.map +0 -1
  510. package/dist/init.d.ts +0 -2
  511. package/dist/init.d.ts.map +0 -1
  512. package/dist/init.js +0 -4
  513. package/dist/init.js.map +0 -1
  514. package/dist/types/webgl.d.ts +0 -144
  515. package/dist/types/webgl.d.ts.map +0 -1
  516. package/dist/types/webgl.js +0 -2
  517. package/dist/types/webgl.js.map +0 -1
  518. package/src/adapter/converters/renderbuffer-formats.ts +0 -92
  519. package/src/adapter/objects/webgl-vertex-array-object.ts +0 -111
  520. package/src/bundle.ts +0 -4
  521. package/src/context/context/context-state.ts +0 -41
  522. package/src/context/context/create-context.ts +0 -110
  523. package/src/context/context/device-pixels.ts +0 -152
  524. package/src/init.ts +0 -4
  525. package/src/types/webgl.ts +0 -283
@@ -0,0 +1,200 @@
1
+ import { assert, Texture, Framebuffer } from '@luma.gl/core';
2
+ import { GL } from '@luma.gl/constants';
3
+ import { BufferWithAccessor as Buffer } from "./buffer-with-accessor.js";
4
+ import { withGLParameters } from "../context/state-tracker/with-parameters.js";
5
+ import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
6
+ import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
7
+ export function readPixelsToArray(source, options) {
8
+ var _framebuffer$colorAtt;
9
+ const {
10
+ sourceX = 0,
11
+ sourceY = 0,
12
+ sourceFormat = GL.RGBA,
13
+ sourceAttachment = GL.COLOR_ATTACHMENT0
14
+ } = options || {};
15
+ let {
16
+ target = null,
17
+ sourceWidth,
18
+ sourceHeight,
19
+ sourceType
20
+ } = options || {};
21
+ const {
22
+ framebuffer,
23
+ deleteFramebuffer
24
+ } = getFramebuffer(source);
25
+ assert(framebuffer);
26
+ const {
27
+ gl,
28
+ handle
29
+ } = framebuffer;
30
+ sourceWidth = sourceWidth || framebuffer.width;
31
+ sourceHeight = sourceHeight || framebuffer.height;
32
+ const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
33
+ sourceType = sourceType || ((_framebuffer$colorAtt = framebuffer.colorAttachments[attachment]) === null || _framebuffer$colorAtt === void 0 ? void 0 : _framebuffer$colorAtt.type) || GL.UNSIGNED_BYTE;
34
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
35
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
36
+ const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
37
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
38
+ gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
39
+ if (deleteFramebuffer) {
40
+ framebuffer.destroy();
41
+ }
42
+ return target;
43
+ }
44
+ export function readPixelsToBuffer(source, options) {
45
+ const {
46
+ sourceX = 0,
47
+ sourceY = 0,
48
+ sourceFormat = GL.RGBA,
49
+ targetByteOffset = 0
50
+ } = options || {};
51
+ let {
52
+ target,
53
+ sourceWidth,
54
+ sourceHeight,
55
+ sourceType
56
+ } = options || {};
57
+ const {
58
+ framebuffer,
59
+ deleteFramebuffer
60
+ } = getFramebuffer(source);
61
+ assert(framebuffer);
62
+ sourceWidth = sourceWidth || framebuffer.width;
63
+ sourceHeight = sourceHeight || framebuffer.height;
64
+ const webglFramebuffer = framebuffer;
65
+ const gl2 = webglFramebuffer.device.assertWebGL2();
66
+ sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);
67
+ if (!target) {
68
+ const components = glFormatToComponents(sourceFormat);
69
+ const byteCount = glTypeToBytes(sourceType);
70
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
71
+ target = new Buffer(gl2, {
72
+ byteLength,
73
+ accessor: {
74
+ type: sourceType,
75
+ size: components
76
+ }
77
+ });
78
+ }
79
+ target.bind({
80
+ glTarget: GL.PIXEL_PACK_BUFFER
81
+ });
82
+ withGLParameters(gl2, {
83
+ framebuffer
84
+ }, () => {
85
+ gl2.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, targetByteOffset);
86
+ });
87
+ target.unbind({
88
+ glTarget: GL.PIXEL_PACK_BUFFER
89
+ });
90
+ if (deleteFramebuffer) {
91
+ framebuffer.destroy();
92
+ }
93
+ return target;
94
+ }
95
+ export function copyToTexture(source, target, options) {
96
+ const {
97
+ sourceX = 0,
98
+ sourceY = 0,
99
+ targetMipmaplevel = 0,
100
+ targetInternalFormat = GL.RGBA
101
+ } = options || {};
102
+ let {
103
+ targetX,
104
+ targetY,
105
+ targetZ,
106
+ width,
107
+ height
108
+ } = options || {};
109
+ const {
110
+ framebuffer,
111
+ deleteFramebuffer
112
+ } = getFramebuffer(source);
113
+ assert(framebuffer);
114
+ const webglFramebuffer = framebuffer;
115
+ const {
116
+ device,
117
+ handle
118
+ } = webglFramebuffer;
119
+ const isSubCopy = typeof targetX !== 'undefined' || typeof targetY !== 'undefined' || typeof targetZ !== 'undefined';
120
+ targetX = targetX || 0;
121
+ targetY = targetY || 0;
122
+ targetZ = targetZ || 0;
123
+ const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);
124
+ assert(target);
125
+ let texture = null;
126
+ let textureTarget;
127
+ if (target instanceof Texture) {
128
+ texture = target;
129
+ width = Number.isFinite(width) ? width : texture.width;
130
+ height = Number.isFinite(height) ? height : texture.height;
131
+ texture.bind(0);
132
+ textureTarget = texture.target;
133
+ } else {
134
+ textureTarget = target;
135
+ }
136
+ if (!isSubCopy) {
137
+ device.gl.copyTexImage2D(textureTarget, targetMipmaplevel, targetInternalFormat, sourceX, sourceY, width, height, 0);
138
+ } else {
139
+ switch (textureTarget) {
140
+ case GL.TEXTURE_2D:
141
+ case GL.TEXTURE_CUBE_MAP:
142
+ device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
143
+ break;
144
+ case GL.TEXTURE_2D_ARRAY:
145
+ case GL.TEXTURE_3D:
146
+ device.assertWebGL2();
147
+ device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
148
+ break;
149
+ default:
150
+ }
151
+ }
152
+ if (texture) {
153
+ texture.unbind();
154
+ }
155
+ device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
156
+ if (deleteFramebuffer) {
157
+ framebuffer.destroy();
158
+ }
159
+ return texture;
160
+ }
161
+ function getFramebuffer(source) {
162
+ if (!(source instanceof Framebuffer)) {
163
+ return {
164
+ framebuffer: toFramebuffer(source),
165
+ deleteFramebuffer: true
166
+ };
167
+ }
168
+ return {
169
+ framebuffer: source,
170
+ deleteFramebuffer: false
171
+ };
172
+ }
173
+ export function toFramebuffer(texture, props) {
174
+ const {
175
+ device,
176
+ width,
177
+ height,
178
+ id
179
+ } = texture;
180
+ const framebuffer = device.createFramebuffer({
181
+ ...props,
182
+ id: `framebuffer-for-${id}`,
183
+ width,
184
+ height,
185
+ colorAttachments: [texture]
186
+ });
187
+ return framebuffer;
188
+ }
189
+ function getPixelArray(pixelArray, type, format, width, height) {
190
+ if (pixelArray) {
191
+ return pixelArray;
192
+ }
193
+ type = type || GL.UNSIGNED_BYTE;
194
+ const ArrayType = getTypedArrayFromGLType(type, {
195
+ clamped: false
196
+ });
197
+ const components = glFormatToComponents(format);
198
+ return new ArrayType(width * height * components);
199
+ }
200
+ //# sourceMappingURL=copy-and-blit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-and-blit.js","names":["assert","Texture","Framebuffer","GL","BufferWithAccessor","Buffer","withGLParameters","getGLTypeFromTypedArray","getTypedArrayFromGLType","glFormatToComponents","glTypeToBytes","readPixelsToArray","source","options","_framebuffer$colorAtt","sourceX","sourceY","sourceFormat","RGBA","sourceAttachment","COLOR_ATTACHMENT0","target","sourceWidth","sourceHeight","sourceType","framebuffer","deleteFramebuffer","getFramebuffer","gl","handle","width","height","attachment","colorAttachments","type","UNSIGNED_BYTE","getPixelArray","prevHandle","bindFramebuffer","FRAMEBUFFER","readPixels","destroy","readPixelsToBuffer","targetByteOffset","webglFramebuffer","gl2","device","assertWebGL2","components","byteCount","byteLength","accessor","size","bind","glTarget","PIXEL_PACK_BUFFER","unbind","copyToTexture","targetMipmaplevel","targetInternalFormat","targetX","targetY","targetZ","isSubCopy","texture","textureTarget","Number","isFinite","copyTexImage2D","TEXTURE_2D","TEXTURE_CUBE_MAP","copyTexSubImage2D","TEXTURE_2D_ARRAY","TEXTURE_3D","copyTexSubImage3D","toFramebuffer","props","id","createFramebuffer","pixelArray","format","ArrayType","clamped"],"sources":["../../src/classic/copy-and-blit.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\nimport {BufferWithAccessor as Buffer} from './buffer-with-accessor';\nimport {WEBGLTexture} from '../adapter/resources/webgl-texture';\nimport {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';\nimport {withGLParameters} from '../context/state-tracker/with-parameters';\nimport {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';\nimport {glFormatToComponents, glTypeToBytes} from './format-utils';\n\n/**\n * Copies data from a type or a Texture object into ArrayBuffer object.\n * App can provide targetPixelArray or have it auto allocated by this method\n * newly allocated by this method unless provided by app.\n * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read\n * @note Slow requires roundtrip to GPU\n *\n * @param source\n * @param options\n * @returns pixel array,\n */\nexport function readPixelsToArray(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n sourceAttachment?: number;\n target?: Uint8Array | Uint16Array | Float32Array;\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Uint8Array | Uint16Array | Float32Array {\n const {\n sourceX = 0,\n sourceY = 0,\n sourceFormat = GL.RGBA,\n sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer\n } = options || {};\n let {\n target = null,\n // following parameters are auto deduced if not provided\n sourceWidth,\n sourceHeight,\n sourceType\n } = options || {};\n\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n const {gl, handle} = framebuffer as WEBGLFramebuffer;\n sourceWidth = sourceWidth || framebuffer.width;\n sourceHeight = sourceHeight || framebuffer.height;\n\n // TODO - Set and unset gl.readBuffer\n // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {\n // sourceAttachment = GL.FRONT;\n // }\n\n const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;\n // assert(attachments[sourceAttachment]);\n\n // Deduce the type from color attachment if not provided.\n sourceType =\n sourceType ||\n (framebuffer.colorAttachments[attachment] as WEBGLTexture)?.type ||\n GL.UNSIGNED_BYTE;\n\n // Deduce type and allocated pixelArray if needed\n target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);\n\n // Pixel array available, if necessary, deduce type from it.\n sourceType = sourceType || getGLTypeFromTypedArray(target);\n\n const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, handle);\n gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);\n // @ts-expect-error\n gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n return target;\n}\n\n/**\n * Copies data from a Framebuffer or a Texture object into a Buffer object.\n * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.\n * @deprecated Use CommandEncoder\n * @param source\n * @param options\n */\nexport function readPixelsToBuffer(\n source: Framebuffer | Texture,\n options?: {\n sourceX?: number;\n sourceY?: number;\n sourceFormat?: number;\n target?: Buffer; // A new Buffer object is created when not provided.\n targetByteOffset?: number; // byte offset in buffer object\n // following parameters are auto deduced if not provided\n sourceWidth?: number;\n sourceHeight?: number;\n sourceType?: number;\n }\n): Buffer {\n const {sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {};\n // following parameters are auto deduced if not provided\n let {target, sourceWidth, sourceHeight, sourceType} = options || {};\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n sourceWidth = sourceWidth || framebuffer.width;\n sourceHeight = sourceHeight || framebuffer.height;\n\n // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature\n const webglFramebuffer = framebuffer as WEBGLFramebuffer;\n const gl2 = webglFramebuffer.device.assertWebGL2();\n\n // deduce type if not available.\n sourceType = sourceType || (target ? target.type : GL.UNSIGNED_BYTE);\n\n if (!target) {\n // Create new buffer with enough size\n const components = glFormatToComponents(sourceFormat);\n const byteCount = glTypeToBytes(sourceType);\n const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;\n target = new Buffer(gl2, {byteLength, accessor: {type: sourceType, size: components}});\n }\n\n target.bind({glTarget: GL.PIXEL_PACK_BUFFER});\n withGLParameters(gl2, {framebuffer}, () => {\n gl2.readPixels(\n sourceX,\n sourceY,\n sourceWidth,\n sourceHeight,\n sourceFormat,\n sourceType,\n targetByteOffset\n );\n });\n target.unbind({glTarget: GL.PIXEL_PACK_BUFFER});\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n\n return target;\n}\n\n/**\n * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)\n * @deprecated Use CommandEncoder\n */\n// eslint-disable-next-line complexity, max-statements\nexport function copyToTexture(\n source: Framebuffer | Texture,\n target: Texture | GL,\n options?: {\n sourceX?: number;\n sourceY?: number;\n\n targetX?: number;\n targetY?: number;\n targetZ?: number;\n targetMipmaplevel?: number;\n targetInternalFormat?: number;\n\n width?: number; // defaults to target width\n height?: number; // defaults to target height\n }\n): Texture {\n const {\n sourceX = 0,\n sourceY = 0,\n // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer\n targetMipmaplevel = 0,\n targetInternalFormat = GL.RGBA\n } = options || {};\n let {\n targetX,\n targetY,\n targetZ,\n width, // defaults to target width\n height // defaults to target height\n } = options || {};\n\n const {framebuffer, deleteFramebuffer} = getFramebuffer(source);\n assert(framebuffer);\n const webglFramebuffer = framebuffer as WEBGLFramebuffer;\n const {device, handle} = webglFramebuffer;\n const isSubCopy =\n typeof targetX !== 'undefined' ||\n typeof targetY !== 'undefined' ||\n typeof targetZ !== 'undefined';\n targetX = targetX || 0;\n targetY = targetY || 0;\n targetZ = targetZ || 0;\n const prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, handle);\n // TODO - support gl.readBuffer (WebGL2 only)\n // const prevBuffer = gl.readBuffer(attachment);\n assert(target);\n let texture = null;\n let textureTarget: GL;\n if (target instanceof Texture) {\n texture = target;\n width = Number.isFinite(width) ? width : texture.width;\n height = Number.isFinite(height) ? height : texture.height;\n texture.bind(0);\n textureTarget = texture.target;\n } else {\n textureTarget = target;\n }\n\n if (!isSubCopy) {\n device.gl.copyTexImage2D(\n textureTarget,\n targetMipmaplevel,\n targetInternalFormat,\n sourceX,\n sourceY,\n width,\n height,\n 0 /* border must be 0 */\n );\n } else {\n switch (textureTarget) {\n case GL.TEXTURE_2D:\n case GL.TEXTURE_CUBE_MAP:\n device.gl.copyTexSubImage2D(\n textureTarget,\n targetMipmaplevel,\n targetX,\n targetY,\n sourceX,\n sourceY,\n width,\n height\n );\n break;\n case GL.TEXTURE_2D_ARRAY:\n case GL.TEXTURE_3D:\n device.assertWebGL2();\n device.gl2.copyTexSubImage3D(\n textureTarget,\n targetMipmaplevel,\n targetX,\n targetY,\n targetZ,\n sourceX,\n sourceY,\n width,\n height\n );\n break;\n default:\n }\n }\n if (texture) {\n texture.unbind();\n }\n // @ts-expect-error\n device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);\n if (deleteFramebuffer) {\n framebuffer.destroy();\n }\n return texture;\n}\n\nfunction getFramebuffer(source: Texture | Framebuffer): {\n framebuffer: Framebuffer;\n deleteFramebuffer: boolean;\n} {\n if (!(source instanceof Framebuffer)) {\n return {framebuffer: toFramebuffer(source), deleteFramebuffer: true};\n }\n return {framebuffer: source, deleteFramebuffer: false};\n}\n\n/**\n * Wraps a given texture into a framebuffer object, that can be further used\n * to read data from the texture object.\n */\nexport function toFramebuffer(texture: Texture, props?: FramebufferProps): Framebuffer {\n const {device, width, height, id} = texture;\n const framebuffer = device.createFramebuffer({\n ...props,\n id: `framebuffer-for-${id}`,\n width,\n height,\n colorAttachments: [texture]\n });\n return framebuffer;\n}\n\nfunction getPixelArray(\n pixelArray,\n type,\n format,\n width: number,\n height: number\n): Uint8Array | Uint16Array | Float32Array {\n if (pixelArray) {\n return pixelArray;\n }\n // Allocate pixel array if not already available, using supplied type\n type = type || GL.UNSIGNED_BYTE;\n const ArrayType = getTypedArrayFromGLType(type, {clamped: false});\n const components = glFormatToComponents(format);\n // TODO - check for composite type (components = 1).\n return new ArrayType(width * height * components) as Uint8Array | Uint16Array | Float32Array;\n}\n"],"mappings":"AAGA,SAAQA,MAAM,EAAEC,OAAO,EAAEC,WAAW,QAAyB,eAAe;AAC5E,SAAQC,EAAE,QAAO,oBAAoB;AAAC,SAE9BC,kBAAkB,IAAIC,MAAM;AAAA,SAG5BC,gBAAgB;AAAA,SAChBC,uBAAuB,EAAEC,uBAAuB;AAAA,SAChDC,oBAAoB,EAAEC,aAAa;AAa3C,OAAO,SAASC,iBAAiBA,CAC/BC,MAA6B,EAC7BC,OAUC,EACwC;EAAA,IAAAC,qBAAA;EACzC,MAAM;IACJC,OAAO,GAAG,CAAC;IACXC,OAAO,GAAG,CAAC;IACXC,YAAY,GAAGd,EAAE,CAACe,IAAI;IACtBC,gBAAgB,GAAGhB,EAAE,CAACiB;EACxB,CAAC,GAAGP,OAAO,IAAI,CAAC,CAAC;EACjB,IAAI;IACFQ,MAAM,GAAG,IAAI;IAEbC,WAAW;IACXC,YAAY;IACZC;EACF,CAAC,GAAGX,OAAO,IAAI,CAAC,CAAC;EAEjB,MAAM;IAACY,WAAW;IAAEC;EAAiB,CAAC,GAAGC,cAAc,CAACf,MAAM,CAAC;EAC/DZ,MAAM,CAACyB,WAAW,CAAC;EACnB,MAAM;IAACG,EAAE;IAAEC;EAAM,CAAC,GAAGJ,WAA+B;EACpDH,WAAW,GAAGA,WAAW,IAAIG,WAAW,CAACK,KAAK;EAC9CP,YAAY,GAAGA,YAAY,IAAIE,WAAW,CAACM,MAAM;EAOjD,MAAMC,UAAU,GAAGb,gBAAgB,GAAGhB,EAAE,CAACiB,iBAAiB;EAI1DI,UAAU,GACRA,UAAU,MAAAV,qBAAA,GACTW,WAAW,CAACQ,gBAAgB,CAACD,UAAU,CAAC,cAAAlB,qBAAA,uBAAzCA,qBAAA,CAA4DoB,IAAI,KAChE/B,EAAE,CAACgC,aAAa;EAGlBd,MAAM,GAAGe,aAAa,CA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AK;IAAEC,MAAM;IAAE8C;EAAE,CAAC,GAAGb,OAAO;EAC3C,MAAMvC,WAAW,GAAGqB,MAAM,CAACgC,iBAAiB,CAAC;IAC3C,GAAGF,KAAK;IACRC,EAAE,EAAG,mBAAkBA,EAAG,EAAC;IAC3B/C,KAAK;IACLC,MAAM;IACNE,gBAAgB,EAAE,CAAC+B,OAAO;EAC5B,CAAC,CAAC;EACF,OAAOvC,WAAW;AACpB;AAEA,SAASW,aAAaA,CACpB2C,UAAU,EACV7C,IAAI,EACJ8C,MAAM,EACNlD,KAAa,EACbC,MAAc,EAC2B;EACzC,IAAIgD,UAAU,EAAE;IACd,OAAOA,UAAU;EACnB;EAEA7C,IAAI,GAAGA,IAAI,IAAI/B,EAAE,CAACgC,aAAa;EAC/B,MAAM8C,SAAS,GAAGzE,uBAAuB,CAAC0B,IAAI,EAAE;IAACgD,OAAO,EAAE;EAAK,CAAC,CAAC;EACjE,MAAMlC,UAAU,GAAGvC,oBAAoB,CAACuE,MAAM,CAAC;EAE/C,OAAO,IAAIC,SAAS,CAACnD,KAAK,GAAGC,MAAM,GAAGiB,UAAU,CAAC;AACnD"}
@@ -0,0 +1,3 @@
1
+ export declare function glFormatToComponents(format: any): 2 | 0 | 1 | 4 | 3;
2
+ export declare function glTypeToBytes(type: any): 2 | 0 | 1 | 4;
3
+ //# sourceMappingURL=format-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"AAOA,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,qBAoB1C;AAGD,wBAAgB,aAAa,CAAC,IAAI,KAAA,iBAejC"}
@@ -0,0 +1,38 @@
1
+ import { assert } from '@luma.gl/core';
2
+ import { GL } from '@luma.gl/constants';
3
+ export function glFormatToComponents(format) {
4
+ switch (format) {
5
+ case GL.ALPHA:
6
+ case GL.R32F:
7
+ case GL.RED:
8
+ return 1;
9
+ case GL.RG32F:
10
+ case GL.RG:
11
+ return 2;
12
+ case GL.RGB:
13
+ case GL.RGB32F:
14
+ return 3;
15
+ case GL.RGBA:
16
+ case GL.RGBA32F:
17
+ return 4;
18
+ default:
19
+ assert(false);
20
+ return 0;
21
+ }
22
+ }
23
+ export function glTypeToBytes(type) {
24
+ switch (type) {
25
+ case GL.UNSIGNED_BYTE:
26
+ return 1;
27
+ case GL.UNSIGNED_SHORT_5_6_5:
28
+ case GL.UNSIGNED_SHORT_4_4_4_4:
29
+ case GL.UNSIGNED_SHORT_5_5_5_1:
30
+ return 2;
31
+ case GL.FLOAT:
32
+ return 4;
33
+ default:
34
+ assert(false);
35
+ return 0;
36
+ }
37
+ }
38
+ //# sourceMappingURL=format-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-utils.js","names":["assert","GL","glFormatToComponents","format","ALPHA","R32F","RED","RG32F","RG","RGB","RGB32F","RGBA","RGBA32F","glTypeToBytes","type","UNSIGNED_BYTE","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","FLOAT"],"sources":["../../src/classic/format-utils.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert} from '@luma.gl/core';\nimport {GL} from '@luma.gl/constants';\n\n// Returns number of components in a specific readPixels WebGL format\nexport function glFormatToComponents(format) {\n switch (format) {\n case GL.ALPHA:\n case GL.R32F:\n case GL.RED:\n return 1;\n case GL.RG32F:\n case GL.RG:\n return 2;\n case GL.RGB:\n case GL.RGB32F:\n return 3;\n case GL.RGBA:\n case GL.RGBA32F:\n return 4;\n // TODO: Add support for additional WebGL2 formats\n default:\n assert(false);\n return 0;\n }\n}\n\n// Return byte count for given readPixels WebGL type\nexport function glTypeToBytes(type) {\n switch (type) {\n case GL.UNSIGNED_BYTE:\n return 1;\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return 2;\n case GL.FLOAT:\n return 4;\n // TODO: Add support for additional WebGL2 types\n default:\n assert(false);\n return 0;\n }\n}\n"],"mappings":"AAGA,SAAQA,MAAM,QAAO,eAAe;AACpC,SAAQC,EAAE,QAAO,oBAAoB;AAGrC,OAAO,SAASC,oBAAoBA,CAACC,MAAM,EAAE;EAC3C,QAAQA,MAAM;IACZ,KAAKF,EAAE,CAACG,KAAK;IACb,KAAKH,EAAE,CAACI,IAAI;IACZ,KAAKJ,EAAE,CAACK,GAAG;MACT,OAAO,CAAC;IACV,KAAKL,EAAE,CAACM,KAAK;IACb,KAAKN,EAAE,CAACO,EAAE;MACR,OAAO,CAAC;IACV,KAAKP,EAAE,CAACQ,GAAG;IACX,KAAKR,EAAE,CAACS,MAAM;MACZ,OAAO,CAAC;IACV,KAAKT,EAAE,CAACU,IAAI;IACZ,KAAKV,EAAE,CAACW,OAAO;MACb,OAAO,CAAC;IAEV;MACEZ,MAAM,CAAC,KAAK,CAAC;MACb,OAAO,CAAC;EACZ;AACF;AAGA,OAAO,SAASa,aAAaA,CAACC,IAAI,EAAE;EAClC,QAAQA,IAAI;IACV,KAAKb,EAAE,CAACc,aAAa;MACnB,OAAO,CAAC;IACV,KAAKd,EAAE,CAACe,oBAAoB;IAC5B,KAAKf,EAAE,CAACgB,sBAAsB;IAC9B,KAAKhB,EAAE,CAACiB,sBAAsB;MAC5B,OAAO,CAAC;IACV,KAAKjB,EAAE,CAACkB,KAAK;MACX,OAAO,CAAC;IAEV;MACEnB,MAAM,CAAC,KAAK,CAAC;MACb,OAAO,CAAC;EACZ;AACF"}
@@ -1,44 +1,42 @@
1
- import { TypedArray } from '@luma.gl/api/types';
2
- import { GLType } from '../types/webgl';
3
- declare type TypedArrayConstructor = Float32ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor;
1
+ import { TypedArray, TypedArrayConstructor } from '@luma.gl/core';
2
+ import { GLDataType, GLPixelType } from '@luma.gl/constants';
4
3
  /**
5
4
  * Converts TYPED ARRAYS to corresponding GL constant
6
5
  * Used to auto deduce gl parameter types
7
- * @param {*} arrayOrType
6
+ * @param arrayOrType
8
7
  * @returns
9
8
  */
10
- export declare function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType;
9
+ export declare function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLDataType;
11
10
  /**
12
11
  * Converts GL constant to corresponding TYPED ARRAY
13
12
  * Used to auto deduce gl parameter types
14
- * @param {*} glType
15
- * @param {*} param1
13
+ * @param glType
14
+ * @param param1
16
15
  * @returns
17
16
  */
18
- export declare function getTypedArrayFromGLType(glType: any, options?: {
17
+ export declare function getTypedArrayFromGLType(glType: GLDataType | GLPixelType, options?: {
19
18
  clamped?: boolean;
20
19
  }): TypedArrayConstructor;
21
20
  /**
22
21
  * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
23
22
  * https: *stackoverflow.com/questions/41969562/
24
23
  * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
25
- * @param {*} param0
24
+ * @param param0
26
25
  */
27
26
  export declare function flipRows(options: {
28
- data: any;
29
- width: any;
30
- height: any;
27
+ data: TypedArray;
28
+ width: number;
29
+ height: number;
31
30
  bytesPerPixel?: number;
32
- temp?: any;
31
+ temp?: Uint8Array;
33
32
  }): void;
34
33
  export declare function scalePixels(options: {
35
- data: any;
36
- width: any;
37
- height: any;
34
+ data: TypedArray;
35
+ width: number;
36
+ height: number;
38
37
  }): {
39
38
  data: Uint8Array;
40
39
  width: number;
41
40
  height: number;
42
41
  };
43
- export {};
44
42
  //# sourceMappingURL=typed-array-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/classic/typed-array-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAE9C,OAAO,E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,MAAM,EAAE,UAAU,GAAG,WAAW,EAChC,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,qBAAqB,CAwBvB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE;IAChC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,GAAG,IAAI,CAgBP;AAGD,wBAAgB,WAAW,CAAC,OAAO,EAAE;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG;IACF,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAaA"}
@@ -1,33 +1,24 @@
1
- import GL from '@luma.gl/constants';
1
+ import { GL } from '@luma.gl/constants';
2
2
  const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
3
3
  export function getGLTypeFromTypedArray(arrayOrType) {
4
4
  const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
5
-
6
5
  switch (type) {
7
6
  case Float32Array:
8
7
  return GL.FLOAT;
9
-
10
8
  case Uint16Array:
11
9
  return GL.UNSIGNED_SHORT;
12
-
13
10
  case Uint32Array:
14
11
  return GL.UNSIGNED_INT;
15
-
16
12
  case Uint8Array:
17
13
  return GL.UNSIGNED_BYTE;
18
-
19
14
  case Uint8ClampedArray:
20
15
  return GL.UNSIGNED_BYTE;
21
-
22
16
  case Int8Array:
23
17
  return GL.BYTE;
24
-
25
18
  case Int16Array:
26
19
  return GL.SHORT;
27
-
28
20
  case Int32Array:
29
21
  return GL.INT;
30
-
31
22
  default:
32
23
  throw new Error(ERR_TYPE_DEDUCTION);
33
24
  }
@@ -36,32 +27,24 @@ export function getTypedArrayFromGLType(glType, options) {
36
27
  const {
37
28
  clamped = true
38
29
  } = options || {};
39
-
40
30
  switch (glType) {
41
31
  case GL.FLOAT:
42
32
  return Float32Array;
43
-
44
33
  case GL.UNSIGNED_SHORT:
45
34
  case GL.UNSIGNED_SHORT_5_6_5:
46
35
  case GL.UNSIGNED_SHORT_4_4_4_4:
47
36
  case GL.UNSIGNED_SHORT_5_5_5_1:
48
37
  return Uint16Array;
49
-
50
38
  case GL.UNSIGNED_INT:
51
39
  return Uint32Array;
52
-
53
40
  case GL.UNSIGNED_BYTE:
54
41
  return clamped ? Uint8ClampedArray : Uint8Array;
55
-
56
42
  case GL.BYTE:
57
43
  return Int8Array;
58
-
59
44
  case GL.SHORT:
60
45
  return Int16Array;
61
-
62
46
  case GL.INT:
63
47
  return Int32Array;
64
-
65
48
  default:
66
49
  throw new Error('Failed to deduce typed array type from GL constant');
67
50
  }
@@ -76,7 +59,6 @@ export function flipRows(options) {
76
59
  } = options;
77
60
  const bytesPerRow = width * bytesPerPixel;
78
61
  const tempBuffer = temp || new Uint8Array(bytesPerRow);
79
-
80
62
  for (let y = 0; y < height / 2; ++y) {
81
63
  const topOffset = y * bytesPerRow;
82
64
  const bottomOffset = (height - y - 1) * bytesPerRow;
@@ -94,7 +76,6 @@ export function scalePixels(options) {
94
76
  const newWidth = Math.round(width / 2);
95
77
  const newHeight = Math.round(height / 2);
96
78
  const newData = new Uint8Array(newWidth * newHeight * 4);
97
-
98
79
  for (let y = 0; y < newHeight; y++) {
99
80
  for (let x = 0; x < newWidth; x++) {
100
81
  for (let c = 0; c < 4; c++) {
@@ -102,7 +83,6 @@ export function scalePixels(options) {
102
83
  }
103
84
  }
104
85
  }
105
-
106
86
  return {
107
87
  data: newData,
108
88
  width: newWidth,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/classic/typed-array-utils.ts"],"names":["GL","ERR_TYPE_DEDUCTION","getGLTypeFromTypedArray","arrayOrType","type","ArrayBuffer","isView","constructor","Float32Array","FLOAT","Uint16Array","UNSIGNED_SHORT","Uint32Array","UNSIGNED_INT","Uint8Array","UNSIGNED_BYTE","Uint8ClampedArray","Int8Array","BYTE","Int16Array","SHORT","Int32Array","INT","Error","getTypedArrayFromGLType","glType","options","clamped","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","flipRows","data","width","height","bytesPerPixel","temp","bytesPerRow","tempBuffer","y","topOffset","bottomOffset","set","subarray","copyWithin","scalePixels","newWidth","Math","round","newHeight","newData","x","c"],"mappings":"AACA,OAAOA,EAAP,MAAe,oBAAf;AAGA,MAAMC,kBAAkB,GAAG,+CAA3B;AAkBA,OAAO,SAASC,uBAAT,CAAiCC,WAAjC,EAAkE;AAEvE,QAAMC,IAAI,GAAGC,WAAW,CAACC,MAAZ,CAAmBH,WAAnB,IAAkCA,WAAW,CAACI,WAA9C,GAA4DJ,WAAzE;;AACA,UAAQC,IAAR;AACE,SAAKI,YAAL;AACE,aAAOR,EAAE,CAACS,KAAV;;AACF,SAAKC,WAAL;AACE,aAAOV,EAAE,CAACW,cAAV;;AACF,SAAKC,WAAL;AACE,aAAOZ,EAAE,CAACa,YAAV;;AACF,SAAKC,UAAL;AACE,aAAOd,EAAE,CAACe,aAAV;;AACF,SAAKC,iBAAL;AACE,aAAOhB,EAAE,CAACe,aAAV;;AACF,SAAKE,SAAL;AACE,aAAOjB,EAAE,CAACkB,IAAV;;AACF,SAAKC,UAAL;AACE,aAAOnB,EAAE,CAACoB,KAAV;;AACF,SAAKC,UAAL;AACE,aAAOrB,EAAE,CAACsB,GAAV;;AACF;AACE,YAAM,IAAIC,KAAJ,CAAUtB,kBAAV,CAAN;AAlBJ;AAoBD;AAUD,OAAO,SAASuB,uBAAT,CACLC,MADK,EAELC,OAFK,EAKkB;AACvB,QAAM;AAACC,IAAAA,OAAO,GAAG;AAAX,MAAmBD,OAAO,IAAI,EAApC;;AAEA,UAAQ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';\nimport {GLType} from '../types/webgl'\n\nconst ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';\n\ntype TypedArrayConstructor =\n | Float32ArrayConstructor\n | Uint16ArrayConstructor\n | Uint32ArrayConstructor\n | Uint8ArrayConstructor\n | Uint8ClampedArrayConstructor\n | Int8ArrayConstructor\n | Int16ArrayConstructor\n | Int32ArrayConstructor;\n\n/**\n * Converts TYPED ARRAYS to corresponding GL constant\n * Used to auto deduce gl parameter types\n * @param {*} arrayOrType\n * @returns\n */\nexport function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {\n // If typed array, look up constructor\n const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;\n switch (type) {\n case Float32Array:\n return GL.FLOAT;\n case Uint16Array:\n return GL.UNSIGNED_SHORT;\n case Uint32Array:\n return GL.UNSIGNED_INT;\n case Uint8Array:\n return GL.UNSIGNED_BYTE;\n case Uint8ClampedArray:\n return GL.UNSIGNED_BYTE;\n case Int8Array:\n return GL.BYTE;\n case Int16Array:\n return GL.SHORT;\n case Int32Array:\n return GL.INT;\n default:\n throw new Error(ERR_TYPE_DEDUCTION);\n }\n}\n\n/**\n * Converts GL constant to corresponding TYPED ARRAY\n * Used to auto deduce gl parameter types\n * @param {*} glType\n * @param {*} param1\n * @returns\n */\n// eslint-disable-next-line complexity\nexport function getTypedArrayFromGLType(\n glType: any,\n options?: {\n clamped?: boolean;\n }\n): TypedArrayConstructor {\n const {clamped = true} = options || {};\n // Sorted in some order of likelihood to reduce amount of comparisons\n switch (glType) {\n case GL.FLOAT:\n return Float32Array;\n case GL.UNSIGNED_SHORT:\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return Uint16Array;\n case GL.UNSIGNED_INT:\n return Uint32Array;\n case GL.UNSIGNED_BYTE:\n return clamped ? Uint8ClampedArray : Uint8Array;\n case GL.BYTE:\n return Int8Array;\n case GL.SHORT:\n return Int16Array;\n case GL.INT:\n return Int32Array;\n default:\n throw new Error('Failed to deduce typed array type from GL constant');\n }\n}\n\n/**\n * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)\n * https: *stackoverflow.com/questions/41969562/\n * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels\n * @param {*} param0\n */\n export function flipRows(options: {\n data: any;\n width: any;\n height: any;\n bytesPerPixel?: number;\n temp?: any;\n}): void {\n const {data, width, height, bytesPerPixel = 4, temp} = options;\n const bytesPerRow = width * bytesPerPixel;\n\n // make a temp buffer to hold one row\n const tempBuffer = temp || new Uint8Array(bytesPerRow);\n for (let y = 0; y < height / 2; ++y) {\n const topOffset = y * bytesPerRow;\n const bottomOffset = (height - y - 1) * bytesPerRow;\n // make copy of a row on the top half\n tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));\n // copy a row from the bottom half to the top\n data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);\n // copy the copy of the top half row to the bottom half\n data.set(tempBuffer, bottomOffset);\n }\n}\n\n\nexport function scalePixels(options: {\n data: any;\n width: any;\n height: any;\n}): {\n data: Uint8Array;\n width: number;\n height: number;\n} {\n const {data, width, height} = options;\n const newWidth = Math.round(width / 2);\n const newHeight = Math.round(height / 2);\n const newData = new Uint8Array(newWidth * newHeight * 4);\n for (let y = 0; y < newHeight; y++) {\n for (let x = 0; x < newWidth; x++) {\n for (let c = 0; c < 4; c++) {\n newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];\n }\n }\n }\n return {data: newData, width: newWidth, height: newHeight};\n}\n"],"file":"typed-array-utils.js"}
1
+ {"version":3,"file":"typed-array-utils.js","names":["GL","ERR_TYPE_DEDUCTION","getGLTypeFromTypedArray","arrayOrType","type","ArrayBuffer","isView","constructor","Float32Array","FLOAT","Uint16Array","UNSIGNED_SHORT","Uint32Array","UNSIGNED_INT","Uint8Array","UNSIGNED_BYTE","Uint8ClampedArray","Int8Array","BYTE","Int16Array","SHORT","Int32Array","INT","Error","getTypedArrayFromGLType","glType","options","clamped","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","flipRows","data","width","height","bytesPerPixel","temp","bytesPerRow","tempBuffer","y","topOffset","bottomOffset","set","subarray","copyWithin","scalePixels","newWidth","Math","round","newHeight","newData","x","c"],"sources":["../../src/classic/typed-array-utils.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {TypedArray, TypedArrayConstructor} from '@luma.gl/core';\nimport {GL, GLDataType, GLPixelType} from '@luma.gl/constants';\n\nconst ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';\n\n/**\n * Converts TYPED ARRAYS to corresponding GL constant\n * Used to auto deduce gl parameter types\n * @param arrayOrType\n * @returns\n */\nexport function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLDataType {\n // If typed array, look up constructor\n const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;\n switch (type) {\n case Float32Array:\n return GL.FLOAT;\n case Uint16Array:\n return GL.UNSIGNED_SHORT;\n case Uint32Array:\n return GL.UNSIGNED_INT;\n case Uint8Array:\n return GL.UNSIGNED_BYTE;\n case Uint8ClampedArray:\n return GL.UNSIGNED_BYTE;\n case Int8Array:\n return GL.BYTE;\n case Int16Array:\n return GL.SHORT;\n case Int32Array:\n return GL.INT;\n default:\n throw new Error(ERR_TYPE_DEDUCTION);\n }\n}\n\n/**\n * Converts GL constant to corresponding TYPED ARRAY\n * Used to auto deduce gl parameter types\n * @param glType\n * @param param1\n * @returns\n */\n// eslint-disable-next-line complexity\nexport function getTypedArrayFromGLType(\n glType: GLDataType | GLPixelType,\n options?: {\n clamped?: boolean;\n }\n): TypedArrayConstructor {\n const {clamped = true} = options || {};\n // Sorted in some order of likelihood to reduce amount of comparisons\n switch (glType) {\n case GL.FLOAT:\n return Float32Array;\n case GL.UNSIGNED_SHORT:\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return Uint16Array;\n case GL.UNSIGNED_INT:\n return Uint32Array;\n case GL.UNSIGNED_BYTE:\n return clamped ? Uint8ClampedArray : Uint8Array;\n case GL.BYTE:\n return Int8Array;\n case GL.SHORT:\n return Int16Array;\n case GL.INT:\n return Int32Array;\n default:\n throw new Error('Failed to deduce typed array type from GL constant');\n }\n}\n\n/**\n * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)\n * https: *stackoverflow.com/questions/41969562/\n * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels\n * @param param0\n */\nexport function flipRows(options: {\n data: TypedArray;\n width: number;\n height: number;\n bytesPerPixel?: number;\n temp?: Uint8Array;\n}): void {\n const {data, width, height, bytesPerPixel = 4, temp} = options;\n const bytesPerRow = width * bytesPerPixel;\n\n // make a temp buffer to hold one row\n const tempBuffer = temp || new Uint8Array(bytesPerRow);\n for (let y = 0; y < height / 2; ++y) {\n const topOffset = y * bytesPerRow;\n const bottomOffset = (height - y - 1) * bytesPerRow;\n // make copy of a row on the top half\n tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));\n // copy a row from the bottom half to the top\n data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);\n // copy the copy of the top half row to the bottom half\n data.set(tempBuffer, bottomOffset);\n }\n}\n\n\nexport function scalePixels(options: {\n data: TypedArray;\n width: number;\n height: number;\n}): {\n data: Uint8Array;\n width: number;\n height: number;\n} {\n const {data, width, height} = options;\n const newWidth = Math.round(width / 2);\n const newHeight = Math.round(height / 2);\n const newData = new Uint8Array(newWidth * newHeight * 4);\n for (let y = 0; y < newHeight; y++) {\n for (let x = 0; x < newWidth; x++) {\n for (let c = 0; c < 4; c++) {\n newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];\n }\n }\n }\n return {data: newData, width: newWidth, height: newHeight};\n}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AAC;EACxC,MAAMgB,OAAO,GAAG,IAAIpC,UAAU,CAACgC,QAAQ,GAAGG,SAAS,GAAG,CAAC,CAAC;EACxD,KAAK,IAAIV,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGU,SAAS,EAAEV,CAAC,EAAE,EAAE;IAClC,KAAK,IAAIY,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,QAAQ,EAAEK,CAAC,EAAE,EAAE;MACjC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;QAC1BF,OAAO,CAAC,CAACX,CAAC,GAAGO,QAAQ,GAAGK,CAAC,IAAI,CAAC,GAAGC,CAAC,CAAC,GAAGpB,IAAI,CAAC,CAACO,CAAC,GAAG,CAAC,GAAGN,KAAK,GAAGkB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAGC,CAAC,CAAC;MAC7E;IACF;EACF;EACA,OAAO;IAACpB,IAAI,EAAEkB,OAAO;IAAEjB,KAAK,EAAEa,QAAQ;IAAEZ,MAAM,EAAEe;EAAS,CAAC;AAC5D"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * ContextProps
3
+ * @param webgl2 Set to false to not create a WebGL2 context (force webgl1)
4
+ * @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)
5
+ * @param onContextLost
6
+ * @param onContextRestored
7
+ *
8
+ * BROWSER CONTEXT PARAMETERS
9
+ * @param debug Instrument context (at the expense of performance).
10
+ * @param alpha Default render target has an alpha buffer.
11
+ * @param depth Default render target has a depth buffer of at least 16 bits.
12
+ * @param stencil Default render target has a stencil buffer of at least 8 bits.
13
+ * @param antialias Boolean that indicates whether or not to perform anti-aliasing.
14
+ * @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
15
+ * @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
16
+ * @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
17
+ */
18
+ type ContextProps = {
19
+ type?: 'webgl' | 'webgl1' | 'webgl2' | string;
20
+ webgl1?: boolean;
21
+ webgl2?: boolean;
22
+ onContextLost?: (event: Event) => void;
23
+ onContextRestored?: (event: Event) => void;
24
+ alpha?: boolean;
25
+ desynchronized?: boolean;
26
+ antialias?: boolean;
27
+ depth?: boolean;
28
+ failIfMajorPerformanceCaveat?: boolean;
29
+ powerPreference?: 'default' | 'high-performance' | 'low-power';
30
+ premultipliedAlpha?: boolean;
31
+ preserveDrawingBuffer?: boolean;
32
+ };
33
+ /**
34
+ * Create a WebGL context for a canvas
35
+ * Note calling this multiple time on the same canvas does return the same context
36
+ * @param canvas A canvas element or offscreen canvas
37
+ */
38
+ export declare function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext;
39
+ export {};
40
+ //# sourceMappingURL=create-browser-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-browser-context.d.ts","sourceRoot":"","sources":["../../../src/context/context/create-browser-context.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,KAAK,YAAY,GAAG;IAClB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACvC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,eAAe,CAAC,EAAE,SAAS,GAAG,kBAAkB,GAAG,WAAW,CAAC;IAC/D,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAYF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAC3C,KAAK,EAAE,YAAY,GAClB,qBAAqB,CAiEvB"}
@@ -0,0 +1,53 @@
1
+ const DEFAULT_CONTEXT_PROPS = {
2
+ webgl2: true,
3
+ webgl1: true,
4
+ powerPreference: 'high-performance',
5
+ onContextLost: () => console.error('WebGL context lost'),
6
+ onContextRestored: () => console.info('WebGL context restored')
7
+ };
8
+ export function createBrowserContext(canvas, props) {
9
+ props = {
10
+ ...DEFAULT_CONTEXT_PROPS,
11
+ ...props
12
+ };
13
+ let errorMessage = null;
14
+ const onCreateError = error => errorMessage = error.statusMessage || errorMessage;
15
+ canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
16
+ let gl = null;
17
+ if (props.type === 'webgl2') {
18
+ props = {
19
+ ...props,
20
+ webgl1: false
21
+ };
22
+ }
23
+ if (props.type === 'webgl1') {
24
+ props = {
25
+ ...props,
26
+ webgl2: false
27
+ };
28
+ }
29
+ if (!gl && props.webgl2) {
30
+ gl = canvas.getContext('webgl2', props);
31
+ }
32
+ if (!gl && props.webgl1) {
33
+ gl = canvas.getContext('webgl', props);
34
+ }
35
+ canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);
36
+ if (!gl) {
37
+ throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${errorMessage || 'Unknown error'}`);
38
+ }
39
+ if (props.onContextLost) {
40
+ const {
41
+ onContextLost
42
+ } = props;
43
+ canvas.addEventListener('webglcontextlost', event => onContextLost(event), false);
44
+ }
45
+ if (props.onContextRestored) {
46
+ const {
47
+ onContextRestored
48
+ } = props;
49
+ canvas.addEventListener('webglcontextrestored', event => onContextRestored(event), false);
50
+ }
51
+ return gl;
52
+ }
53
+ //# sourceMappingURL=create-browser-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-browser-context.js","names":["DEFAULT_CONTEXT_PROPS","webgl2","webgl1","powerPreference","onContextLost","console","error","onContextRestored","info","createBrowserContext","canvas","props","errorMessage","onCreateError","statusMessage","addEventListener","gl","type","getContext","removeEventListener","Error","event"],"sources":["../../../src/context/context/create-browser-context.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\n/**\n * ContextProps\n * @param webgl2 Set to false to not create a WebGL2 context (force webgl1)\n * @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)\n * @param onContextLost\n * @param onContextRestored\n *\n * BROWSER CONTEXT PARAMETERS\n * @param debug Instrument context (at the expense of performance).\n * @param alpha Default render target has an alpha buffer.\n * @param depth Default render target has a depth buffer of at least 16 bits.\n * @param stencil Default render target has a stencil buffer of at least 8 bits.\n * @param antialias Boolean that indicates whether or not to perform anti-aliasing.\n * @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n * @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten\n * @param failIfMajorPerformanceCaveat Do not create if the system performance is low.\n */\ntype ContextProps = {\n type?: 'webgl' | 'webgl1' | 'webgl2' | string;\n webgl1?: boolean;\n webgl2?: boolean;\n onContextLost?: (event: Event) => void;\n onContextRestored?: (event: Event) => void;\n alpha?: boolean; // indicates if the canvas contains an alpha buffer.\n desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop\n antialias?: boolean; // indicates whether or not to perform anti-aliasing.\n depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.\n failIfMajorPerformanceCaveat?: boolean; // indicates if a context will be created if the system performance is low or if no hardware GPU is available.\n powerPreference?: 'default' | 'high-performance' | 'low-power';\n premultipliedAlpha?: boolean; // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n preserveDrawingBuffer?: boolean; // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.\n};\n\nconst DEFAULT_CONTEXT_PROPS: ContextProps = {\n webgl2: true, // Attempt to create a WebGL2 context\n webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)\n powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons\n // eslint-disable-next-line no-console\n onContextLost: () => console.error('WebGL context lost'),\n // eslint-disable-next-line no-console\n onContextRestored: () => console.info('WebGL context restored')\n};\n\n/**\n * Create a WebGL context for a canvas\n * Note calling this multiple time on the same canvas does return the same context\n * @param canvas A canvas element or offscreen canvas\n */\nexport function createBrowserContext(\n canvas: HTMLCanvasElement | OffscreenCanvas,\n props: ContextProps\n): WebGLRenderingContext {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n // Create the desired context\n let gl: WebGLRenderingContext | WebGL2RenderingContext | null = null;\n\n if (props.type === 'webgl2') {\n props = {...props, webgl1: false};\n }\n if (props.type === 'webgl1') {\n props = {...props, webgl2: false};\n }\n\n // props.failIfMajorPerformanceCaveat = true;\n\n // Prefer webgl2 over webgl1 if both are acceptable\n if (!gl && props.webgl2) {\n gl = canvas.getContext('webgl2', props) as WebGL2RenderingContext;\n }\n if (!gl && props.webgl1) {\n gl = canvas.getContext('webgl', props) as WebGLRenderingContext;\n }\n\n // Software GPU\n\n // props.failIfMajorPerformanceCaveat = false;\n // if (!gl && props.webgl2) {\n // gl = canvas.getContext('webgl2', props);\n // }\n // if (!gl && props.webgl1) {\n // gl = canvas.getContext('webgl', props);\n // }\n\n // TODO are we removing this listener before giving it a chance to fire?\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n if (!gl) {\n throw new Error(\n `Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${\n errorMessage || 'Unknown error'\n }`\n );\n }\n\n if (props.onContextLost) {\n // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.\n const {onContextLost} = props;\n canvas.addEventListener('webglcontextlost', (event: Event) => onContextLost(event), false);\n }\n if (props.onContextRestored) {\n // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.\n const {onContextRestored} = props;\n canvas.addEventListener(\n 'webglcontextrestored',\n (event: Event) => onContextRestored(event),\n false\n );\n }\n\n return gl;\n}\n\n/* TODO - can we call this asynchronously to catch the error events?\nexport async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGLRenderingContext> {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n const gl = createBrowserContext(canvas, props);\n\n // Give the listener a chance to fire\n await new Promise(resolve => setTimeout(resolve, 0));\n\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n return gl;\n}\n*/\n"],"mappings":"AAoCA,MAAMA,qBAAmC,GAAG;EAC1CC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,eAAe,EAAE,kBAAkB;EAEnCC,aAAa,EAAEA,CAAA,KAAMC,OAAO,CAACC,KAAK,CAAC,oBAAoB,CAAC;EAExDC,iBAAiB,EAAEA,CAAA,KAAMF,OAAO,CAACG,IAAI,CAAC,wBAAwB;AAChE,CAAC;AAOD,OAAO,SAASC,oBAAoBA,CAClCC,MAA2C,EAC3CC,KAAmB,EACI;EACvBA,KAAK,GAAG;IAAC,GAAGX,qBAAqB;IAAE,GAAGW;EAAK,CAAC;EAG5C,IAAIC,YAAY,GAAG,IAAI;EACvB,MAAMC,aAAa,GAAGP,KAAK,IAAKM,YAAY,GAAGN,KAAK,CAACQ,aAAa,IAAIF,YAAa;EACnFF,MAAM,CAACK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,CAAC,EAC1C,KACF,CAAC;EACH;EAEA,OAAOL,EAAE;AACX"}
@@ -0,0 +1,9 @@
1
+ /** Duck typing for the main headless gl export, a function to create contexts */
2
+ export type HeadlessGL = (width: number, height: number, options: Record<string, unknown>) => WebGLRenderingContext;
3
+ /** By importing `gl` and registering it with this function, contexts can be created under Node.js */
4
+ export declare function registerHeadlessGL(headlessgl: HeadlessGL): void;
5
+ /** @returns true if headless gl is registered */
6
+ export declare function isHeadlessGLRegistered(): boolean;
7
+ /** Create headless gl context (for running under Node.js) */
8
+ export declare function createHeadlessContext(options?: Record<string, any>): WebGLRenderingContext;
9
+ //# sourceMappingURL=create-headless-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-headless-context.d.ts","sourceRoot":"","sources":["../../../src/context/context/create-headless-context.ts"],"names":[],"mappings":"AAkBA,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,qBAAqB,CAAC;AAIpH,qGAAqG;AACrG,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,QAExD;AAED,iDAAiD;AACjD,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAED,6DAA6D;AAC7D,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,qBAAqB,CAgB1F"}