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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +295 -156
  3. package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
  4. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js +73 -67
  6. package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
  7. package/dist/adapter/converters/shader-formats.js +53 -46
  8. package/dist/adapter/converters/texture-formats.d.ts +17 -21
  9. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  10. package/dist/adapter/converters/texture-formats.js +481 -879
  11. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  12. package/dist/adapter/converters/vertex-formats.js +53 -61
  13. package/dist/adapter/device-helpers/webgl-device-features.d.ts +20 -0
  14. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  15. package/dist/adapter/device-helpers/webgl-device-features.js +98 -0
  16. package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
  17. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  18. package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
  19. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
  20. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
  22. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  23. package/dist/adapter/helpers/decode-webgl-types.js +88 -76
  24. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  25. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  26. package/dist/adapter/helpers/get-shader-layout.js +261 -225
  27. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  28. package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
  29. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  30. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  31. package/dist/adapter/helpers/set-uniform.js +68 -82
  32. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  33. package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
  34. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  35. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  36. package/dist/adapter/objects/constants-to-keys.js +19 -12
  37. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  38. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  39. package/dist/adapter/objects/webgl-renderbuffer.js +86 -77
  40. package/dist/adapter/objects/webgl-resource.d.ts +3 -25
  41. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  42. package/dist/adapter/objects/webgl-resource.js +102 -147
  43. package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
  44. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-buffer.js +159 -117
  46. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-command-buffer.js +266 -168
  49. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  50. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-command-encoder.js +33 -39
  52. package/dist/adapter/resources/webgl-external-texture.js +93 -1
  53. package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -12
  54. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-framebuffer.js +174 -139
  56. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  57. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  58. package/dist/adapter/resources/webgl-query-set.js +136 -0
  59. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  60. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgl-render-pass.js +124 -90
  62. package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
  63. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgl-render-pipeline.js +362 -221
  65. package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
  66. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  67. package/dist/adapter/resources/webgl-sampler.js +43 -33
  68. package/dist/adapter/resources/webgl-shader.d.ts +12 -2
  69. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  70. package/dist/adapter/resources/webgl-shader.js +114 -47
  71. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  72. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  73. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  74. package/dist/adapter/resources/webgl-texture.d.ts +8 -10
  75. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  76. package/dist/adapter/resources/webgl-texture.js +616 -694
  77. package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
  78. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
  80. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  81. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  82. package/dist/adapter/resources/webgl-vertex-array.js +229 -157
  83. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  84. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  85. package/dist/adapter/webgl-canvas-context.js +58 -36
  86. package/dist/adapter/webgl-device.d.ts +50 -44
  87. package/dist/adapter/webgl-device.d.ts.map +1 -1
  88. package/dist/adapter/webgl-device.js +427 -352
  89. package/dist/classic/accessor.d.ts.map +1 -1
  90. package/dist/classic/accessor.js +132 -101
  91. package/dist/classic/clear.d.ts +2 -2
  92. package/dist/classic/clear.d.ts.map +1 -1
  93. package/dist/classic/clear.js +73 -72
  94. package/dist/classic/copy-and-blit.d.ts +1 -1
  95. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  96. package/dist/classic/copy-and-blit.js +174 -175
  97. package/dist/classic/format-utils.d.ts +2 -2
  98. package/dist/classic/format-utils.d.ts.map +1 -1
  99. package/dist/classic/format-utils.js +39 -32
  100. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  101. package/dist/classic/typed-array-utils.js +96 -81
  102. package/dist/context/debug/spector.d.ts.map +1 -1
  103. package/dist/context/debug/spector.js +55 -50
  104. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  105. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  106. package/dist/context/debug/webgl-developer-tools.js +104 -77
  107. package/dist/context/{context → helpers}/create-browser-context.d.ts +1 -6
  108. package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
  109. package/dist/context/helpers/create-browser-context.js +67 -0
  110. package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
  111. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  112. package/dist/context/helpers/webgl-context-data.js +21 -0
  113. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  114. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  115. package/dist/context/helpers/webgl-extensions.js +10 -0
  116. package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
  117. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  118. package/dist/context/parameters/unified-parameter-api.js +92 -47
  119. package/dist/context/parameters/webgl-parameter-tables.d.ts +109 -99
  120. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  121. package/dist/context/parameters/webgl-parameter-tables.js +463 -404
  122. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  123. package/dist/context/state-tracker/deep-array-equal.js +19 -14
  124. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  125. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  126. package/dist/context/state-tracker/track-context-state.js +188 -123
  127. package/dist/context/state-tracker/with-parameters.d.ts +2 -3
  128. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  129. package/dist/context/state-tracker/with-parameters.js +42 -28
  130. package/dist/dist.dev.js +4465 -7235
  131. package/dist/dist.min.js +10 -0
  132. package/dist/index.cjs +2146 -3116
  133. package/dist/index.cjs.map +7 -0
  134. package/dist/index.d.ts +25 -31
  135. package/dist/index.d.ts.map +1 -1
  136. package/dist/index.js +19 -10
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/types.js +3 -1
  139. package/dist.min.js +9 -42
  140. package/package.json +10 -15
  141. package/src/adapter/converters/device-parameters.ts +114 -28
  142. package/src/adapter/converters/sampler-parameters.ts +12 -20
  143. package/src/adapter/converters/shader-formats.ts +47 -22
  144. package/src/adapter/converters/texture-formats.ts +183 -227
  145. package/src/adapter/converters/vertex-formats.ts +3 -3
  146. package/src/adapter/device-helpers/webgl-device-features.ts +121 -0
  147. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
  148. package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
  149. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  150. package/src/adapter/helpers/get-shader-layout.ts +21 -31
  151. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  152. package/src/adapter/helpers/set-uniform.ts +3 -4
  153. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  154. package/src/adapter/objects/constants-to-keys.ts +3 -2
  155. package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
  156. package/src/adapter/objects/webgl-resource.ts +8 -141
  157. package/src/adapter/resources/webgl-buffer.ts +10 -14
  158. package/src/adapter/resources/webgl-command-buffer.ts +24 -34
  159. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  160. package/src/adapter/resources/webgl-external-texture.ts +7 -7
  161. package/src/adapter/resources/webgl-framebuffer.ts +65 -58
  162. package/src/adapter/resources/webgl-query-set.ts +171 -0
  163. package/src/adapter/resources/webgl-render-pass.ts +27 -18
  164. package/src/adapter/resources/webgl-render-pipeline.ts +148 -73
  165. package/src/adapter/resources/webgl-sampler.ts +7 -10
  166. package/src/adapter/resources/webgl-shader.ts +65 -11
  167. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  168. package/src/adapter/resources/webgl-texture.ts +43 -106
  169. package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
  170. package/src/adapter/resources/webgl-vertex-array.ts +20 -21
  171. package/src/adapter/webgl-canvas-context.ts +7 -11
  172. package/src/adapter/webgl-device.ts +142 -162
  173. package/src/classic/accessor.ts +5 -4
  174. package/src/classic/clear.ts +25 -20
  175. package/src/classic/copy-and-blit.ts +12 -6
  176. package/src/classic/format-utils.ts +2 -1
  177. package/src/classic/typed-array-utils.ts +3 -7
  178. package/src/context/debug/spector.ts +9 -6
  179. package/src/context/debug/webgl-developer-tools.ts +31 -20
  180. package/src/context/{context → helpers}/create-browser-context.ts +9 -33
  181. package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
  182. package/src/context/helpers/webgl-extensions.ts +17 -0
  183. package/src/context/parameters/unified-parameter-api.ts +6 -17
  184. package/src/context/parameters/webgl-parameter-tables.ts +118 -90
  185. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  186. package/src/context/state-tracker/track-context-state.ts +29 -23
  187. package/src/context/state-tracker/with-parameters.ts +8 -8
  188. package/src/index.ts +16 -56
  189. package/src/types.ts +2 -1
  190. package/dist/adapter/converters/device-parameters.js.map +0 -1
  191. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  192. package/dist/adapter/converters/shader-formats.js.map +0 -1
  193. package/dist/adapter/converters/texture-formats.js.map +0 -1
  194. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  195. package/dist/adapter/device-helpers/device-features.d.ts +0 -9
  196. package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
  197. package/dist/adapter/device-helpers/device-features.js +0 -96
  198. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  199. package/dist/adapter/device-helpers/device-limits.d.ts +0 -52
  200. package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
  201. package/dist/adapter/device-helpers/device-limits.js +0 -87
  202. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  203. package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
  204. package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
  205. package/dist/adapter/device-helpers/get-device-info.js +0 -71
  206. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  207. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  208. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  209. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  210. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  211. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  212. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  213. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  214. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  215. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  216. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  217. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  218. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  219. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  220. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  221. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  222. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  223. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  224. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  225. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  226. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  227. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  228. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  229. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  230. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  231. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  232. package/dist/adapter/webgl-device.js.map +0 -1
  233. package/dist/classic/accessor.js.map +0 -1
  234. package/dist/classic/clear.js.map +0 -1
  235. package/dist/classic/copy-and-blit.js.map +0 -1
  236. package/dist/classic/format-utils.js.map +0 -1
  237. package/dist/classic/typed-array-utils.js.map +0 -1
  238. package/dist/context/context/create-browser-context.d.ts.map +0 -1
  239. package/dist/context/context/create-browser-context.js +0 -53
  240. package/dist/context/context/create-browser-context.js.map +0 -1
  241. package/dist/context/context/create-headless-context.d.ts +0 -9
  242. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  243. package/dist/context/context/create-headless-context.js +0 -42
  244. package/dist/context/context/create-headless-context.js.map +0 -1
  245. package/dist/context/context/webgl-checks.d.ts +0 -13
  246. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  247. package/dist/context/context/webgl-checks.js +0 -31
  248. package/dist/context/context/webgl-checks.js.map +0 -1
  249. package/dist/context/debug/spector.js.map +0 -1
  250. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  251. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  252. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  253. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  254. package/dist/context/polyfill/context-data.js +0 -12
  255. package/dist/context/polyfill/context-data.js.map +0 -1
  256. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  257. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  258. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  259. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  260. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  261. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  262. package/dist/context/polyfill/polyfill-context.js +0 -87
  263. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  264. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  265. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  266. package/dist/context/polyfill/polyfill-table.js +0 -137
  267. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  268. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  269. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  270. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  271. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  272. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  273. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  274. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  275. package/dist/index.js.map +0 -1
  276. package/dist/types.js.map +0 -1
  277. package/src/adapter/device-helpers/device-features.ts +0 -161
  278. package/src/adapter/device-helpers/device-limits.ts +0 -155
  279. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  280. package/src/context/context/create-headless-context.ts +0 -51
  281. package/src/context/context/webgl-checks.ts +0 -51
  282. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  283. package/src/context/polyfill/polyfill-context.ts +0 -104
  284. package/src/context/polyfill/polyfill-table.ts +0 -167
  285. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,192 +1,191 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { assert, Texture, Framebuffer } from '@luma.gl/core';
