From ec69a34c51eb3edb553e0b45396a81a3098137f0 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 13 May 2015 16:16:45 +0800 Subject: [PATCH] add issue9767 test --- cocos/3d/CCSprite3D.cpp | 4 +- .../Classes/Sprite3DTest/Sprite3DTest.cpp | 56 +++++++++++++++++++ .../Classes/Sprite3DTest/Sprite3DTest.h | 22 ++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index 6337f5f670..01cac8b823 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -752,8 +752,8 @@ void Sprite3D::setGLProgramState(GLProgramState *glProgramState) } void Sprite3D::setGLProgram(GLProgram *glprogram) { - Node::setGLProgram(glprogram); - setGLProgramState(getGLProgramState()); + auto glProgramState = GLProgramState::create(glprogram); + setGLProgramState(glProgramState); } void Sprite3D::setBlendFunc(const BlendFunc &blendFunc) diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index b3f80a2190..ee81868699 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -55,6 +55,7 @@ Sprite3DTests::Sprite3DTests() ADD_TEST_CASE(Sprite3DForceDepthTest); ADD_TEST_CASE(Sprite3DCubeMapTest); ADD_TEST_CASE(NodeAnimationTest); + ADD_TEST_CASE(Issue9767); }; //------------------------------------------------------------------ @@ -2509,3 +2510,58 @@ void Sprite3DCubeMapTest::onTouchesMoved(const std::vector& touches, coc _camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f)); } } + +Issue9767::Issue9767() +{ + _shaderType = Issue9767::ShaderType::SHADER_TEX; + + auto s = Director::getInstance()->getWinSize(); + auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj"); + sprite->setScale(3.f); + sprite->setTexture("Sprite3DTest/boss.png"); + addChild( sprite ); + sprite->setPosition(Vec2(s.width/2, s.height/2)); + _sprite = sprite; + + TTFConfig ttfConfig("fonts/arial.ttf", 15); + auto label1 = Label::createWithTTF(ttfConfig,"switch shader"); + auto item1 = MenuItemLabel::create(label1,CC_CALLBACK_1(Issue9767::menuCallback_SwitchShader,this) ); + + item1->setPosition( Vec2(s.width * 0.9f - item1->getContentSize().width * 0.5f, s.height * 0.5f - item1->getContentSize().height ) ); + + auto pMenu1 = CCMenu::create(item1, nullptr); + pMenu1->setPosition(Vec2(0,0)); + addChild(pMenu1); +} + +Issue9767::~Issue9767() +{ + +} + +void Issue9767::menuCallback_SwitchShader(cocos2d::Ref* sender) +{ + GLProgram* glProgram = nullptr; + if (_shaderType == Issue9767::ShaderType::SHADER_TEX) + { + _shaderType = Issue9767::ShaderType::SHADER_COLOR; + glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION); + } + else + { + _shaderType = Issue9767::ShaderType::SHADER_TEX; + glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_POSITION_TEXTURE); + } + _sprite->setGLProgram(glProgram); +} + +std::string Issue9767::title() const +{ + return "Issue9767: test setGLProgram"; +} + +std::string Issue9767::subtitle() const +{ + return ""; +} + diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 5670b7c8cf..1c9fc123df 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -532,4 +532,26 @@ protected: #endif }; +/// issue 9767 setGLProgram +class Issue9767 : public Sprite3DTestDemo +{ + enum class ShaderType + { + SHADER_TEX, + SHADER_COLOR, + }; +public: + CREATE_FUNC(Issue9767); + Issue9767(); + ~Issue9767(); + virtual std::string title() const override; + virtual std::string subtitle() const override; + + void menuCallback_SwitchShader(cocos2d::Ref* sender); + +protected: + ShaderType _shaderType; + cocos2d::Sprite3D* _sprite; +}; + #endif