@luma.gl/webgl 9.0.0-beta.4 → 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,399 +1,458 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
1
3
  import { Device, CanvasContext, log, uid, assert } from '@luma.gl/core';
2
4
  import { isBrowser } from '@probe.gl/env';
3
- import { polyfillContext } from "../context/polyfill/polyfill-context.js";
4
- import { popContextState, pushContextState, trackContextState } from "../context/state-tracker/track-context-state.js";
5
- import { createBrowserContext } from "../context/context/create-browser-context.js";
6
- import { createHeadlessContext, isHeadlessGLRegistered } from "../context/context/create-headless-context.js";
7
- import { getDeviceInfo } from "./device-helpers/get-device-info.js";
8
- import { getDeviceFeatures } from "./device-helpers/device-features.js";
9
- import { getDeviceLimits, getWebGLLimits } from "./device-helpers/device-limits.js";
10
- import { WebGLCanvasContext } from "./webgl-canvas-context.js";
11
- import { loadSpectorJS, initializeSpectorJS } from "../context/debug/spector.js";
12
- import { loadWebGLDeveloperTools, makeDebugContext } from "../context/debug/webgl-developer-tools.js";
13
- import { isTextureFormatSupported, isTextureFormatRenderable, isTextureFormatFilterable } from "./converters/texture-formats.js";
14
- import { WEBGLBuffer } from "./resources/webgl-buffer.js";
15
- import { WEBGLShader } from "./resources/webgl-shader.js";
16
- import { WEBGLSampler } from "./resources/webgl-sampler.js";
17
- import { WEBGLTexture } from "./resources/webgl-texture.js";
18
- import { WEBGLFramebuffer } from "./resources/webgl-framebuffer.js";
19
- import { WEBGLRenderPass } from "./resources/webgl-render-pass.js";
20
- import { WEBGLRenderPipeline } from "./resources/webgl-render-pipeline.js";
21
- import { WEBGLCommandEncoder } from "./resources/webgl-command-encoder.js";
22
- import { WEBGLVertexArray } from "./resources/webgl-vertex-array.js";
23
- import { WEBGLTransformFeedback } from "./resources/webgl-transform-feedback.js";
24
- import { readPixelsToArray, readPixelsToBuffer } from "../classic/copy-and-blit.js";
25
- import { setGLParameters, getGLParameters } from "../context/parameters/unified-parameter-api.js";
26
- import { withGLParameters } from "../context/state-tracker/with-parameters.js";
27
- import { clear } from "../classic/clear.js";
5
+ import { popContextState, pushContextState, trackContextState } from '../context/state-tracker/track-context-state';
6
+ import { createBrowserContext } from '../context/context/create-browser-context';
7
+ import { getDeviceInfo } from './device-helpers/webgl-device-info';
8
+ import { getDeviceFeatures } from './device-helpers/webgl-device-features';
9
+ import { getDeviceLimits, getWebGLLimits } from './device-helpers/webgl-device-limits';
10
+ import { WebGLCanvasContext } from './webgl-canvas-context';
11
+ import { loadSpectorJS, initializeSpectorJS } from '../context/debug/spector';
12
+ import { loadWebGLDeveloperTools, makeDebugContext } from '../context/debug/webgl-developer-tools';
13
+ import { isTextureFormatSupported, isTextureFormatRenderable, isTextureFormatFilterable } from './converters/texture-formats';
14
+ import { WEBGLBuffer } from './resources/webgl-buffer';
15
+ import { WEBGLShader } from './resources/webgl-shader';
16
+ import { WEBGLSampler } from './resources/webgl-sampler';
17
+ import { WEBGLTexture } from './resources/webgl-texture';
18
+ import { WEBGLFramebuffer } from './resources/webgl-framebuffer';
19
+ import { WEBGLRenderPass } from './resources/webgl-render-pass';
20
+ import { WEBGLRenderPipeline } from './resources/webgl-render-pipeline';
21
+ import { WEBGLCommandEncoder } from './resources/webgl-command-encoder';
22
+ import { WEBGLVertexArray } from './resources/webgl-vertex-array';
23
+ import { WEBGLTransformFeedback } from './resources/webgl-transform-feedback';
24
+ import { readPixelsToArray, readPixelsToBuffer } from '../classic/copy-and-blit';
25
+ import { setGLParameters, getGLParameters } from '../context/parameters/unified-parameter-api';
26
+ import { withGLParameters } from '../context/state-tracker/with-parameters';
27
+ import { clear } from '../classic/clear';
28
28
  const LOG_LEVEL = 1;
