@luma.gl/webgl 9.0.0-beta.3 → 9.0.0-beta.5

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 (237) hide show
  1. package/dist/adapter/converters/device-parameters.js +240 -158
  2. package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
  3. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  4. package/dist/adapter/converters/sampler-parameters.js +73 -68
  5. package/dist/adapter/converters/shader-formats.js +33 -46
  6. package/dist/adapter/converters/texture-formats.d.ts +9 -18
  7. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  8. package/dist/adapter/converters/texture-formats.js +454 -871
  9. package/dist/adapter/converters/vertex-formats.js +52 -61
  10. package/dist/adapter/device-helpers/device-features.d.ts +2 -5
  11. package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
  12. package/dist/adapter/device-helpers/device-features.js +56 -87
  13. package/dist/adapter/device-helpers/device-limits.d.ts +2 -4
  14. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  15. package/dist/adapter/device-helpers/device-limits.js +88 -83
  16. package/dist/adapter/device-helpers/get-device-info.d.ts +1 -1
  17. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  18. package/dist/adapter/device-helpers/get-device-info.js +79 -63
  19. package/dist/adapter/device-helpers/webgl-device-features.d.ts +6 -0
  20. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-features.js +52 -0
  22. package/dist/adapter/device-helpers/webgl-device-info.d.ts +4 -0
  23. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  24. package/dist/adapter/device-helpers/webgl-device-info.js +87 -0
  25. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +50 -0
  26. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  27. package/dist/adapter/device-helpers/webgl-device-limits.js +92 -0
  28. package/dist/adapter/helpers/decode-webgl-types.js +87 -76
  29. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  30. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  31. package/dist/adapter/helpers/get-shader-layout.js +261 -226
  32. package/dist/adapter/helpers/parse-shader-compiler-log.js +46 -37
  33. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  34. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  35. package/dist/adapter/helpers/set-uniform.js +67 -82
  36. package/dist/adapter/helpers/webgl-topology-utils.js +77 -93
  37. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  38. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  39. package/dist/adapter/objects/constants-to-keys.js +18 -12
  40. package/dist/adapter/objects/webgl-renderbuffer.js +76 -80
  41. package/dist/adapter/objects/webgl-resource.d.ts +1 -1
  42. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  43. package/dist/adapter/objects/webgl-resource.js +204 -154
  44. package/dist/adapter/resources/webgl-buffer.d.ts +2 -3
  45. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  46. package/dist/adapter/resources/webgl-buffer.js +160 -119
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-command-buffer.js +268 -171
  49. package/dist/adapter/resources/webgl-command-encoder.js +32 -40
  50. package/dist/adapter/resources/webgl-external-texture.js +92 -1
  51. package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -2
  52. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  53. package/dist/adapter/resources/webgl-framebuffer.js +167 -139
  54. package/dist/adapter/resources/webgl-render-pass.js +121 -95
  55. package/dist/adapter/resources/webgl-render-pipeline.d.ts +11 -1
  56. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pipeline.js +378 -228
  58. package/dist/adapter/resources/webgl-sampler.d.ts +0 -2
  59. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-sampler.js +43 -34
  61. package/dist/adapter/resources/webgl-shader.d.ts +10 -1
  62. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-shader.js +106 -45
  64. package/dist/adapter/resources/webgl-texture.d.ts +2 -6
  65. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  66. package/dist/adapter/resources/webgl-texture.js +614 -699
  67. package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
  68. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  69. package/dist/adapter/resources/webgl-transform-feedback.js +143 -145
  70. package/dist/adapter/resources/webgl-vertex-array.d.ts +1 -1
  71. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  72. package/dist/adapter/resources/webgl-vertex-array.js +229 -158
  73. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  74. package/dist/adapter/webgl-canvas-context.js +58 -37
  75. package/dist/adapter/webgl-device.d.ts +7 -15
  76. package/dist/adapter/webgl-device.d.ts.map +1 -1
  77. package/dist/adapter/webgl-device.js +440 -381
  78. package/dist/classic/accessor.js +132 -102
  79. package/dist/classic/clear.d.ts +2 -2
  80. package/dist/classic/clear.d.ts.map +1 -1
  81. package/dist/classic/clear.js +73 -73
  82. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  83. package/dist/classic/copy-and-blit.js +176 -177
  84. package/dist/classic/format-utils.d.ts +2 -2
  85. package/dist/classic/format-utils.js +38 -32
  86. package/dist/classic/typed-array-utils.js +95 -81
  87. package/dist/context/{polyfill → context}/context-data.d.ts +2 -1
  88. package/dist/context/context/context-data.d.ts.map +1 -0
  89. package/dist/context/context/context-data.js +33 -0
  90. package/dist/context/context/create-browser-context.d.ts +1 -6
  91. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  92. package/dist/context/context/create-browser-context.js +62 -49
  93. package/dist/context/debug/spector.js +54 -50
  94. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  95. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  96. package/dist/context/debug/webgl-developer-tools.js +102 -76
  97. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  98. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  99. package/dist/context/parameters/unified-parameter-api.js +95 -46
  100. package/dist/context/parameters/webgl-parameter-tables.d.ts +110 -99
  101. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  102. package/dist/context/parameters/webgl-parameter-tables.js +456 -404
  103. package/dist/context/state-tracker/deep-array-equal.js +18 -14
  104. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  105. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  106. package/dist/context/state-tracker/track-context-state.js +190 -126
  107. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  108. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  109. package/dist/context/state-tracker/with-parameters.js +45 -29
  110. package/dist/dist.dev.js +2568 -3786
  111. package/dist/index.cjs +1346 -2464
  112. package/dist/index.cjs.map +7 -0
  113. package/dist/index.d.ts +2 -5
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +36 -26
  116. package/dist/types.js +2 -1
  117. package/dist.min.js +9 -42
  118. package/package.json +11 -15
  119. package/src/adapter/converters/device-parameters.ts +0 -1
  120. package/src/adapter/converters/sampler-parameters.ts +0 -17
  121. package/src/adapter/converters/texture-formats.ts +86 -154
  122. package/src/adapter/device-helpers/webgl-device-features.ts +69 -0
  123. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +3 -4
  124. package/src/adapter/device-helpers/{device-limits.ts → webgl-device-limits.ts} +25 -23
  125. package/src/adapter/helpers/get-shader-layout.ts +17 -28
  126. package/src/adapter/helpers/set-uniform.ts +1 -3
  127. package/src/adapter/objects/constants-to-keys.ts +1 -1
  128. package/src/adapter/objects/webgl-renderbuffer.ts +4 -4
  129. package/src/adapter/objects/webgl-resource.ts +3 -18
  130. package/src/adapter/resources/webgl-buffer.ts +6 -11
  131. package/src/adapter/resources/webgl-command-buffer.ts +20 -30
  132. package/src/adapter/resources/webgl-external-texture.ts +2 -3
  133. package/src/adapter/resources/webgl-framebuffer.ts +4 -5
  134. package/src/adapter/resources/webgl-render-pass.ts +7 -7
  135. package/src/adapter/resources/webgl-render-pipeline.ts +106 -31
  136. package/src/adapter/resources/webgl-sampler.ts +5 -9
  137. package/src/adapter/resources/webgl-shader.ts +57 -10
  138. package/src/adapter/resources/webgl-texture.ts +29 -103
  139. package/src/adapter/resources/webgl-transform-feedback.ts +14 -15
  140. package/src/adapter/resources/webgl-vertex-array.ts +16 -18
  141. package/src/adapter/webgl-canvas-context.ts +1 -7
  142. package/src/adapter/webgl-device.ts +18 -67
  143. package/src/classic/clear.ts +13 -14
  144. package/src/classic/copy-and-blit.ts +1 -2
  145. package/src/context/context/context-data.ts +44 -0
  146. package/src/context/context/create-browser-context.ts +7 -32
  147. package/src/context/debug/webgl-developer-tools.ts +6 -8
  148. package/src/context/parameters/unified-parameter-api.ts +3 -3
  149. package/src/context/parameters/webgl-parameter-tables.ts +66 -75
  150. package/src/context/state-tracker/track-context-state.ts +18 -17
  151. package/src/context/state-tracker/with-parameters.ts +1 -1
  152. package/src/index.ts +2 -17
  153. package/dist/adapter/converters/device-parameters.js.map +0 -1
  154. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  155. package/dist/adapter/converters/shader-formats.js.map +0 -1
  156. package/dist/adapter/converters/texture-formats.js.map +0 -1
  157. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  158. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  159. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  160. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  161. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  162. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  163. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  164. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  165. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  166. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  167. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  168. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  169. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  170. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  171. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  172. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  173. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  174. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  175. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  176. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  177. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  178. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  179. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  180. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  181. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  182. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  183. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  184. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  185. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  186. package/dist/adapter/webgl-device.js.map +0 -1
  187. package/dist/classic/accessor.js.map +0 -1
  188. package/dist/classic/clear.js.map +0 -1
  189. package/dist/classic/copy-and-blit.js.map +0 -1
  190. package/dist/classic/format-utils.js.map +0 -1
  191. package/dist/classic/typed-array-utils.js.map +0 -1
  192. package/dist/context/context/create-browser-context.js.map +0 -1
  193. package/dist/context/context/create-headless-context.d.ts +0 -9
  194. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  195. package/dist/context/context/create-headless-context.js +0 -42
  196. package/dist/context/context/create-headless-context.js.map +0 -1
  197. package/dist/context/context/webgl-checks.d.ts +0 -13
  198. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  199. package/dist/context/context/webgl-checks.js +0 -31
  200. package/dist/context/context/webgl-checks.js.map +0 -1
  201. package/dist/context/debug/spector.js.map +0 -1
  202. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  203. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  204. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  205. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  206. package/dist/context/polyfill/context-data.js +0 -12
  207. package/dist/context/polyfill/context-data.js.map +0 -1
  208. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  209. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  210. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  211. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  212. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  213. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  214. package/dist/context/polyfill/polyfill-context.js +0 -87
  215. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  216. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  217. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  218. package/dist/context/polyfill/polyfill-table.js +0 -137
  219. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  220. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  221. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  222. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  223. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  224. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  225. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  226. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  227. package/dist/index.js.map +0 -1
  228. package/dist/types.js.map +0 -1
  229. package/src/adapter/device-helpers/device-features.ts +0 -161
  230. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  231. package/src/context/context/create-headless-context.ts +0 -51
  232. package/src/context/context/webgl-checks.ts +0 -51
  233. package/src/context/polyfill/context-data.ts +0 -30
  234. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  235. package/src/context/polyfill/polyfill-context.ts +0 -104
  236. package/src/context/polyfill/polyfill-table.ts +0 -167
  237. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,192 +1,191 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
