From b50a787f6d5d079b89a7fa46391e8fdf846798c6 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 28 Feb 2014 22:03:36 -0800 Subject: [PATCH] Adds new ParticleTest for auto-batching --- cocos/2d/CCProgressTimer.cpp | 3 +- tests/Classes/ParticleTest/ParticleTest.cpp | 38 +++++++++++++++++++-- tests/Classes/ParticleTest/ParticleTest.h | 8 +++++ tests/Classes/ShaderTest/ShaderTest2.cpp | 2 +- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index 9e47e78dbb..2b51dfbdd0 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -532,7 +532,8 @@ void ProgressTimer::onDraw() if(_type == Type::RADIAL) { glDrawArrays(GL_TRIANGLE_FAN, 0, _vertexDataCount); - } + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_vertexDataCount); + } else if (_type == Type::BAR) { if (!_reverseDirection) diff --git a/tests/Classes/ParticleTest/ParticleTest.cpp b/tests/Classes/ParticleTest/ParticleTest.cpp index 5ff2d34e6b..0d91cb729a 100644 --- a/tests/Classes/ParticleTest/ParticleTest.cpp +++ b/tests/Classes/ParticleTest/ParticleTest.cpp @@ -958,8 +958,6 @@ enum static int sceneIdx = -1; -#define MAX_LAYER 45 - Layer* createParticleLayer(int nIndex) { switch(nIndex) @@ -1010,12 +1008,14 @@ Layer* createParticleLayer(int nIndex) case 42: return new PremultipliedAlphaTest(); case 43: return new PremultipliedAlphaTest2(); case 44: return new Issue3990(); + case 45: return new ParticleAutoBatching(); default: break; } return NULL; } +#define MAX_LAYER 46 Layer* nextParticleAction() @@ -1922,6 +1922,40 @@ std::string Issue3990::subtitle() const return "Show '998' or '999' at bottom right side"; } + +// +// ParticleAutoBatching +// +void ParticleAutoBatching::onEnter() +{ + ParticleDemo::onEnter(); + + _color->setColor(Color3B::BLACK); + this->removeChild(_background, true); + _background = NULL; + + Size s = Director::getInstance()->getWinSize(); + + for(int i=0; i<10; i++) { + auto particle = ParticleSystemQuad::create("Particles/SmallSun.plist"); + particle->setTotalParticles(100); + particle->setPosition(Point(i*s.width/11, s.height/2)); + this->addChild(particle ,10); + } +} + +std::string ParticleAutoBatching::title() const +{ + return "AutoBatching"; +} + +std::string ParticleAutoBatching::subtitle() const +{ + return "All 10 particles should be drawin in one batch"; +} + +// +// main // void ParticleTestScene::runThisTest() { diff --git a/tests/Classes/ParticleTest/ParticleTest.h b/tests/Classes/ParticleTest/ParticleTest.h index 42d91981e7..6ca6cc1240 100644 --- a/tests/Classes/ParticleTest/ParticleTest.h +++ b/tests/Classes/ParticleTest/ParticleTest.h @@ -309,4 +309,12 @@ public: virtual std::string subtitle() const override; }; +class ParticleAutoBatching : public ParticleDemo +{ +public: + virtual void onEnter() override; + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + #endif diff --git a/tests/Classes/ShaderTest/ShaderTest2.cpp b/tests/Classes/ShaderTest/ShaderTest2.cpp index e506e64b4d..1758def00a 100644 --- a/tests/Classes/ShaderTest/ShaderTest2.cpp +++ b/tests/Classes/ShaderTest/ShaderTest2.cpp @@ -212,8 +212,8 @@ void ShaderSprite::onDraw() diff = offsetof( V3F_C4B_T2F, colors); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4); } class NormalSprite : public ShaderSprite, public ShaderSpriteCreator