cocos2d-x之CCTexture2D的使用testDemo详细解读

cocos2d-x中CCTexture2D的使用,和测试,这个demo主要验证了各种格式的图片和相同格式图片但位深不同时加载纹理所占用的内存的大小和效果,以及异步加载纹理的方法,以及使用纹理创建CCSprite和删除纹理的方式,和对纹理进行精细处理的方法,参数等等

 

 

#ifndef __TEXTURE2D_TEST_H__
#define __TEXTURE2D_TEST_H__
//包含项目中所有的头文件
#include "../testBasic.h"

//Texture2dTest的基类
class TextureDemo : public CCLayer
{
public:
    virtual ~TextureDemo();             //虚拟构造函数,一般将基类的构造函数设为公有虚拟或者私有非虚拟
    virtual std::string title();             //测试的具体内容
    virtual std::string subtitle();       //测试内容的副标题
    virtual void onEnter();                //集成父类的注册函数,主要为layer添加触摸代,为layer中的child添加触摸代理

    void restartCallback(CCObject* pSender);      //界面中点击重新播放demo的按钮
    void nextCallback(CCObject* pSender);          //界面中点击播放下一个demo的按钮
    void backCallback(CCObject* pSender);         //界面中点击播放上一个demo的按钮
};
//使用TIFF格式加载Texture的demo
class TextureTIFF : public TextureDemo
{
public:
    virtual std::string title();
    virtual void onEnter();
};
//使用PNG格式加载Texture的demo
class TexturePNG : public TextureDemo
{
public:
    virtual std::string title();
    virtual void onEnter();
};
//使用JPG格式加载Texture的demo
class TextureJPEG : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//加载Texture之后精细处理纹理之后创建sprite的demo
class TextureMipMap : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//加载PVR格式的Texture的demo
class TexturePVR : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//加载PVR格式的Texture的demo,且这个文件经过PVRTexToo的处理
class TexturePVR2BPP : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//加载PVR格式的Texture的demo,且这个文件经过PVRTexToo的处理
class TexturePVR4BPP : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//加载PVR格式的Texture的demo,且这个文件经过PVRTexToo的处理,格式为RGBA8888位深为32位
class TexturePVRRGBA8888 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//加载PVR格式的Texture的demo,且这个文件经过PVRTexToo的处理,格式为BGRA8888位深为32位,与上边的不通在于高位低位表示的颜色不同
class TexturePVRBGRA8888 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//加载PVR格式的Texture的demo,且这个文件经过PVRTexToo的处理,格式为BGRA4444位深为16位
class TexturePVRRGBA4444 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};
//这个RGBA4444GZ应该是压缩的格式
class TexturePVRRGBA4444GZ : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA4444CCZ : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA5551 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRRGB565 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRRGB888 : public TextureDemo
{
public:
    virtual std::string title();
    virtual void onEnter();
};

class TexturePVRA8 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRI8 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVRAI88 : public TextureDemo
{
public:
    virtual std::string title();

    virtual void onEnter();
};

class TexturePVR2BPPv3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRII2BPPv3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVR4BPPv3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRII4BPPv3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA8888v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRBGRA8888v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA4444v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGBA5551v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGB565v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRRGB888v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRA8v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};

class TexturePVRI8v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//到这里都是使用了PVR格式来加载Texture,他们用来表示的颜色位数和格式略有不通
class TexturePVRAI88v3 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//使用糟糕的编码方式的PVR加载Textrue
class TexturePVRBadEncoding : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//PVR格式加载纹理后进行精细处理后加载Sprite
class TexturePVRMipMap : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//PVR格式加载纹理后进行精细处理方式2后加载Sprite
class TexturePVRMipMap2 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//PVR格式(文件长宽不是2的N次方的图片处理)加载纹理后进行精细处理后加载Sprite
class TexturePVRNonSquare : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//长宽不是2的N次方且,位深格式为16位的纹理加载
class TexturePVRNPOT4444 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//长宽不是2的N次方且,位深格式为32位的纹理加载
class TexturePVRNPOT8888 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//纹理别名,这个查了找不到具体的说法。。。。。。。。。
class TextureAlias : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//像素格式加载纹理
class TexturePixelFormat : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//纹理混合。。。。。。方式加载
class TextureBlend : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//异步加载纹理
class TextureAsync : public TextureDemo
{
public:
    virtual ~TextureAsync();
    void loadImages(float dt);
    void imageLoaded(CCObject* pObj);
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
private:
    int m_nImageOffset;
};
//重复加载纹理
class TextureGlRepeat : public TextureDemo
{
public:
    virtual ~TextureGlRepeat();
    virtual std::string title();

    virtual void onEnter();
};
//纹理拉伸
class TextureGlClamp : public TextureDemo
{
public:
    virtual ~TextureGlClamp();
    virtual std::string title();

    virtual void onEnter();
};
//纹理Size变形调整
class TextureSizeTest : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//纹理缓存
class TextureCache1 : public TextureDemo
{
public:
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
};
//某一点的纹理显示
class TextureDrawAtPoint : public TextureDemo
{
public:
    ~TextureDrawAtPoint();
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
    virtual void draw();
private:
    CCTexture2D* m_pTex1, *m_pTex2;
};
//纹理截取某一个矩形局域
class TextureDrawInRect : public TextureDemo
{
public:
    ~TextureDrawInRect();
    virtual std::string title();
    virtual std::string subtitle();
    virtual void onEnter();
    virtual void draw();
private:
    CCTexture2D* m_pTex1, *m_pTex2;
};
//纹理测试Scene声明
class TextureTestScene : public TestScene
{
public:
    virtual void runThisTest();//实现自己的runThisTest函数
};
//纹理内存分配
class TextureMemoryAlloc : public TextureDemo
{
public:
    virtual void onEnter();
    virtual std::string title();
    virtual std::string subtitle();
    void updateImage(CCObject *sender);
    void changeBackgroundVisible(CCObject *sender);
private:
    CCSprite *m_pBackground;
};

#endif // __TEXTURE2D_TEST_H__


// local import
#include "Texture2dTest.h"
#include "../testResource.h"

