@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/module.js CHANGED
@@ -1461,9 +1461,11 @@ var GLCapabilityType;
1461
1461
  renderTexture
1462
1462
  ];
1463
1463
  for(var i = 0, n = colorTextures.length; i < n; i++){
1464
- if (colorTextures[i]._isDepthTexture) {
1464
+ var colorTexture = colorTextures[i];
1465
+ if (colorTexture._isDepthTexture) {
1465
1466
  throw "Render texture can't use depth format.";
1466
1467
  }
1468
+ colorTexture._addRefCount(1);
1467
1469
  }
1468
1470
  _this._colorTextures = colorTextures;
1469
1471
  } else {
@@ -1474,6 +1476,7 @@ var GLCapabilityType;
1474
1476
  throw "Depth texture must use depth format.";
1475
1477
  }
1476
1478
  _this._depthTexture = depth;
1479
+ _this._depthTexture._addRefCount(1);
1477
1480
  }
1478
1481
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1479
1482
  return _this;
@@ -1502,8 +1505,14 @@ var GLCapabilityType;
1502
1505
  /**
1503
1506
  * Destroy render target.
1504
1507
  */ _proto.destroy = function destroy() {
1508
+ var _this__depthTexture;
1505
1509
  this._platformRenderTarget.destroy();
1506
- this._colorTextures.length = 0;
1510
+ var _this = this, colorTextures = _this._colorTextures;
1511
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1512
+ colorTextures[i]._addRefCount(-1);
1513
+ }
1514
+ colorTextures.length = 0;
1515
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
1507
1516
  this._depthTexture = null;
1508
1517
  this._depth = null;
1509
1518
  };
@@ -1949,6 +1958,7 @@ var GLCapabilityType;
1949
1958
  var fontAtlas = new FontAtlas(engine);
1950
1959
  var texture = new Texture2D(engine, 256, 256);
1951
1960
  fontAtlas.texture = texture;
1961
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
1952
1962
  this._fontAtlases.push(fontAtlas);
1953
1963
  return fontAtlas;
1954
1964
  };
