From f0e80b32f4901fdb0c01c0515f22a2cdcb6579f9 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 1 Dec 2011 17:04:56 +0800 Subject: [PATCH] fixed #854: cache texture on android --- cocos2dx/textures/CCTextureCache.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index ac89657ca0..7b3c9c5d6d 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -55,6 +55,7 @@ typedef struct _ImageInfo { AsyncStruct *asyncStruct; CCImage *image; + CCImage::EImageFormat imageType; } ImageInfo; static pthread_t s_loadingThread; @@ -101,6 +102,7 @@ static void* loadImage(void* data) // generate image CCImage *pImage = NULL; + CCImage::EImageFormat imageType; if (std::string::npos != pAsyncStruct->filename.find(".jpg") || std::string::npos != pAsyncStruct->filename.find(".jpeg")) { pImage = new CCImage(); @@ -108,6 +110,7 @@ static void* loadImage(void* data) { delete pImage; CCLOG("can not load %s", filename); + imageType = CCImage::kFmtJpg; continue; } } @@ -118,12 +121,13 @@ static void* loadImage(void* data) { delete pImage; CCLOG("can not load %s", filename); + imageType = CCImage::kFmtPng; continue; } } else { - CCLog("unsupportted format %s",filename); + CCLOG("unsupportted format %s",filename); delete pAsyncStruct; continue; @@ -271,6 +275,18 @@ void CCTextureCache::addImageAsyncCallBack(ccTime dt) CCTexture2D *texture = new CCTexture2D(); 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 m_pTextures->setObject(texture, filename); texture->autorelease();