@galacean/engine 0.0.0-experimental-2.0-game.15 → 0.0.0-experimental-2.0-game.16

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/browser.js CHANGED
@@ -9624,6 +9624,18 @@
9624
9624
  this.subChunk = subChunk;
9625
9625
  this.instancedRenderers.length = 0;
9626
9626
  };
9627
+ /**
9628
+ * @internal
9629
+ * Copy identity fields from `source` and reset per-queue batch state, so the same
9630
+ * logical element can live in multiple queues (e.g. an Opaque + Transparent multi-pass
9631
+ * material) without one queue's batching corrupting another's `instancedRenderers`.
9632
+ */ _proto._cloneFrom = function _cloneFrom(source) {
9633
+ this.set(source.component, source.material, source.primitive, source.subPrimitive, source.texture, source.subChunk);
9634
+ this.priority = source.priority;
9635
+ this.distanceForSort = source.distanceForSort;
9636
+ this.subShader = source.subShader;
9637
+ this.shaderData = source.shaderData;
9638
+ };
9627
9639
  _proto.dispose = function dispose() {
9628
9640
  this.component = null;
9629
9641
  this.material = null;
@@ -10596,7 +10608,7 @@
10596
10608
  _inherits$2(Transform, Component);
10597
10609
  function Transform(entity) {
10598
10610
  var _this;
10599
- _this = Component.call(this, entity) || this, _this._position = new Vector3(), _this._rotation = new Vector3(), _this._rotationQuaternion = new Quaternion(), _this._scale = new Vector3(1, 1, 1), _this._localUniformScaling = true, _this._worldPosition = new Vector3(), _this._worldRotation = new Vector3(), _this._worldRotationQuaternion = new Quaternion(), _this._worldUniformScaling = true, _this._lossyWorldScale = new Vector3(1, 1, 1), _this._localMatrix = new Matrix(), _this._worldMatrix = new Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 510;
10611
+ _this = Component.call(this, entity) || this, _this._position = new Vector3(), _this._rotation = new Vector3(), _this._rotationQuaternion = new Quaternion(), _this._scale = new Vector3(1, 1, 1), _this._localUniformScaling = true, _this._worldPosition = new Vector3(), _this._worldRotation = new Vector3(), _this._worldRotationQuaternion = new Quaternion(), _this._worldUniformScaling = true, _this._lossyWorldScale = new Vector3(1, 1, 1), _this._localMatrix = new Matrix(), _this._worldMatrix = new Matrix(), _this._worldForward = null, _this._worldRight = null, _this._worldUp = null, _this._frontFaceInvert = false, _this._isParentDirty = true, _this._parentTransformCache = null, _this._dirtyFlag = 2558;
10600
10612
  _this._onPositionChanged = _this._onPositionChanged.bind(_this);
10601
10613
  _this._onWorldPositionChanged = _this._onWorldPositionChanged.bind(_this);
10602
10614
  _this._onRotationChanged = _this._onRotationChanged.bind(_this);
@@ -10754,7 +10766,7 @@
10754
10766
  // `_getParentTransform` was ever called while their ancestor chain was
10755
10767
  // partially constructed during clone/instantiate). Force them to
10756
10768
  // re-resolve the parent transform on next access.
10757
- this._propagateReparentDirty(444);
10769
+ this._propagateReparentDirty(2492);
10758
10770
  };
10759
10771
  _proto._propagateReparentDirty = function _propagateReparentDirty(flags) {
10760
10772
  this._worldAssociatedChange(flags);
@@ -10770,11 +10782,16 @@
10770
10782
  /**
10771
10783
  * @internal
10772
10784
  */ _proto._isFrontFaceInvert = function _isFrontFaceInvert() {
10773
- var scale = this.lossyWorldScale;
10774
- var isInvert = scale.x < 0;
10775
- scale.y < 0 && (isInvert = !isInvert);
10776
- scale.z < 0 && (isInvert = !isInvert);
10777
- return isInvert;
10785
+ if (this._isContainDirtyFlag(2048)) {
10786
+ var s = this._scale;
10787
+ var invert = s.x < 0;
10788
+ s.y < 0 && (invert = !invert);
10789
+ s.z < 0 && (invert = !invert);
10790
+ var parent = this._getParentTransform();
10791
+ this._frontFaceInvert = parent ? invert !== parent._isFrontFaceInvert() : invert;
10792
+ this._setDirtyFlagFalse(2048);
10793
+ }
10794
+ return this._frontFaceInvert;
10778
10795
  };
10779
10796
  /**
10780
10797
  * @internal
@@ -10797,7 +10814,7 @@
10797
10814
  // the computed value. After this _cloneTo writes new local values, those world-derived caches are stale,
10798
10815
  // so re-dirty them and notify listeners (Collider._updateFlag etc.) so subsequent reads recompute correctly.
10799
10816
  target._setDirtyFlagTrue(2 | 64);
10800
- target._worldAssociatedChange(444);
10817
+ target._worldAssociatedChange(2492);
10801
10818
  };
10802
10819
  _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
10803
10820
  this._setDirtyFlagFalse(64);
@@ -10880,10 +10897,10 @@
10880
10897
  */ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
10881
10898
  var parent = this._getParentTransform();
10882
10899
  var parentWorldUniformScaling = parent ? parent._getWorldUniformScaling() : true;
10883
- var flags = parentWorldUniformScaling ? 152 : 184;
10900
+ var flags = parentWorldUniformScaling ? 152 : 2232;
10884
10901
  if (!this._isContainDirtyFlags(flags)) {
10885
10902
  this._worldAssociatedChange(flags);
10886
- flags = this._getWorldUniformScaling() ? 156 : 188;
10903
+ flags = this._getWorldUniformScaling() ? 156 : 2236;
10887
10904
  var children = this._entity._children;
10888
10905
  for(var i = 0, n = children.length; i < n; i++){
10889
10906
  var _children_i_transform;
@@ -10902,7 +10919,7 @@
10902
10919
  */ _proto._updateWorldPositionAndRotationFlag = function _updateWorldPositionAndRotationFlag(flags) {
10903
10920
  if (!this._isContainDirtyFlags(flags)) {
10904
10921
  this._worldAssociatedChange(flags);
10905
- flags = this._getWorldUniformScaling() ? 156 : 188;
10922
+ flags = this._getWorldUniformScaling() ? 156 : 2236;
10906
10923
  var children = this._entity._children;
10907
10924
  for(var i = 0, n = children.length; i < n; i++){
10908
10925
  var _children_i_transform;
@@ -11024,9 +11041,9 @@
11024
11041
  var localUniformScaling = x == y && y == z;
11025
11042
  if (this._localUniformScaling !== localUniformScaling) {
11026
11043
  this._localUniformScaling = localUniformScaling;
11027
- this._updateWorldScaleFlag(416);
11044
+ this._updateWorldScaleFlag(2464);
11028
11045
  } else {
11029
- this._updateWorldScaleFlag(160);
11046
+ this._updateWorldScaleFlag(2208);
11030
11047
  }
11031
11048
  };
11032
11049
  _proto._getWorldUniformScaling = function _getWorldUniformScaling() {
@@ -11264,9 +11281,9 @@
11264
11281
  var localUniformScaling = scale.x === scale.y && scale.y === scale.z;
11265
11282
  if (this._localUniformScaling !== localUniformScaling) {
11266
11283
  this._localUniformScaling = localUniformScaling;
11267
- this._updateAllWorldFlag(444);
11284
+ this._updateAllWorldFlag(2492);
11268
11285
  } else {
11269
- this._updateAllWorldFlag(188);
11286
+ this._updateAllWorldFlag(2236);
11270
11287
  }
11271
11288
  }
11272
11289
  },
@@ -11392,6 +11409,9 @@
11392
11409
  __decorate$1([
11393
11410
  ignoreClone
11394
11411
  ], Transform.prototype, "_worldUp", void 0);
11412
+ __decorate$1([
11413
+ ignoreClone
11414
+ ], Transform.prototype, "_frontFaceInvert", void 0);
11395
11415
  __decorate$1([
11396
11416
  ignoreClone
11397
11417
  ], Transform.prototype, "_isParentDirty", void 0);
@@ -11433,16 +11453,18 @@
11433
11453
  /** This is an internal flag used to assist in determining the dispatch
11434
11454
  * of world scaling dirty flags in the case of non-uniform scaling.
11435
11455
  */ TransformModifyFlags[TransformModifyFlags["IsWorldUniformScaling"] = 256] = "IsWorldUniformScaling";
11456
+ // Note: 0x200 (UITransformModifyFlags.Size) and 0x400 (Pivot) are reserved by UITransform — do not reuse.
11457
+ TransformModifyFlags[TransformModifyFlags["WorldFrontFaceInvert"] = 2048] = "WorldFrontFaceInvert";
11436
11458
  /** WorldMatrix | WorldPosition */ TransformModifyFlags[TransformModifyFlags["WmWp"] = 132] = "WmWp";
11437
11459
  /** WorldMatrix | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWeWq"] = 152] = "WmWeWq";
11438
- /** WorldMatrix | WorldEuler | WorldQuat | WorldScale*/ TransformModifyFlags[TransformModifyFlags["WmWeWqWs"] = 184] = "WmWeWqWs";
11460
+ /** WorldMatrix | WorldEuler | WorldQuat | WorldScale | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["WmWeWqWs"] = 2232] = "WmWeWqWs";
11439
11461
  /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat */ TransformModifyFlags[TransformModifyFlags["WmWpWeWq"] = 156] = "WmWpWeWq";
11440
- /** WorldMatrix | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWs"] = 160] = "WmWs";
11441
- /** WorldMatrix | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWsWus"] = 416] = "WmWsWus";
11442
- /** WorldMatrix | WorldPosition | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWs"] = 164] = "WmWpWs";
11443
- /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWs"] = 188] = "WmWpWeWqWs";
11444
- /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWsWus"] = 444] = "WmWpWeWqWsWus";
11445
- /** LocalQuat | LocalMatrix | WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling */ TransformModifyFlags[TransformModifyFlags["LqLmWmWpWeWqWsWus"] = 510] = "LqLmWmWpWeWqWsWus";
11462
+ /** WorldMatrix | WorldScale | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["WmWs"] = 2208] = "WmWs";
11463
+ /** WorldMatrix | WorldScale | WorldUniformScaling | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["WmWsWus"] = 2464] = "WmWsWus";
11464
+ /** WorldMatrix | WorldPosition | WorldScale | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["WmWpWs"] = 2212] = "WmWpWs";
11465
+ /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWs"] = 2236] = "WmWpWeWqWs";
11466
+ /** WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["WmWpWeWqWsWus"] = 2492] = "WmWpWeWqWsWus";
11467
+ /** LocalQuat | LocalMatrix | WorldMatrix | WorldPosition | WorldEuler | WorldQuat | WorldScale | WorldUniformScaling | WorldFrontFaceInvert */ TransformModifyFlags[TransformModifyFlags["LqLmWmWpWeWqWsWus"] = 2558] = "LqLmWmWpWeWqWsWus";
11446
11468
  return TransformModifyFlags;
11447
11469
  }({});
11448
11470
  /**
@@ -11490,6 +11512,12 @@
11490
11512
  function ShaderData(group) {
11491
11513
  /** @internal */ this._propertyValueMap = Object.create(null);
11492
11514
  /** @internal */ this._macroCollection = new ShaderMacroCollection();
11515
+ /**
11516
+ * @internal
11517
+ * Sorted (ascending) property ids of renderer-group samplers and arrays. These values
11518
+ * can't differ across instances inside an instanced draw call — `_canBatch` uses this
11519
+ * list to refuse batching renderers that would disagree on what to bind
11520
+ */ this._instanceBatchFields = [];
11493
11521
  this._macroMap = Object.create(null);
11494
11522
  this._refCount = 0;
11495
11523
  this._group = group;
@@ -11708,7 +11736,52 @@
11708
11736
  throw "Shader property " + property.name + " has been used as " + ShaderPropertyType[property._type] + " type.";
11709
11737
  }
11710
11738
  }
11711
- this._propertyValueMap[property._uniqueId] = value;
11739
+ var id = property._uniqueId;
11740
+ // Track renderer-group samplers/arrays so `_canBatch` can refuse instanced batches
11741
+ // whose leader and follower would disagree on what to bind
11742
+ if (this._group === ShaderDataGroup.Renderer && (type === ShaderPropertyType.Texture || type === ShaderPropertyType.TextureArray || type === ShaderPropertyType.FloatArray || type === ShaderPropertyType.IntArray)) {
11743
+ var oldHas = this._propertyValueMap[id] != null;
11744
+ var newHas = value != null;
11745
+ if (oldHas !== newHas) {
11746
+ var fields = this._instanceBatchFields;
11747
+ if (newHas) {
11748
+ // Insert keeping ascending order so exact compare is index-by-index
11749
+ var lo = 0;
11750
+ var hi = fields.length;
11751
+ while(lo < hi){
11752
+ var mid = lo + hi >>> 1;
11753
+ if (fields[mid] < id) {
11754
+ lo = mid + 1;
11755
+ } else {
11756
+ hi = mid;
11757
+ }
11758
+ }
11759
+ fields.splice(lo, 0, id);
11760
+ } else {
11761
+ fields.splice(fields.indexOf(id), 1);
11762
+ }
11763
+ }
11764
+ }
11765
+ this._propertyValueMap[id] = value;
11766
+ };
11767
+ /**
11768
+ * @internal
11769
+ */ _proto._matchesRendererInstanceBatch = function _matchesRendererInstanceBatch(other) {
11770
+ var selfFields = this._instanceBatchFields;
11771
+ var otherFields = other._instanceBatchFields;
11772
+ var fieldCount = selfFields.length;
11773
+ if (fieldCount !== otherFields.length) {
11774
+ return false;
11775
+ }
11776
+ var selfMap = this._propertyValueMap;
11777
+ var otherMap = other._propertyValueMap;
11778
+ for(var i = 0; i < fieldCount; i++){
11779
+ var id = selfFields[i];
11780
+ if (id !== otherFields[i] || selfMap[id] !== otherMap[id]) {
11781
+ return false;
11782
+ }
11783
+ }
11784
+ return true;
11712
11785
  };
11713
11786
  /**
11714
11787
  * @internal
@@ -11739,6 +11812,9 @@
11739
11812
  __decorate$1([
11740
11813
  ignoreClone
11741
11814
  ], ShaderData.prototype, "_macroCollection", void 0);
11815
+ __decorate$1([
11816
+ ignoreClone
11817
+ ], ShaderData.prototype, "_instanceBatchFields", void 0);
11742
11818
  __decorate$1([
11743
11819
  ignoreClone
11744
11820
  ], ShaderData.prototype, "_macroMap", void 0);
@@ -19297,7 +19373,9 @@
19297
19373
  * @internal
19298
19374
  */ _proto._canBatch = function _canBatch(preElement, curElement) {
19299
19375
  if (!this._engine._hardwareRenderer.isWebGL2) return false;
19300
- return preElement.primitive === curElement.primitive && preElement.subPrimitive === curElement.subPrimitive && preElement.material === curElement.material && this._isFrontFaceInvert() === curElement.component._isFrontFaceInvert() && this.shaderData._macroCollection.isEqual(curElement.component.shaderData._macroCollection);
19376
+ var curShaderData = curElement.component.shaderData;
19377
+ return preElement.primitive === curElement.primitive && preElement.subPrimitive === curElement.subPrimitive && preElement.material === curElement.material && this._isFrontFaceInvert() === curElement.component._isFrontFaceInvert() && this.shaderData._macroCollection.isEqual(curShaderData._macroCollection) && // Renderer-group samplers/arrays are shared across the whole instanced draw call
19378
+ this.shaderData._matchesRendererInstanceBatch(curShaderData);
19301
19379
  };
19302
19380
  /**
19303
19381
  * @internal
@@ -23841,8 +23919,11 @@
23841
23919
  * @internal
23842
23920
  */ var RenderTargetPool = /*#__PURE__*/ function() {
23843
23921
  function RenderTargetPool(engine) {
23922
+ /** Frames an entry may sit idle before `tick()` destroys it. */ this.maxFreeAgeFrames = 60;
23844
23923
  this._freeRenderTargets = [];
23924
+ this._freeRenderTargetFrames = [];
23845
23925
  this._freeTextures = [];
23926
+ this._freeTextureFrames = [];
23846
23927
  this._engine = engine;
23847
23928
  }
23848
23929
  var _proto = RenderTargetPool.prototype;
@@ -23851,8 +23932,7 @@
23851
23932
  for(var i = freeRenderTargets.length - 1; i >= 0; i--){
23852
23933
  var renderTarget = freeRenderTargets[i];
23853
23934
  if (RenderTargetPool._matchRenderTarget(renderTarget, width, height, colorFormat, depthFormat, needDepthTexture, mipmap, isSRGBColorSpace, antiAliasing)) {
23854
- freeRenderTargets[i] = freeRenderTargets[freeRenderTargets.length - 1];
23855
- freeRenderTargets.length--;
23935
+ this._removeFreeRenderTargetAt(i);
23856
23936
  var colorTexture = renderTarget.getColorTexture(0);
23857
23937
  if (colorTexture) {
23858
23938
  colorTexture.wrapModeU = colorTexture.wrapModeV = wrapMode;
@@ -23895,8 +23975,7 @@
23895
23975
  for(var i = freeTextures.length - 1; i >= 0; i--){
23896
23976
  var texture = freeTextures[i];
23897
23977
  if (texture.width === width && texture.height === height && texture.format === format && texture.mipmapCount > 1 === mipmap && texture.isSRGBColorSpace === isSRGBColorSpace) {
23898
- freeTextures[i] = freeTextures[freeTextures.length - 1];
23899
- freeTextures.length--;
23978
+ this._removeFreeTextureAt(i);
23900
23979
  texture.wrapModeU = texture.wrapModeV = wrapMode;
23901
23980
  texture.filterMode = filterMode;
23902
23981
  return texture;
@@ -23911,29 +23990,98 @@
23911
23990
  _proto.freeRenderTarget = function freeRenderTarget(renderTarget) {
23912
23991
  if (!renderTarget || renderTarget.destroyed) return;
23913
23992
  this._freeRenderTargets.push(renderTarget);
23993
+ this._freeRenderTargetFrames.push(this._engine.time.frameCount);
23914
23994
  };
23915
23995
  _proto.freeTexture = function freeTexture(texture) {
23916
23996
  if (!texture || texture.destroyed) return;
23917
23997
  this._freeTextures.push(texture);
23998
+ this._freeTextureFrames.push(this._engine.time.frameCount);
23999
+ };
24000
+ _proto.tick = function tick(currentFrame) {
24001
+ var maxAge = this.maxFreeAgeFrames;
24002
+ var rtFrames = this._freeRenderTargetFrames;
24003
+ for(var i = rtFrames.length - 1; i >= 0; i--){
24004
+ if (currentFrame - rtFrames[i] > maxAge) {
24005
+ this._destroyFreeRenderTargetAt(i);
24006
+ }
24007
+ }
24008
+ var texFrames = this._freeTextureFrames;
24009
+ for(var i1 = texFrames.length - 1; i1 >= 0; i1--){
24010
+ if (currentFrame - texFrames[i1] > maxAge) {
24011
+ this._destroyFreeTextureAt(i1);
24012
+ }
24013
+ }
24014
+ };
24015
+ _proto.evictBySize = function evictBySize(width, height) {
24016
+ var freeRenderTargets = this._freeRenderTargets;
24017
+ for(var i = freeRenderTargets.length - 1; i >= 0; i--){
24018
+ var rt = freeRenderTargets[i];
24019
+ if (rt.width === width && rt.height === height) {
24020
+ this._destroyFreeRenderTargetAt(i);
24021
+ }
24022
+ }
24023
+ var freeTextures = this._freeTextures;
24024
+ for(var i1 = freeTextures.length - 1; i1 >= 0; i1--){
24025
+ var tex = freeTextures[i1];
24026
+ if (tex.width === width && tex.height === height) {
24027
+ this._destroyFreeTextureAt(i1);
24028
+ }
24029
+ }
23918
24030
  };
23919
24031
  _proto.gc = function gc() {
23920
24032
  var freeRenderTargets = this._freeRenderTargets;
23921
24033
  for(var i = 0, n = freeRenderTargets.length; i < n; i++){
23922
- var renderTarget = freeRenderTargets[i];
23923
- var colorTexture = renderTarget.getColorTexture(0);
23924
- var depthTexture = renderTarget.depthTexture;
23925
- renderTarget.destroy(true);
23926
- colorTexture == null ? void 0 : colorTexture.destroy(true);
23927
- if (depthTexture && depthTexture !== colorTexture) {
23928
- depthTexture.destroy(true);
23929
- }
24034
+ RenderTargetPool._destroyRenderTargetResource(freeRenderTargets[i]);
23930
24035
  }
23931
24036
  freeRenderTargets.length = 0;
24037
+ this._freeRenderTargetFrames.length = 0;
23932
24038
  var freeTextures = this._freeTextures;
23933
24039
  for(var i1 = 0, n1 = freeTextures.length; i1 < n1; i1++){
23934
24040
  freeTextures[i1].destroy(true);
23935
24041
  }
23936
24042
  freeTextures.length = 0;
24043
+ this._freeTextureFrames.length = 0;
24044
+ };
24045
+ _proto._removeFreeRenderTargetAt = function _removeFreeRenderTargetAt(index) {
24046
+ var rts = this._freeRenderTargets;
24047
+ var frames = this._freeRenderTargetFrames;
24048
+ var last = rts.length - 1;
24049
+ if (index !== last) {
24050
+ rts[index] = rts[last];
24051
+ frames[index] = frames[last];
24052
+ }
24053
+ rts.length = last;
24054
+ frames.length = last;
24055
+ };
24056
+ _proto._removeFreeTextureAt = function _removeFreeTextureAt(index) {
24057
+ var texs = this._freeTextures;
24058
+ var frames = this._freeTextureFrames;
24059
+ var last = texs.length - 1;
24060
+ if (index !== last) {
24061
+ texs[index] = texs[last];
24062
+ frames[index] = frames[last];
24063
+ }
24064
+ texs.length = last;
24065
+ frames.length = last;
24066
+ };
24067
+ _proto._destroyFreeRenderTargetAt = function _destroyFreeRenderTargetAt(index) {
24068
+ var rt = this._freeRenderTargets[index];
24069
+ this._removeFreeRenderTargetAt(index);
24070
+ RenderTargetPool._destroyRenderTargetResource(rt);
24071
+ };
24072
+ _proto._destroyFreeTextureAt = function _destroyFreeTextureAt(index) {
24073
+ var tex = this._freeTextures[index];
24074
+ this._removeFreeTextureAt(index);
24075
+ tex.destroy(true);
24076
+ };
24077
+ RenderTargetPool._destroyRenderTargetResource = function _destroyRenderTargetResource(rt) {
24078
+ var colorTexture = rt.getColorTexture(0);
24079
+ var depthTexture = rt.depthTexture;
24080
+ rt.destroy(true);
24081
+ colorTexture == null ? void 0 : colorTexture.destroy(true);
24082
+ if (depthTexture && depthTexture !== colorTexture) {
24083
+ depthTexture.destroy(true);
24084
+ }
23937
24085
  };
23938
24086
  RenderTargetPool._matchRenderTarget = function _matchRenderTarget(renderTarget, width, height, colorFormat, depthFormat, needDepthTexture, mipmap, isSRGBColorSpace, antiAliasing) {
23939
24087
  if (renderTarget.width !== width || renderTarget.height !== height || renderTarget.antiAliasing !== antiAliasing) {
@@ -31911,17 +32059,15 @@
31911
32059
  }
31912
32060
  var switchProgram = program.bind();
31913
32061
  var switchRenderCount = renderCount !== program._uploadRenderCount;
31914
- // Upload uniforms (cache-aware per block)
32062
+ // Upload uniforms (cache-aware per block). Renderer block carries plain samplers/arrays
32063
+ // even on the instanced path (GLSL forbids them in UBOs); `_canBatch` ensures the whole
32064
+ // batch agrees on those, so the leader's values are correct for the draw call
31915
32065
  if (switchRenderCount) {
31916
32066
  program.groupingOtherUniformBlock();
31917
32067
  program.uploadAll(program.sceneUniformBlock, sceneData);
31918
32068
  program.uploadAll(program.cameraUniformBlock, cameraData);
31919
- if (isInstanced) {
31920
- program._uploadRendererId = -1;
31921
- } else {
31922
- program.uploadAll(program.rendererUniformBlock, rendererData);
31923
- program._uploadRendererId = rendererId;
31924
- }
32069
+ program.uploadAll(program.rendererUniformBlock, rendererData);
32070
+ program._uploadRendererId = isInstanced ? -1 : rendererId;
31925
32071
  program.uploadAll(program.materialUniformBlock, materialData);
31926
32072
  renderElementShaderData && program.uploadAll(program.renderElementUniformBlock, renderElementShaderData);
31927
32073
  // UnGroup textures should upload default value, texture uint maybe change by logic of texture bind
@@ -31943,13 +32089,15 @@
31943
32089
  } else if (switchProgram) {
31944
32090
  program.uploadTextures(program.cameraUniformBlock, cameraData);
31945
32091
  }
31946
- if (!isInstanced) {
31947
- if (program._uploadRendererId !== rendererId) {
31948
- program.uploadAll(program.rendererUniformBlock, rendererData);
31949
- program._uploadRendererId = rendererId;
31950
- } else if (switchProgram) {
31951
- program.uploadTextures(program.rendererUniformBlock, rendererData);
31952
- }
32092
+ if (isInstanced) {
32093
+ // Different batches may have different leaders, re-upload every time
32094
+ program.uploadAll(program.rendererUniformBlock, rendererData);
32095
+ program._uploadRendererId = -1;
32096
+ } else if (program._uploadRendererId !== rendererId) {
32097
+ program.uploadAll(program.rendererUniformBlock, rendererData);
32098
+ program._uploadRendererId = rendererId;
32099
+ } else if (switchProgram) {
32100
+ program.uploadTextures(program.rendererUniformBlock, rendererData);
31953
32101
  }
31954
32102
  if (program._uploadMaterialId !== materialId) {
31955
32103
  program.uploadAll(program.materialUniformBlock, materialData);
@@ -32957,19 +33105,8 @@
32957
33105
  this._copyBackgroundTexture = copyBackgroundTexture;
32958
33106
  }
32959
33107
  this._internalColorTarget = internalColorTarget;
32960
- } else {
32961
- var internalColorTarget1 = this._internalColorTarget;
32962
- var copyBackgroundTexture1 = this._copyBackgroundTexture;
32963
- var pool = engine._renderTargetPool;
32964
- if (internalColorTarget1) {
32965
- pool.freeRenderTarget(internalColorTarget1);
32966
- this._internalColorTarget = null;
32967
- }
32968
- if (copyBackgroundTexture1) {
32969
- pool.freeTexture(copyBackgroundTexture1);
32970
- this._copyBackgroundTexture = null;
32971
- }
32972
33108
  }
33109
+ // Both fields are released at the end of `_drawRenderPass`, so they're null on every entry here.
32973
33110
  // Scalable ambient obscurance pass
32974
33111
  // Before opaque pass so materials can sample ambient occlusion in BRDF
32975
33112
  var saoPass = this._saoPass;
@@ -33086,6 +33223,16 @@
33086
33223
  }
33087
33224
  cameraRenderTarget == null ? void 0 : cameraRenderTarget._blitRenderTarget();
33088
33225
  cameraRenderTarget == null ? void 0 : cameraRenderTarget.generateMipmaps();
33226
+ // Release per-frame leases so the next camera with matching shape can reuse them.
33227
+ var pool = engine._renderTargetPool;
33228
+ if (this._internalColorTarget) {
33229
+ pool.freeRenderTarget(this._internalColorTarget);
33230
+ this._internalColorTarget = null;
33231
+ }
33232
+ if (this._copyBackgroundTexture) {
33233
+ pool.freeTexture(this._copyBackgroundTexture);
33234
+ this._copyBackgroundTexture = null;
33235
+ }
33089
33236
  };
33090
33237
  /**
33091
33238
  * Push render data to render queue.
@@ -33121,6 +33268,7 @@
33121
33268
  _proto._pushRenderElementByType = function _pushRenderElementByType(renderElement, subShader, renderStates) {
33122
33269
  var shaderPasses = subShader.passes;
33123
33270
  var cullingResults = this._cullingResults;
33271
+ renderElement.subShader = subShader;
33124
33272
  var pushedQueueFlags = 0;
33125
33273
  for(var i = 0, n = shaderPasses.length; i < n; i++){
33126
33274
  var renderQueueType = void 0;
@@ -33132,19 +33280,28 @@
33132
33280
  renderQueueType = renderStates[i].renderQueueType;
33133
33281
  }
33134
33282
  var flag = 1 << renderQueueType;
33135
- renderElement.subShader = subShader;
33136
33283
  if (pushedQueueFlags & flag) {
33137
33284
  continue;
33138
33285
  }
33286
+ // First queue keeps the original element; subsequent queues each get an isolated
33287
+ // clone so per-queue batch state (`_isBatched`, `instancedRenderers`) doesn't
33288
+ // leak across queues for multi-pass materials (e.g. Opaque + Transparent)
33289
+ var elementForQueue = void 0;
33290
+ if (pushedQueueFlags === 0) {
33291
+ elementForQueue = renderElement;
33292
+ } else {
33293
+ elementForQueue = renderElement.component.engine._renderElementPool.get();
33294
+ elementForQueue._cloneFrom(renderElement);
33295
+ }
33139
33296
  switch(renderQueueType){
33140
33297
  case RenderQueueType.Opaque:
33141
- cullingResults.opaqueQueue.pushRenderElement(renderElement);
33298
+ cullingResults.opaqueQueue.pushRenderElement(elementForQueue);
33142
33299
  break;
33143
33300
  case RenderQueueType.AlphaTest:
33144
- cullingResults.alphaTestQueue.pushRenderElement(renderElement);
33301
+ cullingResults.alphaTestQueue.pushRenderElement(elementForQueue);
33145
33302
  break;
33146
33303
  case RenderQueueType.Transparent:
33147
- cullingResults.transparentQueue.pushRenderElement(renderElement);
33304
+ cullingResults.transparentQueue.pushRenderElement(elementForQueue);
33148
33305
  break;
33149
33306
  }
33150
33307
  pushedQueueFlags |= flag;
@@ -33357,7 +33514,18 @@
33357
33514
  _inherits$2(Engine, EventDispatcher);
33358
33515
  function Engine(canvas, hardwareRenderer, configuration) {
33359
33516
  var _this;
33360
- _this = EventDispatcher.call(this) || this, /** @internal */ _this._renderingStatistics = new RenderingStatistics(), /** @internal */ _this._isDeviceLost = false, /** @internal */ _this._frameInProcess = false, /** @internal */ _this._pendingDestroyObjects = [], /** @internal */ _this._processingPendingDestroys = false, /** @internal */ _this._physicsInitialized = false, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._textRenderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramMaps = [], /** @internal */ _this._fontMap = {}, /** @internal */ _this._macroCollection = new ShaderMacroCollection(), /** @internal */ _this._postProcessPassNeedRefresh = false, _this._settings = {}, _this._resourceManager = new ResourceManager(_this), _this._sceneManager = new SceneManager(_this), _this._vSyncCount = 1, _this._targetFrameRate = 60, _this._time = new Time(), _this._isPaused = true, _this._vSyncCounter = 1, _this._targetFrameInterval = 1000 / 60, _this._destroyed = false, _this._waitingDestroy = false, _this._waitingGC = false, _this._postProcessPasses = new Array(), _this._activePostProcessPasses = new Array(), _this._animate = function() {
33517
+ _this = EventDispatcher.call(this) || this, /** @internal */ _this._renderingStatistics = new RenderingStatistics(), /** @internal */ _this._isDeviceLost = false, /** @internal */ _this._frameInProcess = false, /** @internal */ _this._pendingDestroyObjects = [], /** @internal */ _this._processingPendingDestroys = false, /** @internal */ _this._physicsInitialized = false, /* @internal */ _this._lastRenderState = new RenderState(), /* @internal */ _this._renderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._textRenderElementPool = new ClearableObjectPool(RenderElement), /* @internal */ _this._charRenderInfoPool = new ReturnableObjectPool(CharRenderInfo, 50), /* @internal */ _this._renderContext = new RenderContext(), /* @internal */ _this._renderCount = 0, /* @internal */ _this._shaderProgramMaps = [], /** @internal */ _this._fontMap = {}, /** @internal */ _this._macroCollection = new ShaderMacroCollection(), /** @internal */ _this._postProcessPassNeedRefresh = false, _this._settings = {}, _this._resourceManager = new ResourceManager(_this), _this._sceneManager = new SceneManager(_this), _this._vSyncCount = 1, _this._targetFrameRate = 60, _this._time = new Time(), _this._isPaused = true, _this._vSyncCounter = 1, _this._targetFrameInterval = 1000 / 60, _this._destroyed = false, _this._waitingDestroy = false, _this._waitingGC = false, _this._postProcessPasses = new Array(), _this._activePostProcessPasses = new Array(), _this._lastCanvasWidth = -1, _this._lastCanvasHeight = -1, /** Evict pool entries sized to the previous canvas dimensions. */ _this._onCanvasResize = function() {
33518
+ var _$canvas = _this._canvas;
33519
+ var newWidth = _$canvas.width;
33520
+ var newHeight = _$canvas.height;
33521
+ if (_this._lastCanvasWidth !== newWidth || _this._lastCanvasHeight !== newHeight) {
33522
+ if (_this._lastCanvasWidth >= 0) {
33523
+ _this._renderTargetPool.evictBySize(_this._lastCanvasWidth, _this._lastCanvasHeight);
33524
+ }
33525
+ _this._lastCanvasWidth = newWidth;
33526
+ _this._lastCanvasHeight = newHeight;
33527
+ }
33528
+ }, _this._animate = function() {
33361
33529
  if (_this._vSyncCount) {
33362
33530
  var _this_xrManager;
33363
33531
  var raf = ((_this_xrManager = _this.xrManager) == null ? void 0 : _this_xrManager._getRequestAnimationFrame()) || requestAnimationFrame;
@@ -33378,6 +33546,9 @@
33378
33546
  _this._textDefaultFont.isGCIgnored = true;
33379
33547
  _this._batcherManager = new BatcherManager(_this);
33380
33548
  _this._renderTargetPool = new RenderTargetPool(_this);
33549
+ _this._lastCanvasWidth = canvas.width;
33550
+ _this._lastCanvasHeight = canvas.height;
33551
+ canvas._sizeUpdateFlagManager.addListener(_this._onCanvasResize);
33381
33552
  _this.inputManager = new InputManager(_this, configuration.input);
33382
33553
  var xrDevice = configuration.xrDevice;
33383
33554
  if (xrDevice) {
@@ -33437,6 +33608,7 @@
33437
33608
  var _this_xrManager;
33438
33609
  var time = this._time;
33439
33610
  time._update();
33611
+ this._renderTargetPool.tick(time.frameCount);
33440
33612
  var deltaTime = time.deltaTime;
33441
33613
  this._frameInProcess = true;
33442
33614
  this._renderElementPool.clear();
@@ -33581,6 +33753,7 @@
33581
33753
  var _this_xrManager;
33582
33754
  this._destroyed = true;
33583
33755
  this._waitingDestroy = false;
33756
+ this._canvas._sizeUpdateFlagManager.removeListener(this._onCanvasResize);
33584
33757
  this._sceneManager._destroyAllScene();
33585
33758
  this._resourceManager._destroy();
33586
33759
  this.inputManager._destroy();
@@ -36364,7 +36537,7 @@
36364
36537
  */ var AnimationClipCurveBinding = /*#__PURE__*/ function() {
36365
36538
  function AnimationClipCurveBinding() {
36366
36539
  /** The index of the component that is animated. */ this.typeIndex = 0;
36367
- this._tempCurveOwner = {};
36540
+ this._tempCurveOwner = new WeakMap();
36368
36541
  }
36369
36542
  var _proto = AnimationClipCurveBinding.prototype;
36370
36543
  /**
@@ -36390,11 +36563,12 @@
36390
36563
  /**
36391
36564
  * @internal
36392
36565
  */ _proto._getTempCurveOwner = function _getTempCurveOwner(entity, component) {
36393
- var instanceId = entity.instanceId;
36394
- if (!this._tempCurveOwner[instanceId]) {
36395
- this._tempCurveOwner[instanceId] = this._createCurveOwner(entity, component);
36566
+ var owner = this._tempCurveOwner.get(entity);
36567
+ if (!owner) {
36568
+ owner = this._createCurveOwner(entity, component);
36569
+ this._tempCurveOwner.set(entity, owner);
36396
36570
  }
36397
- return this._tempCurveOwner[instanceId];
36571
+ return owner;
36398
36572
  };
36399
36573
  return AnimationClipCurveBinding;
36400
36574
  }();
@@ -37844,7 +38018,7 @@
37844
38018
  * @internal
37845
38019
  */ var AnimatorLayerData = /*#__PURE__*/ function() {
37846
38020
  function AnimatorLayerData() {
37847
- this.curveOwnerPool = Object.create(null);
38021
+ this.curveOwnerPool = new WeakMap();
37848
38022
  this.animatorStateDataMap = {};
37849
38023
  this.srcPlayData = new AnimatorStatePlayData();
37850
38024
  this.destPlayData = new AnimatorStatePlayData();
@@ -37880,7 +38054,7 @@
37880
38054
  _inherits$2(Animator, Component);
37881
38055
  function Animator(entity) {
37882
38056
  var _this;
37883
- _this = Component.call(this, entity) || this, /** Culling mode of this Animator. */ _this.cullingMode = AnimatorCullingMode.None, /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0, /** Whether the Animator sends AnimationEvent callbacks. */ _this.fireEvents = true, /** @internal */ _this._playFrameCount = -1, /** @internal */ _this._onUpdateIndex = -1, _this._updateMark = 0, _this._animatorLayersData = new Array(), _this._curveOwnerPool = Object.create(null), _this._animationEventHandlerPool = new ClearableObjectPool(AnimationEventHandler), _this._parametersValueMap = Object.create(null), _this._tempAnimatorStateInfo = {
38057
+ _this = Component.call(this, entity) || this, /** Culling mode of this Animator. */ _this.cullingMode = AnimatorCullingMode.None, /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0, /** Whether the Animator sends AnimationEvent callbacks. */ _this.fireEvents = true, /** @internal */ _this._playFrameCount = -1, /** @internal */ _this._onUpdateIndex = -1, _this._updateMark = 0, _this._animatorLayersData = new Array(), _this._curveOwnerPool = new WeakMap(), _this._animationEventHandlerPool = new ClearableObjectPool(AnimationEventHandler), _this._parametersValueMap = Object.create(null), _this._tempAnimatorStateInfo = {
37884
38058
  layerIndex: -1,
37885
38059
  state: null
37886
38060
  }, _this._controlledRenderers = new Array();
@@ -38076,19 +38250,23 @@
38076
38250
  /**
38077
38251
  * @internal
38078
38252
  */ _proto._reset = function _reset() {
38079
- var _this = this, animationCurveOwners = _this._curveOwnerPool;
38080
- for(var instanceId in animationCurveOwners){
38081
- var propertyOwners = animationCurveOwners[instanceId];
38082
- for(var property in propertyOwners){
38083
- var owner = propertyOwners[property];
38084
- owner.revertDefaultValue();
38085
- }
38086
- }
38253
+ // revertDefaultValue 可能在死 target 上抛;listener 清理必须始终发生,否则
38254
+ // polyfill clipChangedListener 会留在共享的 AnimatorState 上,捕获 this(Animator)→Entity 整树。
38255
+ // try/catch 隔离 revert,listener 块紧跟其后无条件执行。
38087
38256
  var layersData = this._animatorLayersData;
38088
38257
  for(var i = 0, n = layersData.length; i < n; i++){
38089
38258
  var stateDataMap = layersData[i].animatorStateDataMap;
38090
38259
  for(var stateName in stateDataMap){
38091
38260
  var stateData = stateDataMap[stateName];
38261
+ var layerOwners = stateData.curveLayerOwner;
38262
+ for(var j = 0, m = layerOwners.length; j < m; j++){
38263
+ try {
38264
+ var _layerOwners_j_curveOwner, _layerOwners_j;
38265
+ (_layerOwners_j = layerOwners[j]) == null ? void 0 : (_layerOwners_j_curveOwner = _layerOwners_j.curveOwner) == null ? void 0 : _layerOwners_j_curveOwner.revertDefaultValue();
38266
+ } catch (e) {
38267
+ Logger.warn("Animator._reset: revertDefaultValue threw", e);
38268
+ }
38269
+ }
38092
38270
  if (stateData.clipChangedListener && stateData.state) {
38093
38271
  stateData.state._updateFlagManager.removeListener(stateData.clipChangedListener);
38094
38272
  stateData.clipChangedListener = null;
@@ -38097,7 +38275,7 @@
38097
38275
  }
38098
38276
  }
38099
38277
  this._animatorLayersData.length = 0;
38100
- this._curveOwnerPool = Object.create(null);
38278
+ this._curveOwnerPool = new WeakMap();
38101
38279
  this._parametersValueMap = Object.create(null);
38102
38280
  this._animationEventHandlerPool.clear();
38103
38281
  if (this._controllerUpdateFlag) {
@@ -38182,19 +38360,26 @@
38182
38360
  var relativePath = curve.relativePath;
38183
38361
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
38184
38362
  if (targetEntity) {
38185
- var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
38363
+ var _propertyOwners, _property, _layerPropertyOwners, _property1;
38186
38364
  var component = curve.typeIndex > 0 ? targetEntity.getComponents(curve.type, components)[curve.typeIndex] : targetEntity.getComponent(curve.type);
38187
38365
  components.length = 0;
38188
38366
  if (!component) {
38189
38367
  continue;
38190
38368
  }
38191
38369
  var property = curve.property;
38192
- var instanceId = component.instanceId;
38193
- // Get owner
38194
- var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
38370
+ // Get owner — WeakMap keyed by Component so dead components let entries GC.
38371
+ var propertyOwners = curveOwnerPool.get(component);
38372
+ if (!propertyOwners) {
38373
+ propertyOwners = Object.create(null);
38374
+ curveOwnerPool.set(component, propertyOwners);
38375
+ }
38195
38376
  var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity, component));
38196
- // Get layer owner
38197
- var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
38377
+ // Get layer owner — same WeakMap-by-Component pattern (was Record<instanceId,...> which kept dead components pinned for the Animator's lifetime).
38378
+ var layerPropertyOwners = layerCurveOwnerPool.get(component);
38379
+ if (!layerPropertyOwners) {
38380
+ layerPropertyOwners = Object.create(null);
38381
+ layerCurveOwnerPool.set(component, layerPropertyOwners);
38382
+ }
38198
38383
  var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
38199
38384
  if (mask && mask.pathMasks.length) {
38200
38385
  var _mask_getPathMask;
@@ -56452,7 +56637,7 @@
56452
56637
  ], EXT_texture_webp);
56453
56638
 
56454
56639
  //@ts-ignore
56455
- var version = "0.0.0-experimental-2.0-game.15";
56640
+ var version = "0.0.0-experimental-2.0-game.16";
56456
56641
  console.log("Galacean Engine Version: " + version);
56457
56642
  for(var key in CoreObjects){
56458
56643
  Loader.registerClass(key, CoreObjects[key]);