@@ -47,12 +47,14 @@ cc.stencilBits = -1;
4747 * @property {cc.Node } stencil - he cc.Node to use as a stencil to do the clipping.
4848 */
4949cc . ClippingNode = cc . Node . extend ( /** @lends cc.ClippingNode# */ {
50- alphaThreshold : 0 ,
5150 inverted : false ,
51+ _alphaThreshold : 0 ,
5252
5353 _stencil : null ,
5454 _className : "ClippingNode" ,
5555
56+ _originStencilProgram : null ,
57+
5658 /**
5759 * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
5860 * @param {cc.Node } [stencil=null]
@@ -61,6 +63,9 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
6163 stencil = stencil || null ;
6264 cc . Node . prototype . ctor . call ( this ) ;
6365 this . _stencil = stencil ;
66+ if ( stencil ) {
67+ this . _originStencilProgram = stencil . getShaderProgram ( ) ;
68+ }
6469 this . alphaThreshold = 1 ;
6570 this . inverted = false ;
6671 this . _renderCmd . initStencilBits ( ) ;
@@ -154,15 +159,19 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
154159 * @return {Number }
155160 */
156161 getAlphaThreshold : function ( ) {
157- return this . alphaThreshold ;
162+ return this . _alphaThreshold ;
158163 } ,
159164
160165 /**
161166 * set alpha threshold.
162167 * @param {Number } alphaThreshold
163168 */
164169 setAlphaThreshold : function ( alphaThreshold ) {
165- this . alphaThreshold = alphaThreshold ;
170+ if ( alphaThreshold === 1 && alphaThreshold !== this . _alphaThreshold ) {
171+ // should reset program used by _stencil
172+ this . _renderCmd . resetProgramByStencil ( ) ;
173+ }
174+ this . _alphaThreshold = alphaThreshold ;
166175 } ,
167176
168177 /**
@@ -202,6 +211,8 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
202211 setStencil : function ( stencil ) {
203212 if ( this . _stencil === stencil )
204213 return ;
214+ if ( stencil )
215+ this . _originStencilProgram = stencil . getShaderProgram ( ) ;
205216 this . _renderCmd . setStencil ( stencil ) ;
206217 } ,
207218
@@ -219,6 +230,9 @@ var _p = cc.ClippingNode.prototype;
219230/** @expose */
220231_p . stencil ;
221232cc . defineGetterSetter ( _p , "stencil" , _p . getStencil , _p . setStencil ) ;
233+ /** @expose */
234+ _p . alphaThreshold ;
235+ cc . defineGetterSetter ( _p , "alphaThreshold" , _p . getAlphaThreshold , _p . setAlphaThreshold ) ;
222236
223237
224238/**
0 commit comments