2012-03-21 17:27:13 +08:00
|
|
|
#include "ShaderTest.h"
|
|
|
|
#include "../testResource.h"
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocos2d.h"
|
2012-03-21 17:27:13 +08:00
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
#define MAX_LAYER 11
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* createShaderLayer(int nIndex)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
switch (sceneIdx)
|
|
|
|
{
|
2014-05-14 03:55:34 +08:00
|
|
|
case 0: return new ShaderLensFlare();
|
|
|
|
case 1: return new ShaderMandelbrot();
|
|
|
|
case 2: return new ShaderJulia();
|
|
|
|
case 3: return new ShaderHeart();
|
|
|
|
case 4: return new ShaderFlower();
|
|
|
|
case 5: return new ShaderPlasma();
|
|
|
|
case 6: return new ShaderBlur();
|
|
|
|
case 7: return new ShaderRetroEffect();
|
|
|
|
case 8: return new ShaderMonjori();
|
|
|
|
case 9: return new ShaderGlow();
|
|
|
|
case 10: return new ShaderMultiTexture();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* nextAction(void)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = createShaderLayer(sceneIdx);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->autorelease();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* backAction(void)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = createShaderLayer(sceneIdx);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->autorelease();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* restartAction(void)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = createShaderLayer(sceneIdx);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->autorelease();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShaderTestDemo::ShaderTestDemo()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ShaderTestDemo::backCallback(Ref* sender)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new ShaderTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( backAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-03-21 17:27:13 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ShaderTestDemo::nextCallback(Ref* sender)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new ShaderTestScene();//CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( nextAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-03-21 17:27:13 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderTestDemo::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderTestDemo::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ShaderTestDemo::restartCallback(Ref* sender)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new ShaderTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(restartAction());
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///---------------------------------------
|
|
|
|
//
|
|
|
|
// ShaderNode
|
|
|
|
//
|
|
|
|
///---------------------------------------
|
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
SIZE_X = 256,
|
|
|
|
SIZE_Y = 256,
|
2012-03-21 17:27:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ShaderNode::ShaderNode()
|
2014-04-02 15:25:50 +08:00
|
|
|
:_center(Vector2(0.0f, 0.0f))
|
|
|
|
,_resolution(Vector2(0.0f, 0.0f))
|
2013-06-15 14:03:30 +08:00
|
|
|
,_time(0.0f)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-18 10:15:46 +08:00
|
|
|
ShaderNode::~ShaderNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
ShaderNode* ShaderNode::shaderNodeWithVertex(const std::string &vert, const std::string& frag)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto node = new ShaderNode();
|
2012-04-19 14:35:52 +08:00
|
|
|
node->initWithVertex(vert, frag);
|
|
|
|
node->autorelease();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return node;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
bool ShaderNode::initWithVertex(const std::string &vert, const std::string &frag)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-12-31 10:54:37 +08:00
|
|
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
|
|
|
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
|
2014-05-13 10:12:56 +08:00
|
|
|
this->setGLProgramState(nullptr);
|
|
|
|
loadShaderVertex(_vertFileName, _fragFileName);
|
2013-12-31 10:54:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
#endif
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
_vertFileName = vert;
|
|
|
|
_fragFileName = frag;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
loadShaderVertex(vert, frag);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_time = 0;
|
2014-04-02 15:25:50 +08:00
|
|
|
_resolution = Vector2(SIZE_X, SIZE_Y);
|
2014-05-09 09:01:48 +08:00
|
|
|
getGLProgramState()->setUniformVec2("resolution", _resolution);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
scheduleUpdate();
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
setContentSize(Size(SIZE_X, SIZE_Y));
|
2014-04-15 18:23:40 +08:00
|
|
|
setAnchorPoint(Vector2(0.5f, 0.5f));
|
2012-10-18 10:15:46 +08:00
|
|
|
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
void ShaderNode::loadShaderVertex(const std::string &vert, const std::string &frag)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto fileUtiles = FileUtils::getInstance();
|
|
|
|
|
|
|
|
// frag
|
|
|
|
auto fragmentFilePath = fileUtiles->fullPathForFilename(frag);
|
|
|
|
auto fragSource = fileUtiles->getStringFromFile(fragmentFilePath);
|
|
|
|
|
|
|
|
// vert
|
|
|
|
std::string vertSource;
|
|
|
|
if (vert.empty()) {
|
|
|
|
vertSource = ccPositionTextureColor_vert;
|
|
|
|
} else {
|
|
|
|
std::string vertexFilePath = fileUtiles->fullPathForFilename(vert);
|
|
|
|
vertSource = fileUtiles->getStringFromFile(vertexFilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto glprogram = GLProgram::createWithByteArrays(vertSource.c_str(), fragSource.c_str());
|
|
|
|
auto glprogramstate = GLProgramState::getOrCreate(glprogram);
|
|
|
|
setGLProgramState(glprogramstate);
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ShaderNode::update(float dt)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_time += dt;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 16:16:14 +08:00
|
|
|
void ShaderNode::setPosition(const Vector2 &newPosition)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Node::setPosition(newPosition);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto position = getPosition();
|
2014-04-02 15:25:50 +08:00
|
|
|
_center = Vector2(position.x * CC_CONTENT_SCALE_FACTOR(), position.y * CC_CONTENT_SCALE_FACTOR());
|
2014-05-09 09:01:48 +08:00
|
|
|
getGLProgramState()->setUniformVec2("center", _center);
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2014-04-08 22:07:35 +08:00
|
|
|
void ShaderNode::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated)
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-03-06 07:49:08 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(ShaderNode::onDraw, this, transform, transformUpdated);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 16:38:43 +08:00
|
|
|
}
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2014-04-10 10:16:16 +08:00
|
|
|
void ShaderNode::onDraw(const Matrix &transform, bool transformUpdated)
|
2013-12-25 16:38:43 +08:00
|
|
|
{
|
2014-03-06 07:49:08 +08:00
|
|
|
float w = SIZE_X, h = SIZE_Y;
|
|
|
|
GLfloat vertices[12] = {0,0, w,0, w,h, 0,0, 0,h, w,h};
|
|
|
|
|
2014-05-09 06:43:12 +08:00
|
|
|
auto glProgramState = getGLProgramState();
|
|
|
|
glProgramState->setVertexAttribPointer("a_position", 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
|
|
|
glProgramState->apply(transform);
|
2014-05-09 03:34:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
|
|
|
|
2014-02-08 11:37:44 +08:00
|
|
|
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,6);
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ShaderMonjori
|
|
|
|
|
|
|
|
ShaderMonjori::ShaderMonjori()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
init();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderMonjori::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Monjori.fsh");
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sn);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderMonjori::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Shader: Frag shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderMonjori::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Monjori plane deformations";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ShaderMandelbrot
|
|
|
|
ShaderMandelbrot::ShaderMandelbrot()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
init();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderMandelbrot::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Mandelbrot.fsh");
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sn);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderMandelbrot::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Shader: Frag shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderMandelbrot::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Mandelbrot shader with Zoom";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ShaderJulia
|
|
|
|
ShaderJulia::ShaderJulia()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
init();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderJulia::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Julia.fsh");
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sn);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderJulia::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Shader: Frag shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderJulia::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Julia shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ShaderHeart
|
|
|
|
ShaderHeart::ShaderHeart()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
init();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderHeart::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Heart.fsh");
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sn);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderHeart::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Shader: Frag shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderHeart::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Heart";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ShaderFlower
|
|
|
|
ShaderFlower::ShaderFlower()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
init();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderFlower::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Flower.fsh");
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sn);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderFlower::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Shader: Frag shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderFlower::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Flower";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ShaderPlasma
|
|
|
|
ShaderPlasma::ShaderPlasma()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
init();
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderPlasma::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Plasma.fsh");
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sn);
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-21 17:27:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return false;
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderPlasma::title() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Shader: Frag shader";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderPlasma::subtitle() const
|
2012-03-21 17:27:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Plasma";
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|
|
|
|
|
2012-04-17 18:31:31 +08:00
|
|
|
// ShaderBlur
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class SpriteBlur : public Sprite
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-10-18 10:39:56 +08:00
|
|
|
~SpriteBlur();
|
2012-08-01 15:30:12 +08:00
|
|
|
void setBlurSize(float f);
|
2013-06-20 14:17:10 +08:00
|
|
|
bool initWithTexture(Texture2D* texture, const Rect& rect);
|
2014-05-13 10:12:56 +08:00
|
|
|
void initGLProgram();
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
static SpriteBlur* create(const char *pszFileName);
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2013-12-25 16:54:09 +08:00
|
|
|
protected:
|
2014-03-06 07:49:08 +08:00
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
int _blurRadius;
|
2014-04-15 18:23:40 +08:00
|
|
|
Vector2 _pixelSize;
|
2014-02-28 17:34:24 +08:00
|
|
|
|
|
|
|
int _samplingRadius;
|
|
|
|
//gaussian = cons * exp( (dx*dx + dy*dy) * scale);
|
|
|
|
float _scale;
|
|
|
|
float _cons;
|
|
|
|
float _weightSum;
|
2012-04-17 18:31:31 +08:00
|
|
|
};
|
|
|
|
|
2012-10-18 10:39:56 +08:00
|
|
|
SpriteBlur::~SpriteBlur()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
SpriteBlur* SpriteBlur::create(const char *pszFileName)
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
|
|
|
SpriteBlur* pRet = new SpriteBlur();
|
|
|
|
if (pRet && pRet->initWithFile(pszFileName))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
2014-02-28 17:34:24 +08:00
|
|
|
_blurRadius = 0;
|
2013-06-20 14:17:10 +08:00
|
|
|
if( Sprite::initWithTexture(texture, rect) )
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
2013-12-31 10:54:37 +08:00
|
|
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
|
|
|
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
|
2014-05-09 07:42:36 +08:00
|
|
|
setGLProgram(nullptr);
|
2014-05-13 10:12:56 +08:00
|
|
|
initGLProgram();
|
2013-12-31 10:54:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
#endif
|
2012-10-18 10:39:56 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = getTexture()->getContentSizeInPixels();
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_pixelSize = Vector2(1/s.width, 1/s.height);
|
2014-05-09 03:34:26 +08:00
|
|
|
|
2014-02-28 17:34:24 +08:00
|
|
|
_samplingRadius = 0;
|
2014-05-13 10:12:56 +08:00
|
|
|
this->initGLProgram();
|
2014-02-28 17:34:24 +08:00
|
|
|
|
2014-05-09 09:01:48 +08:00
|
|
|
getGLProgramState()->setUniformVec2("onePixelSize", _pixelSize);
|
2014-05-09 03:34:26 +08:00
|
|
|
|
2012-04-17 18:31:31 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
void SpriteBlur::initGLProgram()
|
2012-10-18 10:39:56 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
GLchar * fragSource = (GLchar*) String::createWithContentsOfFile(
|
2014-02-28 17:34:24 +08:00
|
|
|
FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString();
|
2014-05-13 10:12:56 +08:00
|
|
|
auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource);
|
2014-05-09 03:34:26 +08:00
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
auto glProgramState = GLProgramState::getOrCreate(program);
|
|
|
|
setGLProgramState(glProgramState);
|
2012-04-17 18:31:31 +08:00
|
|
|
}
|
|
|
|
|
2012-08-01 15:30:12 +08:00
|
|
|
void SpriteBlur::setBlurSize(float f)
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
2014-02-28 17:34:24 +08:00
|
|
|
if(_blurRadius == (int)f)
|
|
|
|
return;
|
|
|
|
_blurRadius = (int)f;
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2014-02-28 17:34:24 +08:00
|
|
|
_samplingRadius = _blurRadius;
|
|
|
|
if (_samplingRadius > 10)
|
|
|
|
{
|
|
|
|
_samplingRadius = 10;
|
|
|
|
}
|
|
|
|
if (_blurRadius > 0)
|
|
|
|
{
|
|
|
|
float sigma = _blurRadius / 2.0f;
|
|
|
|
_scale = -0.5f / (sigma * sigma);
|
|
|
|
_cons = -1.0f * _scale / 3.141592f;
|
|
|
|
_weightSum = -_cons;
|
|
|
|
|
|
|
|
float weight;
|
|
|
|
int squareX;
|
|
|
|
for(int dx = 0; dx <= _samplingRadius; ++dx)
|
|
|
|
{
|
|
|
|
squareX = dx * dx;
|
|
|
|
weight = _cons * exp(squareX * _scale);
|
|
|
|
_weightSum += 2.0 * weight;
|
|
|
|
for (int dy = 1; dy <= _samplingRadius; ++dy)
|
|
|
|
{
|
|
|
|
weight = _cons * exp((squareX + dy * dy) * _scale);
|
|
|
|
_weightSum += 4.0 * weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log("_blurRadius:%d",_blurRadius);
|
2014-05-09 03:34:26 +08:00
|
|
|
|
2014-05-09 09:01:48 +08:00
|
|
|
getGLProgramState()->setUniformVec4("gaussianCoefficient", Vector4(_samplingRadius, _scale, _cons, _weightSum));
|
2012-04-17 18:31:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ShaderBlur
|
|
|
|
|
|
|
|
ShaderBlur::ShaderBlur()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderBlur::title() const
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
|
|
|
return "Shader: Frag shader";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderBlur::subtitle() const
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
|
|
|
return "Gaussian blur";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider* ShaderBlur::createSliderCtl()
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto screenSize = Director::getInstance()->getWinSize();
|
2014-02-28 17:34:24 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
|
2014-04-15 18:23:40 +08:00
|
|
|
slider->setAnchorPoint(Vector2(0.5f, 1.0f));
|
2012-04-17 18:31:31 +08:00
|
|
|
slider->setMinimumValue(0.0f); // Sets the min value of range
|
2014-02-28 17:34:24 +08:00
|
|
|
slider->setMaximumValue(25.0f); // Sets the max value of range
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
slider->setPosition(Vector2(screenSize.width / 2.0f, screenSize.height / 3.0f));
|
2012-04-17 18:31:31 +08:00
|
|
|
|
|
|
|
// When the value of the slider will change, the given selector will be call
|
2013-07-26 14:37:26 +08:00
|
|
|
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), Control::EventType::VALUE_CHANGED);
|
2014-02-28 17:34:24 +08:00
|
|
|
slider->setValue(2.0f);
|
2012-04-17 18:31:31 +08:00
|
|
|
|
|
|
|
return slider;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderBlur::init()
|
|
|
|
{
|
|
|
|
if( ShaderTestDemo::init() )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_blurSprite = SpriteBlur::create("Images/grossini.png");
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossini.png");
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
_blurSprite->setPosition(Vector2(s.width/3, s.height/2));
|
|
|
|
sprite->setPosition(Vector2(2*s.width/3, s.height/2));
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_blurSprite);
|
2012-04-17 18:31:31 +08:00
|
|
|
addChild(sprite);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_sliderCtl = createSliderCtl();
|
2012-04-17 18:31:31 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_sliderCtl);
|
2012-04-17 18:31:31 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ShaderBlur::sliderAction(Ref* sender, Control::EventType controlEvent)
|
2012-04-17 18:31:31 +08:00
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
ControlSlider* slider = (ControlSlider*)sender;
|
|
|
|
_blurSprite->setBlurSize(slider->getValue());
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ShaderRetroEffect
|
|
|
|
|
|
|
|
ShaderRetroEffect::ShaderRetroEffect()
|
2014-04-09 22:53:59 +08:00
|
|
|
: _label(nullptr)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _accum(0.0f)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderRetroEffect::init()
|
|
|
|
{
|
|
|
|
if( ShaderTestDemo::init() ) {
|
|
|
|
|
2014-05-08 05:38:41 +08:00
|
|
|
GLchar * fragSource = (GLchar*) String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename("Shaders/example_HorizontalColor.fsh"))->getCString();
|
|
|
|
auto p = GLProgram::createWithByteArrays(ccPositionTexture_vert, fragSource);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
|
|
|
auto s = director->getWinSize();
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2014-03-05 14:41:13 +08:00
|
|
|
_label = Label::createWithBMFont("fonts/west_england-64.fnt","RETRO EFFECT");
|
2014-04-15 18:23:40 +08:00
|
|
|
_label->setAnchorPoint(Vector2::ANCHOR_MIDDLE);
|
2014-05-09 07:04:59 +08:00
|
|
|
_label->setGLProgram(p);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_label->setPosition(Vector2(s.width/2,s.height/2));
|
2012-04-18 13:58:24 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_label);
|
2012-04-18 13:58:24 +08:00
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void ShaderRetroEffect::update(float dt)
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_accum += dt;
|
2014-03-07 14:58:44 +08:00
|
|
|
int letterCount = _label->getStringLength();
|
2014-03-05 14:41:13 +08:00
|
|
|
for (int i = 0; i < letterCount; ++i)
|
|
|
|
{
|
|
|
|
auto sprite = _label->getLetter(i);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto oldPosition = sprite->getPosition();
|
2014-04-15 18:23:40 +08:00
|
|
|
sprite->setPosition(Vector2( oldPosition.x, sinf( _accum * 2 + i/2.0) * 20 ));
|
2013-11-29 10:37:40 +08:00
|
|
|
|
2012-04-18 13:58:24 +08:00
|
|
|
// add fabs() to prevent negative scaling
|
2013-06-15 14:03:30 +08:00
|
|
|
float scaleY = ( sinf( _accum * 2 + i/2.0 + 0.707) );
|
2013-11-29 10:37:40 +08:00
|
|
|
|
2012-04-18 13:58:24 +08:00
|
|
|
sprite->setScaleY(scaleY);
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2012-04-18 13:58:24 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderRetroEffect::title() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "Shader: Retro test";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ShaderRetroEffect::subtitle() const
|
2012-04-18 13:58:24 +08:00
|
|
|
{
|
|
|
|
return "sin() effect with moving colors";
|
2012-04-17 18:31:31 +08:00
|
|
|
}
|
|
|
|
|
2014-05-10 02:48:11 +08:00
|
|
|
|
2014-05-10 11:34:15 +08:00
|
|
|
ShaderLensFlare::ShaderLensFlare()
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2014-05-10 11:34:15 +08:00
|
|
|
std::string ShaderLensFlare::title() const
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
return "ShaderToy Test";
|
|
|
|
}
|
|
|
|
|
2014-05-10 11:34:15 +08:00
|
|
|
std::string ShaderLensFlare::subtitle() const
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
2014-05-10 11:34:15 +08:00
|
|
|
return "Lens Flare ";
|
2014-05-10 02:48:11 +08:00
|
|
|
}
|
|
|
|
|
2014-05-10 11:34:15 +08:00
|
|
|
bool ShaderLensFlare::init()
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-13 10:12:56 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/shadertoy_LensFlare.fsh");
|
2014-05-10 02:48:11 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2014-05-10 11:34:15 +08:00
|
|
|
sn->setContentSize(Size(s.width/2,s.height/2));
|
2014-05-10 02:48:11 +08:00
|
|
|
addChild(sn);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
//
|
|
|
|
// ShaderGlow
|
|
|
|
//
|
|
|
|
ShaderGlow::ShaderGlow()
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
std::string ShaderGlow::title() const
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
return "ShaderToy Test";
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
std::string ShaderGlow::subtitle() const
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
2014-05-14 03:55:34 +08:00
|
|
|
return "Glow";
|
2014-05-10 02:48:11 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
bool ShaderGlow::init()
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
2014-05-14 03:55:34 +08:00
|
|
|
auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/shadertoy_Glow.fsh");
|
2014-05-10 02:48:11 +08:00
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
sn->setPosition(Vector2(s.width/2, s.height/2));
|
2014-05-10 11:34:15 +08:00
|
|
|
sn->setContentSize(Size(s.width/2,s.height/2));
|
2014-05-10 02:48:11 +08:00
|
|
|
addChild(sn);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
//
|
|
|
|
// ShaderMultiTexture
|
|
|
|
//
|
|
|
|
ShaderMultiTexture::ShaderMultiTexture()
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
std::string ShaderMultiTexture::title() const
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
2014-05-14 03:55:34 +08:00
|
|
|
return "MultiTexture test";
|
2014-05-10 02:48:11 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
std::string ShaderMultiTexture::subtitle() const
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
2014-05-14 03:55:34 +08:00
|
|
|
return "MultiTexture";
|
2014-05-10 02:48:11 +08:00
|
|
|
}
|
|
|
|
|
2014-05-14 03:55:34 +08:00
|
|
|
bool ShaderMultiTexture::init()
|
2014-05-10 02:48:11 +08:00
|
|
|
{
|
|
|
|
if (ShaderTestDemo::init())
|
|
|
|
{
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-14 03:55:34 +08:00
|
|
|
|
|
|
|
auto sprite = Sprite::create("Images/grossinis_sister1.png");
|
|
|
|
Texture2D *texture1 = Director::getInstance()->getTextureCache()->addImage("Images/grossinis_sister2.png");
|
|
|
|
|
|
|
|
addChild(sprite);
|
|
|
|
|
|
|
|
sprite->setPosition(Vector2(s.width/2, s.height/2));
|
|
|
|
|
|
|
|
auto glprogram = GLProgram::createWithFilenames("Shaders/example_MultiTexture.vsh", "Shaders/example_MultiTexture.fsh");
|
|
|
|
auto glprogramstate = GLProgramState::getOrCreate(glprogram);
|
|
|
|
sprite->setGLProgramState(glprogramstate);
|
|
|
|
|
|
|
|
glprogramstate->setUniformTexture("u_texture1", texture1);
|
2014-05-10 02:48:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-14 03:55:34 +08:00
|
|
|
|
2014-05-10 02:48:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 17:27:13 +08:00
|
|
|
///---------------------------------------
|
2012-11-20 16:16:16 +08:00
|
|
|
//
|
2012-03-21 17:27:13 +08:00
|
|
|
// ShaderTestScene
|
|
|
|
//
|
|
|
|
///---------------------------------------
|
|
|
|
void ShaderTestScene::runThisTest()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx = -1;
|
2012-03-21 17:27:13 +08:00
|
|
|
addChild(nextAction());
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-03-21 17:27:13 +08:00
|
|
|
}
|