Merge pull request #6028 from Dhilan007/develop_label

closed #4494:: Easier for set texture parameters of label's cache textures.
This commit is contained in:
James Chen 2014-03-27 16:40:12 +08:00
commit 2e3b6b62de
5 changed files with 93 additions and 6 deletions

View File

@ -43,6 +43,7 @@ FontAtlas::FontAtlas(Font &theFont)
, _fontAscender(0)
, _toForegroundListener(nullptr)
, _toBackgroundListener(nullptr)
, _antialiasEnabled(true)
{
_font->retain();
@ -189,8 +190,8 @@ void FontAtlas::listenToForeground(EventCustom *event)
{
auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize,
pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize,
pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );
}
}
#endif
@ -204,7 +205,7 @@ void FontAtlas::addLetterDefinition(const FontLetterDefinition &letterDefinition
bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontLetterDefinition &outDefinition)
{
auto outIterator = _fontLetterDefinitions.find(letteCharUTF16);
if (outIterator != _fontLetterDefinitions.end())
{
outDefinition = (*outIterator).second;
@ -274,6 +275,14 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
memset(_currentPageData, 0, _currentPageDataSize);
_currentPage++;
auto tex = new Texture2D;
if (_antialiasEnabled)
{
tex->setAntiAliasTexParameters();
}
else
{
tex->setAliasTexParameters();
}
tex->initWithData(_currentPageData, _currentPageDataSize,
pixelFormat, CacheTextureWidth, CacheTextureHeight, Size(CacheTextureWidth,CacheTextureHeight) );
addTexture(tex,_currentPage);
@ -349,4 +358,28 @@ const Font * FontAtlas::getFont() const
return _font;
}
void FontAtlas::setAliasTexParameters()
{
if (_antialiasEnabled)
{
_antialiasEnabled = false;
for (const auto & tex : _atlasTextures)
{
tex.second->setAliasTexParameters();
}
}
}
void FontAtlas::setAntiAliasTexParameters()
{
if (! _antialiasEnabled)
{
_antialiasEnabled = true;
for (const auto & tex : _atlasTextures)
{
tex.second->setAntiAliasTexParameters();
}
}
}
NS_CC_END

View File

@ -98,6 +98,18 @@ public:
*/
void purgeTexturesAtlas();
/** sets font texture parameters:
- GL_TEXTURE_MIN_FILTER = GL_LINEAR
- GL_TEXTURE_MAG_FILTER = GL_LINEAR
*/
void setAntiAliasTexParameters();
/** sets font texture parameters:
- GL_TEXTURE_MIN_FILTER = GL_NEAREST
- GL_TEXTURE_MAG_FILTER = GL_NEAREST
*/
void setAliasTexParameters();
private:
void relaseTextures();
@ -118,6 +130,7 @@ private:
int _fontAscender;
EventListenerCustom* _toBackgroundListener;
EventListenerCustom* _toForegroundListener;
bool _antialiasEnabled;
};

View File

@ -243,6 +243,7 @@ public:
virtual const Size& getContentSize() const override;
FontAtlas* getFontAtlas() { return _fontAtlas; }
/** Listen "come to background" message
It only has effect on Android.
*/

View File

@ -432,6 +432,7 @@ Texture2D::Texture2D()
, _hasPremultipliedAlpha(false)
, _hasMipmaps(false)
, _shaderProgram(nullptr)
, _antialiasEnabled(true)
{
}
@ -621,16 +622,29 @@ bool Texture2D::initWithMipmaps(MipmapInfo* mipmaps, int mipmapsNum, PixelFormat
if (mipmapsNum == 1)
{
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _antialiasEnabled ? GL_LINEAR : GL_NEAREST);
}else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _antialiasEnabled ? GL_LINEAR_MIPMAP_NEAREST : GL_NEAREST_MIPMAP_NEAREST);
}
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _antialiasEnabled ? GL_LINEAR : GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
#if CC_ENABLE_CACHE_TEXTURE_DATA
if (_antialiasEnabled)
{
TexParams texParams = {(GLuint)(_hasMipmaps?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR),GL_LINEAR,GL_NONE,GL_NONE};
VolatileTextureMgr::setTexParameters(this, texParams);
}
else
{
TexParams texParams = {(GLuint)(_hasMipmaps?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST),GL_NEAREST,GL_NONE,GL_NONE};
VolatileTextureMgr::setTexParameters(this, texParams);
}
#endif
CHECK_GL_ERROR_DEBUG(); // clean possible GL error
// Specify OpenGL texture image
@ -1252,6 +1266,18 @@ void Texture2D::setTexParameters(const TexParams &texParams)
void Texture2D::setAliasTexParameters()
{
if (! _antialiasEnabled)
{
return;
}
_antialiasEnabled = false;
if (_name == 0)
{
return;
}
GL::bindTexture2D( _name );
if( ! _hasMipmaps )
@ -1272,6 +1298,18 @@ void Texture2D::setAliasTexParameters()
void Texture2D::setAntiAliasTexParameters()
{
if ( _antialiasEnabled )
{
return;
}
_antialiasEnabled = true;
if (_name == 0)
{
return;
}
GL::bindTexture2D( _name );
if( ! _hasMipmaps )

View File

@ -436,6 +436,8 @@ protected:
GLProgram* _shaderProgram;
static const PixelFormatInfoMap _pixelFormatInfoTables;
bool _antialiasEnabled;
};