1
3
  import { assert, Texture, Framebuffer } from '@luma.gl/core';
2
- import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from "./typed-array-utils.js";
3
- import { glFormatToComponents, glTypeToBytes } from "./format-utils.js";
4
+ import { GL } from '@luma.gl/constants';
5
+ import { getGLTypeFromTypedArray, getTypedArrayFromGLType } from './typed-array-utils';
6
+ import { glFormatToComponents, glTypeToBytes } from './format-utils';
7
+ /**
8
+ * Copies data from a type or a Texture object into ArrayBuffer object.
9
+ * App can provide targetPixelArray or have it auto allocated by this method
10
+ * newly allocated by this method unless provided by app.
11
+ * @deprecated Use CommandEncoder.copyTextureToBuffer and Buffer.read
12
+ * @note Slow requires roundtrip to GPU
13
+ *
14
+ * @param source
15
+ * @param options
16
+ * @returns pixel array,
17
+ */
4
18
  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;
19
+ const { sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, sourceAttachment = GL.COLOR_ATTACHMENT0 // TODO - support gl.readBuffer
20
+ } = options || {};
21
+ let { target = null,
22
+ // following parameters are auto deduced if not provided
23
+ sourceWidth, sourceHeight, sourceType } = options || {};
24
+ const { framebuffer, deleteFramebuffer } = getFramebuffer(source);
25
+ assert(framebuffer);
26
+ const { gl, handle } = framebuffer;
27
+ sourceWidth = sourceWidth || framebuffer.width;
28
+ sourceHeight = sourceHeight || framebuffer.height;
29
+ // TODO - Set and unset gl.readBuffer
30
+ // if (sourceAttachment === GL.COLOR_ATTACHMENT0 && handle === null) {
31
+ // sourceAttachment = GL.FRONT;
32
+ // }
33
+ const attachment = sourceAttachment - GL.COLOR_ATTACHMENT0;
34
+ // assert(attachments[sourceAttachment]);
35
+ // Deduce the type from color attachment if not provided.
36
+ sourceType =
37
+ sourceType ||
38
+ framebuffer.colorAttachments[attachment]?.type ||
39
+ GL.UNSIGNED_BYTE;
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(GL.FRAMEBUFFER, handle);
45
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
46
+ // @ts-expect-error
47
+ gl.bindFramebuffer(GL.FRAMEBUFFER, 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 = GL.RGBA, 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 || GL.UNSIGNED_BYTE;
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 = GL.RGBA } = 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(GL.FRAMEBUFFER, 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 GL.TEXTURE_2D:
140
+ case GL.TEXTURE_CUBE_MAP:
141
+ device.gl.copyTexSubImage2D(textureTarget, targetMipmaplevel, targetX, targetY, sourceX, sourceY, width, height);
142
+ break;
143
+ case GL.TEXTURE_2D_ARRAY:
144
+ case GL.TEXTURE_3D:
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(GL.FRAMEBUFFER, 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 || GL.UNSIGNED_BYTE;
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,37 +1,43 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
1
3
  import { assert } from '@luma.gl/core';
4
+ import { GL } from '@luma.gl/constants';
5
+ // Returns number of components in a specific readPixels WebGL format
2
6
  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
- }
7
+ switch (format) {
8
+ case GL.ALPHA:
9
+ case GL.R32F:
10
+ case GL.RED:
11
+ return 1;
12
+ case GL.RG32F:
13
+ case GL.RG:
14
+ return 2;
15
+ case GL.RGB:
16
+ case GL.RGB32F:
17
+ return 3;
18
+ case GL.RGBA:
19
+ case GL.RGBA32F:
20
+ return 4;
21
+ // TODO: Add support for additional WebGL2 formats
22
+ default:
23
+ assert(false);
24
+ return 0;
25
+ }
21
26
  }