5
+ import { GL } from '@luma.gl/constants';
2
6
  import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
3
7
  import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
8
+ /**
9
+ * Copies data from a type or a Texture object into ArrayBuffer object.
10
+ * App can provide targetPixelArray or have it auto allocated by this method
11
+ * newly allocated by this method unless provided by app.
12
+ * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
13
+ * @note Slow requires roundtrip to GPU
14
+ *
15
+ * @param source
16
+ * @param options
17
+ * @returns pixel array,
18
+ */
4
19
  export function readPixelsToArray(source, options) {
5
- var _framebuffer$colorAtt;
6
- const {
7
- sourceX = 0,
8
- sourceY = 0,
9
- sourceFormat = 6408,
10
- sourceAttachment = 36064
11
- } = options || {};
12
- let {
13
- target = null,
14
- sourceWidth,
15
- sourceHeight,
16
- sourceType
17
- } = options || {};
18
- const {
19
- framebuffer,
20
- deleteFramebuffer
21
- } = getFramebuffer(source);
22
- assert(framebuffer);
23
- const {
24
- gl,
25
- handle
26
- } = framebuffer;
27
- sourceWidth = sourceWidth || framebuffer.width;
28
- sourceHeight = sourceHeight || framebuffer.height;
29
- const attachment = sourceAttachment - 36064;
30
- sourceType = sourceType || ((_framebuffer$colorAtt = framebuffer.colorAttachments[attachment]) === null || _framebuffer$colorAtt === void 0 ? void 0 : _framebuffer$colorAtt.type) || 5121;
31
- target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
32
- sourceType = sourceType || getGLTypeFromTypedArray(target);
33
- const prevHandle = gl.bindFramebuffer(36160, handle);
34
- gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
35
- gl.bindFramebuffer(36160, prevHandle || null);
36
- if (deleteFramebuffer) {
37
- framebuffer.destroy();
38
- }
39
- return target;
20
+ const { sourceX = 0, sourceY = 0, sourceFormat = 6408, sourceAttachment = 36064 // TODO - support gl.readBuffer
21
+ } = options || {};
22
+ let { target = null,
23
+ // following parameters are auto deduced if not provided
24
+ sourceWidth, sourceHeight, sourceType } = options || {};
25
+ const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
26
+ assert(framebuffer);
27
+ const { gl, handle } = framebuffer;
28
+ sourceWidth = sourceWidth || framebuffer.width;
29
+ sourceHeight = sourceHeight || framebuffer.height;
30
+ // TODO - Set and unset gl.readBuffer
31
+ // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
32
+ // sourceAttachment = GL.FRONT;
33
+ // }
34
+ const attachment = sourceAttachment - 36064;
35
+ // assert(attachments[sourceAttachment]);
36
+ // Deduce the type from color attachment if not provided.
37
+ sourceType =
38
+ sourceType ||
39
+ framebuffer.colorAttachments[attachment]?.texture?.type || 5121;
40
+ // Deduce type and allocated pixelArray if needed
41
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
42
+ // Pixel array available, if necessary, deduce type from it.
43
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
44
+ const prevHandle = gl.bindFramebuffer(36160, handle);
45
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
46
+ // @ts-expect-error
47
+ gl.bindFramebuffer(36160, prevHandle || null);
48
+ if (deleteFramebuffer) {
49
+ framebuffer.destroy();
50
+ }
51
+ return target;
40
52
  }
