[engine] 多纹理渲染、动态图集调整开关时主动刷新渲染状态

This commit is contained in:
SmallMain 2022-06-25 01:03:18 +08:00
parent a414bb7945
commit d46a4db8cb
4 changed files with 45 additions and 2 deletions

View File

@ -586,15 +586,24 @@ let Label = cc.Class({
autoSwitchMaterial: { autoSwitchMaterial: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.autoSwitchMaterial === oldValue) return;
this.setVertsDirty();
},
}, },
allowDynamicAtlas: { allowDynamicAtlas: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.allowDynamicAtlas === oldValue) return;
this.setVertsDirty();
},
}, },
enableRetina: { enableRetina: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) { notify(oldValue) {
if (this.enableRetina === oldValue) return;
this.setVertsDirty(); this.setVertsDirty();
} }
}, },

View File

@ -219,8 +219,20 @@ var MotionStreak = cc.Class({
autoSwitchMaterial: { autoSwitchMaterial: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.autoSwitchMaterial === oldValue) return;
this.setVertsDirty();
}, },
}, },
},
setVertsDirty() {
// 自动切换材质
this._checkSwitchMaterial();
this._updateMaterial();
this._super();
},
__preload() { __preload() {
this._super(); this._super();

View File

@ -391,10 +391,18 @@ var Sprite = cc.Class({
autoSwitchMaterial: { autoSwitchMaterial: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.autoSwitchMaterial === oldValue) return;
this.setVertsDirty();
},
}, },
allowDynamicAtlas: { allowDynamicAtlas: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.allowDynamicAtlas === oldValue) return;
this.setVertsDirty();
},
}, },
}, },

View File

@ -435,10 +435,18 @@ sp.Skeleton = cc.Class({
autoSwitchMaterial: { autoSwitchMaterial: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.autoSwitchMaterial === oldValue) return;
this.setVertsDirty();
},
}, },
allowDynamicAtlas: { allowDynamicAtlas: {
type: RenderComponent.EnableType, type: RenderComponent.EnableType,
default: RenderComponent.EnableType.GLOBAL, default: RenderComponent.EnableType.GLOBAL,
notify(oldValue) {
if (this.allowDynamicAtlas === oldValue) return;
this.setVertsDirty();
},
}, },
}, },
@ -458,6 +466,13 @@ sp.Skeleton = cc.Class({
this._dataDirty = true; this._dataDirty = true;
}, },
setVertsDirty() {
this._dataDirty = true;
this.invalidAnimationCache();
this._materialCache = {};
this._super();
},
// override base class _getDefaultMaterial to modify default material // override base class _getDefaultMaterial to modify default material
_getDefaultMaterial () { _getDefaultMaterial () {
return cc.Material.getBuiltinMaterial('2d-spine'); return cc.Material.getBuiltinMaterial('2d-spine');
@ -1010,8 +1025,7 @@ sp.Skeleton = cc.Class({
attachment.setRegion(region); attachment.setRegion(region);
attachment.updateOffset(); attachment.updateOffset();
} }
this._dataDirty = true; this.setVertsDirty();
this.invalidAnimationCache();
return true; return true;
} }
return false; return false;