I'm using cocos2d-iPhone v.2.2, updating an old game, and I have a clipping node that is causing an error. In AppDelegate.m, I switched the settings to use CCClippingNode:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGB565
depthFormat:GL_DEPTH24_STENCIL8_OES //switched from 0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
And then I used this code to make the clipper in my mainGame.m
//after interface
@property (nonatomic, strong) CCClippingNode *shadowClipper;
//in the init method
CCSprite *stencil = [CCSprite spriteWithSpriteFrameName:@"clipper.png"];
stencil.position = ccp(winSize.width/2, winSize.height/2);
_shadowClipper = [CCClippingNode clippingNodeWithStencil:stencil];
_shadowClipper.alphaThreshold = 0.0;
[_gameLayer addChild:_shadowClipper z:2];
The console logs "OpenGL error 0x0502 in -[CCSprite draw] 530" but other than that the clipping node is doing what it's supposed to in the simulator. Any ideas about what's causing the error and what I can do to fix it?
I am using two nested CCClippingNodes
, both of which have alphaThreshold
set to < 1. The observed error occurs once per frame. It is reported (!) in line 530 of CCSprite
but occurs in CCClippingNode
in line 285:
[program setUniformLocation:alphaValueLocation withF1:_alphaThreshold];
If the alphaThreshold
is less than 1, CCClippingNode
assigns an alpha test shader to all of its stencil nodes. When it updates the alpha threshold uniform in the above line, it does so without calling glUseProgram
before, so the implementation attempts to set a uniform which may not be present in the currently bound shader.
Add the following line before the above line in CCClippingNode
to bind the shader program before its uniform is set. This should get rid of the error.
[program use];
CCClippingNode
appears to be a little rough around the edges, at least the alpha test implementation...