27
+ // Return byte count for given readPixels WebGL type
22
28
  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
- }
29
+ switch (type) {
30
+ case GL.UNSIGNED_BYTE:
31
+ return 1;
32
+ case GL.UNSIGNED_SHORT_5_6_5:
33
+ case GL.UNSIGNED_SHORT_4_4_4_4:
34
+ case GL.UNSIGNED_SHORT_5_5_5_1:
35
+ return 2;
36
+ case GL.FLOAT:
37
+ return 4;
38
+ // TODO: Add support for additional WebGL2 types
39
+ default:
40
+ assert(false);
41
+ return 0;
42
+ }
36
43
  }
37
- //# sourceMappingURL=format-utils.js.map
@@ -1,91 +1,105 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ import { GL } from '@luma.gl/constants';
1
4
  const ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';
5
+ /**
6
+ * Converts TYPED ARRAYS to corresponding GL constant
7
+ * Used to auto deduce gl parameter types
8
+ * @deprecated Use getDataTypeFromTypedArray
9
+ * @param arrayOrType
10
+ * @returns
11
+ */
2
12
  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
- }
13
+ // If typed array, look up constructor
14
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
15
+ switch (type) {
16
+ case Float32Array:
17
+ return GL.FLOAT;
18
+ case Uint16Array:
19
+ return GL.UNSIGNED_SHORT;
20
+ case Uint32Array:
21
+ return GL.UNSIGNED_INT;
22
+ case Uint8Array:
23
+ return GL.UNSIGNED_BYTE;
24
+ case Uint8ClampedArray:
25
+ return GL.UNSIGNED_BYTE;
26
+ case Int8Array:
27
+ return GL.BYTE;
28
+ case Int16Array:
29
+ return GL.SHORT;
30
+ case Int32Array:
31
+ return GL.INT;
32
+ default:
33
+ throw new Error(ERR_TYPE_DEDUCTION);
34
+ }
24
35
  }
