Merge pull request #36 from cocos2d/v3

merge from cocos2d-x
This commit is contained in:
cocoscodeide 2014-06-16 17:50:28 +08:00
commit b00e7a3b86
11 changed files with 84 additions and 23 deletions

View File

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

View File

@ -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() {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

@ -1 +1 @@
Subproject commit 498f24c1683e4725ecaad6168a1aab21b283b8d5
Subproject commit f5037bab73a8fb109e8e34656220bed1a1743087