maplibre-gl 6.0.0-7 → 6.0.0-8

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * MapLibre GL JS
3
- * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.0.0-7/LICENSE.txt
3
+ * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.0.0-8/LICENSE.txt
4
4
  */
5
5
  //#region \0rolldown/runtime.js
6
6
  var __create = Object.create;
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  }) : target, mod));
27
27
  //#endregion
28
28
  //#region package.json
29
- var version$2 = "6.0.0-7";
29
+ var version$2 = "6.0.0-8";
30
30
  //#endregion
31
31
  //#region node_modules/@mapbox/point-geometry/index.js
32
32
  /**
@@ -31160,7 +31160,7 @@ var Tile = class {
31160
31160
  this.hasSymbolBuckets = false;
31161
31161
  this.hasRTLText = false;
31162
31162
  this.dependencies = {};
31163
- this.rtt = [];
31163
+ this.rttObjects = [];
31164
31164
  this.rttFingerprint = {};
31165
31165
  this.expiredRequestCount = 0;
31166
31166
  this.state = "loading";
@@ -31204,6 +31204,31 @@ var Tile = class {
31204
31204
  this.demTexture = null;
31205
31205
  }
31206
31206
  /**
31207
+ * @internal
31208
+ * Returns the cached RTT object for this stack, or undefined on a cache miss.
31209
+ */
31210
+ getRTT(stack) {
31211
+ return this.rttObjects[stack];
31212
+ }
31213
+ /**
31214
+ * @internal
31215
+ * Allocates a fresh RTT object from the painter's pool and stores it at the
31216
+ * given stack slot. Callers should check {@link getRTT} first; calling this
31217
+ * over an existing slot leaks the previous object.
31218
+ */
31219
+ acquireRTT(painter, stack, size) {
31220
+ return this.rttObjects[stack] = painter.acquireRTT(size);
31221
+ }
31222
+ /**
31223
+ * @internal
31224
+ * Returns all cached RTT slots to the painter's pool.
31225
+ */
31226
+ releaseRTT(painter) {
31227
+ if (this.rttObjects.length === 0) return;
31228
+ for (const obj of this.rttObjects) painter.releaseRTT(obj);
31229
+ this.rttObjects.length = 0;
31230
+ }
31231
+ /**
31207
31232
  * Given a data object with a 'buffers' property, load it into
31208
31233
  * this tile's elementGroups and buffers properties and set loaded
31209
31234
  * to true. If the data is null, like in the case of an empty
@@ -44464,6 +44489,7 @@ var Painter = class Painter {
44464
44489
  this.context = new Context(gl);
44465
44490
  this.transform = transform;
44466
44491
  this._tileTextures = {};
44492
+ this._rttObjectRecyclePool = [];
44467
44493
  this.terrainFacilitator = {
44468
44494
  depthDirty: true,
44469
44495
  coordsDirty: false,
@@ -44881,6 +44907,42 @@ var Painter = class Painter {
44881
44907
  const textures = this._tileTextures[size];
44882
44908
  return textures && textures.length > 0 ? textures.pop() : null;
44883
44909
  }
44910
+ acquireRTT(size) {
44911
+ const gl = this.context.gl;
44912
+ const obj = this._rttObjectRecyclePool.pop();
44913
+ if (obj) {
44914
+ if (obj.size !== size) {
44915
+ gl.bindTexture(gl.TEXTURE_2D, obj.texture.texture);
44916
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size, size, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
44917
+ obj.texture.size = [size, size];
44918
+ this.context.bindRenderbuffer.set(obj.fbo.depthAttachment.get());
44919
+ gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, size, size);
44920
+ this.context.bindRenderbuffer.set(null);
44921
+ obj.fbo.width = size;
44922
+ obj.fbo.height = size;
44923
+ obj.size = size;
44924
+ }
44925
+ return obj;
44926
+ }
44927
+ const fbo = this.context.createFramebuffer(size, size, true, true);
44928
+ const texture = new Texture(this.context, {
44929
+ width: size,
44930
+ height: size,
44931
+ data: null
44932
+ }, gl.RGBA);
44933
+ texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
44934
+ if (this.context.extTextureFilterAnisotropic) gl.texParameterf(gl.TEXTURE_2D, this.context.extTextureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT, this.context.extTextureFilterAnisotropicMax);
44935
+ fbo.depthAttachment.set(this.context.createRenderbuffer(gl.DEPTH_STENCIL, size, size));
44936
+ fbo.colorAttachment.set(texture.texture);
44937
+ return {
44938
+ fbo,
44939
+ texture,
44940
+ size
44941
+ };
44942
+ }
44943
+ releaseRTT(obj) {
44944
+ this._rttObjectRecyclePool.push(obj);
44945
+ }
44884
44946
  /**
44885
44947
  * Checks whether a pattern image is needed, and if it is, whether it is not loaded.
44886
44948
  *
@@ -44953,6 +45015,11 @@ var Painter = class Painter {
44953
45015
  }
44954
45016
  this._tileTextures = {};
44955
45017
  }
45018
+ for (const obj of this._rttObjectRecyclePool) {
45019
+ obj.texture.destroy();
45020
+ obj.fbo.destroy();
45021
+ }
45022
+ this._rttObjectRecyclePool = [];
44956
45023
  if (this.tileExtentBuffer) this.tileExtentBuffer.destroy();
44957
45024
  if (this.debugBuffer) this.debugBuffer.destroy();
44958
45025
  if (this.rasterBoundsBuffer) this.rasterBoundsBuffer.destroy();
@@ -49004,6 +49071,7 @@ var TerrainTileManager = class extends Evented {
49004
49071
  destruct() {
49005
49072
  this.tileManager.usedForTerrain = false;
49006
49073
  this.tileManager.tileSize = null;
49074
+ this.releaseAllRTT();
49007
49075
  }
49008
49076
  getSource() {
49009
49077
  return this.tileManager._source;
@@ -49034,19 +49102,27 @@ var TerrainTileManager = class extends Evented {
49034
49102
  this._lastTilesetChange = now();
49035
49103
  }
49036
49104
  }
49037
- for (const key in this._tiles) if (!keys[key]) delete this._tiles[key];
49105
+ for (const key in this._tiles) if (!keys[key]) {
49106
+ this._tiles[key].releaseRTT(this.tileManager.map.painter);
49107
+ delete this._tiles[key];
49108
+ }
49038
49109
  }
49039
49110
  /**
49040
- * Free render to texture cache
49041
- * @param tileID - optional, free only corresponding to tileID.
49111
+ * Release the RTT objects for `tileID` (and its ancestors/descendants),
49042
49112
  */
