2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-09-10 10:29:39 +08:00
|
|
|
#ifndef _RENDERTEXTURE_TEST_H_
|
|
|
|
#define _RENDERTEXTURE_TEST_H_
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2013-06-08 08:21:11 +08:00
|
|
|
#include "../BaseTest.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
DEFINE_TEST_SUITE(RenderTextureTests);
|
2011-02-25 11:31:49 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
class RenderTextureTest : public TestCase
|
|
|
|
{
|
2011-02-25 11:31:49 +08:00
|
|
|
};
|
|
|
|
|
2012-06-14 18:37:57 +08:00
|
|
|
class RenderTextureSave : public RenderTextureTest
|
2011-08-08 14:06:03 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 09:36:33 +08:00
|
|
|
CREATE_FUNC(RenderTextureSave);
|
2012-04-19 14:35:52 +08:00
|
|
|
RenderTextureSave();
|
|
|
|
~RenderTextureSave();
|
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 onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
void clearImage(cocos2d::Ref* pSender);
|
|
|
|
void saveImage(cocos2d::Ref* pSender);
|
2011-08-08 14:06:03 +08:00
|
|
|
|
|
|
|
private:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::RenderTexture* _target;
|
|
|
|
cocos2d::Vector<cocos2d::Sprite*> _brushs;
|
2011-08-08 14:06:03 +08:00
|
|
|
};
|
|
|
|
|
2012-06-14 18:37:57 +08:00
|
|
|
class RenderTextureIssue937 : public RenderTextureTest
|
2011-02-25 11:31:49 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 09:36:33 +08:00
|
|
|
CREATE_FUNC(RenderTextureIssue937);
|
2011-02-25 11:31:49 +08:00
|
|
|
RenderTextureIssue937();
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2011-02-25 11:31:49 +08:00
|
|
|
};
|
|
|
|
|
2012-06-14 18:37:57 +08:00
|
|
|
class RenderTextureZbuffer : public RenderTextureTest
|
2011-07-08 16:27:13 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 09:36:33 +08:00
|
|
|
CREATE_FUNC(RenderTextureZbuffer);
|
2012-04-19 14:35:52 +08:00
|
|
|
RenderTextureZbuffer();
|
2011-07-08 16:27:13 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2011-07-08 16:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void renderScreenShot();
|
2011-07-08 16:27:13 +08:00
|
|
|
|
|
|
|
private:
|
2016-09-12 09:45:34 +08:00
|
|
|
cocos2d::SpriteBatchNode *mgr;
|
2013-06-20 14:17:10 +08:00
|
|
|
|
|
|
|
cocos2d::Sprite *sp1;
|
|
|
|
cocos2d::Sprite *sp2;
|
|
|
|
cocos2d::Sprite *sp3;
|
|
|
|
cocos2d::Sprite *sp4;
|
|
|
|
cocos2d::Sprite *sp5;
|
|
|
|
cocos2d::Sprite *sp6;
|
|
|
|
cocos2d::Sprite *sp7;
|
|
|
|
cocos2d::Sprite *sp8;
|
|
|
|
cocos2d::Sprite *sp9;
|
2011-07-08 16:27:13 +08:00
|
|
|
};
|
|
|
|
|
2012-06-14 18:37:57 +08:00
|
|
|
class RenderTextureTestDepthStencil : public RenderTextureTest
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 09:36:33 +08:00
|
|
|
CREATE_FUNC(RenderTextureTestDepthStencil);
|
2012-06-14 18:37:57 +08:00
|
|
|
RenderTextureTestDepthStencil();
|
2013-12-31 14:48:07 +08:00
|
|
|
virtual ~RenderTextureTestDepthStencil();
|
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 void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override;
|
2013-12-31 11:49:46 +08:00
|
|
|
private:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::CustomCommand _renderCmds[4];
|
2013-12-31 11:49:46 +08:00
|
|
|
void onBeforeClear();
|
|
|
|
void onBeforeStencil();
|
2017-03-23 09:30:42 +08:00
|
|
|
void onBeforeDraw();
|
2013-12-31 11:49:46 +08:00
|
|
|
void onAfterDraw();
|
2013-12-31 14:48:07 +08:00
|
|
|
|
|
|
|
private:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::RenderTexture* _rend;
|
|
|
|
cocos2d::Sprite* _spriteDS;
|
|
|
|
cocos2d::Sprite* _spriteDraw;
|
2012-06-12 15:55:23 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 16:45:59 +08:00
|
|
|
class RenderTextureTargetNode : public RenderTextureTest
|
|
|
|
{
|
|
|
|
private:
|
2013-06-20 14:17:10 +08:00
|
|
|
cocos2d::Sprite *sprite1, *sprite2;
|
|
|
|
cocos2d::RenderTexture *renderTexture;
|
2012-11-20 16:45:59 +08:00
|
|
|
public:
|
2013-11-14 09:36:33 +08:00
|
|
|
CREATE_FUNC(RenderTextureTargetNode);
|
2012-11-20 16:45:59 +08:00
|
|
|
RenderTextureTargetNode();
|
|
|
|
|
2015-07-15 12:04:48 +08:00
|
|
|
virtual void update(float t)override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2012-11-20 16:45:59 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void touched(cocos2d::Ref* sender);
|
2013-02-28 16:35:42 +08:00
|
|
|
};
|
|
|
|
|
2014-03-04 15:07:54 +08:00
|
|
|
class RenderTexturePartTest : public RenderTextureTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(RenderTexturePartTest);
|
|
|
|
RenderTexturePartTest();
|
|
|
|
virtual ~RenderTexturePartTest();
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
|
|
|
private:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::RenderTexture* _rend;
|
|
|
|
cocos2d::Sprite* _spriteDraw;
|
2014-03-04 15:07:54 +08:00
|
|
|
};
|
|
|
|
|
2013-02-28 16:35:42 +08:00
|
|
|
class SpriteRenderTextureBug : public RenderTextureTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
class SimpleSprite : public cocos2d::Sprite
|
2013-11-14 09:36:33 +08:00
|
|
|
{
|
2013-02-28 16:35:42 +08:00
|
|
|
public:
|
2015-04-09 08:37:30 +08:00
|
|
|
static SimpleSprite* create(const char* filename, const cocos2d::Rect &rect);
|
2013-02-28 16:35:42 +08:00
|
|
|
SimpleSprite();
|
2014-04-11 16:05:22 +08:00
|
|
|
~SimpleSprite();
|
2015-04-09 08:37:30 +08:00
|
|
|
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags);
|
2013-02-28 16:35:42 +08:00
|
|
|
public:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::RenderTexture* _rt;
|
2013-11-14 09:36:33 +08:00
|
|
|
};
|
2013-02-28 16:35:42 +08:00
|
|
|
|
|
|
|
public:
|
2013-11-14 09:36:33 +08:00
|
|
|
CREATE_FUNC(SpriteRenderTextureBug);
|
2013-02-28 16:35:42 +08:00
|
|
|
SpriteRenderTextureBug();
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2013-02-28 16:35:42 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
SimpleSprite* addNewSpriteWithCoords(const cocos2d::Vec2& p);
|
2012-11-20 16:45:59 +08:00
|
|
|
};
|
|
|
|
|
2016-07-21 10:34:04 +08:00
|
|
|
class Issue16113Test : public RenderTextureTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(Issue16113Test);
|
|
|
|
Issue16113Test();
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
cocos2d::RenderTexture* _rend;
|
|
|
|
cocos2d::Sprite* _spriteDraw;
|
|
|
|
};
|
|
|
|
|
2016-11-28 09:50:45 +08:00
|
|
|
class RenderTextureWithSprite3DIssue16894 : public RenderTextureTest
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(RenderTextureWithSprite3DIssue16894);
|
|
|
|
RenderTextureWithSprite3DIssue16894();
|
|
|
|
virtual ~RenderTextureWithSprite3DIssue16894();
|
|
|
|
|
|
|
|
virtual void visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags) override;
|
|
|
|
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
cocos2d::Sprite3D* _ship[3];
|
|
|
|
|
|
|
|
cocos2d::RenderTexture* _renderTexDefault;
|
|
|
|
cocos2d::RenderTexture* _renderTexWithBuffer;
|
|
|
|
};
|
|
|
|
|
2010-09-10 10:29:39 +08:00
|
|
|
#endif
|