29
+ /** WebGPU style Device API for a WebGL context */
29
30
  export class WebGLDevice extends Device {
30
- static isSupported() {
31
- return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();
32
- }
33
- get features() {
34
- this._features = this._features || getDeviceFeatures(this.gl);
35
- return this._features;
36
- }
37
- get limits() {
38
- this._limits = this._limits || getDeviceLimits(this.gl);
39
- return this._limits;
40
- }
41
- static attach(gl) {
42
- if (gl instanceof WebGLDevice) {
43
- return gl;
44
- }
45
- if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof Device) {
46
- return gl.device;
47
- }
48
- if (!isWebGL(gl)) {
49
- throw new Error('Invalid WebGLRenderingContext');
50
- }
51
- return new WebGLDevice({
52
- gl: gl
53
- });
54
- }
55
- static async create() {
56
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
57
- log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
58
- if (typeof props.canvas === 'string') {
59
- await CanvasContext.pageLoaded;
60
- }
61
- if (log.get('debug') || props.debug) {
62
- await loadWebGLDeveloperTools();
63
- }
64
- const {
65
- spector
66
- } = props;
67
- if (log.get('spector') || spector) {
68
- await loadSpectorJS();
69
- }
70
- log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
71
- if (props.gl && props.gl.device) {
72
- return WebGLDevice.attach(props.gl);
73
- }
74
- const device = new WebGLDevice(props);
75
- const message = `\
31
+ //
32
+ // Public `Device` API
33
+ //
34
+ static type = 'webgl';
35
+ static isSupported() {
36
+ return typeof WebGL2RenderingContext !== 'undefined';
37
+ }
38
+ info;
39
+ canvasContext;
40
+ handle;
41
+ get features() {
42
+ this._features = this._features || getDeviceFeatures(this.gl);
43
+ return this._features;
44
+ }
45
+ get limits() {
46
+ this._limits = this._limits || getDeviceLimits(this.gl);
47
+ return this._limits;
48
+ }
49
+ lost;
50
+ _resolveContextLost;
51
+ _features;
52
+ _limits;
53
+ //
54
+ // Static methods, expected to be present by `luma.createDevice()`
55
+ //
56
+ /**
57
+ * Get a device instance from a GL context
58
+ * Creates and instruments the device if not already created
59
+ * @param gl
60
+ * @returns
61
+ */
62
+ static attach(gl) {
63
+ if (gl instanceof WebGLDevice) {
64
+ return gl;
65
+ }
66
+ // @ts-expect-error
67
+ if (gl?.device instanceof Device) {
68
+ // @ts-expect-error
69
+ return gl.device;
70
+ }
71
+ if (!isWebGL(gl)) {
72
+ throw new Error('Invalid WebGL2RenderingContext');
73
+ }
74
+ return new WebGLDevice({ gl: gl });
75
+ }
76
+ static async create(props = {}) {
77
+ log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
78
+ // Wait for page to load. Only wait when props. canvas is string
79
+ // to avoid setting page onload callback unless necessary
80
+ if (typeof props.canvas === 'string') {
81
+ await CanvasContext.pageLoaded;
82
+ }
83
+ // Load webgl and spector debug scripts from CDN if requested
84
+ if (log.get('debug') || props.debug) {
85
+ await loadWebGLDeveloperTools();
86
+ }
87
+ // @ts-expect-error spector not on props
88
+ const { spector } = props;
89
+ if (log.get('spector') || spector) {
90
+ await loadSpectorJS();
91
+ }
92
+ log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
93
+ // @ts-expect-error
94
+ if (props.gl && props.gl.device) {
95
+ return WebGLDevice.attach(props.gl);
96
+ }
97
+ const device = new WebGLDevice(props);
98
+ // Log some debug info about the newly created context
99
+ const message = `\
76
100
  Created ${device.info.type}${device.debug ? ' debug' : ''} context: \
77
101
  ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
78
- log.probe(LOG_LEVEL, message)();
79
- log.table(LOG_LEVEL, device.info)();
80
- log.groupEnd(LOG_LEVEL)();
81
- return device;
82
- }
83
- constructor(props) {
84
- var _props$gl, _props$gl2;
85
- super({
86
- ...props,
87
- id: props.id || uid('webgl-device')
88
- });
89
- this.info = void 0;
90
- this.canvasContext = void 0;
91
- this.handle = void 0;
92
- this.lost = void 0;
93
- this._resolveContextLost = void 0;
94
- this._features = void 0;
95
- this._limits = void 0;
96
- this.renderPass = null;
97
- this.gl = void 0;
98
- this.gl2 = null;
99
- this.debug = false;
100
- this.isWebGL1 = void 0;
101
- this.isWebGL2 = void 0;
102
- this._canvasSizeInfo = {
103
- clientWidth: 0,
104
- clientHeight: 0,
105
- devicePixelRatio: 1
106
- };
107
- this._extensions = {};
108
- this._polyfilled = false;
109
- this.spector = void 0;
110
- this._webglLimits = void 0;
111
- this._constants = void 0;
112
- const device = (_props$gl = props.gl) === null || _props$gl === void 0 ? void 0 : _props$gl.device;
113
- if (device) {
114
- throw new Error(`WebGL context already attached to device ${device.id}`);
115
- }
116
- const canvas = props.canvas || ((_props$gl2 = props.gl) === null || _props$gl2 === void 0 ? void 0 : _props$gl2.canvas);
117
- this.canvasContext = new WebGLCanvasContext(this, {
118
- ...props,
119
- canvas
120
- });
121
- this.lost = new Promise(resolve => {
122
- this._resolveContextLost = resolve;
123
- });
124
- const onContextLost = event => {
125
- var _this$_resolveContext;
126
- return (_this$_resolveContext = this._resolveContextLost) === null || _this$_resolveContext === void 0 ? void 0 : _this$_resolveContext.call(this, {
127
- reason: 'destroyed',
128
- message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
129
- });
130
- };
131
- let gl = props.gl || null;
132
- gl = gl || (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {
133
- ...props,
134
- onContextLost
135
- }) : null);
136
- gl = gl || (!isBrowser() ? createHeadlessContext({
137
- ...props,
138
- onContextLost
139
- }) : null);
140
- if (!gl) {
141
- throw new Error('WebGL context creation failed');
142
- }
143
- this.handle = gl;
144
- this.gl = this.handle;
145
- this.gl2 = this.gl;
146
- this.isWebGL2 = isWebGL2(this.gl);
147
- this.isWebGL1 = !this.isWebGL2;
148
- this.canvasContext.resize();
149
- this.info = getDeviceInfo(this.gl);
150
- this.gl.device = this;
151
- this.gl._version = this.isWebGL2 ? 2 : 1;
152
- polyfillContext(this.gl);
153
- const {
154
- enable = true,
155
- copyState = false
156
- } = props;
157
- trackContextState(this.gl, {
158
- enable,
159
- copyState,
160
- log: function () {
161
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
162
- args[_key] = arguments[_key];
102
+ log.probe(LOG_LEVEL, message)();
103
+ log.table(LOG_LEVEL, device.info)();
104
+ log.groupEnd(LOG_LEVEL)();
105
+ return device;
106
+ }
107
+ //
108
+ // Public API
109
+ //
110
+ constructor(props) {
111
+ super({ ...props, id: props.id || uid('webgl-device') });
112
+ // If attaching to an already attached context, return the attached device
113
+ // @ts-expect-error device is attached to context
114
+ const device = props.gl?.device;
115
+ if (device) {
116
+ throw new Error(`WebGL context already attached to device ${device.id}`);
117
+ }
118
+ // Create and instrument context
119
+ const canvas = props.canvas || props.gl?.canvas;
120
+ this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
121
+ this.lost = new Promise(resolve => {
122
+ this._resolveContextLost = resolve;
123
+ });
124
+ const onContextLost = (event) => this._resolveContextLost?.({
125
+ reason: 'destroyed',
126
+ message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
127
+ });
128
+ let gl = props.gl || null;
129
+ gl =
130
+ gl ||
131
+ (isBrowser()
132
+ ? createBrowserContext(this.canvasContext.canvas, { ...props, onContextLost })
133
+ : null);
134
+ if (!gl) {
135
+ throw new Error('WebGL context creation failed');
163
136
  }
164
- return log.log(1, ...args)();
165
- }
166
- });
167
- if (isBrowser() && props.debug) {
168
- this.gl = makeDebugContext(this.gl, {
169
- ...props,
170
- webgl2: this.isWebGL2,
171
- throwOnError: true
172
- });
173
- this.gl2 = this.gl;
174
- this.debug = true;
175
- log.level = Math.max(log.level, 1);
176
- log.warn('WebGL debug mode activated. Performance reduced.')();
177
- }
178
- if (isBrowser() && props.spector) {
179
- const canvas = this.handle.canvas || props.canvas;
180
- this.spector = initializeSpectorJS({
181
- ...this.props,
182
- canvas
183
- });
184
- }
185
- }
186
- destroy() {
187
- const ext = this.gl.getExtension('STACKGL_destroy_context');
188
- if (ext) {
189
- ext.destroy();
190
- }
191
- }
192
- get isLost() {
193
- return this.gl.isContextLost();
194
- }
195
- getSize() {
196
- return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
197
- }
198
- isTextureFormatSupported(format) {
199
- return isTextureFormatSupported(this.gl, format);
200
- }
201
- isTextureFormatFilterable(format) {
202
- return isTextureFormatFilterable(this.gl, format);
203
- }
204
- isTextureFormatRenderable(format) {
205
- return isTextureFormatRenderable(this.gl, format);
206
- }
207
- assertWebGL2() {
208
- if (!this.gl2) {
209
- throw new Error('Requires WebGL2');
210
- }
211
- return this.gl2;
212
- }
213
- createCanvasContext(props) {
214
- throw new Error('WebGL only supports a single canvas');
215
- }
216
- createBuffer(props) {
217
- const newProps = this._getBufferProps(props);
218
- return new WEBGLBuffer(this, newProps);
219
- }
220
- _createTexture(props) {
221
- return new WEBGLTexture(this, props);
222
- }
223
- createExternalTexture(props) {
224
- throw new Error('createExternalTexture() not implemented');
225
- }
226
- createSampler(props) {
227
- return new WEBGLSampler(this, props);
228
- }
229
- createShader(props) {
230
- return new WEBGLShader(this, props);
231
- }
232
- createFramebuffer(props) {
233
- return new WEBGLFramebuffer(this, props);
234
- }
235
- createRenderPipeline(props) {
236
- return new WEBGLRenderPipeline(this, props);
237
- }
238
- createVertexArray(props) {
239
- return new WEBGLVertexArray(this, props);
240
- }
241
- beginRenderPass(props) {
242
- return new WEBGLRenderPass(this, props);
243
- }
244
- createComputePipeline(props) {
245
- throw new Error('ComputePipeline not supported in WebGL');
246
- }
247
- beginComputePass(props) {
248
- throw new Error('ComputePass not supported in WebGL');
249
- }
250
- createTransformFeedback(props) {
251
- return new WEBGLTransformFeedback(this, props);
252
- }
253
- getDefaultRenderPass() {
254
- this.renderPass = this.renderPass || this.beginRenderPass({
255
- framebuffer: this.canvasContext.getCurrentFramebuffer()
256
- });
257
- return this.renderPass;
258
- }
259
- createCommandEncoder(props) {
260
- return new WEBGLCommandEncoder(this, props);
261
- }
262
- submit() {
263
- var _this$renderPass;
264
- (_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.end();
265
- this.renderPass = null;
266
- }
267
- readPixelsToArrayWebGL(source, options) {
268
- return readPixelsToArray(source, options);
269
- }
270
- readPixelsToBufferWebGL(source, options) {
271
- return readPixelsToBuffer(source, options);
272
- }
273
- setParametersWebGL(parameters) {
274
- setGLParameters(this, parameters);
275
- }
276
- getParametersWebGL(parameters) {
277
- return getGLParameters(this, parameters);
278
- }
279
- withParametersWebGL(parameters, func) {
280
- withGLParameters(this, parameters, func);
281
- }
282
- clearWebGL(options) {
283
- clear(this, options);
284
- }
285
- get webglLimits() {
286
- this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
287
- return this._webglLimits;
288
- }
289
- loseDevice() {
290
- var _this$_resolveContext2;
291
- let deviceLossTriggered = false;
292
- const ext = this.gl.getExtension('WEBGL_lose_context');
293
- if (ext) {
294
- deviceLossTriggered = true;
295
- ext.loseContext();
296
- }
297
- (_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
298
- reason: 'destroyed',
299
- message: 'Application triggered context loss'
300
- });
301
- return deviceLossTriggered;
302
- }
303
- pushState() {
304
- pushContextState(this.gl);
305
- }
306
- popState() {
307
- popContextState(this.gl);
308
- }
309
- setSpectorMetadata(handle, props) {
310
- handle.__SPECTOR_Metadata = props;
311
- }
312
- getGLKey(value, gl) {
313
- gl = gl || this.gl2 || this.gl;
314
- const number = Number(value);
315
- for (const key in gl) {
316
- if (gl[key] === number) {
317
- return `GL.${key}`;
318
- }
319
- }
320
- return String(value);
321
- }
322
- setConstantAttribute(location, constant) {
323
- this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
324
- const currentConstant = this._constants[location];
325
- if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
326
- log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
327
- }
328
- this._constants[location] = constant;
329
- switch (constant.constructor) {
330
- case Float32Array:
331
- setConstantFloatArray(this, location, constant);
332
- break;
333
- case Int32Array:
334
- setConstantIntArray(this, location, constant);
335
- break;
336
- case Uint32Array:
337
- setConstantUintArray(this, location, constant);
338
- break;
339
- default:
340
- assert(false);
341
- }
342
- }
137
+ this.handle = gl;
138
+ this.gl = this.handle;
139
+ this.canvasContext.resize();
140
+ // luma Device fields
141
+ this.info = getDeviceInfo(this.gl);
142
+ // @ts-expect-error Link webgl context back to device
143
+ this.gl.device = this;
144
+ // @ts-expect-error Annotate webgl context to handle
145
+ this.gl._version = this.isWebGL2 ? 2 : 1;
146
+ // Install context state tracking
147
+ // @ts-expect-error - hidden parameters
148
+ const { enable = true, copyState = false } = props;
149
+ trackContextState(this.gl, {
150
+ enable,
151
+ copyState,
152
+ log: (...args) => log.log(1, ...args)()
153
+ });
154
+ // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
155
+ if (isBrowser() && props.debug) {
156
+ this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
157
+ this.debug = true;
158
+ log.level = Math.max(log.level, 1);
159
+ log.warn('WebGL debug mode activated. Performance reduced.')();
160
+ }
161
+ // @ts-expect-error spector not on props
162
+ if (isBrowser() && props.spector) {
163
+ const canvas = this.handle.canvas || props.canvas;
164
+ this.spector = initializeSpectorJS({ ...this.props, canvas });
165
+ }
166
+ }
167
+ /**
168
+ * Destroys the context
169
+ * @note Has no effect for browser contexts, there is no browser API for destroying contexts
170
+ */
171
+ destroy() {
172
+ }
173
+ get isLost() {
174
+ return this.gl.isContextLost();
175
+ }
176
+ getSize() {
177
+ return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];
178
+ }
179
+ isTextureFormatSupported(format) {
180
+ return isTextureFormatSupported(this.gl, format);
181
+ }
182
+ isTextureFormatFilterable(format) {
183
+ return isTextureFormatFilterable(this.gl, format);
184
+ }
185
+ isTextureFormatRenderable(format) {
186
+ return isTextureFormatRenderable(this.gl, format);
187
+ }
188
+ // IMPLEMENTATION OF ABSTRACT DEVICE
189
+ createCanvasContext(props) {
190
+ throw new Error('WebGL only supports a single canvas');
191
+ }
192
+ createBuffer(props) {
193
+ const newProps = this._getBufferProps(props);
194
+ return new WEBGLBuffer(this, newProps);
195
+ }
196
+ _createTexture(props) {
197
+ return new WEBGLTexture(this, props);
198
+ }
199
+ createExternalTexture(props) {
200
+ throw new Error('createExternalTexture() not implemented'); // return new Program(props);
201
+ }
202
+ createSampler(props) {
203
+ return new WEBGLSampler(this, props);
204
+ }
205
+ createShader(props) {
206
+ return new WEBGLShader(this, props);
207
+ }
208
+ createFramebuffer(props) {
209
+ return new WEBGLFramebuffer(this, props);
210
+ }
211
+ createRenderPipeline(props) {
212
+ return new WEBGLRenderPipeline(this, props);
213
+ }
214
+ createVertexArray(props) {
215
+ return new WEBGLVertexArray(this, props);
216
+ }
217
+ beginRenderPass(props) {
218
+ return new WEBGLRenderPass(this, props);
219
+ }
220
+ createComputePipeline(props) {
221
+ throw new Error('ComputePipeline not supported in WebGL');
222
+ }
223
+ beginComputePass(props) {
224
+ throw new Error('ComputePass not supported in WebGL');
225
+ }
226
+ createTransformFeedback(props) {
227
+ return new WEBGLTransformFeedback(this, props);
228
+ }
229
+ renderPass = null;
230
+ getDefaultRenderPass() {
231
+ this.renderPass =
232
+ this.renderPass ||
233
+ this.beginRenderPass({
234
+ framebuffer: this.canvasContext.getCurrentFramebuffer()
235
+ });
236
+ return this.renderPass;
237
+ }
238
+ createCommandEncoder(props) {
239
+ return new WEBGLCommandEncoder(this, props);
240
+ }
241
+ /**
242
+ * Offscreen Canvas Support: Commit the frame
243
+ * https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/commit
244
+ * Chrome's offscreen canvas does not require gl.commit
245
+ */
246
+ submit() {
247
+ this.renderPass?.end();
248
+ this.renderPass = null;
249
+ // this.canvasContext.commit();
250
+ }
251
+ //
252
+ // TEMPORARY HACKS - will be removed in v9.1
253
+ //
254
+ /** @deprecated - should use command encoder */
255
+ readPixelsToArrayWebGL(source, options) {
256
+ return readPixelsToArray(source, options);
257
+ }
258
+ /** @deprecated - should use command encoder */
259
+ readPixelsToBufferWebGL(source, options) {
260
+ return readPixelsToBuffer(source, options);
261
+ }
262
+ setParametersWebGL(parameters) {
263
+ setGLParameters(this, parameters);
264
+ }
265
+ getParametersWebGL(parameters) {
266
+ return getGLParameters(this, parameters);
267
+ }
268
+ withParametersWebGL(parameters, func) {
269
+ withGLParameters(this, parameters, func);
270
+ }
271
+ clearWebGL(options) {
272
+ clear(this, options);
273
+ }
274
+ //
275
+ // WebGL-only API (not part of `Device` API)
276
+ //
277
+ /** WebGL2 context. */
278
+ gl;
279
+ debug = false;
280
+ /** State used by luma.gl classes: TODO - move to canvasContext*/
281
+ _canvasSizeInfo = { clientWidth: 0, clientHeight: 0, devicePixelRatio: 1 };
282
+ /** State used by luma.gl classes - TODO - not used? */
283
+ _extensions = {};
284
+ _polyfilled = false;
285
+ /** Instance of Spector.js (if initialized) */
286
+ spector;
287
+ _webglLimits;
288
+ /** Return WebGL specific limits */
289
+ get webglLimits() {
290
+ this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
291
+ return this._webglLimits;
292
+ }
293
+ /**
294
+ * Triggers device (or WebGL context) loss.
295
+ * @note primarily intended for testing how application reacts to device loss
296
+ */
297
+ loseDevice() {
298
+ let deviceLossTriggered = false;
299
+ const ext = this.gl.getExtension('WEBGL_lose_context');
300
+ if (ext) {
301
+ deviceLossTriggered = true;
302
+ ext.loseContext();
303
+ // ext.loseContext should trigger context loss callback but the platform may not do this, so do it explicitly
304
+ }
305
+ this._resolveContextLost?.({
306
+ reason: 'destroyed',
307
+ message: 'Application triggered context loss'
308
+ });
309
+ return deviceLossTriggered;
310
+ }
311
+ /** Save current WebGL context state onto an internal stack */
312
+ pushState() {
313
+ pushContextState(this.gl);
314
+ }
315
+ /** Restores previously saved context state */
316
+ popState() {
317
+ popContextState(this.gl);
318
+ }
319
+ /**
320
+ * Storing data on a special field on WebGLObjects makes that data visible in SPECTOR chrome debug extension
321
+ * luma.gl ids and props can be inspected
322
+ */
323
+ setSpectorMetadata(handle, props) {
324
+ // @ts-expect-error
325
+ // eslint-disable-next-line camelcase
326
+ handle.__SPECTOR_Metadata = props;
327
+ }
328
+ /**
329
+ * Returns the GL.<KEY> constant that corresponds to a numeric value of a GL constant
330
+ * Be aware that there are some duplicates especially for constants that are 0,
331
+ * so this isn't guaranteed to return the right key in all cases.
332
+ */
333
+ getGLKey(value, gl) {
334
+ // @ts-ignore expect-error depends on settings
335
+ gl = gl || this.gl2 || this.gl;
336
+ const number = Number(value);
337
+ for (const key in gl) {
338
+ // @ts-ignore expect-error depends on settings
339
+ if (gl[key] === number) {
340
+ return `GL.${key}`;
341
+ }
342
+ }
343
+ // No constant found. Stringify the value and return it.
344
+ return String(value);
345
+ }
346
+ /** Store constants */
347
+ _constants;
348
+ /**
349
+ * Set a constant value for a location. Disabled attributes at that location will read from this value
350
+ * @note WebGL constants are stored globally on the WebGL context, not the VertexArray
351
+ * so they need to be updated before every render
352
+ * @todo - remember/cache values to avoid setting them unnecessarily?
353
+ */
354
+ setConstantAttribute(location, constant) {
355
+ this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
356
+ const currentConstant = this._constants[location];
357
+ if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
358
+ log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
359
+ }
360
+ this._constants[location] = constant;
361
+ switch (constant.constructor) {
362
+ case Float32Array:
363
+ setConstantFloatArray(this, location, constant);
364
+ break;
365
+ case Int32Array:
366
+ setConstantIntArray(this, location, constant);
367
+ break;
368
+ case Uint32Array:
369
+ setConstantUintArray(this, location, constant);
370
+ break;
371
+ default:
372
+ assert(false);
373
+ }
374
+ }
343
375
  }
