Update mask assembler and mask materials (#2688)

This commit is contained in:
pandamicro
2018-05-16 10:15:21 +08:00
committed by GitHub
parent ec176ce336
commit 172f520259
4 changed files with 55 additions and 24 deletions
+11 -5
View File
@@ -109,7 +109,7 @@ let Mask = cc.Class({
this.destroyRenderData(this._renderData);
this._renderData = null;
}
this._updateMaterial();
this._activateMaterial();
},
type: MaskType,
tooltip: CC_DEV && 'i18n:COMPONENT.mask.type',
@@ -251,7 +251,7 @@ let Mask = cc.Class({
}
// Reactivate material
if (this.enabledInHierarchy) {
this._updateMaterial();
this._activateMaterial();
}
},
@@ -271,16 +271,18 @@ let Mask = cc.Class({
}
},
_updateMaterial: function () {
_activateMaterial: function () {
// cannot be activated if texture not loaded yet
if (this._type === MaskType.IMAGE_STENCIL && (!this.spriteFrame || !this.spriteFrame.textureLoaded)) {
return;
}
// Init material
if (!this._material) {
if (!this._frontMaterial) {
this._frontMaterial = new StencilMaterial();
this._endMaterial = new StencilMaterial();
}
if (!this._material) {
this._material = this._frontMaterial;
}
@@ -288,15 +290,19 @@ let Mask = cc.Class({
if (this._type === MaskType.IMAGE_STENCIL) {
let texture = this.spriteFrame.getTexture();
this._frontMaterial.useTexture = true;
this._frontMaterial.useColor = true;
this._frontMaterial.texture = texture;
this._frontMaterial.alphaThreshold = this.alphaThreshold;
this._endMaterial.useTexture = true;
this._endMaterial.useColor = true;
this._endMaterial.texture = texture;
this._endMaterial.alphaThreshold = this.alphaThreshold;
}
else {
this._frontMaterial.useTexture = false;
this._frontMaterial.useColor = false;
this._endMaterial.useTexture = false;
this._endMaterial.useColor = false;
}
this._frontMaterial.updateHash();
this._endMaterial.updateHash();
@@ -336,7 +342,7 @@ let Mask = cc.Class({
this._renderDatas = [];
// for graphic stencil data
this._graphics = null;
this._updateMaterial();
this._activateMaterial();
this.node._renderFlag |= RenderFlow.FLAG_POST_RENDER | RenderFlow.FLAG_POST_UPDATE_RENDER_DATA;
},
@@ -137,25 +137,24 @@ let maskEndAssembler = js.addon({
else {
mask._material = mask._endMaterial;
}
let material = mask.getMaterial();
let datas;
if (mask._type === Mask.Type.IMAGE_STENCIL) {
datas = mask._renderDatas;
let data = mask._renderData;
data.material = material;
}
else {
datas = mask._graphics._impl._renderDatas;
let datas = mask._graphics._impl._renderDatas;
for (let i = 0; i < datas.length; i++) {
datas[i].material = material;
}
}
let material = mask.getMaterial();
for (let i = 0; i < datas.length; i++) {
datas[i].material = material;
}
return datas;
},
fillBuffers (mask, renderer) {
// Invalid state
if (mask._type !== Mask.Type.IMAGE_STENCIL || mask.spriteFrame) {
// HACK: Must pop mask after batch, so we can only put this logic in fillVertexBuffer or fillIndexBuffer
// HACK: Must pop mask after batch, so we can only put this logic in fillBuffers
_stencilMgr.popMask();
// vertex buffer
+18 -5
View File
@@ -14595,7 +14595,7 @@ var SpriteMaterial = (function (Material$$1) {
this._mainTech = mainTech;
this._texture = null;
this._color = {r: 0, g: 0, b: 0, a: 1};
this._color = {r: 1, g: 1, b: 1, a: 1};
}
if ( Material$$1 ) SpriteMaterial.__proto__ = Material$$1;
@@ -14771,7 +14771,8 @@ var StencilMaterial = (function (Material$$1) {
['transparent'],
[
{ name: 'texture', type: renderer.PARAM_TEXTURE_2D },
{ name: 'alphaThreshold', type: renderer.PARAM_FLOAT } ],
{ name: 'alphaThreshold', type: renderer.PARAM_FLOAT },
{ name: 'color', type: renderer.PARAM_COLOR4 } ],
[
this._pass
]
@@ -14780,11 +14781,15 @@ var StencilMaterial = (function (Material$$1) {
this._effect = new renderer.Effect(
[
mainTech ],
{},
{
'color': {r: 0, g: 0, b: 0, a: 1}
},
[
{ name: 'useTexture', value: true },
{ name: 'useModel', value: false },
{ name: 'alphaTest', value: true } ]
{ name: 'alphaTest', value: true },
{ name: 'use2DPos', value: true },
{ name: 'useColor', value: true } ]
);
this._mainTech = mainTech;
@@ -14795,7 +14800,7 @@ var StencilMaterial = (function (Material$$1) {
StencilMaterial.prototype = Object.create( Material$$1 && Material$$1.prototype );
StencilMaterial.prototype.constructor = StencilMaterial;
var prototypeAccessors = { effect: { configurable: true },useTexture: { configurable: true },texture: { configurable: true },alphaThreshold: { configurable: true } };
var prototypeAccessors = { effect: { configurable: true },useTexture: { configurable: true },useColor: { configurable: true },texture: { configurable: true },alphaThreshold: { configurable: true } };
prototypeAccessors.effect.get = function () {
return this._effect;
@@ -14809,6 +14814,14 @@ var StencilMaterial = (function (Material$$1) {
this._effect.define('useTexture', val);
};
prototypeAccessors.useColor.get = function () {
this._effect.getDefine('useColor');
};
prototypeAccessors.useColor.set = function (val) {
this._effect.define('useColor', val);
};
prototypeAccessors.texture.get = function () {
return this._texture;
};
+18 -5
View File
@@ -2276,7 +2276,7 @@ var SpriteMaterial = (function (Material$$1) {
this._mainTech = mainTech;
this._texture = null;
this._color = {r: 0, g: 0, b: 0, a: 1};
this._color = {r: 1, g: 1, b: 1, a: 1};
}
if ( Material$$1 ) SpriteMaterial.__proto__ = Material$$1;
@@ -2452,7 +2452,8 @@ var StencilMaterial = (function (Material$$1) {
['transparent'],
[
{ name: 'texture', type: renderer.PARAM_TEXTURE_2D },
{ name: 'alphaThreshold', type: renderer.PARAM_FLOAT } ],
{ name: 'alphaThreshold', type: renderer.PARAM_FLOAT },
{ name: 'color', type: renderer.PARAM_COLOR4 } ],
[
this._pass
]
@@ -2461,11 +2462,15 @@ var StencilMaterial = (function (Material$$1) {
this._effect = new renderer.Effect(
[
mainTech ],
{},
{
'color': {r: 1, g: 1, b: 1, a: 1}
},
[
{ name: 'useTexture', value: true },
{ name: 'useModel', value: false },
{ name: 'alphaTest', value: true } ]
{ name: 'alphaTest', value: true },
{ name: 'use2DPos', value: true },
{ name: 'useColor', value: true } ]
);
this._mainTech = mainTech;
@@ -2476,7 +2481,7 @@ var StencilMaterial = (function (Material$$1) {
StencilMaterial.prototype = Object.create( Material$$1 && Material$$1.prototype );
StencilMaterial.prototype.constructor = StencilMaterial;
var prototypeAccessors = { effect: { configurable: true },useTexture: { configurable: true },texture: { configurable: true },alphaThreshold: { configurable: true } };
var prototypeAccessors = { effect: { configurable: true },useTexture: { configurable: true },useColor: { configurable: true },texture: { configurable: true },alphaThreshold: { configurable: true } };
prototypeAccessors.effect.get = function () {
return this._effect;
@@ -2490,6 +2495,14 @@ var StencilMaterial = (function (Material$$1) {
this._effect.define('useTexture', val);
};
prototypeAccessors.useColor.get = function () {
this._effect.getDefine('useColor');
};
prototypeAccessors.useColor.set = function (val) {
this._effect.define('useColor', val);
};
prototypeAccessors.texture.get = function () {
return this._texture;
};