axmol/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h

223 lines
6.2 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-28 16:06:23 +08:00
http://www.cocos2d-x.org
2021-12-28 16:06:23 +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
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
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-26 13:45:03 +08:00
#pragma once
#include "ui/CocosGUI.h"
#include "extensions/cocos-ext.h"
#include "../BaseTest.h"
DEFINE_TEST_SUITE(ShaderTests);
class ShaderTestDemo : public TestCase
{
public:
};
class ShaderMonjori : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderMonjori);
ShaderMonjori();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
};
class ShaderMandelbrot : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderMandelbrot);
ShaderMandelbrot();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
};
class ShaderJulia : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderJulia);
ShaderJulia();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
};
class ShaderHeart : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderHeart);
ShaderHeart();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
};
class ShaderFlower : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderFlower);
ShaderFlower();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
};
class ShaderPlasma : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderPlasma);
ShaderPlasma();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
};
class SpriteBlur;
class ShaderBlur : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderBlur);
ShaderBlur();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
void createSliderCtls();
void onRadiusChanged(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
void onSampleNumChanged(cocos2d::Ref* sender, cocos2d::extension::Control::EventType controlEvent);
2021-12-28 16:06:23 +08:00
protected:
SpriteBlur* _blurSprite;
2015-04-09 12:23:47 +08:00
cocos2d::extension::ControlSlider* _sliderRadiusCtl;
cocos2d::extension::ControlSlider* _sliderNumCtrl;
};
class ShaderRetroEffect : public ShaderTestDemo
{
public:
CREATE_FUNC(ShaderRetroEffect);
ShaderRetroEffect();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
virtual void update(float dt) override;
2021-12-28 16:06:23 +08:00
protected:
cocos2d::Label* _label;
2021-12-28 16:06:23 +08:00
float _accum;
};
class ShaderNode : public cocos2d::Node
{
public:
CREATE_FUNC(ShaderNode);
2021-12-28 17:20:17 +08:00
static ShaderNode* shaderNodeWithVertex(std::string_view vert, std::string_view frag);
virtual void update(float dt) override;
2021-12-28 16:06:23 +08:00
virtual void setPosition(const cocos2d::Vec2& newPosition) override;
virtual void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags) override;
2013-12-25 16:38:43 +08:00
protected:
ShaderNode();
~ShaderNode();
2021-12-28 17:20:17 +08:00
bool initWithVertex(std::string_view vert, std::string_view frag);
void loadShaderVertex(std::string_view vert, std::string_view frag);
2021-12-28 16:06:23 +08:00
virtual bool setProgramState(cocos2d::backend::ProgramState* programState, bool needsRetain = true) override
2019-03-26 13:45:03 +08:00
{
2021-12-28 16:06:23 +08:00
if (Node::setProgramState(programState, needsRetain))
{
_customCommand.getPipelineDescriptor().programState = programState;
updateUniforms();
return true;
2019-03-26 13:45:03 +08:00
}
return false;
2019-03-26 13:45:03 +08:00
}
void updateUniforms();
2021-12-28 16:06:23 +08:00
cocos2d::Vec2 _center;
cocos2d::Vec2 _resolution;
float _time;
std::string _vertFileName;
std::string _fragFileName;
cocos2d::CustomCommand _customCommand;
cocos2d::backend::UniformLocation _locResolution;
cocos2d::backend::UniformLocation _locCenter;
cocos2d::backend::UniformLocation _locMVP;
cocos2d::backend::UniformLocation _locTime;
cocos2d::backend::UniformLocation _locSinTime;
cocos2d::backend::UniformLocation _locCosTime;
cocos2d::backend::UniformLocation _locScreenSize;
};
class ShaderLensFlare : public ShaderTestDemo
2014-05-10 02:48:11 +08:00
{
public:
CREATE_FUNC(ShaderLensFlare);
ShaderLensFlare();
2021-12-28 16:06:23 +08:00
2014-05-10 02:48:11 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
2014-05-10 02:48:11 +08:00
};
2014-05-14 03:55:34 +08:00
class ShaderGlow : public ShaderTestDemo
2014-05-10 02:48:11 +08:00
{
public:
CREATE_FUNC(ShaderGlow);
2014-05-14 03:55:34 +08:00
ShaderGlow();
2021-12-28 16:06:23 +08:00
2014-05-10 02:48:11 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
2014-05-10 02:48:11 +08:00
};
2014-05-14 03:55:34 +08:00
class ShaderMultiTexture : public ShaderTestDemo
2014-05-10 02:48:11 +08:00
{
static const int rightSpriteTag = 2014;
2021-12-28 16:06:23 +08:00
2014-05-10 02:48:11 +08:00
public:
CREATE_FUNC(ShaderMultiTexture);
2014-05-14 03:55:34 +08:00
ShaderMultiTexture();
cocos2d::ui::Slider* createSliderCtl();
void changeTexture(cocos2d::Ref*);
int _changedTextureId;
cocos2d::Sprite* _sprite;
2014-05-14 03:55:34 +08:00
2014-05-10 02:48:11 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init() override;
2014-05-10 02:48:11 +08:00
};