From d763de3d3cce41d071a08d126faab57f03e31c0a Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 9 Sep 2013 17:49:13 +0800 Subject: [PATCH 2/7] new shader test code --- .../Classes/ShaderTest/ShaderTest2.cpp | 535 ++++++++++++++++++ .../TestCpp/Classes/ShaderTest/ShaderTest2.h | 88 +++ samples/Cpp/TestCpp/Classes/controller.cpp | 1 + samples/Cpp/TestCpp/Classes/tests.h | 1 + .../project.pbxproj.REMOVED.git-id | 2 +- 5 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp create mode 100644 samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp new file mode 100644 index 0000000000..ce0043c355 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -0,0 +1,535 @@ +#include "ShaderTest2.h" +#include "ShaderTest.h" +#include "../testResource.h" +#include "cocos2d.h" + +namespace ShaderTest2 +{ + static std::function createFunctions[] = + { + CL(NormalSpriteTest), + CL(GreyScaleSpriteTest), + CL(BlurSpriteTest), + CL(NoiseSpriteTest), + CL(EdgeDetectionSpriteTest), + CL(BloomSpriteTest), + CL(CelShadingSpriteTest), + CL(FlameTest3) + }; + + static unsigned int TEST_CASE_COUNT = sizeof(ShaderTest2::createFunctions) / sizeof(ShaderTest2::createFunctions[0]); + + static int sceneIdx=-1; + Layer* createTest(int index) + { + auto layer = (createFunctions[index])();; + + if (layer) + { + layer->autorelease(); + } + + return layer; + } + + Layer* nextAction(); + Layer* backAction(); + Layer* restartAction(); + + Layer* nextAction() + { + sceneIdx++; + sceneIdx = sceneIdx % TEST_CASE_COUNT; + + return createTest(sceneIdx); + } + + Layer* backAction() + { + sceneIdx--; + if( sceneIdx < 0 ) + sceneIdx = TEST_CASE_COUNT -1; + + return createTest(sceneIdx); + } + + Layer* restartAction() + { + return createTest(sceneIdx); + } + +} + +ShaderTestDemo2::ShaderTestDemo2() +{ + +} + +void ShaderTestDemo2::backCallback(Object* sender) +{ + auto s = new ShaderTestScene2(); + s->addChild( ShaderTest2::backAction() ); + Director::getInstance()->replaceScene(s); + s->release(); +} + +void ShaderTestDemo2::nextCallback(Object* sender) +{ + auto s = new ShaderTestScene2();//CCScene::create(); + s->addChild( ShaderTest2::nextAction() ); + Director::getInstance()->replaceScene(s); + s->release(); +} + +void ShaderTestDemo2::restartCallback(Object* sender) +{ + auto s = new ShaderTestScene2(); + s->addChild(ShaderTest2::restartAction()); + + Director::getInstance()->replaceScene(s); + s->release(); +} + +void ShaderTestScene2::runThisTest() +{ + auto layer = ShaderTest2::nextAction(); + addChild(layer); + Director::getInstance()->replaceScene(this); +} + +template +class ShaderSpriteCreator +{ +public: + static spriteType* createSprite(const char* pszFileName) + { + spriteType* pRet = new spriteType(); + if (pRet && pRet->initWithFile(pszFileName)) + { + pRet->autorelease(); + } + else + { + CC_SAFE_DELETE(pRet); + } + return pRet; + } +}; + +class ShaderSprite : public Sprite +{ +public: + ShaderSprite(); + ~ShaderSprite(); + + bool initWithTexture(Texture2D* texture, const Rect& rect); + void draw(); + void initProgram(); + void listenBackToForeground(Object *obj); + +protected: + virtual void buildCustomUniforms() = 0; + virtual void setCustomUniforms() = 0; +protected: + std::string _fragSourceFile; + +}; + +ShaderSprite::ShaderSprite() +{ +} + +ShaderSprite::~ShaderSprite() +{ + NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +} + +void ShaderSprite::listenBackToForeground(Object *obj) +{ + setShaderProgram(NULL); + initProgram(); +} + +bool ShaderSprite::initWithTexture(Texture2D* texture, const Rect& rect) +{ + if( Sprite::initWithTexture(texture, rect) ) + { + NotificationCenter::getInstance()->addObserver(this, + callfuncO_selector(ShaderSprite::listenBackToForeground), + EVNET_COME_TO_FOREGROUND, + NULL); + + this->initProgram(); + + return true; + } + + return false; +} + +void ShaderSprite::initProgram() +{ + GLchar * fragSource = (GLchar*) String::createWithContentsOfFile( + FileUtils::getInstance()->fullPathForFilename(_fragSourceFile.c_str()).c_str())->getCString(); + auto pProgram = new GLProgram(); + pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource); + setShaderProgram(pProgram); + pProgram->release(); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); + getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); + getShaderProgram()->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->link(); + + CHECK_GL_ERROR_DEBUG(); + + getShaderProgram()->updateUniforms(); + + CHECK_GL_ERROR_DEBUG(); + + buildCustomUniforms(); + + CHECK_GL_ERROR_DEBUG(); +} + +void ShaderSprite::draw() +{ + GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX ); + BlendFunc blend = getBlendFunc(); + GL::blendFunc(blend.src, blend.dst); + + getShaderProgram()->use(); + getShaderProgram()->setUniformsForBuiltins(); + setCustomUniforms(); + + GL::bindTexture2D( getTexture()->getName()); + + // + // Attributes + // +#define kQuadSize sizeof(_quad.bl) + long offset = (long)&_quad; + + // vertex + int diff = offsetof( V3F_C4B_T2F, vertices); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); + + // texCoods + diff = offsetof( V3F_C4B_T2F, texCoords); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); + + // color + diff = offsetof( V3F_C4B_T2F, colors); + glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); + + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + CC_INCREMENT_GL_DRAWS(1); +} + +class NormalSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + NormalSprite(); +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +NormalSprite::NormalSprite() +{ + _fragSourceFile = "Shaders/example_normal.fsh"; +} + +void NormalSprite::buildCustomUniforms() +{ + +} + +void NormalSprite::setCustomUniforms() +{ + +} + +class GreyScaleSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + GreyScaleSprite(); +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +GreyScaleSprite::GreyScaleSprite() +{ + _fragSourceFile = "Shaders/example_greyScale.fsh"; +} + +void GreyScaleSprite::buildCustomUniforms() +{ + +} + +void GreyScaleSprite::setCustomUniforms() +{ + +} + +class BlurSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + BlurSprite(); + void setBlurSize(float f); +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +protected: + Point blur_; + GLfloat sub_[4]; + + GLuint blurLocation; + GLuint subLocation; +}; + +BlurSprite::BlurSprite() +{ + _fragSourceFile = "Shaders/example_Blur.fsh"; +} + +void BlurSprite::buildCustomUniforms() +{ + auto s = getTexture()->getContentSizeInPixels(); + + blur_ = Point(1/s.width, 1/s.height); + sub_[0] = sub_[1] = sub_[2] = sub_[3] = 0; + + subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract"); + blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize"); +} + +void BlurSprite::setCustomUniforms() +{ + + getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y); + getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1); +} + +void BlurSprite::setBlurSize(float f) +{ + auto s = getTexture()->getContentSizeInPixels(); + + blur_ = Point(1/s.width, 1/s.height); + blur_ = blur_ * f; +} + +class NoiseSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + NoiseSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +NoiseSprite::NoiseSprite() +{ + _fragSourceFile = "Shaders/example_Noisy.fsh"; +} + +void NoiseSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void NoiseSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +class EdgeDetectionSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + EdgeDetectionSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +EdgeDetectionSprite::EdgeDetectionSprite() +{ + _fragSourceFile = "Shaders/example_edgeDetection.fsh"; +} + +void EdgeDetectionSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void EdgeDetectionSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +class BloomSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + BloomSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +BloomSprite::BloomSprite() +{ + _fragSourceFile = "Shaders/example_bloom.fsh"; +} + +void BloomSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void BloomSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +class CelShadingSprite : public ShaderSprite, public ShaderSpriteCreator +{ +public: + CelShadingSprite(); + +private: + GLfloat _resolution[2]; + GLuint _resolutionLoc; +protected: + virtual void buildCustomUniforms(); + virtual void setCustomUniforms(); +}; + +CelShadingSprite::CelShadingSprite() +{ + _fragSourceFile = "Shaders/example_celShading.fsh"; +} + +void CelShadingSprite::buildCustomUniforms() +{ + _resolutionLoc = glGetUniformLocation( getShaderProgram()->getProgram(), "resolution"); +} + +void CelShadingSprite::setCustomUniforms() +{ + _resolution[0] = getTexture()->getContentSizeInPixels().width; + _resolution[1] = getTexture()->getContentSizeInPixels().height; + + getShaderProgram()->setUniformLocationWith2fv(_resolutionLoc, _resolution, 1); +} + +NormalSpriteTest::NormalSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + NormalSprite* sprite = NormalSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } + +} + +GreyScaleSpriteTest::GreyScaleSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + GreyScaleSprite* sprite = GreyScaleSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } + +} + +BlurSpriteTest::BlurSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + BlurSprite* sprite = BlurSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setBlurSize(1.5); + addChild(sprite); + } + +} + +NoiseSpriteTest::NoiseSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + NoiseSprite* sprite = NoiseSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + +EdgeDetectionSpriteTest::EdgeDetectionSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + EdgeDetectionSprite* sprite = EdgeDetectionSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + +BloomSpriteTest::BloomSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + BloomSprite* sprite = BloomSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + +CelShadingSpriteTest::CelShadingSpriteTest() +{ + if (ShaderTestDemo2::init()) + { + auto s = Director::getInstance()->getWinSize(); + CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/powered.png"); + sprite->setPosition(Point(s.width/2, s.height/2)); + addChild(sprite); + } +} + diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h new file mode 100644 index 0000000000..b284540075 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -0,0 +1,88 @@ +#ifndef _SHADER_TEST2_H_ +#define _SHADER_TEST2_H_ +#include "../testBasic.h" +#include "cocos-ext.h" +#include "../BaseTest.h" + +USING_NS_CC_EXT; + +class ShaderTestDemo2 : public BaseTest +{ +public: + ShaderTestDemo2(void); + virtual std::string title() { return "New Shader Test!";} + void restartCallback(Object* sender); + void nextCallback(Object* sender); + void backCallback(Object* sender); + + CREATE_FUNC(ShaderTestDemo2); +}; + +class ShaderTestScene2 : public TestScene +{ +public: + virtual void runThisTest(); +}; + + + +class NormalSpriteTest : public ShaderTestDemo2 +{ +public: + NormalSpriteTest(); + + virtual std::string subtitle() {return "NormalSpriteTest";} +}; + +class GreyScaleSpriteTest : public ShaderTestDemo2 +{ +public: + GreyScaleSpriteTest(); + + virtual std::string subtitle() {return "GreyScaleSpriteTest";} +}; + +class BlurSpriteTest : public ShaderTestDemo2 +{ +public: + BlurSpriteTest(); + + virtual std::string subtitle() {return "BlurSpriteTest";} +}; + +class NoiseSpriteTest : public ShaderTestDemo2 +{ +public: + NoiseSpriteTest(); + virtual std::string subtitle() {return "NoiseSpriteTest";} +}; + +class EdgeDetectionSpriteTest : public ShaderTestDemo2 +{ +public: + EdgeDetectionSpriteTest(); + virtual std::string subtitle() {return "EdgeDetectionSpriteTest";} +}; + +class BloomSpriteTest : public ShaderTestDemo2 +{ +public: + BloomSpriteTest(); + virtual std::string subtitle() {return "BloomSpriteTest";} +}; + +class CelShadingSpriteTest : public ShaderTestDemo2 +{ +public: + CelShadingSpriteTest(); + virtual std::string subtitle() {return "CelShadingSpriteTest";} +}; + +class FlameTest3 : public ShaderTestDemo2 +{ +public: + FlameTest3() {} + virtual std::string subtitle() {return "FlameTest3";} +}; + +#endif \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index 26971f6452..cd2f4e02b0 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -70,6 +70,7 @@ struct { { "SceneTest", [](){return new SceneTestScene();} }, { "SchedulerTest", [](){return new SchedulerTestScene(); } }, { "ShaderTest", []() { return new ShaderTestScene(); } }, + { "NewShaderTest", []() { return new ShaderTestScene2(); } }, { "SpineTest", []() { return new SpineTestScene(); } }, { "SpriteTest", [](){return new SpriteTestScene(); } }, { "TextInputTest", [](){return new TextInputTestScene(); } }, diff --git a/samples/Cpp/TestCpp/Classes/tests.h b/samples/Cpp/TestCpp/Classes/tests.h index ea26d0223c..7bf7893a75 100644 --- a/samples/Cpp/TestCpp/Classes/tests.h +++ b/samples/Cpp/TestCpp/Classes/tests.h @@ -52,6 +52,7 @@ #include "TextureCacheTest/TextureCacheTest.h" #include "NodeTest/NodeTest.h" #include "ShaderTest/ShaderTest.h" +#include "ShaderTest/ShaderTest2.h" #include "ExtensionsTest/ExtensionsTest.h" #include "MutiTouchTest/MutiTouchTest.h" #if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index 42c17a6004..6e2a278b84 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -d36d2542f8c085962b01d856a008b085589e62e6 \ No newline at end of file +03e60de189259aa934135a3492ddbe49112cda61 \ No newline at end of file From 8a86a883d0901250c7f469c8857c1009063c0cc0 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 9 Sep 2013 21:33:01 +0800 Subject: [PATCH 3/7] issue #2782: update mac version, update test case title --- samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp | 1 - samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h | 2 +- samples/Cpp/TestCpp/Classes/controller.cpp | 2 +- samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index ce0043c355..df59d624bc 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -532,4 +532,3 @@ CelShadingSpriteTest::CelShadingSpriteTest() addChild(sprite); } } - diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h index b284540075..af41389ff8 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -10,7 +10,7 @@ class ShaderTestDemo2 : public BaseTest { public: ShaderTestDemo2(void); - virtual std::string title() { return "New Shader Test!";} + virtual std::string title() { return "Shader Sprite!";} void restartCallback(Object* sender); void nextCallback(Object* sender); void backCallback(Object* sender); diff --git a/samples/Cpp/TestCpp/Classes/controller.cpp b/samples/Cpp/TestCpp/Classes/controller.cpp index cd2f4e02b0..7bb555beef 100644 --- a/samples/Cpp/TestCpp/Classes/controller.cpp +++ b/samples/Cpp/TestCpp/Classes/controller.cpp @@ -70,7 +70,7 @@ struct { { "SceneTest", [](){return new SceneTestScene();} }, { "SchedulerTest", [](){return new SchedulerTestScene(); } }, { "ShaderTest", []() { return new ShaderTestScene(); } }, - { "NewShaderTest", []() { return new ShaderTestScene2(); } }, + { "ShaderTestSprite", []() { return new ShaderTestScene2(); } }, { "SpineTest", []() { return new SpineTestScene(); } }, { "SpriteTest", [](){return new SpriteTestScene(); } }, { "TextInputTest", [](){return new TextInputTestScene(); } }, diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index b0a731cd10..c40efdcb3c 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -fe014a4c9bc5fb6471d516b0e288b0287708c53c \ No newline at end of file +9ee8407529629a345665ab3dccf235c1e7acff22 \ No newline at end of file From f2fc710f868a25dcc0424cb9c61c7713a3f8632b Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 09:32:03 +0800 Subject: [PATCH 4/7] issue #2782: shadertestSprite android make file --- samples/Cpp/TestCpp/Android.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index 68106673cd..6d4374c254 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -101,6 +101,7 @@ Classes/RotateWorldTest/RotateWorldTest.cpp \ Classes/SceneTest/SceneTest.cpp \ Classes/SchedulerTest/SchedulerTest.cpp \ Classes/ShaderTest/ShaderTest.cpp \ +Classes/ShaderTest/ShaderTest2.cpp \ Classes/SpineTest/SpineTest.cpp \ Classes/SpriteTest/SpriteTest.cpp \ Classes/TextInputTest/TextInputTest.cpp \ From 5801e9118ce29c1ce2d839dcaaab481581b1add3 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 09:38:12 +0800 Subject: [PATCH 5/7] issue #2782: remove a blank test case --- samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp | 3 +-- samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index df59d624bc..b386ff3500 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -13,8 +13,7 @@ namespace ShaderTest2 CL(NoiseSpriteTest), CL(EdgeDetectionSpriteTest), CL(BloomSpriteTest), - CL(CelShadingSpriteTest), - CL(FlameTest3) + CL(CelShadingSpriteTest) }; static unsigned int TEST_CASE_COUNT = sizeof(ShaderTest2::createFunctions) / sizeof(ShaderTest2::createFunctions[0]); diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h index af41389ff8..99efb38240 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.h @@ -78,11 +78,4 @@ public: virtual std::string subtitle() {return "CelShadingSpriteTest";} }; -class FlameTest3 : public ShaderTestDemo2 -{ -public: - FlameTest3() {} - virtual std::string subtitle() {return "FlameTest3";} -}; - #endif \ No newline at end of file From 2912260b3a026cbb278fcd047e3d78100d7cab93 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 11:00:57 +0800 Subject: [PATCH 6/7] issue #2782: shadertestSprite linux and windows version --- samples/Cpp/TestCpp/proj.linux/Makefile | 1 + samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 2 ++ samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/samples/Cpp/TestCpp/proj.linux/Makefile b/samples/Cpp/TestCpp/proj.linux/Makefile index e3b33bb427..8dd200ca1d 100644 --- a/samples/Cpp/TestCpp/proj.linux/Makefile +++ b/samples/Cpp/TestCpp/proj.linux/Makefile @@ -85,6 +85,7 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/SceneTest/SceneTest.cpp \ ../Classes/SchedulerTest/SchedulerTest.cpp \ ../Classes/ShaderTest/ShaderTest.cpp \ + ../Classes/ShaderTest/ShaderTest2.cpp \ ../Classes/SpriteTest/SpriteTest.cpp \ ../Classes/TextInputTest/TextInputTest.cpp \ ../Classes/Texture2dTest/Texture2dTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index d954e1eb21..3bea274854 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -158,6 +158,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + @@ -268,6 +269,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index 0580a13014..7c817c403b 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -558,6 +558,9 @@ Classes\PerformanceTest + + Classes\ShaderTest + @@ -1058,5 +1061,8 @@ Classes\LabelTest + + Classes\ShaderTest + \ No newline at end of file From 8e35e7cc273885fef432bb6926512b08cc12a4d2 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 10 Sep 2013 11:45:38 +0800 Subject: [PATCH 7/7] issue #2782: shadertestSprite change test case textures and add normal sprite for comparison --- .../Classes/ShaderTest/ShaderTest2.cpp | 35 ++++++++++++++----- .../Resources/Images/stone.png.REMOVED.git-id | 1 + 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id diff --git a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp index b386ff3500..694a5b9065 100644 --- a/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp +++ b/samples/Cpp/TestCpp/Classes/ShaderTest/ShaderTest2.cpp @@ -469,8 +469,11 @@ GreyScaleSpriteTest::GreyScaleSpriteTest() { auto s = Director::getInstance()->getWinSize(); GreyScaleSprite* sprite = GreyScaleSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -481,9 +484,11 @@ BlurSpriteTest::BlurSpriteTest() { auto s = Director::getInstance()->getWinSize(); BlurSprite* sprite = BlurSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); - sprite->setBlurSize(1.5); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -494,8 +499,11 @@ NoiseSpriteTest::NoiseSpriteTest() { auto s = Director::getInstance()->getWinSize(); NoiseSprite* sprite = NoiseSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -505,8 +513,11 @@ EdgeDetectionSpriteTest::EdgeDetectionSpriteTest() { auto s = Director::getInstance()->getWinSize(); EdgeDetectionSprite* sprite = EdgeDetectionSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/powered.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -515,9 +526,12 @@ BloomSpriteTest::BloomSpriteTest() if (ShaderTestDemo2::init()) { auto s = Director::getInstance()->getWinSize(); - BloomSprite* sprite = BloomSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + BloomSprite* sprite = BloomSprite::createSprite("Images/stone.png"); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/stone.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } @@ -526,8 +540,11 @@ CelShadingSpriteTest::CelShadingSpriteTest() if (ShaderTestDemo2::init()) { auto s = Director::getInstance()->getWinSize(); - CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/powered.png"); - sprite->setPosition(Point(s.width/2, s.height/2)); + CelShadingSprite* sprite = CelShadingSprite::createSprite("Images/stone.png"); + sprite->setPosition(Point(s.width * 0.75, s.height/2)); + auto sprite2 = Sprite::create("Images/stone.png"); + sprite2->setPosition(Point(s.width * 0.25, s.height/2)); addChild(sprite); + addChild(sprite2); } } diff --git a/samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id b/samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id new file mode 100644 index 0000000000..eadaf4c7a1 --- /dev/null +++ b/samples/Cpp/TestCpp/Resources/Images/stone.png.REMOVED.git-id @@ -0,0 +1 @@ +b42f9d96ee0eba96dc53ef311c3b9b273f4456b8 \ No newline at end of file