I have solved the redrawing part, i just do [renderTarget clear:0 g:0 b:0 a:255]; before each call.
Regarding the slowdowns: My game runs at 50-60 fps normally, using renderTexture, it runs at 12-15 fps.
I am using an iphone 3G OS3.01
I don't know if this is normal, but if i just do this (which makes the mask stuff work perfectly)
(on my layer init):
renderTarget = [RenderTexture renderTextureWithWidth:s.width height:s.height];
[renderTarget setPosition:ccp(s.width/2, s.height/2)];
[self addChild:renderTarget z:20];
Now my game is running at 40-50 fps.
if after that i do:
darkness = [[ColorLayer layerWithColor:ccc4(0,0,0,255)] retain];
[darkness setPosition:ccp(240,160)];
brush = [[Sprite spriteWithFile:@"blanco.png"] retain];
[brush setBlendFunc: (ccBlendFunc) { GL_ZERO,GL_ONE_MINUS_SRC_ALPHA }];
[renderTarget begin];
glColorMask(TRUE, TRUE, TRUE, TRUE);
[darkness visit];
glColorMask(TRUE, TRUE, TRUE, FALSE);
[renderTarget end];
Now my game is running at 25-35 fps.
And if in my update call (or draw) i do:
[renderTarget clear:0 g:0 b:0 a:255];
[renderTarget begin];
glColorMask(FALSE, FALSE, FALSE, TRUE);
[brush setPosition:arrow->arrowBody->p];
[brush visit];
glColorMask(TRUE, TRUE, TRUE, FALSE);
[renderTarget end];
now my game is running at 10-15 fps...
So, what i see is that, just creating and placing the renderTexture and then drawing a colorlayer(or sprite) to it causes me a +- 30 fps drop...
As for "what else am i doing"? a lot of stuff... i am trying to add this to my full game, i don't know if i am doing something "wrong" but if it runs at 60fps and just by adding renderTexture and drawing something to it i get a 30fps drop i think there must be something wrong in there or the way i am doing it...
Another thing i notice (that mostly sure doesn't have anything to do with this) is that whatever size i assign to the renderTarget, the rightmost part of the screen does not get masked...
here is an screenshot of this:
http://www.beta-games.net/IMG_0071.PNG
http://www.beta-games.net/IMG_0072.PNG