@galacean/engine-core 0.9.11 → 0.9.12

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.
@@ -1466,9 +1466,11 @@ exports.GLCapabilityType = void 0;
1466
1466
  renderTexture
1467
1467
  ];
1468
1468
  for(var i = 0, n = colorTextures.length; i < n; i++){
1469
- if (colorTextures[i]._isDepthTexture) {
1469
+ var colorTexture = colorTextures[i];
1470
+ if (colorTexture._isDepthTexture) {
1470
1471
  throw "Render texture can't use depth format.";
1471
1472
  }
1473
+ colorTexture._addRefCount(1);
1472
1474
  }
1473
1475
  _this._colorTextures = colorTextures;
1474
1476
  } else {
@@ -1479,6 +1481,7 @@ exports.GLCapabilityType = void 0;
1479
1481
  throw "Depth texture must use depth format.";
1480
1482
  }
1481
1483
  _this._depthTexture = depth;
1484
+ _this._depthTexture._addRefCount(1);
1482
1485
  }
1483
1486
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1484
1487
  return _this;
@@ -1507,8 +1510,14 @@ exports.GLCapabilityType = void 0;
1507
1510
  /**
1508
1511
  * Destroy render target.
1509
1512
  */ _proto.destroy = function destroy() {
1513
+ var _this__depthTexture;
1510
1514
  this._platformRenderTarget.destroy();
1511
- this._colorTextures.length = 0;
1515
+ var _this = this, colorTextures = _this._colorTextures;
1516
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1517
+ colorTextures[i]._addRefCount(-1);
1518
+ }
1519
+ colorTextures.length = 0;
1520
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
1512
1521
  this._depthTexture = null;
1513
1522
  this._depth = null;
1514
1523
  };
@@ -1954,6 +1963,7 @@ exports.GLCapabilityType = void 0;
1954
1963
  var fontAtlas = new FontAtlas(engine);
1955
1964
  var texture = new Texture2D(engine, 256, 256);
1956
1965
  fontAtlas.texture = texture;
1966
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
1957
1967
  this._fontAtlases.push(fontAtlas);
1958
1968
  return fontAtlas;
1959
1969
  };
