From 626ba2686f2b67eed27cbc4a3b9a4c79decb3943 Mon Sep 17 00:00:00 2001 From: Jaroslaw Lewandowski Date: Tue, 9 Jul 2013 21:21:43 +0100 Subject: [PATCH 1/9] Solving 'black screen' on android --- cocos2dx/platform/CCFileUtils.cpp | 3 + cocos2dx/platform/CCPlatformMacros.h | 2 +- cocos2dx/textures/CCTexture2D.cpp | 150 +++++++----------- cocos2dx/textures/CCTextureCache.cpp | 22 +-- cocos2dx/textures/CCTextureCache.h | 13 +- .../proj.android/jni/hellocpp/main.cpp | 2 - .../proj.android/jni/hellocpp/main.cpp | 2 - .../proj.android/jni/hellocpp/main.cpp | 2 - .../proj.android/jni/hellocpp/main.cpp | 2 - .../TestCpp/proj.android/jni/testcpp/main.cpp | 2 - .../proj.android/jni/cocosdragonjs/main.cpp | 2 - .../proj.android/jni/crystalcraze/main.cpp | 2 - .../proj.android/jni/moonwarriors/main.cpp | 2 - .../proj.android/jni/testjavascript/main.cpp | 2 - .../jni/watermelonwithme/main.cpp | 2 - .../proj.android/jni/hellocpp/main.cpp | 2 - 16 files changed, 66 insertions(+), 146 deletions(-) diff --git a/cocos2dx/platform/CCFileUtils.cpp b/cocos2dx/platform/CCFileUtils.cpp index 13b3646085..b08fa0721b 100644 --- a/cocos2dx/platform/CCFileUtils.cpp +++ b/cocos2dx/platform/CCFileUtils.cpp @@ -654,6 +654,7 @@ const char* FileUtils::fullPathFromRelativeFile(const char *pszFilename, const c void FileUtils::setSearchResolutionsOrder(const std::vector& searchResolutionsOrder) { bool bExistDefault = false; + _fullPathCache.clear(); _searchResolutionsOrderArray.clear(); for (std::vector::const_iterator iter = searchResolutionsOrder.begin(); iter != searchResolutionsOrder.end(); ++iter) { @@ -695,6 +696,7 @@ void FileUtils::setSearchPaths(const std::vector& searchPaths) { bool bExistDefaultRootPath = false; + _fullPathCache.clear(); _searchPathArray.clear(); for (std::vector::const_iterator iter = searchPaths.begin(); iter != searchPaths.end(); ++iter) { @@ -741,6 +743,7 @@ void FileUtils::addSearchPath(const char* path_) void FileUtils::setFilenameLookupDictionary(Dictionary* pFilenameLookupDict) { + _fullPathCache.clear(); CC_SAFE_RELEASE(_filenameLookupDict); _filenameLookupDict = pFilenameLookupDict; CC_SAFE_RETAIN(_filenameLookupDict); diff --git a/cocos2dx/platform/CCPlatformMacros.h b/cocos2dx/platform/CCPlatformMacros.h index 59ac1ba07b..d08122bda2 100644 --- a/cocos2dx/platform/CCPlatformMacros.h +++ b/cocos2dx/platform/CCPlatformMacros.h @@ -81,7 +81,7 @@ to be different from other platforms unless there's a good reason. It's new in cocos2d-x since v0.99.5 */ -#if 0 +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #define CC_ENABLE_CACHE_TEXTURE_DATA 1 #else #define CC_ENABLE_CACHE_TEXTURE_DATA 0 diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index c6e21dc772..e24d33f45e 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -442,107 +442,55 @@ bool Texture2D::initWithString(const char *text, const char *fontName, float fon bool Texture2D::initWithString(const char *text, const char *fontName, float fontSize, const Size& dimensions, TextAlignment hAlignment, VerticalTextAlignment vAlignment) { - #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + FontDefinition tempDef; - FontDefinition tempDef; - - tempDef._shadow._shadowEnabled = false; - tempDef._stroke._strokeEnabled = false; - - - tempDef._fontName = std::string(fontName); - tempDef._fontSize = fontSize; - tempDef._dimensions = dimensions; - tempDef._alignment = hAlignment; - tempDef._vertAlignment = vAlignment; - tempDef._fontFillColor = Color3B::WHITE; - - return initWithString(text, tempDef); - - - #else - - - #if CC_ENABLE_CACHE_TEXTURE_DATA - // cache the texture data - VolatileTexture::addStringTexture(this, text, dimensions, hAlignment, vAlignment, fontName, fontSize); - #endif - - bool bRet = false; - Image::ETextAlign eAlign; - - if (kVerticalTextAlignmentTop == vAlignment) - { - eAlign = (kTextAlignmentCenter == hAlignment) ? Image::kAlignTop - : (kTextAlignmentLeft == hAlignment) ? Image::kAlignTopLeft : Image::kAlignTopRight; - } - else if (kVerticalTextAlignmentCenter == vAlignment) - { - eAlign = (kTextAlignmentCenter == hAlignment) ? Image::kAlignCenter - : (kTextAlignmentLeft == hAlignment) ? Image::kAlignLeft : Image::kAlignRight; - } - else if (kVerticalTextAlignmentBottom == vAlignment) - { - eAlign = (kTextAlignmentCenter == hAlignment) ? Image::kAlignBottom - : (kTextAlignmentLeft == hAlignment) ? Image::kAlignBottomLeft : Image::kAlignBottomRight; - } - else - { - CCAssert(false, "Not supported alignment format!"); - return false; - } - - do - { - Image* pImage = new Image(); - CC_BREAK_IF(NULL == pImage); - bRet = pImage->initWithString(text, (int)dimensions.width, (int)dimensions.height, eAlign, fontName, (int)fontSize); - CC_BREAK_IF(!bRet); - bRet = initWithImage(pImage); - CC_SAFE_RELEASE(pImage); - } while (0); - - - return bRet; - - - #endif + tempDef._shadow._shadowEnabled = false; + tempDef._stroke._strokeEnabled = false; + + tempDef._fontName = std::string(fontName); + tempDef._fontSize = fontSize; + tempDef._dimensions = dimensions; + tempDef._alignment = hAlignment; + tempDef._vertAlignment = vAlignment; + tempDef._fontFillColor = Color3B::WHITE; + + return initWithString(text, tempDef); } bool Texture2D::initWithString(const char *text, const FontDefinition& textDefinition) { - #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - #if CC_ENABLE_CACHE_TEXTURE_DATA // cache the texture data - VolatileTexture::addStringTexture(this, text, textDefinition._dimensions, textDefinition._alignment, textDefinition._vertAlignment, textDefinition._fontName.c_str(), textDefinition._fontSize); + VolatileTexture::addStringTexture(this, text, textDefinition); #endif - - bool bRet = false; - Image::ETextAlign eAlign; - - if (kVerticalTextAlignmentTop == textDefinition._vertAlignment) - { - eAlign = (kTextAlignmentCenter == textDefinition._alignment) ? Image::kAlignTop - : (kTextAlignmentLeft == textDefinition._alignment) ? Image::kAlignTopLeft : Image::kAlignTopRight; - } - else if (kVerticalTextAlignmentCenter == textDefinition._vertAlignment) - { - eAlign = (kTextAlignmentCenter == textDefinition._alignment) ? Image::kAlignCenter - : (kTextAlignmentLeft == textDefinition._alignment) ? Image::kAlignLeft : Image::kAlignRight; - } - else if (kVerticalTextAlignmentBottom == textDefinition._vertAlignment) - { - eAlign = (kTextAlignmentCenter == textDefinition._alignment) ? Image::kAlignBottom - : (kTextAlignmentLeft == textDefinition._alignment) ? Image::kAlignBottomLeft : Image::kAlignBottomRight; - } - else - { - CCAssert(false, "Not supported alignment format!"); - return false; - } - + + bool bRet = false; + Image::ETextAlign eAlign; + + if (kVerticalTextAlignmentTop == textDefinition._vertAlignment) + { + eAlign = (kTextAlignmentCenter == textDefinition._alignment) ? Image::kAlignTop + : (kTextAlignmentLeft == textDefinition._alignment) ? Image::kAlignTopLeft : Image::kAlignTopRight; + } + else if (kVerticalTextAlignmentCenter == textDefinition._vertAlignment) + { + eAlign = (kTextAlignmentCenter == textDefinition._alignment) ? Image::kAlignCenter + : (kTextAlignmentLeft == textDefinition._alignment) ? Image::kAlignLeft : Image::kAlignRight; + } + else if (kVerticalTextAlignmentBottom == textDefinition._vertAlignment) + { + eAlign = (kTextAlignmentCenter == textDefinition._alignment) ? Image::kAlignBottom + : (kTextAlignmentLeft == textDefinition._alignment) ? Image::kAlignBottomLeft : Image::kAlignBottomRight; + } + else + { + CCAssert(false, "Not supported alignment format!"); + return false; + } + + #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + // handle shadow parameters bool shadowEnabled = false; float shadowDX = 0.0f; @@ -612,10 +560,22 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin #else + bool requestUnsupported = textDefinition->_shadow._shadowEnabled || textDefinition->_stroke._strokeEnabled; - CCAssert(false, "Currently only supported on iOS and Android!"); - return false; + CCAssert(requestUnsupported == false, "Currently shadow and stroke only supported on iOS and Android!"); + do + { + CCImage* pImage = new CCImage(); + CC_BREAK_IF(NULL == pImage); + bRet = pImage->initWithString(text, (int)textDefinition->_dimensions.width, (int)textDefinition->_dimensions.height, eAlign, textDefinition->_fontName.c_str(), (int)textDefinition->_fontSize); + CC_BREAK_IF(!bRet); + bRet = initWithImage(pImage); + CC_SAFE_RELEASE(pImage); + } while (0); + + + return bRet; #endif } @@ -624,7 +584,7 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin void Texture2D::drawAtPoint(const Point& point) { - GLfloat coordinates[] = { + GLfloat coordinates[] = { 0.0f, _maxT, _maxS,_maxT, 0.0f, 0.0f, diff --git a/cocos2dx/textures/CCTextureCache.cpp b/cocos2dx/textures/CCTextureCache.cpp index 8aee499d15..688faaf630 100644 --- a/cocos2dx/textures/CCTextureCache.cpp +++ b/cocos2dx/textures/CCTextureCache.cpp @@ -646,14 +646,9 @@ VolatileTexture::VolatileTexture(Texture2D *t) , _pixelFormat(kTexture2DPixelFormat_RGBA8888) , _fileName("") , _fmtImage(Image::kFmtPng) -, _alignment(kTextAlignmentCenter) -, _vAlignment(kVerticalTextAlignmentCenter) -, _fontName("") , _text("") , uiImage(NULL) -, _fontSize(0.0f) { - _size = CCSizeMake(0, 0); _texParams.minFilter = GL_LINEAR; _texParams.magFilter = GL_LINEAR; _texParams.wrapS = GL_CLAMP_TO_EDGE; @@ -727,8 +722,7 @@ void VolatileTexture::addDataTexture(Texture2D *tt, void* data, Texture2DPixelFo vt->_textureSize = contentSize; } -void VolatileTexture::addStringTexture(Texture2D *tt, const char* text, const Size& dimensions, TextAlignment alignment, - VerticalTextAlignment vAlignment, const char *fontName, float fontSize) +void VolatileTexture::addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition) { if (isReloading) { @@ -738,12 +732,8 @@ void VolatileTexture::addStringTexture(Texture2D *tt, const char* text, const Si VolatileTexture *vt = findVolotileTexture(tt); vt->_cashedImageType = kString; - vt->_size = dimensions; - vt->_fontName = fontName; - vt->_alignment = alignment; - vt->_vAlignment = vAlignment; - vt->_fontSize = fontSize; vt->_text = text; + vt->_fontDefinition = fontDefinition; } void VolatileTexture::setTexParameters(Texture2D *t, const ccTexParams &texParams) @@ -834,13 +824,7 @@ void VolatileTexture::reloadAllTextures() break; case kString: { - vt->texture->initWithString(vt->_text.c_str(), - vt->_fontName.c_str(), - vt->_fontSize, - vt->_size, - vt->_alignment, - vt->_vAlignment - ); + vt->texture->initWithString(vt->_text.c_str(), vt->_fontDefinition); } break; case kImage: diff --git a/cocos2dx/textures/CCTextureCache.h b/cocos2dx/textures/CCTextureCache.h index 5a95a5520a..6f8068fd61 100644 --- a/cocos2dx/textures/CCTextureCache.h +++ b/cocos2dx/textures/CCTextureCache.h @@ -213,8 +213,7 @@ public: ~VolatileTexture(); static void addImageTexture(Texture2D *tt, const char* imageFileName, Image::EImageFormat format); - static void addStringTexture(Texture2D *tt, const char* text, const Size& dimensions, TextAlignment alignment, - VerticalTextAlignment vAlignment, const char *fontName, float fontSize); + static void addStringTexture(Texture2D *tt, const char* text, const FontDefinition& fontDefinition); static void addDataTexture(Texture2D *tt, void* data, Texture2DPixelFormat pixelFormat, const Size& contentSize); static void addImage(Texture2D *tt, Image *image); @@ -245,13 +244,9 @@ protected: std::string _fileName; Image::EImageFormat _fmtImage; - ccTexParams _texParams; - Size _size; - TextAlignment _alignment; - VerticalTextAlignment _vAlignment; - std::string _fontName; - std::string _text; - float _fontSize; + ccTexParams _texParams; + std::string _text; + FontDefinition _fontDefinition; }; #endif diff --git a/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp b/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp index 62149196e9..801f23c234 100644 --- a/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp +++ b/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp @@ -31,7 +31,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -42,7 +41,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp b/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp index 9df6544ccc..c48f9af11f 100644 --- a/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp +++ b/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp @@ -28,7 +28,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -39,7 +38,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp b/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp index 2521065482..55e7874cc8 100644 --- a/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp +++ b/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp b/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp index 0663ce4913..421ed0e412 100644 --- a/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp +++ b/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp b/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp index 33457710cd..6895986ba0 100644 --- a/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp +++ b/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp b/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp index 9ec70a81e0..a204013e7a 100644 --- a/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp +++ b/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp b/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp index 9ec70a81e0..a204013e7a 100644 --- a/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp +++ b/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp b/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp index 9ec70a81e0..a204013e7a 100644 --- a/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp +++ b/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp b/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp index 9ec70a81e0..a204013e7a 100644 --- a/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp +++ b/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp b/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp index 9ec70a81e0..a204013e7a 100644 --- a/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp +++ b/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } diff --git a/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp b/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp index e92f90d583..6895986ba0 100644 --- a/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp +++ b/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp @@ -30,7 +30,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi AppDelegate *pAppDelegate = new AppDelegate(); Application::sharedApplication()->run(); } - /* else { ccDrawInit(); @@ -41,7 +40,6 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi NotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::sharedDirector()->setGLDefaultValues(); } - */ } } From 1fcd6883f1befcee41b877017f1d1e32396c82c7 Mon Sep 17 00:00:00 2001 From: Jaroslaw Lewandowski Date: Tue, 9 Jul 2013 23:32:10 +0100 Subject: [PATCH 2/9] fixing Linux build --- cocos2dx/textures/CCTexture2D.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index e24d33f45e..20475d56cf 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -560,15 +560,15 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin #else - bool requestUnsupported = textDefinition->_shadow._shadowEnabled || textDefinition->_stroke._strokeEnabled; + bool requestUnsupported = textDefinition._shadow._shadowEnabled || textDefinition._stroke._strokeEnabled; CCAssert(requestUnsupported == false, "Currently shadow and stroke only supported on iOS and Android!"); do { - CCImage* pImage = new CCImage(); + Image* pImage = new Image(); CC_BREAK_IF(NULL == pImage); - bRet = pImage->initWithString(text, (int)textDefinition->_dimensions.width, (int)textDefinition->_dimensions.height, eAlign, textDefinition->_fontName.c_str(), (int)textDefinition->_fontSize); + bRet = pImage->initWithString(text, (int)textDefinition._dimensions.width, (int)textDefinition._dimensions.height, eAlign, textDefinition._fontName.c_str(), (int)textDefinition._fontSize); CC_BREAK_IF(!bRet); bRet = initWithImage(pImage); CC_SAFE_RELEASE(pImage); From 5b06824036003fd4ff4e16215a9947d102412bfe Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 16 Jul 2013 16:47:35 +0800 Subject: [PATCH 3/9] closed #2410: Formatting codes in Texture2D::initWithString. --- cocos2dx/textures/CCTexture2D.cpp | 171 +++++++++++++++--------------- 1 file changed, 85 insertions(+), 86 deletions(-) diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index da5c299ed4..fb36a4cd7e 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -460,10 +460,10 @@ bool Texture2D::initWithString(const char *text, const char *fontName, float fon bool Texture2D::initWithString(const char *text, const FontDefinition& textDefinition) { - #if CC_ENABLE_CACHE_TEXTURE_DATA - // cache the texture data - VolatileTexture::addStringTexture(this, text, textDefinition); - #endif +#if CC_ENABLE_CACHE_TEXTURE_DATA + // cache the texture data + VolatileTexture::addStringTexture(this, text, textDefinition); +#endif bool bRet = false; Image::ETextAlign eAlign; @@ -489,94 +489,93 @@ bool Texture2D::initWithString(const char *text, const FontDefinition& textDefin return false; } - #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + + // handle shadow parameters + bool shadowEnabled = false; + float shadowDX = 0.0f; + float shadowDY = 0.0f; + float shadowBlur = 0.0f; + float shadowOpacity = 0.0f; - // handle shadow parameters - bool shadowEnabled = false; - float shadowDX = 0.0f; - float shadowDY = 0.0f; - float shadowBlur = 0.0f; - float shadowOpacity = 0.0f; - - if ( textDefinition._shadow._shadowEnabled ) - { - shadowEnabled = true; - shadowDX = textDefinition._shadow._shadowOffset.width; - shadowDY = textDefinition._shadow._shadowOffset.height; - shadowBlur = textDefinition._shadow._shadowBlur; - shadowOpacity = textDefinition._shadow._shadowOpacity; - } - - // handle stroke parameters - bool strokeEnabled = false; - float strokeColorR = 0.0f; - float strokeColorG = 0.0f; - float strokeColorB = 0.0f; - float strokeSize = 0.0f; - - if ( textDefinition._stroke._strokeEnabled ) - { - strokeEnabled = true; - strokeColorR = textDefinition._stroke._strokeColor.r / 255.0f; - strokeColorG = textDefinition._stroke._strokeColor.g / 255.0f; - strokeColorB = textDefinition._stroke._strokeColor.b / 255.0f; - strokeSize = textDefinition._stroke._strokeSize; - } - - Image* pImage = new Image(); - do - { - CC_BREAK_IF(NULL == pImage); - - bRet = pImage->initWithStringShadowStroke(text, - (int)textDefinition._dimensions.width, - (int)textDefinition._dimensions.height, - eAlign, - textDefinition._fontName.c_str(), - textDefinition._fontSize, - textDefinition._fontFillColor.r / 255.0f, - textDefinition._fontFillColor.g / 255.0f, - textDefinition._fontFillColor.b / 255.0f, - shadowEnabled, - shadowDX, - shadowDY, - shadowOpacity, - shadowBlur, - strokeEnabled, - strokeColorR, - strokeColorG, - strokeColorB, - strokeSize); - - - CC_BREAK_IF(!bRet); - bRet = initWithImage(pImage); - - } while (0); - - CC_SAFE_RELEASE(pImage); - - return bRet; + if ( textDefinition._shadow._shadowEnabled ) + { + shadowEnabled = true; + shadowDX = textDefinition._shadow._shadowOffset.width; + shadowDY = textDefinition._shadow._shadowOffset.height; + shadowBlur = textDefinition._shadow._shadowBlur; + shadowOpacity = textDefinition._shadow._shadowOpacity; + } + // handle stroke parameters + bool strokeEnabled = false; + float strokeColorR = 0.0f; + float strokeColorG = 0.0f; + float strokeColorB = 0.0f; + float strokeSize = 0.0f; - #else - bool requestUnsupported = textDefinition._shadow._shadowEnabled || textDefinition._stroke._strokeEnabled; + if ( textDefinition._stroke._strokeEnabled ) + { + strokeEnabled = true; + strokeColorR = textDefinition._stroke._strokeColor.r / 255.0f; + strokeColorG = textDefinition._stroke._strokeColor.g / 255.0f; + strokeColorB = textDefinition._stroke._strokeColor.b / 255.0f; + strokeSize = textDefinition._stroke._strokeSize; + } - CCAssert(requestUnsupported == false, "Currently shadow and stroke only supported on iOS and Android!"); - - do - { - Image* pImage = new Image(); - CC_BREAK_IF(NULL == pImage); - bRet = pImage->initWithString(text, (int)textDefinition._dimensions.width, (int)textDefinition._dimensions.height, eAlign, textDefinition._fontName.c_str(), (int)textDefinition._fontSize); - CC_BREAK_IF(!bRet); - bRet = initWithImage(pImage); - CC_SAFE_RELEASE(pImage); - } while (0); + Image* pImage = new Image(); + do + { + CC_BREAK_IF(NULL == pImage); + bRet = pImage->initWithStringShadowStroke(text, + (int)textDefinition._dimensions.width, + (int)textDefinition._dimensions.height, + eAlign, + textDefinition._fontName.c_str(), + textDefinition._fontSize, + textDefinition._fontFillColor.r / 255.0f, + textDefinition._fontFillColor.g / 255.0f, + textDefinition._fontFillColor.b / 255.0f, + shadowEnabled, + shadowDX, + shadowDY, + shadowOpacity, + shadowBlur, + strokeEnabled, + strokeColorR, + strokeColorG, + strokeColorB, + strokeSize); + + + CC_BREAK_IF(!bRet); + bRet = initWithImage(pImage); + + } while (0); - return bRet; - #endif + CC_SAFE_RELEASE(pImage); + + return bRet; + +#else + bool requestUnsupported = textDefinition._shadow._shadowEnabled || textDefinition._stroke._strokeEnabled; + + CCAssert(requestUnsupported == false, "Currently shadow and stroke only supported on iOS and Android!"); + + Image* pImage = new Image(); + do + { + CC_BREAK_IF(NULL == pImage); + bRet = pImage->initWithString(text, (int)textDefinition._dimensions.width, (int)textDefinition._dimensions.height, eAlign, textDefinition._fontName.c_str(), (int)textDefinition._fontSize); + CC_BREAK_IF(!bRet); + bRet = initWithImage(pImage); + } while (0); + + CC_SAFE_RELEASE(pImage); + + return bRet; +#endif } From 56419b9e90d0e32677e6276141fcb65d5a04b166 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Jul 2013 12:53:30 +0800 Subject: [PATCH 4/9] issue #2410: [Android] Adding listener for CCDrawNode when application resume from background. Reset the order of reloading shaders and textures in main.cpp. --- cocos2dx/draw_nodes/CCDrawNode.cpp | 31 ++++++++++++++----- cocos2dx/draw_nodes/CCDrawNode.h | 4 +++ .../particle_nodes/CCParticleSystemQuad.cpp | 4 +-- cocos2dx/shaders/CCGLProgram.cpp | 2 +- cocos2dx/shaders/ccGLStateCache.cpp | 4 +++ cocos2dx/textures/CCTextureAtlas.cpp | 4 +-- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../TestCpp/proj.android/jni/testcpp/main.cpp | 3 +- .../proj.android/jni/cocosdragonjs/main.cpp | 3 +- .../proj.android/jni/crystalcraze/main.cpp | 3 +- .../proj.android/jni/moonwarriors/main.cpp | 3 +- .../proj.android/jni/testjavascript/main.cpp | 3 +- .../jni/watermelonwithme/main.cpp | 3 +- .../proj.android/jni/hellolua/main.cpp | 3 +- .../TestLua/proj.android/jni/testlua/main.cpp | 3 +- .../proj.android/jni/hellocpp/main.cpp | 3 +- .../proj.android/jni/hellojavascript/main.cpp | 3 +- .../proj.android/jni/hellolua/main.cpp | 3 +- 23 files changed, 51 insertions(+), 49 deletions(-) diff --git a/cocos2dx/draw_nodes/CCDrawNode.cpp b/cocos2dx/draw_nodes/CCDrawNode.cpp index 50a99ad086..ab715e48ac 100644 --- a/cocos2dx/draw_nodes/CCDrawNode.cpp +++ b/cocos2dx/draw_nodes/CCDrawNode.cpp @@ -23,6 +23,8 @@ #include "CCDrawNode.h" #include "shaders/CCShaderCache.h" #include "CCGL.h" +#include "support/CCNotificationCenter.h" +#include "CCEventType.h" NS_CC_BEGIN @@ -118,6 +120,8 @@ DrawNode::~DrawNode() ccGLBindVAO(0); _vao = 0; #endif + + NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); } DrawNode* DrawNode::create() @@ -157,18 +161,17 @@ bool DrawNode::init() glGenVertexArrays(1, &_vao); ccGLBindVAO(_vao); #endif - + glGenBuffers(1, &_vbo); glBindBuffer(GL_ARRAY_BUFFER, _vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW); - glEnableVertexAttribArray(kVertexAttrib_Position); + ccGLEnableVertexAttribs( kVertexAttribFlag_PosColorTex ); + glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices)); - glEnableVertexAttribArray(kVertexAttrib_Color); glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors)); - glEnableVertexAttribArray(kVertexAttrib_TexCoords); glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -181,6 +184,12 @@ bool DrawNode::init() _dirty = true; + // Need to listen the event only when not use batchnode, because it will use VBO + NotificationCenter::getInstance()->addObserver(this, + callfuncO_selector(DrawNode::listenBackToForeground), + EVNET_COME_TO_FOREGROUND, + NULL); + return true; } @@ -196,6 +205,7 @@ void DrawNode::render() ccGLBindVAO(_vao); #else ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); // vertex glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices)); @@ -216,11 +226,9 @@ void DrawNode::render() void DrawNode::draw() { + CC_NODE_DRAW_SETUP(); ccGLBlendFunc(_blendFunc.src, _blendFunc.dst); - - getShaderProgram()->use(); - getShaderProgram()->setUniformsForBuiltins(); - + render(); } @@ -440,4 +448,11 @@ void DrawNode::setBlendFunc(const BlendFunc &blendFunc) _blendFunc = blendFunc; } +/** listen the event that coming to foreground on Android + */ +void DrawNode::listenBackToForeground(Object *obj) +{ + init(); +} + NS_CC_END diff --git a/cocos2dx/draw_nodes/CCDrawNode.h b/cocos2dx/draw_nodes/CCDrawNode.h index 3c74e56e5e..70bebf186d 100644 --- a/cocos2dx/draw_nodes/CCDrawNode.h +++ b/cocos2dx/draw_nodes/CCDrawNode.h @@ -79,6 +79,10 @@ public: DrawNode(); + /** listen the event that coming to foreground on Android + */ + void listenBackToForeground(Object *obj); + private: void ensureCapacity(unsigned int count); void render(); diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index 9503ab8d63..1a9345401f 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -483,16 +483,14 @@ void ParticleSystemQuad::setupVBOandVAO() glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _totalParticles, _quads, GL_DYNAMIC_DRAW); + ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex); // vertices - glEnableVertexAttribArray(kVertexAttrib_Position); glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices)); // colors - glEnableVertexAttribArray(kVertexAttrib_Color); glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors)); // tex coords - glEnableVertexAttribArray(kVertexAttrib_TexCoords); glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]); diff --git a/cocos2dx/shaders/CCGLProgram.cpp b/cocos2dx/shaders/CCGLProgram.cpp index a525687e31..1a44724e29 100644 --- a/cocos2dx/shaders/CCGLProgram.cpp +++ b/cocos2dx/shaders/CCGLProgram.cpp @@ -241,7 +241,7 @@ bool GLProgram::link() _vertShader = _fragShader = 0; -#if DEBUG +#if COCOS2D_DEBUG glGetProgramiv(_program, GL_LINK_STATUS, &status); if (status == GL_FALSE) diff --git a/cocos2dx/shaders/ccGLStateCache.cpp b/cocos2dx/shaders/ccGLStateCache.cpp index 74a83097a7..549719f652 100644 --- a/cocos2dx/shaders/ccGLStateCache.cpp +++ b/cocos2dx/shaders/ccGLStateCache.cpp @@ -76,7 +76,11 @@ void ccGLInvalidateStateCache( void ) s_eBlendingSource = -1; s_eBlendingDest = -1; s_eGLServerState = 0; +#if CC_TEXTURE_ATLAS_USE_VAO + s_uVAO = 0; #endif + +#endif // CC_ENABLE_GL_STATE_CACHE } void ccGLDeleteProgram( GLuint program ) diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 222532a96a..59e3486a12 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -255,16 +255,14 @@ void TextureAtlas::setupVBOandVAO() glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _capacity, _quads, GL_DYNAMIC_DRAW); + ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex); // vertices - glEnableVertexAttribArray(kVertexAttrib_Position); glVertexAttribPointer(kVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices)); // colors - glEnableVertexAttribArray(kVertexAttrib_Color); glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors)); // tex coords - glEnableVertexAttribArray(kVertexAttrib_TexCoords); glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]); diff --git a/plugin/samples/HelloAnalytics-JS/proj.android/jni/hellocpp/main.cpp b/plugin/samples/HelloAnalytics-JS/proj.android/jni/hellocpp/main.cpp index d602be8273..26a98e22fe 100644 --- a/plugin/samples/HelloAnalytics-JS/proj.android/jni/hellocpp/main.cpp +++ b/plugin/samples/HelloAnalytics-JS/proj.android/jni/hellocpp/main.cpp @@ -34,10 +34,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/plugin/samples/HelloIAP-JS/proj.android/jni/hellocpp/main.cpp b/plugin/samples/HelloIAP-JS/proj.android/jni/hellocpp/main.cpp index d602be8273..26a98e22fe 100644 --- a/plugin/samples/HelloIAP-JS/proj.android/jni/hellocpp/main.cpp +++ b/plugin/samples/HelloIAP-JS/proj.android/jni/hellocpp/main.cpp @@ -34,10 +34,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp b/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp index 8c0ced20a8..5a68d26107 100644 --- a/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp +++ b/plugin/samples/HelloPlugins/proj.android/jni/hellocpp/main.cpp @@ -33,10 +33,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp b/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp index 4c4ff0ded1..ac6f58ba07 100644 --- a/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp +++ b/samples/Cpp/AssetsManagerTest/proj.android/jni/hellocpp/main.cpp @@ -30,10 +30,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp b/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp index 47292fa901..7d495c10a1 100644 --- a/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp +++ b/samples/Cpp/HelloCpp/proj.android/jni/hellocpp/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp b/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp index a48824a8ac..e8639bcc2d 100644 --- a/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp +++ b/samples/Cpp/SimpleGame/proj.android/jni/hellocpp/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp b/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp index 112914f998..e503aab97c 100644 --- a/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp +++ b/samples/Cpp/TestCpp/proj.android/jni/testcpp/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp b/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp index 61ccd4a230..1f5171ccb1 100644 --- a/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp +++ b/samples/Javascript/CocosDragonJS/proj.android/jni/cocosdragonjs/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp b/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp index 61ccd4a230..1f5171ccb1 100644 --- a/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp +++ b/samples/Javascript/CrystalCraze/proj.android/jni/crystalcraze/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp b/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp index 61ccd4a230..1f5171ccb1 100644 --- a/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp +++ b/samples/Javascript/MoonWarriors/proj.android/jni/moonwarriors/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp b/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp index 61ccd4a230..1f5171ccb1 100644 --- a/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp +++ b/samples/Javascript/TestJavascript/proj.android/jni/testjavascript/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp b/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp index 61ccd4a230..1f5171ccb1 100644 --- a/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp +++ b/samples/Javascript/WatermelonWithMe/proj.android/jni/watermelonwithme/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Lua/HelloLua/proj.android/jni/hellolua/main.cpp b/samples/Lua/HelloLua/proj.android/jni/hellolua/main.cpp index 3abc83ff7c..51516c9603 100644 --- a/samples/Lua/HelloLua/proj.android/jni/hellolua/main.cpp +++ b/samples/Lua/HelloLua/proj.android/jni/hellolua/main.cpp @@ -31,10 +31,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/samples/Lua/TestLua/proj.android/jni/testlua/main.cpp b/samples/Lua/TestLua/proj.android/jni/testlua/main.cpp index 54c7a4b8c8..e503aab97c 100644 --- a/samples/Lua/TestLua/proj.android/jni/testlua/main.cpp +++ b/samples/Lua/TestLua/proj.android/jni/testlua/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp b/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp index 112914f998..e503aab97c 100644 --- a/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp +++ b/template/multi-platform-cpp/proj.android/jni/hellocpp/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp b/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp index 61ccd4a230..1f5171ccb1 100644 --- a/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp +++ b/template/multi-platform-js/proj.android/jni/hellojavascript/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); diff --git a/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp b/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp index 54c7a4b8c8..e503aab97c 100644 --- a/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp +++ b/template/multi-platform-lua/proj.android/jni/hellolua/main.cpp @@ -32,10 +32,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi } else { - ccDrawInit(); ccGLInvalidateStateCache(); - ShaderCache::getInstance()->reloadDefaultShaders(); + ccDrawInit(); TextureCache::reloadAllTextures(); NotificationCenter::getInstance()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); Director::getInstance()->setGLDefaultValues(); From 7b51599cbdaeec42bceb6b8265b0e4e8493db4e3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Jul 2013 12:55:27 +0800 Subject: [PATCH 5/9] closed #2410: Fixing a bug that loading a wrong texture in ShaderCache::loadDefaultShaders. This could fix DrawNode displays nothing when resume. --- cocos2dx/shaders/CCShaderCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2dx/shaders/CCShaderCache.cpp b/cocos2dx/shaders/CCShaderCache.cpp index e2129a94a7..1fe685885e 100644 --- a/cocos2dx/shaders/CCShaderCache.cpp +++ b/cocos2dx/shaders/CCShaderCache.cpp @@ -219,7 +219,7 @@ void ShaderCache::reloadDefaultShaders() // p = programForKey(kShader_PositionLengthTexureColor); p->reset(); - loadDefaultShader(p, kShaderType_Position_uColor); + loadDefaultShader(p, kShaderType_PositionLengthTexureColor); } void ShaderCache::loadDefaultShader(GLProgram *p, int type) @@ -297,7 +297,7 @@ void ShaderCache::loadDefaultShader(GLProgram *p, int type) GLProgram* ShaderCache::programForKey(const char* key) { - return (GLProgram*)_programs->objectForKey(key); + return static_cast(_programs->objectForKey(key)); } void ShaderCache::addProgram(GLProgram* program, const char* key) From 209392085c2f7f40cc49640c2a5f9e997c784c50 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Jul 2013 13:53:16 +0800 Subject: [PATCH 6/9] issue #2410: Reverting some changes about VAO. And adding CC_ENABLE_CACHE_TEXTURE_DATA to 'EVNET_COME_TO_FOREGROUND' in DrawNode. --- cocos2dx/draw_nodes/CCDrawNode.cpp | 4 ++++ cocos2dx/particle_nodes/CCParticleSystemQuad.cpp | 11 ++++++++--- cocos2dx/textures/CCTextureAtlas.cpp | 10 ++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cocos2dx/draw_nodes/CCDrawNode.cpp b/cocos2dx/draw_nodes/CCDrawNode.cpp index ab715e48ac..9fa3b3f8a5 100644 --- a/cocos2dx/draw_nodes/CCDrawNode.cpp +++ b/cocos2dx/draw_nodes/CCDrawNode.cpp @@ -121,7 +121,9 @@ DrawNode::~DrawNode() _vao = 0; #endif +#if CC_ENABLE_CACHE_TEXTURE_DATA NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +#endif } DrawNode* DrawNode::create() @@ -184,11 +186,13 @@ bool DrawNode::init() _dirty = true; +#if CC_ENABLE_CACHE_TEXTURE_DATA // Need to listen the event only when not use batchnode, because it will use VBO NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(DrawNode::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); +#endif return true; } diff --git a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp index 1a9345401f..9d52604b88 100644 --- a/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystemQuad.cpp @@ -65,13 +65,14 @@ bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles) setShaderProgram(ShaderCache::getInstance()->programForKey(kShader_PositionTextureColor)); - +#if CC_ENABLE_CACHE_TEXTURE_DATA // Need to listen the event only when not use batchnode, because it will use VBO NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(ParticleSystemQuad::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); - +#endif + return true; } return false; @@ -100,7 +101,9 @@ ParticleSystemQuad::~ParticleSystemQuad() #endif } +#if CC_ENABLE_CACHE_TEXTURE_DATA NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +#endif } // implementation ParticleSystemQuad @@ -483,14 +486,16 @@ void ParticleSystemQuad::setupVBOandVAO() glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _totalParticles, _quads, GL_DYNAMIC_DRAW); - ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex); // vertices + glEnableVertexAttribArray(kVertexAttrib_Position); glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices)); // colors + glEnableVertexAttribArray(kVertexAttrib_Color); glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors)); // tex coords + glEnableVertexAttribArray(kVertexAttrib_TexCoords); glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]); diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 59e3486a12..bd0ada0de9 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -66,7 +66,9 @@ TextureAtlas::~TextureAtlas() #endif CC_SAFE_RELEASE(_texture); +#if CC_ENABLE_CACHE_TEXTURE_DATA NotificationCenter::getInstance()->removeObserver(this, EVNET_COME_TO_FOREGROUND); +#endif } unsigned int TextureAtlas::getTotalQuads() const @@ -176,12 +178,14 @@ bool TextureAtlas::initWithTexture(Texture2D *texture, unsigned int capacity) memset( _quads, 0, _capacity * sizeof(V3F_C4B_T2F_Quad) ); memset( _indices, 0, _capacity * 6 * sizeof(GLushort) ); +#if CC_ENABLE_CACHE_TEXTURE_DATA // listen the event when app go to background NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(TextureAtlas::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); - +#endif + this->setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO @@ -255,14 +259,16 @@ void TextureAtlas::setupVBOandVAO() glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(_quads[0]) * _capacity, _quads, GL_DYNAMIC_DRAW); - ccGLEnableVertexAttribs(kVertexAttribFlag_PosColorTex); // vertices + glEnableVertexAttribArray(kVertexAttrib_Position); glVertexAttribPointer(kVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, vertices)); // colors + glEnableVertexAttribArray(kVertexAttrib_Color); glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, colors)); // tex coords + glEnableVertexAttribArray(kVertexAttrib_TexCoords); glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( V3F_C4B_T2F, texCoords)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]); From cd136e6330c5c15ec8b0674bd301aca210d52bd2 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Jul 2013 13:55:31 +0800 Subject: [PATCH 7/9] issue #2410: [Reverting] Don't use 'ccGLEnableVertexAttribs' when using VAO, use 'glEnableVertexAttribArray' instead. --- cocos2dx/draw_nodes/CCDrawNode.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cocos2dx/draw_nodes/CCDrawNode.cpp b/cocos2dx/draw_nodes/CCDrawNode.cpp index 9fa3b3f8a5..75bcd4345b 100644 --- a/cocos2dx/draw_nodes/CCDrawNode.cpp +++ b/cocos2dx/draw_nodes/CCDrawNode.cpp @@ -163,17 +163,18 @@ bool DrawNode::init() glGenVertexArrays(1, &_vao); ccGLBindVAO(_vao); #endif - + glGenBuffers(1, &_vbo); glBindBuffer(GL_ARRAY_BUFFER, _vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW); - ccGLEnableVertexAttribs( kVertexAttribFlag_PosColorTex ); - + glEnableVertexAttribArray(kVertexAttrib_Position); glVertexAttribPointer(kVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices)); + glEnableVertexAttribArray(kVertexAttrib_Color); glVertexAttribPointer(kVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors)); + glEnableVertexAttribArray(kVertexAttrib_TexCoords); glVertexAttribPointer(kVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); glBindBuffer(GL_ARRAY_BUFFER, 0); From 7e107a884169ec4a3cd87a02d9b4196aae2ead45 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Jul 2013 14:26:10 +0800 Subject: [PATCH 8/9] Update AUTHORS [ci skip] --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 9dfe6db5ac..410d8ab60c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -443,6 +443,7 @@ Developers: Explicitly initialising CCAcceleration structure. Add support to save/retrieve CCData into/from CCUserDefault. Text Shadows fix + Solving 'black screen' on android. MarcelBloemendaal Adding secureTextEntry property to CCTextFieldTTF. From 7e4e34d9924cf5912e3b5290473df661d7d764f5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 17 Jul 2013 14:36:10 +0800 Subject: [PATCH 9/9] [ci skip]Update cocos2dx.ini, don't genergate bindings for DrawNode::listenBackToForeground. --- tools/tojs/cocos2dx.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index b14151893b..85b0435fc6 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -43,7 +43,7 @@ skip = Node::[^setPosition$ getGrid setGLServerState description getUserObject . ParticleBatchNode::[getBlendFunc setBlendFunc], LayerColor::[getBlendFunc setBlendFunc], ParticleSystem::[getBlendFunc setBlendFunc], - DrawNode::[getBlendFunc setBlendFunc drawPolygon], + DrawNode::[getBlendFunc setBlendFunc drawPolygon listenBackToForeground], Director::[getAccelerometer (g|s)et.*Dispatcher getOpenGLView getProjection getClassTypeInfo], Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased], Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns],