@luma.gl/webgl 9.0.0-beta.4 → 9.0.0-beta.6

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 (288) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +297 -155
  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 +13 -19
  9. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  10. package/dist/adapter/converters/texture-formats.js +474 -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/device-features.d.ts +2 -5
  14. package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
  15. package/dist/adapter/device-helpers/device-features.js +56 -87
  16. package/dist/adapter/device-helpers/device-limits.d.ts +2 -4
  17. package/dist/adapter/device-helpers/device-limits.d.ts.map +1 -1
  18. package/dist/adapter/device-helpers/device-limits.js +88 -83
  19. package/dist/adapter/device-helpers/get-device-info.d.ts +1 -1
  20. package/dist/adapter/device-helpers/get-device-info.d.ts.map +1 -1
  21. package/dist/adapter/device-helpers/get-device-info.js +79 -63
  22. package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -0
  23. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  24. package/dist/adapter/device-helpers/webgl-device-features.js +86 -0
  25. package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
  26. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  27. package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
  28. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
  29. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  30. package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
  31. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  32. package/dist/adapter/helpers/decode-webgl-types.js +88 -76
  33. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  34. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  35. package/dist/adapter/helpers/get-shader-layout.js +261 -225
  36. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  37. package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
  38. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  39. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  40. package/dist/adapter/helpers/set-uniform.js +68 -82
  41. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  42. package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
  43. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  44. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  45. package/dist/adapter/objects/constants-to-keys.js +19 -12
  46. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  47. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  48. package/dist/adapter/objects/webgl-renderbuffer.js +86 -77
  49. package/dist/adapter/objects/webgl-resource.d.ts +3 -25
  50. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  51. package/dist/adapter/objects/webgl-resource.js +102 -146
  52. package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
  53. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  54. package/dist/adapter/resources/webgl-buffer.js +161 -119
  55. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  56. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-command-buffer.js +266 -168
  58. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  59. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-command-encoder.js +33 -39
  61. package/dist/adapter/resources/webgl-external-texture.js +93 -1
  62. package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -10
  63. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgl-framebuffer.js +167 -137
  65. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  66. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  67. package/dist/adapter/resources/webgl-query-set.js +136 -0
  68. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  69. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  70. package/dist/adapter/resources/webgl-render-pass.js +124 -90
  71. package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
  72. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  73. package/dist/adapter/resources/webgl-render-pipeline.js +356 -221
  74. package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
  75. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  76. package/dist/adapter/resources/webgl-sampler.js +43 -33
  77. package/dist/adapter/resources/webgl-shader.d.ts +12 -2
  78. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-shader.js +114 -47
  80. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  81. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  82. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  83. package/dist/adapter/resources/webgl-texture.d.ts +6 -9
  84. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  85. package/dist/adapter/resources/webgl-texture.js +615 -695
  86. package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
  87. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  88. package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
  89. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  90. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  91. package/dist/adapter/resources/webgl-vertex-array.js +229 -157
  92. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  93. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  94. package/dist/adapter/webgl-canvas-context.js +58 -36
  95. package/dist/adapter/webgl-device.d.ts +34 -40
  96. package/dist/adapter/webgl-device.d.ts.map +1 -1
  97. package/dist/adapter/webgl-device.js +418 -363
  98. package/dist/classic/accessor.d.ts.map +1 -1
  99. package/dist/classic/accessor.js +132 -101
  100. package/dist/classic/clear.d.ts +2 -2
  101. package/dist/classic/clear.d.ts.map +1 -1
  102. package/dist/classic/clear.js +73 -72
  103. package/dist/classic/copy-and-blit.d.ts +1 -1
  104. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  105. package/dist/classic/copy-and-blit.js +175 -175
  106. package/dist/classic/format-utils.d.ts +2 -2
  107. package/dist/classic/format-utils.d.ts.map +1 -1
  108. package/dist/classic/format-utils.js +39 -32
  109. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  110. package/dist/classic/typed-array-utils.js +96 -81
  111. package/dist/context/context/context-data.d.ts +14 -0
  112. package/dist/context/context/context-data.d.ts.map +1 -0
  113. package/dist/context/context/context-data.js +33 -0
  114. package/dist/context/context/create-browser-context.d.ts +1 -6
  115. package/dist/context/context/create-browser-context.d.ts.map +1 -1
  116. package/dist/context/context/create-browser-context.js +62 -49
  117. package/dist/context/debug/spector.d.ts.map +1 -1
  118. package/dist/context/debug/spector.js +55 -50
  119. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  120. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  121. package/dist/context/debug/webgl-developer-tools.js +104 -77
  122. package/dist/context/helpers/create-browser-context.d.ts +35 -0
  123. package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
  124. package/dist/context/helpers/create-browser-context.js +67 -0
  125. package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
  126. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  127. package/dist/context/helpers/webgl-context-data.js +21 -0
  128. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  129. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  130. package/dist/context/helpers/webgl-extensions.js +10 -0
  131. package/dist/context/parameters/unified-parameter-api.d.ts +3 -3
  132. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  133. package/dist/context/parameters/unified-parameter-api.js +94 -44
  134. package/dist/context/parameters/webgl-parameter-tables.d.ts +120 -99
  135. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  136. package/dist/context/parameters/webgl-parameter-tables.js +469 -404
  137. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  138. package/dist/context/state-tracker/deep-array-equal.js +19 -14
  139. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  140. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  141. package/dist/context/state-tracker/track-context-state.js +188 -123
  142. package/dist/context/state-tracker/with-parameters.d.ts +2 -2
  143. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  144. package/dist/context/state-tracker/with-parameters.js +43 -26
  145. package/dist/dist.dev.js +3135 -4142
  146. package/dist/index.cjs +1766 -2717
  147. package/dist/index.cjs.map +7 -0
  148. package/dist/index.d.ts +25 -28
  149. package/dist/index.d.ts.map +1 -1
  150. package/dist/index.js +16 -5
  151. package/dist/types.d.ts.map +1 -1
  152. package/dist/types.js +3 -1
  153. package/dist.min.js +9 -42
  154. package/package.json +11 -15
  155. package/src/adapter/converters/device-parameters.ts +105 -17
  156. package/src/adapter/converters/sampler-parameters.ts +12 -20
  157. package/src/adapter/converters/shader-formats.ts +47 -22
  158. package/src/adapter/converters/texture-formats.ts +138 -185
  159. package/src/adapter/converters/vertex-formats.ts +3 -3
  160. package/src/adapter/device-helpers/webgl-device-features.ts +101 -0
  161. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
  162. package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
  163. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  164. package/src/adapter/helpers/get-shader-layout.ts +21 -31
  165. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  166. package/src/adapter/helpers/set-uniform.ts +3 -4
  167. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  168. package/src/adapter/objects/constants-to-keys.ts +3 -2
  169. package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
  170. package/src/adapter/objects/webgl-resource.ts +7 -140
  171. package/src/adapter/resources/webgl-buffer.ts +10 -14
  172. package/src/adapter/resources/webgl-command-buffer.ts +24 -34
  173. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  174. package/src/adapter/resources/webgl-external-texture.ts +5 -5
  175. package/src/adapter/resources/webgl-framebuffer.ts +38 -34
  176. package/src/adapter/resources/webgl-query-set.ts +171 -0
  177. package/src/adapter/resources/webgl-render-pass.ts +24 -15
  178. package/src/adapter/resources/webgl-render-pipeline.ts +138 -70
  179. package/src/adapter/resources/webgl-sampler.ts +7 -10
  180. package/src/adapter/resources/webgl-shader.ts +65 -11
  181. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  182. package/src/adapter/resources/webgl-texture.ts +38 -105
  183. package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
  184. package/src/adapter/resources/webgl-vertex-array.ts +20 -21
  185. package/src/adapter/webgl-canvas-context.ts +7 -11
  186. package/src/adapter/webgl-device.ts +106 -151
  187. package/src/classic/accessor.ts +5 -4
  188. package/src/classic/clear.ts +25 -20
  189. package/src/classic/copy-and-blit.ts +12 -6
  190. package/src/classic/format-utils.ts +2 -1
  191. package/src/classic/typed-array-utils.ts +3 -7
  192. package/src/context/debug/spector.ts +9 -6
  193. package/src/context/debug/webgl-developer-tools.ts +31 -20
  194. package/src/context/{context → helpers}/create-browser-context.ts +9 -33
  195. package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
  196. package/src/context/helpers/webgl-extensions.ts +17 -0
  197. package/src/context/parameters/unified-parameter-api.ts +5 -4
  198. package/src/context/parameters/webgl-parameter-tables.ts +118 -90
  199. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  200. package/src/context/state-tracker/track-context-state.ts +29 -23
  201. package/src/context/state-tracker/with-parameters.ts +7 -2
  202. package/src/index.ts +4 -18
  203. package/src/types.ts +2 -1
  204. package/dist/adapter/converters/device-parameters.js.map +0 -1
  205. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  206. package/dist/adapter/converters/shader-formats.js.map +0 -1
  207. package/dist/adapter/converters/texture-formats.js.map +0 -1
  208. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  209. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  210. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  211. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  212. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  213. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  214. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  215. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  216. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  217. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  218. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  219. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  220. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  221. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  222. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  223. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  224. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  225. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  226. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  227. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  228. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  229. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  230. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  231. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  232. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  233. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  234. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  235. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  236. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  237. package/dist/adapter/webgl-device.js.map +0 -1
  238. package/dist/classic/accessor.js.map +0 -1
  239. package/dist/classic/clear.js.map +0 -1
  240. package/dist/classic/copy-and-blit.js.map +0 -1
  241. package/dist/classic/format-utils.js.map +0 -1
  242. package/dist/classic/typed-array-utils.js.map +0 -1
  243. package/dist/context/context/create-browser-context.js.map +0 -1
  244. package/dist/context/context/create-headless-context.d.ts +0 -9
  245. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  246. package/dist/context/context/create-headless-context.js +0 -42
  247. package/dist/context/context/create-headless-context.js.map +0 -1
  248. package/dist/context/context/webgl-checks.d.ts +0 -13
  249. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  250. package/dist/context/context/webgl-checks.js +0 -31
  251. package/dist/context/context/webgl-checks.js.map +0 -1
  252. package/dist/context/debug/spector.js.map +0 -1
  253. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  254. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  255. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  256. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  257. package/dist/context/polyfill/context-data.js +0 -12
  258. package/dist/context/polyfill/context-data.js.map +0 -1
  259. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  260. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  261. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  262. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  263. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  264. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  265. package/dist/context/polyfill/polyfill-context.js +0 -87
  266. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  267. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  268. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  269. package/dist/context/polyfill/polyfill-table.js +0 -137
  270. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  271. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  272. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  273. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  274. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  275. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  276. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  277. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  278. package/dist/index.js.map +0 -1
  279. package/dist/types.js.map +0 -1
  280. package/src/adapter/device-helpers/device-features.ts +0 -161
  281. package/src/adapter/device-helpers/device-limits.ts +0 -155
  282. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  283. package/src/context/context/create-headless-context.ts +0 -51
  284. package/src/context/context/webgl-checks.ts +0 -51
  285. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  286. package/src/context/polyfill/polyfill-context.ts +0 -104
  287. package/src/context/polyfill/polyfill-table.ts +0 -167
  288. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,167 +1,239 @@
