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];
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

View File

@ -70,11 +70,11 @@ public:
bool prepareLetterDefinitions(unsigned short *utf16String);
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;
void setCommonLineHeight(float newHeight);
Texture2D& getTexture(int slot);
Texture2D* getTexture(int slot);
const Font* getFont() const;
private:

View File

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

View File

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

View File

@ -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;

View File

@ -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));

View File

@ -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);

View File

@ -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

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_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;