mirror of https://github.com/axmolengine/axmol.git
fixed #854: cache texture on android
This commit is contained in:
parent
d92bdcc40d
commit
f0e80b32f4
|
@ -55,6 +55,7 @@ typedef struct _ImageInfo
|
||||||
{
|
{
|
||||||
AsyncStruct *asyncStruct;
|
AsyncStruct *asyncStruct;
|
||||||
CCImage *image;
|
CCImage *image;
|
||||||
|
CCImage::EImageFormat imageType;
|
||||||
} ImageInfo;
|
} ImageInfo;
|
||||||
|
|
||||||
static pthread_t s_loadingThread;
|
static pthread_t s_loadingThread;
|
||||||
|
@ -101,6 +102,7 @@ static void* loadImage(void* data)
|
||||||
|
|
||||||
// generate image
|
// generate image
|
||||||
CCImage *pImage = NULL;
|
CCImage *pImage = NULL;
|
||||||
|
CCImage::EImageFormat imageType;
|
||||||
if (std::string::npos != pAsyncStruct->filename.find(".jpg") || std::string::npos != pAsyncStruct->filename.find(".jpeg"))
|
if (std::string::npos != pAsyncStruct->filename.find(".jpg") || std::string::npos != pAsyncStruct->filename.find(".jpeg"))
|
||||||
{
|
{
|
||||||
pImage = new CCImage();
|
pImage = new CCImage();
|
||||||
|
@ -108,6 +110,7 @@ static void* loadImage(void* data)
|
||||||
{
|
{
|
||||||
delete pImage;
|
delete pImage;
|
||||||
CCLOG("can not load %s", filename);
|
CCLOG("can not load %s", filename);
|
||||||
|
imageType = CCImage::kFmtJpg;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,12 +121,13 @@ static void* loadImage(void* data)
|
||||||
{
|
{
|
||||||
delete pImage;
|
delete pImage;
|
||||||
CCLOG("can not load %s", filename);
|
CCLOG("can not load %s", filename);
|
||||||
|
imageType = CCImage::kFmtPng;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCLog("unsupportted format %s",filename);
|
CCLOG("unsupportted format %s",filename);
|
||||||
delete pAsyncStruct;
|
delete pAsyncStruct;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -271,6 +275,18 @@ void CCTextureCache::addImageAsyncCallBack(ccTime dt)
|
||||||
CCTexture2D *texture = new CCTexture2D();
|
CCTexture2D *texture = new CCTexture2D();
|
||||||
texture->initWithImage(pImage);
|
texture->initWithImage(pImage);
|
||||||
|
|
||||||
|
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||||
|
// cache the texture file name
|
||||||
|
if (pImageInfo->imageType == CCImage::kFmtJpg)
|
||||||
|
{
|
||||||
|
VolatileTexture::addImageTexture(texture, filename, CCImage::kFmtJpg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VolatileTexture::addImageTexture(texture, filename, CCImage::kFmtPng);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// cache the texture
|
// cache the texture
|
||||||
m_pTextures->setObject(texture, filename);
|
m_pTextures->setObject(texture, filename);
|
||||||
texture->autorelease();
|
texture->autorelease();
|
||||||
|
|
Loading…
Reference in New Issue