@@ -47,12 +47,14 @@ cc.stencilBits = -1;
47
47
* @property {cc.Node } stencil - he cc.Node to use as a stencil to do the clipping.
48
48
*/
49
49
cc . ClippingNode = cc . Node . extend ( /** @lends cc.ClippingNode# */ {
50
- alphaThreshold : 0 ,
51
50
inverted : false ,
51
+ _alphaThreshold : 0 ,
52
52
53
53
_stencil : null ,
54
54
_className : "ClippingNode" ,
55
55
56
+ _originStencilProgram : null ,
57
+
56
58
/**
57
59
* Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
58
60
* @param {cc.Node } [stencil=null]
@@ -61,6 +63,9 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
61
63
stencil = stencil || null ;
62
64
cc . Node . prototype . ctor . call ( this ) ;
63
65
this . _stencil = stencil ;
66
+ if ( stencil ) {
67
+ this . _originStencilProgram = stencil . getShaderProgram ( ) ;
68
+ }
64
69
this . alphaThreshold = 1 ;
65
70
this . inverted = false ;
66
71
this . _renderCmd . initStencilBits ( ) ;
@@ -154,15 +159,19 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
154
159
* @return {Number }
155
160
*/
156
161
getAlphaThreshold : function ( ) {
157
- return this . alphaThreshold ;
162
+ return this . _alphaThreshold ;
158
163
} ,
159
164
160
165
/**
161
166
* set alpha threshold.
162
167
* @param {Number } alphaThreshold
163
168
*/
164
169
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 ;
166
175
} ,
167
176
168
177
/**
@@ -202,6 +211,8 @@ cc.ClippingNode = cc.Node.extend(/** @lends cc.ClippingNode# */{
202
211
setStencil : function ( stencil ) {
203
212
if ( this . _stencil === stencil )
204
213
return ;
214
+ if ( stencil )
215
+ this . _originStencilProgram = stencil . getShaderProgram ( ) ;
205
216
this . _renderCmd . setStencil ( stencil ) ;
206
217
} ,
207
218
@@ -219,6 +230,9 @@ var _p = cc.ClippingNode.prototype;
219
230
/** @expose */
220
231
_p . stencil ;
221
232
cc . defineGetterSetter ( _p , "stencil" , _p . getStencil , _p . setStencil ) ;
233
+ /** @expose */
234
+ _p . alphaThreshold ;
235
+ cc . defineGetterSetter ( _p , "alphaThreshold" , _p . getAlphaThreshold , _p . setAlphaThreshold ) ;
222
236
223
237
224
238
/**
0 commit comments