49043
- freeRtt(tileID) {
49113
+ releaseRTT(tileID) {
49044
49114
  for (const key in this._tiles) {
49045
49115
  const tile = this._tiles[key];
49046
- if (!tileID || tile.tileID.equals(tileID) || tile.tileID.isChildOf(tileID) || tileID.isChildOf(tile.tileID)) tile.rtt = [];
49116
+ if (tile.tileID.equals(tileID) || tile.tileID.isChildOf(tileID) || tileID.isChildOf(tile.tileID)) tile.releaseRTT(this.tileManager.map.painter);
49047
49117
  }
49048
49118
  }
49049
49119
  /**
49120
+ * Release the A RTT objects for all tiles.
49121
+ */
49122
+ releaseAllRTT() {
49123
+ for (const key in this._tiles) this._tiles[key].releaseRTT(this.tileManager.map.painter);
49124
+ }
49125
+ /**
49050
49126
  * get a list of tiles, which are loaded and should be rendered in the current scene
49051
49127
  * @returns the renderable tiles
49052
49128
  */
@@ -49632,75 +49708,6 @@ var Terrain = class {
49632
49708
  }
49633
49709
  };
49634
49710
  //#endregion
49635
- //#region src/webgl/render_pool.ts
49636
- /**
49637
- * @internal
49638
- * `RenderPool` is a resource pool for textures and framebuffers
49639
- */
49640
- var RenderPool = class {
49641
- constructor(_context, _size, _tileSize) {
49642
- this._context = _context;
49643
- this._size = _size;
49644
- this._tileSize = _tileSize;
49645
- this._objects = [];
49646
- this._recentlyUsed = [];
49647
- this._stamp = 0;
49648
- }
49649
- destruct() {
49650
- for (const obj of this._objects) {
49651
- obj.texture.destroy();
49652
- obj.fbo.destroy();
49653
- }
49654
- }
49655
- _createObject(id) {
49656
- const fbo = this._context.createFramebuffer(this._tileSize, this._tileSize, true, true);
49657
- const texture = new Texture(this._context, {
49658
- width: this._tileSize,
49659
- height: this._tileSize,
49660
- data: null
49661
- }, this._context.gl.RGBA);
49662
- texture.bind(this._context.gl.LINEAR, this._context.gl.CLAMP_TO_EDGE);
49663
- if (this._context.extTextureFilterAnisotropic) this._context.gl.texParameterf(this._context.gl.TEXTURE_2D, this._context.extTextureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT, this._context.extTextureFilterAnisotropicMax);
49664
- fbo.depthAttachment.set(this._context.createRenderbuffer(this._context.gl.DEPTH_STENCIL, this._tileSize, this._tileSize));
49665
- fbo.colorAttachment.set(texture.texture);
49666
- return {
49667
- id,
49668
- fbo,
49669
- texture,
49670
- stamp: -1,
49671
- inUse: false
49672
- };
49673
- }
49674
- getObjectForId(id) {
49675
- return this._objects[id];
49676
- }
49677
- useObject(obj) {
49678
- obj.inUse = true;
49679
- this._recentlyUsed = this._recentlyUsed.filter((id) => obj.id !== id);
49680
- this._recentlyUsed.push(obj.id);
49681
- }
49682
- stampObject(obj) {
49683
- obj.stamp = ++this._stamp;
49684
- }
49685
- getOrCreateFreeObject() {
49686
- for (const id of this._recentlyUsed) if (!this._objects[id].inUse) return this._objects[id];
49687
- if (this._objects.length >= this._size) throw new Error("No free RenderPool available, call freeAllObjects() required!");
49688
- const obj = this._createObject(this._objects.length);
49689
- this._objects.push(obj);
49690
- return obj;
49691
- }
49692
- freeObject(obj) {
49693
- obj.inUse = false;
49694
- }
49695
- freeAllObjects() {
49696
- for (const obj of this._objects) this.freeObject(obj);
49697
- }
49698
- isFull() {
49699
- if (this._objects.length < this._size) return false;
49700
- return this._objects.some((o) => !o.inUse) === false;
49701
- }
49702
- };
49703
- //#endregion
49704
49711
  //#region src/webgl/render_to_texture.ts
