Skip to content

Commit e1700a8

Browse files
committed
Merge pull request #3260 from 1scaR1/fix_clipping
Fix nested clipping node
2 parents c11a8fc + 4b7ebfb commit e1700a8

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,22 @@
180180

181181
proto._onAfterVisit = function(ctx){
182182
var gl = ctx || cc._renderContext;
183-
184-
if (!this._currentStencilEnabled)
185-
gl.disable(gl.STENCIL_TEST);
186183

187-
// we are done using this layer, decrement
188184
cc.ClippingNode.WebGLRenderCmd._layer--;
189-
}
185+
186+
if (this._currentStencilEnabled)
187+
{
188+
var mask_layer = 0x1 << ccui.Layout.WebGLRenderCmd._layer;
189+
var mask_layer_l = mask_layer - 1;
190+
var mask_layer_le = mask_layer | mask_layer_l;
191+
192+
gl.stencilMask(mask_layer);
193+
gl.stencilFunc(gl.EQUAL, mask_layer_le, mask_layer_le);
194+
}
195+
else
196+
{
197+
gl.disable(gl.STENCIL_TEST);
198+
199+
}
200+
};
190201
})();

extensions/ccui/layouts/UILayoutWebGLRenderCmd.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,21 @@
108108
proto._onAfterVisitStencil = function(ctx){
109109
var gl = ctx || cc._renderContext;
110110

111-
if (!this._currentStencilEnabled)
112-
gl.disable(gl.STENCIL_TEST);
113111
ccui.Layout.WebGLRenderCmd._layer--;
112+
113+
if (this._currentStencilEnabled)
114+
{
115+
var mask_layer = 0x1 << ccui.Layout.WebGLRenderCmd._layer;
116+
var mask_layer_l = mask_layer - 1;
117+
var mask_layer_le = mask_layer | mask_layer_l;
118+
119+
gl.stencilMask(mask_layer);
120+
gl.stencilFunc(gl.EQUAL, mask_layer_le, mask_layer_le);
121+
}
122+
else
123+
{
124+
gl.disable(gl.STENCIL_TEST);
125+
}
114126
};
115127

116128
proto._onBeforeVisitScissor = function(ctx){

0 commit comments

Comments
 (0)