2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-02-24 18:45:25 +08:00
|
|
|
https://adxeproject.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +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:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2019-03-25 10:08:49 +08:00
|
|
|
#pragma once
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
#include "../BaseTest.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "renderer/CCCustomCommand.h"
|
2013-12-27 14:42:45 +08:00
|
|
|
#include <list>
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
namespace cocos2d
|
|
|
|
{
|
|
|
|
namespace backend
|
|
|
|
{
|
2019-03-25 10:08:49 +08:00
|
|
|
class ProgramState;
|
2021-12-28 16:06:23 +08:00
|
|
|
}
|
|
|
|
} // namespace cocos2d
|
2019-03-25 10:08:49 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
DEFINE_TEST_SUITE(ClippingNodeTests);
|
|
|
|
|
|
|
|
class BaseClippingNodeTest : public TestCase
|
2012-11-21 15:22:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(BaseClippingNodeTest);
|
|
|
|
|
2012-11-21 15:22:54 +08:00
|
|
|
~BaseClippingNodeTest();
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual bool init() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
virtual std::string title() const override;
|
2012-11-21 15:22:54 +08:00
|
|
|
virtual void setup();
|
|
|
|
};
|
|
|
|
|
|
|
|
class BasicTest : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(BasicTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2014-08-28 01:54:15 +08:00
|
|
|
virtual void setup() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
virtual cocos2d::Action* actionRotate();
|
|
|
|
virtual cocos2d::Action* actionScale();
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
virtual cocos2d::DrawNode* shape();
|
|
|
|
virtual cocos2d::Sprite* grossini();
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
virtual cocos2d::Node* stencil();
|
|
|
|
virtual cocos2d::ClippingNode* clipper();
|
|
|
|
virtual cocos2d::Node* content();
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShapeTest : public BasicTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(ShapeTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual cocos2d::Node* stencil() override;
|
|
|
|
virtual cocos2d::Node* content() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ShapeInvertedTest : public ShapeTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(ShapeInvertedTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual cocos2d::ClippingNode* clipper() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class SpriteTest : public BasicTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(SpriteTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual cocos2d::Node* stencil() override;
|
|
|
|
virtual cocos2d::ClippingNode* clipper() override;
|
|
|
|
virtual cocos2d::Node* content() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class SpriteNoAlphaTest : public SpriteTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(SpriteNoAlphaTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual cocos2d::ClippingNode* clipper() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class SpriteInvertedTest : public SpriteTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(SpriteInvertedTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual cocos2d::ClippingNode* clipper() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class NestedTest : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(NestedTest);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 07:10:08 +08:00
|
|
|
virtual void setup() override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class HoleDemo : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(HoleDemo);
|
|
|
|
|
2012-11-21 15:22:54 +08:00
|
|
|
~HoleDemo();
|
2015-03-15 07:10:08 +08:00
|
|
|
virtual void setup() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-04-09 08:37:30 +08:00
|
|
|
void pokeHoleAtPoint(cocos2d::Vec2 point);
|
2021-12-28 16:06:23 +08:00
|
|
|
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
|
2012-11-21 15:22:54 +08:00
|
|
|
private:
|
2021-12-28 16:06:23 +08:00
|
|
|
cocos2d::ClippingNode* _outerClipper;
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Node* _holes;
|
|
|
|
cocos2d::Node* _holesStencil;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ScrollViewDemo : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(ScrollViewDemo);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void setup() override;
|
2021-12-28 16:06:23 +08:00
|
|
|
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
|
2012-11-21 15:22:54 +08:00
|
|
|
private:
|
2021-12-28 16:06:23 +08:00
|
|
|
bool _scrolling;
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Vec2 _lastPoint;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//#if COCOS2D_DEBUG > 1
|
|
|
|
|
|
|
|
class RawStencilBufferTest : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(RawStencilBufferTest);
|
|
|
|
|
2012-11-21 15:22:54 +08:00
|
|
|
~RawStencilBufferTest();
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 07:10:08 +08:00
|
|
|
virtual void setup() override;
|
2021-12-28 16:06:23 +08:00
|
|
|
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override;
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
virtual void setupStencilForClippingOnPlane(int plane);
|
|
|
|
virtual void setupStencilForDrawingOnPlane(int plane);
|
2012-11-21 15:22:54 +08:00
|
|
|
|
2013-12-26 15:34:22 +08:00
|
|
|
protected:
|
2019-03-25 10:08:49 +08:00
|
|
|
void onBeforeDrawClip(int planeIndex);
|
|
|
|
void onBeforeDrawSprite(int planeIndex);
|
|
|
|
void initCommands();
|
|
|
|
|
|
|
|
std::vector<cocos2d::CustomCommand> _renderCmds;
|
|
|
|
cocos2d::CallbackCommand _enableStencilCallback;
|
|
|
|
cocos2d::CallbackCommand _disableStencilCallback;
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Vector<cocos2d::Sprite*> _sprites;
|
|
|
|
cocos2d::Vector<cocos2d::Sprite*> _spritesStencil;
|
2019-03-25 10:08:49 +08:00
|
|
|
cocos2d::backend::UniformLocation _locColor;
|
|
|
|
cocos2d::backend::UniformLocation _locMVPMatrix;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class RawStencilBufferTest2 : public RawStencilBufferTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(RawStencilBufferTest2);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string subtitle() const override;
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void setupStencilForClippingOnPlane(int plane) override;
|
|
|
|
virtual void setupStencilForDrawingOnPlane(int plane) override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class RawStencilBufferTest3 : public RawStencilBufferTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(RawStencilBufferTest3);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string subtitle() const override;
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void setupStencilForClippingOnPlane(int plane) override;
|
|
|
|
virtual void setupStencilForDrawingOnPlane(int plane) override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
2014-04-22 10:58:42 +08:00
|
|
|
class RawStencilBufferTestAlphaTest : public RawStencilBufferTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void setup() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RawStencilBufferTest4 : public RawStencilBufferTestAlphaTest
|
2012-11-21 15:22:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(RawStencilBufferTest4);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string subtitle() const override;
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void setupStencilForClippingOnPlane(int plane) override;
|
|
|
|
virtual void setupStencilForDrawingOnPlane(int plane) override;
|
2019-03-25 10:08:49 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
cocos2d::backend::UniformLocation _alphaMVPMatrix;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
2014-04-22 10:58:42 +08:00
|
|
|
class RawStencilBufferTest5 : public RawStencilBufferTestAlphaTest
|
2012-11-21 15:22:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(RawStencilBufferTest5);
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string subtitle() const override;
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void setupStencilForClippingOnPlane(int plane) override;
|
|
|
|
virtual void setupStencilForDrawingOnPlane(int plane) override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
2014-04-22 10:58:42 +08:00
|
|
|
class RawStencilBufferTest6 : public RawStencilBufferTestAlphaTest
|
2012-11-21 15:22:54 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(RawStencilBufferTest6);
|
2014-08-28 01:54:15 +08:00
|
|
|
|
2019-06-05 17:58:33 +08:00
|
|
|
virtual void setupStencilForClippingOnPlane(int plane) override;
|
|
|
|
virtual void setupStencilForDrawingOnPlane(int plane) override;
|
2014-08-28 01:54:15 +08:00
|
|
|
|
|
|
|
// override
|
|
|
|
virtual void setup() override;
|
|
|
|
virtual std::string subtitle() const override;
|
2012-11-21 15:22:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//#endif //COCOS2D_DEBUG > 1
|
|
|
|
|
2014-08-28 01:54:15 +08:00
|
|
|
class ClippingToRenderTextureTest : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ClippingToRenderTextureTest);
|
|
|
|
|
|
|
|
void expectedBehaviour();
|
|
|
|
void reproduceBug();
|
|
|
|
|
|
|
|
// override
|
|
|
|
virtual void setup() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2014-10-15 13:41:47 +08:00
|
|
|
class ClippingRectangleNodeTest : public BaseClippingNodeTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(ClippingRectangleNodeTest);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-10-15 13:41:47 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2015-03-15 07:10:08 +08:00
|
|
|
virtual void setup() override;
|
2014-10-15 13:41:47 +08:00
|
|
|
};
|