Skip to content

Commit fe175fa

Browse files
author
Travis Gesslein
committed
cached some more calls
1 parent 37abe89 commit fe175fa

File tree

3 files changed

+82
-20
lines changed

3 files changed

+82
-20
lines changed

CCBoot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,7 @@ cc.game = /** @lends cc.game# */{
25232523
win.glInst = cc.glExt.instanced_arrays;
25242524

25252525
cc.renderer.initialize();
2526+
cc.initGLParameterCache();
25262527
}
25272528

25282529
cc._gameDiv = localContainer;

cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,28 @@
179179
this._mask_layer_le = mask_layer | mask_layer_l;
180180

181181
this._currentStencilEnabled = gl.isEnabled(gl.STENCIL_TEST);
182-
this._currentStencilWriteMask = gl.getParameter(gl.STENCIL_WRITEMASK);
183-
this._currentStencilFunc = gl.getParameter(gl.STENCIL_FUNC);
184-
this._currentStencilRef = gl.getParameter(gl.STENCIL_REF);
185-
this._currentStencilValueMask = gl.getParameter(gl.STENCIL_VALUE_MASK);
186-
this._currentStencilFail = gl.getParameter(gl.STENCIL_FAIL);
187-
this._currentStencilPassDepthFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);
188-
this._currentStencilPassDepthPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);
182+
this._currentStencilWriteMask = cc.glGetParameter(gl.STENCIL_WRITEMASK);
183+
this._currentStencilFunc = cc.glGetParameter(gl.STENCIL_FUNC);
184+
this._currentStencilRef = cc.glGetParameter(gl.STENCIL_REF);
185+
this._currentStencilValueMask = cc.glGetParameter(gl.STENCIL_VALUE_MASK);
186+
this._currentStencilFail = cc.glGetParameter(gl.STENCIL_FAIL);
187+
this._currentStencilPassDepthFail = cc.glGetParameter(gl.STENCIL_PASS_DEPTH_FAIL);
188+
this._currentStencilPassDepthPass = cc.glGetParameter(gl.STENCIL_PASS_DEPTH_PASS);
189189

190190
// enable stencil use
191191
gl.enable(gl.STENCIL_TEST);
192-
gl.stencilMask(mask_layer);
193-
this._currentDepthWriteMask = gl.getParameter(gl.DEPTH_WRITEMASK);
192+
cc.glStencilMask(mask_layer);
193+
this._currentDepthWriteMask = cc.glGetParameter(gl.DEPTH_WRITEMASK);
194194

195-
gl.depthMask(false);
195+
cc.glDepthMask(false);
196196

197-
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
198-
gl.stencilOp(!node.inverted ? gl.ZERO : gl.REPLACE, gl.KEEP, gl.KEEP);
197+
cc.glStencilFunc(gl.NEVER, mask_layer, mask_layer);
198+
cc.glStencilOp(!node.inverted ? gl.ZERO : gl.REPLACE, gl.KEEP, gl.KEEP);
199199

200200
this._drawFullScreenQuadClearStencil();
201201

202-
gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
203-
gl.stencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);
202+
cc.glStencilFunc(gl.NEVER, mask_layer, mask_layer);
203+
cc.glStencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP);
204204

205205
if (node.alphaThreshold < 1) { //TODO desktop
206206
var program = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLORALPHATEST);
@@ -213,16 +213,16 @@
213213
};
214214

215215
proto._onAfterDrawStencil = function(){
216-
gl.depthMask(this._currentDepthWriteMask);
216+
cc.glDepthMask(this._currentDepthWriteMask);
217217

218-
gl.stencilFunc(gl.EQUAL, this._mask_layer_le, this._mask_layer_le);
219-
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
218+
cc.glStencilFunc(gl.EQUAL, this._mask_layer_le, this._mask_layer_le);
219+
cc.glStencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
220220
};
221221