1
- let _Symbol$toStringTag;
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
2
4
  import { VertexArray, getScratchArray, fillArray } from '@luma.gl/core';
5
+ import { GL } from '@luma.gl/constants';
3
6
  import { getBrowser } from '@probe.gl/env';
4
7
  import { getGLFromVertexType } from "../converters/vertex-formats.js";
5
- _Symbol$toStringTag = Symbol.toStringTag;
8
+ // import {AccessorObject} from '../..';
9
+ // import {getGLFromVertexType} from '../converters/vertex-formats';
10
+ /** VertexArrayObject wrapper */
6
11
  export class WEBGLVertexArray extends VertexArray {
7
- get [_Symbol$toStringTag]() {
8
- return 'VertexArray';
9
- }
10
- static isConstantAttributeZeroSupported(device) {
11
- return device.info.type === 'webgl2' || getBrowser() === 'Chrome';
12
- }
13
- constructor(device, props) {
14
- super(device, props);
15
- this.device = void 0;
16
- this.handle = void 0;
17
- this.buffer = null;
18
- this.bufferValue = null;
19
- this.init = false;
20
- this.device = device;
21
- this.handle = this.device.gl2.createVertexArray();
22
- }
23
- destroy() {
24
- super.destroy();
25
- if (this.buffer) {
26
- var _this$buffer;
27
- (_this$buffer = this.buffer) === null || _this$buffer === void 0 ? void 0 : _this$buffer.destroy();
28
- }
29
- if (this.handle) {
30
- this.device.gl2.deleteVertexArray(this.handle);
31
- this.handle = undefined;
32
- }
33
- }
34
- setIndexBuffer(indexBuffer) {
35
- const buffer = indexBuffer;
36
- if (buffer && buffer.glTarget !== 34963) {
37
- throw new Error('Use .setBuffer()');
38
- }
39
- this.device.gl2.bindVertexArray(this.handle);
40
- this.device.gl2.bindBuffer(34963, buffer ? buffer.handle : null);
41
- this.indexBuffer = buffer;
42
- }
43
- setBuffer(location, attributeBuffer) {
44
- const buffer = attributeBuffer;
45
- if (buffer.glTarget === 34963) {
46
- throw new Error('Use .setIndexBuffer()');
47
- }
48
- const {
49
- size,
50
- type,
51
- stride,
52
- offset,
53
- normalized,
54
- integer,
55
- divisor
56
- } = this._getAccessor(location);
57
- this.device.gl2.bindVertexArray(this.handle);
58
- this.device.gl.bindBuffer(34962, buffer.handle);
59
- if (integer) {
60
- this.device.assertWebGL2();
61
- this.device.gl2.vertexAttribIPointer(location, size, type, stride, offset);
62
- } else {
63
- this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
64
- }
65
- this.device.gl.enableVertexAttribArray(location);
66
- this.device.gl2.vertexAttribDivisor(location, divisor || 0);
67
- this.attributes[location] = buffer;
68
- }
69
- setConstant(location, value) {
70
- this._enable(location, false);
71
- this.attributes[location] = value;
72
- }
73
- bindBeforeRender() {
74
- this.device.gl2.bindVertexArray(this.handle);
75
- if (!this.init) {
76
- const webglBuffer = this.indexBuffer;
77
- this.device.gl2.bindBuffer(34963, (webglBuffer === null || webglBuffer === void 0 ? void 0 : webglBuffer.handle) || null);
78
- this.init = true;
79
- }
80
- this._applyConstantAttributes();
81
- }
82
- unbindAfterRender() {
83
- this.device.gl2.bindVertexArray(null);
84
- }
85
- _applyConstantAttributes() {
86
- for (let location = 0; location < this.maxVertexAttributes; ++location) {
87
- const constant = this.attributes[location];
88
- if (ArrayBuffer.isView(constant)) {
89
- this.device.setConstantAttribute(location, constant);
90
- }
91
- }
92
- }
93
- _getAccessor(location) {
94
- const attributeInfo = this.attributeInfos[location];
95
- if (!attributeInfo) {
96
- throw new Error(`Unknown attribute location ${location}`);
97
- }
98
- const glType = getGLFromVertexType(attributeInfo.bufferDataType);
99
- return {
100
- size: attributeInfo.bufferComponents,
101
- type: glType,
102
- stride: attributeInfo.byteStride,
103
- offset: attributeInfo.byteOffset,
104
- normalized: attributeInfo.normalized,
105
- integer: attributeInfo.integer,
106
- divisor: attributeInfo.stepMode === 'instance' ? 1 : 0
107
- };
108
- }
109
- _enable(location) {
110
- let enable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
111
- const canDisableAttributeZero = WEBGLVertexArray.isConstantAttributeZeroSupported(this.device);
112
- const canDisableAttribute = canDisableAttributeZero || location !== 0;
113
- if (enable || canDisableAttribute) {
114
- location = Number(location);
115
- this.device.gl2.bindVertexArray(this.handle);
116
- if (enable) {
12
+ get [Symbol.toStringTag]() {
13
+ return 'VertexArray';
14
+ }
15
+ device;
16
+ handle;
17
+ /** Attribute 0 buffer constant */
18
+ buffer = null;
19
+ bufferValue = null;
20
+ /** * Attribute 0 can not be disable on most desktop OpenGL based browsers */
21
+ static isConstantAttributeZeroSupported(device) {
22
+ return getBrowser() === 'Chrome';
23
+ }
24
+ // Create a VertexArray
25
+ constructor(device, props) {
26
+ super(device, props);
27
+ this.device = device;
28
+ this.handle = this.device.gl.createVertexArray();
29
+ }
30
+ destroy() {
31
+ super.destroy();
32
+ if (this.buffer) {
33
+ this.buffer?.destroy();
34
+ }
35
+ if (this.handle) {
36
+ this.device.gl.deleteVertexArray(this.handle);
37
+ // @ts-expect-error read-only/undefined
38
+ this.handle = undefined;
39
+ }
40
+ // Auto-delete elements?
41
+ // return [this.elements];
42
+ }
43
+ /**
44
+ // Set (bind/unbind) an elements buffer, for indexed rendering.
45
+ // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER or null. Constants not supported
46
+ *
47
+ * @param elementBuffer
48
+ */
49
+ setIndexBuffer(indexBuffer) {
50
+ const buffer = indexBuffer;
51
+ // Explicitly allow `null` to support clearing the index buffer
52
+ if (buffer && buffer.glTarget !== GL.ELEMENT_ARRAY_BUFFER) {
53
+ throw new Error('Use .setBuffer()');
54
+ }
55
+ // In WebGL The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject
56
+ this.device.gl.bindVertexArray(this.handle);
57
+ // TODO - this initial binding does not seem to take effect? see bindBeforeRender()
58
+ this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, buffer ? buffer.handle : null);
59
+ // log.log(1, 'VertexArray.setIndexBuffer', indexBuffer)();
60
+ // log.log(1, `Binding vertex array ${this.id}`, buffer?.id)();
61
+ this.indexBuffer = buffer;
62
+ }
63
+ /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
64
+ setBuffer(location, attributeBuffer) {
65
+ const buffer = attributeBuffer;
66
+ // Sanity check target
67
+ if (buffer.glTarget === GL.ELEMENT_ARRAY_BUFFER) {
68
+ throw new Error('Use .setIndexBuffer()');
69
+ }
70
+ const { size, type, stride, offset, normalized, integer, divisor } = this._getAccessor(location);
71
+ this.device.gl.bindVertexArray(this.handle);
72
+ // A non-zero buffer object must be bound to the GL_ARRAY_BUFFER target
73
+ this.device.gl.bindBuffer(GL.ARRAY_BUFFER, buffer.handle);
74
+ // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
75
+ if (integer) {
76
+ this.device.gl.vertexAttribIPointer(location, size, type, stride, offset);
77
+ }
78
+ else {
79
+ // Attaches ARRAY_BUFFER with specified buffer format to location
80
+ this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
81
+ }
82
+ // Mark as non-constant
117
83
  this.device.gl.enableVertexAttribArray(location);
118
- } else {
119
- this.device.gl.disableVertexAttribArray(location);
120
- }
121
- this.device.gl2.bindVertexArray(null);
122
- }
123
- }
124
- getConstantBuffer(elementCount, value) {
125
- const constantValue = normalizeConstantArrayValue(value);
126
- const byteLength = constantValue.byteLength * elementCount;
127
- const length = constantValue.length * elementCount;
128
- if (this.buffer && byteLength !== this.buffer.byteLength) {
129
- throw new Error(`Buffer size is immutable, byte length ${byteLength} !== ${this.buffer.byteLength}.`);
130
- }
131
- let updateNeeded = !this.buffer;
132
- this.buffer = this.buffer || this.device.createBuffer({
133
- byteLength
134
- });
135
- updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
136
- if (updateNeeded) {
137
- const typedArray = getScratchArray(value.constructor, length);
138
- fillArray({
139
- target: typedArray,
140
- source: constantValue,
141
- start: 0,
142
- count: length
143
- });
144
- this.buffer.write(typedArray);
145
- this.bufferValue = value;
146
- }
147
- return this.buffer;
148
- }
84
+ // Set the step mode 0=vertex, 1=instance
85
+ this.device.gl.vertexAttribDivisor(location, divisor || 0);
86
+ this.attributes[location] = buffer;
87
+ }
88
+ /** Set a location in vertex attributes array to a constant value, disables the location */
89
+ setConstantWebGL(location, value) {
90
+ this._enable(location, false);
91
+ this.attributes[location] = value;
92
+ }
93
+ init = false;
94
+ bindBeforeRender() {
95
+ this.device.gl.bindVertexArray(this.handle);
96
+ // TODO - the initial bind does not seem to take effect.
97
+ if (!this.init) {
98
+ // log.log(1, `Binding vertex array ${this.id}`, this.indexBuffer?.id)();
99
+ const webglBuffer = this.indexBuffer;
100
+ this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, webglBuffer?.handle || null);
101
+ this.init = true;
102
+ }
103
+ this._applyConstantAttributes();
104
+ }
105
+ unbindAfterRender() {
106
+ // log.log(1, `Unbinding vertex array ${this.id}`)();
107
+ // TODO technically this is not necessary, but we might be interfacing
108
+ // with code that does not use vertex array objects
109
+ this.device.gl.bindVertexArray(null);
110
+ // this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
111
+ }
112
+ // Internal methods
113
+ /**
114
+ * Constant attributes need to be reset before every draw call
115
+ * Any attribute that is disabled in the current vertex array object
116
+ * is read from the context's global constant value for that attribute location.
117
+ * @note Constant attributes are only supported in WebGL, not in WebGPU
118
+ */
119
+ _applyConstantAttributes() {
120
+ for (let location = 0; location < this.maxVertexAttributes; ++location) {
121
+ const constant = this.attributes[location];
122
+ // A typed array means this is a constant
123
+ if (ArrayBuffer.isView(constant)) {
124
+ this.device.setConstantAttributeWebGL(location, constant);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Set a location in vertex attributes array to a buffer, enables the location, sets divisor
130
+ * @note requires vertex array to be bound
131
+ */
132
+ // protected _setAttributeLayout(location: number): void {
133
+ // const {size, type, stride, offset, normalized, integer, divisor} = this._getAccessor(location);
134
+ // // WebGL2 supports *integer* data formats, i.e. GPU will see integer values
135
+ // if (integer) {
136
+ // this.device.gl.vertexAttribIPointer(location, size, type, stride, offset);
137
+ // } else {
138
+ // // Attaches ARRAY_BUFFER with specified buffer format to location
139
+ // this.device.gl.vertexAttribPointer(location, size, type, normalized, stride, offset);
140
+ // }
141
+ // this.device.gl.vertexAttribDivisor(location, divisor || 0);
142
+ // }
143
+ /** Get an accessor from the */
144
+ _getAccessor(location) {
145
+ const attributeInfo = this.attributeInfos[location];
146
+ if (!attributeInfo) {
147
+ throw new Error(`Unknown attribute location ${location}`);
148
+ }
149
+ const glType = getGLFromVertexType(attributeInfo.bufferDataType);
150
+ return {
151
+ size: attributeInfo.bufferComponents,
152
+ type: glType,
153
+ stride: attributeInfo.byteStride,
154
+ offset: attributeInfo.byteOffset,
155
+ normalized: attributeInfo.normalized,
156
+ // it is the shader attribute declaration, not the vertex memory format,
157
+ // that determines if the data in the buffer will be treated as integers.
158
+ //
159
+ // Also note that WebGL supports assigning non-normalized integer data to floating point attributes,
160
+ // but as far as we can tell, WebGPU does not.
161
+ integer: attributeInfo.integer,
162
+ divisor: attributeInfo.stepMode === 'instance' ? 1 : 0
163
+ };
164
+ }
165
+ /**
166
+ * Enabling an attribute location makes it reference the currently bound buffer
167
+ * Disabling an attribute location makes it reference the global constant value
168
+ * TODO - handle single values for size 1 attributes?
169
+ * TODO - convert classic arrays based on known type?
170
+ */
171
+ _enable(location, enable = true) {
172
+ // Attribute 0 cannot be disabled in most desktop OpenGL based browsers...
173
+ const canDisableAttributeZero = WEBGLVertexArray.isConstantAttributeZeroSupported(this.device);
174
+ const canDisableAttribute = canDisableAttributeZero || location !== 0;
175
+ if (enable || canDisableAttribute) {
176
+ location = Number(location);
177
+ this.device.gl.bindVertexArray(this.handle);
178
+ if (enable) {
179
+ this.device.gl.enableVertexAttribArray(location);
180
+ }
181
+ else {
182
+ this.device.gl.disableVertexAttribArray(location);
183
+ }
184
+ this.device.gl.bindVertexArray(null);
185
+ }
186
+ }
187
+ /**
188
+ * Provide a means to create a buffer that is equivalent to a constant.
189
+ * NOTE: Desktop OpenGL cannot disable attribute 0.
190
+ * https://stackoverflow.com/questions/20305231/webgl-warning-attribute-0-is-disabled-
191
+ * this-has-significant-performance-penalty
192
+ */
193
+ getConstantBuffer(elementCount, value) {
194
+ // Create buffer only when needed, and reuse it (avoids inflating buffer creation statistics)
195
+ const constantValue = normalizeConstantArrayValue(value);
196
+ const byteLength = constantValue.byteLength * elementCount;
197
+ const length = constantValue.length * elementCount;
198
+ if (this.buffer && byteLength !== this.buffer.byteLength) {
199
+ throw new Error(`Buffer size is immutable, byte length ${byteLength} !== ${this.buffer.byteLength}.`);
200
+ }
201
+ let updateNeeded = !this.buffer;
202
+ this.buffer = this.buffer || this.device.createBuffer({ byteLength });
203
+ // Reallocate and update contents if needed
204
+ updateNeeded = updateNeeded || !compareConstantArrayValues(constantValue, this.bufferValue);
205
+ if (updateNeeded) {
206
+ // Create a typed array that is big enough, and fill it with the required data
207
+ const typedArray = getScratchArray(value.constructor, length);
208
+ fillArray({ target: typedArray, source: constantValue, start: 0, count: length });
209
+ this.buffer.write(typedArray);
210
+ this.bufferValue = value;
211
+ }
212
+ return this.buffer;
213
+ }
149
214
  }
215
+ // HELPER FUNCTIONS
216
+ /**
217
+ * TODO - convert Arrays based on known type? (read type from accessor, don't assume Float32Array)
218
+ * TODO - handle single values for size 1 attributes?
219
+ */
150
220
  function normalizeConstantArrayValue(arrayValue) {
151
- if (Array.isArray(arrayValue)) {
152
- return new Float32Array(arrayValue);
153
- }
154
- return arrayValue;
221
+ if (Array.isArray(arrayValue)) {
222
+ return new Float32Array(arrayValue);
223
+ }
224
+ return arrayValue;
155
225
  }
226
+ /**
227
+ *
228
+ */
156
229
  function compareConstantArrayValues(v1, v2) {
157
- if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
158
- return false;
159
- }
160
- for (let i = 0; i < v1.length; ++i) {
161
- if (v1[i] !== v2[i]) {
162
- return false;
163
- }
164
- }
165
- return true;
230
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
231
+ return false;
232
+ }
233
+ for (let i = 0; i < v1.length; ++i) {
234
+ if (v1[i] !== v2[i]) {
235
+ return false;
236
+ }
237
+ }
238
+ return true;
166
239
  }
