@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.
package/dist/module.js CHANGED
@@ -2744,9 +2744,11 @@ function ObjectValues(obj) {
2744
2744
  renderTexture
2745
2745
  ];
2746
2746
  for(var i = 0, n = colorTextures.length; i < n; i++){
2747
- if (colorTextures[i]._isDepthTexture) {
2747
+ var colorTexture = colorTextures[i];
2748
+ if (colorTexture._isDepthTexture) {
2748
2749
  throw "Render texture can't use depth format.";
2749
2750
  }
2751
+ colorTexture._addRefCount(1);
2750
2752
  }
2751
2753
  _this._colorTextures = colorTextures;
2752
2754
  } else {
@@ -2757,6 +2759,7 @@ function ObjectValues(obj) {
2757
2759
  throw "Depth texture must use depth format.";
2758
2760
  }
2759
2761
  _this._depthTexture = depth;
2762
+ _this._depthTexture._addRefCount(1);
2760
2763
  }
2761
2764
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
2762
2765
  return _this;
@@ -2785,8 +2788,14 @@ function ObjectValues(obj) {
2785
2788
  /**
2786
2789
  * Destroy render target.
2787
2790
  */ _proto.destroy = function destroy() {
2791
+ var _this__depthTexture;
2788
2792
  this._platformRenderTarget.destroy();
2789
- this._colorTextures.length = 0;
2793
+ var _this = this, colorTextures = _this._colorTextures;
2794
+ for(var i = 0, n = colorTextures.length; i < n; i++){
2795
+ colorTextures[i]._addRefCount(-1);
2796
+ }
2797
+ colorTextures.length = 0;
2798
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
2790
2799
  this._depthTexture = null;
2791
2800
  this._depth = null;
2792
2801
  };
@@ -3232,6 +3241,7 @@ function ObjectValues(obj) {
3232
3241
  var fontAtlas = new FontAtlas(engine);
3233
3242
  var texture = new Texture2D(engine, 256, 256);
3234
3243
  fontAtlas.texture = texture;
3244
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
3235
3245
  this._fontAtlases.push(fontAtlas);
3236
3246
  return fontAtlas;
3237
3247
  };
@@ -8768,6 +8778,7 @@ var DynamicColliderConstraints;
8768
8778
  _proto.cloneTo = function cloneTo(target) {
8769
8779
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8770
8780
  Object.assign(target._macroMap, this._macroMap);
8781
+ var referCount = target._getRefCount();
8771
8782
  var propertyValueMap = this._propertyValueMap;
8772
8783
  var targetPropertyValueMap = target._propertyValueMap;
8773
8784
  var keys = Object.keys(propertyValueMap);
@@ -8779,6 +8790,7 @@ var DynamicColliderConstraints;
8779
8790
  targetPropertyValueMap[k] = property;
8780
8791
  } else if (_instanceof(property, Texture)) {
8781
8792
  targetPropertyValueMap[k] = property;
8793
+ referCount > 0 && property._addRefCount(referCount);
8782
8794
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8783
8795
  targetPropertyValueMap[k] = property.slice();
8784
8796
  } else {
@@ -10523,16 +10535,6 @@ SimpleSpriteAssembler = __decorate([
10523
10535
  }
10524
10536
  var _proto = SpriteMask.prototype;
10525
10537
  /**
10526
- * @override
10527
- * @inheritdoc
10528
- */ _proto._onDestroy = function _onDestroy() {
10529
- var _this__sprite;
10530
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10531
- this._sprite = null;
10532
- this._renderData = null;
10533
- Renderer.prototype._onDestroy.call(this);
10534
- };
10535
- /**
10536
10538
  * @internal
10537
10539
  */ _proto._cloneTo = function _cloneTo(target) {
10538
10540
  Renderer.prototype._cloneTo.call(this, target);
@@ -10572,6 +10574,19 @@ SimpleSpriteAssembler = __decorate([
10572
10574
  context.camera._renderPipeline._allSpriteMasks.add(this);
10573
10575
  this._maskElement = maskElement;
10574
10576
  };
10577
+ /**
10578
+ * @internal
10579
+ * @inheritdoc
10580
+ */ _proto._onDestroy = function _onDestroy() {
10581
+ Renderer.prototype._onDestroy.call(this);
10582
+ var sprite = this._sprite;
10583
+ if (sprite) {
10584
+ sprite._addRefCount(-1);
10585
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10586
+ }
10587
+ this._sprite = null;
10588
+ this._renderData = null;
10589
+ };
10575
10590
  _proto._calDefaultSize = function _calDefaultSize() {
10576
10591
  var sprite = this._sprite;
10577
10592
  if (sprite) {
@@ -10690,9 +10705,13 @@ SimpleSpriteAssembler = __decorate([
10690
10705
  set: function set(value) {
10691
10706
  var lastSprite = this._sprite;
10692
10707
  if (lastSprite !== value) {
10693
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10708
+ if (lastSprite) {
10709
+ lastSprite._addRefCount(-1);
10710
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10711
+ }
10694
10712
  this._dirtyUpdateFlag |= 0x7;
10695
10713
  if (value) {
10714
+ value._addRefCount(1);
10696
10715
  value._updateFlagManager.addListener(this._onSpriteChange);
10697
10716
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10698
10717
  } else {
@@ -11259,10 +11278,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11259
11278
  /**
11260
11279
  * @internal
11261
11280
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11262
- if (this._getRefCount() > 0) {
11263
- var lastBinding = this._vertexBufferBindings[index];
11264
- lastBinding && lastBinding._buffer._addRefCount(-1);
11265
- binding._buffer._addRefCount(1);
11281
+ var referCount = this._getRefCount();
11282
+ if (referCount > 0) {
11283
+ var _this__vertexBufferBindings_index;
11284
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11285
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11266
11286
  }
11267
11287
  this._vertexBufferBindings[index] = binding;
11268
11288
  this._bufferStructChanged = true;
@@ -11276,11 +11296,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11276
11296
  /**
11277
11297
  * @override
11278
11298
  */ _proto._addRefCount = function _addRefCount(value) {
11299
+ var _this__indexBufferBinding;
11279
11300
  RefObject.prototype._addRefCount.call(this, value);
11280
11301
  var vertexBufferBindings = this._vertexBufferBindings;
11281
11302
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11282
11303
  vertexBufferBindings[i]._buffer._addRefCount(value);
11283
11304
  }
11305
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11284
11306
  };
11285
11307
  /**
11286
11308
  * @override
@@ -11300,6 +11322,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11300
11322
  };
11301
11323
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11302
11324
  var lastBinding = this._indexBufferBinding;
11325
+ var referCount = this._getRefCount();
11326
+ if (referCount > 0) {
11327
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11328
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11329
+ }
11303
11330
  if (binding) {
11304
11331
  this._indexBufferBinding = binding;
11305
11332
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -14478,14 +14505,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14478
14505
  _proto._createMesh = function _createMesh(engine, index) {
14479
14506
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14480
14507
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14508
+ mesh.isGCIgnored = true;
14481
14509
  var vertexElements = [];
14482
14510
  var vertexStride = this.createVertexElements(vertexElements);
14483
14511
  // vertices
14484
- this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
14512
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
14513
+ vertexBuffer.isGCIgnored = true;
14485
14514
  // indices
14486
- this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
14487
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14488
- mesh.setIndexBufferBinding(this._indiceBuffers[index], IndexFormat.UInt16);
14515
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
14516
+ indiceBuffer.isGCIgnored = true;
14517
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14518
+ mesh.setIndexBufferBinding(indiceBuffer, IndexFormat.UInt16);
14489
14519
  mesh.setVertexElements(vertexElements);
14490
14520
  return mesh;
14491
14521
  };
@@ -14724,6 +14754,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14724
14754
  var _proto = Sky.prototype;
14725
14755
  /**
14726
14756
  * @internal
14757
+ */ _proto.destroy = function destroy() {
14758
+ this.mesh = null;
14759
+ this.material = null;
14760
+ };
14761
+ /**
14762
+ * @internal
14727
14763
  */ _proto._render = function _render(context) {
14728
14764
  var _this = this, material = _this.material, mesh = _this.mesh;
14729
14765
  if (!material) {
@@ -14762,6 +14798,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14762
14798
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14763
14799
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14764
14800
  };
14801
+ _create_class(Sky, [
14802
+ {
14803
+ key: "material",
14804
+ get: /**
14805
+ * Material of the sky.
14806
+ */ function get() {
14807
+ return this._material;
14808
+ },
14809
+ set: function set(value) {
14810
+ if (this._material !== value) {
14811
+ var _this__material;
14812
+ value == null ? void 0 : value._addRefCount(1);
14813
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14814
+ this._material = value;
14815
+ }
14816
+ }
14817
+ },
14818
+ {
14819
+ key: "mesh",
14820
+ get: /**
14821
+ * Mesh of the sky.
14822
+ */ function get() {
14823
+ return this._mesh;
14824
+ },
14825
+ set: function set(value) {
14826
+ if (this._mesh !== value) {
14827
+ var _this__mesh;
14828
+ value == null ? void 0 : value._addRefCount(1);
14829
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14830
+ this._mesh = value;
14831
+ }
14832
+ }
14833
+ }
14834
+ ]);
14765
14835
  return Sky;
14766
14836
  }();
14767
14837
  (function() {
@@ -14792,11 +14862,28 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14792
14862
  this.sky = new Sky();
14793
14863
  this./** @internal */ _textureFillMode = BackgroundTextureFillMode.AspectFitHeight;
14794
14864
  this._texture = null;
14795
- this._mesh = this._createPlane(_engine);
14865
+ this._initMesh(_engine);
14796
14866
  }
14797
14867
  var _proto = Background.prototype;
14798
14868
  /**
14799
14869
  * @internal
14870
+ */ _proto.destroy = function destroy() {
14871
+ this._mesh._addRefCount(-1);
14872
+ this._mesh = null;
14873
+ this.texture = null;
14874
+ this.solidColor = null;
14875
+ this.sky.destroy();
14876
+ this._engine = null;
14877
+ };
14878
+ /**
14879
+ * @internal
14880
+ * Standalone for CanvasRenderer plugin.
14881
+ */ _proto._initMesh = function _initMesh(engine) {
14882
+ this._mesh = this._createPlane(engine);
14883
+ this._mesh._addRefCount(1);
14884
+ };
14885
+ /**
14886
+ * @internal
14800
14887
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14801
14888
  if (!this._texture) {
14802
14889
  return;
@@ -14865,6 +14952,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14865
14952
  },
14866
14953
  set: function set(value) {
14867
14954
  if (this._texture !== value) {
14955
+ var _this__texture;
14956
+ value == null ? void 0 : value._addRefCount(1);
14957
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14868
14958
  this._texture = value;
14869
14959
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14870
14960
  }
@@ -15377,6 +15467,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15377
15467
  this._rootEntities[0].destroy();
15378
15468
  }
15379
15469
  this._activeCameras.length = 0;
15470
+ this.background.destroy();
15380
15471
  this.shaderData._addRefCount(-1);
15381
15472
  };
15382
15473
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15796,7 +15887,7 @@ ShaderPool.init();
15796
15887
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15797
15888
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15798
15889
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15799
- _this._textDefaultFont.isGCIgnored = false;
15890
+ _this._textDefaultFont.isGCIgnored = true;
15800
15891
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15801
15892
  var magentaPixel = new Uint8Array([
15802
15893
  255,
@@ -15831,6 +15922,7 @@ ShaderPool.init();
15831
15922
  _this._magentaTexture2DArray = magentaTexture2DArray;
15832
15923
  }
15833
15924
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
15925
+ magentaMaterial.isGCIgnored = true;
15834
15926
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15835
15927
  _this._magentaMaterial = magentaMaterial;
15836
15928
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17363,7 +17455,11 @@ var /**
17363
17455
  var height = shadowCascades == ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17364
17456
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17365
17457
  }
17366
- this._renderTargets = null;
17458
+ var renderTargets = this._renderTargets;
17459
+ if (renderTargets) {
17460
+ renderTargets.destroy();
17461
+ this._renderTargets = null;
17462
+ }
17367
17463
  var viewportOffset = this._viewportOffsets;
17368
17464
  var shadowTileResolution1 = this._shadowTileResolution;
17369
17465
  switch(shadowCascades){
@@ -19405,10 +19501,17 @@ var TextVerticalAlignment;
19405
19501
  * @internal
19406
19502
  */ _proto._addSprite = function _addSprite(sprite) {
19407
19503
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19504
+ sprite._atlas = this;
19505
+ sprite.isGCIgnored = true;
19408
19506
  };
19409
19507
  /**
19410
19508
  * @override
19411
19509
  */ _proto._onDestroy = function _onDestroy() {
19510
+ var _this = this, sprites = _this._sprites;
19511
+ for(var i = 0, n = sprites.length; i < n; i++){
19512
+ sprites[i].destroy();
19513
+ }
19514
+ sprites.length = 0;
19412
19515
  this._sprites = null;
19413
19516
  this._spriteNamesToIndex = null;
19414
19517
  };
@@ -19509,10 +19612,29 @@ var TextVerticalAlignment;
19509
19612
  };
19510
19613
  /**
19511
19614
  * @override
19615
+ * @internal
19616
+ */ _proto._addRefCount = function _addRefCount(value) {
19617
+ var _this__atlas;
19618
+ RefObject.prototype._addRefCount.call(this, value);
19619
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19620
+ };
19621
+ /**
19622
+ * @override
19623
+ * @internal
19512
19624
  */ _proto._onDestroy = function _onDestroy() {
19513
- if (this._texture) {
19514
- this._texture = null;
19515
- }
19625
+ this._positions.length = 0;
19626
+ this._positions = null;
19627
+ this._uvs.length = 0;
19628
+ this._uvs = null;
19629
+ this._atlasRegion = null;
19630
+ this._atlasRegionOffset = null;
19631
+ this._region = null;
19632
+ this._pivot = null;
19633
+ this._border = null;
19634
+ this._bounds = null;
19635
+ this._atlas = null;
19636
+ this._texture = null;
19637
+ this._updateFlagManager = null;
19516
19638
  };
19517
19639
  _proto._calDefaultSize = function _calDefaultSize() {
19518
19640
  if (this._texture) {
@@ -19615,7 +19737,7 @@ var TextVerticalAlignment;
19615
19737
  key: "width",
19616
19738
  get: /**
19617
19739
  * The width of the sprite (in world coordinates).
19618
- *
19740
+ *
19619
19741
  * @remarks
19620
19742
  * If width is set, return the set value,
19621
19743
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19638,7 +19760,7 @@ var TextVerticalAlignment;
19638
19760
  key: "height",
19639
19761
  get: /**
19640
19762
  * The height of the sprite (in world coordinates).
19641
- *
19763
+ *
19642
19764
  * @remarks
19643
19765
  * If height is set, return the set value,
19644
19766
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19946,17 +20068,6 @@ SlicedSpriteAssembler = __decorate([
19946
20068
  target.drawMode = this._drawMode;
19947
20069
  };
19948
20070
  /**
19949
- * @internal
19950
- */ _proto._onDestroy = function _onDestroy() {
19951
- var _this__sprite;
19952
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19953
- this._color = null;
19954
- this._sprite = null;
19955
- this._assembler = null;
19956
- this._renderData = null;
19957
- Renderer.prototype._onDestroy.call(this);
19958
- };
19959
- /**
19960
20071
  * @override
19961
20072
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19962
20073
  if (this.sprite) {
@@ -19994,6 +20105,20 @@ SlicedSpriteAssembler = __decorate([
19994
20105
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19995
20106
  }
19996
20107
  };
20108
+ /**
20109
+ * @internal
20110
+ */ _proto._onDestroy = function _onDestroy() {
20111
+ Renderer.prototype._onDestroy.call(this);
20112
+ var sprite = this._sprite;
20113
+ if (sprite) {
20114
+ sprite._addRefCount(-1);
20115
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20116
+ }
20117
+ this._color = null;
20118
+ this._sprite = null;
20119
+ this._assembler = null;
20120
+ this._renderData = null;
20121
+ };
19997
20122
  _proto._calDefaultSize = function _calDefaultSize() {
19998
20123
  var sprite = this._sprite;
19999
20124
  if (sprite) {
@@ -20085,9 +20210,13 @@ SlicedSpriteAssembler = __decorate([
20085
20210
  set: function set(value) {
20086
20211
  var lastSprite = this._sprite;
20087
20212
  if (lastSprite !== value) {
20088
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20213
+ if (lastSprite) {
20214
+ lastSprite._addRefCount(-1);
20215
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20216
+ }
20089
20217
  this._dirtyUpdateFlag |= 0x7;
20090
20218
  if (value) {
20219
+ value._addRefCount(1);
20091
20220
  value._updateFlagManager.addListener(this._onSpriteChange);
20092
20221
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20093
20222
  } else {