@galacean/engine-core 0.0.0-experimental-0.9-plus.6 → 0.0.0-experimental-0.9-plus.7

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.
@@ -2749,9 +2749,11 @@ function ObjectValues(obj) {
2749
2749
  renderTexture
2750
2750
  ];
2751
2751
  for(var i = 0, n = colorTextures.length; i < n; i++){
2752
- if (colorTextures[i]._isDepthTexture) {
2752
+ var colorTexture = colorTextures[i];
2753
+ if (colorTexture._isDepthTexture) {
2753
2754
  throw "Render texture can't use depth format.";
2754
2755
  }
2756
+ colorTexture._addRefCount(1);
2755
2757
  }
2756
2758
  _this._colorTextures = colorTextures;
2757
2759
  } else {
@@ -2762,6 +2764,7 @@ function ObjectValues(obj) {
2762
2764
  throw "Depth texture must use depth format.";
2763
2765
  }
2764
2766
  _this._depthTexture = depth;
2767
+ _this._depthTexture._addRefCount(1);
2765
2768
  }
2766
2769
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
2767
2770
  return _this;
@@ -2790,8 +2793,14 @@ function ObjectValues(obj) {
2790
2793
  /**
2791
2794
  * Destroy render target.
2792
2795
  */ _proto.destroy = function destroy() {
2796
+ var _this__depthTexture;
2793
2797
  this._platformRenderTarget.destroy();
2794
- this._colorTextures.length = 0;
2798
+ var _this = this, colorTextures = _this._colorTextures;
2799
+ for(var i = 0, n = colorTextures.length; i < n; i++){
2800
+ colorTextures[i]._addRefCount(-1);
2801
+ }
2802
+ colorTextures.length = 0;
2803
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
2795
2804
  this._depthTexture = null;
2796
2805
  this._depth = null;
2797
2806
  };
@@ -3237,6 +3246,7 @@ function ObjectValues(obj) {
3237
3246
  var fontAtlas = new FontAtlas(engine);
3238
3247
  var texture = new Texture2D(engine, 256, 256);
3239
3248
  fontAtlas.texture = texture;
3249
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
3240
3250
  this._fontAtlases.push(fontAtlas);
3241
3251
  return fontAtlas;
3242
3252
  };
@@ -8773,6 +8783,7 @@ exports.DynamicColliderConstraints = void 0;
8773
8783
  _proto.cloneTo = function cloneTo(target) {
8774
8784
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8775
8785
  Object.assign(target._macroMap, this._macroMap);
8786
+ var referCount = target._getRefCount();
8776
8787
  var propertyValueMap = this._propertyValueMap;
8777
8788
  var targetPropertyValueMap = target._propertyValueMap;
8778
8789
  var keys = Object.keys(propertyValueMap);
@@ -8784,6 +8795,7 @@ exports.DynamicColliderConstraints = void 0;
8784
8795
  targetPropertyValueMap[k] = property;
8785
8796
  } else if (_instanceof(property, Texture)) {
8786
8797
  targetPropertyValueMap[k] = property;
8798
+ referCount > 0 && property._addRefCount(referCount);
8787
8799
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8788
8800
  targetPropertyValueMap[k] = property.slice();
8789
8801
  } else {
@@ -10528,16 +10540,6 @@ SimpleSpriteAssembler = __decorate([
10528
10540
  }
10529
10541
  var _proto = SpriteMask.prototype;
10530
10542
  /**
10531
- * @override
10532
- * @inheritdoc
10533
- */ _proto._onDestroy = function _onDestroy() {
10534
- var _this__sprite;
10535
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10536
- this._sprite = null;
10537
- this._renderData = null;
10538
- Renderer.prototype._onDestroy.call(this);
10539
- };
10540
- /**
10541
10543
  * @internal
10542
10544
  */ _proto._cloneTo = function _cloneTo(target) {
10543
10545
  Renderer.prototype._cloneTo.call(this, target);
@@ -10577,6 +10579,19 @@ SimpleSpriteAssembler = __decorate([
10577
10579
  context.camera._renderPipeline._allSpriteMasks.add(this);
10578
10580
  this._maskElement = maskElement;
10579
10581
  };
10582
+ /**
10583
+ * @internal
10584
+ * @inheritdoc
10585
+ */ _proto._onDestroy = function _onDestroy() {
10586
+ Renderer.prototype._onDestroy.call(this);
10587
+ var sprite = this._sprite;
10588
+ if (sprite) {
10589
+ sprite._addRefCount(-1);
10590
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10591
+ }
10592
+ this._sprite = null;
10593
+ this._renderData = null;
10594
+ };
10580
10595
  _proto._calDefaultSize = function _calDefaultSize() {
10581
10596
  var sprite = this._sprite;
10582
10597
  if (sprite) {
@@ -10695,9 +10710,13 @@ SimpleSpriteAssembler = __decorate([
10695
10710
  set: function set(value) {
10696
10711
  var lastSprite = this._sprite;
10697
10712
  if (lastSprite !== value) {
10698
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10713
+ if (lastSprite) {
10714
+ lastSprite._addRefCount(-1);
10715
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10716
+ }
10699
10717
  this._dirtyUpdateFlag |= 0x7;
10700
10718
  if (value) {
10719
+ value._addRefCount(1);
10701
10720
  value._updateFlagManager.addListener(this._onSpriteChange);
10702
10721
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10703
10722
  } else {
@@ -11264,10 +11283,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11264
11283
  /**
11265
11284
  * @internal
11266
11285
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11267
- if (this._getRefCount() > 0) {
11268
- var lastBinding = this._vertexBufferBindings[index];
11269
- lastBinding && lastBinding._buffer._addRefCount(-1);
11270
- binding._buffer._addRefCount(1);
11286
+ var referCount = this._getRefCount();
11287
+ if (referCount > 0) {
11288
+ var _this__vertexBufferBindings_index;
11289
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11290
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11271
11291
  }
11272
11292
  this._vertexBufferBindings[index] = binding;
11273
11293
  this._bufferStructChanged = true;
@@ -11281,11 +11301,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11281
11301
  /**
11282
11302
  * @override
11283
11303
  */ _proto._addRefCount = function _addRefCount(value) {
11304
+ var _this__indexBufferBinding;
11284
11305
  RefObject.prototype._addRefCount.call(this, value);
11285
11306
  var vertexBufferBindings = this._vertexBufferBindings;
11286
11307
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11287
11308
  vertexBufferBindings[i]._buffer._addRefCount(value);
11288
11309
  }
11310
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11289
11311
  };
11290
11312
  /**
11291
11313
  * @override
@@ -11305,6 +11327,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11305
11327
  };
11306
11328
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11307
11329
  var lastBinding = this._indexBufferBinding;
11330
+ var referCount = this._getRefCount();
11331
+ if (referCount > 0) {
11332
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11333
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11334
+ }
11308
11335
  if (binding) {
11309
11336
  this._indexBufferBinding = binding;
11310
11337
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -14483,14 +14510,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14483
14510
  _proto._createMesh = function _createMesh(engine, index) {
14484
14511
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14485
14512
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14513
+ mesh.isGCIgnored = true;
14486
14514
  var vertexElements = [];
14487
14515
  var vertexStride = this.createVertexElements(vertexElements);
14488
14516
  // vertices
14489
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14517
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14518
+ vertexBuffer.isGCIgnored = true;
14490
14519
  // indices
14491
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14492
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14493
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
14520
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14521
+ indiceBuffer.isGCIgnored = true;
14522
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14523
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
14494
14524
  mesh.setVertexElements(vertexElements);
14495
14525
  return mesh;
14496
14526
  };
@@ -14729,6 +14759,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14729
14759
  var _proto = Sky.prototype;
14730
14760
  /**
14731
14761
  * @internal
14762
+ */ _proto.destroy = function destroy() {
14763
+ this.mesh = null;
14764
+ this.material = null;
14765
+ };
14766
+ /**
14767
+ * @internal
14732
14768
  */ _proto._render = function _render(context) {
14733
14769
  var _this = this, material = _this.material, mesh = _this.mesh;
14734
14770
  if (!material) {
@@ -14767,6 +14803,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14767
14803
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14768
14804
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14769
14805
  };
14806
+ _create_class(Sky, [
14807
+ {
14808
+ key: "material",
14809
+ get: /**
14810
+ * Material of the sky.
14811
+ */ function get() {
14812
+ return this._material;
14813
+ },
14814
+ set: function set(value) {
14815
+ if (this._material !== value) {
14816
+ var _this__material;
14817
+ value == null ? void 0 : value._addRefCount(1);
14818
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14819
+ this._material = value;
14820
+ }
14821
+ }
14822
+ },
14823
+ {
14824
+ key: "mesh",
14825
+ get: /**
14826
+ * Mesh of the sky.
14827
+ */ function get() {
14828
+ return this._mesh;
14829
+ },
14830
+ set: function set(value) {
14831
+ if (this._mesh !== value) {
14832
+ var _this__mesh;
14833
+ value == null ? void 0 : value._addRefCount(1);
14834
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14835
+ this._mesh = value;
14836
+ }
14837
+ }
14838
+ }
14839
+ ]);
14770
14840
  return Sky;
14771
14841
  }();
14772
14842
  (function() {
@@ -14797,11 +14867,28 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14797
14867
  this.sky = new Sky();
14798
14868
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
14799
14869
  this._texture = null;
14800
- this._mesh = this._createPlane(_engine);
14870
+ this._initMesh(_engine);
14801
14871
  }
14802
14872
  var _proto = Background.prototype;
14803
14873
  /**
14804
14874
  * @internal
14875
+ */ _proto.destroy = function destroy() {
14876
+ this._mesh._addRefCount(-1);
14877
+ this._mesh = null;
14878
+ this.texture = null;
14879
+ this.solidColor = null;
14880
+ this.sky.destroy();
14881
+ this._engine = null;
14882
+ };
14883
+ /**
14884
+ * @internal
14885
+ * Standalone for CanvasRenderer plugin.
14886
+ */ _proto._initMesh = function _initMesh(engine) {
14887
+ this._mesh = this._createPlane(engine);
14888
+ this._mesh._addRefCount(1);
14889
+ };
14890
+ /**
14891
+ * @internal
14805
14892
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14806
14893
  if (!this._texture) {
14807
14894
  return;
@@ -14870,6 +14957,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14870
14957
  },
14871
14958
  set: function set(value) {
14872
14959
  if (this._texture !== value) {
14960
+ var _this__texture;
14961
+ value == null ? void 0 : value._addRefCount(1);
14962
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14873
14963
  this._texture = value;
14874
14964
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14875
14965
  }
@@ -15382,6 +15472,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15382
15472
  this._rootEntities[0].destroy();
15383
15473
  }
15384
15474
  this._activeCameras.length = 0;
15475
+ this.background.destroy();
15385
15476
  this.shaderData._addRefCount(-1);
15386
15477
  };
15387
15478
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15801,7 +15892,7 @@ ShaderPool.init();
15801
15892
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15802
15893
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15803
15894
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15804
- _this._textDefaultFont.isGCIgnored = false;
15895
+ _this._textDefaultFont.isGCIgnored = true;
15805
15896
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15806
15897
  var magentaPixel = new Uint8Array([
15807
15898
  255,
@@ -15836,6 +15927,7 @@ ShaderPool.init();
15836
15927
  _this._magentaTexture2DArray = magentaTexture2DArray;
15837
15928
  }
15838
15929
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
15930
+ magentaMaterial.isGCIgnored = true;
15839
15931
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15840
15932
  _this._magentaMaterial = magentaMaterial;
15841
15933
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17368,7 +17460,11 @@ var /**
17368
17460
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17369
17461
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17370
17462
  }
17371
- this._renderTargets = null;
17463
+ var renderTargets = this._renderTargets;
17464
+ if (renderTargets) {
17465
+ renderTargets.destroy();
17466
+ this._renderTargets = null;
17467
+ }
17372
17468
  var viewportOffset = this._viewportOffsets;
17373
17469
  var shadowTileResolution1 = this._shadowTileResolution;
17374
17470
  switch(shadowCascades){
@@ -19410,10 +19506,17 @@ exports.TextVerticalAlignment = void 0;
19410
19506
  * @internal
19411
19507
  */ _proto._addSprite = function _addSprite(sprite) {
19412
19508
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19509
+ sprite._atlas = this;
19510
+ sprite.isGCIgnored = true;
19413
19511
  };
19414
19512
  /**
19415
19513
  * @override
19416
19514
  */ _proto._onDestroy = function _onDestroy() {
19515
+ var _this = this, sprites = _this._sprites;
19516
+ for(var i = 0, n = sprites.length; i < n; i++){
19517
+ sprites[i].destroy();
19518
+ }
19519
+ sprites.length = 0;
19417
19520
  this._sprites = null;
19418
19521
  this._spriteNamesToIndex = null;
19419
19522
  };
@@ -19514,10 +19617,29 @@ exports.TextVerticalAlignment = void 0;
19514
19617
  };
19515
19618
  /**
19516
19619
  * @override
19620
+ * @internal
19621
+ */ _proto._addRefCount = function _addRefCount(value) {
19622
+ var _this__atlas;
19623
+ RefObject.prototype._addRefCount.call(this, value);
19624
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19625
+ };
19626
+ /**
19627
+ * @override
19628
+ * @internal
19517
19629
  */ _proto._onDestroy = function _onDestroy() {
19518
- if (this._texture) {
19519
- this._texture = null;
19520
- }
19630
+ this._positions.length = 0;
19631
+ this._positions = null;
19632
+ this._uvs.length = 0;
19633
+ this._uvs = null;
19634
+ this._atlasRegion = null;
19635
+ this._atlasRegionOffset = null;
19636
+ this._region = null;
19637
+ this._pivot = null;
19638
+ this._border = null;
19639
+ this._bounds = null;
19640
+ this._atlas = null;
19641
+ this._texture = null;
19642
+ this._updateFlagManager = null;
19521
19643
  };
19522
19644
  _proto._calDefaultSize = function _calDefaultSize() {
19523
19645
  if (this._texture) {
@@ -19620,7 +19742,7 @@ exports.TextVerticalAlignment = void 0;
19620
19742
  key: "width",
19621
19743
  get: /**
19622
19744
  * The width of the sprite (in world coordinates).
19623
- *
19745
+ *
19624
19746
  * @remarks
19625
19747
  * If width is set, return the set value,
19626
19748
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19643,7 +19765,7 @@ exports.TextVerticalAlignment = void 0;
19643
19765
  key: "height",
19644
19766
  get: /**
19645
19767
  * The height of the sprite (in world coordinates).
19646
- *
19768
+ *
19647
19769
  * @remarks
19648
19770
  * If height is set, return the set value,
19649
19771
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19951,17 +20073,6 @@ SlicedSpriteAssembler = __decorate([
19951
20073
  target.drawMode = this._drawMode;
19952
20074
  };
19953
20075
  /**
19954
- * @internal
19955
- */ _proto._onDestroy = function _onDestroy() {
19956
- var _this__sprite;
19957
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19958
- this._color = null;
19959
- this._sprite = null;
19960
- this._assembler = null;
19961
- this._renderData = null;
19962
- Renderer.prototype._onDestroy.call(this);
19963
- };
19964
- /**
19965
20076
  * @override
19966
20077
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19967
20078
  if (this.sprite) {
@@ -19999,6 +20110,20 @@ SlicedSpriteAssembler = __decorate([
19999
20110
  context.camera._renderPipeline.pushPrimitive(spriteElement);
20000
20111
  }
20001
20112
  };
20113
+ /**
20114
+ * @internal
20115
+ */ _proto._onDestroy = function _onDestroy() {
20116
+ Renderer.prototype._onDestroy.call(this);
20117
+ var sprite = this._sprite;
20118
+ if (sprite) {
20119
+ sprite._addRefCount(-1);
20120
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20121
+ }
20122
+ this._color = null;
20123
+ this._sprite = null;
20124
+ this._assembler = null;
20125
+ this._renderData = null;
20126
+ };
20002
20127
  _proto._calDefaultSize = function _calDefaultSize() {
20003
20128
  var sprite = this._sprite;
20004
20129
  if (sprite) {
@@ -20090,9 +20215,13 @@ SlicedSpriteAssembler = __decorate([
20090
20215
  set: function set(value) {
20091
20216
  var lastSprite = this._sprite;
20092
20217
  if (lastSprite !== value) {
20093
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20218
+ if (lastSprite) {
20219
+ lastSprite._addRefCount(-1);
20220
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20221
+ }
20094
20222
  this._dirtyUpdateFlag |= 0x7;
20095
20223
  if (value) {
20224
+ value._addRefCount(1);
20096
20225
  value._updateFlagManager.addListener(this._onSpriteChange);
20097
20226
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20098
20227
  } else {