Add Texture tests.

This commit is contained in:
zhangbin 2015-09-06 17:39:00 +08:00
parent bd47385bbd
commit 5ce4ddfb1d
10 changed files with 365 additions and 0 deletions

View File

@ -1034,6 +1034,8 @@
FADE788A1B96C51C0061590D /* Particle3D in Resources */ = {isa = PBXBuildFile; fileRef = FADE78881B96C51C0061590D /* Particle3D */; };
FADE788D1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */; };
FADE788E1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */; };
FADE78911B9C363D0061590D /* PerformanceTextureTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE788F1B9C363D0061590D /* PerformanceTextureTest.cpp */; };
FADE78921B9C363D0061590D /* PerformanceTextureTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE788F1B9C363D0061590D /* PerformanceTextureTest.cpp */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -2168,6 +2170,8 @@
FADE78881B96C51C0061590D /* Particle3D */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Particle3D; path = "../tests/performance-tests/Resources/Particle3D"; sourceTree = "<group>"; };
FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceSpriteTest.cpp; sourceTree = "<group>"; };
FADE788C1B96D0710061590D /* PerformanceSpriteTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceSpriteTest.h; sourceTree = "<group>"; };
FADE788F1B9C363D0061590D /* PerformanceTextureTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceTextureTest.cpp; sourceTree = "<group>"; };
FADE78901B9C363D0061590D /* PerformanceTextureTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceTextureTest.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -4785,6 +4789,8 @@
FADE78851B96C4780061590D /* PerformanceParticle3DTest.h */,
FADE788B1B96D0710061590D /* PerformanceSpriteTest.cpp */,
FADE788C1B96D0710061590D /* PerformanceSpriteTest.h */,
FADE788F1B9C363D0061590D /* PerformanceTextureTest.cpp */,
FADE78901B9C363D0061590D /* PerformanceTextureTest.h */,
);
path = tests;
sourceTree = "<group>";
@ -6260,6 +6266,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FADE78921B9C363D0061590D /* PerformanceTextureTest.cpp in Sources */,
FA94B2451B90497E0074B261 /* controller.cpp in Sources */,
FADE788E1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */,
FA94B2431B90497E0074B261 /* BaseTest.cpp in Sources */,
@ -6282,6 +6289,7 @@
files = (
FA94B2421B90497E0074B261 /* BaseTest.cpp in Sources */,
FADE78861B96C4780061590D /* PerformanceParticle3DTest.cpp in Sources */,
FADE78911B9C363D0061590D /* PerformanceTextureTest.cpp in Sources */,
FADE786F1B9451540061590D /* PerformanceNodeChildrenTest.cpp in Sources */,
FA94B2351B8F02880074B261 /* Profile.cpp in Sources */,
FADE788D1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */,

View File

@ -0,0 +1,334 @@
#include "PerformanceTextureTest.h"
#include "Profile.h"
USING_NS_CC;
PerformceTextureTests::PerformceTextureTests()
{
ADD_TEST_CASE(TexturePerformceTest);
}
static float calculateDeltaTime( struct timeval *lastUpdate )
{
struct timeval now;
gettimeofday( &now, nullptr);
float dt = (now.tv_sec - lastUpdate->tv_sec) + (now.tv_usec - lastUpdate->tv_usec) / 1000000.0f;
return dt;
}
////////////////////////////////////////////////////////
//
// TexturePerformceTest
//
////////////////////////////////////////////////////////
void TexturePerformceTest::performTestsPNG(const char* filename, const char* fileType, const char* resolution, const char* remark)
{
struct timeval now;
Texture2D *texture;
auto cache = Director::getInstance()->getTextureCache();
Texture2D::PixelFormat defaultFormat = Texture2D::getDefaultAlphaPixelFormat();
log("RGBA 8888");
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA8888);
gettimeofday(&now, nullptr);
texture = cache->addImage(filename);
if( texture )
{
auto dt = calculateDeltaTime(&now);
log(" ms:%f", dt);
if (isAutoTesting())
Profile::getInstance()->addTestResult(genStrVector(fileType, resolution, "RGBA8888", remark, nullptr),
genStrVector(genStr("%f", dt).c_str(), nullptr));
}
else
log(" ERROR");
cache->removeTexture(texture);
log("RGBA 4444");
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGBA4444);
gettimeofday(&now, nullptr);
texture = cache->addImage(filename);
if( texture )
{
auto dt = calculateDeltaTime(&now);
log(" ms:%f", dt);
if (isAutoTesting())
Profile::getInstance()->addTestResult(genStrVector(fileType, resolution, "RGBA4444", remark, nullptr),
genStrVector(genStr("%f", dt).c_str(), nullptr));
}
else
log(" ERROR");
cache->removeTexture(texture);
log("RGBA 5551");
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB5A1);
gettimeofday(&now, nullptr);
texture = cache->addImage(filename);
if( texture )
{
auto dt = calculateDeltaTime(&now);
log(" ms:%f", dt);
if (isAutoTesting())
Profile::getInstance()->addTestResult(genStrVector(fileType, resolution, "RGBA5551", remark, nullptr),
genStrVector(genStr("%f", dt).c_str(), nullptr));
}
else
log(" ERROR");
cache->removeTexture(texture);
log("RGB 565");
Texture2D::setDefaultAlphaPixelFormat(Texture2D::PixelFormat::RGB565);
gettimeofday(&now, nullptr);
texture = cache->addImage(filename);
if( texture )
{
auto dt = calculateDeltaTime(&now);
log(" ms:%f", dt);
if (isAutoTesting())
Profile::getInstance()->addTestResult(genStrVector(fileType, resolution, "RGB565", remark, nullptr),
genStrVector(genStr("%f", dt).c_str(), nullptr));
}
else
log(" ERROR");
cache->removeTexture(texture);
Texture2D::setDefaultAlphaPixelFormat(defaultFormat);
}
void TexturePerformceTest::performTests()
{
if (isAutoTesting()) {
Profile::getInstance()->testCaseBegin("TextureTest",
genStrVector("FileType", "Resolution", "TextureFormat", "Remark", nullptr),
genStrVector("Time", nullptr));
}
// Texture2D *texture;
// struct timeval now;
// auto cache = Director::getInstance()->getTextureCache();
log("--------");
log("--- PNG 128x128 ---");
performTestsPNG("Images/test_image.png", "png", "128x128", "");
// log("--- PVR 128x128 ---");
// log("RGBA 8888");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/test_image_rgba8888.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("BGRA 8888");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/test_image_bgra8888.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/test_image_rgba4444.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("RGB 565");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/test_image_rgb565.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
log("--- PNG 512x512 ---");
performTestsPNG("Images/texture512x512.png", "png", "512x512", "");
// log("--- PVR 512x512 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/texture512x512_rgba4444.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// ---- 1024X1024
// RGBA4444
// Empty image
//
log("EMPTY IMAGE");
log("--- PNG 1024x1024 ---");
performTestsPNG("Images/texture1024x1024.png", "png", "1024x1024", "EMPTY IMAGE");
// log("--- PVR 1024x1024 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("--- PVR.GZ 1024x1024 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr.gz");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("--- PVR.CCZ 1024x1024 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/texture1024x1024_rgba4444.pvr.ccz");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// ---- 1024X1024
// RGBA4444
// SpriteSheet images
//
log("SPRITESHEET IMAGE");
log("--- PNG 1024x1024 ---");
performTestsPNG("Images/PlanetCute-1024x1024.png", "png", "1024x1024", "SPRITESHEET IMAGE");
// log("--- PVR 1024x1024 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("--- PVR.GZ 1024x1024 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr.gz");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("--- PVR.CCZ 1024x1024 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/PlanetCute-1024x1024-rgba4444.pvr.ccz");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// ---- 1024X1024
// RGBA8888
// Landscape Image
//
log("LANDSCAPE IMAGE");
log("--- PNG 1024x1024 ---");
performTestsPNG("Images/landscape-1024x1024.png", "png", "1024x1024", "LANDSCAPE IMAGE");
// log("--- PVR 1024x1024 ---");
// log("RGBA 8888");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("--- PVR.GZ 1024x1024 ---");
// log("RGBA 8888");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr.gz");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// log("--- PVR.CCZ 1024x1024 ---");
// log("RGBA 8888");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/landscape-1024x1024-rgba8888.pvr.ccz");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
//
// 2048x2048
// RGBA444
//
// most platform don't support texture with width/height is 2048
// log("--- PNG 2048x2048 ---");
// performTestsPNG("Images/texture2048x2048.png");
// log("--- PVR 2048x2048 ---");
// log("RGBA 4444");
// gettimeofday(&now, nullptr);
// texture = cache->addImage("Images/texture2048x2048_rgba4444.pvr");
// if( texture )
// log(" ms:%f", calculateDeltaTime(&now) );
// else
// log("ERROR");
// cache->removeTexture(texture);
if (isAutoTesting())
{
Profile::getInstance()->testCaseEnd();
setAutoTesting(false);
}
}
void TexturePerformceTest::onEnter()
{
TestCase::onEnter();
performTests();
}
std::string TexturePerformceTest::title() const
{
return "Texture Performance Test";
}
std::string TexturePerformceTest::subtitle() const
{
return "See console for results";
}

View File

@ -0,0 +1,21 @@
#ifndef __PERFORMANCE_TEXTURE_TEST_H__
#define __PERFORMANCE_TEXTURE_TEST_H__
#include "BaseTest.h"
DEFINE_TEST_SUITE(PerformceTextureTests);
class TexturePerformceTest : public TestCase
{
public:
CREATE_FUNC(TexturePerformceTest);
virtual void performTests();
void performTestsPNG(const char* filename, const char* fileType, const char* resolution, const char* remark);
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onEnter() override;
};
#endif

View File

@ -26,6 +26,7 @@ public:
addTest("Particle3D Tests", []() { return new PerformceParticle3DTests(); });
addTest("Sprite Tests", []() { return new PerformceParticle3DTests(); });
addTest("Sprite Tests", []() { return new PerformceSpriteTests(); });
addTest("Texture Tests", []() { return new PerformceTextureTests(); });
}
};

View File

@ -7,5 +7,6 @@
#include "PerformanceParticleTest.h"
#include "PerformanceParticle3DTest.h"
#include "PerformanceSpriteTest.h"
#include "PerformanceTextureTest.h"
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B