From afd8391ca80bbfaf9820e90dc83799b6440eb5e7 Mon Sep 17 00:00:00 2001 From: Martin Sherburn Date: Thu, 30 Aug 2012 20:02:05 +0100 Subject: [PATCH 1/2] Fixed bug where texParams would get lost after reloading textures on android --- cocos2dx/textures/CCTexture2D.cpp | 12 ++++++++++++ cocos2dx/textures/CCTextureCache.cpp | 19 +++++++++++++++++++ cocos2dx/textures/CCTextureCache.h | 2 ++ 3 files changed, 33 insertions(+) diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 94d49e1e18..c34a077b68 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -622,6 +622,10 @@ void CCTexture2D::setTexParameters(ccTexParams *texParams) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texParams->magFilter ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texParams->wrapS ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texParams->wrapT ); + +#if CC_ENABLE_CACHE_TEXTURE_DATA + VolatileTexture::setTexParameters(this, texParams); +#endif } void CCTexture2D::setAliasTexParameters() @@ -638,6 +642,10 @@ void CCTexture2D::setAliasTexParameters() } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); +#if CC_ENABLE_CACHE_TEXTURE_DATA + ccTexParams texParams = {m_bHasMipmaps?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST,GL_NEAREST,GL_NONE,GL_NONE}; + VolatileTexture::setTexParameters(this, &texParams); +#endif } void CCTexture2D::setAntiAliasTexParameters() @@ -654,6 +662,10 @@ void CCTexture2D::setAntiAliasTexParameters() } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); +#if CC_ENABLE_CACHE_TEXTURE_DATA + ccTexParams texParams = {m_bHasMipmaps?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR,GL_LINEAR,GL_NONE,GL_NONE}; + VolatileTexture::setTexParameters(this, &texParams); +#endif } const char* CCTexture2D::stringForFormat() diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 99ad1b20ef..12551ad858 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -713,6 +713,10 @@ VolatileTexture::VolatileTexture(CCTexture2D *t) , m_fFontSize(0.0f) { m_size = CCSizeMake(0, 0); + m_texParams.minFilter = GL_LINEAR; + m_texParams.magFilter = GL_LINEAR; + m_texParams.wrapS = GL_CLAMP_TO_EDGE; + m_texParams.wrapT = GL_CLAMP_TO_EDGE; textures.push_back(this); } @@ -801,6 +805,20 @@ void VolatileTexture::addStringTexture(CCTexture2D *tt, const char* text, const vt->m_strText = text; } +void VolatileTexture::setTexParameters(CCTexture2D *t, ccTexParams *texParams) +{ + VolatileTexture *vt = findVolotileTexture(t); + + if (texParams->minFilter != GL_NONE) + vt->m_texParams.minFilter = texParams->minFilter; + if (texParams->magFilter != GL_NONE) + vt->m_texParams.magFilter = texParams->magFilter; + if (texParams->wrapS != GL_NONE) + vt->m_texParams.wrapS = texParams->wrapS; + if (texParams->wrapT != GL_NONE) + vt->m_texParams.wrapT = texParams->wrapT; +} + void VolatileTexture::removeTexture(CCTexture2D *t) { @@ -890,6 +908,7 @@ void VolatileTexture::reloadAllTextures() default: break; } + vt->texture->setTexParameters(&vt->m_texParams); } isReloading = false; diff --git a/cocos2dx/textures/CCTextureCache.h b/cocos2dx/textures/CCTextureCache.h index ee3335c3ba..d21bf1a663 100644 --- a/cocos2dx/textures/CCTextureCache.h +++ b/cocos2dx/textures/CCTextureCache.h @@ -195,6 +195,7 @@ public: static void addDataTexture(CCTexture2D *tt, void* data, CCTexture2DPixelFormat pixelFormat, const CCSize& contentSize); static void addCCImage(CCTexture2D *tt, CCImage *image); + static void setTexParameters(CCTexture2D *t, ccTexParams *texParams); static void removeTexture(CCTexture2D *t); static void reloadAllTextures(); @@ -221,6 +222,7 @@ protected: std::string m_strFileName; CCImage::EImageFormat m_FmtImage; + ccTexParams m_texParams; CCSize m_size; CCTextAlignment m_alignment; CCVerticalTextAlignment m_vAlignment; From 56c329cf0ee7732ff6493b07bbc30abf36d73e28 Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 3 Sep 2012 16:47:18 +0800 Subject: [PATCH 2/2] reset texture parameter when coming to foreground on android --- .../tilemap_parallax_nodes/CCTMXLayer.cpp | 19 ------------------- cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h | 5 ----- 2 files changed, 24 deletions(-) diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp index a3ab078657..91cc21bd7b 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.cpp @@ -32,8 +32,6 @@ THE SOFTWARE. #include "shaders/CCGLProgram.h" #include "support/CCPointExtension.h" #include "support/data_support/ccCArray.h" -#include "support/CCNotificationCenter.h" -#include "CCEventType.h" #include "CCDirector.h" NS_CC_BEGIN @@ -99,26 +97,11 @@ bool CCTMXLayer::initWithTilesetInfo(CCTMXTilesetInfo *tilesetInfo, CCTMXLayerIn m_bUseAutomaticVertexZ = false; m_nVertexZvalue = 0; - - // listen the event of "EVNET_COME_TO_FOREGROUND", this event only trigged on android - CCNotificationCenter::sharedNotificationCenter()->addObserver(this, - callfuncO_selector(CCTMXLayer::listenBackToForeground), - EVNET_COME_TO_FOREGROUND, - NULL); - return true; } return false; } -void CCTMXLayer::listenBackToForeground(CCObject *sender) -{ - if (m_pobTextureAtlas) - { - m_pobTextureAtlas->getTexture()->setAliasTexParameters(); - } -} - CCTMXLayer::CCTMXLayer() :m_tLayerSize(CCSizeZero) ,m_tMapTileSize(CCSizeZero) @@ -143,8 +126,6 @@ CCTMXLayer::~CCTMXLayer() } CC_SAFE_DELETE_ARRAY(m_pTiles); - - CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND); } CCTMXTilesetInfo * CCTMXLayer::getTileSet() diff --git a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h index 81c6d26c42..018193f690 100644 --- a/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h +++ b/cocos2dx/tilemap_parallax_nodes/CCTMXLayer.h @@ -158,11 +158,6 @@ public: virtual void addChild(CCNode * child, int zOrder, int tag); // super method void removeChild(CCNode* child, bool cleanup); - - /** listen the event to invoke CCTexture2D::setAliasTexParameters() after - comming to foreground on android - */ - void listenBackToForeground(CCObject *sender); inline const char* getLayerName(){ return m_sLayerName.c_str(); } inline void setLayerName(const char *layerName){ m_sLayerName = layerName; }