@luma.gl/webgl 9.0.0 → 9.0.4

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 (28) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +5 -5
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +8 -3
  4. package/dist/adapter/device-helpers/webgl-device-features.d.ts +1 -0
  5. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -1
  6. package/dist/adapter/device-helpers/webgl-device-features.js +10 -10
  7. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  8. package/dist/adapter/resources/webgl-command-buffer.js +29 -56
  9. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  10. package/dist/adapter/resources/webgl-framebuffer.js +3 -2
  11. package/dist/adapter/resources/webgl-render-pipeline.d.ts +3 -1
  12. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgl-render-pipeline.js +4 -2
  14. package/dist/adapter/resources/webgl-vertex-array.d.ts +0 -1
  15. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  16. package/dist/adapter/resources/webgl-vertex-array.js +5 -15
  17. package/dist/dist.dev.js +105 -80
  18. package/dist/dist.min.js +2 -2
  19. package/dist/index.cjs +51 -47
  20. package/dist/index.cjs.map +2 -2
  21. package/dist.min.js +19 -0
  22. package/package.json +4 -4
  23. package/src/adapter/converters/device-parameters.ts +37 -28
  24. package/src/adapter/device-helpers/webgl-device-features.ts +11 -10
  25. package/src/adapter/resources/webgl-command-buffer.ts +54 -67
  26. package/src/adapter/resources/webgl-framebuffer.ts +6 -2
  27. package/src/adapter/resources/webgl-render-pipeline.ts +6 -4
  28. package/src/adapter/resources/webgl-vertex-array.ts +9 -18
@@ -153,6 +153,7 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
153
153
 
154
154
  // Asynchronous read (PIXEL_PACK_BUFFER) is WebGL2 only feature
155
155
  const {framebuffer, destroyFramebuffer} = getFramebuffer(source);
