Improve render flag control in render component (#2695)

* Improve render flag control in render component

* Overwrite disableRender in Mask

* Secure markForUpdateRenderData for Sprite (check material)

* Fix particle auto remove process
This commit is contained in:
pandamicro
2018-05-17 10:41:46 +08:00
committed by GitHub
parent 68e635383b
commit c3a9e6235b
7 changed files with 93 additions and 38 deletions
+3 -8
View File
@@ -476,12 +476,7 @@ var Label = cc.Class({
},
_checkStringEmpty () {
if (!this.string) {
this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
}
else {
this.node._renderFlag |= RenderFlow.FLAG_RENDER;
}
this.markForRender(!!this.string);
},
_updateAssembler () {
@@ -500,7 +495,7 @@ var Label = cc.Class({
_activateMaterial (force) {
let material = this._material;
if (!material) {
material = this._material = new SpriteMaterial();
material = new SpriteMaterial();
}
else if (!force) {
return;
@@ -539,7 +534,7 @@ var Label = cc.Class({
if (renderData) {
renderData.vertDirty = true;
renderData.uvDirty = true;
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
if (CC_EDITOR || force) {
+28 -3
View File
@@ -247,7 +247,7 @@ let Mask = cc.Class({
if (this._renderData) {
this._renderData.uvDirty = true;
this._renderData.vertDirty = true;
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
// Reactivate material
if (this.enabledInHierarchy) {
@@ -273,7 +273,8 @@ let Mask = cc.Class({
_activateMaterial: function () {
// cannot be activated if texture not loaded yet
if (this._type === MaskType.IMAGE_STENCIL && (!this.spriteFrame || !this.spriteFrame.textureLoaded)) {
if (this._type === MaskType.IMAGE_STENCIL && (!this.spriteFrame || !this.spriteFrame.textureLoaded())) {
this.markForRender(false);
return;
}
@@ -306,6 +307,7 @@ let Mask = cc.Class({
}
this._frontMaterial.updateHash();
this._endMaterial.updateHash();
this.markForRender(true);
},
_hitTest: function (point) {
@@ -336,15 +338,38 @@ let Mask = cc.Class({
}
},
markForUpdateRenderData (enable) {
if (enable && this.enabledInHierarchy) {
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA;
}
else if (!enable) {
this.node._renderFlag &= ~(RenderFlow.FLAG_UPDATE_RENDER_DATA | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA);
}
},
markForRender (enable) {
if (enable && this.enabledInHierarchy) {
this.node._renderFlag |= RenderFlow.FLAG_RENDER | RenderFlow.FLAG_POST_RENDER;
}
else if (!enable) {
this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_POST_RENDER);
}
},
disableRender () {
this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA |
RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA);
},
onEnable () {
this._super();
// for graphic stencil data
this._renderDatas = [];
// for graphic stencil data
this._graphics = null;
this._activateMaterial();
this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA;
this._activateMaterial();
},
onDisable () {
+7 -1
View File
@@ -209,7 +209,13 @@ var MotionStreak = cc.Class({
onEnable () {
this._super();
this._activateMaterial();
if (!this._texture || !this._texture.loaded) {
this.disableRender();
}
else {
this._activateMaterial();
}
this.reset();
},
+20 -3
View File
@@ -73,9 +73,26 @@ var RenderComponent = cc.Class({
this.__allocedDatas.length = 0;
},
markUpdateRenderData () {
if (!this.enabledInHierarchy) return;
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
markForUpdateRenderData (enable) {
if (enable && this.enabledInHierarchy) {
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
else if (!enable) {
this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
},
markForRender (enable) {
if (enable && this.enabledInHierarchy) {
this.node._renderFlag |= RenderFlow.FLAG_RENDER;
}
else if (!enable) {
this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
}
},
disableRender () {
this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA);
},
requestRenderData () {
+22 -18
View File
@@ -219,10 +219,10 @@ var Sprite = cc.Class({
this._spriteFrame = value;
if ((this._material && this._material._texture) !== (value && value._texture)) {
// disable render flow util texture is loaded
this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
this.markForRender(false);
}
// render & update render data flag will be triggered while applying new sprite frame
this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
this.markForUpdateRenderData(false);
this._applySpriteFrame(lastSprite);
if (CC_EDITOR) {
this.node.emit('spriteframe-changed', this);
@@ -277,7 +277,7 @@ var Sprite = cc.Class({
this._renderData = null;
}
else if (this._renderData) {
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
this._fillType = value;
this._updateAssembler();
@@ -304,7 +304,7 @@ var Sprite = cc.Class({
set: function(value) {
this._fillCenter = cc.v2(value);
if (this._type === SpriteType.FILLED && this._renderData) {
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
},
tooltip: CC_DEV && 'i18n:COMPONENT.sprite.fill_center',
@@ -328,7 +328,7 @@ var Sprite = cc.Class({
set: function(value) {
this._fillStart = misc.clampf(value, -1, 1);
if (this._type === SpriteType.FILLED && this._renderData) {
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
},
tooltip: CC_DEV && 'i18n:COMPONENT.sprite.fill_start'
@@ -352,7 +352,7 @@ var Sprite = cc.Class({
set: function(value) {
this._fillRange = misc.clampf(value, -1, 1);
if (this._type === SpriteType.FILLED && this._renderData) {
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
},
tooltip: CC_DEV && 'i18n:COMPONENT.sprite.fill_range'
@@ -374,7 +374,7 @@ var Sprite = cc.Class({
this._isTrimmedMode = value;
if ((this._type === SpriteType.SIMPLE || this._type === SpriteType.MESH) &&
this._renderData) {
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
}
}
},
@@ -484,7 +484,7 @@ var Sprite = cc.Class({
if (!this._spriteFrame || !this._spriteFrame.textureLoaded()) {
// Do not render when sprite frame is not ready
this.node._renderFlag &= ~(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA);
this.disableRender();
}
this._updateAssembler();
@@ -503,7 +503,7 @@ var Sprite = cc.Class({
_onNodeSizeDirty () {
if (!this._renderData) return;
this.markUpdateRenderData();
this.markForUpdateRenderData(true);
},
_updateAssembler: function () {
@@ -517,25 +517,23 @@ var Sprite = cc.Class({
if (!this._renderData) {
this._renderData = this._assembler.createData(this);
this._renderData.material = this._material;
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
this.markForUpdateRenderData(true);
}
},
_activateMaterial: function () {
this.node._renderFlag &= ~RenderFlow.FLAG_RENDER;
if (!this.enabledInHierarchy) {
this.disableRender();
return;
}
let spriteFrame = this._spriteFrame;
// cannot be activated if texture not loaded yet
if (!spriteFrame || !spriteFrame.textureLoaded()) {
this.disableRender();
return;
}
this.markUpdateRenderData();
// Get material
let texture = spriteFrame.getTexture();
let material;
@@ -567,7 +565,8 @@ var Sprite = cc.Class({
else {
material.updateHash();
}
this.node._renderFlag |= RenderFlow.FLAG_RENDER;
this.markForUpdateRenderData(true);
this.markForRender(true);
},
_updateBlendFunc: function () {
@@ -597,11 +596,16 @@ var Sprite = cc.Class({
}
},
markUpdateRenderData () {
this._super();
markForUpdateRenderData (enable) {
if (enable && this._material && this.enabledInHierarchy) {
this.node._renderFlag |= RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
else if (!enable) {
this.node._renderFlag &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
}
let renderData = this._renderData;
if (renderData) {
if (renderData && enable) {
renderData.uvDirty = true;
renderData.vertDirty = true;
}
+12 -4
View File
@@ -978,7 +978,7 @@ var ParticleSystem = cc.Class({
onEnable: function () {
this._super();
// should add render flag after particle loaded
this.node._renderFlag &= !(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA);
this.disableRender();
this._updateMaterial();
},
@@ -996,7 +996,8 @@ var ParticleSystem = cc.Class({
this._focused = true;
if (this.preview) {
this.resetSystem();
this.node._renderFlag |= RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA;
this.markForUpdateRenderData(true);
this.markForRender(true);
var self = this;
this._previewTimer = setInterval(function () {
@@ -1019,7 +1020,7 @@ var ParticleSystem = cc.Class({
if (this.preview) {
this.resetSystem();
this.stopSystem();
this.node._renderFlag &= !(RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA);
this.disableRender();
cc.engine.repaintInEditMode();
}
if (this._previewTimer) {
@@ -1327,8 +1328,13 @@ var ParticleSystem = cc.Class({
},
_updateMaterial: function () {
if (!this.enabledInHierarchy) {
this.disableRender();
return;
}
// cannot be activated if texture not loaded yet
if (!this._texture || !this._texture.loaded) {
this.markForRender(false);
if (this._spriteFrame) {
this._applySpriteFrame();
}
@@ -1351,7 +1357,8 @@ var ParticleSystem = cc.Class({
this._updateBlendFunc();
this.node._renderFlag |= RenderFlow.FLAG_RENDER | RenderFlow.FLAG_UPDATE_RENDER_DATA;
this.markForUpdateRenderData(true);
this.markForRender(true);
},
_updateBlendFunc: function () {
@@ -1370,6 +1377,7 @@ var ParticleSystem = cc.Class({
_finishedSimulation: function () {
if (this._autoRemoveOnFinish && this._vfx.stopped) {
this.disableRender();
this.node.destroy();
}
}
@@ -89,7 +89,7 @@ var particleSystemAssembler = {
vfx.step(cc.director.getDeltaTime());
// check finish
if (running && vfx.stopped) {
comp._finishedSimulation();
comp.scheduleOnce(comp._finishedSimulation, 0);
}
renderData.vertexCount = vfx.buffers.indexes.length;