344
- WebGLDevice.type = 'webgl';
376
+ /** Check if supplied parameter is a WebGL2RenderingContext */
345
377
  function isWebGL(gl) {
346
- if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {
347
- return true;
348
- }
349
- if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
350
- return true;
351
- }
352
- return Boolean(gl && Number.isFinite(gl._version));
353
- }
354
- function isWebGL2(gl) {
355
- if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
356
- return true;
357
- }
358
- return Boolean(gl && gl._version === 2);
378
+ if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
379
+ return true;
380
+ }
381
+ // Look for debug contexts, headless gl etc
382
+ return Boolean(gl && Number.isFinite(gl._version));
359
383
  }
384
+ /** Set constant float array attribute */
360
385
  function setConstantFloatArray(device, location, array) {
361
- switch (array.length) {
362
- case 1:
363
- device.gl.vertexAttrib1fv(location, array);
364
- break;
365
- case 2:
366
- device.gl.vertexAttrib2fv(location, array);
367
- break;
368
- case 3:
369
- device.gl.vertexAttrib3fv(location, array);
370
- break;
371
- case 4:
372
- device.gl.vertexAttrib4fv(location, array);
373
- break;
374
- default:
375
- assert(false);
376
- }
386
+ switch (array.length) {
387
+ case 1:
388
+ device.gl.vertexAttrib1fv(location, array);
389
+ break;
390
+ case 2:
391
+ device.gl.vertexAttrib2fv(location, array);
392
+ break;
393
+ case 3:
394
+ device.gl.vertexAttrib3fv(location, array);
395
+ break;
396
+ case 4:
397
+ device.gl.vertexAttrib4fv(location, array);
398
+ break;
399
+ default:
400
+ assert(false);
401
+ }
377
402
  }
