remove unused shader and also did adjust FontAtlas::getTexture

This commit is contained in:
Dhilan007 2014-03-05 16:51:16 +08:00
parent 23501b40aa
commit dfdf19daff
10 changed files with 28 additions and 55 deletions

View File

@ -62,7 +62,7 @@ _currentPageData(nullptr)
_currentPageData = new unsigned char[_currentPageDataSize]; _currentPageData = new unsigned char[_currentPageDataSize];
memset(_currentPageData, 0, _currentPageDataSize); memset(_currentPageData, 0, _currentPageDataSize);
addTexture(*texture,0); addTexture(texture,0);
texture->release(); texture->release();
} }
} }
@ -157,7 +157,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
memset(_currentPageData, 0, _currentPageDataSize); memset(_currentPageData, 0, _currentPageDataSize);
_currentPage++; _currentPage++;
auto tex = new Texture2D; auto tex = new Texture2D;
addTexture(*tex,_currentPage); addTexture(tex,_currentPage);
tex->release(); tex->release();
} }
} }
@ -201,15 +201,15 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
return true; return true;
} }
void FontAtlas::addTexture(Texture2D &texture, int slot) void FontAtlas::addTexture(Texture2D *texture, int slot)
{ {
texture.retain(); texture->retain();
_atlasTextures[slot] = &texture; _atlasTextures[slot] = texture;
} }
Texture2D & FontAtlas::getTexture(int slot) Texture2D* FontAtlas::getTexture(int slot)
{ {
return *(_atlasTextures[slot]); return _atlasTextures[slot];
} }
float FontAtlas::getCommonLineHeight() const float FontAtlas::getCommonLineHeight() const

View File

@ -70,11 +70,11 @@ public:
bool prepareLetterDefinitions(unsigned short *utf16String); bool prepareLetterDefinitions(unsigned short *utf16String);
inline const std::unordered_map<int, Texture2D*>& getTextures() const{ return _atlasTextures;} inline const std::unordered_map<int, Texture2D*>& getTextures() const{ return _atlasTextures;}
void addTexture(Texture2D &texture, int slot); void addTexture(Texture2D *texture, int slot);
float getCommonLineHeight() const; float getCommonLineHeight() const;
void setCommonLineHeight(float newHeight); void setCommonLineHeight(float newHeight);
Texture2D& getTexture(int slot); Texture2D* getTexture(int slot);
const Font* getFont() const; const Font* getFont() const;
private: private:

View File

@ -158,7 +158,7 @@ FontAtlas * FontCharMap::createFontAtlas()
} }
} }
tempAtlas->addTexture(*_texture,0); tempAtlas->addTexture(_texture,0);
return tempAtlas; return tempAtlas;
} }

View File

@ -816,7 +816,7 @@ FontAtlas * FontFNT::createFontAtlas()
return 0; return 0;
// add the texture // add the texture
tempAtlas->addTexture(*tempTexture, 0); tempAtlas->addTexture(tempTexture, 0);
// done // done
return tempAtlas; return tempAtlas;

View File

@ -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_NORMAL = "ShaderLabelNormol";
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW = "ShaderLabelGlow"; const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW = "ShaderLabelGlow";
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE = "ShaderLabelOutline"; const char* GLProgram::SHADER_NAME_LABEL_OUTLINE = "ShaderLabelOutline";
const char* GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW = "ShaderLabelShadow";
// uniform names // uniform names

View File

@ -92,8 +92,7 @@ public:
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL; static const char* SHADER_NAME_LABEL_DISTANCEFIELD_NORMAL;
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_GLOW; static const char* SHADER_NAME_LABEL_DISTANCEFIELD_GLOW;
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE; static const char* SHADER_NAME_LABEL_OUTLINE;
static const char* SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW;
// uniform names // uniform names
static const char* UNIFORM_NAME_P_MATRIX; static const char* UNIFORM_NAME_P_MATRIX;

View File

@ -224,10 +224,10 @@ bool Label::init()
bool ret = true; bool ret = true;
if(_fontAtlas) if(_fontAtlas)
{ {
ret = SpriteBatchNode::initWithTexture(&_fontAtlas->getTexture(0), 30); ret = SpriteBatchNode::initWithTexture(_fontAtlas->getTexture(0), 30);
if (_reusedLetter == nullptr) if (_reusedLetter == nullptr)
{ {
_reusedLetter = Sprite::createWithTexture(&_fontAtlas->getTexture(0)); _reusedLetter = Sprite::createWithTexture(_fontAtlas->getTexture(0));
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB); _reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
_reusedLetter->retain(); _reusedLetter->retain();
_reusedLetter->setAnchorPoint(Point::ANCHOR_TOP_LEFT); _reusedLetter->setAnchorPoint(Point::ANCHOR_TOP_LEFT);
@ -255,7 +255,7 @@ void Label::initProgram()
break; break;
case cocos2d::LabelEffect::OUTLINE: case cocos2d::LabelEffect::OUTLINE:
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE)); setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_LABEL_OUTLINE));
break; break;
case cocos2d::LabelEffect::GLOW: case cocos2d::LabelEffect::GLOW:
if (_useDistanceField) if (_useDistanceField)
@ -865,7 +865,7 @@ Sprite * Label::getLetter(int lettetIndex)
uvRect.origin.x = _lettersInfo[lettetIndex].def.U; uvRect.origin.x = _lettersInfo[lettetIndex].def.U;
uvRect.origin.y = _lettersInfo[lettetIndex].def.V; 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->setBatchNode(this);
sp->setAnchorPoint(Point::ANCHOR_MIDDLE); sp->setAnchorPoint(Point::ANCHOR_MIDDLE);
sp->setPosition(Point(_lettersInfo[lettetIndex].position.x+uvRect.size.width/2,_lettersInfo[lettetIndex].position.y-uvRect.size.height/2)); sp->setPosition(Point(_lettersInfo[lettetIndex].position.x+uvRect.size.width/2,_lettersInfo[lettetIndex].position.y-uvRect.size.height/2));

