2012-04-19 14:35:52 +08:00
|
|
|
#include "PerformanceTextureTest.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEST_COUNT = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int s_nTexCurCase = 0;
|
|
|
|
|
2011-03-25 13:59:08 +08:00
|
|
|
float calculateDeltaTime( struct timeval *lastUpdate )
|
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
|
|
|
|
gettimeofday( &now, NULL);
|
|
|
|
|
|
|
|
float dt = (now.tv_sec - lastUpdate->tv_sec) + (now.tv_usec - lastUpdate->tv_usec) / 1000000.0f;
|
|
|
|
|
|
|
|
return dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TextureMenuLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void TextureMenuLayer::showCurrentTest()
|
|
|
|
{
|
|
|
|
CCScene* pScene = NULL;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
switch (_curCase)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
pScene = TextureTest::scene();
|
|
|
|
break;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
s_nTexCurCase = _curCase;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (pScene)
|
|
|
|
{
|
|
|
|
CCDirector::sharedDirector()->replaceScene(pScene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureMenuLayer::onEnter()
|
|
|
|
{
|
|
|
|
PerformBasicLayer::onEnter();
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
// Title
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 40);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(label, 1);
|
|
|
|
label->setPosition(ccp(s.width/2, s.height-32));
|
|
|
|
label->setColor(ccc3(255,255,40));
|
|
|
|
|
|
|
|
// Subtitle
|
|
|
|
std::string strSubTitle = subtitle();
|
|
|
|
if(strSubTitle.length())
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLabelTTF *l = CCLabelTTF::create(strSubTitle.c_str(), "Thonburi", 16);
|
2011-03-25 13:59:08 +08:00
|
|
|
addChild(l, 1);
|
|
|
|
l->setPosition(ccp(s.width/2, s.height-80));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
performTests();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TextureMenuLayer::title()
|
|
|
|
{
|
|
|
|
return "no title";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TextureMenuLayer::subtitle()
|
|
|
|
{
|
|
|
|
return "no subtitle";
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TextureTest
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
2011-03-25 13:59:08 +08:00
|
|
|
void TextureTest::performTestsPNG(const char* filename)
|
|
|
|
{
|
|
|
|
struct timeval now;
|
|
|
|
CCTexture2D *texture;
|
|
|
|
CCTextureCache *cache = CCTextureCache::sharedTextureCache();
|
|
|
|
|
|
|
|
CCLog("RGBA 8888");
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
texture = cache->addImage(filename);
|
|
|
|
if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ERROR");
|
2011-03-25 13:59:08 +08:00
|
|
|
cache->removeTexture(texture);
|
|
|
|
|
|
|
|
CCLog("RGBA 4444");
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
texture = cache->addImage(filename);
|
|
|
|
if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ERROR");
|
2011-03-25 13:59:08 +08:00
|
|
|
cache->removeTexture(texture);
|
|
|
|
|
|
|
|
CCLog("RGBA 5551");
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1);
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
texture = cache->addImage(filename);
|
|
|
|
if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ERROR");
|
2011-03-25 13:59:08 +08:00
|
|
|
cache->removeTexture(texture);
|
|
|
|
|
|
|
|
CCLog("RGB 565");
|
|
|
|
CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
|
2012-04-19 14:35:52 +08:00
|
|
|
gettimeofday(&now, NULL);
|
2011-03-25 13:59:08 +08:00
|
|
|
texture = cache->addImage(filename);
|
|
|
|
if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2011-03-25 13:59:08 +08:00
|
|
|
else
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog(" ERROR");
|
2011-03-25 13:59:08 +08:00
|
|
|
cache->removeTexture(texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureTest::performTests()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCTexture2D *texture;
|
|
|
|
// struct timeval now;
|
|
|
|
// CCTextureCache *cache = CCTextureCache::sharedTextureCache();
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("--------");
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("--- PNG 128x128 ---");
|
2011-03-25 13:59:08 +08:00
|
|
|
performTestsPNG("Images/test_image.png");
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR 128x128 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 8888");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/test_image_rgba8888.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
|
|
|
// CCLog("BGRA 8888");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/test_image_bgra8888.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/test_image_rgba4444.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
|
|
|
// CCLog("RGB 565");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/test_image_rgb565.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("--- PNG 512x512 ---");
|
2011-03-25 13:59:08 +08:00
|
|
|
performTestsPNG("Images/texture512x512.png");
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR 512x512 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/texture512x512_rgba4444.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// ---- 1024X1024
|
|
|
|
// RGBA4444
|
|
|
|
// Empty image
|
|
|
|
//
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("EMPTY IMAGE");
|
|
|
|
CCLog("--- PNG 1024x1024 ---");
|
2011-03-25 13:59:08 +08:00
|
|
|
performTestsPNG("Images/texture1024x1024.png");
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR.GZ 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr.gz");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR.CCZ 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr.ccz");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// ---- 1024X1024
|
|
|
|
// RGBA4444
|
|
|
|
// SpriteSheet images
|
|
|
|
//
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("SPRITESHEET IMAGE");
|
|
|
|
CCLog("--- PNG 1024x1024 ---");
|
2011-03-25 13:59:08 +08:00
|
|
|
performTestsPNG("Images/PlanetCute-1024x1024.png");
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR.GZ 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr.gz");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR.CCZ 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr.ccz");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// ---- 1024X1024
|
|
|
|
// RGBA8888
|
|
|
|
// Landscape Image
|
|
|
|
//
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("LANDSCAPE IMAGE");
|
2011-03-25 13:59:08 +08:00
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
CCLog("--- PNG 1024x1024 ---");
|
2011-03-25 13:59:08 +08:00
|
|
|
performTestsPNG("Images/landscape-1024x1024.png");
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 8888");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR.GZ 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 8888");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr.gz");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
|
|
|
//
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR.CCZ 1024x1024 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 8888");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr.ccz");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 2048x2048
|
|
|
|
// RGBA444
|
|
|
|
//
|
|
|
|
|
2011-04-07 14:30:35 +08:00
|
|
|
// most platform don't support texture with width/height is 2048
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PNG 2048x2048 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// performTestsPNG("Images/texture2048x2048.png");
|
|
|
|
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("--- PVR 2048x2048 ---");
|
2012-04-19 14:35:52 +08:00
|
|
|
// CCLog("RGBA 4444");
|
|
|
|
// gettimeofday(&now, NULL);
|
|
|
|
// texture = cache->addImage("Images/texture2048x2048_rgba4444.pvr");
|
|
|
|
// if( texture )
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog(" ms:%f", calculateDeltaTime(&now) );
|
2012-04-19 14:35:52 +08:00
|
|
|
// else
|
2013-03-16 23:56:03 +08:00
|
|
|
// CCLog("ERROR");
|
2012-04-19 14:35:52 +08:00
|
|
|
// cache->removeTexture(texture);
|
2011-03-25 13:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TextureTest::title()
|
|
|
|
{
|
|
|
|
return "Texture Performance Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TextureTest::subtitle()
|
|
|
|
{
|
|
|
|
return "See console for results";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCScene* TextureTest::scene()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene *pScene = CCScene::create();
|
2011-03-25 13:59:08 +08:00
|
|
|
TextureTest *layer = new TextureTest(false, TEST_COUNT, s_nTexCurCase);
|
|
|
|
pScene->addChild(layer);
|
|
|
|
layer->release();
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return pScene;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runTextureTest()
|
|
|
|
{
|
|
|
|
s_nTexCurCase = 0;
|
|
|
|
CCScene* pScene = TextureTest::scene();
|
|
|
|
CCDirector::sharedDirector()->replaceScene(pScene);
|
|
|
|
}
|