167
- //# sourceMappingURL=webgl-vertex-array.js.map
@@ -1,7 +1,7 @@
1
1
  import type { CanvasContextProps } from '@luma.gl/core';
2
2
  import { CanvasContext } from '@luma.gl/core';
3
- import { WebGLDevice } from './webgl-device';
4
- import { WEBGLFramebuffer } from './resources/webgl-framebuffer';
3
+ import { WebGLDevice } from "./webgl-device.js";
4
+ import { WEBGLFramebuffer } from "./resources/webgl-framebuffer.js";
5
5
  /**
6
6
  * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-canvas-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,OAAO,CAAC,YAAY,CAAiC;gBAEzC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,kBAAkB;IAS1D,qBAAqB,IAAI,gBAAgB;IAOzC,sDAAsD;IACtD,MAAM;IASN;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAiB7F,MAAM;CAOP"}
1
+ {"version":3,"file":"webgl-canvas-context.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-canvas-context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAC3C,OAAO,EAAC,gBAAgB,EAAC,yCAAsC;AAE/D;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,aAAa;IACnD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,OAAO,CAAC,YAAY,CAAiC;gBAEzC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,kBAAkB;IAS1D,qBAAqB,IAAI,gBAAgB;IAOzC,sDAAsD;IACtD,MAAM;IAUN;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAC,GAAG,IAAI;IAW7F,MAAM;CAOP"}
@@ -1,43 +1,65 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { CanvasContext } from '@luma.gl/core';
2
5
  import { WEBGLFramebuffer } from "./resources/webgl-framebuffer.js";
6
+ /**
7
+ * A WebGL Canvas Context which manages the canvas and handles drawing buffer resizing etc
8
+ */
3
9
  export class WebGLCanvasContext extends CanvasContext {
4
- constructor(device, props) {
5
- super(props);
6
- this.device = void 0;
7
- this.presentationSize = void 0;
8
- this._framebuffer = null;
9
- this.device = device;
10
- this.presentationSize = [-1, -1];
11
- this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
12
- this.update();
13
- }
14
- getCurrentFramebuffer() {
15
- this.update();
16
- this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, {
17
- handle: null
18
- });
19
- return this._framebuffer;
20
- }
21
- update() {
22
- const size = this.getPixelSize();
23
- const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
24
- if (sizeChanged) {
25
- this.presentationSize = size;
26
- this.resize();
10
+ device;
11
+ presentationSize;
12
+ _framebuffer = null;
13
+ constructor(device, props) {
14
+ // Note: Base class creates / looks up the canvas (unless under Node.js)
15
+ super(props);
16
+ this.device = device;
17
+ this.presentationSize = [-1, -1];
18
+ this._setAutoCreatedCanvasId(`${this.device.id}-canvas`);
19
+ this.update();
27
20
  }
28
- }
29
- resize(options) {
30
- if (!this.device.gl) return;
31
- if (this.canvas) {
32
- const devicePixelRatio = this.getDevicePixelRatio(options === null || options === void 0 ? void 0 : options.useDevicePixels);
33
- this.setDevicePixelRatio(devicePixelRatio, options);
34
- return;
21
+ getCurrentFramebuffer() {
22
+ this.update();
23
+ // Setting handle to null returns a reference to the default framebuffer
24
+ this._framebuffer = this._framebuffer || new WEBGLFramebuffer(this.device, { handle: null });
25
+ return this._framebuffer;
35
26
  }
36
- const ext = this.device.gl.getExtension('STACKGL_resize_drawingbuffer');
37
- if (ext && options && 'width' in options && 'height' in options) {
38
- ext.resize(options.width, options.height);
27
+ /** Resizes and updates render targets if necessary */
28
+ update() {
29
+ const size = this.getPixelSize();
30
+ const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
31
+ if (sizeChanged) {
32
+ this.presentationSize = size;
33
+ this.resize();
34
+ }
35
+ }
36
+ /**
37
+ * Resize the canvas' drawing buffer.
38
+ *
39
+ * Can match the canvas CSS size, and optionally also consider devicePixelRatio
40
+ * Can be called every frame
41
+ *
42
+ * Regardless of size, the drawing buffer will always be scaled to the viewport, but
43
+ * for best visual results, usually set to either:
44
+ * canvas CSS width x canvas CSS height
45
+ * canvas CSS width * devicePixelRatio x canvas CSS height * devicePixelRatio
46
+ * See http://webgl2fundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
47
+ */
48
+ resize(options) {
49
+ if (!this.device.gl)
50
+ return;
51
+ // Resize browser context .
52
+ if (this.canvas) {
53
+ const devicePixelRatio = this.getDevicePixelRatio(options?.useDevicePixels);
54
+ this.setDevicePixelRatio(devicePixelRatio, options);
55
+ return;
56
+ }
57
+ }
58
+ commit() {
59
+ // gl.commit was ultimately removed from the WebGL standard??
60
+ // if (this.offScreen && this.gl.commit) {
61
+ // // @ts-expect-error gl.commit is not officially part of WebGL2RenderingContext
62
+ // this.gl.commit();
63
+ // }
39
64
  }
40
- }
41
- commit() {}
42
65
  }
43
- //# sourceMappingURL=webgl-canvas-context.js.map