View File

@ -45,8 +45,7 @@ enum {
kShaderType_PositionLengthTexureColor, kShaderType_PositionLengthTexureColor,
kShaderType_LabelDistanceFieldNormal, kShaderType_LabelDistanceFieldNormal,
kShaderType_LabelDistanceFieldGlow, kShaderType_LabelDistanceFieldGlow,
kShaderType_LabelDistanceFieldOutline, kShaderType_LabelOutline,
kShaderType_LabelDistanceFieldShadow,
kShaderType_MAX, kShaderType_MAX,
}; };
@ -177,12 +176,8 @@ void ShaderCache::loadDefaultShaders()
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW, p) ); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_GLOW, p) );
p = new GLProgram(); p = new GLProgram();
loadDefaultShader(p, kShaderType_LabelDistanceFieldOutline); loadDefaultShader(p, kShaderType_LabelOutline);
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE, p) ); _programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_OUTLINE, p) );
p = new GLProgram();
loadDefaultShader(p, kShaderType_LabelDistanceFieldShadow);
_programs.insert( std::make_pair(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW, p) );
} }
void ShaderCache::reloadDefaultShaders() void ShaderCache::reloadDefaultShaders()
@ -260,13 +255,9 @@ void ShaderCache::reloadDefaultShaders()
p->reset(); p->reset();
loadDefaultShader(p, kShaderType_LabelDistanceFieldGlow); loadDefaultShader(p, kShaderType_LabelDistanceFieldGlow);
p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_OUTLINE); p = getProgram(GLProgram::SHADER_NAME_LABEL_OUTLINE);
p->reset(); p->reset();
loadDefaultShader(p, kShaderType_LabelDistanceFieldOutline); loadDefaultShader(p, kShaderType_LabelOutline);
p = getProgram(GLProgram::SHADER_NAME_LABEL_DISTANCEFIELD_SHADOW);
p->reset();
loadDefaultShader(p, kShaderType_LabelDistanceFieldShadow);
} }
void ShaderCache::loadDefaultShader(GLProgram *p, int type) 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); p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
break; break;
case kShaderType_LabelDistanceFieldOutline: case kShaderType_LabelOutline:
p->initWithByteArrays(ccLabelDistanceFieldOutline_vert, ccLabelDistanceFieldOutline_frag); 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);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
break;
case kShaderType_LabelDistanceFieldShadow:
p->initWithByteArrays(ccLabelDistanceFieldShadow_vert, ccLabelDistanceFieldShadow_frag);
p->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); 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_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);

View File

@ -91,14 +91,9 @@ const GLchar * ccLabelDistanceFieldGlow_frag =
const GLchar * ccLabelDistanceFieldGlow_vert = const GLchar * ccLabelDistanceFieldGlow_vert =
#include "ccShader_Label_vert.h" #include "ccShader_Label_vert.h"
const GLchar * ccLabelDistanceFieldOutline_frag = const GLchar * ccLabelOutline_frag =
#include "ccShader_Label_frag_outline.h" #include "ccShader_Label_frag_outline.h"
const GLchar * ccLabelDistanceFieldOutline_vert = const GLchar * ccLabelOutline_vert =
#include "ccShader_Label_vert.h"
const GLchar * ccLabelDistanceFieldShadow_frag =
#include "ccShader_Label_frag_shadow.h"
const GLchar * ccLabelDistanceFieldShadow_vert =
#include "ccShader_Label_vert.h" #include "ccShader_Label_vert.h"
NS_CC_END NS_CC_END

View File

@ -68,11 +68,8 @@ extern CC_DLL const GLchar * ccLabelDistanceFieldNormal_vert;
extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_frag; extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_frag;
extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_vert; extern CC_DLL const GLchar * ccLabelDistanceFieldGlow_vert;
extern CC_DLL const GLchar * ccLabelDistanceFieldOutline_frag; extern CC_DLL const GLchar * ccLabelOutline_frag;
extern CC_DLL const GLchar * ccLabelDistanceFieldOutline_vert; extern CC_DLL const GLchar * ccLabelOutline_vert;
extern CC_DLL const GLchar * ccLabelDistanceFieldShadow_frag;
extern CC_DLL const GLchar * ccLabelDistanceFieldShadow_vert;
extern CC_DLL const GLchar * ccExSwitchMask_frag; extern CC_DLL const GLchar * ccExSwitchMask_frag;