222222
proto._onAfterVisit = function(){
223-
gl.stencilFunc(this._currentStencilFunc, this._currentStencilRef, this._currentStencilValueMask);
224-
gl.stencilOp(this._currentStencilFail, this._currentStencilPassDepthFail, this._currentStencilPassDepthPass);
225-
gl.stencilMask(this._currentStencilWriteMask);
223+
cc.glStencilFunc(this._currentStencilFunc, this._currentStencilRef, this._currentStencilValueMask);
224+
cc.glStencilOp(this._currentStencilFail, this._currentStencilPassDepthFail, this._currentStencilPassDepthPass);
225+
cc.glStencilMask(this._currentStencilWriteMask);
226226
if (!this._currentStencilEnabled)
227227
gl.disable(gl.STENCIL_TEST);
228228

cocos2d/shaders/CCGLStateCache.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,4 +408,65 @@ cc.glActiveTexture =function(slot)
408408
activeTextureSlot = slot;
409409
gl.activeTexture(slot);
410410
}
411+
}
412+
413+
cc._paramCache = {
414+
415+
};
416+
417+
cc.initGLParameterCache = function()
418+
{
419+
function cacheParam(param)
420+
{
421+
cc._paramCache[param] = gl.getParameter(param);
422+
}
423+
424+
var params = [gl.DEPTH_WRITEMASK, gl.STENCIL_WRITEMASK, gl.STENCIL_FUNC, gl.STENCIL_REF, gl.STENCIL_VALUE_MASK, gl.STENCIL_FAIL, gl.STENCIL_PASS_DEPTH_FAIL, gl.STENCIL_PASS_DEPTH_PASS];
425+
426+
params.forEach(cacheParam);
427+
}
428+
429+
cc.glGetParameter = function(val)
430+
{
431+
return this._paramCache[val];
432+
}
433+
434+
cc.glStencilMask = function(val)
435+
{
436+
if (cc._paramCache[gl.STENCIL_WRITEMASK] !== val)
437+
{
438+
cc._paramCache[gl.STENCIL_WRITEMASK] = val;
439+
gl.stencilMask(val);
440+
}
441+
}
442+
443+
cc.glStencilFunc = function(func,ref,valueMask)
444+
{
445+
if(cc._paramCache[gl.STENCIL_FUNC] !== func || cc._paramCache[gl.STENCIL_REF] !== ref || cc._paramCache[gl.STENCIL_VALUE_MASK] !== valueMask)
446+
{
447+
cc._paramCache[gl.STENCIL_FUNC] = func;
448+
cc._paramCache[gl.STENCIL_REF] = ref;
449+
cc._paramCache[gl.STENCIL_VALUE_MASK] = valueMask;
450+
gl.stencilFunc(func, ref, valueMask);
451+
}
452+
}
453+
454+
cc.glStencilOp = function(stencilFail, depthFail, depthPass)
455+
{
456+
if(cc._paramCache[gl.STENCIL_FAIL] !== stencilFail || cc._paramCache[gl.STENCIL_PASS_DEPTH_FAIL] !== depthFail || cc._paramCache[gl.STENCIL_PASS_DEPTH_PASS] !== depthPass)
457+
{
458+
cc._paramCache[gl.STENCIL_FAIL] = stencilFail;
459+
cc._paramCache[gl.STENCIL_PASS_DEPTH_FAIL] = depthFail;
460+
cc._paramCache[gl.STENCIL_PASS_DEPTH_PASS] = depthPass;
461+
gl.stencilOp(stencilFail, depthFail, depthPass);
462+
}
463+
}
464+
465+
cc.glDepthMask = function(mask)
466+
{
467+
if (cc._paramCache[gl.DEPTH_WRITEMASK] !== mask)
468+
{
469+
cc._paramCache[gl.DEPTH_WRITEMASK] = mask;
470+
gl.depthMask(mask);
471+
}
411472
}

0 commit comments

Comments
 (0)