enum {
    kTagLabel = 1,
    kTagSprite1 = 2,
    kTagSprite2 = 3,
};
//定义函数指针,次函数指针类型为,返回CCLayer* 参数为空
typedef CCLayer* (*NEWTEXTURE2DTESTFUNC)(); 
//定义根据className创建具体类的宏定义,create##className表示在这里不用展开,
//将生成create**函数名
#define TEXTURE2D_CREATE_FUNC(className) \
static CCLayer* create##className() \
{ return new className(); }
//以下运用宏定义,声明了定义具体demo的layer的函数
TEXTURE2D_CREATE_FUNC(TextureMemoryAlloc);
TEXTURE2D_CREATE_FUNC(TextureAlias);
TEXTURE2D_CREATE_FUNC(TexturePVRMipMap);
TEXTURE2D_CREATE_FUNC(TexturePVRMipMap2);
TEXTURE2D_CREATE_FUNC(TexturePVRNonSquare);
TEXTURE2D_CREATE_FUNC(TexturePVRNPOT4444);
TEXTURE2D_CREATE_FUNC(TexturePVRNPOT8888);
TEXTURE2D_CREATE_FUNC(TexturePVR);
TEXTURE2D_CREATE_FUNC(TexturePVR2BPP);
TEXTURE2D_CREATE_FUNC(TexturePVR2BPPv3);
TEXTURE2D_CREATE_FUNC(TexturePVR4BPP);
TEXTURE2D_CREATE_FUNC(TexturePVR4BPPv3);
TEXTURE2D_CREATE_FUNC(TexturePVRII4BPPv3);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA8888);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA8888v3);
TEXTURE2D_CREATE_FUNC(TexturePVRBGRA8888);
TEXTURE2D_CREATE_FUNC(TexturePVRBGRA8888v3);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444v3);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444GZ);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444CCZ);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA5551);
TEXTURE2D_CREATE_FUNC(TexturePVRRGBA5551v3);
TEXTURE2D_CREATE_FUNC(TexturePVRRGB565);
TEXTURE2D_CREATE_FUNC(TexturePVRRGB565v3);
TEXTURE2D_CREATE_FUNC(TexturePVRRGB888);
TEXTURE2D_CREATE_FUNC(TexturePVRRGB888v3);
TEXTURE2D_CREATE_FUNC(TexturePVRA8);
TEXTURE2D_CREATE_FUNC(TexturePVRA8v3);
TEXTURE2D_CREATE_FUNC(TexturePVRI8);
TEXTURE2D_CREATE_FUNC(TexturePVRI8v3);
TEXTURE2D_CREATE_FUNC(TexturePVRAI88);
TEXTURE2D_CREATE_FUNC(TexturePVRAI88v3);
TEXTURE2D_CREATE_FUNC(TexturePVRBadEncoding);
TESTLAYER_CREATE_FUNC(TexturePNG);
TESTLAYER_CREATE_FUNC(TextureJPEG);
TESTLAYER_CREATE_FUNC(TextureTIFF);
TESTLAYER_CREATE_FUNC(TexturePixelFormat);
TESTLAYER_CREATE_FUNC(TextureBlend);
TESTLAYER_CREATE_FUNC(TextureAsync);
TESTLAYER_CREATE_FUNC(TextureGlClamp);
TESTLAYER_CREATE_FUNC(TextureGlRepeat);
TESTLAYER_CREATE_FUNC(TextureSizeTest);
TESTLAYER_CREATE_FUNC(TextureCache1);
TESTLAYER_CREATE_FUNC(TextureDrawAtPoint);
TESTLAYER_CREATE_FUNC(TextureDrawInRect);

//定义函数指针类型的数据,每个创建函数名
static NEWTEXTURE2DTESTFUNC createFunctions[] =
{
    createTextureMemoryAlloc,
    createTextureAlias,
    createTexturePVRMipMap,
    createTexturePVRMipMap2,
    createTexturePVRNonSquare,
    createTexturePVRNPOT4444,
    createTexturePVRNPOT8888,
    createTexturePVR,
    createTexturePVR2BPP,
    createTexturePVR2BPPv3,
    createTexturePVR4BPP,
    createTexturePVR4BPPv3,
    createTexturePVRII4BPPv3,
    createTexturePVRRGBA8888,
    createTexturePVRRGBA8888v3,
    createTexturePVRBGRA8888,
    createTexturePVRBGRA8888v3,
    createTexturePVRRGBA4444,
    createTexturePVRRGBA4444v3,
    createTexturePVRRGBA4444GZ,
    createTexturePVRRGBA4444CCZ,
    createTexturePVRRGBA5551,
    createTexturePVRRGBA5551v3,
    createTexturePVRRGB565,
    createTexturePVRRGB565v3,
    createTexturePVRRGB888,
    createTexturePVRRGB888v3,
    createTexturePVRA8,
    createTexturePVRA8v3,
    createTexturePVRI8,
    createTexturePVRI8v3,
    createTexturePVRAI88,
    createTexturePVRAI88v3,
    
    createTexturePVRBadEncoding,
    createTexturePNG,
    createTextureJPEG,
    createTextureTIFF,
    createTexturePixelFormat,
    createTextureBlend,
    createTextureAsync,
    createTextureGlClamp,
    createTextureGlRepeat,
    createTextureSizeTest,
    createTextureCache1,
    createTextureDrawAtPoint,
    createTextureDrawInRect,
};
//计算demo的总个数
static unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]);
//初始化demo次序从-1开始
static int sceneIdx=-1;
//定义根据idx创建具体的demoLayer的函数
CCLayer* createTextureTest(int index)
{
	//调用函数指针,创建Layer
    CCLayer* pLayer = (createFunctions[index])();;

    if (pLayer)
    {
	    //创建成功,则自动释放
        pLayer->autorelease();
    }

    return pLayer;
}
//点击下一个按钮,创建下一个layer,声明这个函数
CCLayer* nextTextureTest();
//点击上一个函数,创建上一个layer,声明这个函数
CCLayer* backTextureTest();
//点击重新播放的按钮,重新创建layer,声明这个函数
CCLayer* restartTextureTest();

CCLayer* nextTextureTest()
{
	//获取需要创建的layer的id值
    sceneIdx++;
    //根据layer的总个数,取余求当前的id
    sceneIdx = sceneIdx % TEST_CASE_COUNT;
    //根据id创建layer
    return createTextureTest(sceneIdx);
}

CCLayer* backTextureTest()
{
    //获取上一个layer的id值
    sceneIdx--;
    //如果小于0则为最大值-1
    if( sceneIdx < 0 )
        sceneIdx = TEST_CASE_COUNT -1;    

    return createTextureTest(sceneIdx);
}

CCLayer* restartTextureTest()
{
	//重新创建当前的layer
    return createTextureTest(sceneIdx);
}

//------------------------------------------------------------------
//
// TextureDemo
//
//------------------------------------------------------------------
void TextureDemo::onEnter()
{
   //注册layer,使得每个child可以响应触摸
    CCLayer::onEnter();
    //计算当前纹理所占的内存大小
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
    CCSize s = CCDirector::sharedDirector()->getWinSize();    
    //创建标题标签
    CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 26);
    addChild(label, 1, kTagLabel);
    label->setPosition(ccp(s.width/2, s.height-50));
    //创建副标题标签
    std::string strSubtitle = subtitle();
    if(strSubtitle.length())
    {
        CCLabelTTF *l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
        addChild(l, 1);
        l->setPosition(ccp(s.width/2, s.height-80));
    }
    //创建下一个,前一个,重复播放的menuItem
    CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TextureDemo::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TextureDemo::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TextureDemo::nextCallback) );
    
    CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
    menu->setPosition(CCPointZero);
    item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
    item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
    item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
    addChild(menu, 1);    
    //计算纹理缓存
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

