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

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 (192) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +128 -71
  3. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  4. package/dist/adapter/converters/sampler-parameters.js +20 -19
  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 +16 -11
  8. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  9. package/dist/adapter/converters/texture-formats.js +224 -205
  10. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  11. package/dist/adapter/converters/vertex-formats.js +22 -21
  12. package/dist/adapter/device-helpers/webgl-device-features.d.ts +19 -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 +89 -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 +22 -19
  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 +47 -46
  23. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  24. package/dist/adapter/helpers/get-shader-layout.js +35 -34
  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 +42 -41
  29. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  30. package/dist/adapter/helpers/webgl-topology-utils.js +40 -39
  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 +30 -17
  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 -101
  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 +16 -15
  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 +32 -31
  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 +6 -5
  49. package/dist/adapter/resources/webgl-framebuffer.d.ts +6 -10
  50. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-framebuffer.js +60 -53
  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 +20 -12
  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 +52 -61
  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 +5 -4
  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 +15 -9
  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 +6 -4
  71. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  72. package/dist/adapter/resources/webgl-texture.js +39 -32
  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 +10 -10
  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 +10 -9
  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 +35 -30
  83. package/dist/adapter/webgl-device.d.ts.map +1 -1
  84. package/dist/adapter/webgl-device.js +110 -109
  85. package/dist/classic/accessor.d.ts.map +1 -1
  86. package/dist/classic/accessor.js +8 -7
  87. package/dist/classic/clear.d.ts.map +1 -1
  88. package/dist/classic/clear.js +5 -4
  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 +19 -19
  92. package/dist/classic/format-utils.d.ts.map +1 -1
  93. package/dist/classic/format-utils.js +16 -15
  94. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  95. package/dist/classic/typed-array-utils.js +20 -19
  96. package/dist/context/debug/spector.d.ts.map +1 -1
  97. package/dist/context/debug/spector.js +2 -1
  98. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  99. package/dist/context/debug/webgl-developer-tools.js +7 -6
  100. package/dist/context/{context → helpers}/create-browser-context.d.ts.map +1 -1
  101. package/dist/context/{context → helpers}/create-browser-context.js +2 -1
  102. package/dist/context/{context/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -3
  103. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  104. package/dist/context/helpers/webgl-context-data.js +21 -0
  105. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  106. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  107. package/dist/context/helpers/webgl-extensions.js +10 -0
  108. package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
  109. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  110. package/dist/context/parameters/unified-parameter-api.js +7 -11
  111. package/dist/context/parameters/webgl-parameter-tables.d.ts +12 -13
  112. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  113. package/dist/context/parameters/webgl-parameter-tables.js +302 -295
  114. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  115. package/dist/context/state-tracker/deep-array-equal.js +2 -1
  116. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  117. package/dist/context/state-tracker/track-context-state.js +5 -4
  118. package/dist/context/state-tracker/with-parameters.d.ts +2 -3
  119. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  120. package/dist/context/state-tracker/with-parameters.js +6 -8
  121. package/dist/dist.dev.js +1635 -1387
  122. package/dist/index.cjs +1766 -1534
  123. package/dist/index.cjs.map +4 -4
  124. package/dist/index.d.ts +25 -25
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +24 -23
  127. package/dist/types.d.ts.map +1 -1
  128. package/dist/types.js +2 -1
  129. package/dist.min.js +6 -6
  130. package/package.json +4 -4
  131. package/src/adapter/converters/device-parameters.ts +114 -27
  132. package/src/adapter/converters/sampler-parameters.ts +12 -3
  133. package/src/adapter/converters/shader-formats.ts +47 -22
  134. package/src/adapter/converters/texture-formats.ts +138 -114
  135. package/src/adapter/converters/vertex-formats.ts +3 -3
  136. package/src/adapter/device-helpers/webgl-device-features.ts +102 -50
  137. package/src/adapter/device-helpers/webgl-device-info.ts +28 -19
  138. package/src/adapter/device-helpers/webgl-device-limits.ts +46 -150
  139. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  140. package/src/adapter/helpers/get-shader-layout.ts +4 -3
  141. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  142. package/src/adapter/helpers/set-uniform.ts +2 -1
  143. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  144. package/src/adapter/objects/constants-to-keys.ts +2 -1
  145. package/src/adapter/objects/webgl-renderbuffer.ts +36 -14
  146. package/src/adapter/objects/webgl-resource.ts +7 -125
  147. package/src/adapter/resources/webgl-buffer.ts +4 -3
  148. package/src/adapter/resources/webgl-command-buffer.ts +5 -5
  149. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  150. package/src/adapter/resources/webgl-external-texture.ts +6 -5
  151. package/src/adapter/resources/webgl-framebuffer.ts +61 -53
  152. package/src/adapter/resources/webgl-query-set.ts +171 -0
  153. package/src/adapter/resources/webgl-render-pass.ts +20 -11
  154. package/src/adapter/resources/webgl-render-pipeline.ts +54 -54
  155. package/src/adapter/resources/webgl-sampler.ts +2 -1
  156. package/src/adapter/resources/webgl-shader.ts +12 -5
  157. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  158. package/src/adapter/resources/webgl-texture.ts +14 -3
  159. package/src/adapter/resources/webgl-transform-feedback.ts +2 -7
  160. package/src/adapter/resources/webgl-vertex-array.ts +4 -3
  161. package/src/adapter/webgl-canvas-context.ts +6 -4
  162. package/src/adapter/webgl-device.ts +116 -107
  163. package/src/classic/accessor.ts +5 -4
  164. package/src/classic/clear.ts +14 -8
  165. package/src/classic/copy-and-blit.ts +11 -4
  166. package/src/classic/format-utils.ts +2 -1
  167. package/src/classic/typed-array-utils.ts +3 -7
  168. package/src/context/debug/spector.ts +9 -6
  169. package/src/context/debug/webgl-developer-tools.ts +27 -14
  170. package/src/context/{context → helpers}/create-browser-context.ts +3 -2
  171. package/src/context/helpers/webgl-context-data.ts +31 -0
  172. package/src/context/helpers/webgl-extensions.ts +17 -0
  173. package/src/context/parameters/unified-parameter-api.ts +6 -17
  174. package/src/context/parameters/webgl-parameter-tables.ts +69 -32
  175. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  176. package/src/context/state-tracker/track-context-state.ts +11 -6
  177. package/src/context/state-tracker/with-parameters.ts +8 -8
  178. package/src/index.ts +7 -6
  179. package/src/types.ts +2 -1
  180. package/dist/adapter/device-helpers/device-features.d.ts +0 -6
  181. package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
  182. package/dist/adapter/device-helpers/device-features.js +0 -65
  183. package/dist/adapter/device-helpers/device-limits.d.ts +0 -50
  184. package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
  185. package/dist/adapter/device-helpers/device-limits.js +0 -92
  186. package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
  187. package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
  188. package/dist/adapter/device-helpers/get-device-info.js +0 -87
  189. package/dist/context/context/context-data.d.ts.map +0 -1
  190. package/dist/context/context/context-data.js +0 -33
  191. package/src/context/context/context-data.ts +0 -44
  192. /package/dist/context/{context → helpers}/create-browser-context.d.ts +0 -0
@@ -1,14 +1,12 @@
1
- // luma.gl, MIT license
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
2
3
  // Copyright (c) vis.gl contributors
3
4
 
4
- import {Resource, assert, uid, stubRemovedMethods} from '@luma.gl/core';
5
5
  import type {Device, ResourceProps} from '@luma.gl/core';
6
+ import {Resource, uid, stubRemovedMethods} from '@luma.gl/core';
6
7
  import {GL} from '@luma.gl/constants';
7
8
  import {WebGLDevice} from '../webgl-device';
8
9
 
9
- // Requires full GL enum to be bundled... Make these bindings dependent on dynamic import (debug)?
10
- import {getKeyValue} from './constants-to-keys';
11
-
12
10
  const ERR_RESOURCE_METHOD_UNDEFINED = 'Resource subclass must define virtual methods';
13
11
 
14
12
  /**
@@ -27,13 +25,13 @@ export abstract class WebGLResource<Props extends ResourceProps> extends Resourc
27
25
  constructor(device: Device, props: Props, defaultProps: Required<Props>) {
28
26
  super(device, props, defaultProps);
29
27
 
30
- this.device = WebGLDevice.attach(device);
28
+ this.device = device as WebGLDevice;
31
29
  const gl = this.device.gl;
32
30
 
33
- // extends
31
+ // extends
34
32
  const {id} = props || {};
35
33
  this.gl = gl;
36
- this.gl2 = gl ;
34
+ this.gl2 = gl;
37
35
  this.id = id || uid(this.constructor.name);
38
36
 
39
37
  // Set the handle
@@ -81,7 +79,7 @@ export abstract class WebGLResource<Props extends ResourceProps> extends Resourc
81
79
  // @ts-expect-error
82
80
  if (children && deleteChildren) {
83
81
  // @ts-expect-error
84
- children.filter(Boolean).forEach((child) => child.destroy());
82
+ children.filter(Boolean).forEach(child => child.destroy());
85
83
  }
86
84
 
87
85
  return this;
@@ -114,122 +112,6 @@ export abstract class WebGLResource<Props extends ResourceProps> extends Resourc
114
112
  this.bind(null);
115
113
  }
116
114
 
117
- /**
118
- * Query a Resource parameter
119
- *
120
- * @param name
121
- * @return param
122
- */
123
- getParameter(pname: number, props: any = {}): any {
124
- pname = getKeyValue(this.gl, pname);
125
- assert(pname);
126
-
127
- // @ts-expect-error
128
- const parameters = this.constructor.PARAMETERS || {};
129
-
130
- // Use parameter definitions to handle unsupported parameters
131
- const parameter = parameters[pname];
132
- if (parameter) {
133
- // Check if we can query for this parameter
134
- const parameterAvailable =
135
- (!('extension' in parameter) || this.gl.getExtension(parameter.extension));
136
-
137
- if (!parameterAvailable) {
138
- return parameter.webgl2;
139
- }
140
- }
141
-
142
- // If unknown parameter - Could be a valid parameter not covered by PARAMS
143
- // Attempt to query for it and let WebGL report errors
144
- return this._getParameter(pname, props);
145
- }
146
-
147
- // Many resources support a getParameter call -
148
- // getParameters will get all parameters - slow but useful for debugging
149
- // eslint-disable-next-line complexity
150
- getParameters(options: {parameters?: any, keys?: any} = {}) {
151
- const {parameters, keys} = options;
152
-
153
- // Get parameter definitions for this Resource
154
- // @ts-expect-error
155
- const PARAMETERS = this.constructor.PARAMETERS || {};
156
-
157
- const values: Record<string, any> = {};
158
-
159
- // Query all parameters if no list provided
160
- const parameterKeys = parameters || Object.keys(PARAMETERS);
161
-
162
- // WEBGL limits
163
- for (const pname of parameterKeys) {
164
- const parameter = PARAMETERS[pname];
165
-
166
- // Check if this parameter is available on this platform
167
- const parameterAvailable =
168
- parameter &&
169
- (!('extension' in parameter) || this.gl.getExtension(parameter.extension));
170
-
171
- if (parameterAvailable) {
172
- const key = keys ? this.device.getGLKey(pname) : pname;
173
- values[key] = this.getParameter(pname, options);
174
- if (keys && parameter.type === 'GLenum') {
175
- values[key] = this.device.getGLKey(values[key]);
176
- }
177
- }
178
- }
179
-
180
- return values;
181
- }
182
-
183
- /**
184
- * Update a Resource setting
185
- *
186
- * @todo - cache parameter to avoid issuing WebGL calls?
187
- *
188
- * @param pname - parameter (GL constant, value or key)
189
- * @param value {GLint|GLfloat|GLenum}
190
- * @return returns self to enable chaining
191
- */
192
- setParameter(pname: GL | string, value: any): this {
193
- pname = getKeyValue(this.gl, pname);
194
- assert(pname);
195
-
196
- // @ts-expect-error
197
- const parameters = this.constructor.PARAMETERS || {};
198
-
199
- const parameter = parameters[pname];
200
- if (parameter) {
201
- // Check if this parameter is available on this platform
202
- const parameterAvailable =
203
- (!('extension' in parameter) || this.gl.getExtension(parameter.extension));
204
-
205
- if (!parameterAvailable) {
206
- throw new Error('Parameter not available on this platform');
207
- }
208
-
209
- // Handle string keys
210
- if (parameter.type === 'GLenum') {
211
- // @ts-expect-error
212
- value = getKeyValue(value);
213
- }
214
- }
215
-
216
- // If unknown parameter - Could be a valid parameter not covered by PARAMS
217
- // attempt to set it and let WebGL report errors
218
- this._setParameter(pname, value);
219
- return this;
220
- }
221
-
222
- /*
223
- * Batch update resource parameters
224
- * Assumes the subclass supports a setParameter call
225
- */
226
- setParameters(parameters: Record<GL, any>) {
227
- for (const pname in parameters) {
228
- this.setParameter(pname, parameters[pname]);
229
- }
230
- return this;
231
- }
232
-
233
115
  // Install stubs for removed methods
234
116
  stubRemovedMethods(className: string, version: string, methodNames: string[]) {
235
117
  return stubRemovedMethods(this, className, version, methodNames);
@@ -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 type {BufferProps} from '@luma.gl/core';
@@ -166,9 +167,9 @@ export class WEBGLBuffer extends Buffer {
166
167
  * static STORAGE = 0x0080;
167
168
  * static INDIRECT = 0x0100;
168
169
  * static QUERY_RESOLVE = 0x0200;
169
- *
170
+ *
170
171
  * @returns WebGL buffer targe
171
- *
172
+ *
172
173
  * Buffer bind points in WebGL2
173
174
  * gl.COPY_READ_BUFFER: Buffer for copying from one buffer object to another.
174
175
  * gl.COPY_WRITE_BUFFER: Buffer for copying from one buffer object to another.
@@ -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 type {
@@ -156,7 +157,7 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
156
157
  const webglBuffer = destination as WEBGLBuffer;
157
158
  const sourceWidth = width || framebuffer.width;
158
159
  const sourceHeight = height || framebuffer.height;
159
- const sourceParams = getWebGLTextureParameters(framebuffer.texture.format);
160
+ const sourceParams = getWebGLTextureParameters(framebuffer.texture.props.format);
160
161
  const sourceFormat = sourceParams.dataFormat;
161
162
  const sourceType = sourceParams.type;
162
163
 
@@ -225,19 +226,18 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
225
226
  origin = [0, 0],
226
227
 
227
228
  /** Texture to copy to/from. */
228
- destination,
229
+ destination
229
230
  /** Mip-map level of the texture to copy to/from. (Default 0) */
230
231
  // destinationMipLevel = options.mipLevel,
231
232
  /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
232
233
  // destinationOrigin = [0, 0],
233
234
  /** Defines which aspects of the texture to copy to/from. */
234
235
  // destinationAspect = options.aspect,
235
-
236
236
  } = options;
237
237
 
238
238
  let {
239
239
  width = options.destination.width,
240
- height = options.destination.width,
240
+ height = options.destination.width
241
241
  // depthOrArrayLayers = 0
242
242
  } = options;
243
243
 
@@ -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 {CommandEncoder, CommandEncoderProps} from '@luma.gl/core';
@@ -6,7 +7,9 @@ import type {
6
7
  CopyBufferToBufferOptions,
7
8
  CopyBufferToTextureOptions,
8
9
  CopyTextureToBufferOptions,
9
- CopyTextureToTextureOptions
10
+ CopyTextureToTextureOptions,
11
+ QuerySet,
12
+ Buffer
10
13
  } from '@luma.gl/core';
11
14
 
12
15
  import {WEBGLCommandBuffer} from './webgl-command-buffer';
@@ -54,13 +57,13 @@ export class WEBGLCommandEncoder extends CommandEncoder {
54
57
 
55
58
  override insertDebugMarker(markerLabel: string): void {}
56
59
 
57
- // writeTimestamp(querySet: Query, queryIndex: number): void {}
58
-
59
- // resolveQuerySet(options: {
60
- // querySet: GPUQuerySet,
61
- // firstQuery: number,
62
- // queryCount: number,
63
- // destination: Buffer,
64
- // destinationOffset?: number;
65
- // }): void;
60
+ override resolveQuerySet(
61
+ querySet: QuerySet,
62
+ destination: Buffer,
63
+ options?: {
64
+ firstQuery?: number;
65
+ queryCount?: number;
66
+ destinationOffset?: number;
67
+ }
68
+ ): void {}
66
69
  }
@@ -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
  /*
@@ -52,12 +53,12 @@ export class WEBGLExternalTexture extends WEBGLTexture {
52
53
  }
53
54
 
54
55
  // eslint-disable-next-line max-statements
55
- constructor(device: Device | WebGL2RenderingContext, props: TextureProps) {
56
- super(WebGLDevice.attach(device), {id: uid('texture'), ...props});
56
+ constructor(device: Device , props: TextureProps) {
57
+ super(device as WebGLDevice, {id: uid('texture'), ...props});
57
58
 
58
59
  this.glTarget = getWebGLTextureTarget(props);
59
60
 
60
- this.device = WebGLDevice.attach(device);
61
+ this.device = device as WebGLDevice;
61
62
  this.gl = this.device.gl;
62
63
  this.gl2 = this.device.gl2;
63
64
  this.handle = this.props.handle || this.gl.createTexture();
@@ -91,4 +92,4 @@ export class WEBGLExternalTexture extends WEBGLTexture {
91
92
  }
92
93
 
93
94
 
94
- */
95
+ */
@@ -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 type {FramebufferProps, TextureFormat} from '@luma.gl/core';
@@ -6,11 +7,13 @@ import {Framebuffer, Texture, assert} from '@luma.gl/core';
6
7
  import {GL} from '@luma.gl/constants';
7
8
  import {WebGLDevice} from '../webgl-device';
8
9
  import {WEBGLTexture} from './webgl-texture';
9
- import {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';
10
+ import {WEBGLTextureView} from './webgl-texture-view';
10
11
  import {getDepthStencilAttachmentWebGL} from '../converters/texture-formats';
11
12
 
12
- export type TextureAttachment = [Texture, number?, number?];
13
- export type Attachment = WEBGLTexture | WEBGLRenderbuffer | TextureAttachment;
13
+ // TODO - for now we don't see a usage for renderbuffers in WebGL 2.
14
+ // import {WEBGLRenderbuffer} from '../objects/webgl-renderbuffer';
15
+
16
+ export type Attachment = WEBGLTextureView | WEBGLTexture; // | WEBGLRenderbuffer;
14
17
 
15
18
  /** luma.gl Framebuffer, WebGL implementation */
16
19
  export class WEBGLFramebuffer extends Framebuffer {
@@ -45,26 +48,30 @@ export class WEBGLFramebuffer extends Framebuffer {
45
48
 
46
49
  // Walk the attachments
47
50
  for (let i = 0; i < this.colorAttachments.length; ++i) {
48
- const attachment = this.colorAttachments[i];
51
+ const attachment = this.colorAttachments[i] as WEBGLTextureView;
49
52
  const attachmentPoint = GL.COLOR_ATTACHMENT0 + i;
50
53
  if (attachment) {
51
- this._attachOne(attachmentPoint, attachment as WEBGLTexture);
54
+ this._attachOne(attachmentPoint, attachment);
52
55
  }
53
56
  }
54
57
 
55
58
  if (this.depthStencilAttachment) {
56
59
  this._attachOne(
57
- getDepthStencilAttachmentWebGL(this.depthStencilAttachment.format),
58
- this.depthStencilAttachment as WEBGLTexture
60
+ getDepthStencilAttachmentWebGL(this.depthStencilAttachment.props.format),
61
+ this.depthStencilAttachment as WEBGLTextureView
59
62
  );
60
63
  }
61
64
 
62
- this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
63
- }
65
+ /** Check the status */
66
+ // @ts-expect-error
67
+ if (props.check !== false) {
68
+ const status = this.gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL;
69
+ if (status !== GL.FRAMEBUFFER_COMPLETE) {
70
+ throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
71
+ }
72
+ }
64
73
 
65
- // @ts-expect-error
66
- if (props.check !== false) {
67
- this._checkStatus();
74
+ this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
68
75
  }
69
76
  }
70
77
 
@@ -79,32 +86,20 @@ export class WEBGLFramebuffer extends Framebuffer {
79
86
 
80
87
  // PRIVATE
81
88
 
82
- /** Check the status */
83
- protected _checkStatus(): void {
84
- const {gl} = this;
85
- // TODO - should we really rely on this trick?
86
- const prevHandle = gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle) as unknown as WebGLFramebuffer;
87
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER);
88
- gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
89
- if (status !== gl.FRAMEBUFFER_COMPLETE) {
90
- throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
91
- }
92
- }
93
-
94
89
  /** In WebGL we must use renderbuffers for depth/stencil attachments (unless we have extensions) */
95
90
  protected override createDepthStencilTexture(format: TextureFormat): Texture {
96
- return new WEBGLRenderbuffer(this.device, {
97
- id: `${this.id}-depth-stencil`, // TODO misleading if not depth and stencil?
91
+ // return new WEBGLRenderbuffer(this.device, {
92
+ return new WEBGLTexture(this.device, {
93
+ id: `${this.id}-depth-stencil`,
98
94
  format,
99
- // dataFormat: GL.DEPTH_STENCIL,
100
- // type: GL.UNSIGNED_INT_24_8,
101
95
  width: this.width,
102
- height: this.height
103
- }) as unknown as WEBGLTexture;
96
+ height: this.height,
97
+ mipmaps: false
98
+ });
104
99
  }
105
100
 
106
- /**
107
- * Attachment resize is expected to be a noop if size is same
101
+ /**
102
+ * Attachment resize is expected to be a noop if size is same
108
103
  */
109
104
  protected override resizeAttachments(width: number, height: number): this {
110
105
  // for default framebuffer, just update the stored size
@@ -125,41 +120,51 @@ export class WEBGLFramebuffer extends Framebuffer {
125
120
  // TODO Not clear that this is better than default destroy/create implementation
126
121
 
127
122
  for (const colorAttachment of this.colorAttachments) {
128
- (colorAttachment as WEBGLTexture).resize({width, height});
123
+ (colorAttachment.texture as WEBGLTexture).resize({width, height});
129
124
  }
130
125
  if (this.depthStencilAttachment) {
131
- (this.depthStencilAttachment as WEBGLTexture).resize({width, height});
126
+ (this.depthStencilAttachment.texture as WEBGLTexture).resize({width, height});
132
127
  }
133
128
  return this;
134
129
  }
135
130
 
136
131
  /** Attach one attachment */
137
- protected _attachOne(
138
- attachmentPoint: GL,
139
- attachment: Attachment
140
- ): WEBGLTexture | WEBGLRenderbuffer {
141
- if (attachment instanceof WEBGLRenderbuffer) {
142
- this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
143
- return attachment;
144
- } else if (Array.isArray(attachment)) {
132
+ protected _attachOne(attachmentPoint: GL, attachment: Attachment): WEBGLTexture {
133
+ // if (attachment instanceof WEBGLRenderbuffer) {
134
+ // this._attachWEBGLRenderbuffer(attachmentPoint, attachment);
135
+ // return attachment;
136
+ // }
137
+ if (Array.isArray(attachment)) {
145
138
  const [texture, layer = 0, level = 0] = attachment;
146
139
  this._attachTexture(attachmentPoint, texture as unknown as WEBGLTexture, layer, level);
147
140
  return texture as unknown as WEBGLTexture;
148
- } else if (attachment instanceof WEBGLTexture) {
141
+ }
142
+ if (attachment instanceof WEBGLTexture) {
149
143
  this._attachTexture(attachmentPoint, attachment, 0, 0);
150
144
  return attachment;
151
145
  }
146
+ if (attachment instanceof WEBGLTextureView) {
147
+ const textureView = attachment;
148
+ this._attachTexture(
149
+ attachmentPoint,
150
+ textureView.texture,
151
+ textureView.props.baseMipLevel,
152
+ textureView.props.baseArrayLayer
153
+ );
154
+ return attachment.texture;
155
+ }
152
156
  throw new Error('attach');
153
157
  }
154
158
 
155
- protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {
156
- this.gl.framebufferRenderbuffer(
157
- GL.FRAMEBUFFER,
158
- attachment,
159
- GL.RENDERBUFFER,
160
- renderbuffer.handle
161
- );
162
- }
159
+ // TODO - we do not seem to need render buffers in WebGL 2
160
+ // protected _attachWEBGLRenderbuffer(attachment: GL, renderbuffer: WEBGLRenderbuffer): void {
161
+ // this.gl.framebufferRenderbuffer(
162
+ // GL.FRAMEBUFFER,
163
+ // attachment,
164
+ // GL.RENDERBUFFER,
165
+ // renderbuffer.handle
166
+ // );
167
+ // }
163
168
 
164
169
  /**
165
170
  * @param attachment
@@ -174,6 +179,7 @@ export class WEBGLFramebuffer extends Framebuffer {
174
179
  level: number
175
180
  ): void {
176
181
  const {gl} = this.device;
182
+
177
183
  gl.bindTexture(texture.target, texture.handle);
178
184
 
179
185
  switch (texture.target) {
@@ -206,7 +212,9 @@ export class WEBGLFramebuffer extends Framebuffer {
206
212
  function mapIndexToCubeMapFace(layer: number | GL): GL {
207
213
  // TEXTURE_CUBE_MAP_POSITIVE_X is a big value (0x8515)
208
214
  // if smaller assume layer is index, otherwise assume it is already a cube map face constant
209
- return layer < (GL.TEXTURE_CUBE_MAP_POSITIVE_X as number) ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X : layer;
215
+ return layer < (GL.TEXTURE_CUBE_MAP_POSITIVE_X as number)
216
+ ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X
217
+ : layer;
210
218
  }
211
219
 
212
220
  // Helper METHODS
@@ -0,0 +1,171 @@
1
+ // WebGL2 Query (also handles disjoint timer extensions)
2
+ import {QuerySet, QuerySetProps} from '@luma.gl/core';
3
+ import {GL} from '@luma.gl/constants';
4
+ import {WebGLDevice} from '../webgl-device';
5
+
6
+ /**
7
+ * Asynchronous queries for different kinds of information
8
+ */
9
+ export class WEBGLQuerySet extends QuerySet {
10
+ device: WebGLDevice;
11
+ handle: WebGLQuery;
12
+
13
+ target: number | null = null;
14
+ _queryPending = false;
15
+ _pollingPromise: Promise<any> | null = null;
16
+
17
+ override get [Symbol.toStringTag](): string {
18
+ return 'Query';
19
+ }
20
+
21
+ // Create a query class
22
+ constructor(device: WebGLDevice, props: QuerySetProps) {
23
+ super(device, props);
24
+ this.device = device;
25
+
26
+ if (props.count > 1) {
27
+ throw new Error('WebGL QuerySet can only have one value');
28
+ }
29
+
30
+ this.handle = this.device.gl.createQuery();
31
+ Object.seal(this);
32
+ }
33
+
34
+ override destroy() {
35
+ this.device.gl.deleteQuery(this.handle);
36
+ }
37
+
38
+ // FOR RENDER PASS AND COMMAND ENCODER
39
+
40
+ /**
41
+ * Shortcut for timer query (dependent on extension in both WebGL1 and 2)
42
+ * Measures GPU time delta between this call and a matching `end` call in the
43
+ * GPU instruction stream.
44
+ */
45
+ beginTimestampQuery(): void {
46
+ return this._begin(GL.TIME_ELAPSED_EXT);
47
+ }
48
+
49
+ endTimestampQuery(): void {
50
+ this._end();
51
+ }
52
+
53
+ // Shortcut for occlusion queries
54
+ beginOcclusionQuery(options?: {conservative?: boolean}): void {
55
+ return this._begin(
56
+ options?.conservative ? GL.ANY_SAMPLES_PASSED_CONSERVATIVE : GL.ANY_SAMPLES_PASSED
57
+ );
58
+ }
59
+
60
+ endOcclusionQuery() {
61
+ this._end();
62
+ }
63
+
64
+ // Shortcut for transformFeedbackQuery
65
+ beginTransformFeedbackQuery(): void {
66
+ return this._begin(GL.TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
67
+ }
68
+
69
+ endTransformFeedbackQuery(): void {
70
+ this._end();
71
+ }
72
+
73
+ async resolveQuery(): Promise<bigint[]> {
74
+ const value = await this.pollQuery();
75
+ return [value];
76
+ }
77
+
78
+ // PRIVATE METHODS
79
+
80
+ /**
81
+ * Due to OpenGL API limitations, after calling `begin()` on one Query
82
+ * instance, `end()` must be called on that same instance before
83
+ * calling `begin()` on another query. While there can be multiple
84
+ * outstanding queries representing disjoint `begin()`/`end()` intervals.
85
+ * It is not possible to interleave or overlap `begin` and `end` calls.
86
+ */
87
+ protected _begin(target: number): void {
88
+ // Don't start a new query if one is already active.
89
+ if (this._queryPending) {
90
+ return;
91
+ }
92
+
93
+ this.target = target;
94
+ this.device.gl.beginQuery(this.target, this.handle);
95
+
96
+ return;
97
+ }
98
+
99
+ // ends the current query
100
+ protected _end(): void {
101
+ // Can't end a new query if the last one hasn't been resolved.
102
+ if (this._queryPending) {
103
+ return;
104
+ }
105
+
106
+ if (this.target) {
107
+ this.device.gl.endQuery(this.target);
108
+ this.target = null;
109
+ this._queryPending = true;
110
+ }
111
+ return;
112
+ }
113
+
114
+ // Returns true if the query result is available
115
+ isResultAvailable(): boolean {
116
+ if (!this._queryPending) {
117
+ return false;
118
+ }
119
+
120
+ const resultAvailable = this.device.gl.getQueryParameter(
121
+ this.handle,
122
+ GL.QUERY_RESULT_AVAILABLE
123
+ );
124
+ if (resultAvailable) {
125
+ this._queryPending = false;
126
+ }
127
+ return resultAvailable;
128
+ }
129
+
130
+ // Timing query is disjoint, i.e. results are invalid
131
+ isTimerDisjoint(): boolean {
132
+ return this.device.gl.getParameter(GL.GPU_DISJOINT_EXT);
133
+ }
134
+
135
+ // Returns query result.
136
+ getResult(): any {
137
+ return this.device.gl.getQueryParameter(this.handle, GL.QUERY_RESULT);
138
+ }
139
+
140
+ // Returns the query result, converted to milliseconds to match JavaScript conventions.
141
+ getTimerMilliseconds() {
142
+ return this.getResult() / 1e6;
143
+ }
144
+
145
+ // Polls the query
146
+ pollQuery(limit: number = Number.POSITIVE_INFINITY): Promise<any> {
147
+ if (this._pollingPromise) {
148
+ return this._pollingPromise;
149
+ }
150
+
151
+ let counter = 0;
152
+
153
+ this._pollingPromise = new Promise((resolve, reject) => {
154
+ const poll = () => {
155
+ if (this.isResultAvailable()) {
156
+ resolve(this.getResult());
157
+ this._pollingPromise = null;
158
+ } else if (counter++ > limit) {
159
+ reject('Timed out');
160
+ this._pollingPromise = null;
161
+ } else {
162
+ requestAnimationFrame(poll);
163
+ }
164
+ };
165
+
166
+ requestAnimationFrame(poll);
167
+ });
168
+
169
+ return this._pollingPromise;
170
+ }
171
+ }