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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +71 -11
  3. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  4. package/dist/adapter/converters/sampler-parameters.js +3 -2
  5. package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
  6. package/dist/adapter/converters/shader-formats.js +40 -20
  7. package/dist/adapter/converters/texture-formats.d.ts +10 -7
  8. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  9. package/dist/adapter/converters/texture-formats.js +76 -64
  10. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/vertex-formats.js +2 -1
  12. package/dist/adapter/device-helpers/webgl-device-features.d.ts +18 -5
  13. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  14. package/dist/adapter/device-helpers/webgl-device-features.js +77 -43
  15. package/dist/adapter/device-helpers/webgl-device-info.d.ts +2 -1
  16. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -1
  17. package/dist/adapter/device-helpers/webgl-device-info.js +17 -14
  18. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +33 -48
  19. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -1
  20. package/dist/adapter/device-helpers/webgl-device-limits.js +42 -87
  21. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  22. package/dist/adapter/helpers/decode-webgl-types.js +2 -1
  23. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  24. package/dist/adapter/helpers/get-shader-layout.js +6 -5
  25. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  26. package/dist/adapter/helpers/parse-shader-compiler-log.js +3 -2
  27. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  28. package/dist/adapter/helpers/set-uniform.js +2 -1
  29. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  30. package/dist/adapter/helpers/webgl-topology-utils.js +2 -1
  31. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  32. package/dist/adapter/objects/constants-to-keys.js +2 -1
  33. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  34. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  35. package/dist/adapter/objects/webgl-renderbuffer.js +24 -11
  36. package/dist/adapter/objects/webgl-resource.d.ts +2 -24
  37. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  38. package/dist/adapter/objects/webgl-resource.js +6 -100
  39. package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
  40. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  41. package/dist/adapter/resources/webgl-buffer.js +2 -1
  42. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  43. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgl-command-buffer.js +7 -6
  45. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  46. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  47. package/dist/adapter/resources/webgl-command-encoder.js +4 -2
  48. package/dist/adapter/resources/webgl-external-texture.js +3 -2
  49. package/dist/adapter/resources/webgl-framebuffer.d.ts +6 -8
  50. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-framebuffer.js +25 -23
  52. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  53. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  54. package/dist/adapter/resources/webgl-query-set.js +136 -0
  55. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  56. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  57. package/dist/adapter/resources/webgl-render-pass.js +15 -7
  58. package/dist/adapter/resources/webgl-render-pipeline.d.ts +4 -5
  59. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  60. package/dist/adapter/resources/webgl-render-pipeline.js +34 -49
  61. package/dist/adapter/resources/webgl-sampler.d.ts +1 -1
  62. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  63. package/dist/adapter/resources/webgl-sampler.js +3 -2
  64. package/dist/adapter/resources/webgl-shader.d.ts +3 -2
  65. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  66. package/dist/adapter/resources/webgl-shader.js +12 -6
  67. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  68. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  69. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  70. package/dist/adapter/resources/webgl-texture.d.ts +4 -3
  71. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  72. package/dist/adapter/resources/webgl-texture.js +12 -7
  73. package/dist/adapter/resources/webgl-transform-feedback.d.ts +1 -1
  74. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  75. package/dist/adapter/resources/webgl-transform-feedback.js +2 -2
  76. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  77. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  78. package/dist/adapter/resources/webgl-vertex-array.js +5 -4
  79. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  80. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  81. package/dist/adapter/webgl-canvas-context.js +3 -2
  82. package/dist/adapter/webgl-device.d.ts +29 -27
  83. package/dist/adapter/webgl-device.d.ts.map +1 -1
  84. package/dist/adapter/webgl-device.js +90 -94
  85. package/dist/classic/accessor.d.ts.map +1 -1
  86. package/dist/classic/accessor.js +4 -3
  87. package/dist/classic/clear.d.ts.map +1 -1
  88. package/dist/classic/clear.js +3 -2
  89. package/dist/classic/copy-and-blit.d.ts +1 -1
  90. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  91. package/dist/classic/copy-and-blit.js +5 -4
  92. package/dist/classic/format-utils.d.ts +2 -2
  93. package/dist/classic/format-utils.d.ts.map +1 -1
  94. package/dist/classic/format-utils.js +2 -1
  95. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  96. package/dist/classic/typed-array-utils.js +2 -1
  97. package/dist/context/debug/spector.d.ts.map +1 -1
  98. package/dist/context/debug/spector.js +2 -1
  99. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  100. package/dist/context/debug/webgl-developer-tools.js +7 -6
  101. package/dist/context/helpers/create-browser-context.d.ts +35 -0
  102. package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
  103. package/dist/context/helpers/create-browser-context.js +67 -0
  104. package/dist/context/helpers/webgl-context-data.d.ts +13 -0
  105. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  106. package/dist/context/helpers/webgl-context-data.js +21 -0
  107. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  108. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  109. package/dist/context/helpers/webgl-extensions.js +10 -0
  110. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  111. package/dist/context/parameters/unified-parameter-api.js +4 -3
  112. package/dist/context/parameters/webgl-parameter-tables.d.ts +10 -0
  113. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  114. package/dist/context/parameters/webgl-parameter-tables.js +29 -16
  115. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  116. package/dist/context/state-tracker/deep-array-equal.js +2 -1
  117. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  118. package/dist/context/state-tracker/track-context-state.js +5 -4
  119. package/dist/context/state-tracker/with-parameters.d.ts +1 -1
  120. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  121. package/dist/context/state-tracker/with-parameters.js +5 -4
  122. package/dist/dist.dev.js +941 -730
  123. package/dist/index.cjs +732 -565
  124. package/dist/index.cjs.map +4 -4
  125. package/dist/index.d.ts +25 -25
  126. package/dist/index.d.ts.map +1 -1
  127. package/dist/index.js +24 -23
  128. package/dist/types.d.ts.map +1 -1
  129. package/dist/types.js +2 -1
  130. package/dist.min.js +5 -5
  131. package/package.json +4 -4
  132. package/src/adapter/converters/device-parameters.ts +105 -16
  133. package/src/adapter/converters/sampler-parameters.ts +12 -3
  134. package/src/adapter/converters/shader-formats.ts +47 -22
  135. package/src/adapter/converters/texture-formats.ts +87 -66
  136. package/src/adapter/converters/vertex-formats.ts +3 -3
  137. package/src/adapter/device-helpers/webgl-device-features.ts +83 -51
  138. package/src/adapter/device-helpers/webgl-device-info.ts +28 -19
  139. package/src/adapter/device-helpers/webgl-device-limits.ts +46 -150
  140. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  141. package/src/adapter/helpers/get-shader-layout.ts +4 -3
  142. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  143. package/src/adapter/helpers/set-uniform.ts +2 -1
  144. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  145. package/src/adapter/objects/constants-to-keys.ts +2 -1
  146. package/src/adapter/objects/webgl-renderbuffer.ts +35 -13
  147. package/src/adapter/objects/webgl-resource.ts +6 -124
  148. package/src/adapter/resources/webgl-buffer.ts +4 -3
  149. package/src/adapter/resources/webgl-command-buffer.ts +5 -5
  150. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  151. package/src/adapter/resources/webgl-external-texture.ts +3 -2
  152. package/src/adapter/resources/webgl-framebuffer.ts +34 -29
  153. package/src/adapter/resources/webgl-query-set.ts +171 -0
  154. package/src/adapter/resources/webgl-render-pass.ts +17 -8
  155. package/src/adapter/resources/webgl-render-pipeline.ts +41 -48
  156. package/src/adapter/resources/webgl-sampler.ts +2 -1
  157. package/src/adapter/resources/webgl-shader.ts +12 -5
  158. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  159. package/src/adapter/resources/webgl-texture.ts +9 -2
  160. package/src/adapter/resources/webgl-transform-feedback.ts +2 -7
  161. package/src/adapter/resources/webgl-vertex-array.ts +4 -3
  162. package/src/adapter/webgl-canvas-context.ts +6 -4
  163. package/src/adapter/webgl-device.ts +94 -90
  164. package/src/classic/accessor.ts +5 -4
  165. package/src/classic/clear.ts +12 -6
  166. package/src/classic/copy-and-blit.ts +11 -4
  167. package/src/classic/format-utils.ts +2 -1
  168. package/src/classic/typed-array-utils.ts +3 -7
  169. package/src/context/debug/spector.ts +9 -6
  170. package/src/context/debug/webgl-developer-tools.ts +27 -14
  171. package/src/context/{context → helpers}/create-browser-context.ts +3 -2
  172. package/src/context/helpers/webgl-context-data.ts +31 -0
  173. package/src/context/helpers/webgl-extensions.ts +17 -0
  174. package/src/context/parameters/unified-parameter-api.ts +2 -1
  175. package/src/context/parameters/webgl-parameter-tables.ts +69 -32
  176. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  177. package/src/context/state-tracker/track-context-state.ts +11 -6
  178. package/src/context/state-tracker/with-parameters.ts +7 -2
  179. package/src/index.ts +3 -2
  180. package/src/types.ts +2 -1
  181. package/src/context/context/context-data.ts +0 -44