36
+ /**
37
+ * Converts GL constant to corresponding TYPED ARRAY
38
+ * Used to auto deduce gl parameter types
39
+ * @deprecated Use getTypedArrayFromDataType
40
+ * @param glType
41
+ * @param param1
42
+ * @returns
43
+ */
44
+ // eslint-disable-next-line complexity
25
45
  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
- }
46
+ const { clamped = true } = options || {};
47
+ // Sorted in some order of likelihood to reduce amount of comparisons
48
+ switch (glType) {
49
+ case GL.FLOAT:
50
+ return Float32Array;
51
+ case GL.UNSIGNED_SHORT:
52
+ case GL.UNSIGNED_SHORT_5_6_5:
53
+ case GL.UNSIGNED_SHORT_4_4_4_4:
54
+ case GL.UNSIGNED_SHORT_5_5_5_1:
55
+ return Uint16Array;
56
+ case GL.UNSIGNED_INT:
57
+ return Uint32Array;
58
+ case GL.UNSIGNED_BYTE:
59
+ return clamped ? Uint8ClampedArray : Uint8Array;
60
+ case GL.BYTE:
61
+ return Int8Array;
62
+ case GL.SHORT:
63
+ return Int16Array;
64
+ case GL.INT:
65
+ return Int32Array;
66
+ default:
67
+ throw new Error('Failed to deduce typed array type from GL constant');
68
+ }
50
69
  }