403
+ /** Set constant signed int array attribute */
378
404
  function setConstantIntArray(device, location, array) {
379
- var _device$gl;
380
- device.assertWebGL2();
381
- (_device$gl = device.gl2) === null || _device$gl === void 0 ? void 0 : _device$gl.vertexAttribI4iv(location, array);
405
+ device.gl.vertexAttribI4iv(location, array);
406
+ // TODO - not clear if we need to use the special forms, more testing needed
407
+ // switch (array.length) {
408
+ // case 1:
409
+ // gl.vertexAttribI1iv(location, array);
410
+ // break;
411
+ // case 2:
412
+ // gl.vertexAttribI2iv(location, array);
413
+ // break;
414
+ // case 3:
415
+ // gl.vertexAttribI3iv(location, array);
416
+ // break;
417
+ // case 4:
418
+ // break;
419
+ // default:
420
+ // assert(false);
421
+ // }
382
422
  }
423
+ /** Set constant unsigned int array attribute */
383
424
  function setConstantUintArray(device, location, array) {
384
- var _device$gl2;
385
- device.assertWebGL2();
386
- (_device$gl2 = device.gl2) === null || _device$gl2 === void 0 ? void 0 : _device$gl2.vertexAttribI4uiv(location, array);
425
+ device.gl.vertexAttribI4uiv(location, array);
426
+ // TODO - not clear if we need to use the special forms, more testing needed
427
+ // switch (array.length) {
428
+ // case 1:
429
+ // gl.vertexAttribI1uiv(location, array);
430
+ // break;
431
+ // case 2:
432
+ // gl.vertexAttribI2uiv(location, array);
433
+ // break;
434
+ // case 3:
435
+ // gl.vertexAttribI3uiv(location, array);
436
+ // break;
437
+ // case 4:
438
+ // gl.vertexAttribI4uiv(location, array);
439
+ // break;
440
+ // default:
441
+ // assert(false);
442
+ // }
387
443
  }
444
+ /**
445
+ * Compares contents of two typed arrays
446
+ * @todo max length?
447
+ */
388
448
  function compareConstantArrayValues(v1, v2) {
389
- if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
390
- return false;
391
- }
392
- for (let i = 0; i < v1.length; ++i) {
393
- if (v1[i] !== v2[i]) {
394
- return false;
395
- }
396
- }
397
- return true;
449
+ if (!v1 || !v2 || v1.length !== v2.length || v1.constructor !== v2.constructor) {
450
+ return false;
451
+ }
452
+ for (let i = 0; i < v1.length; ++i) {
453
+ if (v1[i] !== v2[i]) {
454
+ return false;
455
+ }
456
+ }
457
+ return true;
398
458
  }
399
- //# sourceMappingURL=webgl-device.js.map