@@ -8759,6 +8769,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8759
8769
  _proto.cloneTo = function cloneTo(target) {
8760
8770
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8761
8771
  Object.assign(target._macroMap, this._macroMap);
8772
+ var referCount = target._getRefCount();
8762
8773
  var propertyValueMap = this._propertyValueMap;
8763
8774
  var targetPropertyValueMap = target._propertyValueMap;
8764
8775
  var keys = Object.keys(propertyValueMap);
@@ -8770,6 +8781,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8770
8781
  targetPropertyValueMap[k] = property;
8771
8782
  } else if (_instanceof(property, Texture)) {
8772
8783
  targetPropertyValueMap[k] = property;
8784
+ referCount > 0 && property._addRefCount(referCount);
8773
8785
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8774
8786
  targetPropertyValueMap[k] = property.slice();
8775
8787
  } else {
@@ -10514,16 +10526,6 @@ SimpleSpriteAssembler = __decorate([
10514
10526
  }
10515
10527
  var _proto = SpriteMask.prototype;
10516
10528
  /**
10517
- * @override
10518
- * @inheritdoc
10519
- */ _proto._onDestroy = function _onDestroy() {
10520
- var _this__sprite;
10521
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10522
- this._sprite = null;
10523
- this._renderData = null;
10524
- Renderer.prototype._onDestroy.call(this);
10525
- };
10526
- /**
10527
10529
  * @internal
10528
10530
  */ _proto._cloneTo = function _cloneTo(target) {
10529
10531
  Renderer.prototype._cloneTo.call(this, target);
@@ -10563,6 +10565,19 @@ SimpleSpriteAssembler = __decorate([
10563
10565
  context.camera._renderPipeline._allSpriteMasks.add(this);
10564
10566
  this._maskElement = maskElement;
10565
10567
  };
10568
+ /**
10569
+ * @internal
10570
+ * @inheritdoc
10571
+ */ _proto._onDestroy = function _onDestroy() {
10572
+ Renderer.prototype._onDestroy.call(this);
10573
+ var sprite = this._sprite;
10574
+ if (sprite) {
10575
+ sprite._addRefCount(-1);
10576
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10577
+ }
10578
+ this._sprite = null;
10579
+ this._renderData = null;
10580
+ };
10566
10581
  _proto._calDefaultSize = function _calDefaultSize() {
10567
10582
  var sprite = this._sprite;
10568
10583
  if (sprite) {
@@ -10681,9 +10696,13 @@ SimpleSpriteAssembler = __decorate([
10681
10696
  set: function set(value) {
10682
10697
  var lastSprite = this._sprite;
10683
10698
  if (lastSprite !== value) {
10684
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10699
+ if (lastSprite) {
10700
+ lastSprite._addRefCount(-1);
10701
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10702
+ }
10685
10703
  this._dirtyUpdateFlag |= 0x7;
10686
10704
  if (value) {
10705
+ value._addRefCount(1);
10687
10706
  value._updateFlagManager.addListener(this._onSpriteChange);
10688
10707
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10689
10708
  } else {
@@ -11250,10 +11269,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11250
11269
  /**
11251
11270
  * @internal
11252
11271
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11253
- if (this._getRefCount() > 0) {
11254
- var lastBinding = this._vertexBufferBindings[index];
11255
- lastBinding && lastBinding._buffer._addRefCount(-1);
11256
- binding._buffer._addRefCount(1);
11272
+ var referCount = this._getRefCount();
11273
+ if (referCount > 0) {
11274
+ var _this__vertexBufferBindings_index;
11275
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11276
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11257
11277
  }
11258
11278
  this._vertexBufferBindings[index] = binding;
11259
11279
  this._bufferStructChanged = true;
@@ -11267,11 +11287,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11267
11287
  /**
11268
11288
  * @override
11269
11289
  */ _proto._addRefCount = function _addRefCount(value) {
11290
+ var _this__indexBufferBinding;
11270
11291
  RefObject.prototype._addRefCount.call(this, value);
11271
11292
  var vertexBufferBindings = this._vertexBufferBindings;
11272
11293
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11273
11294
  vertexBufferBindings[i]._buffer._addRefCount(value);
11274
11295
  }
11296
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11275
11297
  };
11276
11298
  /**
11277
11299
  * @override
@@ -11291,6 +11313,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11291
11313
  };
11292
11314
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11293
11315
  var lastBinding = this._indexBufferBinding;
11316
+ var referCount = this._getRefCount();
11317
+ if (referCount > 0) {
11318
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11319
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11320
+ }
11294
11321
  if (binding) {
11295
11322
  this._indexBufferBinding = binding;
11296
11323
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -14469,14 +14496,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14469
14496
  _proto._createMesh = function _createMesh(engine, index) {
14470
14497
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14471
14498
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14499
+ mesh.isGCIgnored = true;
14472
14500
  var vertexElements = [];
14473
14501
  var vertexStride = this.createVertexElements(vertexElements);
14474
14502
  // vertices
14475
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14503
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14504
+ vertexBuffer.isGCIgnored = true;
14476
14505
  // indices
14477
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14478
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14479
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
14506
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14507
+ indiceBuffer.isGCIgnored = true;
14508
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14509
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
14480
14510
  mesh.setVertexElements(vertexElements);
14481
14511
  return mesh;
14482
14512
  };
@@ -14715,6 +14745,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14715
14745
  var _proto = Sky.prototype;
14716
14746
  /**
14717
14747
  * @internal
14748
+ */ _proto.destroy = function destroy() {
14749
+ this.mesh = null;
14750
+ this.material = null;
14751
+ };
14752
+ /**
14753
+ * @internal
14718
14754
  */ _proto._render = function _render(context) {
14719
14755
  var _this = this, material = _this.material, mesh = _this.mesh;
14720
14756
  if (!material) {
@@ -14753,6 +14789,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14753
14789
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14754
14790
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14755
14791
  };
14792
+ _create_class(Sky, [
14793
+ {
14794
+ key: "material",
14795
+ get: /**
14796
+ * Material of the sky.
14797
+ */ function get() {
14798
+ return this._material;
14799
+ },
14800
+ set: function set(value) {
14801
+ if (this._material !== value) {
14802
+ var _this__material;
14803
+ value == null ? void 0 : value._addRefCount(1);
14804
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14805
+ this._material = value;
14806
+ }
14807
+ }
14808
+ },
14809
+ {
14810
+ key: "mesh",
14811
+ get: /**
14812
+ * Mesh of the sky.
14813
+ */ function get() {
14814
+ return this._mesh;
14815
+ },
14816
+ set: function set(value) {
14817
+ if (this._mesh !== value) {
14818
+ var _this__mesh;
14819
+ value == null ? void 0 : value._addRefCount(1);
14820
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14821
+ this._mesh = value;
14822
+ }
14823
+ }
14824
+ }
14825
+ ]);
14756
14826
  return Sky;
14757
14827
  }();
14758
14828
  (function() {
@@ -14783,11 +14853,28 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14783
14853
  this.sky = new Sky();
14784
14854
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
14785
14855
  this._texture = null;
14786
- this._mesh = this._createPlane(_engine);
14856
+ this._initMesh(_engine);
14787
14857
  }
14788
14858
  var _proto = Background.prototype;
14789
14859
  /**
14790
14860
  * @internal
14861
+ */ _proto.destroy = function destroy() {
14862
+ this._mesh._addRefCount(-1);
14863
+ this._mesh = null;
14864
+ this.texture = null;
14865
+ this.solidColor = null;
14866
+ this.sky.destroy();
14867
+ this._engine = null;
14868
+ };
14869
+ /**
14870
+ * @internal
14871
+ * Standalone for CanvasRenderer plugin.
14872
+ */ _proto._initMesh = function _initMesh(engine) {
14873
+ this._mesh = this._createPlane(engine);
14874
+ this._mesh._addRefCount(1);
14875
+ };
14876
+ /**
14877
+ * @internal
14791
14878
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14792
14879
  if (!this._texture) {
14793
14880
  return;
@@ -14856,6 +14943,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14856
14943
  },
14857
14944
  set: function set(value) {
14858
14945
  if (this._texture !== value) {
14946
+ var _this__texture;
14947
+ value == null ? void 0 : value._addRefCount(1);
14948
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14859
14949
  this._texture = value;
14860
14950
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14861
14951
  }
@@ -15359,6 +15449,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15359
15449
  this._rootEntities[0].destroy();
15360
15450
  }
15361
15451
  this._activeCameras.length = 0;
15452
+ this.background.destroy();
15362
15453
  this.shaderData._addRefCount(-1);
15363
15454
  };
15364
15455
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15772,7 +15863,7 @@ ShaderPool.init();
15772
15863
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15773
15864
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15774
15865
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15775
- _this._textDefaultFont.isGCIgnored = false;
15866
+ _this._textDefaultFont.isGCIgnored = true;
15776
15867
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15777
15868
  var magentaPixel = new Uint8Array([
15778
15869
  255,
@@ -15807,6 +15898,7 @@ ShaderPool.init();
15807
15898
  _this._magentaTexture2DArray = magentaTexture2DArray;
15808
15899
  }
15809
15900
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
15901
+ magentaMaterial.isGCIgnored = true;
15810
15902
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15811
15903
  _this._magentaMaterial = magentaMaterial;
15812
15904
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17339,7 +17431,11 @@ var /**
17339
17431
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17340
17432
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17341
17433
  }
17342
- this._renderTargets = null;
17434
+ var renderTargets = this._renderTargets;
17435
+ if (renderTargets) {
17436
+ renderTargets.destroy();
17437
+ this._renderTargets = null;
17438
+ }
17343
17439
  var viewportOffset = this._viewportOffsets;
17344
17440
  var shadowTileResolution1 = this._shadowTileResolution;
17345
17441
  switch(shadowCascades){
@@ -19381,10 +19477,17 @@ exports.TextVerticalAlignment = void 0;
19381
19477
  * @internal
19382
19478
  */ _proto._addSprite = function _addSprite(sprite) {
19383
19479
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19480
+ sprite._atlas = this;
19481
+ sprite.isGCIgnored = true;
19384
19482
  };
19385
19483
  /**
19386
19484
  * @override
19387
19485
  */ _proto._onDestroy = function _onDestroy() {
19486
+ var _this = this, sprites = _this._sprites;
19487
+ for(var i = 0, n = sprites.length; i < n; i++){
19488
+ sprites[i].destroy();
19489
+ }
19490
+ sprites.length = 0;
19388
19491
  this._sprites = null;
19389
19492
  this._spriteNamesToIndex = null;
19390
19493
  };
@@ -19485,10 +19588,29 @@ exports.TextVerticalAlignment = void 0;
19485
19588
  };
19486
19589
  /**
19487
19590
  * @override
19591
+ * @internal
19592
+ */ _proto._addRefCount = function _addRefCount(value) {
19593
+ var _this__atlas;
19594
+ RefObject.prototype._addRefCount.call(this, value);
19595
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19596
+ };
19597
+ /**
19598
+ * @override
19599
+ * @internal
19488
19600
  */ _proto._onDestroy = function _onDestroy() {
19489
- if (this._texture) {
19490
- this._texture = null;
19491
- }
19601
+ this._positions.length = 0;
19602
+ this._positions = null;
19603
+ this._uvs.length = 0;
19604
+ this._uvs = null;
19605
+ this._atlasRegion = null;
19606
+ this._atlasRegionOffset = null;
19607
+ this._region = null;
19608
+ this._pivot = null;
19609
+ this._border = null;
19610
+ this._bounds = null;
19611
+ this._atlas = null;
19612
+ this._texture = null;
19613
+ this._updateFlagManager = null;
19492
19614
  };
19493
19615
  _proto._calDefaultSize = function _calDefaultSize() {
19494
19616
  if (this._texture) {
@@ -19591,7 +19713,7 @@ exports.TextVerticalAlignment = void 0;
19591
19713
  key: "width",
19592
19714
  get: /**
19593
19715
  * The width of the sprite (in world coordinates).
19594
- *
19716
+ *
19595
19717
  * @remarks
19596
19718
  * If width is set, return the set value,
19597
19719
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19614,7 +19736,7 @@ exports.TextVerticalAlignment = void 0;
19614
19736
  key: "height",
19615
19737
  get: /**
19616
19738
  * The height of the sprite (in world coordinates).
19617
- *
19739
+ *
19618
19740
  * @remarks
19619
19741
  * If height is set, return the set value,
19620
19742
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19922,17 +20044,6 @@ SlicedSpriteAssembler = __decorate([
19922
20044
  target.drawMode = this._drawMode;
19923
20045
  };
19924
20046
  /**
19925
- * @internal
19926
- */ _proto._onDestroy = function _onDestroy() {
19927
- var _this__sprite;
19928
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19929
- this._color = null;
19930
- this._sprite = null;
19931
- this._assembler = null;
19932
- this._renderData = null;
19933
- Renderer.prototype._onDestroy.call(this);
19934
- };
19935
- /**
19936
20047
  * @override
19937
20048
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19938
20049
  if (this.sprite) {
@@ -19970,6 +20081,20 @@ SlicedSpriteAssembler = __decorate([
19970
20081
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19971
20082
  }
19972
20083
  };
20084
+ /**
20085
+ * @internal
20086
+ */ _proto._onDestroy = function _onDestroy() {
20087
+ Renderer.prototype._onDestroy.call(this);
20088
+ var sprite = this._sprite;
20089
+ if (sprite) {
20090
+ sprite._addRefCount(-1);
20091
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20092
+ }
20093
+ this._color = null;
20094
+ this._sprite = null;
20095
+ this._assembler = null;
20096
+ this._renderData = null;
20097
+ };
19973
20098
  _proto._calDefaultSize = function _calDefaultSize() {
19974
20099
  var sprite = this._sprite;
19975
20100
  if (sprite) {
@@ -20061,9 +20186,13 @@ SlicedSpriteAssembler = __decorate([
20061
20186
  set: function set(value) {
20062
20187
  var lastSprite = this._sprite;
20063
20188
  if (lastSprite !== value) {
20064
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20189
+ if (lastSprite) {
20190
+ lastSprite._addRefCount(-1);
20191
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20192
+ }
20065
20193
  this._dirtyUpdateFlag |= 0x7;
20066
20194
  if (value) {
20195
+ value._addRefCount(1);
20067
20196
  value._updateFlagManager.addListener(this._onSpriteChange);
20068
20197
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20069
20198
  } else {