@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/dist.dev.js CHANGED
@@ -2060,12 +2060,8 @@ var __exports__ = (() => {
2060
2060
  getWebGLExtension(gl, "EXT_color_buffer_float", extensions);
2061
2061
  }
2062
2062
  *[Symbol.iterator]() {
2063
- for (const feature of Object.keys(WEBGL_FEATURES)) {
2064
- if (this.has(feature)) {
2065
- yield feature;
2066
- }
2067
- }
2068
- for (const feature of Object.keys(TEXTURE_FEATURES)) {
2063
+ const features = this.getFeatures();
2064
+ for (const feature of features) {
2069
2065
  if (this.has(feature)) {
2070
2066
  yield feature;
2071
2067
  }
@@ -2089,10 +2085,15 @@ var __exports__ = (() => {
2089
2085
  }
2090
2086
  // FOR DEVICE
2091
2087
  initializeFeatures() {
2092
- for (const feature of this) {
2088
+ const features = this.getFeatures().filter((feature) => feature !== "polygon-mode-webgl");
2089
+ for (const feature of features) {
2090
+ this.has(feature);
2093
2091
  }
2094
2092
  }
2095
2093
  // IMPLEMENTATION
2094
+ getFeatures() {
2095
+ return [...Object.keys(WEBGL_FEATURES), ...Object.keys(TEXTURE_FEATURES)];
2096
+ }
2096
2097
  /** Extract all WebGL features */
2097
2098
  getWebGLFeature(feature) {
2098
2099
  const featureInfo = WEBGL_FEATURES[feature];
@@ -2314,10 +2315,14 @@ var __exports__ = (() => {
2314
2315
  const extensions = webglDevice.getExtension("WEBGL_provoking_vertex");
2315
2316
  const ext = extensions.WEBGL_provoking_vertex;
2316
2317
  if (parameters.provokingVertex) {
2317
- const vertex = map("provokingVertex", parameters.provokingVertex, {
2318
- first: 36429 /* FIRST_VERTEX_CONVENTION_WEBGL */,
2319
- last: 36430 /* LAST_VERTEX_CONVENTION_WEBGL */
2320
- });
2318
+ const vertex = map(
2319
+ "provokingVertex",
2320
+ parameters.provokingVertex,
2321
+ {
2322
+ first: 36429 /* FIRST_VERTEX_CONVENTION_WEBGL */,
2323
+ last: 36430 /* LAST_VERTEX_CONVENTION_WEBGL */
2324
+ }
2325
+ );
2321
2326
  ext?.provokingVertexWEBGL(vertex);
2322
2327
  }
2323
2328
  }
@@ -2325,9 +2330,9 @@ var __exports__ = (() => {
2325
2330
  const extensions = webglDevice.getExtension("WEBGL_polygon_mode");
2326
2331
  const ext = extensions.WEBGL_polygon_mode;
2327
2332
  if (parameters.polygonMode) {
2328
- const mode = map("polygonMode", parameters.provokingVertex, {
2333
+ const mode = map("polygonMode", parameters.polygonMode, {
2329
2334
  fill: 6914 /* FILL_WEBGL */,
2330
- lint: 6913 /* LINE_WEBGL */
2335
+ line: 6913 /* LINE_WEBGL */
2331
2336
  });
2332
2337
  ext?.polygonModeWEBGL(1028 /* FRONT */, mode);
2333
2338
  ext?.polygonModeWEBGL(1029 /* BACK */, mode);
@@ -2468,7 +2473,12 @@ var __exports__ = (() => {
2468
2473
  "src-alpha": 770 /* SRC_ALPHA */,
2469
2474
  "one-minus-src-alpha": 771 /* ONE_MINUS_SRC_ALPHA */,
2470
2475
  "dst-alpha": 772 /* DST_ALPHA */,
2471
- "one-minus-dst-alpha": 773 /* ONE_MINUS_DST_ALPHA */
2476
+ "one-minus-dst-alpha": 773 /* ONE_MINUS_DST_ALPHA */,
2477
+ "src-alpha-saturated": 776 /* SRC_ALPHA_SATURATE */,
2478
+ "constant-color": 32769 /* CONSTANT_COLOR */,
2479
+ "one-minus-constant-color": 32770 /* ONE_MINUS_CONSTANT_COLOR */,
2480
+ "constant-alpha": 32771 /* CONSTANT_ALPHA */,
2481
+ "one-minus-constant-alpha": 32772 /* ONE_MINUS_CONSTANT_ALPHA */
2472
2482
  });
2473
2483
  }
2474
2484
  function message(parameter, value) {
@@ -3441,7 +3451,10 @@ var __exports__ = (() => {
3441
3451
  if (!isDefaultFramebuffer) {
3442
3452
  device.setSpectorMetadata(this.handle, { id: this.props.id, props: this.props });
3443
3453
  this.autoCreateAttachmentTextures();
3444
- this.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, this.handle);
3454
+ const prevHandle = this.gl.bindFramebuffer(
3455
+ 36160 /* FRAMEBUFFER */,
3456
+ this.handle
3457
+ );
3445
3458
  for (let i = 0; i < this.colorAttachments.length; ++i) {
3446
3459
  const attachment = this.colorAttachments[i];
3447
3460
  const attachmentPoint = 36064 /* COLOR_ATTACHMENT0 */ + i;
@@ -3461,7 +3474,7 @@ var __exports__ = (() => {
3461
3474
  throw new Error(`Framebuffer ${_getFrameBufferStatus(status)}`);
3462
3475
  }
3463
3476
  }
3464
- this.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, null);
3477
+ this.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, prevHandle);
3465
3478
  }
3466
3479
  }
3467
3480
  /** destroys any auto created resources etc. */
@@ -3699,38 +3712,35 @@ var __exports__ = (() => {
3699
3712
  // src/context/debug/webgl-developer-tools.ts
3700
3713
  var import_core13 = __toESM(require_core(), 1);
3701
3714
 
3715
+ // ../../node_modules/@probe.gl/env/dist/lib/globals.js
3716
+ var document_ = globalThis.document || {};
3717
+ var process_ = globalThis.process || {};
3718
+ var console_ = globalThis.console;
3719
+ var navigator_ = globalThis.navigator || {};
3720
+
3702
3721
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
3703
3722
  function isElectron(mockUserAgent) {
3704
- if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
3723
+ if (typeof window !== "undefined" && window.process?.type === "renderer") {
3705
3724
  return true;
3706
3725
  }
3707
- if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
3726
+ if (typeof process !== "undefined" && Boolean(process.versions?.["electron"])) {
3708
3727
  return true;
3709
3728
  }
3710
- const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
3729
+ const realUserAgent = typeof navigator !== "undefined" && navigator.userAgent;
3711
3730
  const userAgent = mockUserAgent || realUserAgent;
3712
- if (userAgent && userAgent.indexOf("Electron") >= 0) {
3713
- return true;
3714
- }
3715
- return false;
3731
+ return Boolean(userAgent && userAgent.indexOf("Electron") >= 0);
3716
3732
  }
3717
3733
 
3718
3734
  // ../../node_modules/@probe.gl/env/dist/lib/is-browser.js
3719
3735
  function isBrowser() {
3720
- const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
3736
+ const isNode = (
3737
+ // @ts-expect-error
3738
+ typeof process === "object" && String(process) === "[object process]" && !process?.browser
3739
+ );
3721
3740
  return !isNode || isElectron();
3722
3741
  }
3723
3742
 
3724
- // ../../node_modules/@probe.gl/env/dist/lib/globals.js
3725
- var self_ = globalThis.self || globalThis.window || globalThis.global;
3726
- var window_ = globalThis.window || globalThis.self || globalThis.global;
3727
- var document_ = globalThis.document || {};
3728
- var process_ = globalThis.process || {};
3729
- var console_ = globalThis.console;
3730
- var navigator_ = globalThis.navigator || {};
3731
-
3732
3743
  // ../../node_modules/@probe.gl/env/dist/lib/get-browser.js
3733
- var window2 = globalThis;
3734
3744
  function getBrowser(mockUserAgent) {
3735
3745
  if (!mockUserAgent && !isBrowser()) {
3736
3746
  return "Node";
@@ -3742,18 +3752,13 @@ var __exports__ = (() => {
3742
3752
  if (userAgent.indexOf("Edge") > -1) {
3743
3753
  return "Edge";
3744
3754
  }
3745
- const isMSIE = userAgent.indexOf("MSIE ") !== -1;
3746
- const isTrident = userAgent.indexOf("Trident/") !== -1;
3747
- if (isMSIE || isTrident) {
3748
- return "IE";
3749
- }
3750
- if (window2.chrome) {
3755
+ if (globalThis.chrome) {
3751
3756
  return "Chrome";
3752
3757
  }
3753
- if (window2.safari) {
3758
+ if (globalThis.safari) {
3754
3759
  return "Safari";
3755
3760
  }
3756
- if (window2.mozInnerScreenX) {
3761
+ if (globalThis.mozInnerScreenX) {
3757
3762
  return "Firefox";
3758
3763
  }
3759
3764
  return "Unknown";
@@ -4797,14 +4802,16 @@ ${source2}`;
4797
4802
  * Bindings include: textures, samplers and uniform buffers
4798
4803
  * @todo needed for portable model
4799
4804
  */
4800
- setBindings(bindings) {
4805
+ setBindings(bindings, options) {
4801
4806
  for (const [name, value] of Object.entries(bindings)) {
4802
4807
  const binding = this.shaderLayout.bindings.find((binding2) => binding2.name === name) || this.shaderLayout.bindings.find((binding2) => binding2.name === `${name}Uniforms`);
4803
4808
  if (!binding) {
4804
4809
  const validBindings = this.shaderLayout.bindings.map((binding2) => `"${binding2.name}"`).join(", ");
4805
- import_core17.log.warn(
4806
- `Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
4807
- )();
4810
+ if (options?.disableWarnings) {
4811
+ import_core17.log.warn(
4812
+ `Unknown binding "${name}" in render pipeline "${this.id}", expected one of ${validBindings}`
4813
+ )();
4814
+ }
4808
4815
  continue;
4809
4816
  }
4810
4817
  if (!value) {
@@ -5182,6 +5189,7 @@ ${source2}`;
5182
5189
  throw new Error("not implemented");
5183
5190
  }
5184
5191
  const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
5192
+ let prevHandle;
5185
5193
  try {
5186
5194
  const webglBuffer = destination;
5187
5195
  const sourceWidth = width || framebuffer.width;
@@ -5190,7 +5198,7 @@ ${source2}`;
5190
5198
  const sourceFormat = sourceParams.dataFormat;
5191
5199
  const sourceType = sourceParams.type;
5192
5200
  device.gl.bindBuffer(35051 /* PIXEL_PACK_BUFFER */, webglBuffer.handle);
5193
- device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, framebuffer.handle);
5201
+ prevHandle = device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, framebuffer.handle);
5194
5202
  device.gl.readPixels(
5195
5203
  origin[0],
5196
5204
  origin[1],
@@ -5202,7 +5210,9 @@ ${source2}`;
5202
5210
  );
5203
5211
  } finally {
5204
5212
  device.gl.bindBuffer(35051 /* PIXEL_PACK_BUFFER */, null);
5205
- device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, null);
5213
+ if (prevHandle !== void 0) {
5214
+ device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, prevHandle);
5215
+ }
5206
5216
  if (destroyFramebuffer) {
5207
5217
  framebuffer.destroy();
5208
5218
  }
@@ -5212,12 +5222,14 @@ ${source2}`;
5212
5222
  const {
5213
5223
  /** Texture to copy to/from. */
5214
5224
  source,
5215
- /** Mip-map level of the texture to copy to/from. (Default 0) */
5216
- // mipLevel = 0,
5225
+ /** Mip-map level of the texture to copy to (Default 0) */
5226
+ destinationMipLevel = 0,
5217
5227
  /** Defines which aspects of the texture to copy to/from. */
5218
5228
  // aspect = 'all',
5219
- /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to/from. */
5229
+ /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy from. */
5220
5230
  origin = [0, 0],
5231
+ /** Defines the origin of the copy - the minimum corner of the texture sub-region to copy to. */
5232
+ destinationOrigin = [0, 0],
5221
5233
  /** Texture to copy to/from. */
5222
5234
  destination
5223
5235
  /** Mip-map level of the texture to copy to/from. (Default 0) */
@@ -5229,15 +5241,16 @@ ${source2}`;
5229
5241
  } = options;
5230
5242
  let {
5231
5243
  width = options.destination.width,
5232
- height = options.destination.width
5244
+ height = options.destination.height
5233
5245
  // depthOrArrayLayers = 0
5234
5246
  } = options;
5235
- const destinationMipmaplevel = 0;
5236
- const destinationInternalFormat = 6408 /* RGBA */;
5237
5247
  const { framebuffer, destroyFramebuffer } = getFramebuffer(source);
5238
5248
  const [sourceX, sourceY] = origin;
5239
- const isSubCopy = false;
5240
- device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, framebuffer.handle);
5249
+ const [destinationX, destinationY, destinationZ] = destinationOrigin;
5250
+ const prevHandle = device.gl.bindFramebuffer(
5251
+ 36160 /* FRAMEBUFFER */,
5252
+ framebuffer.handle
5253
+ );
5241
5254
  let texture = null;
5242
5255
  let textureTarget;
5243
5256
  if (destination instanceof WEBGLTexture) {
@@ -5245,31 +5258,47 @@ ${source2}`;
5245
5258
  width = Number.isFinite(width) ? width : texture.width;
5246
5259
  height = Number.isFinite(height) ? height : texture.height;
5247
5260
  texture.bind(0);
5248
- textureTarget = texture.destination;
5249
- } else {
5250
- throw new Error("whoops");
5251
- }
5252
- if (!isSubCopy) {
5253
- device.gl.copyTexImage2D(
5254
- textureTarget,
5255
- destinationMipmaplevel,
5256
- destinationInternalFormat,
5257
- sourceX,
5258
- sourceY,
5259
- width,
5260
- height,
5261
- 0
5262
- /* border must be 0 */
5263
- );
5261
+ textureTarget = texture.target;
5264
5262
  } else {
5263
+ throw new Error("invalid destination");
5264
+ }
5265
+ switch (textureTarget) {
5266
+ case 3553 /* TEXTURE_2D */:
5267
+ case 34067 /* TEXTURE_CUBE_MAP */:
5268
+ device.gl.copyTexSubImage2D(
5269
+ textureTarget,
5270
+ destinationMipLevel,
5271
+ destinationX,
5272
+ destinationY,
5273
+ sourceX,
5274
+ sourceY,
5275
+ width,
5276
+ height
5277
+ );
5278
+ break;
5279
+ case 35866 /* TEXTURE_2D_ARRAY */:
5280
+ case 32879 /* TEXTURE_3D */:
5281
+ device.gl.copyTexSubImage3D(
5282
+ textureTarget,
5283
+ destinationMipLevel,
5284
+ destinationX,
5285
+ destinationY,
5286
+ destinationZ,
5287
+ sourceX,
5288
+ sourceY,
5289
+ width,
5290
+ height
5291
+ );
5292
+ break;
5293
+ default:
5265
5294
  }
5266
5295
  if (texture) {
5267
5296
  texture.unbind();
5268
5297
  }
5298
+ device.gl.bindFramebuffer(36160 /* FRAMEBUFFER */, prevHandle);
5269
5299
  if (destroyFramebuffer) {
5270
5300
  framebuffer.destroy();
5271
5301
  }
5272
- return texture;
5273
5302
  }
5274
5303
  function getFramebuffer(source) {
5275
5304
  if (source instanceof import_core19.Texture) {
@@ -5358,8 +5387,8 @@ ${source2}`;
5358
5387
  /**
5359
5388
  // Set (bind/unbind) an elements buffer, for indexed rendering.
5360
5389
  // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER or null. Constants not supported
5361
- *
5362
- * @param elementBuffer
5390
+ *
5391
+ * @param elementBuffer
5363
5392
  */
5364
5393
  setIndexBuffer(indexBuffer) {
5365
5394
  const buffer = indexBuffer;
@@ -5369,6 +5398,7 @@ ${source2}`;
5369
5398
  this.device.gl.bindVertexArray(this.handle);
5370
5399
  this.device.gl.bindBuffer(34963 /* ELEMENT_ARRAY_BUFFER */, buffer ? buffer.handle : null);
5371
5400
  this.indexBuffer = buffer;
5401
+ this.device.gl.bindVertexArray(null);
5372
5402
  }
5373
5403
  /** Set a location in vertex attributes array to a buffer, enables the location, sets divisor */
5374
5404
  setBuffer(location, attributeBuffer) {
@@ -5387,20 +5417,15 @@ ${source2}`;
5387
5417
  this.device.gl.enableVertexAttribArray(location);
5388
5418
  this.device.gl.vertexAttribDivisor(location, divisor || 0);
5389
5419
  this.attributes[location] = buffer;
5420
+ this.device.gl.bindVertexArray(null);
5390
5421
  }
5391
5422
  /** Set a location in vertex attributes array to a constant value, disables the location */
5392
5423
  setConstantWebGL(location, value) {
5393
5424
  this._enable(location, false);
5394
5425
  this.attributes[location] = value;
5395
5426
  }
5396
- init = false;
5397
5427
  bindBeforeRender() {
5398
5428
  this.device.gl.bindVertexArray(this.handle);
5399
- if (!this.init) {
5400
- const webglBuffer = this.indexBuffer;
5401
- this.device.gl.bindBuffer(34963 /* ELEMENT_ARRAY_BUFFER */, webglBuffer?.handle || null);
5402
- this.init = true;
5403
- }
5404
5429
  this._applyConstantAttributes();
5405
5430
  }
5406
5431
  unbindAfterRender() {