diff --git a/CHANGELOG b/CHANGELOG index 4d58d944e0..25d4f2d170 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,7 @@ cocos2d-x-3.2 ??? [FIX] Node: state of _transformUpdated, _transformDirty and _inverseDirty are wrong in setParent() [FIX] Node: _orderOfArrival is set to 0 after visit [FIX] Other: link error with Xcode 6 when building with 32-bit architecture + [FIX] RenderTexture: saveToFile() lost alpha channel [FIX] Repeat: will run one more over in rare situations [FIX] Scale9Sprite: support culling [FIX] Schedule: schedulePerFrame() can not be called twice diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 84d0973693..cfac0a194f 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1529,7 +1529,7 @@ public: virtual void setOpacityModifyRGB(bool bValue) override { return Node::setOpacityModifyRGB(bValue); } virtual bool isOpacityModifyRGB() const override { return Node::isOpacityModifyRGB(); } -protected: +CC_CONSTRUCTOR_ACCESS: __NodeRGBA(); virtual ~__NodeRGBA() {} diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index f8d08d3185..7738341537 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -409,29 +409,47 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3 _orderOfArrival = 0; } -bool RenderTexture::saveToFile(const std::string& filename) +bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA) { - return saveToFile(filename,Image::Format::JPG); + std::string basename(filename); + std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower); + + if (basename.find(".png") != std::string::npos) + { + return saveToFile(filename, Image::Format::PNG, isRGBA); + } + else if (basename.find(".jpg") != std::string::npos) + { + if (isRGBA) CCLOG("RGBA is not supported for JPG format."); + return saveToFile(filename, Image::Format::JPG, false); + } + else + { + CCLOG("Only PNG and JPG format are supported now!"); + } + + return saveToFile(filename, Image::Format::JPG, false); } -bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format) +bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA) { CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, "the image can only be saved as JPG or PNG format"); + if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); - _saveToFileCommand.func = CC_CALLBACK_0(RenderTexture::onSaveToFile,this,fullpath); + _saveToFileCommand.func = CC_CALLBACK_0(RenderTexture::onSaveToFile, this, fullpath, isRGBA); Director::getInstance()->getRenderer()->addCommand(&_saveToFileCommand); return true; } -void RenderTexture::onSaveToFile(const std::string& filename) +void RenderTexture::onSaveToFile(const std::string& filename, bool isRGBA) { Image *image = newImage(true); if (image) { - image->saveToFile(filename.c_str(), true); + image->saveToFile(filename.c_str(), !isRGBA); } CC_SAFE_DELETE(image); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 09ba451df7..187acc18b3 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -103,12 +103,12 @@ public: /** saves the texture into a file using JPEG format. The file will be saved in the Documents folder. Returns true if the operation is successful. */ - bool saveToFile(const std::string& filename); + bool saveToFile(const std::string& filename, bool isRGBA = true); /** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder. Returns true if the operation is successful. */ - bool saveToFile(const std::string& filename, Image::Format format); + bool saveToFile(const std::string& filename, Image::Format format, bool isRGBA = true); /** Listen "come to background" message, and save render texture. It only has effect on Android. @@ -222,7 +222,7 @@ protected: void onClear(); void onClearDepth(); - void onSaveToFile(const std::string& fileName); + void onSaveToFile(const std::string& fileName, bool isRGBA = true); Mat4 _oldTransMatrix, _oldProjMatrix; Mat4 _transformMatrix, _projectionMatrix; diff --git a/cocos/platform/ios/CCImage.mm b/cocos/platform/ios/CCImage.mm index 71ebce91a2..ab288f8f65 100644 --- a/cocos/platform/ios/CCImage.mm +++ b/cocos/platform/ios/CCImage.mm @@ -42,7 +42,9 @@ bool cocos2d::Image::saveToFile(const std::string& filename, bool isToRGB) bool saveToPNG = false; bool needToCopyPixels = false; - if (std::string::npos != filename.find(".png")) + std::string basename(filename); + std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower); + if (std::string::npos != basename.find(".png")) { saveToPNG = true; } diff --git a/cocos/renderer/ccGLStateCache.cpp b/cocos/renderer/ccGLStateCache.cpp index 33b85c9b7a..4a73ffeeac 100644 --- a/cocos/renderer/ccGLStateCache.cpp +++ b/cocos/renderer/ccGLStateCache.cpp @@ -164,22 +164,25 @@ void bindTexture2DN(GLuint textureUnit, GLuint textureId) void deleteTexture(GLuint textureId) -{ - deleteTextureN(0, textureId); -} - -void deleteTextureN(GLuint textureUnit, GLuint textureId) { #if CC_ENABLE_GL_STATE_CACHE - if (s_currentBoundTexture[textureUnit] == textureId) + for (size_t i = 0; i < MAX_ACTIVE_TEXTURE; ++i) { - s_currentBoundTexture[textureUnit] = -1; + if (s_currentBoundTexture[i] == textureId) + { + s_currentBoundTexture[i] = -1; + } } #endif // CC_ENABLE_GL_STATE_CACHE glDeleteTextures(1, &textureId); } +void deleteTextureN(GLuint textureUnit, GLuint textureId) +{ + deleteTexture(textureId); +} + void activeTexture(GLenum texture) { #if CC_ENABLE_GL_STATE_CACHE diff --git a/cocos/renderer/ccGLStateCache.h b/cocos/renderer/ccGLStateCache.h index 9c1047c922..5c3b32ca0a 100644 --- a/cocos/renderer/ccGLStateCache.h +++ b/cocos/renderer/ccGLStateCache.h @@ -129,7 +129,7 @@ void CC_DLL deleteTexture(GLuint textureId); If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glDeleteTextures() directly. @since v2.1.0 */ -void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId); +CC_DEPRECATED_ATTRIBUTE void CC_DLL deleteTextureN(GLuint textureUnit, GLuint textureId); /** Select active texture unit. If CC_ENABLE_GL_STATE_CACHE is disabled, it will call glActiveTexture() directly. diff --git a/cocos/scripting/lua-bindings/auto/api/RenderTexture.lua b/cocos/scripting/lua-bindings/auto/api/RenderTexture.lua index 1a072caad4..8542858754 100644 --- a/cocos/scripting/lua-bindings/auto/api/RenderTexture.lua +++ b/cocos/scripting/lua-bindings/auto/api/RenderTexture.lua @@ -64,14 +64,15 @@ -- @param self -------------------------------- --- overload function: saveToFile(string, cc.Image::Format) +-- overload function: saveToFile(string, cc.Image::Format, bool) -- --- overload function: saveToFile(string) +-- overload function: saveToFile(string, bool) -- -- @function [parent=#RenderTexture] saveToFile -- @param self -- @param #string str -- @param #cc.Image::Format format +-- @param #bool bool -- @return bool#bool ret (retunr value: bool) -------------------------------- diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index 8f264e16eb..19394c8005 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -48007,6 +48007,26 @@ int lua_cocos2dx_RenderTexture_saveToFile(lua_State* tolua_S) } }while(0); ok = true; + do{ + if (argc == 3) { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2,&arg0); + + if (!ok) { break; } + cocos2d::Image::Format arg1; + ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1); + + if (!ok) { break; } + bool arg2; + ok &= luaval_to_boolean(tolua_S, 4,&arg2); + + if (!ok) { break; } + bool ret = cobj->saveToFile(arg0, arg1, arg2); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; do{ if (argc == 1) { std::string arg0; @@ -48019,6 +48039,22 @@ int lua_cocos2dx_RenderTexture_saveToFile(lua_State* tolua_S) } }while(0); ok = true; + do{ + if (argc == 2) { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2,&arg0); + + if (!ok) { break; } + bool arg1; + ok &= luaval_to_boolean(tolua_S, 3,&arg1); + + if (!ok) { break; } + bool ret = cobj->saveToFile(arg0, arg1); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "saveToFile",argc, 1); return 0; diff --git a/external/config.json b/external/config.json index 94ea34592a..87b845080d 100644 --- a/external/config.json +++ b/external/config.json @@ -1,5 +1,5 @@ { - "version":"v3-deps-2", + "version":"v3-deps-3", "zip_file_size":"57171285", "repo_name":"cocos2d-x-3rd-party-libs-bin", "repo_parent":"https://github.com/cocos2d/" diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 498f24c168..f5037bab73 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 498f24c1683e4725ecaad6168a1aab21b283b8d5 +Subproject commit f5037bab73a8fb109e8e34656220bed1a1743087