156
+ let prevHandle: WebGLFramebuffer | null | undefined;
156
157
  try {
157
158
  const webglBuffer = destination as WEBGLBuffer;
158
159
  const sourceWidth = width || framebuffer.width;
@@ -170,7 +171,8 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
170
171
  // }
171
172
 
172
173
  device.gl.bindBuffer(GL.PIXEL_PACK_BUFFER, webglBuffer.handle);
173
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
174
+ // @ts-expect-error native bindFramebuffer is overridden by our state tracker
175
+ prevHandle = device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
174
176
 
175
177
  device.gl.readPixels(
176
178
  origin[0],
@@ -183,7 +185,10 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
183
185
  );
184
186
  } finally {
185
187
  device.gl.bindBuffer(GL.PIXEL_PACK_BUFFER, null);
186
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
188
+ // prevHandle may be unassigned if the try block failed before binding
189
+ if (prevHandle !== undefined) {
190
+ device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
191
+ }
187
192
 
188
193
  if (destroyFramebuffer) {
189
194
  framebuffer.destroy();
@@ -218,13 +223,16 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
218
223
  const {
219
224
  /** Texture to copy to/from. */
220
225
  source,
221
- /** Mip-map level of the texture to copy to/from. (Default 0) */
222
- // mipLevel = 0,
226
+ /** Mip-map level of the texture to copy to (Default 0) */
227
+ destinationMipLevel = 0,
223
228
  /** Defines which aspects of the texture to copy to/from. */
224
229
  // aspect = 'all',
225
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
230
+ /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */
226
231
  origin = [0, 0],
227
232
 
233
+ /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
234
+ destinationOrigin = [0, 0],
235
+
228
236
  /** Texture to copy to/from. */
229
237
  destination
230
238
  /** Mip-map level of the texture to copy to/from. (Default 0) */
@@ -237,93 +245,72 @@ function _copyTextureToTexture(device: WebGLDevice, options: CopyTextureToTextur
237
245
 
238
246
  let {
239
247
  width = options.destination.width,
240
- height = options.destination.width
248
+ height = options.destination.height
241
249
  // depthOrArrayLayers = 0
242
250
  } = options;
243
251
 
244
- const destinationMipmaplevel = 0;
245
- const destinationInternalFormat = GL.RGBA;
246
-
247
252
  const {framebuffer, destroyFramebuffer} = getFramebuffer(source);
248
253
  const [sourceX, sourceY] = origin;
254
+ const [destinationX, destinationY, destinationZ] = destinationOrigin;
249
255
 
250
- const isSubCopy = false;
251
- // typeof destinationX !== 'undefined' ||
252
- // typeof destinationY !== 'undefined' ||
253
- // typeof destinationZ !== 'undefined';
254
-
255
- // destinationX = destinationX || 0;
256
- // destinationY = destinationY || 0;
257
- // destinationZ = destinationZ || 0;
258
- device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
256
+ // @ts-expect-error native bindFramebuffer is overridden by our state tracker
257
+ const prevHandle: WebGLFramebuffer | null = device.gl.bindFramebuffer(
258
+ GL.FRAMEBUFFER,
259
+ framebuffer.handle
260
+ );
259
261
  // TODO - support gl.readBuffer (WebGL2 only)
260
262
  // const prevBuffer = gl.readBuffer(attachment);
261
263
 
262
- let texture = null;
264
+ let texture: WEBGLTexture = null;
263
265
  let textureTarget: GL;
264
266
  if (destination instanceof WEBGLTexture) {
265
267
  texture = destination;
266
268
  width = Number.isFinite(width) ? width : texture.width;
267
269
  height = Number.isFinite(height) ? height : texture.height;
268
270
  texture.bind(0);
269
- textureTarget = texture.destination;
271
+ textureTarget = texture.target;
270
272
  } else {
271
- throw new Error('whoops');
272
- // textureTarget = destination;
273
+ throw new Error('invalid destination');
273
274
  }
274
275
 
275
- if (!isSubCopy) {
276
- device.gl.copyTexImage2D(
277
- textureTarget,
278
- destinationMipmaplevel,
279
- destinationInternalFormat,
280
- sourceX,
281
- sourceY,
282
- width,
283
- height,
284
- 0 /* border must be 0 */
285
- );
286
- } else {
287
- // switch (textureTarget) {
288
- // case GL.TEXTURE_2D:
289
- // case GL.TEXTURE_CUBE_MAP:
290
- // device.gl.copyTexSubImage2D(
291
- // textureTarget,
292
- // destinationMipmaplevel,
293
- // destinationX,
294
- // destinationY,
295
- // sourceX,
296
- // sourceY,
297
- // width,
298
- // height
299
- // );
300
- // break;
301
- // case GL.TEXTURE_2D_ARRAY:
302
- // case GL.TEXTURE_3D:
303
- // device.gl.copyTexSubImage3D(
304
- // textureTarget,
305
- // destinationMipmaplevel,
306
- // destinationX,
307
- // destinationY,
308
- // destinationZ,
309
- // sourceX,
310
- // sourceY,
311
- // width,
312
- // height
313
- // );
314
- // break;
315
- // default:
316
- // }
276
+ switch (textureTarget) {
277
+ case GL.TEXTURE_2D:
278
+ case GL.TEXTURE_CUBE_MAP:
279
+ device.gl.copyTexSubImage2D(
280
+ textureTarget,
281
+ destinationMipLevel,
282
+ destinationX,
283
+ destinationY,
284
+ sourceX,
285
+ sourceY,
286
+ width,
287
+ height
288
+ );
289
+ break;
290
+ case GL.TEXTURE_2D_ARRAY:
291
+ case GL.TEXTURE_3D:
292
+ device.gl.copyTexSubImage3D(
293
+ textureTarget,
294
+ destinationMipLevel,
295
+ destinationX,
296
+ destinationY,
297
+ destinationZ,
298
+ sourceX,
299
+ sourceY,
300
+ width,
301
+ height
302
+ );
303
+ break;
304
+ default:
317
305
  }
306
+
318
307
  if (texture) {
319
308
  texture.unbind();
320
309
  }
321
- // ts-expect-error
322
- // device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle || null);
310
+ device.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
323
311
  if (destroyFramebuffer) {
324
312
  framebuffer.destroy();
325
313
  }
326
- return texture;
327
314
  }
328
315
 
329
316
  // Returns number of components in a specific readPixels WebGL format
@@ -44,7 +44,11 @@ export class WEBGLFramebuffer extends Framebuffer {
44
44
  this.autoCreateAttachmentTextures();
45
45
 
46
46
  /** Attach from a map of attachments */
47
- this.gl.bindFramebuffer(GL.FRAMEBUFFER, this.handle);
47
+ // @ts-expect-error native bindFramebuffer is overridden by our state tracker
48
+ const prevHandle: WebGLFramebuffer | null = this.gl.bindFramebuffer(
49
+ GL.FRAMEBUFFER,
50
+ this.handle
51
+ );
48
52
 
49
53
  // Walk the attachments
50
54
  for (let i = 0; i < this.colorAttachments.length; ++i) {
@@ -71,7 +75,7 @@ export class WEBGLFramebuffer extends Framebuffer {
71
75
  }
72
76
  }
73
77
 
74
- this.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
78
+ this.gl.bindFramebuffer(GL.FRAMEBUFFER, prevHandle);
75
79
  }
76
80
  }
77
81
 
@@ -103,7 +103,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
103
103
  * Bindings include: textures, samplers and uniform buffers
104
104
  * @todo needed for portable model
105
105
  */
106
- setBindings(bindings: Record<string, Binding>): void {
106
+ setBindings(bindings: Record<string, Binding>, options?: {disableWarnings?: boolean}): void {
107
107
  // if (log.priority >= 2) {
108
108
  // checkUniformValues(uniforms, this.id, this._uniformSetters);
109
109
  // }
@@ -121,9 +121,11 @@ export class WEBGLRenderPipeline extends RenderPipeline {
121
121
  const validBindings = this.shaderLayout.bindings
122
122
  .map(binding => `"${binding.name}"`)
123
123
  .join(', ');
124
- log.warn(
125
- `Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
126
- )();
124
+ if (options?.disableWarnings) {
125
+ log.warn(
126
+ `Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
127
+ )();
128
+ }
127
129
  continue; // eslint-disable-line no-continue
128
130
  }
129
131
  if (!value) {
@@ -57,8 +57,8 @@ export class WEBGLVertexArray extends VertexArray {
57
57
  /**
58
58
  // Set (bind/unbind) an elements buffer, for indexed rendering.
59
59
  // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER or null. Constants not supported
60
- *
61
- * @param elementBuffer
60
+ *
61
+ * @param elementBuffer
62
62
  */
63
63
  setIndexBuffer(indexBuffer: Buffer | null): void {
64
64
  const buffer = indexBuffer as WEBGLBuffer;
@@ -68,12 +68,12 @@ export class WEBGLVertexArray extends VertexArray {
68
68
  }
69
69
  // In WebGL The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject
70
70
  this.device.gl.bindVertexArray(this.handle);
71
- // TODO - this initial binding does not seem to take effect? see bindBeforeRender()
72
71
  this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, buffer ? buffer.handle : null);
73
- // log.log(1, 'VertexArray.setIndexBuffer', indexBuffer)();
74
- // log.log(1, `Binding vertex array ${this.id}`, buffer?.id)();
75
72
 
76
73
  this.indexBuffer = buffer;
74
+
75
+ // Unbind to prevent unintended changes to the VAO.
76
+ this.device.gl.bindVertexArray(null);
77
77
  }
78
78
 
79
79
  /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
@@ -104,6 +104,9 @@ export class WEBGLVertexArray extends VertexArray {
104
104
  this.device.gl.vertexAttribDivisor(location, divisor || 0);
105
105
 
106
106
  this.attributes[location] = buffer;
107
+
108
+ // Unbind to prevent unintended changes to the VAO.
109
+ this.device.gl.bindVertexArray(null);
107
110
  }
108
111
 
109
112
  /** Set a location in vertex attributes array to a constant value, disables the location */
@@ -112,26 +115,14 @@ export class WEBGLVertexArray extends VertexArray {
112
115
  this.attributes[location] = value;
113
116
  }
114
117
 
115
- init = false;
116
-
117
118
  override bindBeforeRender(): void {
118
119
  this.device.gl.bindVertexArray(this.handle);
119
- // TODO - the initial bind does not seem to take effect.
120
- if (!this.init) {
121
- // log.log(1, `Binding vertex array ${this.id}`, this.indexBuffer?.id)();
122
- const webglBuffer = this.indexBuffer as WEBGLBuffer;
123
- this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, webglBuffer?.handle || null);
124
- this.init = true;
125
- }
126
120
  this._applyConstantAttributes();
127
121
  }
128
122
 
129
123
  override unbindAfterRender(): void {
130
- // log.log(1, `Unbinding vertex array ${this.id}`)();
131
- // TODO technically this is not necessary, but we might be interfacing
132
- // with code that does not use vertex array objects
124
+ // Unbind to prevent unintended changes to the VAO.
133
125
  this.device.gl.bindVertexArray(null);
134
- // this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
135
126
  }
136
127
 
137
128
  // Internal methods