@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,17 +1,21 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ /** deeply compare two arrays */
1
4
  export function deepArrayEqual(x, y) {
2
- if (x === y) {
3
- return true;
4
- }
5
- const isArrayX = Array.isArray(x) || ArrayBuffer.isView(x);
6
- const isArrayY = Array.isArray(y) || ArrayBuffer.isView(y);
7
- if (isArrayX && isArrayY && x.length === y.length) {
8
- for (let i = 0; i < x.length; ++i) {
9
- if (x[i] !== y[i]) {
10
- return false;
11
- }
5
+ if (x === y) {
6
+ return true;
12
7
  }
13
- return true;
14
- }
15
- return false;
8
+ const isArrayX = Array.isArray(x) || ArrayBuffer.isView(x);
9
+ const isArrayY = Array.isArray(y) || ArrayBuffer.isView(y);
10
+ // @ts-expect-error TODO fix
11
+ if (isArrayX && isArrayY && x.length === y.length) {
12
+ // @ts-expect-error TODO fix
13
+ for (let i = 0; i < x.length; ++i) {
14
+ if (x[i] !== y[i]) {
15
+ return false;
16
+ }
17
+ }
18
+ return true;
19
+ }
20
+ return false;
16
21
  }
17
- //# sourceMappingURL=deep-array-equal.js.map
@@ -6,17 +6,17 @@
6
6
  * gl.state.push() and gl.state.pop() will be available for saving,
7
7
  * temporarily modifying, and then restoring state.
8
8
  */
9
- export declare function trackContextState(gl: WebGLRenderingContext, options?: {
9
+ export declare function trackContextState(gl: WebGL2RenderingContext, options?: {
10
10
  enable?: boolean;
11
11
  copyState?: boolean;
12
12
  log?: any;
13
- }): WebGLRenderingContext;
13
+ }): WebGL2RenderingContext;
14
14
  /**
15
15
  * Saves current WebGL context state onto an internal per-context stack
16
16
  */
17
- export declare function pushContextState(gl: WebGLRenderingContext): void;
17
+ export declare function pushContextState(gl: WebGL2RenderingContext): void;
18
18
  /**
19
19
  * Restores previously saved WebGL context state
20
20
  */
21
- export declare function popContextState(gl: WebGLRenderingContext): void;
21
+ export declare function popContextState(gl: WebGL2RenderingContext): void;
22
22
  //# sourceMappingURL=track-context-state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"track-context-state.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/track-context-state.ts"],"names":[],"mappings":"AA6FA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,qBAAqB,EACzB,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,GACA,qBAAqB,CAgCvB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,qBAAqB,GAAG,IAAI,CAOhE;AAGD;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,qBAAqB,GAAG,IAAI,CAI/D"}
1
+ {"version":3,"file":"track-context-state.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/track-context-state.ts"],"names":[],"mappings":"AA6FA;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,sBAAsB,EAC1B,OAAO,CAAC,EAAE;IACR,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,GACA,sBAAsB,CAgCxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAOjE;AAGD;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAIhE"}
@@ -1,147 +1,211 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ // Support for listening to context state changes and intercepting state queries
4
+ // NOTE: this system does not handle buffer bindings
1
5
  import { assert } from '@luma.gl/core';
