@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
package/dist/index.cjs CHANGED
@@ -1348,12 +1348,8 @@ var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
1348
1348
  getWebGLExtension(gl, "EXT_color_buffer_float", extensions);
1349
1349
  }
1350
1350
  *[Symbol.iterator]() {
1351
- for (const feature of Object.keys(WEBGL_FEATURES)) {
1352
- if (this.has(feature)) {
1353
- yield feature;
1354
- }
1355
- }
1356
- for (const feature of Object.keys(TEXTURE_FEATURES)) {
1351
+ const features = this.getFeatures();
1352
+ for (const feature of features) {
1357
1353
  if (this.has(feature)) {
1358
1354
  yield feature;
1359
1355
  }
@@ -1377,10 +1373,15 @@ var WebGLDeviceFeatures = class extends import_core3.DeviceFeatures {
1377
1373
  }
1378
1374
  // FOR DEVICE
1379
1375
  initializeFeatures() {
1380
- for (const feature of this) {
1376
+ const features = this.getFeatures().filter((feature) => feature !== "polygon-mode-webgl");
1377
+ for (const feature of features) {
1378
+ this.has(feature);
1381
1379
  }
1382
1380
  }
1383
1381
  // IMPLEMENTATION
1382
+ getFeatures() {
1383
+ return [...Object.keys(WEBGL_FEATURES), ...Object.keys(TEXTURE_FEATURES)];
1384
+ }
1384
1385
  /** Extract all WebGL features */
1385
1386
  getWebGLFeature(feature) {
1386
1387
  const featureInfo = WEBGL_FEATURES[feature];
@@ -1618,9 +1619,9 @@ function setDeviceParameters(device, parameters) {
1618
1619
  const extensions = webglDevice.getExtension("WEBGL_polygon_mode");
1619
1620
  const ext = extensions.WEBGL_polygon_mode;
1620
1621
  if (parameters.polygonMode) {
1621
- const mode = map("polygonMode", parameters.provokingVertex, {
1622
+ const mode = map("polygonMode", parameters.polygonMode, {
1622
1623
  fill: 6914,
1623
- lint: 6913
1624
+ line: 6913
1624
1625
  });
1625
1626
  ext == null ? void 0 : ext.polygonModeWEBGL(1028, mode);
1626
1627
  ext == null ? void 0 : ext.polygonModeWEBGL(1029, mode);
@@ -1740,7 +1741,12 @@ function convertBlendFactorToFunction(parameter, value) {
1740
1741
  "src-alpha": 770,
1741
1742
  "one-minus-src-alpha": 771,
1742
1743
  "dst-alpha": 772,
1743
- "one-minus-dst-alpha": 773
1744
+ "one-minus-dst-alpha": 773,
1745
+ "src-alpha-saturated": 776,
1746
+ "constant-color": 32769,
1747
+ "one-minus-constant-color": 32770,
1748
+ "constant-alpha": 32771,
1749
+ "one-minus-constant-alpha": 32772
1744
1750
  });
1745
1751
  }
1746
1752
  function message(parameter, value) {
@@ -2617,7 +2623,7 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
2617
2623
  if (!isDefaultFramebuffer) {
2618
2624
  device.setSpectorMetadata(this.handle, { id: this.props.id, props: this.props });
2619
2625
  this.autoCreateAttachmentTextures();
2620
- this.gl.bindFramebuffer(36160, this.handle);
2626
+ const prevHandle = this.gl.bindFramebuffer(36160, this.handle);
2621
2627
  for (let i = 0; i < this.colorAttachments.length; ++i) {
2622
2628
  const attachment = this.colorAttachments[i];
2623
2629
  const attachmentPoint = 36064 + i;
@@ -2634,7 +2640,7 @@ var WEBGLFramebuffer = class extends import_core10.Framebuffer {
2634
2640
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
2635
2641
  }
2636
2642
  }
2637
- this.gl.bindFramebuffer(36160, null);
2643
+ this.gl.bindFramebuffer(36160, prevHandle);
2638
2644
  }
2639
2645
  }
2640
2646
  /** destroys any auto created resources etc. */
@@ -3888,12 +3894,14 @@ var WEBGLRenderPipeline = class extends import_core17.RenderPipeline {
3888
3894
  * Bindings include: textures, samplers and uniform buffers
3889
3895
  * @todo needed for portable model
3890
3896
  */
3891
- setBindings(bindings) {
3897
+ setBindings(bindings, options) {
3892
3898
  for (const [name, value] of Object.entries(bindings)) {
3893
3899
  const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name) || this.shaderLayout.bindings.find((binding2) => binding2.name === `${name}Uniforms`);
3894
3900
  if (!binding) {
3895
3901
  const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
3896
- import_core17.log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
3902
+ if (options == null ? void 0 : options.disableWarnings) {
3903
+ import_core17.log.warn(`Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`)();
3904
+ }
3897
3905
  continue;
3898
3906
  }
3899
3907
  if (!value) {
@@ -4252,6 +4260,7 @@ function _copyTextureToBuffer(device, options) {
4252
4260
  throw new Error("not implemented");
4253
4261
  }
4254
4262
  const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
4263
+ let prevHandle;
4255
4264
  try {
4256
4265
  const webglBuffer = destination;
4257
4266
  const sourceWidth = width || framebuffer.width;
@@ -4260,11 +4269,13 @@ function _copyTextureToBuffer(device, options) {
4260
4269
  const sourceFormat = sourceParams.dataFormat;
4261
4270
  const sourceType = sourceParams.type;
4262
4271
  device.gl.bindBuffer(35051, webglBuffer.handle);
4263
- device.gl.bindFramebuffer(36160, framebuffer.handle);
4272
+ prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
4264
4273
  device.gl.readPixels(origin[0], origin[1], sourceWidth, sourceHeight, sourceFormat, sourceType, byteOffset);
4265
4274
  } finally {
4266
4275
  device.gl.bindBuffer(35051, null);
4267
- device.gl.bindFramebuffer(36160, null);
4276
+ if (prevHandle !== void 0) {
4277
+ device.gl.bindFramebuffer(36160, prevHandle);
4278
+ }
4268
4279
  if (destroyFramebuffer) {
4269
4280
  framebuffer.destroy();
4270
4281
  }
@@ -4274,12 +4285,14 @@ function _copyTextureToTexture(device, options) {
4274
4285
  const {
4275
4286
  /** Texture to copy to/from. */
4276
4287
  source,
4277
- /** Mip-map level of the texture to copy to/from. (Default 0) */
4278
- // mipLevel = 0,
4288
+ /** Mip-map level of the texture to copy to (Default 0) */
4289
+ destinationMipLevel = 0,
4279
4290
  /** Defines which aspects of the texture to copy to/from. */
4280
4291
  // aspect = 'all',
4281
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
4292
+ /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */
4282
4293
  origin = [0, 0],
4294
+ /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
4295
+ destinationOrigin = [0, 0],
4283
4296
  /** Texture to copy to/from. */
4284
4297
  destination
4285
4298
  /** Mip-map level of the texture to copy to/from. (Default 0) */
@@ -4291,15 +4304,13 @@ function _copyTextureToTexture(device, options) {
4291
4304
  } = options;
4292
4305
  let {
4293
4306
  width = options.destination.width,
4294
- height = options.destination.width
4307
+ height = options.destination.height
4295
4308
  // depthOrArrayLayers = 0
4296
4309
  } = options;
4297
- const destinationMipmaplevel = 0;
4298
- const destinationInternalFormat = 6408;
4299
4310
  const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
4300
4311
  const [sourceX, sourceY] = origin;
4301
- const isSubCopy = false;
4302
- device.gl.bindFramebuffer(36160, framebuffer.handle);
4312
+ const [destinationX, destinationY, destinationZ] = destinationOrigin;
4313
+ const prevHandle = device.gl.bindFramebuffer(36160, framebuffer.handle);
4303
4314
  let texture = null;
4304
4315
  let textureTarget;
4305
4316
  if (destination instanceof WEBGLTexture) {
@@ -4307,31 +4318,28 @@ function _copyTextureToTexture(device, options) {
4307
4318
  width = Number.isFinite(width) ? width : texture.width;
4308
4319
  height = Number.isFinite(height) ? height : texture.height;
4309
4320
  texture.bind(0);
4310
- textureTarget = texture.destination;
4311
- } else {
4312
- throw new Error("whoops");
4313
- }
4314
- if (!isSubCopy) {
4315
- device.gl.copyTexImage2D(
4316
- textureTarget,
4317
- destinationMipmaplevel,
4318
- destinationInternalFormat,
4319
- sourceX,
4320
- sourceY,
4321
- width,
4322
- height,
4323
- 0
4324
- /* border must be 0 */
4325
- );
4321
+ textureTarget = texture.target;
4326
4322
  } else {
4323
+ throw new Error("invalid destination");
4324
+ }
4325
+ switch (textureTarget) {
4326
+ case 3553:
4327
+ case 34067:
4328
+ device.gl.copyTexSubImage2D(textureTarget, destinationMipLevel, destinationX, destinationY, sourceX, sourceY, width, height);
4329
+ break;
4330
+ case 35866:
4331
+ case 32879:
4332
+ device.gl.copyTexSubImage3D(textureTarget, destinationMipLevel, destinationX, destinationY, destinationZ, sourceX, sourceY, width, height);
4333
+ break;
4334
+ default:
4327
4335
  }
4328
4336
  if (texture) {
4329
4337
  texture.unbind();
4330
4338
  }
4339
+ device.gl.bindFramebuffer(36160, prevHandle);
4331
4340
  if (destroyFramebuffer) {
4332
4341
  framebuffer.destroy();
4333
4342
  }
4334
- return texture;
4335
4343
  }
4336
4344
  function getFramebuffer(source) {
4337
4345
  if (source instanceof import_core19.Texture) {
@@ -4434,6 +4442,7 @@ var WEBGLVertexArray = class extends import_core21.VertexArray {
4434
4442
  this.device.gl.bindVertexArray(this.handle);
4435
4443
  this.device.gl.bindBuffer(34963, buffer ? buffer.handle : null);
4436
4444
  this.indexBuffer = buffer;
4445
+ this.device.gl.bindVertexArray(null);
4437
4446
  }
4438
4447
  /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
4439
4448
  setBuffer(location, attributeBuffer) {
@@ -4452,20 +4461,15 @@ var WEBGLVertexArray = class extends import_core21.VertexArray {
4452
4461
  this.device.gl.enableVertexAttribArray(location);
4453
4462
  this.device.gl.vertexAttribDivisor(location, divisor || 0);
4454
4463
  this.attributes[location] = buffer;
4464
+ this.device.gl.bindVertexArray(null);
4455
4465
  }
4456
4466
  /** Set a location in vertex attributes array to a constant value, disables the location */
4457
4467
  setConstantWebGL(location, value) {
4458
4468
  this._enable(location, false);
4459
4469
  this.attributes[location] = value;
4460
4470
  }
4461
- init = false;
4462
4471
  bindBeforeRender() {
4463
4472
  this.device.gl.bindVertexArray(this.handle);
4464
- if (!this.init) {
4465
- const webglBuffer = this.indexBuffer;
4466
- this.device.gl.bindBuffer(34963, (webglBuffer == null ? void 0 : webglBuffer.handle) || null);
4467
- this.init = true;
4468
- }
4469
4473
  this._applyConstantAttributes();
4470
4474
  }
4471
4475
  unbindAfterRender() {