Merge pull request #2526 from minggo/optimize

optimize performance
This commit is contained in:
pandamicro
2018-04-12 20:34:15 +08:00
committed by GitHub
4 changed files with 77 additions and 59 deletions
+12
View File
@@ -9,6 +9,15 @@ class Effect {
this._properties = properties;
this._defines = defines;
var techniqueObjs = [];
var techniqueObj;
for (var i = 0, len = techniques.length; i < len; ++i) {
techniqueObj = techniques[i]._nativeObj;
techniqueObjs.push(techniqueObj);
}
this._nativeObj = new renderer.EffectNative(techniqueObjs, properties, defines);
// TODO: check if params is valid for current technique???
}
@@ -37,6 +46,7 @@ class Effect {
setProperty(name, value) {
// TODO: check if params is valid for current technique???
this._properties[name] = value;
this._nativeObj.setProperty(name, value);
}
getDefine(name) {
@@ -60,6 +70,8 @@ class Effect {
}
}
this._nativeObj.setDefine(name, value);
console.warn(`Failed to set define ${name}, define not found.`);
}
+60
View File
@@ -38,10 +38,14 @@ class Pass {
this._stencilZFailOpBack = gfx.STENCIL_OP_KEEP;
this._stencilZPassOpBack = gfx.STENCIL_OP_KEEP;
this._stencilWriteMaskBack = 0xff;
this._binary = new Uint32Array(25);
this._updateBinary();
}
setCullMode(cullMode) {
this._cullMode = cullMode;
this._binary[0] = cullMode;
}
setBlend(
@@ -61,6 +65,14 @@ class Pass {
this._blendSrcAlpha = blendSrcAlpha;
this._blendDstAlpha = blendDstAlpha;
this._blendColor = blendColor;
this._binary[1] = this._blendEq;
this._binary[2] = this._blendSrc;
this._binary[3] = this._blendDst;
this._binary[4] = this._blendAlphaEq;
this._binary[5] = this._blendSrcAlpha;
this._binary[6] = this._blendDstAlpha;
this._binary[7] = this._blendColor;
}
setDepth(
@@ -71,6 +83,10 @@ class Pass {
this._depthTest = depthTest;
this._depthWrite = depthWrite;
this._depthFunc = depthFunc;
this._binary[8] = this._depthTest;
this._binary[9] = this._depthWrite;
this._binary[10] = this._depthFunc;
}
setStencilFront(
@@ -90,6 +106,14 @@ class Pass {
this._stencilZFailOpFront = stencilZFailOp;
this._stencilZPassOpFront = stencilZPassOp;
this._stencilWriteMaskFront = stencilWriteMask;
this._binary[11] = this._stencilFuncFront;
this._binary[12] = this._stencilRefFront;
this._binary[13] = this._stencilMaskFront;
this._binary[14] = this._stencilFailOpFront;
this._binary[15] = this._stencilZFailOpFront;
this._binary[16] = this._stencilZPassOpFront;
this._binary[17] = this._stencilWriteMaskFront;
}
setStencilBack(
@@ -109,6 +133,42 @@ class Pass {
this._stencilZFailOpBack = stencilZFailOp;
this._stencilZPassOpBack = stencilZPassOp;
this._stencilWriteMaskBack = stencilWriteMask;
this._binary[18] = this._stencilFuncBack;
this._binary[19] = this._stencilRefBack;
this._binary[20] = this._stencilMaskBack;
this._binary[21] = this._stencilFailOpBack;
this._binary[22] = this._stencilZFailOpBack;
this._binary[23] = this._stencilZPassOpBack;
this._binary[24] = this._stencilWriteMaskBack;
}
_updateBinary() {
this._binary[0] = this._cullMode;
this._binary[1] = this._blendEq;
this._binary[2] = this._blendSrc;
this._binary[3] = this._blendDst;
this._binary[4] = this._blendAlphaEq;
this._binary[5] = this._blendSrcAlpha;
this._binary[6] = this._blendDstAlpha;
this._binary[7] = this._blendColor;
this._binary[8] = this._depthTest;
this._binary[9] = this._depthWrite;
this._binary[10] = this._depthFunc;
this._binary[11] = this._stencilFuncFront;
this._binary[12] = this._stencilRefFront;
this._binary[13] = this._stencilMaskFront;
this._binary[14] = this._stencilFailOpFront;
this._binary[15] = this._stencilZFailOpFront;
this._binary[16] = this._stencilZPassOpFront;
this._binary[17] = this._stencilWriteMaskFront;
this._binary[18] = this._stencilFuncBack;
this._binary[19] = this._stencilRefBack;
this._binary[20] = this._stencilMaskBack;
this._binary[21] = this._stencilFailOpBack;
this._binary[22] = this._stencilZFailOpBack;
this._binary[23] = this._stencilZPassOpBack;
this._binary[24] = this._stencilWriteMaskBack;
}
}
-59
View File
@@ -93,65 +93,6 @@ cc.defineGetterSetter(_p, "_count", _p.getCount, _p.setCount);
// Scene
_p = renderer.Scene.prototype;
// _p.addModel = function(model) {
// // var modelNative = new renderer.ModelNative();
// // var effects = model._effects;
// // var effectNatives = [];
// // for (var i = 0, len = effects.length; i < len; ++i) {
// // var effect = effects[i];
// // var techniques = effect._techniques;
// // var techniqueNatives = [];
// // for (var j = 0, len1 = techniques.length; j < len1; ++j) {
// // var technique = techniques[j];
// // var passesNatives = [];
// // var passes = technique.passes;
// // for (var k =0, len2 = passes.length; k < len2; ++k) {
// // var pass = passes[k];
// // var passNative = new renderer.PassNative(pass._programName);
// // passNative.setCullMode(pass._cullMode);
// // passNative.setBlend(pass._blendEq,
// // pass._blendSrc,
// // pass._blendDst,
// // pass._blendAlphaEq,
// // pass._blendSrcAlpha,
// // pass._blendDstAlpha,
// // pass._blendColor);
// // passNative.setDepth(pass._depthTest, pass._depthWrite, pass._depthFunc);
// // passNative.setStencilFront(pass._stencilFuncFront,
// // pass._stencilRefFront,
// // pass._stencilMaskFront,
// // pass._stencilFailOpFront,
// // pass._stencilZFailOpFront,
// // pass._stencilZPassOpFront,
// // pass._stencilWriteMaskFront);
// // passNative.setStencilBack(pass._stencilFuncBack,
// // pass._stencilRefBack,
// // pass._stencilMaskBack,
// // pass._stencilFailOpBack,
// // pass._stencilZFailOpBack,
// // pass._stencilZPassOpBack,
// // pass._stencilWriteMaskBack);
// // passesNatives.push(passNative);
// // }
// // var techniqueNative = new renderer.TechniqueNative(technique._stages, technique._parameters, passesNatives, technique._layer);
// // techniqueNatives.push(techniqueNative);
// // }
// // var effectNative = new renderer.EffectNative(techniqueNatives, effect._properties, effect._defines);
// // modelNative.addEffect(effectNative);
// // }
// // modelNative.setDynamicIA(model._dynamicIA);
// // modelNative.setViewId(model._viewID);
// // modelNative.setNode(model._node);
// // var inputAssemblers = model._inputAssemblers;
// // for (var k = 0, len2 = inputAssemblers.length; k < len2; ++k) {
// // modelNative.addInputAssembler(inputAssemblers[k]);
// // }
// // this.addModelNative(modelNative);
// this.addModelNative(model);
// };
_p.removeModel = function() {}
+5
View File
@@ -19,11 +19,16 @@ class Technique {
this._layer = layer;
this._stages = stages;
// TODO: this._version = 'webgl' or 'webgl2' // ????
this._nativeObj = new renderer.TechniqueNative(stages, parameters, passes, layer);
}
setStages(stages) {
this._stageIDs = config.stageIDs(stages);
this._stages = stages;
this._nativeObj.setStages(stages);
}
// get passes() {