2
- import { GL_PARAMETER_DEFAULTS, GL_HOOKED_SETTERS, NON_CACHE_PARAMETERS } from "../parameters/webgl-parameter-tables.js";
3
- import { setGLParameters, getGLParameters } from "../parameters/unified-parameter-api.js";
4
- import { deepArrayEqual } from "./deep-array-equal.js";
6
+ import { GL_PARAMETER_DEFAULTS, GL_HOOKED_SETTERS, NON_CACHE_PARAMETERS } from '../parameters/webgl-parameter-tables';
7
+ import { setGLParameters, getGLParameters } from '../parameters/unified-parameter-api';
8
+ import { deepArrayEqual } from './deep-array-equal';
9
+ // HELPER CLASS - GLState
10
+ /* eslint-disable no-shadow */
5
11
  class GLState {
6
- constructor(gl) {
7
- let {
8
- copyState = false,
9
- log = () => {}
10
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
11
- this.gl = void 0;
12
- this.program = null;
13
- this.stateStack = [];
14
- this.enable = true;
15
- this.cache = void 0;
16
- this.log = void 0;
17
- this.gl = gl;
18
- this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
19
- this.log = log;
20
- this._updateCache = this._updateCache.bind(this);
21
- Object.seal(this);
22
- }
23
- push() {
24
- let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25
- this.stateStack.push({});
26
- }
27
- pop() {
28
- assert(this.stateStack.length > 0);
29
- const oldValues = this.stateStack[this.stateStack.length - 1];
30
- setGLParameters(this.gl, oldValues);
31
- this.stateStack.pop();
32
- }
33
- _updateCache(values) {
34
- let valueChanged = false;
35
- let oldValue;
36
- const oldValues = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
37
- for (const key in values) {
38
- assert(key !== undefined);
39
- const value = values[key];
40
- const cached = this.cache[key];
41
- if (!deepArrayEqual(value, cached)) {
42
- valueChanged = true;
43
- oldValue = cached;
44
- if (oldValues && !(key in oldValues)) {
45
- oldValues[key] = cached;
12
+ gl;
13
+ program = null;
14
+ stateStack = [];
15
+ enable = true;
16
+ cache;
17
+ log;
18
+ constructor(gl, { copyState = false, // Copy cache from params (slow) or initialize from WebGL defaults (fast)
19
+ log = () => { } // Logging function, called when gl parameter change calls are actually issued
20
+ } = {}) {
21
+ this.gl = gl;
22
+ this.cache = copyState ? getGLParameters(gl) : Object.assign({}, GL_PARAMETER_DEFAULTS);
23
+ this.log = log;
24
+ this._updateCache = this._updateCache.bind(this);
25
+ Object.seal(this);
26
+ }
27
+ push(values = {}) {
28
+ this.stateStack.push({});
29
+ }
30
+ pop() {
31
+ assert(this.stateStack.length > 0);
32
+ // Use the saved values in the state stack to restore parameters
33
+ const oldValues = this.stateStack[this.stateStack.length - 1];
34
+ setGLParameters(this.gl, oldValues);
35
+ // Don't pop until we have reset parameters (to make sure other "stack frames" are not affected)
36
+ this.stateStack.pop();
37
+ }
38
+ /**
39
+ // interceptor for context set functions - update our cache and our stack
40
+ // values (Object) - the key values for this setter
41
+ * @param values
42
+ * @returns
43
+ */
44
+ _updateCache(values) {
45
+ let valueChanged = false;
46
+ let oldValue; // = undefined
47
+ const oldValues = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
48
+ for (const key in values) {
49
+ assert(key !== undefined);
50
+ const value = values[key];
51
+ const cached = this.cache[key];
52
+ // Check that value hasn't already been shadowed
53
+ if (!deepArrayEqual(value, cached)) {
54
+ valueChanged = true;
55
+ oldValue = cached;
56
+ // First, save current value being shadowed
57
+ // If a state stack frame is active, save the current parameter values for pop
58
+ // but first check that value hasn't already been shadowed and saved
59
+ if (oldValues && !(key in oldValues)) {
60
+ oldValues[key] = cached;
61
+ }
62
+ // Save current value being shadowed
63
+ this.cache[key] = value;
64
+ }
46
65
  }
47
- this.cache[key] = value;
48
- }
66
+ return { valueChanged, oldValue };
49
67
  }
50
- return {
51
- valueChanged,
52
- oldValue
53
- };
54
- }
55
68
  }
56
69
  function getContextState(gl) {
57
- return gl.state;
70
+ // @ts-expect-error
71
+ return gl.state;
58
72
  }
73
+ // PUBLIC API
74
+ /**
75
+ * Initialize WebGL state caching on a context
76
+ * can be called multiple times to enable/disable
77
+ *
78
+ * @note After calling this function, context state will be cached
79
+ * gl.state.push() and gl.state.pop() will be available for saving,
80
+ * temporarily modifying, and then restoring state.
81
+ */
59
82
  export function trackContextState(gl, options) {
60
- const {
61
- enable = true,
62
- copyState
63
- } = options;
64
- assert(copyState !== undefined);
65
- if (!gl.state) {
66
- gl.state = new GLState(gl, {
67
- copyState
68
- });
69
- installProgramSpy(gl);
70
- for (const key in GL_HOOKED_SETTERS) {
71
- const setter = GL_HOOKED_SETTERS[key];
72
- installSetterSpy(gl, key, setter);
83
+ const { enable = true, copyState } = options;
84
+ assert(copyState !== undefined);
85
+ // @ts-expect-error
86
+ if (!gl.state) {
87
+ // @ts-ignore
88
+ // const {polyfillContext} = global_;
89
+ // if (polyfillContext) {
90
+ // polyfillContext(gl);
91
+ // }
92
+ // Create a state cache
93
+ // @ts-expect-error
94
+ gl.state = new GLState(gl, { copyState });
95
+ installProgramSpy(gl);
96
+ // intercept all setter functions in the table
97
+ for (const key in GL_HOOKED_SETTERS) {
98
+ const setter = GL_HOOKED_SETTERS[key];
99
+ installSetterSpy(gl, key, setter);
100
+ }
101
+ // intercept all getter functions in the table
102
+ installGetterOverride(gl, 'getParameter');
103
+ installGetterOverride(gl, 'isEnabled');
73
104
  }
74
- installGetterOverride(gl, 'getParameter');
75
- installGetterOverride(gl, 'isEnabled');
76
- }
77
- const glState = getContextState(gl);
78
- glState.enable = enable;
79
- return gl;
105
+ const glState = getContextState(gl);
106
+ glState.enable = enable;
107
+ return gl;
80
108
  }
109
+ /**
110
+ * Saves current WebGL context state onto an internal per-context stack
111
+ */
81
112
  export function pushContextState(gl) {
82
- let glState = getContextState(gl);
83
- if (!glState) {
84
- trackContextState(gl, {
85
- copyState: false
86
- });
87
- glState = getContextState(gl);
88
- }
89
- glState.push();
113
+ let glState = getContextState(gl);
114
+ if (!glState) {
115
+ trackContextState(gl, { copyState: false });
116
+ glState = getContextState(gl);
117
+ }
118
+ glState.push();
90
119
  }
120
+ /**
121
+ * Restores previously saved WebGL context state
122
+ */
91
123
  export function popContextState(gl) {
92
- const glState = getContextState(gl);
93
- assert(glState);
94
- glState.pop();
124
+ const glState = getContextState(gl);
125
+ assert(glState);
126
+ glState.pop();
95
127
  }
128
+ // HELPER FUNCTIONS - INSTALL GET/SET INTERCEPTORS (SPYS) ON THE CONTEXT
129
+ /**
130
+ // Overrides a WebGL2RenderingContext state "getter" function
131
+ // to return values directly from cache
132
+ * @param gl
133
+ * @param functionName
134
+ */
96
135
  function installGetterOverride(gl, functionName) {
97
- const originalGetterFunc = gl[functionName].bind(gl);
98
- gl[functionName] = function get(pname) {
99
- if (pname === undefined || NON_CACHE_PARAMETERS.has(pname)) {
100
- return originalGetterFunc(pname);
101
- }
102
- const glState = getContextState(gl);
103
- if (!(pname in glState.cache)) {
104
- glState.cache[pname] = originalGetterFunc(pname);
105
- }
106
- return glState.enable ? glState.cache[pname] : originalGetterFunc(pname);
107
- };
108
- Object.defineProperty(gl[functionName], 'name', {
109
- value: `${functionName}-from-cache`,
110
- configurable: false
111
- });
136
+ // Get the original function from the WebGL2RenderingContext
137
+ const originalGetterFunc = gl[functionName].bind(gl);
138
+ // Wrap it with a spy so that we can update our state cache when it gets called
139
+ gl[functionName] = function get(pname) {
140
+ if (pname === undefined || NON_CACHE_PARAMETERS.has(pname)) {
141
+ // Invalid or blacklisted parameter, do not cache
142
+ return originalGetterFunc(pname);
143
+ }
144
+ const glState = getContextState(gl);
145
+ if (!(pname in glState.cache)) {
146
+ // WebGL limits are not prepopulated in the cache, call the original getter when first queried.
147
+ glState.cache[pname] = originalGetterFunc(pname);
148
+ }
149
+ // Optionally call the original function to do a "hard" query from the WebGL2RenderingContext
150
+ return glState.enable
151
+ ? // Call the getter the params so that it can e.g. serve from a cache
152
+ glState.cache[pname]
153
+ : // Optionally call the original function to do a "hard" query from the WebGL2RenderingContext
154
+ originalGetterFunc(pname);
155
+ };
156
+ // Set the name of this anonymous function to help in debugging and profiling
157
+ Object.defineProperty(gl[functionName], 'name', {
158
+ value: `${functionName}-from-cache`,
159
+ configurable: false
160
+ });
112
161
  }
162
+ /**
163
+ // Overrides a WebGL2RenderingContext state "setter" function
164
+ // to call a setter spy before the actual setter. Allows us to keep a cache
165
+ // updated with a copy of the WebGL context state.
166
+ * @param gl
167
+ * @param functionName
168
+ * @param setter
169
+ * @returns
170
+ */
113
171
  function installSetterSpy(gl, functionName, setter) {
114
- if (!gl[functionName]) {
115
- return;
116
- }
117
- const originalSetterFunc = gl[functionName].bind(gl);
118
- gl[functionName] = function set() {
119
- const glState = getContextState(gl);
120
- for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
121
- params[_key] = arguments[_key];
122
- }
123
- const {
124
- valueChanged,
125
- oldValue
126
- } = setter(glState._updateCache, ...params);
127
- if (valueChanged) {
128
- originalSetterFunc(...params);
172
+ // Get the original function from the WebGL2RenderingContext
173
+ if (!gl[functionName]) {
174
+ // TODO - remove?
175
+ // This could happen if we try to intercept WebGL2 method on a WebGL1 context
176
+ return;
129
177
  }
130
- return oldValue;
131
- };
132
- Object.defineProperty(gl[functionName], 'name', {
133
- value: `${functionName}-to-cache`,
134
- configurable: false
135
- });
178
+ const originalSetterFunc = gl[functionName].bind(gl);
179
+ // Wrap it with a spy so that we can update our state cache when it gets called
180
+ gl[functionName] = function set(...params) {
181
+ // Update the value
182
+ // Call the setter with the state cache and the params so that it can store the parameters
183
+ const glState = getContextState(gl);
184
+ // eslint-disable-next-line @typescript-eslint/unbound-method
185
+ const { valueChanged, oldValue } = setter(glState._updateCache, ...params);
186
+ // Call the original WebGL2RenderingContext func to make sure the context actually gets updated
187
+ if (valueChanged) {
188
+ originalSetterFunc(...params);
189
+ }
190
+ // Note: if the original function fails to set the value, our state cache will be bad
191
+ // No solution for this at the moment, but assuming that this is unlikely to be a real problem
192
+ // We could call the setter after the originalSetterFunc. Concern is that this would
193
+ // cause different behavior in debug mode, where originalSetterFunc can throw exceptions
194
+ return oldValue;
195
+ };
196
+ // Set the name of this anonymous function to help in debugging and profiling
197
+ Object.defineProperty(gl[functionName], 'name', {
198
+ value: `${functionName}-to-cache`,
199
+ configurable: false
200
+ });
136
201
  }
137
202
  function installProgramSpy(gl) {
138
- const originalUseProgram = gl.useProgram.bind(gl);
139
- gl.useProgram = function useProgramLuma(handle) {
140
- const glState = getContextState(gl);
141
- if (glState.program !== handle) {
142
- originalUseProgram(handle);
143
- glState.program = handle;
144
- }
145
- };
203
+ const originalUseProgram = gl.useProgram.bind(gl);
204
+ gl.useProgram = function useProgramLuma(handle) {
205
+ const glState = getContextState(gl);
206
+ if (glState.program !== handle) {
207
+ originalUseProgram(handle);
208
+ glState.program = handle;
209
+ }
210
+ };
146
211
  }
147
- //# sourceMappingURL=track-context-state.js.map
@@ -8,7 +8,7 @@ import { GLParameters } from '../parameters/unified-parameter-api';
8
8
  * - Restores parameters
9
9
  * - Returns the return value of the supplied function
10
10
  */
11
- export declare function withGLParameters(device: Device | WebGLRenderingContext, parameters: GLParameters & {
11
+ export declare function withGLParameters(device: Device | WebGL2RenderingContext, parameters: GLParameters & {
12
12
  nocatch?: boolean;
13
13
  }, func: any): any;
14
14
  //# sourceMappingURL=with-parameters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-parameters.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/with-parameters.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAC,YAAY,EAAkB,MAAM,qCAAqC,CAAC;AAGlF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,EAAE,UAAU,EAAE,YAAY,GAAG;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,CA+BvI"}
1
+ {"version":3,"file":"with-parameters.d.ts","sourceRoot":"","sources":["../../../src/context/state-tracker/with-parameters.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAC,YAAY,EAAkB,MAAM,qCAAqC,CAAC;AAGlF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,EAAE,UAAU,EAAE,YAAY,GAAG;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG,CA+BxI"}
@@ -1,34 +1,50 @@
1
- import { WebGLDevice } from "../../adapter/webgl-device.js";
2
- import { setGLParameters } from "../parameters/unified-parameter-api.js";
3
- import { pushContextState, popContextState } from "./track-context-state.js";
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+ import { WebGLDevice } from '../../adapter/webgl-device';
4
+ import { setGLParameters } from '../parameters/unified-parameter-api';
5
+ import { pushContextState, popContextState } from './track-context-state';
6
+ /**
7
+ * Execute a function with a set of temporary WebGL parameter overrides
8
+ * - Saves current "global" WebGL context settings
9
+ * - Sets the supplies WebGL context parameters,
10
+ * - Executes supplied function
11
+ * - Restores parameters
12
+ * - Returns the return value of the supplied function
13
+ */
4
14
  export function withGLParameters(device, parameters, func) {
5
- const webglDevice = WebGLDevice.attach(device);
6
- const gl = webglDevice.gl;
7
- if (isObjectEmpty(parameters)) {
8
- return func(device);
9
- }
10
- const {
11
- nocatch = true
12
- } = parameters;
13
- pushContextState(gl);
14
- setGLParameters(gl, parameters);
15
- let value;
16
- if (nocatch) {
17
- value = func(gl);
18
- popContextState(gl);
19
- } else {
20
- try {
21
- value = func(gl);
22
- } finally {
23
- popContextState(gl);
15
+ const webglDevice = WebGLDevice.attach(device);
16
+ const gl = webglDevice.gl;
17
+ if (isObjectEmpty(parameters)) {
18
+ // Avoid setting state if no parameters provided. Just call and return
19
+ return func(device);
24
20
  }
25
- }
26
- return value;
21
+ const { nocatch = true } = parameters;
22
+ pushContextState(gl);
23
+ setGLParameters(gl, parameters);
24
+ // Setup is done, call the function
25
+ let value;
26
+ if (nocatch) {
27
+ // Avoid try catch to minimize stack size impact for safe execution paths
28
+ value = func(gl);
29
+ popContextState(gl);
30
+ }
31
+ else {
32
+ // Wrap in a try-catch to ensure that parameters are restored on exceptions
33
+ try {
34
+ value = func(gl);
35
+ }
36
+ finally {
37
+ popContextState(gl);
38
+ }
39
+ }
40
+ return value;
27
41
  }
42
+ // Helpers
43
+ // Returns true if given object is empty, false otherwise.
28
44
  function isObjectEmpty(object) {
29
- for (const key in object) {
30
- return false;
31
- }
32
- return true;
45
+ // @ts-ignore - dummy key variable
46
+ for (const key in object) {
47
+ return false;
48
+ }
49
+ return true;
33
50
  }
34
- //# sourceMappingURL=with-parameters.js.map