Permalink
Browse files

Use glClear to clear the stencil buffer.

Use glClear instead of drawing a rectange so that current layer's mask
for the entire stencil buffer is cleared. This fixes clipping when
drawn to a texture larger than the screen size or when the stencil or
clipping node's children contain vertices with negative coordinates.
  • Loading branch information...
colesbury committed Feb 21, 2013
1 parent 636728e commit b02c8a8686620cfc932b90c8e1ff78d9fcbe205a
Showing with 3 additions and 5 deletions.
  1. +3 −5 cocos2d/CCClippingNode.m
View
@@ -215,17 +215,15 @@ - (void)visit
///////////////////////////////////
// CLEAR STENCIL BUFFER
// manually clear the stencil buffer by drawing a fullscreen rectangle on it
// setup the stencil test func like this:
// for each pixel in the fullscreen rectangle
// for each pixel in the stencil buffer
// never draw it into the frame buffer
// if not in inverted mode: set the current layer value to 0 in the stencil buffer
// if in inverted mode: set the current layer value to 1 in the stencil buffer
glStencilFunc(GL_NEVER, mask_layer, mask_layer);
glClearStencil(!_inverted ? 0 : ~0);
glStencilOp(!_inverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP);
// draw a fullscreen solid rectangle to clear the stencil buffer
ccDrawSolidRect(CGPointZero, ccpFromSize([[CCDirector sharedDirector] winSize]), ccc4f(1, 1, 1, 1));
glClear(GL_STENCIL_BUFFER_BIT);
///////////////////////////////////
// DRAW CLIPPING STENCIL

0 comments on commit b02c8a8

Please sign in to comment.