|
32 | 32 | this._afterDrawStencilCmd = new cc.CustomRenderCmd(this, this._onAfterDrawStencil);
|
33 | 33 | this._afterVisitCmd = new cc.CustomRenderCmd(this, this._onAfterVisit);
|
34 | 34 |
|
35 |
| - this._currentStencilFunc = null; |
36 |
| - this._currentStencilRef = null; |
37 |
| - this._currentStencilValueMask = null; |
38 |
| - this._currentStencilFail = null; |
39 |
| - this._currentStencilPassDepthFail = null; |
40 |
| - this._currentStencilPassDepthPass = null; |
41 |
| - this._currentStencilWriteMask = null; |
42 | 35 | this._currentStencilEnabled = null;
|
43 |
| - this._currentDepthWriteMask = null; |
44 | 36 | this._mask_layer_le = null;
|
45 | 37 | };
|
46 | 38 |
|
|
142 | 134 | node._stencil._parent = node;
|
143 | 135 | };
|
144 | 136 |
|
145 |
| - proto._drawFullScreenQuadClearStencil = function () { |
146 |
| - // draw a fullscreen solid rectangle to clear the stencil buffer |
147 |
| - var projStack = cc.projection_matrix_stack; |
148 |
| - //cc.kmGLMatrixMode(cc.KM_GL_PROJECTION); |
149 |
| - //cc.kmGLPushMatrix(); |
150 |
| - //cc.kmGLLoadIdentity(); |
151 |
| - projStack.push(); |
152 |
| - projStack.top.identity(); |
153 |
| - |
154 |
| - //cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW); |
155 |
| - //cc.kmGLPushMatrix(); |
156 |
| - //cc.kmGLLoadIdentity(); |
157 |
| - var modelViewStack = cc.modelview_matrix_stack; |
158 |
| - modelViewStack.push(); |
159 |
| - modelViewStack.top.identity(); |
160 |
| - |
161 |
| - cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255)); |
162 |
| - |
163 |
| - //cc.kmGLMatrixMode(cc.KM_GL_PROJECTION); |
164 |
| - //cc.kmGLPopMatrix(); |
165 |
| - projStack.pop(); |
166 |
| - |
167 |
| - //cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW); |
168 |
| - //cc.kmGLPopMatrix(); |
169 |
| - modelViewStack.pop(); |
170 |
| - }; |
171 |
| - |
172 | 137 | proto._onBeforeVisit = function(ctx){
|
173 | 138 | var gl = ctx || cc._renderContext, node = this._node;
|
174 | 139 | cc.ClippingNode.WebGLRenderCmd._layer++;
|
|
182 | 147 | this._mask_layer_le = mask_layer | mask_layer_l;
|
183 | 148 | // manually save the stencil state
|
184 | 149 | this._currentStencilEnabled = gl.isEnabled(gl.STENCIL_TEST);
|
185 |
| - this._currentStencilWriteMask = gl.getParameter(gl.STENCIL_WRITEMASK); |
186 |
| - this._currentStencilFunc = gl.getParameter(gl.STENCIL_FUNC); |
187 |
| - this._currentStencilRef = gl.getParameter(gl.STENCIL_REF); |
188 |
| - this._currentStencilValueMask = gl.getParameter(gl.STENCIL_VALUE_MASK); |
189 |
| - this._currentStencilFail = gl.getParameter(gl.STENCIL_FAIL); |
190 |
| - this._currentStencilPassDepthFail = gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL); |
191 |
| - this._currentStencilPassDepthPass = gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS); |
192 | 150 |
|
| 151 | + gl.clear(gl.DEPTH_BUFFER_BIT); |
193 | 152 | // enable stencil use
|
194 | 153 | gl.enable(gl.STENCIL_TEST);
|
195 |
| - gl.stencilMask(mask_layer); |
196 |
| - this._currentDepthWriteMask = gl.getParameter(gl.DEPTH_WRITEMASK); |
197 | 154 |
|
198 | 155 | gl.depthMask(false);
|
199 | 156 |
|
| 157 | + gl.clear(gl.STENCIL_BUFFER_BIT); |
200 | 158 | gl.stencilFunc(gl.NEVER, mask_layer, mask_layer);
|
201 |
| - gl.stencilOp(!node.inverted ? gl.ZERO : gl.REPLACE, gl.KEEP, gl.KEEP); |
202 |
| - |
203 |
| - this._drawFullScreenQuadClearStencil(); |
| 159 | + gl.stencilOp(gl.REPLACE, gl.KEEP, gl.KEEP); |
204 | 160 |
|
205 |
| - gl.stencilFunc(gl.NEVER, mask_layer, mask_layer); |
206 |
| - gl.stencilOp(!node.inverted ? gl.REPLACE : gl.ZERO, gl.KEEP, gl.KEEP); |
| 161 | + gl.stencilMask(mask_layer); |
| 162 | + gl.clear(gl.STENCIL_BUFFER_BIT); |
207 | 163 |
|
208 | 164 | if (node.alphaThreshold < 1) { //TODO desktop
|
209 | 165 | var program = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURECOLORALPHATEST);
|
|
217 | 173 |
|
218 | 174 | proto._onAfterDrawStencil = function(ctx){
|
219 | 175 | var gl = ctx || cc._renderContext;
|
220 |
| - gl.depthMask(this._currentDepthWriteMask); |
221 |
| - |
222 |
| - gl.stencilFunc(gl.EQUAL, this._mask_layer_le, this._mask_layer_le); |
| 176 | + gl.depthMask(true); |
| 177 | + gl.stencilFunc(!this._node.inverted ? gl.EQUAL : gl.NOTEQUAL, this._mask_layer_le, this._mask_layer_le); |
223 | 178 | gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
224 | 179 | };
|
225 | 180 |
|
226 | 181 | proto._onAfterVisit = function(ctx){
|
227 | 182 | var gl = ctx || cc._renderContext;
|
228 |
| - |
229 |
| - gl.stencilFunc(this._currentStencilFunc, this._currentStencilRef, this._currentStencilValueMask); |
230 |
| - gl.stencilOp(this._currentStencilFail, this._currentStencilPassDepthFail, this._currentStencilPassDepthPass); |
231 |
| - gl.stencilMask(this._currentStencilWriteMask); |
| 183 | + |
232 | 184 | if (!this._currentStencilEnabled)
|
233 | 185 | gl.disable(gl.STENCIL_TEST);
|
234 | 186 |
|
|
0 commit comments