From 012f1020ca22eaa5d6c9632fbcf2b283417643bc Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Mon, 12 May 2014 19:12:56 -0700 Subject: [PATCH] GLProgramState fixes It is possible to submit to the Renderer a Sprite with custom uniforms (although it won't be batched). It is possible to use a custom shader + uniforms on Sprite with subclassing Sprite --- cocos/2d/CCAtlasNode.cpp | 4 +- cocos/2d/CCDrawNode.cpp | 2 +- cocos/2d/CCGrid.cpp | 4 +- cocos/2d/CCLabel.cpp | 10 +- cocos/2d/CCLayer.cpp | 2 +- cocos/2d/CCMotionStreak.cpp | 2 +- cocos/2d/CCNode.cpp | 2 +- cocos/2d/CCParticleBatchNode.cpp | 2 +- cocos/2d/CCParticleSystemQuad.cpp | 4 +- cocos/2d/CCProgressTimer.cpp | 2 +- cocos/2d/CCSprite.cpp | 4 +- cocos/2d/CCSpriteBatchNode.cpp | 2 +- cocos/2d/CCTMXLayer.cpp | 2 +- cocos/2d/CCTexture2D.cpp | 4 +- cocos/deprecated/CCDeprecated.h | 2 +- .../editor-support/cocostudio/CCArmature.cpp | 2 +- .../editor-support/cocostudio/CCBatchNode.cpp | 2 +- cocos/editor-support/cocostudio/CCSkin.cpp | 2 +- cocos/editor-support/spine/CCSkeleton.cpp | 2 +- cocos/renderer/CCBatchCommand.h | 2 - cocos/renderer/CCGLProgramState.cpp | 50 +++-- cocos/renderer/CCGLProgramState.h | 10 +- cocos/renderer/CCQuadCommand.cpp | 59 ++--- cocos/renderer/CCQuadCommand.h | 34 +-- cocos/renderer/CCRenderer.cpp | 6 +- cocos/renderer/ccGLStateCache.h | 4 +- .../ClippingNodeTest/ClippingNodeTest.cpp | 2 +- .../CocoStudioArmatureTest/ArmatureScene.cpp | 2 +- .../CocoStudioSceneTest/SceneEditorTest.cpp | 2 +- .../Classes/MutiTouchTest/MutiTouchTest.cpp | 2 +- tests/cpp-tests/Classes/NodeTest/NodeTest.cpp | 2 +- .../Classes/ShaderTest/ShaderTest.cpp | 203 ++++-------------- .../cpp-tests/Classes/ShaderTest/ShaderTest.h | 42 +--- .../Classes/ShaderTest/ShaderTest2.cpp | 202 +---------------- .../Resources/Shaders/example_Flower.vsh | 8 - .../Resources/Shaders/example_Heart.vsh | 8 - .../Resources/Shaders/example_Julia.vsh | 8 - .../Resources/Shaders/example_Mandelbrot.vsh | 8 - .../Resources/Shaders/example_Monjori.vsh | 8 - .../Resources/Shaders/example_Plasma.vsh | 8 - .../Resources/Shaders/example_Twist.vsh | 8 - .../Shaders/example_attribautobind.fsh | 13 -- .../Shaders/example_attribautobind.vsh | 19 -- .../Resources/Shaders/example_normal.vsh | 20 -- .../Resources/Shaders/example_outline.vsh | 20 -- 45 files changed, 163 insertions(+), 643 deletions(-) delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Flower.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Heart.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Julia.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Mandelbrot.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Monjori.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Plasma.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_Twist.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_attribautobind.fsh delete mode 100644 tests/cpp-tests/Resources/Shaders/example_attribautobind.vsh delete mode 100644 tests/cpp-tests/Resources/Shaders/example_normal.vsh delete mode 100755 tests/cpp-tests/Resources/Shaders/example_outline.vsh diff --git a/cocos/2d/CCAtlasNode.cpp b/cocos/2d/CCAtlasNode.cpp index e2927f744a..3403bf51e8 100644 --- a/cocos/2d/CCAtlasNode.cpp +++ b/cocos/2d/CCAtlasNode.cpp @@ -106,7 +106,7 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh _quadsToDraw = itemsToRender; // shader stuff - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); return true; } @@ -138,7 +138,7 @@ void AtlasNode::draw(Renderer *renderer, const Matrix &transform, bool transform _quadCommand.init( _globalZOrder, _textureAtlas->getTexture()->getName(), - getGLProgram(), + getGLProgramState(), _blendFunc, _textureAtlas->getQuads(), _quadsToDraw, diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 7a225a9483..666cf80d35 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -158,7 +158,7 @@ bool DrawNode::init() { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR)); ensureCapacity(512); diff --git a/cocos/2d/CCGrid.cpp b/cocos/2d/CCGrid.cpp index 92924b0204..96f927363a 100644 --- a/cocos/2d/CCGrid.cpp +++ b/cocos/2d/CCGrid.cpp @@ -314,7 +314,7 @@ void Grid3D::blit(void) { int n = _gridSize.width * _gridSize.height; - GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS ); + GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD ); _shaderProgram->use(); _shaderProgram->setUniformsForBuiltins();; @@ -536,7 +536,7 @@ void TiledGrid3D::blit(void) // // Attributes // - GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS ); + GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD ); #ifdef EMSCRIPTEN int numQuads = _gridSize.width * _gridSize.height; diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index f8eb51e1df..7e990b7e28 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -339,21 +339,21 @@ void Label::updateShaderProgram() { case cocos2d::LabelEffect::NORMAL: if (_useDistanceField) - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL)); else if (_useA8Shader) - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_LABEL_NORMAL)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_NORMAL)); else - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); break; case cocos2d::LabelEffect::OUTLINE: - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_LABEL_OUTLINE)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_OUTLINE)); _uniformEffectColor = glGetUniformLocation(getGLProgram()->getProgram(), "v_effectColor"); break; case cocos2d::LabelEffect::GLOW: if (_useDistanceField) { - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW)); _uniformEffectColor = glGetUniformLocation(getGLProgram()->getProgram(), "v_effectColor"); } break; diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index e27f5e1989..621012bc2d 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -534,7 +534,7 @@ bool LayerColor::initWithColor(const Color4B& color, GLfloat w, GLfloat h) updateColor(); setContentSize(Size(w, h)); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR_NO_MVP)); return true; } return false; diff --git a/cocos/2d/CCMotionStreak.cpp b/cocos/2d/CCMotionStreak.cpp index f3fcd43fc5..3ec2972d44 100644 --- a/cocos/2d/CCMotionStreak.cpp +++ b/cocos/2d/CCMotionStreak.cpp @@ -128,7 +128,7 @@ bool MotionStreak::initWithFade(float fade, float minSeg, float stroke, const Co _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; // shader state - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); setTexture(texture); setColor(color); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 3622946209..7296f3dec8 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -647,7 +647,7 @@ void Node::setGLProgram(GLProgram *glProgram) if (_glProgramState == nullptr || (_glProgramState && _glProgramState->getGLProgram() != glProgram)) { CC_SAFE_RELEASE(_glProgramState); - _glProgramState = GLProgramState::get(glProgram); + _glProgramState = GLProgramState::getOrCreate(glProgram); _glProgramState->retain(); } } diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 0d8296dd80..77bca62e7e 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -103,7 +103,7 @@ bool ParticleBatchNode::initWithTexture(Texture2D *tex, int capacity) _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } diff --git a/cocos/2d/CCParticleSystemQuad.cpp b/cocos/2d/CCParticleSystemQuad.cpp index 887ef92569..941aab8ac5 100644 --- a/cocos/2d/CCParticleSystemQuad.cpp +++ b/cocos/2d/CCParticleSystemQuad.cpp @@ -131,7 +131,7 @@ bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles) setupVBO(); } - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); #if CC_ENABLE_CACHE_TEXTURE_DATA // Need to listen the event only when not use batchnode, because it will use VBO @@ -374,7 +374,7 @@ void ParticleSystemQuad::draw(Renderer *renderer, const Matrix &transform, bool //quad command if(_particleIdx > 0) { - _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgram(), _blendFunc, _quads, _particleIdx, transform); + _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _quads, _particleIdx, transform); renderer->addCommand(&_quadCommand); } } diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index 2d9f8edb89..f4fc73987f 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -87,7 +87,7 @@ bool ProgressTimer::initWithSprite(Sprite* sp) setSprite(sp); // shader state - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 8e038b3603..34305cae42 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -249,7 +249,7 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) _quad.tr.colors = Color4B::WHITE; // shader state - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); // update texture (calls updateBlendFunc) setTexture(texture); @@ -590,7 +590,7 @@ void Sprite::draw(Renderer *renderer, const Matrix &transform, bool transformUpd if(_insideBounds) { - _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgram(), _blendFunc, &_quad, 1, transform); + _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transform); renderer->addCommand(&_quadCommand); #if CC_SPRITE_DEBUG_DRAW _customDebugDrawCommand.init(_globalZOrder); diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 1e363f04b8..b2bfaa4bfb 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -100,7 +100,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity) _descendants.reserve(capacity); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return true; } diff --git a/cocos/2d/CCTMXLayer.cpp b/cocos/2d/CCTMXLayer.cpp index e6d75570c4..d88dcd4c0e 100644 --- a/cocos/2d/CCTMXLayer.cpp +++ b/cocos/2d/CCTMXLayer.cpp @@ -205,7 +205,7 @@ void TMXLayer::parseInternalProperties() _useAutomaticVertexZ = true; auto alphaFuncVal = getProperty("cc_alpha_func"); float alphaFuncValue = alphaFuncVal.asFloat(); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST)); GLint alphaValueLocation = glGetUniformLocation(getGLProgram()->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE); diff --git a/cocos/2d/CCTexture2D.cpp b/cocos/2d/CCTexture2D.cpp index 2a62e4b231..cd7075b4cd 100644 --- a/cocos/2d/CCTexture2D.cpp +++ b/cocos/2d/CCTexture2D.cpp @@ -1159,7 +1159,7 @@ void Texture2D::drawAtPoint(const Vector2& point) point.x, height + point.y, width + point.x, height + point.y }; - GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS ); + GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD ); _shaderProgram->use(); _shaderProgram->setUniformsForBuiltins(); @@ -1193,7 +1193,7 @@ void Texture2D::drawInRect(const Rect& rect) rect.origin.x, rect.origin.y + rect.size.height, /*0.0f,*/ rect.origin.x + rect.size.width, rect.origin.y + rect.size.height, /*0.0f*/ }; - GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORDS ); + GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD ); _shaderProgram->use(); _shaderProgram->setUniformsForBuiltins(); diff --git a/cocos/deprecated/CCDeprecated.h b/cocos/deprecated/CCDeprecated.h index b471ed1a98..a266998a24 100644 --- a/cocos/deprecated/CCDeprecated.h +++ b/cocos/deprecated/CCDeprecated.h @@ -848,7 +848,7 @@ CC_DEPRECATED_ATTRIBUTE extern const char* kCCAttributeNameTexCoord; CC_DEPRECATED_ATTRIBUTE const int kCCVertexAttribFlag_None = GL::VERTEX_ATTRIB_FLAG_NONE; CC_DEPRECATED_ATTRIBUTE const int kCCVertexAttribFlag_Position = GL::VERTEX_ATTRIB_FLAG_POSITION; CC_DEPRECATED_ATTRIBUTE const int kCCVertexAttribFlag_Color = GL::VERTEX_ATTRIB_FLAG_COLOR; -CC_DEPRECATED_ATTRIBUTE const int kCCVertexAttribFlag_TexCoords = GL::VERTEX_ATTRIB_FLAG_TEX_COORDS; +CC_DEPRECATED_ATTRIBUTE const int kCCVertexAttribFlag_TexCoords = GL::VERTEX_ATTRIB_FLAG_TEX_COORD; CC_DEPRECATED_ATTRIBUTE const int kCCVertexAttribFlag_PosColorTex = GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX; CC_DEPRECATED_ATTRIBUTE const ProgressTimer::Type kCCProgressTimerTypeRadial = ProgressTimer::Type::RADIAL; diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 526631fbc2..43707dd634 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -182,7 +182,7 @@ bool Armature::init(const std::string& name) } - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); setCascadeOpacityEnabled(true); setCascadeColorEnabled(true); diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 90f6e0c24e..4d338de01b 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -61,7 +61,7 @@ BatchNode::~BatchNode() bool BatchNode::init() { bool ret = Node::init(); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); return ret; } diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 4c891c261a..7af7220625 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -224,7 +224,7 @@ void Skin::draw(Renderer *renderer, const Matrix &transform, bool transformUpdat Matrix mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); //TODO implement z order - _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgram(), _blendFunc, &_quad, 1, mv); + _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, mv); renderer->addCommand(&_quadCommand); } diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index e84355cc79..f7c6bcf5d6 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -69,7 +69,7 @@ void Skeleton::initialize () { setOpacityModifyRGB(true); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); } void Skeleton::setSkeletonData (spSkeletonData *skeletonData, bool isOwnsSkeletonData) { diff --git a/cocos/renderer/CCBatchCommand.h b/cocos/renderer/CCBatchCommand.h index 1861d0021c..ed3e9abcd1 100644 --- a/cocos/renderer/CCBatchCommand.h +++ b/cocos/renderer/CCBatchCommand.h @@ -33,8 +33,6 @@ NS_CC_BEGIN class TextureAtlas; -#define CC_NO_TEXTURE 0 - class BatchCommand : public RenderCommand { public: diff --git a/cocos/renderer/CCGLProgramState.cpp b/cocos/renderer/CCGLProgramState.cpp index db2d3abad3..f578ce20fe 100644 --- a/cocos/renderer/CCGLProgramState.cpp +++ b/cocos/renderer/CCGLProgramState.cpp @@ -166,12 +166,14 @@ void UniformValue::setMat4(const Matrix& value) VertexAttribValue::VertexAttribValue() : _useCallback(false) , _vertexAttrib(nullptr) +, _enabled(false) { } VertexAttribValue::VertexAttribValue(VertexAttrib *vertexAttrib) : _useCallback(false) , _vertexAttrib(vertexAttrib) +, _enabled(false) { } @@ -182,18 +184,20 @@ VertexAttribValue::~VertexAttribValue() } void VertexAttribValue::apply() -{ - if(_useCallback) { - (*_value.callback)(_vertexAttrib); - } - else - { - glVertexAttribPointer(_vertexAttrib->index, - _value.pointer.size, - _value.pointer.type, - _value.pointer.normalized, - _value.pointer.stride, - _value.pointer.pointer); +{ + if(_enabled) { + if(_useCallback) { + (*_value.callback)(_vertexAttrib); + } + else + { + glVertexAttribPointer(_vertexAttrib->index, + _value.pointer.size, + _value.pointer.type, + _value.pointer.normalized, + _value.pointer.stride, + _value.pointer.pointer); + } } } @@ -202,6 +206,7 @@ void VertexAttribValue::setCallback(const std::function &ca _value.callback = new std::function(); *_value.callback = callback; _useCallback = true; + _enabled = true; } void VertexAttribValue::setPointer(GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer) @@ -211,6 +216,7 @@ void VertexAttribValue::setPointer(GLint size, GLenum type, GLboolean normalized _value.pointer.normalized = normalized; _value.pointer.stride = stride; _value.pointer.pointer = pointer; + _enabled = true; } // @@ -229,18 +235,18 @@ GLProgramState* GLProgramState::create(GLProgram *glprogram) return ret; } -GLProgramState* GLProgramState::getWithGLProgramName(const std::string &glProgramName ) +GLProgramState* GLProgramState::getOrCreateWithGLProgramName(const std::string &glProgramName ) { GLProgram *glProgram = GLProgramCache::getInstance()->getGLProgram(glProgramName); if( glProgram ) - return get(glProgram); + return getOrCreate(glProgram); CCLOG("cocos2d: warning: GLProgram '%s' not found", glProgramName.c_str()); return nullptr; } -GLProgramState* GLProgramState::get(GLProgram *glprogram) +GLProgramState* GLProgramState::getOrCreate(GLProgram *glprogram) { GLProgramState* ret = GLProgramStateCache::getInstance()->getGLProgramState(glprogram); return ret; @@ -294,12 +300,16 @@ void GLProgramState::apply(const Matrix& modelView) _glprogram->setUniformsForBuiltins(modelView); - // enable/disable vertex attribs - GL::enableVertexAttribs(_vertexAttribsFlags); + // quick hack: + // Don't deal with attributes if they were set + if(_vertexAttribsFlags) { + // enable/disable vertex attribs + GL::enableVertexAttribs(_vertexAttribsFlags); - // set attributes - for(auto &attribute : _attributes) { - attribute.second.apply(); + // set attributes + for(auto &attribute : _attributes) { + attribute.second.apply(); + } } // set uniforms diff --git a/cocos/renderer/CCGLProgramState.h b/cocos/renderer/CCGLProgramState.h index 613a81aa6b..1aca92a3d3 100644 --- a/cocos/renderer/CCGLProgramState.h +++ b/cocos/renderer/CCGLProgramState.h @@ -108,6 +108,7 @@ public: protected: VertexAttrib* _vertexAttrib; // weak ref bool _useCallback; + bool _enabled; union U{ struct { @@ -143,19 +144,22 @@ public: static GLProgramState* create(GLProgram* glprogram); /** gets-or-creates an instance of GLProgramState for a given GLProgram */ - static GLProgramState* get(GLProgram* glprogram); + static GLProgramState* getOrCreate(GLProgram* glprogram); /** gets-or-creates an instance of GLProgramState for a given GLProgramName */ - static GLProgramState* getWithGLProgramName(const std::string &glProgramName ); + static GLProgramState* getOrCreateWithGLProgramName(const std::string &glProgramName ); void apply(const Matrix& modelView); void setGLProgram(GLProgram* glprogram); GLProgram* getGLProgram() const { return _glprogram; } + uint32_t getVertexAttribsFlags() const { return _vertexAttribsFlags; } + ssize_t getVertexAttribCount() const { return _attributes.size(); } void setVertexAttribCallback(const std::string &name, const std::function &callback); void setVertexAttribPointer(const std::string &name, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLvoid *pointer); + ssize_t getUniformCount() const { return _uniforms.size(); } void setUniformFloat(const std::string &uniformName, float value); void setUniformInt(const std::string &uniformName, int value); void setUniformVec2(const std::string &uniformName, const Vector2& value); @@ -164,6 +168,7 @@ public: void setUniformMat4(const std::string &uniformName, const Matrix& value); void setUniformCallback(const std::string &uniformName, const std::function &callback); + protected: GLProgramState(); ~GLProgramState(); @@ -176,7 +181,6 @@ protected: std::unordered_map _attributes; uint32_t _vertexAttribsFlags; - GLProgram *_glprogram; }; diff --git a/cocos/renderer/CCQuadCommand.cpp b/cocos/renderer/CCQuadCommand.cpp index 6e7b9c701f..495d2b3cb7 100644 --- a/cocos/renderer/CCQuadCommand.cpp +++ b/cocos/renderer/CCQuadCommand.cpp @@ -25,20 +25,17 @@ #include "renderer/CCQuadCommand.h" #include "renderer/ccGLStateCache.h" +#include "renderer/CCGLProgram.h" +#include "renderer/CCGLProgramState.h" #include "xxhash.h" NS_CC_BEGIN -static void convertIntToByteArray(int value, int* output) -{ - *output = value; -} - QuadCommand::QuadCommand() :_materialID(0) ,_textureID(0) -,_shader(nullptr) +,_glProgramState(nullptr) ,_blendType(BlendFunc::DISABLE) ,_quads(nullptr) ,_quadsCount(0) @@ -46,8 +43,11 @@ QuadCommand::QuadCommand() _type = RenderCommand::Type::QUAD_COMMAND; } -void QuadCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const Matrix &mv) +void QuadCommand::init(float globalOrder, GLuint textureID, GLProgramState* glProgramState, BlendFunc blendType, V3F_C4B_T2F_Quad* quad, ssize_t quadCount, const Matrix &mv) { + CCASSERT(glProgramState, "Invalid GLProgramState"); + CCASSERT(glProgramState->getVertexAttribsFlags() == 0, "No custom attributes are supported in QuadCommand"); + _globalOrder = globalOrder; _quadsCount = quadCount; @@ -55,12 +55,12 @@ void QuadCommand::init(float globalOrder, GLuint textureID, GLProgram* shader, B _mv = mv; - if( _textureID != textureID || _blendType.src != blendType.src || _blendType.dst != blendType.dst || _shader != shader) { - + if( _textureID != textureID || _blendType.src != blendType.src || _blendType.dst != blendType.dst || _glProgramState != glProgramState) { + _textureID = textureID; _blendType = blendType; - _shader = shader; - + _glProgramState = glProgramState; + generateMaterialID(); } } @@ -71,48 +71,29 @@ QuadCommand::~QuadCommand() void QuadCommand::generateMaterialID() { - //TODO fix blend id generation - int blendID = 0; - if(_blendType == BlendFunc::DISABLE) + + if( _glProgramState->getUniformCount() > 0 ) { - blendID = 0; - } - else if(_blendType == BlendFunc::ALPHA_PREMULTIPLIED) - { - blendID = 1; - } - else if(_blendType == BlendFunc::ALPHA_NON_PREMULTIPLIED) - { - blendID = 2; - } - else if(_blendType == BlendFunc::ADDITIVE) - { - blendID = 3; + _materialID = QuadCommand::MATERIAL_ID_IGNORE; } else { - blendID = 4; + int glProgram = (int)_glProgramState->getGLProgram()->getProgram(); + int intArray[4] = { glProgram, (int)_textureID, (int)_blendType.src, (int)_blendType.dst}; + + _materialID = XXH32((const void*)intArray, sizeof(intArray), 0); } - - // convert program id, texture id and blend id into byte array - int intArray[3]; - convertIntToByteArray(_shader->getProgram(), intArray); - convertIntToByteArray(blendID, intArray+1); - convertIntToByteArray(_textureID, intArray+2); - - _materialID = XXH32((const void*)intArray, sizeof(intArray), 0); } void QuadCommand::useMaterial() const { - _shader->use(); - _shader->setUniformsForBuiltins(_mv); - //Set texture GL::bindTexture2D(_textureID); //set blend mode GL::blendFunc(_blendType.src, _blendType.dst); + + _glProgramState->apply(_mv); } NS_CC_END \ No newline at end of file diff --git a/cocos/renderer/CCQuadCommand.h b/cocos/renderer/CCQuadCommand.h index bace79ed04..601aab442b 100644 --- a/cocos/renderer/CCQuadCommand.h +++ b/cocos/renderer/CCQuadCommand.h @@ -25,61 +25,47 @@ #ifndef _CC_QUADCOMMAND_H_ #define _CC_QUADCOMMAND_H_ -#include "CCRenderCommand.h" -#include "renderer/CCGLProgram.h" -#include "CCRenderCommandPool.h" +#include "renderer/CCRenderCommand.h" +#include "renderer/CCGLProgramState.h" +#include "renderer/CCRenderCommandPool.h" NS_CC_BEGIN -#define CC_NO_TEXTURE 0 - /** Command used to render one or more Quads */ class QuadCommand : public RenderCommand { public: + static const int MATERIAL_ID_IGNORE = 0; QuadCommand(); ~QuadCommand(); /** Initializes the command with a globalZOrder, a texture ID, a `GLProgram`, a blending function, a pointer to quads, * quantity of quads, and the Model View transform to be used for the quads */ - void init(float globalOrder, GLuint texutreID, GLProgram* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount, + void init(float globalOrder, GLuint texutreID, GLProgramState* shader, BlendFunc blendType, V3F_C4B_T2F_Quad* quads, ssize_t quadCount, const Matrix& mv); void useMaterial() const; - //TODO use material to decide if it is translucent - inline bool isTranslucent() const { return true; } inline uint32_t getMaterialID() const { return _materialID; } - inline GLuint getTextureID() const { return _textureID; } - inline V3F_C4B_T2F_Quad* getQuads() const { return _quads; } - inline ssize_t getQuadCount() const { return _quadsCount; } - - inline GLProgram* getShader() const { return _shader; } - + inline GLProgramState* getGLProgramState() const { return _glProgramState; } inline BlendFunc getBlendType() const { return _blendType; } - inline const Matrix& getModelView() const { return _mv; } -private: + +protected: void generateMaterialID(); - -protected: + uint32_t _materialID; - GLuint _textureID; - - GLProgram* _shader; - + GLProgramState* _glProgramState; BlendFunc _blendType; - V3F_C4B_T2F_Quad* _quads; ssize_t _quadsCount; - Matrix _mv; }; NS_CC_END diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index 8831f135fa..8282eb168f 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -450,10 +450,10 @@ void Renderer::drawBatchedQuads() } //Start drawing verties in batch - //for(auto i = _batchedQuadCommands.begin(); i != _batchedQuadCommands.end(); ++i) for(const auto& cmd : _batchedQuadCommands) { - if(_lastMaterialID != cmd->getMaterialID()) + auto newMaterialID = cmd->getMaterialID(); + if(_lastMaterialID != newMaterialID || newMaterialID == QuadCommand::MATERIAL_ID_IGNORE) { //Draw quads if(quadsToDraw > 0) @@ -468,7 +468,7 @@ void Renderer::drawBatchedQuads() //Use new material cmd->useMaterial(); - _lastMaterialID = cmd->getMaterialID(); + _lastMaterialID = newMaterialID; } quadsToDraw += cmd->getQuadCount(); diff --git a/cocos/renderer/ccGLStateCache.h b/cocos/renderer/ccGLStateCache.h index 77cd03127e..9c1047c922 100644 --- a/cocos/renderer/ccGLStateCache.h +++ b/cocos/renderer/ccGLStateCache.h @@ -50,9 +50,9 @@ enum { VERTEX_ATTRIB_FLAG_POSITION = 1 << 0, VERTEX_ATTRIB_FLAG_COLOR = 1 << 1, - VERTEX_ATTRIB_FLAG_TEX_COORDS = 1 << 2, + VERTEX_ATTRIB_FLAG_TEX_COORD = 1 << 2, - VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = (VERTEX_ATTRIB_FLAG_POSITION | VERTEX_ATTRIB_FLAG_COLOR | VERTEX_ATTRIB_FLAG_TEX_COORDS), + VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = (VERTEX_ATTRIB_FLAG_POSITION | VERTEX_ATTRIB_FLAG_COLOR | VERTEX_ATTRIB_FLAG_TEX_COORD), }; /** @file ccGLStateCache.h diff --git a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp index ab367dc7d2..27fcede20a 100644 --- a/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/tests/cpp-tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -748,7 +748,7 @@ void RawStencilBufferTest3::setupStencilForDrawingOnPlane(GLint plane) void RawStencilBufferTestAlphaTest::setup() { RawStencilBufferTest::setup(); - auto programState = GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV); + auto programState = GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV); for(int i = 0; i < _planeCount; ++i) { _spritesStencil.at(i)->setGLProgramState(programState); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp index cf2c2671c6..ee8705c9e2 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp @@ -185,7 +185,7 @@ void ArmatureTestLayer::onEnter() addChild(menu, 100); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); } void ArmatureTestLayer::onExit() diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp index e53c411d91..db2c88bb4f 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp @@ -150,7 +150,7 @@ void SceneEditorTestLayer::onEnter() addChild(menu, 100); - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); } void SceneEditorTestLayer::onExit() diff --git a/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp b/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp index b12eb3c6b7..848293b58e 100644 --- a/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp +++ b/tests/cpp-tests/Classes/MutiTouchTest/MutiTouchTest.cpp @@ -14,7 +14,7 @@ class TouchPoint : public Node public: TouchPoint() { - setGLProgramState(GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); } virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) diff --git a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp index 3965b96546..0f082167c7 100644 --- a/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp +++ b/tests/cpp-tests/Classes/NodeTest/NodeTest.cpp @@ -989,7 +989,7 @@ public: sprite->initWithFile(spritefilename); sprite->autorelease(); - auto shaderState = GLProgramState::getWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR); + auto shaderState = GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR); sprite->setGLProgramState(shaderState); return sprite; } diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp index 91badc1207..dcb9115eee 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.cpp @@ -120,7 +120,7 @@ ShaderNode::~ShaderNode() { } -ShaderNode* ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) +ShaderNode* ShaderNode::shaderNodeWithVertex(const std::string &vert, const std::string& frag) { auto node = new ShaderNode(); node->initWithVertex(vert, frag); @@ -129,17 +129,20 @@ ShaderNode* ShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) return node; } -bool ShaderNode::initWithVertex(const char *vert, const char *frag) +bool ShaderNode::initWithVertex(const std::string &vert, const std::string &frag) { #if CC_ENABLE_CACHE_TEXTURE_DATA auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ - this->setGLProgram(nullptr); - loadShaderVertex(_vertFileName.c_str(), _fragFileName.c_str()); + this->setGLProgramState(nullptr); + loadShaderVertex(_vertFileName, _fragFileName); }); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); #endif + _vertFileName = vert; + _fragFileName = frag; + loadShaderVertex(vert, frag); _time = 0; @@ -151,16 +154,30 @@ bool ShaderNode::initWithVertex(const char *vert, const char *frag) setContentSize(Size(SIZE_X, SIZE_Y)); setAnchorPoint(Vector2(0.5f, 0.5f)); - _vertFileName = vert; - _fragFileName = frag; return true; } -void ShaderNode::loadShaderVertex(const char *vert, const char *frag) +void ShaderNode::loadShaderVertex(const std::string &vert, const std::string &frag) { - auto shader = GLProgram::createWithFilenames(vert, frag); - this->setGLProgram(shader); + 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); } void ShaderNode::update(float dt) @@ -208,7 +225,7 @@ bool ShaderMonjori::init() { if (ShaderTestDemo::init()) { - auto sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Monjori.vsh", "Shaders/example_Monjori.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Monjori.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -242,7 +259,7 @@ bool ShaderMandelbrot::init() { if (ShaderTestDemo::init()) { - auto sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Mandelbrot.vsh", "Shaders/example_Mandelbrot.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Mandelbrot.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -275,7 +292,7 @@ bool ShaderJulia::init() { if (ShaderTestDemo::init()) { - auto sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Julia.vsh", "Shaders/example_Julia.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Julia.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -309,7 +326,7 @@ bool ShaderHeart::init() { if (ShaderTestDemo::init()) { - auto sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Heart.vsh", "Shaders/example_Heart.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Heart.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -342,7 +359,7 @@ bool ShaderFlower::init() { if (ShaderTestDemo::init()) { - auto sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Flower.vsh", "Shaders/example_Flower.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Flower.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -375,7 +392,7 @@ bool ShaderPlasma::init() { if (ShaderTestDemo::init()) { - auto sn = ShaderNode::shaderNodeWithVertex("Shaders/example_Plasma.vsh", "Shaders/example_Plasma.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/example_Plasma.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -406,15 +423,13 @@ public: ~SpriteBlur(); void setBlurSize(float f); bool initWithTexture(Texture2D* texture, const Rect& rect); - virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override; - void initProgram(); + void initGLProgram(); static SpriteBlur* create(const char *pszFileName); protected: - void onDraw(const Matrix &transform, bool transformUpdated); - int _blurRadius; + int _blurRadius; Vector2 _pixelSize; int _samplingRadius; @@ -422,8 +437,6 @@ protected: float _scale; float _cons; float _weightSum; - - CustomCommand _customCommand; }; SpriteBlur::~SpriteBlur() @@ -453,7 +466,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) #if CC_ENABLE_CACHE_TEXTURE_DATA auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ setGLProgram(nullptr); - initProgram(); + initGLProgram(); }); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); @@ -464,7 +477,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) _pixelSize = Vector2(1/s.width, 1/s.height); _samplingRadius = 0; - this->initProgram(); + this->initGLProgram(); getGLProgramState()->setUniformVec2("onePixelSize", _pixelSize); @@ -474,45 +487,14 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect) return false; } -void SpriteBlur::initProgram() +void SpriteBlur::initGLProgram() { GLchar * fragSource = (GLchar*) String::createWithContentsOfFile( FileUtils::getInstance()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString(); - auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_vert, fragSource); - setGLProgram(program); + auto program = GLProgram::createWithByteArrays(ccPositionTextureColor_noMVP_vert, fragSource); - auto glProgramState = getGLProgramState(); -#define kQuadSize sizeof(_quad.bl) - size_t offset = (size_t)&_quad; - - // position - int diff = offsetof( V3F_C4B_T2F, vertices); - glProgramState->setVertexAttribPointer("a_position", 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - // texcoord - diff = offsetof( V3F_C4B_T2F, texCoords); - glProgramState->setVertexAttribPointer("a_texCoord", 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff)); - // color - diff = offsetof( V3F_C4B_T2F, colors); - glProgramState->setVertexAttribPointer("a_color", 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff)); -} - -void SpriteBlur::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) -{ - _customCommand.init(_globalZOrder); - _customCommand.func = CC_CALLBACK_0(SpriteBlur::onDraw, this, transform, transformUpdated); - renderer->addCommand(&_customCommand); -} - -void SpriteBlur::onDraw(const Matrix &transform, bool transformUpdated) -{ - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - GL::bindTexture2D(_texture->getName()); - - auto glProgramState = getGLProgramState(); - glProgramState->apply(transform); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,4); + auto glProgramState = GLProgramState::getOrCreate(program); + setGLProgramState(glProgramState); } void SpriteBlur::setBlurSize(float f) @@ -614,8 +596,8 @@ bool ShaderBlur::init() void ShaderBlur::sliderAction(Ref* sender, Control::EventType controlEvent) { - ControlSlider* pSlider = (ControlSlider*)sender; - _blurSprite->setBlurSize(pSlider->getValue()); + ControlSlider* slider = (ControlSlider*)sender; + _blurSprite->setBlurSize(slider->getValue()); } // ShaderRetroEffect @@ -680,101 +662,6 @@ std::string ShaderRetroEffect::subtitle() const } - -UniformShaderNode::UniformShaderNode() -:_center(Vector2(0.0f, 0.0f)) -,_resolution(Vector2(0.0f, 0.0f)) -,_time(0.0f) -{ - -} - -UniformShaderNode::~UniformShaderNode() -{ - -} - -bool UniformShaderNode::initWithVertex(const char *vert, const char *frag) -{ - -#if CC_ENABLE_CACHE_TEXTURE_DATA - auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ - this->setGLProgram(nullptr); - loadShaderVertex(_vertFileName.c_str(), _fragFileName.c_str()); - }); - - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); -#endif - - loadShaderVertex(vert, frag); - - _time = 0; - auto s = Director::getInstance()->getWinSize(); - _resolution = Vector2(s.width , s.height ); - getGLProgramState()->setUniformVec2("resolution", _resolution); - - scheduleUpdate(); - - //setContentSize(Size(getContentSize().width, getContentSize().height)); - setAnchorPoint(Vector2(0.5f, 0.5f)); - - _vertFileName = vert; - _fragFileName = frag; - - return true; -} - -void UniformShaderNode::loadShaderVertex(const char *vert, const char *frag) -{ - auto shader = GLProgram::createWithFilenames(vert, frag); - this->setGLProgram(shader); -} - -void UniformShaderNode::update(float dt) -{ - _time += dt; -} - -void UniformShaderNode::setPosition(const Vector2 &newPosition) -{ - Node::setPosition(newPosition); - auto position = getPosition(); - _center = Vector2(position.x * CC_CONTENT_SCALE_FACTOR(), position.y * CC_CONTENT_SCALE_FACTOR()); - getGLProgramState()->setUniformVec2("center", _center); -} - -void UniformShaderNode::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) -{ - _customCommand.init(_globalZOrder); - _customCommand.func = CC_CALLBACK_0(UniformShaderNode::onDraw, this, transform, transformUpdated); - renderer->addCommand(&_customCommand); - -} - -UniformShaderNode* UniformShaderNode::shaderNodeWithVertex(const char *vert, const char *frag) -{ - auto node = new UniformShaderNode(); - node->initWithVertex(vert, frag); - node->autorelease(); - - return node; -} - -void UniformShaderNode::onDraw(const Matrix &transform, bool transformUpdated) -{ - float w = getContentSize().width, h = getContentSize().height; - GLfloat vertices[12] = {0,0, w,0, w,h, 0,0, 0,h, w,h}; - - auto glProgramState = getGLProgramState(); - glProgramState->setVertexAttribPointer("a_position", 2, GL_FLOAT, GL_FALSE, 0, vertices); - glProgramState->apply(transform); - - glDrawArrays(GL_TRIANGLES, 0, 6); - - CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,6); - -} - ShaderLensFlare::ShaderLensFlare() { init(); @@ -794,7 +681,7 @@ bool ShaderLensFlare::init() { if (ShaderTestDemo::init()) { - auto sn = UniformShaderNode::shaderNodeWithVertex("Shaders/example_Heart.vsh", "Shaders/shadertoy_LensFlare.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/shadertoy_LensFlare.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -826,7 +713,7 @@ bool ShaderFireBall::init() { if (ShaderTestDemo::init()) { - auto sn = UniformShaderNode::shaderNodeWithVertex("Shaders/example_Heart.vsh", "Shaders/shadertoy_FireBall.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/shadertoy_FireBall.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); @@ -859,7 +746,7 @@ bool ShaderGlow::init() { if (ShaderTestDemo::init()) { - auto sn = UniformShaderNode::shaderNodeWithVertex("Shaders/example_Heart.vsh", "Shaders/shadertoy_Glow.fsh"); + auto sn = ShaderNode::shaderNodeWithVertex("", "Shaders/shadertoy_Glow.fsh"); auto s = Director::getInstance()->getWinSize(); sn->setPosition(Vector2(s.width/2, s.height/2)); diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h index e5722961dc..c8918e4529 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest.h @@ -113,19 +113,19 @@ protected: class ShaderNode : public Node { public: - ShaderNode(); - ~ShaderNode(); - - bool initWithVertex(const char *vert, const char *frag); - void loadShaderVertex(const char *vert, const char *frag); + static ShaderNode* shaderNodeWithVertex(const std::string &vert, const std::string &frag); virtual void update(float dt); virtual void setPosition(const Vector2 &newPosition); virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override; - static ShaderNode* shaderNodeWithVertex(const char *vert, const char *frag); - protected: + ShaderNode(); + ~ShaderNode(); + + bool initWithVertex(const std::string &vert, const std::string &frag); + void loadShaderVertex(const std::string &vert, const std::string &frag); + void onDraw(const Matrix &transform, bool transformUpdated); Vector2 _center; @@ -142,34 +142,6 @@ public: virtual void runThisTest(); }; - -class UniformShaderNode : public Node -{ -public: - UniformShaderNode(); - ~UniformShaderNode(); - - bool initWithVertex(const char *vert, const char *frag); - void loadShaderVertex(const char *vert, const char *frag); - - virtual void update(float dt); - virtual void setPosition(const Vector2 &newPosition); - virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override; - - static UniformShaderNode* shaderNodeWithVertex(const char *vert, const char *frag); - -protected: - void onDraw(const Matrix &transform, bool transformUpdated); - - Vector2 _center; - Vector2 _resolution; - float _time; - std::string _vertFileName; - std::string _fragFileName; - CustomCommand _customCommand; - -}; - class ShaderLensFlare : public ShaderTestDemo { public: diff --git a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp index 3f7d645df7..6b005cc816 100644 --- a/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp +++ b/tests/cpp-tests/Classes/ShaderTest/ShaderTest2.cpp @@ -136,7 +136,6 @@ public: virtual void initShader(); void setBackgroundNotification(); - virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override; void listenBackToForeground(Ref *obj); protected: @@ -144,9 +143,6 @@ protected: std::string _fragSourceFile; std::string _vertSourceFile; - - CustomCommand _renderCommand; - void onDraw(const Matrix &transform, bool transformUpdated); }; ShaderSprite::ShaderSprite() @@ -162,7 +158,7 @@ void ShaderSprite::setBackgroundNotification() { #if CC_ENABLE_CACHE_TEXTURE_DATA auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ - this->setGLProgram(nullptr); + this->setGLProgramState(nullptr); this->initShader(); }); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); @@ -176,49 +172,17 @@ void ShaderSprite::initShader() auto fragSource = fileUtiles->getStringFromFile(fragmentFilePath); std::string vertSource; if (_vertSourceFile.empty()) { - vertSource = ccPositionTextureColor_vert; + vertSource = ccPositionTextureColor_noMVP_vert; }else{ std::string vertexFilePath = fileUtiles->fullPathForFilename(_vertSourceFile); vertSource = fileUtiles->getStringFromFile(vertexFilePath); } - auto program = GLProgram::createWithByteArrays(vertSource.c_str(), fragSource.c_str()); - setGLProgram(program); - - auto glprogramState = getGLProgramState(); + auto glprogram = GLProgram::createWithByteArrays(vertSource.c_str(), fragSource.c_str()); + auto glprogramState = GLProgramState::getOrCreate(glprogram); + this->setGLProgramState(glprogramState); setCustomUniforms(); - -#define kQuadSize sizeof(_quad.bl) - size_t offset = (size_t)&_quad; - - // vertex - int diff = offsetof( V3F_C4B_T2F, vertices); - glprogramState->setVertexAttribPointer("a_position", 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - // texCoods - diff = offsetof( V3F_C4B_T2F, texCoords); - glprogramState->setVertexAttribPointer("a_texCoord", 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - // color - diff = offsetof( V3F_C4B_T2F, colors); - glprogramState->setVertexAttribPointer("a_color", 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*) (offset + diff)); - -} - -void ShaderSprite::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) -{ - _renderCommand.init(_globalZOrder); - _renderCommand.func = CC_CALLBACK_0(ShaderSprite::onDraw, this, transform, transformUpdated); - renderer->addCommand(&_renderCommand); -} - -void ShaderSprite::onDraw(const Matrix &transform, bool transformUpdated) -{ - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - GL::bindTexture2D(_texture->getName()); - - getGLProgramState()->apply(transform); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4); } class NormalSprite : public ShaderSprite, public ShaderSpriteCreator @@ -588,7 +552,7 @@ protected: OutlineSprite::OutlineSprite() { _fragSourceFile = "Shaders/example_outline.fsh"; - _vertSourceFile = "Shaders/example_outline.vsh"; + _vertSourceFile = ""; //"Shaders/example_outline.vsh"; _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; } @@ -619,157 +583,3 @@ OutlineShadingSpriteTest::OutlineShadingSpriteTest() } } -class UniformSprite : public Sprite -{ -public: - UniformSprite(); - ~UniformSprite(); - CREATE_FUNC(UniformSprite); - - virtual void initShader(); - // void setBackgroundNotification(); - - virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override; - // void listenBackToForeground(Ref *obj); - -protected: - virtual void setCustomUniforms(); - - std::string _fragSourceFile; - std::string _vertSourceFile; - - CustomCommand _renderCommand; - void onDraw(const Matrix &transform, bool transformUpdated); -}; - -UniformSprite::UniformSprite() -{ - _vertSourceFile = "Shaders/example_Heart.vsh"; - _fragSourceFile = "Shaders/example_Heart.fsh"; -} - -UniformSprite::~UniformSprite() -{ - -} - -void UniformSprite::initShader() -{ - auto shader = GLProgram::createWithFilenames(_vertSourceFile, _fragSourceFile); - this->setGLProgram(shader); -} - -void UniformSprite::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) -{ - _renderCommand.init(_globalZOrder); - _renderCommand.func = CC_CALLBACK_0(UniformSprite::onDraw, this, transform, transformUpdated); - renderer->addCommand(&_renderCommand); -} - -void UniformSprite::setCustomUniforms() -{ - auto glprogramstate = getGLProgramState(); - glprogramstate->setUniformVec2("center", Vector2(480,320)); - glprogramstate->setUniformVec2("resolution", Vector2(256,256)); -} - -void UniformSprite::onDraw(const Matrix &transform, bool transformUpdated) -{ - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - GL::bindTexture2D(_texture->getName()); - - float w = 256, h = 256; - GLfloat vertices[12] = {0,0, w,0, w,h, 0,0, 0,h, w,h}; - - auto glprogramstate = getGLProgramState(); - glprogramstate->setVertexAttribPointer("a_position", 2, GL_FLOAT, GL_FALSE, 0, vertices); - glprogramstate->apply(transform); - - - // Draw Call Test - glDrawArrays(GL_TRIANGLES, 0, 6); - CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,6); - - CHECK_GL_ERROR_DEBUG(); -} - -class AttribSprite : public Sprite -{ -public: - AttribSprite(); - ~AttribSprite(); - CREATE_FUNC(AttribSprite); - - virtual void initShader(); - // void setBackgroundNotification(); - - virtual void draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) override; - // void listenBackToForeground(Ref *obj); - -protected: - virtual void setCustomUniforms(); - - std::string _fragSourceFile; - std::string _vertSourceFile; - - CustomCommand _renderCommand; - void onDraw(const Matrix &transform, bool transformUpdated); -}; - -AttribSprite::AttribSprite() -{ - _fragSourceFile = "Shaders/example_normal.fsh"; - _vertSourceFile = "Shaders/example_normal.vsh"; -} - -AttribSprite::~AttribSprite() -{ - -} - -void AttribSprite::initShader() -{ - auto glProgram = GLProgram::createWithFilenames(_vertSourceFile, _fragSourceFile); - setGLProgram(glProgram); - - auto glProgramState = getGLProgramState(); - -#define kQuadSize sizeof(_quad.bl) - size_t offset = (size_t)&_quad; - - // vertex - int diff = offsetof( V3F_C4B_T2F, vertices); - glProgramState->setVertexAttribPointer("a_position", 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - // texCoods - diff = offsetof( V3F_C4B_T2F, texCoords); - glProgramState->setVertexAttribPointer("a_texCoord", 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff)); - // color - diff = offsetof( V3F_C4B_T2F, colors); - glProgramState->setVertexAttribPointer("a_color", 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*) (offset + diff)); - - //program->getUniformValue("u_diffuseColor")->setValue(Vector4(1,1,1,1)); -} - -void AttribSprite::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated) -{ - _renderCommand.init(_globalZOrder); - _renderCommand.func = CC_CALLBACK_0(AttribSprite::onDraw, this, transform, transformUpdated); - renderer->addCommand(&_renderCommand); -} - -void AttribSprite::setCustomUniforms() -{ -} - -void AttribSprite::onDraw(const Matrix &transform, bool transformUpdated) -{ - GL::blendFunc(_blendFunc.src, _blendFunc.dst); - GL::bindTexture2D(_texture->getName()); - - getGLProgramState()->apply(transform); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4); - - CHECK_GL_ERROR_DEBUG(); -} diff --git a/tests/cpp-tests/Resources/Shaders/example_Flower.vsh b/tests/cpp-tests/Resources/Shaders/example_Flower.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Flower.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_Heart.vsh b/tests/cpp-tests/Resources/Shaders/example_Heart.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Heart.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_Julia.vsh b/tests/cpp-tests/Resources/Shaders/example_Julia.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Julia.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_Mandelbrot.vsh b/tests/cpp-tests/Resources/Shaders/example_Mandelbrot.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Mandelbrot.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_Monjori.vsh b/tests/cpp-tests/Resources/Shaders/example_Monjori.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Monjori.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_Plasma.vsh b/tests/cpp-tests/Resources/Shaders/example_Plasma.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Plasma.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_Twist.vsh b/tests/cpp-tests/Resources/Shaders/example_Twist.vsh deleted file mode 100755 index 359ef1e855..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_Twist.vsh +++ /dev/null @@ -1,8 +0,0 @@ -// http://www.cocos2d-iphone.org - -attribute vec4 a_position; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_attribautobind.fsh b/tests/cpp-tests/Resources/Shaders/example_attribautobind.fsh deleted file mode 100755 index 80a030ad2d..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_attribautobind.fsh +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef GL_ES -precision mediump float; -#endif - -varying vec4 v_fragmentColor; -varying vec4 v_diffColor; - -uniform sampler2D CC_Texture0; - -void main(void) -{ - gl_FragColor = v_fragmentColor;// * v_diffColor; -} \ No newline at end of file diff --git a/tests/cpp-tests/Resources/Shaders/example_attribautobind.vsh b/tests/cpp-tests/Resources/Shaders/example_attribautobind.vsh deleted file mode 100644 index a0794484a5..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_attribautobind.vsh +++ /dev/null @@ -1,19 +0,0 @@ -attribute vec3 a_position; -attribute vec4 a_color; - -uniform vec4 u_diffuseColor; - -#ifdef GL_ES -varying lowp vec4 v_fragmentColor; -varying mediump vec4 v_diffColor; -#else -varying vec4 v_fragmentColor; -varying vec4 v_diffColor; -#endif - -void main() -{ - gl_Position = CC_MVPMatrix * vec4(a_position, 1); - v_fragmentColor = a_color; - v_diffColor = u_diffuseColor; -} diff --git a/tests/cpp-tests/Resources/Shaders/example_normal.vsh b/tests/cpp-tests/Resources/Shaders/example_normal.vsh deleted file mode 100644 index 57c3a902a0..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_normal.vsh +++ /dev/null @@ -1,20 +0,0 @@ - -attribute vec3 a_position; -attribute vec4 a_color; -attribute vec2 a_texCoord; - -#ifdef GL_ES -varying lowp vec4 v_fragmentColor; -varying mediump vec2 v_texCoord; -#else -varying vec4 v_fragmentColor; -varying vec2 v_texCoord; -#endif - -void main() -{ - gl_Position = CC_MVPMatrix * vec4(a_position, 1); - v_fragmentColor = a_color; - v_texCoord = a_texCoord; - -} diff --git a/tests/cpp-tests/Resources/Shaders/example_outline.vsh b/tests/cpp-tests/Resources/Shaders/example_outline.vsh deleted file mode 100755 index 9d7e6bc813..0000000000 --- a/tests/cpp-tests/Resources/Shaders/example_outline.vsh +++ /dev/null @@ -1,20 +0,0 @@ -/* - Created by guanghui on 4/8/14. - -*/ - - -attribute vec4 a_position; -attribute vec4 a_color; -attribute vec2 a_texCoord; - -varying vec2 v_texCoord; - -varying vec4 v_fragmentColor; - -void main() -{ - gl_Position = CC_MVPMatrix * a_position; - v_fragmentColor = a_color; - v_texCoord = a_texCoord; -} \ No newline at end of file