TextureDemo::~TextureDemo()
{
	//释放一次缓存,并计算释放后的缓存大小
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

void TextureDemo::restartCallback(CCObject* pSender)
{
	//重新播放demo的scene
    CCScene *s = new TextureTestScene();
    s->addChild(restartTextureTest());
    CCDirector::sharedDirector()->replaceScene(s);
    s->autorelease();
}

void TextureDemo::nextCallback(CCObject* pSender)
{
	//播放下一个demo
    CCScene *s = new TextureTestScene();
    s->addChild(nextTextureTest());
    CCDirector::sharedDirector()->replaceScene(s);
    s->autorelease();
}

void TextureDemo::backCallback(CCObject* pSender)
{
    //播放上一个demo
    CCScene *s = new TextureTestScene();
    s->addChild(backTextureTest());
    CCDirector::sharedDirector()->replaceScene(s);
    s->autorelease();
}

std::string TextureDemo::title()
{
    return "No title";
}

std::string TextureDemo::subtitle()
{
    return "";
}

//------------------------------------------------------------------
//
// TextureTIFF
//
//------------------------------------------------------------------

void TextureTIFF::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //使用TIFF格式创建一个精灵,并打印当前所占的缓存
    CCSprite *img = CCSprite::create("Images/test_image.tiff");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    this->addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureTIFF::title()
{
    return "TIFF Test";
}

//------------------------------------------------------------------
//
// TexturePNG
//
//------------------------------------------------------------------
void TexturePNG::onEnter()
{
    TextureDemo::onEnter();    

    CCSize s = CCDirector::sharedDirector()->getWinSize();
   //使用PNG格式创建一个精灵,并打印当前所占的缓存
    CCSprite *img = CCSprite::create("Images/test_image.png");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePNG::title()
{
    return "PNG Test";
}

//------------------------------------------------------------------
//
// TextureJPEG
//
//------------------------------------------------------------------
void TextureJPEG::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //使用JPG格式创建一个精灵,并打印当前所占的缓存
    CCSprite *img = CCSprite::create("Images/test_image.jpeg");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureJPEG::title()
{
    return "JPEG Test";
}

//------------------------------------------------------------------
//
// TextureMipMap
//
//------------------------------------------------------------------
void TextureMipMap::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //使用PNG格式创建一个纹理texture0
    CCTexture2D *texture0 = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png");
    //对纹理进行精细处理,对比处理前的效果看上去更加清晰
    texture0->generateMipmap();
    //定义处理参数,并设置纹理即将被处理的参数
    ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };    
    //对纹理进行处理,如果纹理的size不是2的幂将只能使用 GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.
    texture0->setTexParameters(&texParams);
    //定义纹理创建后不进行任何处理的纹理
    CCTexture2D *texture1 = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas_nomipmap.png");
    //根据纹理0创建精灵
    CCSprite *img0 = CCSprite::createWithTexture(texture0);
    img0->setTextureRect(CCRectMake(85, 121, 85, 121));
    img0->setPosition(ccp( s.width/3.0f, s.height/2.0f));
    addChild(img0);
    //根据纹理1创建精灵,
    CCSprite *img1 = CCSprite::createWithTexture(texture1);
    img1->setTextureRect(CCRectMake(85, 121, 85, 121));
    img1->setPosition(ccp( 2*s.width/3.0f, s.height/2.0f));
    addChild(img1);
    
    //创建加速变形的action
    CCEaseOut* scale1 = CCEaseOut::create(CCScaleBy::create(4, 0.01f), 3);
    CCActionInterval* sc_back = scale1->reverse();
    
    CCEaseOut* scale2 = (CCEaseOut*) (scale1->copy());
    scale2->autorelease();
    CCActionInterval* sc_back2 = scale2->reverse();

    img0->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(scale1, sc_back, NULL))));
    img1->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(scale2, sc_back2, NULL))));
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureMipMap::title()
{
    return "Texture Mipmap";
}

std::string TextureMipMap::subtitle()
{
    return "Left image uses mipmap. Right image doesn't";
}

//------------------------------------------------------------------
//
// TexturePVRMipMap
// To generate PVR images read this article:
// http://developer.apple.com/iphone/library/qa/qa2008/qa1611.html
//
//------------------------------------------------------------------
void TexturePVRMipMap::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //使用pvr格式创建精灵,并进行精细化处理
    CCSprite *imgMipMap = CCSprite::create("Images/logo-mipmap.pvr");
    if( imgMipMap )
    {
        imgMipMap->setPosition(ccp( s.width/2.0f-100, s.height/2.0f));
        addChild(imgMipMap);

        // support mipmap filtering
        ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE }; 
	//获取精灵中的纹理,并设置精细处理的参数
        imgMipMap->getTexture()->setTexParameters(&texParams);
    }
    //创建不进行精细处理的精灵
    CCSprite *img = CCSprite::create("Images/logo-nomipmap.pvr");
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
        addChild(img);

        CCEaseOut* scale1 = CCEaseOut::create(CCScaleBy::create(4, 0.01f), 3);
        CCActionInterval* sc_back = scale1->reverse();

        CCEaseOut* scale2 = (CCEaseOut*) (scale1->copy());
        scale2->autorelease();
        CCActionInterval* sc_back2 = scale2->reverse();
        
        imgMipMap->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(scale1, sc_back, NULL))));
        img->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(scale2, sc_back2, NULL))));
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRMipMap::title()
{
    return "PVRTC MipMap Test";
}
std::string TexturePVRMipMap::subtitle()
{
    return "Left image uses mipmap. Right image doesn't";
}

//------------------------------------------------------------------
//
// TexturePVRMipMap2
//
//------------------------------------------------------------------
void TexturePVRMipMap2::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    //创建存储格式为pvr,且位深格式为RGBA4444格式的精细化处理的精灵
    CCSprite *imgMipMap = CCSprite::create("Images/test_image_rgba4444_mipmap.pvr");
    imgMipMap->setPosition(ccp( s.width/2.0f-100, s.height/2.0f));
    addChild(imgMipMap);
    
    // support mipmap filtering
    ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };    
    imgMipMap->getTexture()->setTexParameters(&texParams);

    CCSprite *img = CCSprite::create("Images/test_image.png");
    img->setPosition(ccp( s.width/2.0f+100, s.height/2.0f));
    addChild(img);
    
    CCEaseOut* scale1 = CCEaseOut::create(CCScaleBy::create(4, 0.01f), 3);
    CCActionInterval* sc_back = scale1->reverse();

    CCEaseOut* scale2 = (CCEaseOut*) (scale1->copy());
    scale2->autorelease();
    CCActionInterval* sc_back2 = scale2->reverse();
    
    imgMipMap->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(scale1, sc_back, NULL))));
    img->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(scale2, sc_back2, NULL))));
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRMipMap2::title()
{
    return "PVR MipMap Test #2";
}