70
+ /**
71
+ * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)
72
+ * https: *stackoverflow.com/questions/41969562/
73
+ * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels
74
+ * @param param0
75
+ */
51
76
  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
- }
77
+ const { data, width, height, bytesPerPixel = 4, temp } = options;
78
+ const bytesPerRow = width * bytesPerPixel;
79
+ // make a temp buffer to hold one row
80
+ const tempBuffer = temp || new Uint8Array(bytesPerRow);
81
+ for (let y = 0; y < height / 2; ++y) {
82
+ const topOffset = y * bytesPerRow;
83
+ const bottomOffset = (height - y - 1) * bytesPerRow;
84
+ // make copy of a row on the top half
85
+ tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));
86
+ // copy a row from the bottom half to the top
87
+ data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);
88
+ // copy the copy of the top half row to the bottom half
89
+ data.set(tempBuffer, bottomOffset);
90
+ }
68
91
  }
69
92
  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
- }
93
+ const { data, width, height } = options;
94
+ const newWidth = Math.round(width / 2);
95
+ const newHeight = Math.round(height / 2);
96
+ const newData = new Uint8Array(newWidth * newHeight * 4);
97
+ for (let y = 0; y < newHeight; y++) {
98
+ for (let x = 0; x < newWidth; x++) {
99
+ for (let c = 0; c < 4; c++) {
100
+ newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];
101
+ }
102
+ }
83
103
  }
84
- }
85
- return {
86
- data: newData,
87
- width: newWidth,
88
- height: newHeight
89
- };
104
+ return { data: newData, width: newWidth, height: newHeight };
90
105
  }
91
- //# sourceMappingURL=typed-array-utils.js.map
@@ -9,5 +9,6 @@ export interface WebGLContextData {
9
9
  * Gets luma.gl specific state from a context
10
10
  * @returns context state
11
11
  */
12
- export declare function getContextData(gl: WebGLRenderingContext): WebGLContextData;
12
+ export declare function getContextData(gl: WebGL2RenderingContext): WebGLContextData;
13
+ export declare function initializeExtensions(gl: WebGL2RenderingContext): void;
13
14
  //# sourceMappingURL=context-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-data.d.ts","sourceRoot":"","sources":["../../../src/context/context/context-data.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,sBAAsB,GAAG,gBAAgB,CAc3E;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAYrE"}