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