std::string TexturePVRMipMap2::subtitle()
{
    return "Left image uses mipmap. Right image doesn't";
}

//------------------------------------------------------------------
//
// TexturePVR2BPP
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVR2BPP::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image_pvrtc2bpp.pvr");
    
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVR2BPP::title()
{
    return "PVR TC 2bpp Test";
}

//------------------------------------------------------------------
//
// TexturePVR
// To generate PVR images read this article:
// http://developer.apple.com/iphone/library/qa/qa2008/qa1611.html
//
//------------------------------------------------------------------
void TexturePVR::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image.pvr");
    
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    else
    {
        CCLog("This test is not supported.");
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
    
}

std::string TexturePVR::title()
{
    return "PVR TC 4bpp Test #2";
}

//------------------------------------------------------------------
//
// TexturePVR4BPP
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVR4BPP::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image_pvrtc4bpp.pvr");
    
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    else
    {
        CCLog("This test is not supported in cocos2d-mac");
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVR4BPP::title()
{
    return "PVR TC 4bpp Test #3";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA8888
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA8888::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image_rgba8888.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA8888::title()
{
    return "PVR + RGBA  8888 Test";
}

//------------------------------------------------------------------
//
// TexturePVRBGRA8888
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRBGRA8888::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_bgra8888.pvr");
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    else
    {
        CCLog("BGRA8888 images are not supported");
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRBGRA8888::title()
{
    return "PVR + BGRA 8888 Test";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA5551
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA5551::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgba5551.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA5551::title()
{
    return "PVR + RGBA 5551 Test";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA4444
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA4444::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgba4444.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA4444::title()
{
    return "PVR + RGBA 4444 Test";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA4444GZ
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA4444GZ::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // android can not pack .gz file into apk file
    CCSprite *img = CCSprite::create("Images/test_image_rgba4444.pvr");
#else
    CCSprite *img = CCSprite::create("Images/test_image_rgba4444.pvr.gz");
#endif
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA4444GZ::title()
{
    return "PVR + RGBA 4444 + GZ Test";
}

std::string TexturePVRRGBA4444GZ::subtitle()
{
    return "This is a gzip PVR image";
}

//------------------------------------------------------------------
//
// TexturePVRRGBA4444CCZ
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGBA4444CCZ::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image_rgba4444.pvr.ccz");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGBA4444CCZ::title()
{
    return "PVR + RGBA 4444 + CCZ Test";
}

std::string TexturePVRRGBA4444CCZ::subtitle()
{
    return "This is a ccz PVR image";
}

//------------------------------------------------------------------
//
// TexturePVRRGB565
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRRGB565::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgb565.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRRGB565::title()
{
    return "PVR + RGB 565 Test";
}

// TexturePVR RGB888
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
void TexturePVRRGB888::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image_rgb888.pvr");
    if (img != NULL)
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }

    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();

}
std::string TexturePVRRGB888::title()
{
    return "PVR + RGB 888 Test";
}

//------------------------------------------------------------------
//
// TexturePVRA8
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRA8::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_a8.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();

}

std::string TexturePVRA8::title()
{
    return "PVR + A8 Test";
}

//------------------------------------------------------------------
//
// TexturePVRI8
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRI8::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image_i8.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRI8::title()
{
    return "PVR + I8 Test";
}

//------------------------------------------------------------------
//
// TexturePVRAI88
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRAI88::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_ai88.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRAI88::title()
{
    return "PVR + AI88 Test";
}

// TexturePVR2BPPv3
void TexturePVR2BPPv3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_pvrtc2bpp_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVR2BPPv3::title()
{
    return "PVR TC 2bpp Test";
}

string TexturePVR2BPPv3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRII2BPPv3
void TexturePVRII2BPPv3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_pvrtcii2bpp_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRII2BPPv3::title()
{
    return "PVR TC II 2bpp Test";
}

string TexturePVRII2BPPv3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVR4BPPv3
void TexturePVR4BPPv3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_pvrtc4bpp_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    else
    {
        CCLog("This test is not supported");
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVR4BPPv3::title()
{
    return "PVR TC 4bpp Test";
}

string TexturePVR4BPPv3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRII4BPPv3

// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp

void TexturePVRII4BPPv3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_pvrtcii4bpp_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    else
    {
        CCLog("This test is not supported");
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRII4BPPv3::title()
{
    return "PVR TC II 4bpp Test";
}

string TexturePVRII4BPPv3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRRGBA8888v3
void TexturePVRRGBA8888v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgba8888_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRRGBA8888v3::title()
{
    return "PVR + RGBA  8888 Test";
}

string TexturePVRRGBA8888v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRBGRA8888v3
void TexturePVRBGRA8888v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_bgra8888_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    else
    {
        CCLog("BGRA images are not supported");
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRBGRA8888v3::title()
{
    return "PVR + BGRA 8888 Test";
}

string TexturePVRBGRA8888v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRRGBA5551v3
void TexturePVRRGBA5551v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgba5551_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRRGBA5551v3::title()
{
    return "PVR + RGBA 5551 Test";
}

string TexturePVRRGBA5551v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRRGBA4444v3
void TexturePVRRGBA4444v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgba4444_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRRGBA4444v3::title()
{
    return "PVR + RGBA 4444 Test";
}

string TexturePVRRGBA4444v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRRGB565v3
void TexturePVRRGB565v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgb565_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRRGB565v3::title()
{
    return "PVR + RGB 565 Test";
}

string TexturePVRRGB565v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRRGB888v3
void TexturePVRRGB888v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_rgb888_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRRGB888v3::title()
{
    return "PVR + RGB 888 Test";
}

string TexturePVRRGB888v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRA8v3
void TexturePVRA8v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_a8_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRA8v3::title()
{
    return "PVR + A8 Test";
}

string TexturePVRA8v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRI8v3
void TexturePVRI8v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_i8_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRI8v3::title()
{
    return "PVR + I8 Test";
}

string TexturePVRI8v3::subtitle()
{
    return "Testing PVR File Format v3";
}

// TexturePVRAI88v3
void TexturePVRAI88v3::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/test_image_ai88_v3.pvr");
    
    if (img)
    {
        img->setPosition(ccp(s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

string TexturePVRAI88v3::title()
{
    return "PVR + AI88 Test";
}

string TexturePVRAI88v3::subtitle()
{
    return "Testing PVR File Format v3";
}

//------------------------------------------------------------------
//
// TexturePVRBadEncoding
// Image generated using PVRTexTool:
// http://www.imgtec.com/powervr/insider/powervr-pvrtextool.asp
//
//------------------------------------------------------------------
void TexturePVRBadEncoding::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/test_image-bad_encoding.pvr");
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
}

std::string TexturePVRBadEncoding::title()
{
    return "PVR Unsupported encoding";
}

std::string TexturePVRBadEncoding::subtitle()
{
    return "You should not see any image";
}

//------------------------------------------------------------------
//
// TexturePVRNonSquare
//
//------------------------------------------------------------------
void TexturePVRNonSquare::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/grossini_128x256_mipmap.pvr");
    img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
    addChild(img);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRNonSquare::title()
{
    return "PVR + Non square texture";
}

std::string TexturePVRNonSquare::subtitle()
{
    return "Loading a 128x256 texture";
}

//------------------------------------------------------------------
//
// TexturePVRNPOT4444
//
//------------------------------------------------------------------
void TexturePVRNPOT4444::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCSprite *img = CCSprite::create("Images/grossini_pvr_rgba4444.pvr");
    if ( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRNPOT4444::title()
{
    return "PVR RGBA4 + NPOT texture";
}

std::string TexturePVRNPOT4444::subtitle()
{
    return "Loading a 81x121 RGBA4444 texture.";
}

//------------------------------------------------------------------
//
// TexturePVRNPOT8888
//
//------------------------------------------------------------------
void TexturePVRNPOT8888::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *img = CCSprite::create("Images/grossini_pvr_rgba8888.pvr");
    if( img )
    {
        img->setPosition(ccp( s.width/2.0f, s.height/2.0f));
        addChild(img);
    }
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePVRNPOT8888::title()
{
    return "PVR RGBA8 + NPOT texture";
}

std::string TexturePVRNPOT8888::subtitle()
{
    return "Loading a 81x121 RGBA8888 texture.";
}

//------------------------------------------------------------------
//
// TextureAlias
//
//------------------------------------------------------------------
void TextureAlias::onEnter()
{
    TextureDemo::onEnter();
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    //
    // Sprite 1: GL_LINEAR
    //
    // Default filter is GL_LINEAR
    
    CCSprite *sprite = CCSprite::create("Images/grossinis_sister1.png");
    sprite->setPosition(ccp( s.width/3.0f, s.height/2.0f));
    addChild(sprite);
    
    // this is the default filterting
    sprite->getTexture()->setAntiAliasTexParameters();
    
    //
    // Sprite 1: GL_NEAREST
    //    
    
    CCSprite *sprite2 = CCSprite::create("Images/grossinis_sister2.png");
    sprite2->setPosition(ccp( 2*s.width/3.0f, s.height/2.0f));
    addChild(sprite2);
    
    // Use Nearest in this one
    sprite2->getTexture()->setAliasTexParameters();
        
    // scale them to show
    CCScaleBy* sc = CCScaleBy::create(3, 8.0f);
    CCScaleBy* sc_back = (CCScaleBy*) (sc->reverse());
    CCRepeatForever* scaleforever = CCRepeatForever::create((CCActionInterval*) (CCSequence::create(sc, sc_back, NULL)));
    CCRepeatForever* scaleToo = (CCRepeatForever*) (scaleforever->copy());
    scaleToo->autorelease();

    sprite2->runAction(scaleforever);
    sprite->runAction(scaleToo);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TextureAlias::title()
{
    return "AntiAlias / Alias textures";
}

std::string TextureAlias::subtitle()
{
    return "Left image is antialiased. Right image is aliases";
}

//------------------------------------------------------------------
//
// TexturePixelFormat
//
//------------------------------------------------------------------
void TexturePixelFormat::onEnter()
{
    //
    // This example displays 1 png images 4 times.
    // Each time the image is generated using:
    // 1- 32-bit RGBA8
    // 2- 16-bit RGBA4
    // 3- 16-bit RGB5A1
    // 4- 16-bit RGB565
    TextureDemo::onEnter();
    
    CCLabelTTF *label = (CCLabelTTF*) getChildByTag(kTagLabel);
    label->setColor(ccc3(16,16,255));
    
    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCLayerColor *background = CCLayerColor::create(ccc4(128,128,128,255), s.width, s.height);
    addChild(background, -1);
    
    // RGBA 8888 image (32-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
    CCSprite *sprite1 = CCSprite::create("Images/test-rgba1.png");
    sprite1->setPosition(ccp(1*s.width/7, s.height/2+32));
    addChild(sprite1, 0);

    // remove texture from texture manager    
    CCTextureCache::sharedTextureCache()->removeTexture(sprite1->getTexture());

    // RGBA 4444 image (16-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
    CCSprite *sprite2 = CCSprite::create("Images/test-rgba1.png");
    sprite2->setPosition(ccp(2*s.width/7, s.height/2-32));
    addChild(sprite2, 0);

    // remove texture from texture manager    
    CCTextureCache::sharedTextureCache()->removeTexture(sprite2->getTexture());

    // RGB5A1 image (16-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1);
    CCSprite *sprite3 = CCSprite::create("Images/test-rgba1.png");
    sprite3->setPosition(ccp(3*s.width/7, s.height/2+32));
    addChild(sprite3, 0);

    // remove texture from texture manager    
    CCTextureCache::sharedTextureCache()->removeTexture(sprite3->getTexture());

    // RGB888 image
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB888);
    CCSprite *sprite4 = CCSprite::create("Images/test-rgba1.png");
    sprite4->setPosition(ccp(4*s.width/7, s.height/2-32));
    addChild(sprite4, 0);

    // remove texture from texture manager    
    CCTextureCache::sharedTextureCache()->removeTexture(sprite4->getTexture());

    // RGB565 image (16-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
    CCSprite *sprite5 = CCSprite::create("Images/test-rgba1.png");
    sprite5->setPosition(ccp(5*s.width/7, s.height/2+32));
    addChild(sprite5, 0);

    // remove texture from texture manager    
    CCTextureCache::sharedTextureCache()->removeTexture(sprite5->getTexture());

    // A8 image (8-bit)
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_A8);
    CCSprite *sprite6 = CCSprite::create("Images/test-rgba1.png");
    sprite6->setPosition(ccp(6*s.width/7, s.height/2-32));
    addChild(sprite6, 0);
    
    // remove texture from texture manager    
    CCTextureCache::sharedTextureCache()->removeTexture(sprite6->getTexture());

    CCFadeOut* fadeout = CCFadeOut::create(2);
    CCFadeIn*  fadein  = CCFadeIn::create(2);
    CCFiniteTimeAction* seq = CCSequence::create(CCDelayTime::create(2), fadeout, fadein, NULL);
    CCRepeatForever* seq_4ever = CCRepeatForever::create((CCActionInterval*) seq);
    CCRepeatForever* seq_4ever2 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever2->autorelease();
    CCRepeatForever* seq_4ever3 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever3->autorelease();
    CCRepeatForever* seq_4ever4 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever4->autorelease();
    CCRepeatForever* seq_4ever5 = (CCRepeatForever*) (seq_4ever->copy()); seq_4ever5->autorelease();
    
    sprite1->runAction(seq_4ever);
    sprite2->runAction(seq_4ever2);
    sprite3->runAction(seq_4ever3);
    sprite4->runAction(seq_4ever4);
    sprite5->runAction(seq_4ever5);

    // restore default
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
}

std::string TexturePixelFormat::title()
{
    return "Texture Pixel Formats";
}

std::string TexturePixelFormat::subtitle()
{
    return "Textures: RGBA8888, RGBA4444, RGB5A1, RGB888, RGB565, A8";
}

//------------------------------------------------------------------
//
// TextureBlend
//
//------------------------------------------------------------------
void TextureBlend::onEnter()
{
    TextureDemo::onEnter();

    for( int i=0;i < 15;i++ )
    {
        // BOTTOM sprites have alpha pre-multiplied
        // they use by default GL_ONE, GL_ONE_MINUS_SRC_ALPHA
        CCSprite *cloud = CCSprite::create("Images/test_blend.png");
        addChild(cloud, i+1, 100+i);
        cloud->setPosition(ccp(50+25*i, 80));
        ccBlendFunc blendFunc1 = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
        cloud->setBlendFunc(blendFunc1);

        // CENTER sprites have also alpha pre-multiplied
        // they use by default GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
        cloud = CCSprite::create("Images/test_blend.png");
        addChild(cloud, i+1, 200+i);
        cloud->setPosition(ccp(50+25*i, 160));
        ccBlendFunc blendFunc2 = { GL_ONE_MINUS_DST_COLOR, GL_ZERO };
        cloud->setBlendFunc(blendFunc2);

        // UPPER sprites are using custom blending function
        // You can set any blend function to your sprites
        cloud = CCSprite::create("Images/test_blend.png");
        addChild(cloud, i+1, 200+i);
        cloud->setPosition(ccp(50+25*i, 320-80));
        ccBlendFunc blendFunc3 = { GL_SRC_ALPHA, GL_ONE };
        cloud->setBlendFunc(blendFunc3);  // additive blending
    }
}

std::string TextureBlend::title()
{
    return "Texture Blending";
}

std::string TextureBlend::subtitle()
{
    return "Testing 3 different blending modes";
}


//------------------------------------------------------------------
//
// TextureAsync
//
//------------------------------------------------------------------
/*之前的每一种格式图片创建精灵,并打印出所占缓存的例子,明白就行了, 我想作者的本意是让使用者对比一下不通图片不图格式不同处理的情况下,显示的效果,和所占用内存的大小
但是,真理是不会变的,效果好的就会牺牲点内存,内存小的效果可能根本不行,所以大家每次在使用什么格式的时候仔细对比考虑*/
void TextureAsync::onEnter()
{
    TextureDemo::onEnter();
    //这是个异步加载纹理的例子,这个例子可以帮我们解决很多异步加载图片的处理
    m_nImageOffset = 0;

    CCSize size =CCDirector::sharedDirector()->getWinSize();
    //创建加载进度提示的label
    CCLabelTTF *label = CCLabelTTF::create("Loading...", "Marker Felt", 32);
    label->setPosition(ccp( size.width/2, size.height/2));
    addChild(label, 10);
    //创建异步加载时候标签的action
    CCScaleBy* scale = CCScaleBy::create(0.3f, 2);
    CCScaleBy* scale_back = (CCScaleBy*)scale->reverse();
    CCSequence* seq = (CCSequence*)CCSequence::create(scale, scale_back, NULL);
    label->runAction(CCRepeatForever::create(seq));
    //每一秒钟加载一次
    scheduleOnce(schedule_selector(TextureAsync::loadImages), 1.0f);
}

TextureAsync::~TextureAsync()
{
    CCTextureCache::sharedTextureCache()->removeAllTextures();
}

void TextureAsync::loadImages(float dt)
{
    for( int i=0;i < 8;i++) {
        for( int j=0;j < 8; j++) {
            char szSpriteName[100] = {0};
	    //通过sprintf将i,j转换成固定的图片
            sprintf(szSpriteName, "Images/sprites_test/sprite-%d-%d.png", i, j);
	    //调用异步加载图片的函数,将图片加载至纹理缓存,其中函数采用了另外的线程加载图片
            CCTextureCache::sharedTextureCache()->addImageAsync(szSpriteName,this, callfuncO_selector(TextureAsync::imageLoaded));
        }
    }
    /*这个函数,第一个参数是图片名称,第二个是目标对象的指针,第三个参数是这个对象内部的一个成员函数,且这个函数的参数以第一个参数创建的纹理为参数*/
    CCTextureCache::sharedTextureCache()->addImageAsync("Images/background1.jpg",this, callfuncO_selector(TextureAsync::imageLoaded));
    CCTextureCache::sharedTextureCache()->addImageAsync("Images/background2.jpg",this, callfuncO_selector(TextureAsync::imageLoaded));
    CCTextureCache::sharedTextureCache()->addImageAsync("Images/background.png",this, callfuncO_selector(TextureAsync::imageLoaded));
    CCTextureCache::sharedTextureCache()->addImageAsync("Images/atlastest.png",this, callfuncO_selector(TextureAsync::imageLoaded));
    CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_atlas.png",this, callfuncO_selector(TextureAsync::imageLoaded));
}

//这个函数正式以纹理为参数的函数,并用纹理创建了精灵
void TextureAsync::imageLoaded(CCObject* pObj)
{
    CCTexture2D* tex = (CCTexture2D*)pObj;
    CCDirector *director = CCDirector::sharedDirector();

    //CCAssert( [NSThread currentThread] == [director runningThread], @"FAIL. Callback should be on cocos2d thread");

    // IMPORTANT: The order on the callback is not guaranteed. Don't depend on the callback

    // This test just creates a sprite based on the Texture

    CCSprite *sprite = CCSprite::createWithTexture(tex);
    sprite->setAnchorPoint(ccp(0,0));
    addChild(sprite, -1);

    CCSize size = director->getWinSize();
    int i = m_nImageOffset * 32;
    sprite->setPosition(ccp( i % (int)size.width, (i / (int)size.width) * 32 ));

    m_nImageOffset++;

    CCLog("Image loaded: %p", tex);
}

std::string TextureAsync::title()
{
    return "Texture Async Load";
}

std::string TextureAsync::subtitle()
{
    return "Textures should load while an animation is being run";
}


//------------------------------------------------------------------
//
// TextureGlClamp
//
//------------------------------------------------------------------
void TextureGlClamp::onEnter()
{
    TextureDemo::onEnter();

    CCSize size = CCDirector::sharedDirector()->getWinSize();

    // The .png image MUST be power of 2 in order to create a continue effect.
    // eg: 32x64, 512x128, 256x1024, 64x64, etc..
   // png只支持宽高为2的幂的图片,不然就会自动截取为2的幂的纹理,就是说23*64会按照32*64的加载纹理
    CCSprite *sprite = CCSprite::create("Images/pattern1.png", CCRectMake(0,0,512,256));
    addChild(sprite, -1, kTagSprite1);
    sprite->setPosition(ccp(size.width/2,size.height/2));
    ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE};
    sprite->getTexture()->setTexParameters(¶ms);

    CCRotateBy* rotate = CCRotateBy::create(4, 360);
    sprite->runAction(rotate);
    CCScaleBy* scale = CCScaleBy::create(2, 0.04f);
    CCScaleBy* scaleBack = (CCScaleBy*) (scale->reverse());
    CCFiniteTimeAction* seq = CCSequence::create(scale, scaleBack, NULL);
    sprite->runAction(seq);
}

std::string TextureGlClamp::title()
{
    return "Texture GL_CLAMP";
}

TextureGlClamp::~TextureGlClamp()
{
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

//------------------------------------------------------------------
//
// TextureGlRepeat
//
//------------------------------------------------------------------
void TextureGlRepeat::onEnter()
{
    TextureDemo::onEnter();

    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    // The .png image MUST be power of 2 in order to create a continue effect.
    // eg: 32x64, 512x128, 256x1024, 64x64, etc..
    CCSprite *sprite = CCSprite::create("Images/pattern1.png", CCRectMake(0, 0, 4096, 4096));
    addChild(sprite, -1, kTagSprite1);
    sprite->setPosition(ccp(size.width/2,size.height/2));
    ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
    sprite->getTexture()->setTexParameters(¶ms);
    
    CCRotateBy* rotate = CCRotateBy::create(4, 360);
    sprite->runAction(rotate);
    CCScaleBy* scale = CCScaleBy::create(2, 0.04f);
    CCScaleBy* scaleBack = (CCScaleBy*) (scale->reverse());
    CCFiniteTimeAction* seq = CCSequence::create(scale, scaleBack, NULL);
    sprite->runAction(seq);
}

std::string TextureGlRepeat::title()
{
    return "Texture GL_REPEAT";
}

TextureGlRepeat::~TextureGlRepeat()
{
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
}

//------------------------------------------------------------------
//
// TextureSizeTest
//
//------------------------------------------------------------------
void TextureSizeTest::onEnter()
{
    TextureDemo::onEnter();
    CCSprite *sprite = NULL;
    
    CCLog("Loading 512x512 image...");
    sprite = CCSprite::create("Images/texture512x512.png");
    if( sprite )
        CCLog("OK\n");
    else
        CCLog("Error\n");

    CCLog("Loading 1024x1024 image...");
    sprite = CCSprite::create("Images/texture1024x1024.png");
    if( sprite )
        CCLog("OK\n");
    else
        CCLog("Error\n");
//     @todo
//     CCLog("Loading 2048x2048 image...");
//     sprite = CCSprite::create("Images/texture2048x2048.png");
//     if( sprite )
//         CCLog("OK\n");
//     else
//         CCLog("Error\n");
//     
//     CCLog("Loading 4096x4096 image...");
//     sprite = CCSprite::create("Images/texture4096x4096.png");
//     if( sprite )
//         CCLog("OK\n");
//     else
//         CCLog("Error\n");
}

std::string TextureSizeTest::title()
{
    return "Different Texture Sizes";
}

std::string TextureSizeTest::subtitle()
{
    return "512x512, 1024x1024. See the console.";
}

//------------------------------------------------------------------
//
// TextureCache1
//
//------------------------------------------------------------------
void TextureCache1::onEnter()
{
    TextureDemo::onEnter();

    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    CCSprite *sprite;

    sprite = CCSprite::create("Images/grossinis_sister1.png");
    sprite->setPosition(ccp(s.width/5*1, s.height/2));
    sprite->getTexture()->setAliasTexParameters();
    sprite->setScale(2);
    addChild(sprite);
    //从纹理缓存中删除纹理
    CCTextureCache::sharedTextureCache()->removeTexture(sprite->getTexture());
    
    sprite = CCSprite::create("Images/grossinis_sister1.png");
    sprite->setPosition(ccp(s.width/5*2, s.height/2));
    sprite->getTexture()->setAntiAliasTexParameters();
    sprite->setScale(2);
    addChild(sprite);

    // 2nd set of sprites
    
    sprite = CCSprite::create("Images/grossinis_sister2.png");
    sprite->setPosition(ccp(s.width/5*3, s.height/2));
    sprite->getTexture()->setAliasTexParameters();
    sprite->setScale(2);
    addChild(sprite);
    //根据纹理图片的名称删除纹理
    CCTextureCache::sharedTextureCache()->removeTextureForKey("Images/grossinis_sister2.png");

    sprite = CCSprite::create("Images/grossinis_sister2.png");
    sprite->setPosition(ccp(s.width/5*4, s.height/2));
    //为加载的sprite设置纹理处理方式
    sprite->getTexture()->setAntiAliasTexParameters();
    sprite->setScale(2);
    addChild(sprite);
}

std::string TextureCache1::title()
{
    return "CCTextureCache: remove";
}

std::string TextureCache1::subtitle()
{
    return "4 images should appear: alias, antialias, alias, antilias";
}

// TextureDrawAtPoint
void TextureDrawAtPoint::onEnter()
{
    TextureDemo::onEnter();
    //根据文件名称穿件一个纹理对象,如果纹理对象已经存在了,则返回这个纹理对象的指针
    m_pTex1 = CCTextureCache::sharedTextureCache()->addImage("Images/grossinis_sister1.png");
    m_pTex2 = CCTextureCache::sharedTextureCache()->addImage("Images/grossinis_sister2.png");

    m_pTex1->retain();
    m_pTex2->retain();
}

TextureDrawAtPoint::~TextureDrawAtPoint()
{
    m_pTex1->release();
    m_pTex2->release();
}

std::string TextureDrawAtPoint::title()
{
    return "CCTexture2D: drawAtPoint";
}

std::string TextureDrawAtPoint::subtitle()
{
    return "draws 2 textures using drawAtPoint";
}

void TextureDrawAtPoint::draw()
{
    TextureDemo::draw();

    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //将纹理画在某一点上,就是直接显示这个纹理
    m_pTex1->drawAtPoint(ccp(s.width/2-50, s.height/2 - 50));
    m_pTex2->drawAtPoint(ccp(s.width/2+50, s.height/2 - 50));

}

// TextureDrawInRect

void TextureDrawInRect::onEnter()
{
    TextureDemo::onEnter();
    m_pTex1 = CCTextureCache::sharedTextureCache()->addImage("Images/grossinis_sister1.png");
    m_pTex2 = CCTextureCache::sharedTextureCache()->addImage("Images/grossinis_sister2.png");

    m_pTex1->retain();
    m_pTex2->retain();
}

TextureDrawInRect::~TextureDrawInRect()
{
    m_pTex1->release();
    m_pTex2->release();
}

void TextureDrawInRect::draw()
{
    TextureDemo::draw();

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    CCRect rect1 = CCRectMake( s.width/2 - 80, 20, m_pTex1->getContentSize().width * 0.5f, m_pTex1->getContentSize().height *2 );
    CCRect rect2 = CCRectMake( s.width/2 + 80, s.height/2, m_pTex1->getContentSize().width * 2, m_pTex1->getContentSize().height * 0.5f );
    //将纹理显示在某个矩形区域内,会被拉伸
    m_pTex1->drawInRect(rect1);
    m_pTex2->drawInRect(rect2);

}

std::string TextureDrawInRect::title()
{
    return "CCTexture2D: drawInRect";
}

std::string TextureDrawInRect::subtitle()
{
    return "draws 2 textures using drawInRect";
}

//------------------------------------------------------------------
//
// TextureTestScene
//
//------------------------------------------------------------------
void TextureTestScene::runThisTest()
{
    CCLayer* pLayer = nextTextureTest();
    addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(this);
}

//------------------------------------------------------------------
//
// TextureMemoryAlloc
//
//------------------------------------------------------------------
void TextureMemoryAlloc::onEnter()
{
    TextureDemo::onEnter();  //调用父类的onEnter,初始化公用界面
    m_pBackground = NULL;  //初始化背景sprite为NULL
    
    CCMenuItemFont::setFontSize(24);//设置FontItem中Font的字体大小
    //点击加载PNG格式的背景图像的FONT菜单item,并设置TAG为0
    CCMenuItem *item1 = CCMenuItemFont::create("PNG", this, menu_selector(TextureMemoryAlloc::updateImage));
    item1->setTag(0);
    //点击加载RGBA8格式的背景图像的FONT菜单item,并设置TAG为1
    CCMenuItem *item2 = CCMenuItemFont::create("RGBA8", this, menu_selector(TextureMemoryAlloc::updateImage));
    item2->setTag(1);
    //点击加载RGB8格式的背景图像的FONT菜单item,并设置TAG为2
    CCMenuItem *item3 = CCMenuItemFont::create("RGB8", this, menu_selector(TextureMemoryAlloc::updateImage));
    item3->setTag(2);
    //点击加载RGBA4格式的背景图像的FONT菜单item,并设置TAG为3
    CCMenuItem *item4 = CCMenuItemFont::create("RGBA4", this, menu_selector(TextureMemoryAlloc::updateImage));
    item4->setTag(3);
     //点击加载A8格式的背景图像的FONT菜单item,并设置TAG为4
    CCMenuItem *item5 = CCMenuItemFont::create("A8", this, menu_selector(TextureMemoryAlloc::updateImage));
    item5->setTag(4);
    //初始化menu
    CCMenu *menu = CCMenu::create(item1, item2, item3, item4, item5, NULL);
    menu->alignItemsHorizontally();//设置水平排放menuItems
    
    addChild(menu); //添加menu
    //添加显示当前加载好的背景sprite
    CCMenuItemFont *warmup = CCMenuItemFont::create("warm up texture", this, menu_selector(TextureMemoryAlloc::changeBackgroundVisible));
    //创建menu
    CCMenu *menu2 = CCMenu::create(warmup, NULL);

    menu2->alignItemsHorizontally();
    
    addChild(menu2);
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    
    menu2->setPosition(ccp(s.width/2, s.height/4));
}
//改变背景sprite的显示状态
void TextureMemoryAlloc::changeBackgroundVisible(cocos2d::CCObject *sender)
{
    if (m_pBackground)
    {
        m_pBackground->setVisible(true);
    }
}
//更新背景图片的文件名称,删除旧的sprite,并加载新的sprite
void TextureMemoryAlloc::updateImage(cocos2d::CCObject *sender)
{
    if (m_pBackground)
    {
	    //将背景从父节点删除,true表示删除的同时清空sprite上的actions和scheduledSelectors_,并释放内存
        m_pBackground->removeFromParentAndCleanup(true);
    }
    //删除所有不在使用的纹理缓存,引用计数为1的NODE会被删除,多用于Scene切换的时候
    CCTextureCache::sharedTextureCache()->removeUnusedTextures();
   //根据tag修改文件名称	
    int tag = ((CCNode*)sender)->getTag();
	string file;
	switch (tag) 
    {
		case 0:
			file = "Images/test_1021x1024.png";
			break;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
            // android can not pack .gz file into apk file
        case 1:
            file = "Images/test_1021x1024_rgba8888.pvr";
            break;
        case 2:
            file = "Images/test_1021x1024_rgb888.pvr";
            break;
        case 3:
            file = "Images/test_1021x1024_rgba4444.pvr";
            break;
        case 4:
            file = "Images/test_1021x1024_a8.pvr";
            break;
	    //以上至1923行,为android平台下的文件名称
#else
		//以下为其他平台下的文件名称
		case 1:
			file = "Images/test_1021x1024_rgba8888.pvr.gz";
			break;
		case 2:
			file = "Images/test_1021x1024_rgb888.pvr.gz";
			break;
		case 3:
			file = "Images/test_1021x1024_rgba4444.pvr.gz";
			break;
		case 4:
			file = "Images/test_1021x1024_a8.pvr.gz";
			break;
#endif
	}
    //创建新的背景sprite
    m_pBackground = CCSprite::create(file.c_str());
    addChild(m_pBackground, -10);
   //设为隐藏
    m_pBackground->setVisible(false);
    
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    m_pBackground->setPosition(ccp(s.width/2, s.height/2));
}

string TextureMemoryAlloc::title()
{
    return "Texture memory";
}

string TextureMemoryAlloc::subtitle()
{
    return "Testing Texture Memory allocation. Use Instruments + VM Tracker";
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zanglengyu

敲碗要饭

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值