49705
49712
  /**
49706
49713
  * lookup table which layers should rendered to texture
@@ -49715,19 +49722,19 @@ const LAYERS_TO_TEXTURES = {
49715
49722
  };
49716
49723
  /**
49717
49724
  * @internal
49718
- * A helper class to help define what should be rendered to texture and how
49725
+ * Renders RTT-eligible layers into per-tile cached textures, then drapes
49726
+ * them onto the terrain mesh. Slots live on each Tile so their lifetime
49727
+ * tracks the tile itself; the underlying FBO+texture handles are recycled
49728
+ * via the painter's RTT pool.
49719
49729
  */
49720
49730
  var RenderToTexture = class {
49721
49731
  constructor(painter, terrain) {
49722
49732
  this.painter = painter;
49723
49733
  this.terrain = terrain;
49724
- this.pool = new RenderPool(painter.context, 30, terrain.tileManager.tileSize * terrain.qualityFactor);
49725
- }
49726
- destruct() {
49727
- this.pool.destruct();
49734
+ this.rttSize = terrain.tileManager.tileSize * terrain.qualityFactor;
49728
49735
  }
49729
49736
  getTexture(tile) {
49730
- return this.pool.getObjectForId(tile.rtt[this._stacks.length - 1].id).texture;
49737
+ return tile.getRTT(this._stacks.length - 1).texture;
49731
49738
  }
49732
49739
  prepareForRender(style, zoom) {
49733
49740
  this._stacks = [];
@@ -49761,7 +49768,7 @@ var RenderToTexture = class {
49761
49768
  }
49762
49769
  for (const tile of this._renderableTiles) for (const source in this._rttFingerprints) {
49763
49770
  const fingerprint = this._rttFingerprints[source][tile.tileID.key];
49764
- if (fingerprint && fingerprint !== tile.rttFingerprint[source]) tile.rtt = [];
49771
+ if (fingerprint && fingerprint !== tile.rttFingerprint[source]) tile.releaseRTT(this.painter);
49765
49772
  }
49766
49773
  }
49767
49774
  /**
@@ -49794,26 +49801,9 @@ var RenderToTexture = class {
49794
49801
  this._prevType = type;
49795
49802
  const stack = this._stacks.length - 1, layers = this._stacks[stack] || [];
49796
49803
  for (const tile of this._renderableTiles) {
49797
- if (this.pool.isFull()) {
49798
- drawTerrain(this.painter, this.terrain, this._rttTiles, options);
49799
- this._rttTiles = [];
49800
- this.pool.freeAllObjects();
49801
- }
49802
49804
  this._rttTiles.push(tile);
49803
- if (tile.rtt[stack]) {
49804
- const obj = this.pool.getObjectForId(tile.rtt[stack].id);
49805
- if (obj.stamp === tile.rtt[stack].stamp) {
49806
- this.pool.useObject(obj);
49807
- continue;
49808
- }
49809
- }
49810
- const obj = this.pool.getOrCreateFreeObject();
49811
- this.pool.useObject(obj);
49812
- this.pool.stampObject(obj);
49813
- tile.rtt[stack] = {
49814
- id: obj.id,
49815
- stamp: obj.stamp
49816
- };
49805
+ if (tile.getRTT(stack)) continue;
49806
+ const obj = tile.acquireRTT(painter, stack, this.rttSize);
49817
49807
  painter.context.bindFramebuffer.set(obj.fbo.framebuffer);
49818
49808
  painter.context.clear({
49819
49809
  color: Color.transparent,
@@ -49836,7 +49826,6 @@ var RenderToTexture = class {
49836
49826
  }
49837
49827
  drawTerrain(this.painter, this.terrain, this._rttTiles, options);
49838
49828
  this._rttTiles = [];
49839
- this.pool.freeAllObjects();
49840
49829
  return LAYERS_TO_TEXTURES[type];
49841
49830
  }
49842
49831
  return false;
@@ -51225,7 +51214,6 @@ var Map$1 = class extends Camera {
51225
51214
  if (!options) {
51226
51215
  if (this.terrain) this.terrain.destroy();
51227
51216
  this.terrain = null;
51228
- if (this.painter.renderToTexture) this.painter.renderToTexture.destruct();
51229
51217
  this.painter.renderToTexture = null;
51230
51218
  this.transform.setMinElevationForCurrentTile(0);
51231
51219
  if (this._centerClampedToGround) this.transform.setElevation(0);
@@ -51243,14 +51231,14 @@ var Map$1 = class extends Camera {
51243
51231
  this.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this.transform.center, this.transform.tileZoom));
51244
51232
  this.transform.setElevation(this.terrain.getElevationForLngLatZoom(this.transform.center, this.transform.tileZoom));
51245
51233
  this._terrainDataCallback = (e) => {
51246
- if (e.dataType === "style") this.terrain.tileManager.freeRtt();
51234
+ if (e.dataType === "style") this.terrain.tileManager.releaseAllRTT();
51247
51235
  else if (e.dataType === "source" && e.tile) {
51248
51236
  if (e.sourceId === options.source && !this._elevationFreeze) {
51249
51237
  this.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this.transform.center, this.transform.tileZoom));
51250
51238
  if (this._centerClampedToGround) this.transform.setElevation(this.terrain.getElevationForLngLatZoom(this.transform.center, this.transform.tileZoom));
51251
51239
  }
51252
- if (e.source?.type === "image") this.terrain.tileManager.freeRtt();
51253
- else this.terrain.tileManager.freeRtt(e.tile.tileID);
51240
+ if (e.source?.type === "image") this.terrain.tileManager.releaseAllRTT();
51241
+ else this.terrain.tileManager.releaseRTT(e.tile.tileID);
51254
51242
  }
51255
51243
  };
51256
51244
  this.style.on("data", this._terrainDataCallback);