diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 06a8df4c38..a4e255b43e 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -62,7 +62,7 @@ _currentPageData(nullptr) _currentPageData = new unsigned char[_currentPageDataSize]; memset(_currentPageData, 0, _currentPageDataSize); - addTexture(*texture,0); + addTexture(texture,0); texture->release(); } } @@ -157,7 +157,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) memset(_currentPageData, 0, _currentPageDataSize); _currentPage++; auto tex = new Texture2D; - addTexture(*tex,_currentPage); + addTexture(tex,_currentPage); tex->release(); } } @@ -201,15 +201,15 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) return true; } -void FontAtlas::addTexture(Texture2D &texture, int slot) +void FontAtlas::addTexture(Texture2D *texture, int slot) { - texture.retain(); - _atlasTextures[slot] = &texture; + texture->retain(); + _atlasTextures[slot] = texture; } -Texture2D & FontAtlas::getTexture(int slot) +Texture2D* FontAtlas::getTexture(int slot) { - return *(_atlasTextures[slot]); + return _atlasTextures[slot]; } float FontAtlas::getCommonLineHeight() const diff --git a/cocos/2d/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h index 2ed6f8ac54..bdb5f07c37 100644 --- a/cocos/2d/CCFontAtlas.h +++ b/cocos/2d/CCFontAtlas.h @@ -70,11 +70,11 @@ public: bool prepareLetterDefinitions(unsigned short *utf16String); inline const std::unordered_map& getTextures() const{ return _atlasTextures;} - void addTexture(Texture2D &texture, int slot); + void addTexture(Texture2D *texture, int slot); float getCommonLineHeight() const; void setCommonLineHeight(float newHeight); - Texture2D& getTexture(int slot); + Texture2D* getTexture(int slot); const Font* getFont() const; private: diff --git a/cocos/2d/CCFontCharMap.cpp b/cocos/2d/CCFontCharMap.cpp index 29098acde3..8a47687061 100644 --- a/cocos/2d/CCFontCharMap.cpp +++ b/cocos/2d/CCFontCharMap.cpp @@ -158,7 +158,7 @@ FontAtlas * FontCharMap::createFontAtlas() } } - tempAtlas->addTexture(*_texture,0); + tempAtlas->addTexture(_texture,0); return tempAtlas; } diff --git a/cocos/2d/CCFontFNT.cpp b/cocos/2d/CCFontFNT.cpp index 837b1f4a7d..cbc66fa32e 100644 --- a/cocos/2d/CCFontFNT.cpp +++ b/cocos/2d/CCFontFNT.cpp @@ -816,7 +816,7 @@ FontAtlas * FontFNT::createFontAtlas() return 0; // add the texture - tempAtlas->addTexture(*tempTexture, 0); + tempAtlas->addTexture(tempTexture, 0); // done return tempAtlas; diff --git a/cocos/2d/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp index 4597df6c95..0655a8f9be 100644 --- a/cocos/2d/CCGLProgram.cpp +++ b/cocos/2d/CCGLProgram.cpp @@ -59,8 +59,7 @@ const char* GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR = "ShaderPositi const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL = "ShaderLabelNormol"; const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW = "ShaderLabelGlow"; -const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE = "ShaderLabelOutline"; -const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW = "ShaderLabelShadow"; +const char* GLProgram::SHADER_NAME_LABEL_OUTLINE = "ShaderLabelOutline"; // uniform names diff --git a/cocos/2d/CCGLProgram.h b/cocos/2d/CCGLProgram.h index 9705eecb9c..68a29ad539 100644 --- a/cocos/2d/CCGLProgram.h +++ b/cocos/2d/CCGLProgram.h @@ -92,8 +92,7 @@ public: static const char* SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL; static const char* SHADER_NAME_LABEL_DISTANCEFIELD_GLOW; - static const char* SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE; - static const char* SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW; + static const char* SHADER_NAME_LABEL_OUTLINE; // uniform names static const char* UNIFORM_NAME_P_MATRIX; diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 456dbc09ae..fd05b65d2f 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -224,10 +224,10 @@ bool Label::init() bool ret = true; if(_fontAtlas) { - ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); + ret = SpriteBatchNode::initWithTexture(_fontAtlas->getTexture(0), 30); if (_reusedLetter == nullptr) { - _reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); + _reusedLetter = Sprite::createWithTexture(_fontAtlas->getTexture(0)); _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); _reusedLetter->retain(); _reusedLetter->setAnchorPoint(Point::ANCHOR_TOP_LEFT); @@ -255,7 +255,7 @@ void Label::initProgram() break; case cocos2d::LabelEffect::OUTLINE: - setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE)); + setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_OUTLINE)); break; case cocos2d::LabelEffect::GLOW: if (_useDistanceField) @@ -865,7 +865,7 @@ Sprite * Label::getLetter(int lettetIndex) uvRect.origin.x = _lettersInfo[lettetIndex].def.U; uvRect.origin.y = _lettersInfo[lettetIndex].def.V; - sp = Sprite::createWithTexture(&_fontAtlas->getTexture(_lettersInfo[lettetIndex].def.textureID),uvRect); + sp = Sprite::createWithTexture(_fontAtlas->getTexture(_lettersInfo[lettetIndex].def.textureID),uvRect); sp->setBatchNode(this); sp->setAnchorPoint(Point::ANCHOR_MIDDLE); sp->setPosition(Point(_lettersInfo[lettetIndex].position.x+uvRect.size.width/2,_lettersInfo[lettetIndex].position.y-uvRect.size.height/2)); diff --git a/cocos/2d/CCShaderCache.cpp b/cocos/2d/CCShaderCache.cpp index 8ab253ce2c..7567d265df 100644 --- a/cocos/2d/CCShaderCache.cpp +++ b/cocos/2d/CCShaderCache.cpp @@ -45,8 +45,7 @@ enum { kShaderType_PositionLengthTexureColor, kShaderType_LabelDistanceFieldNormal, kShaderType_LabelDistanceFieldGlow, - kShaderType_LabelDistanceFieldOutline, - kShaderType_LabelDistanceFieldShadow, + kShaderType_LabelOutline, kShaderType_MAX, }; @@ -177,12 +176,8 @@ void ShaderCache::loadDefaultShaders() _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW, p) ); p = new GLProgram(); - loadDefaultShader(p, kShaderType_LabelDistanceFieldOutline); - _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE, p) ); - - p = new GLProgram(); - loadDefaultShader(p, kShaderType_LabelDistanceFieldShadow); - _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW, p) ); + loadDefaultShader(p, kShaderType_LabelOutline); + _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_OUTLINE, p) ); } void ShaderCache::reloadDefaultShaders() @@ -260,13 +255,9 @@ void ShaderCache::reloadDefaultShaders() p->reset(); loadDefaultShader(p, kShaderType_LabelDistanceFieldGlow); - p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE); + p = getProgram(GLProgram::SHADER_NAME_LABEL_OUTLINE); p->reset(); - loadDefaultShader(p, kShaderType_LabelDistanceFieldOutline); - - p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW); - p->reset(); - loadDefaultShader(p, kShaderType_LabelDistanceFieldShadow); + loadDefaultShader(p, kShaderType_LabelOutline); } void ShaderCache::loadDefaultShader(GLProgram *p, int type) @@ -362,16 +353,8 @@ void ShaderCache::loadDefaultShader(GLProgram *p, int type) p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); break; - case kShaderType_LabelDistanceFieldOutline: - p->initWithByteArrays(ccLabelDistanceFieldOutline_vert, ccLabelDistanceFieldOutline_frag); - - p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); - p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); - p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS); - - break; - case kShaderType_LabelDistanceFieldShadow: - p->initWithByteArrays(ccLabelDistanceFieldShadow_vert, ccLabelDistanceFieldShadow_frag); + case kShaderType_LabelOutline: + p->initWithByteArrays(ccLabelOutline_vert, ccLabelOutline_frag); p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); diff --git a/cocos/2d/ccShaders.cpp b/cocos/2d/ccShaders.cpp index 38d22e1c44..c5863f6a9a 100644 --- a/cocos/2d/ccShaders.cpp +++ b/cocos/2d/ccShaders.cpp @@ -91,14 +91,9 @@ const GLchar * ccLabelDistanceFieldGlow_frag = const GLchar * ccLabelDistanceFieldGlow_vert = #include "ccShader_Label_vert.h" -const GLchar * ccLabelDistanceFieldOutline_frag = +const GLchar * ccLabelOutline_frag = #include "ccShader_Label_frag_outline.h" -const GLchar * ccLabelDistanceFieldOutline_vert = -#include "ccShader_Label_vert.h" - -const GLchar * ccLabelDistanceFieldShadow_frag = -#include "ccShader_Label_frag_shadow.h" -const GLchar * ccLabelDistanceFieldShadow_vert = +const GLchar * ccLabelOutline_vert = #include "ccShader_Label_vert.h" NS_CC_END diff --git a/cocos/2d/ccShaders.h b/cocos/2d/ccShaders.h index 97fc404b95..35440df11d 100644 --- a/cocos/2d/ccShaders.h +++ b/cocos/2d/ccShaders.h @@ -68,11 +68,8 @@ extern CC_DLL const GLchar * ccLabelDistanceFieldNormal_vert; extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_frag; extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_vert; -extern CC_DLL const GLchar * ccLabelDistanceFieldOutline_frag; -extern CC_DLL const GLchar * ccLabelDistanceFieldOutline_vert; - -extern CC_DLL const GLchar * ccLabelDistanceFieldShadow_frag; -extern CC_DLL const GLchar * ccLabelDistanceFieldShadow_vert; +extern CC_DLL const GLchar * ccLabelOutline_frag; +extern CC_DLL const GLchar * ccLabelOutline_vert; extern CC_DLL const GLchar * ccExSwitchMask_frag;