fixed #967: fixed PVR Textures can not be reloaded after GL context lost on android.

This commit is contained in:
dumganhar 2012-02-07 11:18:39 +08:00
parent ee2139023a
commit 1e807d00c3
1 changed files with 37 additions and 16 deletions

View File

@ -463,6 +463,10 @@ CCTexture2D * CCTextureCache::addPVRImage(const char* path)
tex = new CCTexture2D(); tex = new CCTexture2D();
if( tex->initWithPVRFile(fullpath.c_str()) ) if( tex->initWithPVRFile(fullpath.c_str()) )
{ {
#if CC_ENABLE_CACHE_TEXTTURE_DATA
// cache the texture file name
VolatileTexture::addImageTexture(tex, fullpath.c_str(), CCImage::kFmtRawData);
#endif
m_pTextures->setObject(tex, key); m_pTextures->setObject(tex, key);
tex->autorelease(); tex->autorelease();
} }
@ -732,22 +736,39 @@ void VolatileTexture::reloadAllTextures()
switch (vt->m_eCashedImageType) switch (vt->m_eCashedImageType)
{ {
case kImageFile: case kImageFile:
{ {
CCImage image; CCImage image;
CCFileData data(vt->m_strFileName.c_str(), "rb"); std::string lowerCase(vt->m_strFileName.c_str());
unsigned long nSize = data.getSize(); for (unsigned int i = 0; i < lowerCase.length(); ++i)
unsigned char* pBuffer = data.getBuffer(); {
lowerCase[i] = tolower(lowerCase[i]);
if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage)) }
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat(); if (std::string::npos != lowerCase.find(".pvr"))
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat); {
vt->texture->initWithImage(&image); CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat); CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
}
} vt->texture->initWithPVRFile(vt->m_strFileName.c_str());
break; CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
}
else
{
CCFileData data(vt->m_strFileName.c_str(), "rb");
unsigned long nSize = data.getSize();
unsigned char* pBuffer = data.getBuffer();
if (image.initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
vt->texture->initWithImage(&image);
CCTexture2D::setDefaultAlphaPixelFormat(oldPixelFormat);
}
}
}
break;
case kImageData: case kImageData:
{ {
unsigned int nPOTWide, nPOTHigh; unsigned int nPOTWide, nPOTHigh;