2013-12-18 10:41:09 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-08-31 16:25:45 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2013-12-18 10:41:09 +08:00
|
|
|
|
2021-08-31 16:25:45 +08:00
|
|
|
https://adxe.org
|
2013-12-18 10:41:09 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-12-17 16:34:05 +08:00
|
|
|
#include "NewRendererTest.h"
|
2019-08-05 14:25:58 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <sstream>
|
2019-10-15 09:40:59 +08:00
|
|
|
#include "renderer/backend/Device.h"
|
|
|
|
|
2021-08-31 16:25:45 +08:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
enum CustomProgramType : uint32_t
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
BLUR = 1,
|
2021-08-31 16:25:45 +08:00
|
|
|
SEPIA = 2,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class DurationRecorder
|
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
void startTick(const std::string& key) { _durations[key] = -now(); }
|
2019-08-05 14:25:58 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
int endTick(const std::string& key)
|
|
|
|
{
|
|
|
|
auto n = now();
|
2019-08-05 14:25:58 +08:00
|
|
|
auto itr = _durations.find(key);
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_durations.find(key) == _durations.end())
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
else if (itr->second < 0)
|
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
itr->second = n + itr->second;
|
|
|
|
}
|
2019-10-25 16:40:30 +08:00
|
|
|
return static_cast<int>(itr->second);
|
2019-08-05 14:25:58 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
inline int64_t now() const
|
|
|
|
{
|
|
|
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch())
|
|
|
|
.count();
|
2019-08-05 14:25:58 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void reset() { _durations.clear(); }
|
2019-08-05 14:25:58 +08:00
|
|
|
|
|
|
|
private:
|
2021-12-28 16:06:23 +08:00
|
|
|
std::map<std::string, int64_t> _durations;
|
2019-08-05 14:25:58 +08:00
|
|
|
};
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
NewRendererTests::NewRendererTests()
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
2021-08-31 16:25:45 +08:00
|
|
|
auto programCache = backend::ProgramCache::getInstance();
|
|
|
|
programCache->registerCustomProgramFactory(CustomProgramType::BLUR, positionTextureColor_vert,
|
|
|
|
FileUtils::getInstance()->getStringFromFile("Shaders/example_Blur.fsh"));
|
2021-12-28 16:06:23 +08:00
|
|
|
programCache->registerCustomProgramFactory(
|
|
|
|
CustomProgramType::SEPIA, positionTextureColor_vert,
|
|
|
|
FileUtils::getInstance()->getStringFromFile("Shaders/example_Sepia.fsh"));
|
2019-08-05 14:25:58 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(NewSpriteTest);
|
|
|
|
ADD_TEST_CASE(GroupCommandTest);
|
2021-12-28 16:06:23 +08:00
|
|
|
// ADD_TEST_CASE(NewClippingNodeTest); // When depth and stencil are used together, ...
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(NewDrawNodeTest);
|
|
|
|
ADD_TEST_CASE(NewCullingTest);
|
|
|
|
ADD_TEST_CASE(VBOFullTest);
|
|
|
|
ADD_TEST_CASE(CaptureScreenTest);
|
2016-05-07 22:10:53 +08:00
|
|
|
ADD_TEST_CASE(CaptureNodeTest);
|
2016-02-09 03:25:37 +08:00
|
|
|
ADD_TEST_CASE(BugAutoCulling);
|
|
|
|
ADD_TEST_CASE(RendererBatchQuadTri);
|
2021-12-28 16:06:23 +08:00
|
|
|
ADD_TEST_CASE(RendererUniformBatch);
|
2019-05-14 09:00:27 +08:00
|
|
|
ADD_TEST_CASE(RendererUniformBatch2);
|
2019-08-05 14:25:58 +08:00
|
|
|
ADD_TEST_CASE(SpriteCreation);
|
2019-03-12 10:37:52 +08:00
|
|
|
ADD_TEST_CASE(NonBatchSprites);
|
2013-11-13 03:19:18 +08:00
|
|
|
};
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultiSceneTest::title() const
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
2014-02-28 23:02:22 +08:00
|
|
|
return "New Renderer";
|
2013-11-13 03:19:18 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string MultiSceneTest::subtitle() const
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
2014-02-28 23:02:22 +08:00
|
|
|
return "MultiSceneTest";
|
2013-11-13 03:19:18 +08:00
|
|
|
}
|
|
|
|
|
2013-11-13 03:23:10 +08:00
|
|
|
NewSpriteTest::NewSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto touchListener = EventListenerTouchAllAtOnce::create();
|
2013-11-13 03:23:10 +08:00
|
|
|
touchListener->onTouchesEnded = CC_CALLBACK_2(NewSpriteTest::onTouchesEnded, this);
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-11-08 08:50:53 +08:00
|
|
|
createSpriteTest();
|
2013-11-05 01:14:22 +08:00
|
|
|
createNewSpriteTest();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
NewSpriteTest::~NewSpriteTest() {}
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-11-13 03:19:18 +08:00
|
|
|
void NewSpriteTest::createSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
Sprite* parent = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
parent->setPosition(winSize.width / 4, winSize.height / 2);
|
2013-11-05 01:14:22 +08:00
|
|
|
Sprite* child1 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
child1->setPosition(0.0f, -20.0f);
|
|
|
|
Sprite* child2 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child2->setPosition(20.0f, -20.0f);
|
|
|
|
Sprite* child3 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
child3->setPosition(40.0f, -20.0f);
|
2013-11-08 07:48:37 +08:00
|
|
|
Sprite* child4 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child4->setPosition(60.0f, -20.0f);
|
2013-11-08 07:48:37 +08:00
|
|
|
Sprite* child5 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child5->setPosition(80.0f, -20.0f);
|
|
|
|
Sprite* child6 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child6->setPosition(100.0f, -20.0f);
|
|
|
|
Sprite* child7 = Sprite::create("Images/grossinis_sister2.png");
|
|
|
|
child7->setPosition(120.0f, -20.0f);
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
parent->addChild(child1);
|
|
|
|
parent->addChild(child2);
|
|
|
|
parent->addChild(child3);
|
|
|
|
parent->addChild(child4);
|
2013-11-08 07:48:37 +08:00
|
|
|
parent->addChild(child5);
|
|
|
|
parent->addChild(child6);
|
|
|
|
parent->addChild(child7);
|
2013-11-05 01:14:22 +08:00
|
|
|
addChild(parent);
|
|
|
|
}
|
|
|
|
|
2013-11-13 03:19:18 +08:00
|
|
|
void NewSpriteTest::createNewSpriteTest()
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* parent = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
parent->setPosition(winSize.width * 2 / 3, winSize.height / 2);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child1 = Sprite::create("Images/grossinis_sister1.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child1->setPosition(0.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child2 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child2->setPosition(20.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child3 = Sprite::create("Images/grossinis_sister1.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child3->setPosition(40.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child4 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-05 01:14:22 +08:00
|
|
|
child4->setPosition(60.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child5 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
child5->setPosition(80.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child6 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
child6->setPosition(100.0f, -20.0f);
|
2013-12-23 21:07:25 +08:00
|
|
|
Sprite* child7 = Sprite::create("Images/grossinis_sister2.png");
|
2013-11-08 07:48:37 +08:00
|
|
|
child7->setPosition(120.0f, -20.0f);
|
2013-11-05 01:14:22 +08:00
|
|
|
|
|
|
|
parent->addChild(child1);
|
|
|
|
parent->addChild(child2);
|
|
|
|
parent->addChild(child3);
|
|
|
|
parent->addChild(child4);
|
2013-11-08 07:48:37 +08:00
|
|
|
parent->addChild(child5);
|
|
|
|
parent->addChild(child6);
|
|
|
|
parent->addChild(child7);
|
2013-11-05 01:14:22 +08:00
|
|
|
addChild(parent);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void NewSpriteTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event) {}
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewSpriteTest::title() const
|
2013-11-05 01:14:22 +08:00
|
|
|
{
|
2014-03-06 03:50:12 +08:00
|
|
|
return "Renderer";
|
2013-11-13 03:19:18 +08:00
|
|
|
}
|
2013-11-05 01:14:22 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewSpriteTest::subtitle() const
|
2013-11-13 03:19:18 +08:00
|
|
|
{
|
|
|
|
return "SpriteTest";
|
2013-11-05 01:14:22 +08:00
|
|
|
}
|
2013-11-13 03:53:53 +08:00
|
|
|
|
2014-04-07 22:31:24 +08:00
|
|
|
class SpriteInGroupCommand : public Sprite
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
GroupCommand _spriteWrapperCommand;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-07 22:31:24 +08:00
|
|
|
public:
|
2021-12-28 15:58:56 +08:00
|
|
|
static SpriteInGroupCommand* create(std::string_view filename);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
2014-04-07 22:31:24 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 15:58:56 +08:00
|
|
|
SpriteInGroupCommand* SpriteInGroupCommand::create(std::string_view filename)
|
2014-04-07 22:31:24 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
SpriteInGroupCommand* sprite = new SpriteInGroupCommand();
|
2014-04-07 22:31:24 +08:00
|
|
|
sprite->initWithFile(filename);
|
|
|
|
sprite->autorelease();
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void SpriteInGroupCommand::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
2014-04-07 22:31:24 +08:00
|
|
|
{
|
|
|
|
CCASSERT(renderer, "Render is null");
|
|
|
|
_spriteWrapperCommand.init(_globalZOrder);
|
|
|
|
renderer->addCommand(&_spriteWrapperCommand);
|
|
|
|
renderer->pushGroup(_spriteWrapperCommand.getRenderQueueID());
|
2014-05-31 07:42:05 +08:00
|
|
|
Sprite::draw(renderer, transform, flags);
|
2014-04-07 22:31:24 +08:00
|
|
|
renderer->popGroup();
|
|
|
|
}
|
|
|
|
|
2014-04-07 22:02:43 +08:00
|
|
|
GroupCommandTest::GroupCommandTest()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto sprite = SpriteInGroupCommand::create("Images/grossini.png");
|
2014-04-07 22:02:43 +08:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(winSize.width / 2, winSize.height / 2);
|
2014-04-07 22:02:43 +08:00
|
|
|
addChild(sprite);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
GroupCommandTest::~GroupCommandTest() {}
|
2014-04-07 22:02:43 +08:00
|
|
|
|
|
|
|
std::string GroupCommandTest::title() const
|
|
|
|
{
|
|
|
|
return "Renderer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GroupCommandTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "GroupCommandTest: You should see a sprite";
|
|
|
|
}
|
|
|
|
|
2013-11-16 03:29:11 +08:00
|
|
|
NewClippingNodeTest::NewClippingNodeTest()
|
|
|
|
{
|
2013-11-16 09:32:29 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
2013-12-24 14:08:57 +08:00
|
|
|
auto clipper = ClippingNode::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
clipper->setTag(kTagClipperNode);
|
|
|
|
clipper->setContentSize(Size(200.0f, 200.0f));
|
|
|
|
clipper->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
clipper->setPosition(Vec2(s.width / 2, s.height / 2));
|
2013-11-19 07:52:47 +08:00
|
|
|
|
2013-11-16 03:29:11 +08:00
|
|
|
clipper->runAction(RepeatForever::create(RotateBy::create(1, 45)));
|
|
|
|
this->addChild(clipper);
|
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
// TODO: Fix draw node as clip node
|
2021-12-28 16:06:23 +08:00
|
|
|
// auto stencil = NewDrawNode::create();
|
|
|
|
// Vec2 rectangle[4];
|
|
|
|
// rectangle[0] = Vec2(0, 0);
|
|
|
|
// rectangle[1] = Vec2(clipper->getContentSize().width, 0);
|
|
|
|
// rectangle[2] = Vec2(clipper->getContentSize().width, clipper->getContentSize().height);
|
|
|
|
// rectangle[3] = Vec2(0, clipper->getContentSize().height);
|
|
|
|
//
|
|
|
|
// Color4F white(1, 1, 1, 1);
|
|
|
|
// stencil->drawPolygon(rectangle, 4, white, 1, white);
|
|
|
|
// clipper->setStencil(stencil);
|
|
|
|
|
|
|
|
// Test with alpha Test
|
2013-11-19 07:52:47 +08:00
|
|
|
clipper->setAlphaThreshold(0.05f);
|
2013-12-23 21:07:25 +08:00
|
|
|
auto stencil = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
stencil->setPosition(s.width / 2, s.height / 2);
|
2013-11-19 06:58:41 +08:00
|
|
|
clipper->setStencil(stencil);
|
2013-11-16 03:29:11 +08:00
|
|
|
|
2013-12-23 21:07:25 +08:00
|
|
|
auto content = Sprite::create("Images/background2.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
content->setTag(kTagContentNode);
|
|
|
|
content->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
content->setPosition(Vec2(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2));
|
2013-11-16 03:29:11 +08:00
|
|
|
clipper->addChild(content);
|
|
|
|
|
|
|
|
_scrolling = false;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2013-11-16 03:29:11 +08:00
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(NewClippingNodeTest::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(NewClippingNodeTest::onTouchesMoved, this);
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(NewClippingNodeTest::onTouchesEnded, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
NewClippingNodeTest::~NewClippingNodeTest() {}
|
2013-11-16 03:29:11 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewClippingNodeTest::title() const
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
|
|
|
return "New Render";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewClippingNodeTest::subtitle() const
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
|
|
|
return "ClipNode";
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void NewClippingNodeTest::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
Touch* touch = touches[0];
|
2013-11-16 03:29:11 +08:00
|
|
|
auto clipper = this->getChildByTag(kTagClipperNode);
|
2021-12-28 16:06:23 +08:00
|
|
|
Vec2 point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
|
|
|
|
auto rect = Rect(0, 0, clipper->getContentSize().width, clipper->getContentSize().height);
|
|
|
|
_scrolling = rect.containsPoint(point);
|
|
|
|
_lastPoint = point;
|
2013-11-16 03:29:11 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void NewClippingNodeTest::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!_scrolling)
|
|
|
|
return;
|
|
|
|
Touch* touch = touches[0];
|
2013-11-16 03:29:11 +08:00
|
|
|
auto clipper = this->getChildByTag(kTagClipperNode);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto point = clipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
|
|
|
|
Vec2 diff = point - _lastPoint;
|
2013-11-16 03:29:11 +08:00
|
|
|
auto content = clipper->getChildByTag(kTagContentNode);
|
|
|
|
content->setPosition(content->getPosition() + diff);
|
|
|
|
_lastPoint = point;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void NewClippingNodeTest::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
2013-11-16 03:29:11 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!_scrolling)
|
|
|
|
return;
|
2013-11-16 03:29:11 +08:00
|
|
|
_scrolling = false;
|
|
|
|
}
|
2013-11-20 05:57:39 +08:00
|
|
|
|
|
|
|
/**
|
2021-12-28 16:06:23 +08:00
|
|
|
* NewDrawNode
|
|
|
|
*/
|
2013-11-20 05:57:39 +08:00
|
|
|
NewDrawNodeTest::NewDrawNodeTest()
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
auto parent = Node::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
parent->setPosition(s.width / 2, s.height / 2);
|
2013-11-20 05:57:39 +08:00
|
|
|
addChild(parent);
|
|
|
|
|
2013-12-19 03:45:30 +08:00
|
|
|
auto rectNode = DrawNode::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 rectangle[4];
|
|
|
|
rectangle[0] = Vec2(-50, -50);
|
|
|
|
rectangle[1] = Vec2(50, -50);
|
|
|
|
rectangle[2] = Vec2(50, 50);
|
|
|
|
rectangle[3] = Vec2(-50, 50);
|
2013-11-20 05:57:39 +08:00
|
|
|
|
|
|
|
Color4F white(1, 1, 1, 1);
|
|
|
|
rectNode->drawPolygon(rectangle, 4, white, 1, white);
|
|
|
|
parent->addChild(rectNode);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
NewDrawNodeTest::~NewDrawNodeTest() {}
|
2013-11-20 05:57:39 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewDrawNodeTest::title() const
|
2013-11-20 05:57:39 +08:00
|
|
|
{
|
|
|
|
return "New Render";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewDrawNodeTest::subtitle() const
|
2013-11-20 05:57:39 +08:00
|
|
|
{
|
|
|
|
return "DrawNode";
|
|
|
|
}
|
2013-11-27 10:35:23 +08:00
|
|
|
|
|
|
|
NewCullingTest::NewCullingTest()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
Size size = Director::getInstance()->getWinSize();
|
2014-04-14 11:33:40 +08:00
|
|
|
auto sprite = Sprite::create("Images/btn-about-normal-vertical.png");
|
2014-04-15 07:46:19 +08:00
|
|
|
sprite->setRotation(5);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(size.width / 2, size.height / 3));
|
2014-04-14 11:33:40 +08:00
|
|
|
sprite->setScale(2);
|
|
|
|
addChild(sprite);
|
2014-04-15 22:21:04 +08:00
|
|
|
|
2014-04-14 11:33:40 +08:00
|
|
|
auto sprite2 = Sprite::create("Images/btn-about-normal-vertical.png");
|
|
|
|
sprite2->setRotation(-85);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite2->setPosition(Vec2(size.width / 2, size.height * 2 / 3));
|
2014-04-14 11:33:40 +08:00
|
|
|
sprite2->setScale(2);
|
|
|
|
addChild(sprite2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-14 11:33:40 +08:00
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
2014-04-14 11:45:06 +08:00
|
|
|
listener->setSwallowTouches(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
listener->onTouchBegan = CC_CALLBACK_2(NewCullingTest::onTouchBegan, this);
|
|
|
|
listener->onTouchMoved = CC_CALLBACK_2(NewCullingTest::onTouchMoved, this);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2014-04-14 11:33:40 +08:00
|
|
|
}
|
2013-11-27 14:30:38 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
bool NewCullingTest::onTouchBegan(Touch* touch, Event* event)
|
2014-04-14 11:33:40 +08:00
|
|
|
{
|
2014-04-14 11:45:06 +08:00
|
|
|
auto pos = touch->getLocation();
|
|
|
|
_lastPos = pos;
|
|
|
|
return true;
|
2014-04-14 11:33:40 +08:00
|
|
|
}
|
2013-11-27 14:30:38 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void NewCullingTest::onTouchMoved(Touch* touch, Event* event)
|
|
|
|
{
|
2014-04-14 11:45:06 +08:00
|
|
|
auto pos = touch->getLocation();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
auto offset = pos - _lastPos;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
auto layerPos = getPosition();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto newPos = layerPos + offset;
|
|
|
|
|
2014-04-14 11:45:06 +08:00
|
|
|
setPosition(newPos);
|
|
|
|
_lastPos = pos;
|
2013-11-27 10:35:23 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
NewCullingTest::~NewCullingTest() {}
|
2013-11-27 10:35:23 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewCullingTest::title() const
|
2013-11-27 10:35:23 +08:00
|
|
|
{
|
|
|
|
return "New Render";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string NewCullingTest::subtitle() const
|
2013-11-27 10:35:23 +08:00
|
|
|
{
|
2014-04-14 11:33:40 +08:00
|
|
|
return "Drag the layer to test the result of culling";
|
2013-11-27 10:35:23 +08:00
|
|
|
}
|
|
|
|
|
2019-08-05 14:25:58 +08:00
|
|
|
SpriteCreation::SpriteCreation()
|
|
|
|
{
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2019-08-05 14:25:58 +08:00
|
|
|
Node* parent = Node::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
parent->setPosition(s.width / 2, s.height / 2);
|
2019-08-05 14:25:58 +08:00
|
|
|
addChild(parent);
|
|
|
|
|
|
|
|
#define KEY_CREATION "11"
|
|
|
|
#define KEY_DESTROYATION "22"
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
labelCreate = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "Sprite Creation: ..");
|
|
|
|
labelDestory = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "Destroy Sprites: ..");
|
2019-08-05 14:25:58 +08:00
|
|
|
|
|
|
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
|
|
|
MenuItemFont::setFontSize(65);
|
|
|
|
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(SpriteCreation::delSpritesCallback, this));
|
|
|
|
decrease->setColor(Color3B(0, 200, 20));
|
|
|
|
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(SpriteCreation::addSpritesCallback, this));
|
|
|
|
increase->setColor(Color3B(0, 200, 20));
|
|
|
|
|
|
|
|
auto menu = Menu::create(decrease, increase, nullptr);
|
|
|
|
menu->alignItemsHorizontally();
|
|
|
|
menu->setPosition(Vec2(s.width / 2, s.height - 105));
|
|
|
|
addChild(menu, 1);
|
|
|
|
|
|
|
|
TTFConfig ttfCount("fonts/Marker Felt.ttf", 30);
|
|
|
|
_labelSpriteNum = Label::createWithTTF(ttfCount, "Label");
|
|
|
|
_labelSpriteNum->setColor(Color3B(0, 200, 20));
|
|
|
|
_labelSpriteNum->setPosition(Vec2(s.width / 2, s.height - 130));
|
|
|
|
addChild(_labelSpriteNum);
|
|
|
|
|
|
|
|
updateSpriteCountLabel(totalSprites);
|
|
|
|
|
|
|
|
labelCreate->setPosition(0, -20);
|
|
|
|
labelDestory->setPosition(0, -50);
|
|
|
|
|
|
|
|
parent->addChild(labelCreate);
|
|
|
|
parent->addChild(labelDestory);
|
|
|
|
|
|
|
|
doTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteCreation::updateSpriteCountLabel(int x)
|
|
|
|
{
|
|
|
|
totalSprites = std::max(1, x);
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << totalSprites << " sprites";
|
|
|
|
_labelSpriteNum->setString(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpriteCreation::doTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
DurationRecorder perf;
|
2021-12-28 16:06:23 +08:00
|
|
|
std::vector<std::string> predefineTextures = {"Images/concave.png",
|
|
|
|
"Images/atlastest.png",
|
|
|
|
"Images/grossini_dance_atlas-mono.png",
|
|
|
|
"Images/HelloWorld.png",
|
|
|
|
"Images/background1.png",
|
|
|
|
"Images/background2.png",
|
|
|
|
"Images/stone.png",
|
|
|
|
"Images/issue_17116.png",
|
|
|
|
"Images/sprite_polygon_crash.png",
|
|
|
|
"Images/bitmapFontTest3.png",
|
|
|
|
"Images/cocos-html5.png",
|
|
|
|
"Images/Fog.png",
|
|
|
|
"Images/poly_test_textures.png",
|
|
|
|
"Images/powered.png",
|
|
|
|
"Images/bug14017.png",
|
|
|
|
"Images/test-rgba1.png",
|
|
|
|
"Images/grossinis_heads.png",
|
|
|
|
"Images/cocos2dbanner.png"};
|
2019-08-05 14:25:58 +08:00
|
|
|
|
|
|
|
std::vector<Sprite*> spriteCache;
|
|
|
|
spriteCache.reserve(totalSprites);
|
|
|
|
|
|
|
|
perf.startTick(KEY_CREATION);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int i = 0; i < totalSprites; ++i)
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
auto* sprite = new Sprite();
|
2021-12-28 16:06:23 +08:00
|
|
|
if (sprite == nullptr)
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!sprite->initWithFile(predefineTextures[i % predefineTextures.size()]))
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
delete sprite;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spriteCache.push_back(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto creationDuration = perf.endTick(KEY_CREATION);
|
|
|
|
perf.startTick(KEY_DESTROYATION);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int i = 0; i < totalSprites; ++i)
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
spriteCache[i]->release();
|
|
|
|
}
|
|
|
|
auto destroyDuration = perf.endTick(KEY_DESTROYATION);
|
|
|
|
std::stringstream ss;
|
|
|
|
auto t1_ms = creationDuration * 1.0 / 1000000;
|
2021-12-28 16:06:23 +08:00
|
|
|
ss << "Create " << spriteCache.size() << " sprites takes " << t1_ms << " ms, "
|
|
|
|
<< (int64_t)(spriteCache.size() * 1000 / t1_ms) << " sprites per second!";
|
2019-08-05 14:25:58 +08:00
|
|
|
labelCreate->setString(ss.str());
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (t1_ms < 100)
|
|
|
|
{
|
|
|
|
suggestDelta = (int)(0.5 * totalSprites);
|
|
|
|
}
|
|
|
|
else if (t1_ms < 1000)
|
|
|
|
{
|
|
|
|
suggestDelta = (int)(0.2 * totalSprites);
|
|
|
|
}
|
|
|
|
else if (t1_ms)
|
|
|
|
{
|
|
|
|
suggestDelta = (int)(0.1 * totalSprites);
|
2019-08-05 14:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
suggestDelta = suggestDelta < 1000 ? 1000 : suggestDelta - suggestDelta % 1000;
|
|
|
|
|
|
|
|
ss.str("");
|
|
|
|
auto t2_ms = destroyDuration * 1.0 / 1000000;
|
2021-12-28 16:06:23 +08:00
|
|
|
ss << "Destroy " << spriteCache.size() << " sprites takes " << t2_ms << " ms, "
|
|
|
|
<< (int64_t)(spriteCache.size() * 1000 / t2_ms) << " sprites per second!";
|
2019-08-05 14:25:58 +08:00
|
|
|
labelDestory->setString(ss.str());
|
|
|
|
|
|
|
|
spriteCache.clear();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void SpriteCreation::addSpritesCallback(cocos2d::Ref*)
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
updateSpriteCountLabel(totalSprites + suggestDelta);
|
|
|
|
doTest();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void SpriteCreation::delSpritesCallback(cocos2d::Ref*)
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
updateSpriteCountLabel(totalSprites - suggestDelta);
|
|
|
|
doTest();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SpriteCreation::~SpriteCreation() {}
|
2019-08-05 14:25:58 +08:00
|
|
|
|
|
|
|
std::string SpriteCreation::title() const
|
|
|
|
{
|
|
|
|
return "Sprite Creation";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SpriteCreation::subtitle() const
|
|
|
|
{
|
|
|
|
#if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG == 1
|
|
|
|
return "In debug mode";
|
|
|
|
#else
|
|
|
|
return "In release mode";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-01-15 09:03:54 +08:00
|
|
|
VBOFullTest::VBOFullTest()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2014-01-15 09:03:54 +08:00
|
|
|
Node* parent = Node::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
parent->setPosition(0, 0);
|
2014-01-15 09:03:54 +08:00
|
|
|
addChild(parent);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < Renderer::VBO_SIZE / 3.9; ++i)
|
2014-01-15 09:03:54 +08:00
|
|
|
{
|
|
|
|
Sprite* sprite = Sprite::create("Images/grossini_dance_01.png");
|
2015-01-15 10:07:23 +08:00
|
|
|
sprite->setScale(0.1f, 0.1f);
|
2021-12-28 16:06:23 +08:00
|
|
|
float x = ((float)std::rand()) / RAND_MAX;
|
|
|
|
float y = ((float)std::rand()) / RAND_MAX;
|
2014-10-16 18:30:01 +08:00
|
|
|
sprite->setPosition(Vec2(x * s.width, y * s.height));
|
2014-01-15 09:03:54 +08:00
|
|
|
parent->addChild(sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
VBOFullTest::~VBOFullTest() {}
|
2014-01-15 09:03:54 +08:00
|
|
|
|
|
|
|
std::string VBOFullTest::title() const
|
|
|
|
{
|
|
|
|
return "New Renderer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VBOFullTest::subtitle() const
|
|
|
|
{
|
2017-02-10 10:35:52 +08:00
|
|
|
return "VBO full Test, everything should render normally";
|
2014-01-15 09:11:32 +08:00
|
|
|
}
|
2014-05-13 16:23:35 +08:00
|
|
|
|
|
|
|
CaptureScreenTest::CaptureScreenTest()
|
|
|
|
{
|
2014-05-13 17:17:15 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2014-05-26 20:18:11 +08:00
|
|
|
Vec2 left(s.width / 4, s.height / 2);
|
|
|
|
Vec2 right(s.width / 4 * 3, s.height / 2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-05-13 17:17:15 +08:00
|
|
|
auto sp1 = Sprite::create("Images/grossini.png");
|
|
|
|
sp1->setPosition(left);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto move1 = MoveBy::create(1, Vec2(s.width / 2, 0.0f));
|
|
|
|
auto seq1 = RepeatForever::create(Sequence::create(move1, move1->reverse(), nullptr));
|
2014-05-13 17:17:15 +08:00
|
|
|
addChild(sp1);
|
|
|
|
sp1->runAction(seq1);
|
|
|
|
auto sp2 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
sp2->setPosition(right);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto move2 = MoveBy::create(1, Vec2(-s.width / 2, 0.0f));
|
|
|
|
auto seq2 = RepeatForever::create(Sequence::create(move2, move2->reverse(), nullptr));
|
2014-05-13 17:17:15 +08:00
|
|
|
addChild(sp2);
|
|
|
|
sp2->runAction(seq2);
|
|
|
|
|
|
|
|
auto label1 = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "capture all");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto mi1 = MenuItemLabel::create(label1, CC_CALLBACK_1(CaptureScreenTest::onCaptured, this));
|
|
|
|
auto menu = Menu::create(mi1, nullptr);
|
2014-05-13 17:17:15 +08:00
|
|
|
addChild(menu);
|
|
|
|
menu->setPosition(s.width / 2, s.height / 4);
|
2014-05-13 18:34:35 +08:00
|
|
|
|
2014-05-14 01:06:26 +08:00
|
|
|
_filename = "";
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CaptureScreenTest::~CaptureScreenTest()
|
|
|
|
{
|
2014-05-19 01:12:56 +08:00
|
|
|
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CaptureScreenTest::title() const
|
|
|
|
{
|
2014-05-13 17:17:15 +08:00
|
|
|
return "New Renderer";
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CaptureScreenTest::subtitle() const
|
|
|
|
{
|
2014-05-26 16:32:13 +08:00
|
|
|
return "Capture screen test, press the menu items to capture the screen";
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
2014-05-26 13:42:47 +08:00
|
|
|
void CaptureScreenTest::onCaptured(Ref*)
|
2014-05-13 16:23:35 +08:00
|
|
|
{
|
2014-05-14 01:06:26 +08:00
|
|
|
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
|
2014-05-26 16:32:13 +08:00
|
|
|
removeChildByTag(childTag);
|
2014-05-14 01:06:26 +08:00
|
|
|
_filename = "CaptureScreenTest.png";
|
2021-12-28 16:06:23 +08:00
|
|
|
// retain it to avoid crash caused by invoking afterCaptured
|
2017-09-12 09:39:15 +08:00
|
|
|
this->retain();
|
2014-05-27 14:29:52 +08:00
|
|
|
utils::captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured, this), _filename);
|
2014-05-13 16:23:35 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 15:58:56 +08:00
|
|
|
void CaptureScreenTest::afterCaptured(bool succeed, std::string_view outputFile)
|
2014-05-13 16:23:35 +08:00
|
|
|
{
|
2014-05-13 17:17:15 +08:00
|
|
|
if (succeed)
|
|
|
|
{
|
2014-05-14 10:40:56 +08:00
|
|
|
auto sp = Sprite::create(outputFile);
|
2014-05-26 16:32:13 +08:00
|
|
|
addChild(sp, 0, childTag);
|
2014-05-14 10:40:56 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
sp->setPosition(s.width / 2, s.height / 2);
|
|
|
|
sp->setScale(0.25);
|
2014-05-14 01:06:26 +08:00
|
|
|
_filename = outputFile;
|
2014-05-13 17:17:15 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-26 16:24:57 +08:00
|
|
|
log("Capture screen failed.");
|
2014-05-13 17:17:15 +08:00
|
|
|
}
|
2017-09-12 09:39:15 +08:00
|
|
|
|
|
|
|
// release it since it is retained in `CaptureScreenTest::onCaptured()`
|
|
|
|
this->release();
|
2014-05-14 16:25:47 +08:00
|
|
|
}
|
2015-06-29 17:25:13 +08:00
|
|
|
|
2016-05-07 22:10:53 +08:00
|
|
|
CaptureNodeTest::CaptureNodeTest()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
Vec2 left(s.width / 4, s.height / 2);
|
|
|
|
Vec2 right(s.width / 4 * 3, s.height / 2);
|
|
|
|
|
|
|
|
auto sp1 = Sprite::create("Images/grossini.png");
|
|
|
|
sp1->setPosition(left);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto move1 = MoveBy::create(1, Vec2(s.width / 2, 0.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq1 = RepeatForever::create(Sequence::create(move1, move1->reverse(), nullptr));
|
2016-05-07 22:10:53 +08:00
|
|
|
addChild(sp1);
|
|
|
|
sp1->runAction(seq1);
|
|
|
|
auto sp2 = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
sp2->setPosition(right);
|
2019-09-24 11:31:35 +08:00
|
|
|
auto move2 = MoveBy::create(1, Vec2(-s.width / 2, 0.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq2 = RepeatForever::create(Sequence::create(move2, move2->reverse(), nullptr));
|
2016-05-07 22:10:53 +08:00
|
|
|
addChild(sp2);
|
|
|
|
sp2->runAction(seq2);
|
|
|
|
|
|
|
|
auto label1 = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "capture this scene");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto mi1 = MenuItemLabel::create(label1, CC_CALLBACK_1(CaptureNodeTest::onCaptured, this));
|
|
|
|
auto menu = Menu::create(mi1, nullptr);
|
2016-05-07 22:10:53 +08:00
|
|
|
addChild(menu);
|
|
|
|
menu->setPosition(s.width / 2, s.height / 4);
|
|
|
|
|
|
|
|
_filename = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
CaptureNodeTest::~CaptureNodeTest()
|
|
|
|
{
|
|
|
|
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CaptureNodeTest::title() const
|
|
|
|
{
|
|
|
|
return "New Renderer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CaptureNodeTest::subtitle() const
|
|
|
|
{
|
|
|
|
return "Capture node test, press the menu items to capture this scene with scale 0.5";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureNodeTest::onCaptured(Ref*)
|
2021-12-28 16:06:23 +08:00
|
|
|
{
|
2016-05-07 22:10:53 +08:00
|
|
|
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
|
|
|
|
removeChildByTag(childTag);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2016-05-07 22:10:53 +08:00
|
|
|
_filename = FileUtils::getInstance()->getWritablePath() + "/CaptureNodeTest.png";
|
|
|
|
|
|
|
|
// capture this
|
2021-12-28 16:06:23 +08:00
|
|
|
auto callback = [&](RefPtr<Image> image) {
|
2019-02-27 11:29:20 +08:00
|
|
|
// create a sprite with the captured image directly
|
|
|
|
auto sp = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(image, _filename));
|
|
|
|
addChild(sp, 0, childTag);
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
sp->setPosition(s.width / 2, s.height / 2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-02-27 11:29:20 +08:00
|
|
|
// store to disk
|
|
|
|
image->saveToFile(_filename);
|
|
|
|
};
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-02-27 11:29:20 +08:00
|
|
|
auto callbackFunction = std::bind(callback, std::placeholders::_1);
|
|
|
|
utils::captureNode(this, callbackFunction, 0.5);
|
2016-05-07 22:10:53 +08:00
|
|
|
}
|
|
|
|
|
2015-06-29 17:25:13 +08:00
|
|
|
BugAutoCulling::BugAutoCulling()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2019-10-23 14:58:31 +08:00
|
|
|
auto fastmap = cocos2d::FastTMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2015-07-30 15:07:03 +08:00
|
|
|
this->addChild(fastmap);
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int i = 0; i < 30; i++)
|
|
|
|
{
|
2015-06-29 17:25:13 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossini.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(s.width / 2 + s.width / 10 * i, s.height / 2);
|
2015-06-29 17:25:13 +08:00
|
|
|
this->addChild(sprite);
|
2015-07-30 13:59:50 +08:00
|
|
|
auto label = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "Label");
|
2021-12-28 16:06:23 +08:00
|
|
|
label->setPosition(s.width / 2 + s.width / 10 * i, s.height / 2);
|
2015-07-30 13:59:50 +08:00
|
|
|
this->addChild(label);
|
2015-06-29 17:25:13 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
this->scheduleOnce(
|
|
|
|
[=](float) {
|
|
|
|
auto camera = Director::getInstance()->getRunningScene()->getCameras().front();
|
|
|
|
auto move = MoveBy::create(2.0f, Vec2(2 * s.width, 0.0f));
|
|
|
|
camera->runAction(Sequence::create(move, move->reverse(), nullptr));
|
|
|
|
},
|
|
|
|
1.0f, "lambda-autoculling-bug");
|
2015-06-29 17:25:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string BugAutoCulling::title() const
|
|
|
|
{
|
|
|
|
return "Bug-AutoCulling";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string BugAutoCulling::subtitle() const
|
|
|
|
{
|
|
|
|
return "Moving the camera to the right instead of moving the layer";
|
2016-02-09 03:25:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// RendererBatchQuadTri
|
|
|
|
//
|
|
|
|
|
|
|
|
RendererBatchQuadTri::RendererBatchQuadTri()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int i = 0; i < 250; i++)
|
2016-02-09 03:25:37 +08:00
|
|
|
{
|
|
|
|
int x = CCRANDOM_0_1() * s.width;
|
|
|
|
int y = CCRANDOM_0_1() * s.height;
|
|
|
|
|
|
|
|
auto label = LabelAtlas::create("This is a label", "fonts/tuffy_bold_italic-charmap.plist");
|
|
|
|
label->setColor(Color3B::RED);
|
2021-12-28 16:06:23 +08:00
|
|
|
label->setPosition(Vec2(x, y));
|
2016-02-09 03:25:37 +08:00
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
auto sprite = Sprite::create("fonts/tuffy_bold_italic-charmap.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setTextureRect(Rect(0.0f, 0.0f, 100.0f, 100.0f));
|
|
|
|
sprite->setPosition(Vec2(x, y));
|
2016-02-09 03:25:37 +08:00
|
|
|
sprite->setColor(Color3B::BLUE);
|
|
|
|
addChild(sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RendererBatchQuadTri::title() const
|
|
|
|
{
|
|
|
|
return "RendererBatchQuadTri";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RendererBatchQuadTri::subtitle() const
|
|
|
|
{
|
|
|
|
return "QuadCommand and TriangleCommands are batched together";
|
2016-05-07 22:10:53 +08:00
|
|
|
}
|
2016-08-08 05:51:02 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// RendererUniformBatch
|
|
|
|
//
|
|
|
|
|
2019-05-14 09:00:27 +08:00
|
|
|
RendererUniformBatch::RendererUniformBatch()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto blurState = createBlurProgramState();
|
2019-05-14 09:00:27 +08:00
|
|
|
auto sepiaState = createSepiaProgramState();
|
|
|
|
|
|
|
|
auto x_inc = s.width / 20;
|
|
|
|
auto y_inc = s.height / 6;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int y = 0; y < 6; ++y)
|
2019-05-14 09:00:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int x = 0; x < 20; ++x)
|
2019-05-14 09:00:27 +08:00
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini.png");
|
|
|
|
sprite->setPosition(Vec2(x * x_inc, y * y_inc));
|
|
|
|
sprite->setScale(0.4);
|
|
|
|
addChild(sprite);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (y >= 4)
|
|
|
|
{
|
2019-05-14 09:00:27 +08:00
|
|
|
sprite->setProgramState(sepiaState);
|
2021-12-28 16:06:23 +08:00
|
|
|
}
|
|
|
|
else if (y >= 2)
|
|
|
|
{
|
2019-05-14 09:00:27 +08:00
|
|
|
sprite->setProgramState(blurState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::backend::ProgramState* RendererUniformBatch::createBlurProgramState()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto programState =
|
|
|
|
new backend::ProgramState(backend::ProgramCache::getInstance()->getCustomProgram(CustomProgramType::BLUR));
|
2019-10-15 09:40:59 +08:00
|
|
|
programState->autorelease();
|
2019-05-14 09:00:27 +08:00
|
|
|
|
|
|
|
backend::UniformLocation loc = programState->getUniformLocation("resolution");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto resolution = Vec2(85, 121);
|
2019-05-14 09:00:27 +08:00
|
|
|
programState->setUniform(loc, &resolution, sizeof(resolution));
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
loc = programState->getUniformLocation("blurRadius");
|
2019-05-14 09:00:27 +08:00
|
|
|
float blurRadius = 10.0f;
|
|
|
|
programState->setUniform(loc, &blurRadius, sizeof(blurRadius));
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
loc = programState->getUniformLocation("sampleNum");
|
2019-05-14 09:00:27 +08:00
|
|
|
float sampleNum = 5.0f;
|
|
|
|
programState->setUniform(loc, &sampleNum, sizeof(sampleNum));
|
|
|
|
|
|
|
|
return programState;
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::backend::ProgramState* RendererUniformBatch::createSepiaProgramState()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto programState =
|
|
|
|
new backend::ProgramState(backend::ProgramCache::getInstance()->getCustomProgram(CustomProgramType::SEPIA));
|
2021-08-31 16:25:45 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// programState->updateUniformID();
|
2019-05-14 09:00:27 +08:00
|
|
|
|
2019-10-15 09:40:59 +08:00
|
|
|
programState->autorelease();
|
|
|
|
return programState;
|
2019-05-14 09:00:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string RendererUniformBatch::title() const
|
|
|
|
{
|
|
|
|
return "RendererUniformBatch";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RendererUniformBatch::subtitle() const
|
|
|
|
{
|
|
|
|
return "Only 9 draw calls should appear";
|
|
|
|
}
|
|
|
|
|
2019-02-19 11:57:13 +08:00
|
|
|
////
|
|
|
|
//// RendererUniformBatch2
|
|
|
|
////
|
2019-05-14 09:00:27 +08:00
|
|
|
|
|
|
|
RendererUniformBatch2::RendererUniformBatch2()
|
|
|
|
{
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto blurState = createBlurProgramState();
|
2019-05-14 09:00:27 +08:00
|
|
|
auto sepiaState = createSepiaProgramState();
|
|
|
|
|
|
|
|
auto x_inc = s.width / 20;
|
|
|
|
auto y_inc = s.height / 6;
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int y = 0; y < 6; ++y)
|
2019-05-14 09:00:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int x = 0; x < 20; ++x)
|
2019-05-14 09:00:27 +08:00
|
|
|
{
|
|
|
|
auto sprite = Sprite::create("Images/grossini.png");
|
|
|
|
sprite->setPosition(Vec2(x * x_inc, y * y_inc));
|
|
|
|
sprite->setScale(0.4);
|
|
|
|
addChild(sprite);
|
|
|
|
|
|
|
|
auto r = CCRANDOM_0_1();
|
|
|
|
if (r < 0.33)
|
|
|
|
sprite->setProgramState(sepiaState);
|
|
|
|
else if (r < 0.66)
|
|
|
|
sprite->setProgramState(blurState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
backend::ProgramState* RendererUniformBatch2::createBlurProgramState()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto programState =
|
|
|
|
new backend::ProgramState(backend::ProgramCache::getInstance()->getCustomProgram(CustomProgramType::BLUR));
|
2019-05-14 09:00:27 +08:00
|
|
|
|
|
|
|
backend::UniformLocation loc = programState->getUniformLocation("resolution");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto resolution = Vec2(85, 121);
|
2019-05-14 09:00:27 +08:00
|
|
|
programState->setUniform(loc, &resolution, sizeof(resolution));
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
loc = programState->getUniformLocation("blurRadius");
|
2019-05-14 09:00:27 +08:00
|
|
|
float blurRadius = 10.0f;
|
|
|
|
programState->setUniform(loc, &blurRadius, sizeof(blurRadius));
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
loc = programState->getUniformLocation("sampleNum");
|
2019-05-14 09:00:27 +08:00
|
|
|
float sampleNum = 5.0f;
|
|
|
|
programState->setUniform(loc, &sampleNum, sizeof(sampleNum));
|
|
|
|
|
|
|
|
return programState;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
backend::ProgramState* RendererUniformBatch2::createSepiaProgramState()
|
2019-05-14 09:00:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto programState =
|
|
|
|
new backend::ProgramState(backend::ProgramCache::getInstance()->getCustomProgram(CustomProgramType::SEPIA));
|
2019-10-15 09:40:59 +08:00
|
|
|
programState->autorelease();
|
|
|
|
return programState;
|
2019-05-14 09:00:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string RendererUniformBatch2::title() const
|
|
|
|
{
|
|
|
|
return "RendererUniformBatch 2";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string RendererUniformBatch2::subtitle() const
|
|
|
|
{
|
|
|
|
return "Mixing different shader states should work ok";
|
|
|
|
}
|
2019-03-12 10:37:52 +08:00
|
|
|
|
|
|
|
NonBatchSprites::NonBatchSprites()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2019-08-05 14:25:58 +08:00
|
|
|
_spritesAnchor = Node::create();
|
|
|
|
_spritesAnchor->setPosition(0, 0);
|
|
|
|
addChild(_spritesAnchor);
|
|
|
|
|
|
|
|
_totalSprites = Label::createWithTTF(TTFConfig("fonts/arial.ttf"), "sprites");
|
|
|
|
_totalSprites->setColor(Color3B::YELLOW);
|
|
|
|
_totalSprites->enableOutline(Color4B::RED, 2);
|
2021-12-28 16:06:23 +08:00
|
|
|
_totalSprites->setPosition(s.width / 2, s.height / 2);
|
2019-08-05 14:25:58 +08:00
|
|
|
|
|
|
|
addChild(_totalSprites);
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NonBatchSprites::createSprite()
|
|
|
|
{
|
2019-03-12 10:37:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2019-08-05 14:25:58 +08:00
|
|
|
Sprite* sprite = nullptr;
|
|
|
|
if (_spriteIndex % 2 == 0)
|
2019-03-12 10:37:52 +08:00
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
sprite = Sprite::create("Images/grossini_dance_05.png");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite = Sprite::create("Images/grossini_dance_01.png");
|
|
|
|
}
|
2019-05-14 09:00:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (!sprite)
|
|
|
|
return;
|
2019-08-05 14:25:58 +08:00
|
|
|
auto r = rand_0_1() * 0.6 + 0.2;
|
|
|
|
sprite->setScale(r, r);
|
|
|
|
float x = ((float)std::rand()) / RAND_MAX;
|
|
|
|
float y = ((float)std::rand()) / RAND_MAX;
|
|
|
|
sprite->runAction(RepeatForever::create(RotateBy::create(1, 45)));
|
2019-05-14 09:00:27 +08:00
|
|
|
|
2019-08-05 14:25:58 +08:00
|
|
|
sprite->setPosition(Vec2(x * s.width, y * s.height));
|
|
|
|
_spritesAnchor->addChild(sprite);
|
|
|
|
|
|
|
|
_spriteIndex++;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << _spriteIndex << " sprites";
|
|
|
|
_totalSprites->setString(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void NonBatchSprites::update(float dt)
|
|
|
|
{
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (dt <= 1.0f / 28.0f && dt >= 1.0f / 31.0f)
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
_around30fps.hit();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_around30fps.cancel();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
_maDt = 0.7f * _maDt + 0.3f * dt;
|
|
|
|
_rmaDt = 0.5f * _rmaDt + 0.5f * dt;
|
|
|
|
if (_maDt <= DEST_DT_30FPS)
|
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
_contSlow.cancel();
|
|
|
|
_contFast.hit();
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_contFast.ok())
|
|
|
|
{
|
|
|
|
auto t2 = DEST_DT_30FPS - _rmaDt;
|
2019-08-05 14:25:58 +08:00
|
|
|
auto delta = (int)(t2 / _rmaDt * _spriteIndex * 0.1);
|
2021-12-28 16:06:23 +08:00
|
|
|
delta = std::min(20, std::max(1, delta));
|
|
|
|
for (int i = 0; i < delta; i++)
|
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
createSprite();
|
|
|
|
}
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
_contSlow.hit();
|
|
|
|
_contFast.cancel();
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
if (_contSlow.ok() || _around30fps.ok())
|
2019-08-05 14:25:58 +08:00
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << _spriteIndex << " sprites, DONE!";
|
|
|
|
_totalSprites->setString(ss.str());
|
|
|
|
_totalSprites->setScale(1.2);
|
2019-03-12 10:37:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
NonBatchSprites::~NonBatchSprites() {}
|
2019-03-12 10:37:52 +08:00
|
|
|
|
|
|
|
std::string NonBatchSprites::title() const
|
|
|
|
{
|
|
|
|
return "Non Batched Sprites";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string NonBatchSprites::subtitle() const
|
|
|
|
{
|
2019-08-05 14:25:58 +08:00
|
|
|
#if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG == 1
|
|
|
|
return "DEBUG: simulate lots of sprites, drop to 30 fps";
|
|
|
|
#else
|
|
|
|
return "RELEASE: simulate lots of sprites, drop to 30 fps";
|
|
|
|
#endif
|
2019-03-12 10:37:52 +08:00
|
|
|
}
|