@@ -8754,6 +8764,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8754
8764
  _proto.cloneTo = function cloneTo(target) {
8755
8765
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8756
8766
  Object.assign(target._macroMap, this._macroMap);
8767
+ var referCount = target._getRefCount();
8757
8768
  var propertyValueMap = this._propertyValueMap;
8758
8769
  var targetPropertyValueMap = target._propertyValueMap;
8759
8770
  var keys = Object.keys(propertyValueMap);
@@ -8765,6 +8776,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8765
8776
  targetPropertyValueMap[k] = property;
8766
8777
  } else if (_instanceof(property, Texture)) {
8767
8778
  targetPropertyValueMap[k] = property;
8779
+ referCount > 0 && property._addRefCount(referCount);
8768
8780
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8769
8781
  targetPropertyValueMap[k] = property.slice();
8770
8782
  } else {
@@ -10509,16 +10521,6 @@ SimpleSpriteAssembler = __decorate([
10509
10521
  }
10510
10522
  var _proto = SpriteMask.prototype;
10511
10523
  /**
10512
- * @override
10513
- * @inheritdoc
10514
- */ _proto._onDestroy = function _onDestroy() {
10515
- var _this__sprite;
10516
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10517
- this._sprite = null;
10518
- this._renderData = null;
10519
- Renderer.prototype._onDestroy.call(this);
10520
- };
10521
- /**
10522
10524
  * @internal
10523
10525
  */ _proto._cloneTo = function _cloneTo(target) {
10524
10526
  Renderer.prototype._cloneTo.call(this, target);
@@ -10558,6 +10560,19 @@ SimpleSpriteAssembler = __decorate([
10558
10560
  context.camera._renderPipeline._allSpriteMasks.add(this);
10559
10561
  this._maskElement = maskElement;
10560
10562
  };
10563
+ /**
10564
+ * @internal
10565
+ * @inheritdoc
10566
+ */ _proto._onDestroy = function _onDestroy() {
10567
+ Renderer.prototype._onDestroy.call(this);
10568
+ var sprite = this._sprite;
10569
+ if (sprite) {
10570
+ sprite._addRefCount(-1);
10571
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10572
+ }
10573
+ this._sprite = null;
10574
+ this._renderData = null;
10575
+ };
10561
10576
  _proto._calDefaultSize = function _calDefaultSize() {
10562
10577
  var sprite = this._sprite;
10563
10578
  if (sprite) {
@@ -10676,9 +10691,13 @@ SimpleSpriteAssembler = __decorate([
10676
10691
  set: function set(value) {
10677
10692
  var lastSprite = this._sprite;
10678
10693
  if (lastSprite !== value) {
10679
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10694
+ if (lastSprite) {
10695
+ lastSprite._addRefCount(-1);
10696
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10697
+ }
10680
10698
  this._dirtyUpdateFlag |= 0x7;
10681
10699
  if (value) {
10700
+ value._addRefCount(1);
10682
10701
  value._updateFlagManager.addListener(this._onSpriteChange);
10683
10702
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10684
10703
  } else {
@@ -11245,10 +11264,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11245
11264
  /**
11246
11265
  * @internal
11247
11266
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11248
- if (this._getRefCount() > 0) {
11249
- var lastBinding = this._vertexBufferBindings[index];
11250
- lastBinding && lastBinding._buffer._addRefCount(-1);
11251
- binding._buffer._addRefCount(1);
11267
+ var referCount = this._getRefCount();
11268
+ if (referCount > 0) {
11269
+ var _this__vertexBufferBindings_index;
11270
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11271
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11252
11272
  }
11253
11273
  this._vertexBufferBindings[index] = binding;
11254
11274
  this._bufferStructChanged = true;
@@ -11262,11 +11282,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11262
11282
  /**
11263
11283
  * @override
11264
11284
  */ _proto._addRefCount = function _addRefCount(value) {
11285
+ var _this__indexBufferBinding;
11265
11286
  RefObject.prototype._addRefCount.call(this, value);
11266
11287
  var vertexBufferBindings = this._vertexBufferBindings;
11267
11288
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11268
11289
  vertexBufferBindings[i]._buffer._addRefCount(value);
11269
11290
  }
11291
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11270
11292
  };
11271
11293
  /**
11272
11294
  * @override
@@ -11286,6 +11308,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11286
11308
  };
11287
11309
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11288
11310
  var lastBinding = this._indexBufferBinding;
11311
+ var referCount = this._getRefCount();
11312
+ if (referCount > 0) {
11313
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11314
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11315
+ }
11289
11316
  if (binding) {
11290
11317
  this._indexBufferBinding = binding;
11291
11318
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -14464,14 +14491,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14464
14491
  _proto._createMesh = function _createMesh(engine, index) {
14465
14492
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14466
14493
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14494
+ mesh.isGCIgnored = true;
14467
14495
  var vertexElements = [];
14468
14496
  var vertexStride = this.createVertexElements(vertexElements);
14469
14497
  // vertices
14470
- this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
14498
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
14499
+ vertexBuffer.isGCIgnored = true;
14471
14500
  // indices
14472
- this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
14473
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14474
- mesh.setIndexBufferBinding(this._indiceBuffers[index], IndexFormat.UInt16);
14501
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
14502
+ indiceBuffer.isGCIgnored = true;
14503
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14504
+ mesh.setIndexBufferBinding(indiceBuffer, IndexFormat.UInt16);
14475
14505
  mesh.setVertexElements(vertexElements);
14476
14506
  return mesh;
14477
14507
  };
@@ -14710,6 +14740,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14710
14740
  var _proto = Sky.prototype;
14711
14741
  /**
14712
14742
  * @internal
14743
+ */ _proto.destroy = function destroy() {
14744
+ this.mesh = null;
14745
+ this.material = null;
14746
+ };
14747
+ /**
14748
+ * @internal
14713
14749
  */ _proto._render = function _render(context) {
14714
14750
  var _this = this, material = _this.material, mesh = _this.mesh;
14715
14751
  if (!material) {
@@ -14748,6 +14784,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14748
14784
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14749
14785
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14750
14786
  };
14787
+ _create_class(Sky, [
14788
+ {
14789
+ key: "material",
14790
+ get: /**
14791
+ * Material of the sky.
14792
+ */ function get() {
14793
+ return this._material;
14794
+ },
14795
+ set: function set(value) {
14796
+ if (this._material !== value) {
14797
+ var _this__material;
14798
+ value == null ? void 0 : value._addRefCount(1);
14799
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14800
+ this._material = value;
14801
+ }
14802
+ }
14803
+ },
14804
+ {
14805
+ key: "mesh",
14806
+ get: /**
14807
+ * Mesh of the sky.
14808
+ */ function get() {
14809
+ return this._mesh;
14810
+ },
14811
+ set: function set(value) {
14812
+ if (this._mesh !== value) {
14813
+ var _this__mesh;
14814
+ value == null ? void 0 : value._addRefCount(1);
14815
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14816
+ this._mesh = value;
14817
+ }
14818
+ }
14819
+ }
14820
+ ]);
14751
14821
  return Sky;
14752
14822
  }();
14753
14823
  (function() {
@@ -14778,11 +14848,28 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14778
14848
  this.sky = new Sky();
14779
14849
  this./** @internal */ _textureFillMode = BackgroundTextureFillMode.AspectFitHeight;
14780
14850
  this._texture = null;
14781
- this._mesh = this._createPlane(_engine);
14851
+ this._initMesh(_engine);
14782
14852
  }
14783
14853
  var _proto = Background.prototype;
14784
14854
  /**
14785
14855
  * @internal
14856
+ */ _proto.destroy = function destroy() {
14857
+ this._mesh._addRefCount(-1);
14858
+ this._mesh = null;
14859
+ this.texture = null;
14860
+ this.solidColor = null;
14861
+ this.sky.destroy();
14862
+ this._engine = null;
14863
+ };
14864
+ /**
14865
+ * @internal
14866
+ * Standalone for CanvasRenderer plugin.
14867
+ */ _proto._initMesh = function _initMesh(engine) {
14868
+ this._mesh = this._createPlane(engine);
14869
+ this._mesh._addRefCount(1);
14870
+ };
14871
+ /**
14872
+ * @internal
14786
14873
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14787
14874
  if (!this._texture) {
14788
14875
  return;
@@ -14851,6 +14938,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14851
14938
  },
14852
14939
  set: function set(value) {
14853
14940
  if (this._texture !== value) {
14941
+ var _this__texture;
14942
+ value == null ? void 0 : value._addRefCount(1);
14943
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14854
14944
  this._texture = value;
14855
14945
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14856
14946
  }
@@ -15354,6 +15444,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15354
15444
  this._rootEntities[0].destroy();
15355
15445
  }
15356
15446
  this._activeCameras.length = 0;
15447
+ this.background.destroy();
15357
15448
  this.shaderData._addRefCount(-1);
15358
15449
  };
15359
15450
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15767,7 +15858,7 @@ ShaderPool.init();
15767
15858
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15768
15859
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15769
15860
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15770
- _this._textDefaultFont.isGCIgnored = false;
15861
+ _this._textDefaultFont.isGCIgnored = true;
15771
15862
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15772
15863
  var magentaPixel = new Uint8Array([
15773
15864
  255,
@@ -15802,6 +15893,7 @@ ShaderPool.init();
15802
15893
  _this._magentaTexture2DArray = magentaTexture2DArray;
15803
15894
  }
15804
15895
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
15896
+ magentaMaterial.isGCIgnored = true;
15805
15897
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15806
15898
  _this._magentaMaterial = magentaMaterial;
15807
15899
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17334,7 +17426,11 @@ var /**
17334
17426
  var height = shadowCascades == ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17335
17427
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17336
17428
  }
17337
- this._renderTargets = null;
17429
+ var renderTargets = this._renderTargets;
17430
+ if (renderTargets) {
17431
+ renderTargets.destroy();
17432
+ this._renderTargets = null;
17433
+ }
17338
17434
  var viewportOffset = this._viewportOffsets;
17339
17435
  var shadowTileResolution1 = this._shadowTileResolution;
17340
17436
  switch(shadowCascades){
@@ -19376,10 +19472,17 @@ var TextVerticalAlignment;
19376
19472
  * @internal
19377
19473
  */ _proto._addSprite = function _addSprite(sprite) {
19378
19474
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19475
+ sprite._atlas = this;
19476
+ sprite.isGCIgnored = true;
19379
19477
  };
19380
19478
  /**
19381
19479
  * @override
19382
19480
  */ _proto._onDestroy = function _onDestroy() {
19481
+ var _this = this, sprites = _this._sprites;
19482
+ for(var i = 0, n = sprites.length; i < n; i++){
19483
+ sprites[i].destroy();
19484
+ }
19485
+ sprites.length = 0;
19383
19486
  this._sprites = null;
19384
19487
  this._spriteNamesToIndex = null;
19385
19488
  };
@@ -19480,10 +19583,29 @@ var TextVerticalAlignment;
19480
19583
  };
19481
19584
  /**
19482
19585
  * @override
19586
+ * @internal
19587
+ */ _proto._addRefCount = function _addRefCount(value) {
19588
+ var _this__atlas;
19589
+ RefObject.prototype._addRefCount.call(this, value);
19590
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19591
+ };
19592
+ /**
19593
+ * @override
19594
+ * @internal
19483
19595
  */ _proto._onDestroy = function _onDestroy() {
19484
- if (this._texture) {
19485
- this._texture = null;
19486
- }
19596
+ this._positions.length = 0;
19597
+ this._positions = null;
19598
+ this._uvs.length = 0;
19599
+ this._uvs = null;
19600
+ this._atlasRegion = null;
19601
+ this._atlasRegionOffset = null;
19602
+ this._region = null;
19603
+ this._pivot = null;
19604
+ this._border = null;
19605
+ this._bounds = null;
19606
+ this._atlas = null;
19607
+ this._texture = null;
19608
+ this._updateFlagManager = null;
19487
19609
  };
19488
19610
  _proto._calDefaultSize = function _calDefaultSize() {
19489
19611
  if (this._texture) {
@@ -19586,7 +19708,7 @@ var TextVerticalAlignment;
19586
19708
  key: "width",
19587
19709
  get: /**
19588
19710
  * The width of the sprite (in world coordinates).
19589
- *
19711
+ *
19590
19712
  * @remarks
19591
19713
  * If width is set, return the set value,
19592
19714
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19609,7 +19731,7 @@ var TextVerticalAlignment;
19609
19731
  key: "height",
19610
19732
  get: /**
19611
19733
  * The height of the sprite (in world coordinates).
19612
- *
19734
+ *
19613
19735
  * @remarks
19614
19736
  * If height is set, return the set value,
19615
19737
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19917,17 +20039,6 @@ SlicedSpriteAssembler = __decorate([
19917
20039
  target.drawMode = this._drawMode;
19918
20040
  };
19919
20041
  /**
19920
- * @internal
19921
- */ _proto._onDestroy = function _onDestroy() {
19922
- var _this__sprite;
19923
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19924
- this._color = null;
19925
- this._sprite = null;
19926
- this._assembler = null;
19927
- this._renderData = null;
19928
- Renderer.prototype._onDestroy.call(this);
19929
- };
19930
- /**
19931
20042
  * @override
19932
20043
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19933
20044
  if (this.sprite) {
@@ -19965,6 +20076,20 @@ SlicedSpriteAssembler = __decorate([
19965
20076
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19966
20077
  }
19967
20078
  };
20079
+ /**
20080
+ * @internal
20081
+ */ _proto._onDestroy = function _onDestroy() {
20082
+ Renderer.prototype._onDestroy.call(this);
20083
+ var sprite = this._sprite;
20084
+ if (sprite) {
20085
+ sprite._addRefCount(-1);
20086
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20087
+ }
20088
+ this._color = null;
20089
+ this._sprite = null;
20090
+ this._assembler = null;
20091
+ this._renderData = null;
20092
+ };
19968
20093
  _proto._calDefaultSize = function _calDefaultSize() {
19969
20094
  var sprite = this._sprite;
19970
20095
  if (sprite) {
@@ -20056,9 +20181,13 @@ SlicedSpriteAssembler = __decorate([
20056
20181
  set: function set(value) {
20057
20182
  var lastSprite = this._sprite;
20058
20183
  if (lastSprite !== value) {
20059
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20184
+ if (lastSprite) {
20185
+ lastSprite._addRefCount(-1);
20186
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20187
+ }
20060
20188
  this._dirtyUpdateFlag |= 0x7;
20061
20189
  if (value) {
20190
+ value._addRefCount(1);
20062
20191
  value._updateFlagManager.addListener(this._onSpriteChange);
20063
20192
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20064
20193
  } else {