Cocos2d-x v3.x equivalent for ccExSwitchMask_frag [SOLVED]

Hello, I was porting over CCMask to Cocos2d-x API v3.1.1 and the only thing I seem to be getting stuck on to get it to compile is pProgram->initWithByteArrays(ccPositionTextureColor_vert, ccExSwitchMask_frag); ; specifically, the ccExSwitchMask_frag. I noticed that it exists in early v3 but now I can’t find it with the other shader stuff. How should I proceed?
Thanks.

I believe what you’re looking for is to use the updated ClippingNode. Example is given within the ControlSwitchSprite class (under extensions->gui->cccontrolextension). ClippingNode now uses the regular alpha test shader GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV with a set of custom rendering callbacks to implement an OpenGL stencil mask instead of the 2.x mask shader. You just supply the stencil mask texture by way of a Sprite (see example below).

if (Sprite::initWithTexture(maskSprite->getTexture()))
{
// ....

ClippingNode* clipper = ClippingNode::create();
_clipperStencil = Sprite::createWithTexture(maskSprite->getTexture());
_clipperStencil->retain();
clipper->setAlphaThreshold(0.1f);
clipper->setStencil(_clipperStencil);
addChild(clipper);
// ...
// Set up the mask with the Mask shader
setMaskTexture(maskSprite->getTexture());
setContentSize(_maskTexture->getContentSize());

// ....
}

If however that is overkill you’ll probably have to manual create the vert/frag shaders. If you create the mask.vert and mask.frag files by copying or using ccShaderEx_SwitchMask_frag.h as reference you can then attach them in 3.x with:

auto sprite = Sprite::create("sprite-to-mask.png");
auto spriteMask = Sprite::create("mask.png");

auto maskTexture = maskSprite->getTexture();

auto glprogram = GLProgram::createWithFilenames("mask.vert", "mask.frag");
auto glprogramstate = GLProgramState::getOrCreateWithGLProgram(glprogram);
glprogramstate->setUniformTexture("u_texture1", maskTexture);
sprite->setGLProgramState(glprogramstate);

Thanks for your quick response. I ended up using the native ClippingNode in my own simple wrapper class (dropped CCMask entirely since it’s redundant now). Works like a charm!