@@ -1,11 +1,10 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import type {
5
6
  DeviceProps,
6
7
  DeviceInfo,
7
- DeviceLimits,
8
- DeviceFeature,
9
8
  CanvasContextProps,
10
9
  TextureFormat,
11
10
  VertexArray,
@@ -16,16 +15,16 @@ import type {
16
15
  TypedArray
17
16
  } from '@luma.gl/core';
18
17
  import {Device, CanvasContext, log, uid, assert} from '@luma.gl/core';
19
- import {isBrowser} from '@probe.gl/env';
18
+ import type {GLExtensions} from '@luma.gl/constants';
20
19
  import {
21
20
  popContextState,
22
21
  pushContextState,
23
22
  trackContextState
24
23
  } from '../context/state-tracker/track-context-state';
25
- import {createBrowserContext} from '../context/context/create-browser-context';
24
+ import {createBrowserContext} from '../context/helpers/create-browser-context';
26
25
  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';
26
+ import {WebGLDeviceFeatures} from './device-helpers/webgl-device-features';
27
+ import {WebGLDeviceLimits} from './device-helpers/webgl-device-limits';
29
28
  import {WebGLCanvasContext} from './webgl-canvas-context';
30
29
  import {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';
31
30
  import {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';
@@ -55,7 +54,8 @@ import type {
55
54
  ComputePassProps,
56
55
  // CommandEncoder,
57
56
  CommandEncoderProps,
58
- TransformFeedbackProps
57
+ TransformFeedbackProps,
58
+ QuerySetProps
59
59
  } from '@luma.gl/core';
60
60
 
61
61
  import {WEBGLBuffer} from './resources/webgl-buffer';
@@ -68,11 +68,13 @@ import {WEBGLRenderPipeline} from './resources/webgl-render-pipeline';
68
68
  import {WEBGLCommandEncoder} from './resources/webgl-command-encoder';
69
69
  import {WEBGLVertexArray} from './resources/webgl-vertex-array';
70
70
  import {WEBGLTransformFeedback} from './resources/webgl-transform-feedback';
71
+ import {WEBGLQuerySet} from './resources/webgl-query-set';
71
72
 
72
73
  import {readPixelsToArray, readPixelsToBuffer} from '../classic/copy-and-blit';
73
74
  import {setGLParameters, getGLParameters} from '../context/parameters/unified-parameter-api';
74
75
  import {withGLParameters} from '../context/state-tracker/with-parameters';
75
76
  import {clear} from '../classic/clear';
77
+ import {getWebGLExtension} from '../context/helpers/webgl-extensions';
76
78
 
77
79
  const LOG_LEVEL = 1;
78
80
 
@@ -88,26 +90,17 @@ export class WebGLDevice extends Device {
88
90
  return typeof WebGL2RenderingContext !== 'undefined';
89
91
  }
90
92
 
91
- readonly info: DeviceInfo;
92
- readonly canvasContext: WebGLCanvasContext;
93
-
93
+ /** The underlying WebGL context */
94
94
  readonly handle: WebGL2RenderingContext;
95
+ features: WebGLDeviceFeatures;
96
+ limits: WebGLDeviceLimits;
95
97
 
96
- get features(): Set<DeviceFeature> {
97
- this._features = this._features || getDeviceFeatures(this.gl);
98
- return this._features;
99
- }
100
-
101
- get limits(): DeviceLimits {
102
- this._limits = this._limits || getDeviceLimits(this.gl);
103
- return this._limits;
104
- }
98
+ readonly info: DeviceInfo;
99
+ readonly canvasContext: WebGLCanvasContext;
105
100
 
106
101
  readonly lost: Promise<{reason: 'destroyed'; message: string}>;
107
102
 
108
103
  private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
109
- private _features?: Set<DeviceFeature>;
110
- private _limits?: DeviceLimits;
111
104
 
112
105
  //
113
106
  // Static methods, expected to be present by `luma.createDevice()`
@@ -137,27 +130,31 @@ export class WebGLDevice extends Device {
137
130
  static async create(props: DeviceProps = {}): Promise<WebGLDevice> {
138
131
  log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
139
132
 
140
- // Wait for page to load. Only wait when props. canvas is string
141
- // to avoid setting page onload callback unless necessary
142
- if (typeof props.canvas === 'string') {
143
- await CanvasContext.pageLoaded;
144
- }
133
+ const promises: Promise<unknown>[] = [];
145
134
 
146
135
  // Load webgl and spector debug scripts from CDN if requested
147
- if (log.get('debug') || props.debug) {
148
- await loadWebGLDeveloperTools();
136
+ if (props.debug) {
137
+ promises.push(loadWebGLDeveloperTools());
149
138
  }
150
139
 
151
- // @ts-expect-error spector not on props
152
- const {spector} = props;
153
- if (log.get('spector') || spector) {
154
- await loadSpectorJS();
140
+ if (props.spector) {
141
+ promises.push(loadSpectorJS());
155
142
  }
156
143
 
144
+ // Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
145
+ // We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
146
+ if (typeof props.canvas === 'string') {
147
+ promises.push(CanvasContext.pageLoaded);
148
+ }
149
+
150
+ // Wait for all the loads to settle before creating the context.
151
+ // The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
152
+ await Promise.all(promises);
153
+
157
154
  log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
158
155
 
159
156
  // @ts-expect-error
160
- if (props.gl && props.gl.device) {
157
+ if (props.gl?.device) {
161
158
  return WebGLDevice.attach(props.gl);
162
159
  }
163
160
 
@@ -190,41 +187,39 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
190
187
  }
191
188
 
192
189
  // Create and instrument context
193
- const canvas = props.canvas || props.gl?.canvas;
190
+ const canvas = props.gl?.canvas || props.canvas;
194
191
  this.canvasContext = new WebGLCanvasContext(this, {...props, canvas});
195
192
 
196
193
  this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {
197
194
  this._resolveContextLost = resolve;
198
195
  });
199
196
 
200
- const onContextLost = (event: Event) =>
201
- this._resolveContextLost?.({
202
- reason: 'destroyed',
203
- message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
204
- });
205
-
206
197
  let gl: WebGL2RenderingContext | null = props.gl || null;
207
- gl =
208
- gl ||
209
- (isBrowser()
210
- ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost})
211
- : null);
212
-
198
+ gl ||= createBrowserContext(this.canvasContext.canvas, {
199
+ ...props,
200
+ onContextLost: (event: Event) =>
201
+ this._resolveContextLost?.({
202
+ reason: 'destroyed',
203
+ message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
204
+ })
205
+ });
206
+
213
207
  if (!gl) {
214
208
  throw new Error('WebGL context creation failed');
215
209
  }
216
210
 
217
211
  this.handle = gl;
218
- this.gl = this.handle;
219
- this.canvasContext.resize();
212
+ this.gl = gl;
213
+
214
+ (this.gl as any).device = this; // Update GL context: Link webgl context back to device
215
+ (this.gl as any)._version = 2; // Update GL context: Store WebGL version field on gl context (HACK to identify debug contexts)
220
216
 
221
217
  // luma Device fields
222
- this.info = getDeviceInfo(this.gl);
218
+ this.info = getDeviceInfo(this.gl, this._extensions);
219
+ this.features = new WebGLDeviceFeatures(this.gl, this._extensions);
220
+ this.limits = new WebGLDeviceLimits(this.gl);
223
221
 
224
- // @ts-expect-error Link webgl context back to device
225
- this.gl.device = this;
226
- // @ts-expect-error Annotate webgl context to handle
227
- this.gl._version = this.isWebGL2 ? 2 : 1;
222
+ this.canvasContext.resize();
228
223
 
229
224
  // Install context state tracking
230
225
  // @ts-expect-error - hidden parameters
@@ -236,26 +231,23 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
236
231
  });
237
232
 
238
233
  // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
239
- if (isBrowser() && props.debug) {
234
+ if (props.debug) {
240
235
  this.gl = makeDebugContext(this.gl, {...props, throwOnError: true});
241
236
  this.debug = true;
242
237
  log.level = Math.max(log.level, 1);
243
238
  log.warn('WebGL debug mode activated. Performance reduced.')();
244
239
  }
245
240
 
246
- // @ts-expect-error spector not on props
247
- if (isBrowser() && props.spector) {
248
- const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);
249
- this.spector = initializeSpectorJS({...this.props, canvas});
241
+ if (props.spector) {
242
+ this.spectorJS = initializeSpectorJS({...this.props, canvas: this.handle.canvas});
250
243
  }
251
244
  }
252
245
 
253
246
  /**
254
247
  * Destroys the context
255
- * @note Has no effect for browser contexts, there is no browser API for destroying contexts
248
+ * @note Has no effect for WebGL browser contexts, there is no browser API for destroying contexts
256
249
  */
257
- destroy(): void {
258
- }
250
+ destroy(): void {}
259
251
 
260
252
  get isLost(): boolean {
261
253
  return this.gl.isContextLost();
@@ -266,15 +258,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
266
258
  }
267
259
 
268
260
  isTextureFormatSupported(format: TextureFormat): boolean {
269
- return isTextureFormatSupported(this.gl, format);
261
+ return isTextureFormatSupported(this.gl, format, this._extensions);
270
262
  }
271
263
 
272
264
  isTextureFormatFilterable(format: TextureFormat): boolean {
273
- return isTextureFormatFilterable(this.gl, format);
265
+ return isTextureFormatFilterable(this.gl, format, this._extensions);
274
266
  }
275
267
 
276
268
  isTextureFormatRenderable(format: TextureFormat): boolean {
277
- return isTextureFormatRenderable(this.gl, format);
269
+ return isTextureFormatRenderable(this.gl, format, this._extensions);
278
270
  }
279
271
 
280
272
  // IMPLEMENTATION OF ABSTRACT DEVICE
@@ -308,12 +300,20 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
308
300
  return new WEBGLFramebuffer(this, props);
309
301
  }
310
302
 
311
- createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {
312
- return new WEBGLRenderPipeline(this, props);
303
+ createVertexArray(props: VertexArrayProps): VertexArray {
304
+ return new WEBGLVertexArray(this, props);
313
305
  }
314
306
 
315
- override createVertexArray(props: VertexArrayProps): VertexArray {
316
- return new WEBGLVertexArray(this, props);
307
+ createTransformFeedback(props: TransformFeedbackProps): WEBGLTransformFeedback {
308
+ return new WEBGLTransformFeedback(this, props);
309
+ }
310
+
311
+ createQuerySet(props: QuerySetProps): WEBGLQuerySet {
312
+ return new WEBGLQuerySet(this, props);
313
+ }
314
+
315
+ createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {
316
+ return new WEBGLRenderPipeline(this, props);
317
317
  }
318
318
 
319
319
  beginRenderPass(props: RenderPassProps): WEBGLRenderPass {
@@ -328,10 +328,6 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
328
328
  throw new Error('ComputePass not supported in WebGL');
329
329
  }
330
330
 
331
- createTransformFeedback(props: TransformFeedbackProps): WEBGLTransformFeedback {
332
- return new WEBGLTransformFeedback(this, props);
333
- }
334
-
335
331
  private renderPass: WEBGLRenderPass | null = null;
336
332
 
337
333
  getDefaultRenderPass(): WEBGLRenderPass {
@@ -360,7 +356,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
360
356
 
361
357
  //
362
358
  // TEMPORARY HACKS - will be removed in v9.1
363
- //
359
+ //
364
360
 
365
361
  /** @deprecated - should use command encoder */
366
362
  override readPixelsToArrayWebGL(
@@ -410,10 +406,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
410
406
  withGLParameters(this, parameters, func);
411
407
  }
412
408
 
413
- override clearWebGL(options?: {framebuffer?: Framebuffer; color?: any; depth?: any; stencil?: any}): void {
409
+ override clearWebGL(options?: {
410
+ framebuffer?: Framebuffer;
411
+ color?: any;
412
+ depth?: any;
413
+ stencil?: any;
414
+ }): void {
414
415
  clear(this, options);
415
416
  }
416
-
417
+
417
418
  //
418
419
  // WebGL-only API (not part of `Device` API)
419
420
  //
@@ -426,19 +427,11 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
426
427
  readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
427
428
 
428
429
  /** State used by luma.gl classes - TODO - not used? */
429
- readonly _extensions: Record<string, any> = {};
430
+ readonly _extensions: GLExtensions = {};
430
431
  _polyfilled: boolean = false;
431
432
 
432
433
  /** Instance of Spector.js (if initialized) */
433
- spector;
434
-
435
- private _webglLimits?: WebGLLimits;
436
-
437
- /** Return WebGL specific limits */
438
- get webglLimits(): WebGLLimits {
439
- this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
440
- return this._webglLimits;
441
- }
434
+ spectorJS: unknown;
442
435
 
443
436
  /**
444
437
  * Triggers device (or WebGL context) loss.
@@ -446,7 +439,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
446
439
  */
447
440
  override loseDevice(): boolean {
448
441
  let deviceLossTriggered = false;
449
- const ext = this.gl.getExtension('WEBGL_lose_context');
442
+ const extensions = this.getExtension('WEBGL_lose_context');
443
+ const ext = extensions.WEBGL_lose_context;
450
444
  if (ext) {
451
445
  deviceLossTriggered = true;
452
446
  ext.loseContext();
@@ -507,11 +501,15 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
507
501
  * so they need to be updated before every render
508
502
  * @todo - remember/cache values to avoid setting them unnecessarily?
509
503
  */
510
- setConstantAttribute(location: number, constant: TypedArray): void {
511
- this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
504
+ setConstantAttributeWebGL(location: number, constant: TypedArray): void {
505
+ const maxVertexAttributes = this.limits.maxVertexAttributes;
506
+ this._constants = this._constants || new Array(maxVertexAttributes).fill(null);
512
507
  const currentConstant = this._constants[location];
513
508
  if (currentConstant && compareConstantArrayValues(currentConstant, constant)) {
514
- log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
509
+ log.info(
510
+ 1,
511
+ `setConstantAttributeWebGL(${location}) could have been skipped, value unchanged`
512
+ )();
515
513
  }
516
514
  this._constants[location] = constant;
517
515
 
@@ -529,6 +527,12 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
529
527
  assert(false);
530
528
  }
531
529
  }
530
+
531
+ /** Ensure extensions are only requested once */
532
+ getExtension(name: keyof GLExtensions): GLExtensions {
533
+ getWebGLExtension(this.gl, name, this._extensions);
534
+ return this._extensions;
535
+ }
532
536
  }
533
537
 
534
538
  /** Check if supplied parameter is a WebGL2RenderingContext */
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {assert, checkProps, Buffer, AccessorObject} from '@luma.gl/core';
@@ -58,7 +59,7 @@ export class Accessor implements AccessorObject {
58
59
  }
59
60
 
60
61
  constructor(...accessors: AccessorObject[]) {
61
- accessors.forEach((accessor) => this._assign(accessor)); // Merge in sequence
62
+ accessors.forEach(accessor => this._assign(accessor)); // Merge in sequence
62
63
  Object.freeze(this);
63
64
  }
64
65
 
@@ -151,10 +152,10 @@ export class Accessor implements AccessorObject {
151
152
  if (this.divisor === undefined) delete this.divisor;
152
153
  if (this.normalized === undefined) delete this.normalized;
153
154
  if (this.integer === undefined) delete this.integer;
154
-
155
+
155
156
  if (this.buffer === undefined) delete this.buffer;
156
157
  if (this.index === undefined) delete this.index;
157
-
158
+
158
159
  return this;
159
160
  }
160
161
  }
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {Device, Framebuffer, assert} from '@luma.gl/core';
@@ -18,8 +19,8 @@ const GL_DEPTH_STENCIL = 0x84f9;
18
19
  // Should disappear if asserts are removed
19
20
  const ERR_ARGUMENTS = 'clear: bad arguments';
20
21
 
21
- /**
22
- * Optionally clears depth, color and stencil buffers
22
+ /**
23
+ * Optionally clears depth, color and stencil buffers
23
24
  * @deprecated Set clear color when creating a RenderPass.
24
25
  */
25
26
  export function clear(
@@ -65,15 +66,20 @@ export function clear(
65
66
  });
66
67
  }
67
68
 
68
- /**
69
- * WebGL2 - clear a specific drawing buffer
69
+ /**
70
+ * WebGL2 - clear a specific drawing buffer
70
71
  * @deprecated Set clear color when creating a RenderPass
71
72
  */
72
73
  export function clearBuffer(
73
74
  device: Device,
74
75
  options?: {framebuffer?: Framebuffer; buffer?: any; drawBuffer?: any; value?: any}
75
76
  ) {
76
- const {framebuffer = null, buffer = GL_COLOR, drawBuffer = 0, value = [0, 0, 0, 0]} = options || {};
77
+ const {
78
+ framebuffer = null,
79
+ buffer = GL_COLOR,
80
+ drawBuffer = 0,
81
+ value = [0, 0, 0, 0]
82
+ } = options || {};
77
83
  const gl = (device as WebGLDevice).gl;
78
84
  withGLParameters(gl, {framebuffer}, () => {
79
85
  // Method selection per OpenGL ES 3 docs
@@ -1,10 +1,11 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {assert, Buffer, Texture, Framebuffer, FramebufferProps} from '@luma.gl/core';
5
6
  import {GL} from '@luma.gl/constants';
6
7
 
7
- import {WEBGLTexture} from '../adapter/resources/webgl-texture';
8
+ import {WEBGLTextureView} from '../adapter/resources/webgl-texture-view';
8
9
  import {WEBGLFramebuffer} from '../adapter/resources/webgl-framebuffer';
9
10
  import {getGLTypeFromTypedArray, getTypedArrayFromGLType} from './typed-array-utils';
10
11
  import {glFormatToComponents, glTypeToBytes} from './format-utils';
@@ -66,7 +67,7 @@ export function readPixelsToArray(
66
67
  // Deduce the type from color attachment if not provided.
67
68
  sourceType =
68
69
  sourceType ||
69
- (framebuffer.colorAttachments[attachment] as WEBGLTexture)?.type ||
70
+ (framebuffer.colorAttachments[attachment] as WEBGLTextureView)?.texture?.type ||
70
71
  GL.UNSIGNED_BYTE;
71
72
 
72
73
  // Deduce type and allocated pixelArray if needed
@@ -106,7 +107,13 @@ export function readPixelsToBuffer(
106
107
  sourceType?: number;
107
108
  }
108
109
  ): WEBGLBuffer {
109
- const {target, sourceX = 0, sourceY = 0, sourceFormat = GL.RGBA, targetByteOffset = 0} = options || {};
110
+ const {
111
+ target,
112
+ sourceX = 0,
113
+ sourceY = 0,
114
+ sourceFormat = GL.RGBA,
115
+ targetByteOffset = 0
116
+ } = options || {};
110
117
  // following parameters are auto deduced if not provided
111
118
  let {sourceWidth, sourceHeight, sourceType} = options || {};
112
119
  const {framebuffer, deleteFramebuffer} = getFramebuffer(source);
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {assert} from '@luma.gl/core';
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {TypedArray, TypedArrayConstructor} from '@luma.gl/core';
@@ -108,12 +109,7 @@ export function flipRows(options: {
108
109
  }
109
110
  }
110
111
 
111
-
112
- export function scalePixels(options: {
113
- data: TypedArray;
114
- width: number;
115
- height: number;
116
- }): {
112
+ export function scalePixels(options: {data: TypedArray; width: number; height: number}): {
117
113
  data: Uint8Array;
118
114
  width: number;
119
115
  height: number;
@@ -1,4 +1,5 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {log, loadScript} from '@luma.gl/core';
@@ -34,8 +35,8 @@ export async function loadSpectorJS(props?: SpectorProps) {
34
35
  if (!globalThis.SPECTOR) {
35
36
  try {
36
37
  await loadScript(SPECTOR_CDN_URL);
37
- } catch(error) {
38
- log.warn(String(error))
38
+ } catch (error) {
39
+ log.warn(String(error));
39
40
  }
40
41
  }
41
42
  }
@@ -64,14 +65,16 @@ export function initializeSpectorJS(props?: SpectorProps) {
64
65
  // enables recording some extra information merged in the capture like texture memory sizes and formats
65
66
  spector.spyCanvases();
66
67
  // A callback when results are ready
67
- spector?.onCaptureStarted.add((capture: unknown) => log.info('Spector capture started:', capture)());
68
+ spector?.onCaptureStarted.add((capture: unknown) =>
69
+ log.info('Spector capture started:', capture)()
70
+ );
68
71
  spector?.onCapture.add((capture: unknown) => {
69
72
  log.info('Spector capture complete:', capture)();
70
73
  // Use undocumented Spector API to open the UI with our capture
71
74
  // See https://github.com/BabylonJS/Spector.js/blob/767ad1195a25b85a85c381f400eb50a979239eca/src/spector.ts#L124
72
- spector?.getResultUI()
75
+ spector?.getResultUI();
73
76
  spector?.resultView.display();
74
- spector?.resultView.addCapture(capture)
77
+ spector?.resultView.addCapture(capture);
75
78
  });
76
79
  }
77
80
 
@@ -1,10 +1,11 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
5
  import {log, loadScript} from '@luma.gl/core';
5
6
  // Rename constant to prevent inlining. We need the full set of constants for generating debug strings.
6
7
  import {GL as GLEnum} from '@luma.gl/constants';
7
- import {isBrowser} from '@probe.gl/env'
8
+ import {isBrowser} from '@probe.gl/env';
8
9
 
9
10
  const WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';
10
11
 
@@ -24,10 +25,10 @@ type DebugContextProps = {
24
25
  type ContextData = {
25
26
  realContext?: WebGL2RenderingContext;
26
27
  debugContext?: WebGL2RenderingContext;
27
- }
28
+ };
28
29
 
29
30
  // Helper to get shared context data
30
- function getContextData(gl: any): ContextData {
31
+ function getWebGLContextData(gl: any): ContextData {
31
32
  gl.luma = gl.luma || {};
32
33
  return gl.luma;
33
34
  }
@@ -38,7 +39,7 @@ declare global {
38
39
  }
39
40
 
40
41
  /**
41
- * Loads Khronos WebGLDeveloperTools from CDN if not already installed
42
+ * Loads Khronos WebGLDeveloperTools from CDN if not already installed
42
43
  * const WebGLDebugUtils = require('webgl-debug');
43
44
  * @see https://github.com/KhronosGroup/WebGLDeveloperTools
44
45
  * @see https://github.com/vorg/webgl-debug
@@ -54,7 +55,10 @@ export async function loadWebGLDeveloperTools(): Promise<void> {
54
55
 
55
56
  // Returns (a potentially new) context with debug instrumentation turned off or on.
56
57
  // Note that this actually returns a new context
57
- export function makeDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps = {}): WebGL2RenderingContext | null {
58
+ export function makeDebugContext(
59
+ gl: WebGL2RenderingContext,
60
+ props: DebugContextProps = {}
61
+ ): WebGL2RenderingContext | null {
58
62
  // Return null to ensure we don't try to create a context in this case (TODO what case is that?)
59
63
  if (!gl) {
60
64
  return null;
@@ -65,19 +69,22 @@ export function makeDebugContext(gl: WebGL2RenderingContext, props: DebugContext
65
69
 
66
70
  // Returns the real context from either of the real/debug contexts
67
71
  function getRealContext(gl: WebGL2RenderingContext): WebGL2RenderingContext {
68
- const data = getContextData(gl);
72
+ const data = getWebGLContextData(gl);
69
73
  // If the context has a realContext member, it is a debug context so return the realContext
70
74
  return data.realContext ? data.realContext : gl;
71
75
  }
72
76
 
73
77
  // Returns the debug context from either of the real/debug contexts
74
- function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps): WebGL2RenderingContext {
78
+ function getDebugContext(
79
+ gl: WebGL2RenderingContext,
80
+ props: DebugContextProps
81
+ ): WebGL2RenderingContext {
75
82
  if (!globalThis.WebGLDebugUtils) {
76
83
  log.warn('webgl-debug not loaded')();
77
84
  return gl;
78
85
  }
79
86
 
80
- const data = getContextData(gl);
87
+ const data = getWebGLContextData(gl);
81
88
 
82
89
  // If this already has a debug context, return it.
83
90
  if (data.debugContext) {
@@ -98,7 +105,7 @@ function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps):
98
105
  glDebug[key] = GLEnum[key];
99
106
  }
100
107
  }
101
-
108
+
102
109
  // Ensure we have a clean prototype on the instrumented object
103
110
  // Note: setPrototypeOf does come with perf warnings, but we already take a bigger perf reduction
104
111
  // by synchronizing the WebGL errors after each WebGL call.
@@ -119,7 +126,7 @@ function getDebugContext(gl: WebGL2RenderingContext, props: DebugContextProps):
119
126
 
120
127
  function getFunctionString(functionName: string, functionArgs): string {
121
128
  // Cover bug in webgl-debug-tools
122
- functionArgs = Array.from(functionArgs).map(arg => arg === undefined ? 'undefined' : arg);
129
+ functionArgs = Array.from(functionArgs).map(arg => (arg === undefined ? 'undefined' : arg));
123
130
  let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);
124
131
  args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`;
125
132
  return `gl.${functionName}(${args})`;
@@ -127,7 +134,7 @@ function getFunctionString(functionName: string, functionArgs): string {
127
134
 
128
135
  function onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void {
129
136
  // Cover bug in webgl-debug-tools
130
- args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg);
137
+ args = Array.from(args).map(arg => (arg === undefined ? 'undefined' : arg));
131
138
  const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);
132
139
  const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);
133
140
  const message = `${errorMessage} in gl.${functionName}(${functionArgs})`;
@@ -139,7 +146,11 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
139
146
  }
140
147
 
141
148
  // Don't generate function string until it is needed
142
- function onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void {
149
+ function onValidateGLFunc(
150
+ props: DebugContextProps,
151
+ functionName: string,
152
+ functionArgs: any[]
153
+ ): void {
143
154
  let functionString: string = '';
144
155
  if (log.level >= 1) {
145
156
  functionString = getFunctionString(functionName, functionArgs);
@@ -149,7 +160,9 @@ function onValidateGLFunc(props: DebugContextProps, functionName: string, functi
149
160
  // If array of breakpoint strings supplied, check if any of them is contained in current GLEnum function
150
161
  if (props.break && props.break.length > 0) {
151
162
  functionString = functionString || getFunctionString(functionName, functionArgs);
152
- const isBreakpoint = props.break.every((breakOn: string) => functionString.indexOf(breakOn) !== -1);
163
+ const isBreakpoint = props.break.every(
164
+ (breakOn: string) => functionString.indexOf(breakOn) !== -1
165
+ );
153
166
  if (isBreakpoint) {
154
167
  debugger; // eslint-disable-line
155
168
  }