Darren Yeates wrote:
OK, fixed it.
>
Turns out that during the draw, the shader program didn’t exist anymore (it was being destroyed after it was initialised?)
Anyhow, the attached updated file seems to work, hopefully this will help someone, is there a way of getting changes like this updated into the mainline?
year It change the shader program when reset the texture in ccsprite.
@
void CCControlSwitchSprite::needsLayout()
{
m_pOnSprite~~>setPosition.width / 2 + m_fSliderXPosition,
m_pOnSprite~~>getContentSize().height / 2));
m_pOffSprite~~>setPosition.width + m_pOffSprite~~>getContentSize().width / 2 + m_fSliderXPosition,
m_pOffSprite~~>getContentSize.height / 2));
m_ThumbSprite~~>setPosition(ccp(m_pOnSprite~~>getContentSize.width + m_fSliderXPosition,
m_pMaskTexture~~>getContentSize().height / 2));
if (m_pOnLabel)
{
m_pOnLabel~~>setPosition.x~~ m_ThumbSprite~~>getContentSize.width / 6,
m_pOnSprite~~>getContentSize().height / 2));
}
if (m_pOffLabel)
{
m_pOffLabel~~>setPosition.x + m_ThumbSprite~~>getContentSize().width / 6,
m_pOffSprite~~>getContentSize.height / 2));
}
CCRenderTexture *rt = CCRenderTexture::createm_pMaskTexture~~>getContentSize().width, (int)m_pMaskTexture~~>getContentSize.height);
rt~~>begin();
m_pOnSprite~~>visit;
m_pOffSprite~~>visit();
if (m_pOnLabel)
{
m_pOnLabel~~>visit;
}
if
{
m_pOffLabel~~>visit();
}
rt->end();
setTexture(rt->getSprite()->getTexture());
setFlipY(true);
}
@
and the setTexture do like this :
@
void CCSprite::setTexture(CCTexture2D *texture)
{
// If batchnode, then texture id should be the same
CCAssert(! m_pobBatchNode || texture->getName() m_pobBatchNode->getTexture()->getName(), “CCSprite: Batched sprites should use the same texture as the batchnode”);
// accept texturenil as argument
CCAssert( !texture || dynamic_cast<CCTexture2D*>(texture), “setTexture expects a CCTexture2D. Invalid argument”);
// shader program
if (texture)
{
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
}
else
{
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor));
}
if (= texture)
{
CC_SAFE_RETAIN(texture);
CC_SAFE_RELEASE(m_pobTexture);
m_pobTexture = texture;
updateBlendFunc();
}
}
@