53
+ /**
54
+ * Copies data from a Framebuffer or a Texture object into a Buffer object.
55
+ * NOTE: doesn't wait for copy to be complete, it programs GPU to perform a DMA transffer.
56
+ * @deprecated Use CommandEncoder
57
+ * @param source
58
+ * @param options
59
+ */
41
60
  export function readPixelsToBuffer(source, options) {
42
- const {
43
- target,
44
- sourceX = 0,
45
- sourceY = 0,
46
- sourceFormat = 6408,
47
- targetByteOffset = 0
48
- } = options || {};
49
- let {
50
- sourceWidth,
51
- sourceHeight,
52
- sourceType
53
- } = options || {};
54
- const {
55
- framebuffer,
56
- deleteFramebuffer
57
- } = getFramebuffer(source);
58
- assert(framebuffer);
59
- sourceWidth = sourceWidth || framebuffer.width;
60
- sourceHeight = sourceHeight || framebuffer.height;
61
- const webglFramebuffer = framebuffer;
62
- sourceType = sourceType || 5121;
63
- let webglBufferTarget = target;
64
- if (!webglBufferTarget) {
65
- const components = glFormatToComponents(sourceFormat);
66
- const byteCount = glTypeToBytes(sourceType);
67
- const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
68
- webglBufferTarget = webglFramebuffer.device.createBuffer({
69
- byteLength
61
+ const { target, sourceX = 0, sourceY = 0, sourceFormat = 6408, targetByteOffset = 0 } = options || {};
62
+ // following parameters are auto deduced if not provided
63
+ let { sourceWidth, sourceHeight, sourceType } = options || {};
64
+ const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
65
+ assert(framebuffer);
66
+ sourceWidth = sourceWidth || framebuffer.width;
67
+ sourceHeight = sourceHeight || framebuffer.height;
68
+ // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
69
+ const webglFramebuffer = framebuffer;
70
+ // deduce type if not available.
71
+ sourceType = sourceType || 5121;
72
+ let webglBufferTarget = target;
73
+ if (!webglBufferTarget) {
74
+ // Create new buffer with enough size
75
+ const components = glFormatToComponents(sourceFormat);
76
+ const byteCount = glTypeToBytes(sourceType);
77
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
78
+ webglBufferTarget = webglFramebuffer.device.createBuffer({ byteLength });
79
+ }
80
+ // TODO(donmccurdy): Do we have tests to confirm this is working?
81
+ const commandEncoder = source.device.createCommandEncoder();
82
+ commandEncoder.copyTextureToBuffer({
83
+ source: source,
84
+ width: sourceWidth,
85
+ height: sourceHeight,
86
+ origin: [sourceX, sourceY],
87
+ destination: webglBufferTarget,
88
+ byteOffset: targetByteOffset
70
89
  });
71
- }
72
- const commandEncoder = source.device.createCommandEncoder();
73
- commandEncoder.copyTextureToBuffer({
74
- source: source,
75
- width: sourceWidth,
76
- height: sourceHeight,
77
- origin: [sourceX, sourceY],
78
- destination: webglBufferTarget,
79
- byteOffset: targetByteOffset
80
- });
81
- commandEncoder.destroy();
82
- if (deleteFramebuffer) {
83
- framebuffer.destroy();
84
- }
85
- return webglBufferTarget;
90
+ commandEncoder.destroy();
91
+ if (deleteFramebuffer) {
92
+ framebuffer.destroy();
93
+ }
94
+ return webglBufferTarget;
86
95
  }
96
+ /**
97
+ * Copy a rectangle from a Framebuffer or Texture object into a texture (at an offset)
98
+ * @deprecated Use CommandEncoder
99
+ */
100
+ // eslint-disable-next-line complexity, max-statements
87
101
  export function copyToTexture(source, target, options) {
88
- const {
89
- sourceX = 0,
90
- sourceY = 0,
91
- targetMipmaplevel = 0,
92
- targetInternalFormat = 6408
93
- } = options || {};
94
- let {
95
- targetX,
96
- targetY,
97
- targetZ,
98
- width,
99
- height
100
- } = options || {};
101
- const {
102
- framebuffer,
103
- deleteFramebuffer
104
- } = getFramebuffer(source);
105
- assert(framebuffer);
106
- const webglFramebuffer = framebuffer;
107
- const {
108
- device,
109
- handle
110
- } = webglFramebuffer;
111
- const isSubCopy = typeof targetX !== 'undefined' || typeof targetY !== 'undefined' || typeof targetZ !== 'undefined';
112
- targetX = targetX || 0;
113
- targetY = targetY || 0;
114
- targetZ = targetZ || 0;
115
- const prevHandle = device.gl.bindFramebuffer(36160, handle);
116
- assert(target);
117
- let texture = null;
118
- let textureTarget;
119
- if (target instanceof Texture) {
120
- texture = target;
121
- width = Number.isFinite(width) ? width : texture.width;
122
- height = Number.isFinite(height) ? height : texture.height;
123
- texture.bind(0);
124
- textureTarget = texture.target;
125
- } else {
126
- textureTarget = target;
127
- }
128
- if (!isSubCopy) {
129
- device.gl.copyTexImage2D(textureTarget, targetMipmaplevel, targetInternalFormat, sourceX, sourceY, width, height, 0);
130
- } else {
131
- switch (textureTarget) {
132
- case 3553:
133
- case 34067:
134
- device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
135
- break;
136
- case 35866:
137
- case 32879:
138
- device.assertWebGL2();
139
- device.gl2.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
140
- break;
141
- default:
102
+ const { sourceX = 0, sourceY = 0,
103
+ // attachment = GL.COLOR_ATTACHMENT0, // TODO - support gl.readBuffer
104
+ targetMipmaplevel = 0, targetInternalFormat = 6408 } = options || {};
105
+ let { targetX, targetY, targetZ, width, // defaults to target width
106
+ height // defaults to target height
107
+ } = options || {};
108
+ const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
109
+ assert(framebuffer);
110
+ const webglFramebuffer = framebuffer;
111
+ const { device, handle } = webglFramebuffer;
112
+ const isSubCopy = typeof targetX !== 'undefined' ||
113
+ typeof targetY !== 'undefined' ||
114
+ typeof targetZ !== 'undefined';
115
+ targetX = targetX || 0;
116
+ targetY = targetY || 0;
117
+ targetZ = targetZ || 0;
118
+ const prevHandle = device.gl.bindFramebuffer(36160, handle);
119
+ // TODO - support gl.readBuffer (WebGL2 only)
120
+ // const prevBuffer = gl.readBuffer(attachment);
121
+ assert(target);
122
+ let texture = null;
123
+ let textureTarget;
124
+ if (target instanceof Texture) {
125
+ texture = target;
126
+ width = Number.isFinite(width) ? width : texture.width;
127
+ height = Number.isFinite(height) ? height : texture.height;
128
+ texture.bind(0);
129
+ textureTarget = texture.target;
130
+ }
131
+ else {
132
+ textureTarget = target;
133
+ }
134
+ if (!isSubCopy) {
135
+ device.gl.copyTexImage2D(textureTarget, targetMipmaplevel, targetInternalFormat, sourceX, sourceY, width, height, 0 /* border must be 0 */);
136
+ }
137
+ else {
138
+ switch (textureTarget) {
139
+ case 3553:
140
+ case 34067:
141
+ device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
142
+ break;
143
+ case 35866:
144
+ case 32879:
145
+ device.gl.copyTexSubImage3D(textureTarget, targetMipmaplevel, targetX, targetY, targetZ, sourceX, sourceY, width, height);
146
+ break;
147
+ default:
148
+ }
142
149
  }
143
- }
144
- if (texture) {
145
- texture.unbind();
146
- }
147
- device.gl.bindFramebuffer(36160, prevHandle || null);
148
- if (deleteFramebuffer) {
149
- framebuffer.destroy();
150
- }
151
- return texture;
150
+ if (texture) {
151
+ texture.unbind();
152
+ }
153
+ // @ts-expect-error
154
+ device.gl.bindFramebuffer(36160, prevHandle || null);
155
+ if (deleteFramebuffer) {
156
+ framebuffer.destroy();
157
+ }
158
+ return texture;
152
159
  }
153
160
  function getFramebuffer(source) {
154
- if (!(source instanceof Framebuffer)) {
155
- return {
156
- framebuffer: toFramebuffer(source),
157
- deleteFramebuffer: true
158
- };
159
- }
160
- return {
161
- framebuffer: source,
162
- deleteFramebuffer: false
163
- };
161
+ if (!(source instanceof Framebuffer)) {
162
+ return { framebuffer: toFramebuffer(source), deleteFramebuffer: true };
163
+ }
164
+ return { framebuffer: source, deleteFramebuffer: false };
164
165
  }
166
+ /**
167
+ * Wraps a given texture into a framebuffer object, that can be further used
168
+ * to read data from the texture object.
169
+ */
165
170
  export function toFramebuffer(texture, props) {
166
- const {
167
- device,
168
- width,
169
- height,
170
- id
171
- } = texture;
172
- const framebuffer = device.createFramebuffer({
173
- ...props,
174
- id: `framebuffer-for-${id}`,
175
- width,
176
- height,
177
- colorAttachments: [texture]
178
- });
179
- return framebuffer;
171
+ const { device, width, height, id } = texture;
172
+ const framebuffer = device.createFramebuffer({
173
+ ...props,
174
+ id: `framebuffer-for-${id}`,
175
+ width,
176
+ height,
177
+ colorAttachments: [texture]
178
+ });
179
+ return framebuffer;
180
180
  }
181
181
  function getPixelArray(pixelArray, type, format, width, height) {
182
- if (pixelArray) {
183
- return pixelArray;
184
- }
185
- type = type || 5121;
186
- const ArrayType = getTypedArrayFromGLType(type, {
187
- clamped: false
188
- });
189
- const components = glFormatToComponents(format);
190
- return new ArrayType(width * height * components);
182
+ if (pixelArray) {
183
+ return pixelArray;
184
+ }
185
+ // Allocate pixel array if not already available, using supplied type
186
+ type = type || 5121;
187
+ const ArrayType = getTypedArrayFromGLType(type, { clamped: false });
188
+ const components = glFormatToComponents(format);
189
+ // TODO - check for composite type (components = 1).
190
+ return new ArrayType(width * height * components);
191
191
  }
192
- //# sourceMappingURL=copy-and-blit.js.map
@@ -1,3 +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;
1
+ export declare function glFormatToComponents(format: any): 0 | 1 | 4 | 2 | 3;
2
+ export declare function glTypeToBytes(type: any): 0 | 1 | 4 | 2;
3
3
  //# sourceMappingURL=format-utils.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"format-utils.d.ts","sourceRoot":"","sources":["../../src/classic/format-utils.ts"],"names":[],"mappings":"AAQA,wBAAgB,oBAAoB,CAAC,MAAM,KAAA,qBAoB1C;AAGD,wBAAgB,aAAa,CAAC,IAAI,KAAA,iBAejC"}
@@ -1,37 +1,44 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { assert } from '@luma.gl/core';
5
+ import { GL } from '@luma.gl/constants';
6
+ // Returns number of components in a specific readPixels WebGL format
2
7
  export function glFormatToComponents(format) {
3
- switch (format) {
4
- case 6406:
5
- case 33326:
6
- case 6403:
7
- return 1;
8
- case 33328:
9
- case 33319:
10
- return 2;
11
- case 6407:
12
- case 34837:
13
- return 3;
14
- case 6408:
15
- case 34836:
16
- return 4;
17
- default:
18
- assert(false);
19
- return 0;
20
- }
8
+ switch (format) {
9
+ case 6406:
10
+ case 33326:
11
+ case 6403:
12
+ return 1;
13
+ case 33328:
14
+ case 33319:
15
+ return 2;
16
+ case 6407:
17
+ case 34837:
18
+ return 3;
19
+ case 6408:
20
+ case 34836:
21
+ return 4;
22
+ // TODO: Add support for additional WebGL2 formats
23
+ default:
24
+ assert(false);
25
+ return 0;
26
+ }
21
27
  }
28
+ // Return byte count for given readPixels WebGL type
22
29
  export function glTypeToBytes(type) {
23
- switch (type) {
24
- case 5121:
25
- return 1;
26
- case 33635:
27
- case 32819:
28
- case 32820:
29
- return 2;
30
- case 5126:
31
- return 4;
32
- default:
33
- assert(false);
34
- return 0;
35
- }
30
+ switch (type) {
31
+ case 5121:
32
+ return 1;
33
+ case 33635:
34
+ case 32819:
35
+ case 32820:
36
+ return 2;
37
+ case 5126:
38
+ return 4;
39
+ // TODO: Add support for additional WebGL2 types
40
+ default:
41
+ assert(false);
42
+ return 0;
43
+ }
36
44
  }
37
- //# sourceMappingURL=format-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/classic/typed-array-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,UAAU,EAAE,qBAAqB,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAK,UAAU,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,UAAU,GAAG,UAAU,CAuB3E;AAED;;;;;;;GAOG;AAEH,wBAAgB,uBAAuB,CACrC,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
+ {"version":3,"file":"typed-array-utils.d.ts","sourceRoot":"","sources":["../../src/classic/typed-array-utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAE,qBAAqB,EAAC,MAAM,eAAe,CAAC;AAChE,OAAO,EAAK,UAAU,EAAE,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAI/D;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,UAAU,GAAG,UAAU,CAuB3E;AAED;;;;;;;GAOG;AAEH,wBAAgB,uBAAuB,CACrC,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;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,GAAG;IACvF,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAaA"}
@@ -1,91 +1,106 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { GL } from '@luma.gl/constants';
1
5
  const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
6
+ /**
7
+ * Converts TYPED ARRAYS to corresponding GL constant
8
+ * Used to auto deduce gl parameter types
9
+ * @deprecated Use getDataTypeFromTypedArray
10
+ * @param arrayOrType
11
+ * @returns
12
+ */
2
13
  export function getGLTypeFromTypedArray(arrayOrType) {
3
- const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
4
- switch (type) {
5
- case Float32Array:
6
- return 5126;
7
- case Uint16Array:
8
- return 5123;
9
- case Uint32Array:
10
- return 5125;
11
- case Uint8Array:
12
- return 5121;
13
- case Uint8ClampedArray:
14
- return 5121;
15
- case Int8Array:
16
- return 5120;
17
- case Int16Array:
18
- return 5122;
19
- case Int32Array:
20
- return 5124;
21
- default:
22
- throw new Error(ERR_TYPE_DEDUCTION);
23
- }
14
+ // If typed array, look up constructor
15
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
16
+ switch (type) {
17
+ case Float32Array:
18
+ return 5126;
19
+ case Uint16Array:
20
+ return 5123;
21
+ case Uint32Array:
22
+ return 5125;
23
+ case Uint8Array:
24
+ return 5121;
25
+ case Uint8ClampedArray:
26
+ return 5121;
27
+ case Int8Array:
28
+ return 5120;
29
+ case Int16Array:
30
+ return 5122;
31
+ case Int32Array:
32
+ return 5124;
33
+ default:
34
+ throw new Error(ERR_TYPE_DEDUCTION);
35
+ }
24
36
  }
37
+ /**
38
+ * Converts GL constant to corresponding TYPED ARRAY
39
+ * Used to auto deduce gl parameter types
40
+ * @deprecated Use getTypedArrayFromDataType
41
+ * @param glType
42
+ * @param param1
43
+ * @returns
44
+ */
45
+ // eslint-disable-next-line complexity
25
46
  export function getTypedArrayFromGLType(glType, options) {
26
- const {
27
- clamped = true
28
- } = options || {};
29
- switch (glType) {
30
- case 5126:
31
- return Float32Array;
32
- case 5123:
33
- case 33635:
34
- case 32819:
35
- case 32820:
36
- return Uint16Array;
37
- case 5125:
38
- return Uint32Array;
39
- case 5121:
40
- return clamped ? Uint8ClampedArray : Uint8Array;
41
- case 5120:
42
- return Int8Array;
43
- case 5122:
44
- return Int16Array;
45
- case 5124:
46
- return Int32Array;
47
- default:
48
- throw new Error('Failed to deduce typed array type from GL constant');
49
- }
47
+ const { clamped = true } = options || {};
48
+ // Sorted in some order of likelihood to reduce amount of comparisons
49
+ switch (glType) {
50
+ case 5126:
51
+ return Float32Array;
52
+ case 5123:
53
+ case 33635:
54
+ case 32819:
55
+ case 32820:
56
+ return Uint16Array;
57
+ case 5125:
58
+ return Uint32Array;
59
+ case 5121:
60
+ return clamped ? Uint8ClampedArray : Uint8Array;
61
+ case 5120:
62
+ return Int8Array;
63
+ case 5122:
64
+ return Int16Array;
65
+ case 5124:
66
+ return Int32Array;
67
+ default:
68
+ throw new Error('Failed to deduce typed array type from GL constant');
69
+ }
50
70
  }
71
+ /**
72
+ * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
73
+ * https: *stackoverflow.com/questions/41969562/
74
+ * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
75
+ * @param param0
76
+ */
51
77
  export function flipRows(options) {
52
- const {
53
- data,
54
- width,
55
- height,
56
- bytesPerPixel = 4,
57
- temp
58
- } = options;
59
- const bytesPerRow = width * bytesPerPixel;
60
- const tempBuffer = temp || new Uint8Array(bytesPerRow);
61
- for (let y = 0; y < height / 2; ++y) {
62
- const topOffset = y * bytesPerRow;
63
- const bottomOffset = (height - y - 1) * bytesPerRow;
64
- tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
65
- data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
66
- data.set(tempBuffer, bottomOffset);
67
- }
78
+ const { data, width, height, bytesPerPixel = 4, temp } = options;
79
+ const bytesPerRow = width * bytesPerPixel;
80
+ // make a temp buffer to hold one row
81
+ const tempBuffer = temp || new Uint8Array(bytesPerRow);
82
+ for (let y = 0; y < height / 2; ++y) {
83
+ const topOffset = y * bytesPerRow;
84
+ const bottomOffset = (height - y - 1) * bytesPerRow;
85
+ // make copy of a row on the top half
86
+ tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
87
+ // copy a row from the bottom half to the top
88
+ data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
89
+ // copy the copy of the top half row to the bottom half
90
+ data.set(tempBuffer, bottomOffset);
91
+ }
68
92
  }
69
93
  export function scalePixels(options) {
70
- const {
71
- data,
72
- width,
73
- height
74
- } = options;
75
- const newWidth = Math.round(width / 2);
76
- const newHeight = Math.round(height / 2);
77
- const newData = new Uint8Array(newWidth * newHeight * 4);
78
- for (let y = 0; y < newHeight; y++) {
79
- for (let x = 0; x < newWidth; x++) {
80
- for (let c = 0; c < 4; c++) {
81
- newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
82
- }
94
+ const { data, width, height } = options;
95
+ const newWidth = Math.round(width / 2);
96
+ const newHeight = Math.round(height / 2);
97
+ const newData = new Uint8Array(newWidth * newHeight * 4);
98
+ for (let y = 0; y < newHeight; y++) {
99
+ for (let x = 0; x < newWidth; x++) {
100
+ for (let c = 0; c < 4; c++) {
101
+ newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
102
+ }
103
+ }
83
104
  }
84
- }
85
- return {
86
- data: newData,
87
- width: newWidth,
88
- height: newHeight
89
- };
105
+ return { data: newData, width: newWidth, height: newHeight };
90
106
  }
91
- //# sourceMappingURL=typed-array-utils.js.map