@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
@@ -17,21 +17,15 @@ import type {
17
17
  } from '@luma.gl/core';
18
18
  import {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';
19
19
  import {isBrowser} from '@probe.gl/env';
20
- import {polyfillContext} from '../context/polyfill/polyfill-context';
21
20
  import {
22
21
  popContextState,
23
22
  pushContextState,
24
23
  trackContextState
25
24
  } from '../context/state-tracker/track-context-state';
26
25
  import {createBrowserContext} from '../context/context/create-browser-context';
27
- import {
28
- createHeadlessContext,
29
- isHeadlessGLRegistered
30
- } from '../context/context/create-headless-context';
31
-
32
- import {getDeviceInfo} from './device-helpers/get-device-info';
33
- import {getDeviceFeatures} from './device-helpers/device-features';
34
- import {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';
26
+ import {getDeviceInfo} from './device-helpers/webgl-device-info';
27
+ import {getDeviceFeatures} from './device-helpers/webgl-device-features';
28
+ import {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/webgl-device-limits';
35
29
  import {WebGLCanvasContext} from './webgl-canvas-context';
36
30
  import {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';
37
31
  import {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';
@@ -91,13 +85,13 @@ export class WebGLDevice extends Device {
91
85
  static type: string = 'webgl';
92
86
 
93
87
  static isSupported(): boolean {
94
- return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();
88
+ return typeof WebGL2RenderingContext !== 'undefined';
95
89
  }
96
90
 
97
91
  readonly info: DeviceInfo;
98
92
  readonly canvasContext: WebGLCanvasContext;
99
93
 
100
- readonly handle: WebGLRenderingContext;
94
+ readonly handle: WebGL2RenderingContext;
101
95
 
102
96
  get features(): Set<DeviceFeature> {
103
97
  this._features = this._features || getDeviceFeatures(this.gl);
@@ -125,7 +119,7 @@ export class WebGLDevice extends Device {
125
119
  * @param gl
126
120
  * @returns
127
121
  */
128
- static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {
122
+ static attach(gl: Device | WebGL2RenderingContext): WebGLDevice {
129
123
  if (gl instanceof WebGLDevice) {
130
124
  return gl;
131
125
  }
@@ -135,9 +129,9 @@ export class WebGLDevice extends Device {
135
129
  return gl.device as WebGLDevice;
136
130
  }
137
131
  if (!isWebGL(gl)) {
138
- throw new Error('Invalid WebGLRenderingContext');
132
+ throw new Error('Invalid WebGL2RenderingContext');
139
133
  }
140
- return new WebGLDevice({gl: gl as WebGLRenderingContext});
134
+ return new WebGLDevice({gl: gl as WebGL2RenderingContext});
141
135
  }
142
136
 
143
137
  static async create(props: DeviceProps = {}): Promise<WebGLDevice> {
@@ -209,23 +203,19 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
209
203
  message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
210
204
  });
211
205
 
212
- let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl || null;
206
+ let gl: WebGL2RenderingContext | null = props.gl || null;
213
207
  gl =
214
208
  gl ||
215
209
  (isBrowser()
216
210
  ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost})
217
211
  : null);
218
- gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);
219
-
212
+
220
213
  if (!gl) {
221
214
  throw new Error('WebGL context creation failed');
222
215
  }
223
216
 
224
217
  this.handle = gl;
225
218
  this.gl = this.handle;
226
- this.gl2 = this.gl as WebGL2RenderingContext;
227
- this.isWebGL2 = isWebGL2(this.gl);
228
- this.isWebGL1 = !this.isWebGL2;
229
219
  this.canvasContext.resize();
230
220
 
231
221
  // luma Device fields
@@ -236,9 +226,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
236
226
  // @ts-expect-error Annotate webgl context to handle
237
227
  this.gl._version = this.isWebGL2 ? 2 : 1;
238
228
 
239
- // Add subset of WebGL2 methods to WebGL1 context
240
- polyfillContext(this.gl);
241
-
242
229
  // Install context state tracking
243
230
  // @ts-expect-error - hidden parameters
244
231
  const {enable = true, copyState = false} = props;
@@ -250,8 +237,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
250
237
 
251
238
  // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
252
239
  if (isBrowser() && props.debug) {
253
- this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});
254
- this.gl2 = this.gl as WebGL2RenderingContext;
240
+ this.gl = makeDebugContext(this.gl, {...props, throwOnError: true});
255
241
  this.debug = true;
256
242
  log.level = Math.max(log.level, 1);
257
243
  log.warn('WebGL debug mode activated. Performance reduced.')();
@@ -269,10 +255,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
269
255
  * @note Has no effect for browser contexts, there is no browser API for destroying contexts
270
256
  */
271
257
  destroy(): void {
272
- const ext = this.gl.getExtension('STACKGL_destroy_context');
273
- if (ext) {
274
- ext.destroy();
275
- }
276
258
  }
277
259
 
278
260
  get isLost(): boolean {
@@ -295,16 +277,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
295
277
  return isTextureFormatRenderable(this.gl, format);
296
278
  }
297
279
 
298
- // WEBGL SPECIFIC METHODS
299
-
300
- /** Returns a WebGL2RenderingContext or throws an error */
301
- assertWebGL2(): WebGL2RenderingContext {
302
- if (!this.gl2) {
303
- throw new Error('Requires WebGL2');
304
- }
305
- return this.gl2;
306
- }
307
-
308
280
  // IMPLEMENTATION OF ABSTRACT DEVICE
309
281
 
310
282
  createCanvasContext(props?: CanvasContextProps): CanvasContext {
@@ -377,7 +349,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
377
349
 
378
350
  /**
379
351
  * Offscreen Canvas Support: Commit the frame
380
- * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit
352
+ * https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext/commit
381
353
  * Chrome's offscreen canvas does not require gl.commit
382
354
  */
383
355
  submit(): void {
@@ -446,17 +418,10 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
446
418
  // WebGL-only API (not part of `Device` API)
447
419
  //
448
420
 
449
- /** WebGL1 typed context. Can always be used. */
450
- readonly gl: WebGLRenderingContext;
451
- /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
452
- readonly gl2: WebGL2RenderingContext | null = null;
421
+ /** WebGL2 context. */
422
+ readonly gl: WebGL2RenderingContext;
453
423
  readonly debug: boolean = false;
454
424
 
455
- /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
456
- readonly isWebGL1: boolean;
457
- /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */
458
- readonly isWebGL2: boolean;
459
-
460
425
  /** State used by luma.gl classes: TODO - move to canvasContext*/
461
426
  readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
462
427
 
@@ -519,7 +484,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
519
484
  * Be aware that there are some duplicates especially for constants that are 0,
520
485
  * so this isn't guaranteed to return the right key in all cases.
521
486
  */
522
- getGLKey(value: unknown, gl?: WebGLRenderingContext): string {
487
+ getGLKey(value: unknown, gl?: WebGL2RenderingContext): string {
523
488
  // @ts-ignore expect-error depends on settings
524
489
  gl = gl || this.gl2 || this.gl;
525
490
  const number = Number(value);
@@ -566,11 +531,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
566
531
  }
567
532
  }
568
533
 
569
- /** Check if supplied parameter is a WebGLRenderingContext */
534
+ /** Check if supplied parameter is a WebGL2RenderingContext */
570
535
  function isWebGL(gl: any): boolean {
571
- if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {
572
- return true;
573
- }
574
536
  if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
575
537
  return true;
576
538
  }
@@ -578,15 +540,6 @@ function isWebGL(gl: any): boolean {
578
540
  return Boolean(gl && Number.isFinite(gl._version));
579
541
  }
580
542
 
581
- /** Check if supplied parameter is a WebGL2RenderingContext */
582
- function isWebGL2(gl: any): boolean {
583
- if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
584
- return true;
585
- }
586
- // Look for debug contexts, headless gl etc
587
- return Boolean(gl && gl._version === 2);
588
- }
589
-
590
543
  /** Set constant float array attribute */
591
544
  function setConstantFloatArray(device: WebGLDevice, location: number, array: Float32Array): void {
592
545
  switch (array.length) {
@@ -609,8 +562,7 @@ function setConstantFloatArray(device: WebGLDevice, location: number, array: Flo
609
562
 
610
563
  /** Set constant signed int array attribute */
611
564
  function setConstantIntArray(device: WebGLDevice, location: number, array: Int32Array): void {
612
- device.assertWebGL2();
613
- device.gl2?.vertexAttribI4iv(location, array);
565
+ device.gl.vertexAttribI4iv(location, array);
614
566
  // TODO - not clear if we need to use the special forms, more testing needed
615
567
  // switch (array.length) {
616
568
  // case 1:
@@ -631,8 +583,7 @@ function setConstantIntArray(device: WebGLDevice, location: number, array: Int32
631
583
 
632
584
  /** Set constant unsigned int array attribute */
633
585
  function setConstantUintArray(device: WebGLDevice, location: number, array: Uint32Array) {
634
- device.assertWebGL2();
635
- device.gl2?.vertexAttribI4uiv(location, array);
586
+ device.gl.vertexAttribI4uiv(location, array);
636
587
  // TODO - not clear if we need to use the special forms, more testing needed
637
588
  // switch (array.length) {
638
589
  // case 1:
@@ -23,10 +23,9 @@ const ERR_ARGUMENTS = 'clear: bad arguments';
23
23
  * @deprecated Set clear color when creating a RenderPass.
24
24
  */
25
25
  export function clear(
26
- gl: Device | WebGLRenderingContext,
26
+ device: Device,
27
27
  options?: {framebuffer?: Framebuffer; color?: any; depth?: any; stencil?: any}
28
28
  ): void {
29
- const device = WebGLDevice.attach(gl);
30
29
  const {framebuffer = null, color = null, depth = null, stencil = null} = options || {};
31
30
  const parameters: any = {};
32
31
 
@@ -60,8 +59,9 @@ export function clear(
60
59
  assert(clearFlags !== 0, ERR_ARGUMENTS);
61
60
 
62
61
  // Temporarily set any clear "colors" and call clear
63
- withGLParameters(device.gl, parameters, () => {
64
- device.gl.clear(clearFlags);
62
+ withGLParameters(device, parameters, () => {
63
+ const gl = (device as WebGLDevice).gl;
64
+ gl.clear(clearFlags);
65
65
  });
66
66
  }
67
67
 
@@ -70,40 +70,39 @@ export function clear(
70
70
  * @deprecated Set clear color when creating a RenderPass
71
71
  */
72
72
  export function clearBuffer(
73
- gl: Device | WebGLRenderingContext,
73
+ device: Device,
74
74
  options?: {framebuffer?: Framebuffer; buffer?: any; drawBuffer?: any; value?: any}
75
75
  ) {
76
- const device = WebGLDevice.attach(gl);
77
-
78
76
  const {framebuffer = null, buffer = GL_COLOR, drawBuffer = 0, value = [0, 0, 0, 0]} = options || {};
79
- withGLParameters(device.gl2, {framebuffer}, () => {
77
+ const gl = (device as WebGLDevice).gl;
78
+ withGLParameters(gl, {framebuffer}, () => {
80
79
  // Method selection per OpenGL ES 3 docs
81
80
  switch (buffer) {
82
81
  case GL_COLOR:
83
82
  switch (value.constructor) {
84
83
  case Int32Array:
85
- device.gl2.clearBufferiv(buffer, drawBuffer, value);
84
+ gl.clearBufferiv(buffer, drawBuffer, value);
86
85
  break;
87
86
  case Uint32Array:
88
- device.gl2.clearBufferuiv(buffer, drawBuffer, value);
87
+ gl.clearBufferuiv(buffer, drawBuffer, value);
89
88
  break;
90
89
  case Float32Array:
91
90
  default:
92
- device.gl2.clearBufferfv(buffer, drawBuffer, value);
91
+ gl.clearBufferfv(buffer, drawBuffer, value);
93
92
  }
94
93
  break;
95
94
 
96
95
  case GL_DEPTH:
97
- device.gl2.clearBufferfv(GL_DEPTH, 0, [value]);
96
+ gl.clearBufferfv(GL_DEPTH, 0, [value]);
98
97
  break;
99
98
 
100
99
  case GL_STENCIL:
101
- device.gl2.clearBufferiv(GL_STENCIL, 0, [value]);
100
+ gl.clearBufferiv(GL_STENCIL, 0, [value]);
102
101
  break;
103
102
 
104
103
  case GL_DEPTH_STENCIL:
105
104
  const [depth, stencil] = value;
106
- device.gl2.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
105
+ gl.clearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
107
106
  break;
108
107
 
109
108
  default:
@@ -240,8 +240,7 @@ export function copyToTexture(
240
240
  break;
241
241
  case GL.TEXTURE_2D_ARRAY:
242
242
  case GL.TEXTURE_3D:
243
- device.assertWebGL2();
244
- device.gl2.copyTexSubImage3D(
243
+ device.gl.copyTexSubImage3D(
245
244
  textureTarget,
246
245
  targetMipmaplevel,
247
246
  targetX,
@@ -0,0 +1,44 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ /**
5
+ * Stores luma.gl specific state associated with a context
6
+ */
7
+ export interface WebGLContextData {
8
+ _polyfilled: boolean;
9
+ _extensions: Record<string, any>;
10
+ }
11
+
12
+ /**
13
+ * Gets luma.gl specific state from a context
14
+ * @returns context state
15
+ */
16
+ export function getContextData(gl: WebGL2RenderingContext): WebGLContextData {
17
+ // @ts-expect-error
18
+ const luma = gl.luma as WebGLContextData | null;
19
+ if (!luma) {
20
+ const contextState: WebGLContextData = {
21
+ _polyfilled: false,
22
+ _extensions: {}
23
+ };
24
+ // @ts-expect-error
25
+ gl.luma = contextState;
26
+ }
27
+
28
+ // @ts-expect-error
29
+ return gl.luma;
30
+ }
31
+
32
+ export function initializeExtensions(gl: WebGL2RenderingContext): void {
33
+ const contextState = getContextData(gl);
34
+ // `getSupportedExtensions` can return null when context is lost.
35
+ const EXTENSIONS = gl.getSupportedExtensions() || [];
36
+ // Generates warnings in Chrome
37
+ const IGNORE_EXTENSIONS = ['WEBGL_polygon_mode'];
38
+ for (const extensionName of EXTENSIONS) {
39
+ if (!IGNORE_EXTENSIONS.includes(extensionName)) {
40
+ const extension = gl.getExtension(extensionName);
41
+ contextState._extensions[extensionName] = extension;
42
+ }
43
+ }
44
+ }
@@ -3,8 +3,6 @@
3
3
 
4
4
  /**
5
5
  * ContextProps
6
- * @param webgl2 Set to false to not create a WebGL2 context (force webgl1)
7
- * @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)
8
6
  * @param onContextLost
9
7
  * @param onContextRestored
10
8
  *
@@ -19,9 +17,6 @@
19
17
  * @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
20
18
  */
21
19
  type ContextProps = {
22
- type?: 'webgl' | 'webgl1' | 'webgl2' | string;
23
- webgl1?: boolean;
24
- webgl2?: boolean;
25
20
  onContextLost?: (event: Event) => void;
26
21
  onContextRestored?: (event: Event) => void;
27
22
  alpha?: boolean; // indicates if the canvas contains an alpha buffer.
@@ -35,8 +30,6 @@ type ContextProps = {
35
30
  };
36
31
 
37
32
  const DEFAULT_CONTEXT_PROPS: ContextProps = {
38
- webgl2: true, // Attempt to create a WebGL2 context
39
- webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)
40
33
  powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons
41
34
  // eslint-disable-next-line no-console
42
35
  onContextLost: () => console.error('WebGL context lost'),
@@ -52,7 +45,7 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
52
45
  export function createBrowserContext(
53
46
  canvas: HTMLCanvasElement | OffscreenCanvas,
54
47
  props: ContextProps
55
- ): WebGLRenderingContext {
48
+ ): WebGL2RenderingContext {
56
49
  props = {...DEFAULT_CONTEXT_PROPS, ...props};
57
50
 
58
51
  // Try to extract any extra information about why context creation failed
@@ -61,31 +54,17 @@ export function createBrowserContext(
61
54
  canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
62
55
 
63
56
  // Create the desired context
64
- let gl: WebGLRenderingContext | WebGL2RenderingContext | null = null;
65
-
66
- if (props.type === 'webgl2') {
67
- props = {...props, webgl1: false};
68
- }
69
- if (props.type === 'webgl1') {
70
- props = {...props, webgl2: false};
71
- }
57
+ let gl: WebGL2RenderingContext | null = null;
72
58
 
73
59
  // props.failIfMajorPerformanceCaveat = true;
74
60
 
75
- // Prefer webgl2 over webgl1 if both are acceptable
76
- if (!gl && props.webgl2) {
77
- gl = canvas.getContext('webgl2', props) as WebGL2RenderingContext;
78
- }
79
- if (!gl && props.webgl1) {
80
- gl = canvas.getContext('webgl', props) as WebGLRenderingContext;
81
- }
61
+ // We require webgl2 context
62
+ gl ||= canvas.getContext('webgl2', props) as WebGL2RenderingContext;
82
63
 
83
64
  // Software GPU
84
65
 
85
66
  // props.failIfMajorPerformanceCaveat = false;
86
- // if (!gl && props.webgl2) {
87
- // gl = canvas.getContext('webgl2', props);
88
- // }
67
+
89
68
  // if (!gl && props.webgl1) {
90
69
  // gl = canvas.getContext('webgl', props);
91
70
  // }
@@ -94,11 +73,7 @@ export function createBrowserContext(
94
73
  canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);
95
74
 
96
75
  if (!gl) {
97
- throw new Error(
98
- `Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${
99
- errorMessage || 'Unknown error'
100
- }`
101
- );
76
+ throw new Error(`Failed to create WebGL context: ${errorMessage || 'Unknown error'}`);
102
77
  }
103
78
 
104
79
  if (props.onContextLost) {
@@ -120,7 +95,7 @@ export function createBrowserContext(
120
95
  }
121
96
 
122
97
  /* TODO - can we call this asynchronously to catch the error events?
123
- export async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGLRenderingContext> {
98
+ export async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGL2RenderingContext> {
124
99
  props = {...DEFAULT_CONTEXT_PROPS, ...props};
125
100
 
126
101
  // Try to extract any extra information about why context creation failed
@@ -12,7 +12,6 @@ type DebugContextProps = {
12
12
  debug?: boolean;
13
13
  throwOnError?: boolean;
14
14
  break?: string[];
15
- webgl2?: boolean;
16
15
  };
17
16
 
18
17
  // const DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {
@@ -23,8 +22,8 @@ type DebugContextProps = {
23
22
  // }
24
23
 
25
24
  type ContextData = {
26
- realContext?: WebGLRenderingContext;
27
- debugContext?: WebGLRenderingContext;
25
+ realContext?: WebGL2RenderingContext;
26
+ debugContext?: WebGL2RenderingContext;
28
27
  }
29
28
 
30
29
  // Helper to get shared context data
@@ -55,7 +54,7 @@ export async function loadWebGLDeveloperTools(): Promise<void> {
55
54
 
56
55
  // Returns (a potentially new) context with debug instrumentation turned off or on.
57
56
  // Note that this actually returns a new context
58
- export function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext | null {
57
+ export function makeDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps = {}): WebGL2RenderingContext | null {
59
58
  // Return null to ensure we don't try to create a context in this case (TODO what case is that?)
60
59
  if (!gl) {
61
60
  return null;
@@ -65,14 +64,14 @@ export function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextP
65
64
  }
66
65
 
67
66
  // Returns the real context from either of the real/debug contexts
68
- function getRealContext(gl: WebGLRenderingContext): WebGLRenderingContext {
67
+ function getRealContext(gl: WebGL2RenderingContext): WebGL2RenderingContext {
69
68
  const data = getContextData(gl);
70
69
  // If the context has a realContext member, it is a debug context so return the realContext
71
70
  return data.realContext ? data.realContext : gl;
72
71
  }
73
72
 
74
73
  // Returns the debug context from either of the real/debug contexts
75
- function getDebugContext(gl: WebGLRenderingContext, props: DebugContextProps): WebGLRenderingContext {
74
+ function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps): WebGL2RenderingContext {
76
75
  if (!globalThis.WebGLDebugUtils) {
77
76
  log.warn('webgl-debug not loaded')();
78
77
  return gl;
@@ -131,8 +130,7 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
131
130
  args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg);
132
131
  const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
133
132
  const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
134
- const glName = props.webgl2 ? 'gl2' : 'gl1';
135
- const message = `${errorMessage} in ${glName}.${functionName}(${functionArgs})`;
133
+ const message = `${errorMessage} in gl.${functionName}(${functionArgs})`;
136
134
  log.error(message)();
137
135
  debugger; // eslint-disable-line
138
136
  if (props.throwOnError) {
@@ -24,7 +24,7 @@ export type {GLParameters};
24
24
  * This object is used to fill in any missing values for composite setter functions
25
25
  */
26
26
  export function setGLParameters(
27
- device: Device | WebGLRenderingContext,
27
+ device: Device | WebGL2RenderingContext,
28
28
  parameters: GLParameters
29
29
  ): void {
30
30
  const webglDevice = WebGLDevice.attach(device);
@@ -92,7 +92,7 @@ export function setGLParameters(
92
92
  * by external code needs to be synchronized for the first time
93
93
  */
94
94
  export function getGLParameters(
95
- device: Device | WebGLRenderingContext,
95
+ device: Device | WebGL2RenderingContext,
96
96
  parameters: keyof GLParameters | (keyof GLParameters)[] | GLParameters = GL_PARAMETER_DEFAULTS
97
97
  ): GLParameters {
98
98
  const webglDevice = WebGLDevice.attach(device);
@@ -123,7 +123,7 @@ export function getGLParameters(
123
123
  * NOT the canvas size dimensions, so they will have to be properly set after
124
124
  * calling this function.
125
125
  */
126
- export function resetGLParameters(device: Device | WebGLRenderingContext): void {
126
+ export function resetGLParameters(device: Device | WebGL2RenderingContext): void {
127
127
  setGLParameters(device, GL_PARAMETER_DEFAULTS);
128
128
  }
129
129