Merge branch 'v3' into cleanupBinaryLoader

This commit is contained in:
andyque 2014-06-17 09:45:16 +08:00
commit 9ab45744bb
36 changed files with 475 additions and 619 deletions

View File

@ -841,6 +841,7 @@ Developers:
sachingarg05
Re-added orientation change callback in java activity
GLProgram should not abort() if shader compilation fails, returning false is better.
dplusic
Fixed that cc.pGetAngle may return wrong value
@ -882,6 +883,12 @@ Developers:
Added TextField::getStringLength()
Add shadow, outline, glow filter support for UIText
QiuleiWang
Fix the bug that calculated height of multi-line string was incorrect on iOS
Rumist
Fix the bug that the result of Director->convertToUI() is error.
Retired Core Developers:
WenSheng Yang
Author of windows port, CCTextField,

View File

@ -1,4 +1,5 @@
cocos2d-x-3.2 ???
[NEW] Console: add a command to show engine version
[NEW] Node: added setter/getter for NormalizedPosition(). Allows to set positions in normalized values (between 0 and 1)
[NEW] Scene: Added createWithSize() method
[NEW] TextField: added getStringLength()
@ -10,22 +11,29 @@ cocos2d-x-3.2 ???
[FIX] Android: 3d model will be black when coming from background
[FIX] Android: don't trigger EVENT_COME_TO_BACKGROUND event when go to background
[FIX] Cocos2dxGLSurfaceView.java: prevent flickering when opening another activity
[FIX] Director: Director->convertToUI() returns wrong value.
[FIX] GLProgram: not abort if shader compilation fails, just retuan false.
[FIX] GLProgramState: sampler can not be changed
[FIX] Image: Set jpeg save quality to 90
[FIX] Image: premultiply alpha when loading png file to resolve black border issue
[FIX] Label: label is unsharp if it's created by smaller font
[FIX] Label: Label's display may go bonkers if invoking Label::setString() with outline feature enabled
[FIX] Label: don't release cached texture in time
[FIX] Label: calculated height of multi-line string was incorrect on iOS
[FIX] Lua-binding: compiling error on release mode
[FIX] Lua-binding: Add xxtea encrypt support
[FIX] Node: setPhysicsBody() can not work correctly if it is added to a Node
[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
[FIX] ShaderTest: 7 times performance improved of blur effect
[FIX] SpriteFrameCache: fix memory leak
[FIX] Texture2D: use image's pixel format to create texture
[FIX] TextureCache: addImageAsync() may repeatedly generate Image for the same image file
[FIX] WP8: will restart if app goes to background, then touches icon to go to foreground
[FIX] WP8: will be black if: 1. 3rd pops up a view; 2. go to background; 3. come to foreground
[FIX] WP8: project name of new project created by console is wrong

View File

@ -392,16 +392,12 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false *
if (_reusedLetter == nullptr)
{
_reusedLetter = Sprite::createWithTexture(_fontAtlas->getTexture(0));
_reusedLetter = Sprite::create();
_reusedLetter->setOpacityModifyRGB(_isOpacityModifyRGB);
_reusedLetter->retain();
_reusedLetter->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
}
_reusedLetter->setBatchNode(this);
}
else
{
_reusedLetter->setTexture(_fontAtlas->getTexture(0));
}
if (_fontAtlas)
{

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);
}
bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format)
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 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

@ -280,6 +280,7 @@
<ClCompile Include="..\base\ccUtils.cpp" />
<ClCompile Include="..\base\CCValue.cpp" />
<ClCompile Include="..\base\etc1.cpp" />
<ClCompile Include="..\base\ObjectFactory.cpp" />
<ClCompile Include="..\base\s3tc.cpp" />
<ClCompile Include="..\base\TGAlib.cpp" />
<ClCompile Include="..\base\ZipUtils.cpp" />
@ -476,6 +477,7 @@
<ClInclude Include="..\base\CCVector.h" />
<ClInclude Include="..\base\etc1.h" />
<ClInclude Include="..\base\firePngData.h" />
<ClInclude Include="..\base\ObjectFactory.h" />
<ClInclude Include="..\base\s3tc.h" />
<ClInclude Include="..\base\TGAlib.h" />
<ClInclude Include="..\base\uthash.h" />

View File

@ -593,6 +593,9 @@
<Filter>renderer</Filter>
</ClCompile>
<ClCompile Include="..\platform\wp8\pch.cpp" />
<ClCompile Include="..\base\ObjectFactory.cpp">
<Filter>base</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\physics\CCPhysicsBody.h">
@ -1205,6 +1208,9 @@
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="..\platform\wp8\pch.h" />
<ClInclude Include="..\base\ObjectFactory.h">
<Filter>base</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\math\Mat4.inl">

View File

@ -65,6 +65,7 @@
#include "base/base64.h"
NS_CC_BEGIN
extern const char* cocos2dVersion(void);
//TODO: these general utils should be in a seperate class
//
// Trimming functions were taken from: http://stackoverflow.com/a/217605
@ -295,6 +296,9 @@ Console::Console()
{ "director", "director commands, type -h or [director help] to list supported directives", std::bind(&Console::commandDirector, this, std::placeholders::_1, std::placeholders::_2) },
{ "touch", "simulate touch event via console, type -h or [touch help] to list supported directives", std::bind(&Console::commandTouch, this, std::placeholders::_1, std::placeholders::_2) },
{ "upload", "upload file. Args: [filename base64_encoded_data]", std::bind(&Console::commandUpload, this, std::placeholders::_1) },
{ "version", "print version string ", [](int fd, const std::string& args) {
mydprintf(fd, "%s\n", cocos2dVersion());
} },
};
;

View File

@ -1,4 +1,4 @@
/****************************************************************************
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2013 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
@ -763,6 +763,18 @@ Vec2 Director::convertToUI(const Vec2& glPoint)
Vec4 glCoord(glPoint.x, glPoint.y, 0.0, 1);
transform.transformVector(glCoord, &clipCoord);
/*
BUG-FIX #5506
a = (Vx, Vy, Vz, 1)
b = (a×M)T
Out = 1 bw(bx, by, bz)
*/
clipCoord.x = clipCoord.x / clipCoord.w;
clipCoord.y = clipCoord.y / clipCoord.w;
clipCoord.z = clipCoord.z / clipCoord.w;
Size glSize = _openGLView->getDesignResolutionSize();
float factor = 1.0/glCoord.w;
return Vec2(glSize.width*(clipCoord.x*0.5 + 0.5) * factor, glSize.height*(-clipCoord.y*0.5 + 0.5) * factor);

View File

@ -215,25 +215,13 @@ static inline void lazyCheckIOS7()
static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
{
NSArray *listItems = [str componentsSeparatedByString: @"\n"];
CGSize dim = CGSizeZero;
CGSize textRect = CGSizeZero;
textRect.width = constrainSize->width > 0 ? constrainSize->width
: 0x7fffffff;
textRect.height = constrainSize->height > 0 ? constrainSize->height
: 0x7fffffff;
for (NSString *s in listItems)
{
CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect];
if (tmp.width > dim.width)
{
dim.width = tmp.width;
}
dim.height += tmp.height;
}
CGSize dim = [str sizeWithFont:font constrainedToSize:textRect];
dim.width = ceilf(dim.width);
dim.height = ceilf(dim.height);

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

@ -138,9 +138,17 @@ GLProgram::~GLProgram()
{
CCLOGINFO("%s %d deallocing GLProgram: %p", __FUNCTION__, __LINE__, this);
// there is no need to delete the shaders. They should have been already deleted.
CCASSERT(_vertShader == 0, "Vertex Shaders should have been already deleted");
CCASSERT(_fragShader == 0, "Fragment Shaders should have been already deleted");
if (_vertShader)
{
glDeleteShader(_vertShader);
}
if (_fragShader)
{
glDeleteShader(_fragShader);
}
_vertShader = _fragShader = 0;
if (_program)
{
@ -436,7 +444,7 @@ bool GLProgram::compileShader(GLuint * shader, GLenum type, const GLchar* source
}
free(src);
abort();
return false;;
}
return (status == GL_TRUE);
}

View File

@ -206,11 +206,11 @@ void TextureCache::loadImage()
for (; pos < infoSize; pos++)
{
imageInfo = (*_imageInfoQueue)[pos];
if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename))
if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename) == 0)
break;
}
_imageInfoMutex.unlock();
if(infoSize == 0 || pos < infoSize)
if(infoSize == 0 || pos == infoSize)
generateImage = 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

@ -19,18 +19,9 @@
-- @param #cc.Texture2D texture2d
--------------------------------
-- overload function: initWithTexture(cc.Texture2D, rect_table, bool, vec2_table, size_table)
--
-- overload function: initWithTexture(cc.Texture2D, rect_table)
--
-- @function [parent=#SpriteFrame] initWithTexture
-- @function [parent=#SpriteFrame] getOffset
-- @param self
-- @param #cc.Texture2D texture2d
-- @param #rect_table rect
-- @param #bool bool
-- @param #vec2_table vec2
-- @param #size_table size
-- @return bool#bool ret (retunr value: bool)
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
-- @function [parent=#SpriteFrame] setRectInPixels
@ -77,30 +68,11 @@
-- @param self
-- @param #vec2_table vec2
--------------------------------
-- @function [parent=#SpriteFrame] getOffset
-- @param self
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
-- @function [parent=#SpriteFrame] isRotated
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
-- overload function: initWithTextureFilename(string, rect_table, bool, vec2_table, size_table)
--
-- overload function: initWithTextureFilename(string, rect_table)
--
-- @function [parent=#SpriteFrame] initWithTextureFilename
-- @param self
-- @param #string str
-- @param #rect_table rect
-- @param #bool bool
-- @param #vec2_table vec2
-- @param #size_table size
-- @return bool#bool ret (retunr value: bool)
--------------------------------
-- @function [parent=#SpriteFrame] setRect
-- @param self

View File

@ -18065,77 +18065,46 @@ int lua_cocos2dx_SpriteFrame_setTexture(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_SpriteFrame_initWithTexture(lua_State* tolua_S)
int lua_cocos2dx_SpriteFrame_getOffset(lua_State* tolua_S)
{
int argc = 0;
cocos2d::SpriteFrame* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.SpriteFrame",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::SpriteFrame*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_SpriteFrame_initWithTexture'", nullptr);
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_SpriteFrame_getOffset'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
do{
if (argc == 5) {
cocos2d::Texture2D* arg0;
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 2, "cc.Texture2D",&arg0);
if (!ok) { break; }
cocos2d::Rect arg1;
ok &= luaval_to_rect(tolua_S, 3, &arg1);
if (!ok) { break; }
bool arg2;
ok &= luaval_to_boolean(tolua_S, 4,&arg2);
if (!ok) { break; }
cocos2d::Vec2 arg3;
ok &= luaval_to_vec2(tolua_S, 5, &arg3);
if (!ok) { break; }
cocos2d::Size arg4;
ok &= luaval_to_size(tolua_S, 6, &arg4);
if (!ok) { break; }
bool ret = cobj->initWithTexture(arg0, arg1, arg2, arg3, arg4);
tolua_pushboolean(tolua_S,(bool)ret);
if (argc == 0)
{
if(!ok)
return 0;
const cocos2d::Vec2& ret = cobj->getOffset();
vec2_to_luaval(tolua_S, ret);
return 1;
}
}while(0);
ok = true;
do{
if (argc == 2) {
cocos2d::Texture2D* arg0;
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 2, "cc.Texture2D",&arg0);
if (!ok) { break; }
cocos2d::Rect arg1;
ok &= luaval_to_rect(tolua_S, 3, &arg1);
if (!ok) { break; }
bool ret = cobj->initWithTexture(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", "initWithTexture",argc, 2);
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getOffset",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_SpriteFrame_initWithTexture'.",&tolua_err);
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_SpriteFrame_getOffset'.",&tolua_err);
#endif
return 0;
@ -18546,50 +18515,6 @@ int lua_cocos2dx_SpriteFrame_setOffset(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_SpriteFrame_getOffset(lua_State* tolua_S)
{
int argc = 0;
cocos2d::SpriteFrame* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.SpriteFrame",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::SpriteFrame*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_SpriteFrame_getOffset'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
return 0;
const cocos2d::Vec2& ret = cobj->getOffset();
vec2_to_luaval(tolua_S, ret);
return 1;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getOffset",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_SpriteFrame_getOffset'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_SpriteFrame_isRotated(lua_State* tolua_S)
{
int argc = 0;
@ -18634,81 +18559,6 @@ int lua_cocos2dx_SpriteFrame_isRotated(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_SpriteFrame_initWithTextureFilename(lua_State* tolua_S)
{
int argc = 0;
cocos2d::SpriteFrame* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.SpriteFrame",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::SpriteFrame*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_SpriteFrame_initWithTextureFilename'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
do{
if (argc == 5) {
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0);
if (!ok) { break; }
cocos2d::Rect arg1;
ok &= luaval_to_rect(tolua_S, 3, &arg1);
if (!ok) { break; }
bool arg2;
ok &= luaval_to_boolean(tolua_S, 4,&arg2);
if (!ok) { break; }
cocos2d::Vec2 arg3;
ok &= luaval_to_vec2(tolua_S, 5, &arg3);
if (!ok) { break; }
cocos2d::Size arg4;
ok &= luaval_to_size(tolua_S, 6, &arg4);
if (!ok) { break; }
bool ret = cobj->initWithTextureFilename(arg0, arg1, arg2, arg3, arg4);
tolua_pushboolean(tolua_S,(bool)ret);
return 1;
}
}while(0);
ok = true;
do{
if (argc == 2) {
std::string arg0;
ok &= luaval_to_std_string(tolua_S, 2,&arg0);
if (!ok) { break; }
cocos2d::Rect arg1;
ok &= luaval_to_rect(tolua_S, 3, &arg1);
if (!ok) { break; }
bool ret = cobj->initWithTextureFilename(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", "initWithTextureFilename",argc, 2);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_SpriteFrame_initWithTextureFilename'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_SpriteFrame_setRect(lua_State* tolua_S)
{
int argc = 0;
@ -18984,7 +18834,7 @@ int lua_register_cocos2dx_SpriteFrame(lua_State* tolua_S)
tolua_function(tolua_S,"clone",lua_cocos2dx_SpriteFrame_clone);
tolua_function(tolua_S,"setRotated",lua_cocos2dx_SpriteFrame_setRotated);
tolua_function(tolua_S,"setTexture",lua_cocos2dx_SpriteFrame_setTexture);
tolua_function(tolua_S,"initWithTexture",lua_cocos2dx_SpriteFrame_initWithTexture);
tolua_function(tolua_S,"getOffset",lua_cocos2dx_SpriteFrame_getOffset);
tolua_function(tolua_S,"setRectInPixels",lua_cocos2dx_SpriteFrame_setRectInPixels);
tolua_function(tolua_S,"getTexture",lua_cocos2dx_SpriteFrame_getTexture);
tolua_function(tolua_S,"getRect",lua_cocos2dx_SpriteFrame_getRect);
@ -18994,9 +18844,7 @@ int lua_register_cocos2dx_SpriteFrame(lua_State* tolua_S)
tolua_function(tolua_S,"getOriginalSizeInPixels",lua_cocos2dx_SpriteFrame_getOriginalSizeInPixels);
tolua_function(tolua_S,"setOriginalSizeInPixels",lua_cocos2dx_SpriteFrame_setOriginalSizeInPixels);
tolua_function(tolua_S,"setOffset",lua_cocos2dx_SpriteFrame_setOffset);
tolua_function(tolua_S,"getOffset",lua_cocos2dx_SpriteFrame_getOffset);
tolua_function(tolua_S,"isRotated",lua_cocos2dx_SpriteFrame_isRotated);
tolua_function(tolua_S,"initWithTextureFilename",lua_cocos2dx_SpriteFrame_initWithTextureFilename);
tolua_function(tolua_S,"setRect",lua_cocos2dx_SpriteFrame_setRect);
tolua_function(tolua_S,"getOffsetInPixels",lua_cocos2dx_SpriteFrame_getOffsetInPixels);
tolua_function(tolua_S,"getOriginalSize",lua_cocos2dx_SpriteFrame_getOriginalSize);
@ -48159,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;
@ -48171,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

@ -1612,8 +1612,6 @@ int register_all_cocos2dx(lua_State* tolua_S);

View File

@ -255,27 +255,10 @@ int LuaStack::executeString(const char *codes)
int LuaStack::executeScriptFile(const char* filename)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
std::string code("require \"");
code.append(filename);
code.append("\"");
return executeString(code.c_str());
#else
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
++_callFromLua;
int nRet = luaL_dofile(_state, fullPath.c_str());
--_callFromLua;
CC_ASSERT(_callFromLua >= 0);
// lua_gc(_state, LUA_GCCOLLECT, 0);
if (nRet != 0)
{
CCLOG("[LUA ERROR] %s", lua_tostring(_state, -1));
lua_pop(_state, 1);
return nRet;
}
return 0;
#endif
}
int LuaStack::executeGlobalFunction(const char* functionName)

View File

@ -383,165 +383,183 @@ cc.LabelEffect =
GLOW = 3,
}
cc.KeyCodeKey =
{
"KEY_NONE",
"KEY_PAUSE",
"KEY_SCROLL_LOCK",
"KEY_PRINT",
"KEY_SYSREQ",
"KEY_BREAK",
"KEY_ESCAPE",
"KEY_BACKSPACE",
"KEY_TAB",
"KEY_BACK_TAB",
"KEY_RETURN",
"KEY_CAPS_LOCK",
"KEY_SHIFT",
"KEY_CTRL",
"KEY_ALT",
"KEY_MENU",
"KEY_HYPER",
"KEY_INSERT",
"KEY_HOME",
"KEY_PG_UP",
"KEY_DELETE",
"KEY_END",
"KEY_PG_DOWN",
"KEY_LEFT_ARROW",
"KEY_RIGHT_ARROW",
"KEY_UP_ARROW",
"KEY_DOWN_ARROW",
"KEY_NUM_LOCK",
"KEY_KP_PLUS",
"KEY_KP_MINUS",
"KEY_KP_MULTIPLY",
"KEY_KP_DIVIDE",
"KEY_KP_ENTER",
"KEY_KP_HOME",
"KEY_KP_UP",
"KEY_KP_PG_UP",
"KEY_KP_LEFT",
"KEY_KP_FIVE",
"KEY_KP_RIGHT",
"KEY_KP_END",
"KEY_KP_DOWN",
"KEY_KP_PG_DOWN",
"KEY_KP_INSERT",
"KEY_KP_DELETE",
"KEY_F1",
"KEY_F2",
"KEY_F3",
"KEY_F4",
"KEY_F5",
"KEY_F6",
"KEY_F7",
"KEY_F8",
"KEY_F9",
"KEY_F10",
"KEY_F11",
"KEY_F12",
"KEY_SPACE",
"KEY_EXCLAM",
"KEY_QUOTE",
"KEY_NUMBER",
"KEY_DOLLAR",
"KEY_PERCENT",
"KEY_CIRCUMFLEX",
"KEY_AMPERSAND",
"KEY_APOSTROPHE",
"KEY_LEFT_PARENTHESIS",
"KEY_RIGHT_PARENTHESIS",
"KEY_ASTERISK",
"KEY_PLUS",
"KEY_COMMA",
"KEY_MINUS",
"KEY_PERIOD",
"KEY_SLASH",
"KEY_0",
"KEY_1",
"KEY_2",
"KEY_3",
"KEY_4",
"KEY_5",
"KEY_6",
"KEY_7",
"KEY_8",
"KEY_9",
"KEY_COLON",
"KEY_SEMICOLON",
"KEY_LESS_THAN",
"KEY_EQUAL",
"KEY_GREATER_THAN",
"KEY_QUESTION",
"KEY_AT",
"KEY_CAPITAL_A",
"KEY_CAPITAL_B",
"KEY_CAPITAL_C",
"KEY_CAPITAL_D",
"KEY_CAPITAL_E",
"KEY_CAPITAL_F",
"KEY_CAPITAL_G",
"KEY_CAPITAL_H",
"KEY_CAPITAL_I",
"KEY_CAPITAL_J",
"KEY_CAPITAL_K",
"KEY_CAPITAL_L",
"KEY_CAPITAL_M",
"KEY_CAPITAL_N",
"KEY_CAPITAL_O",
"KEY_CAPITAL_P",
"KEY_CAPITAL_Q",
"KEY_CAPITAL_R",
"KEY_CAPITAL_S",
"KEY_CAPITAL_T",
"KEY_CAPITAL_U",
"KEY_CAPITAL_V",
"KEY_CAPITAL_W",
"KEY_CAPITAL_X",
"KEY_CAPITAL_Y",
"KEY_CAPITAL_Z",
"KEY_LEFT_BRACKET",
"KEY_BACK_SLASH",
"KEY_RIGHT_BRACKET",
"KEY_UNDERSCORE",
"KEY_GRAVE",
"KEY_A",
"KEY_B",
"KEY_C",
"KEY_D",
"KEY_E",
"KEY_F",
"KEY_G",
"KEY_H",
"KEY_I",
"KEY_J",
"KEY_K",
"KEY_L",
"KEY_M",
"KEY_N",
"KEY_O",
"KEY_P",
"KEY_Q",
"KEY_R",
"KEY_S",
"KEY_T",
"KEY_U",
"KEY_V",
"KEY_W",
"KEY_X",
"KEY_Y",
"KEY_Z",
"KEY_LEFT_BRACE",
"KEY_BAR",
"KEY_RIGHT_BRACE",
"KEY_TILDE",
"KEY_EURO",
"KEY_POUND",
"KEY_YEN",
"KEY_MIDDLE_DOT",
"KEY_SEARCH",
"KEY_DPAD_LEFT",
"KEY_DPAD_RIGHT",
"KEY_DPAD_UP",
"KEY_DPAD_DOWN",
"KEY_DPAD_CENTER",
"KEY_ENTER",
"KEY_PLAY",
}
cc.KeyCode =
{
KEY_NONE = 0,
KEY_PAUSE = 0x0013,
KEY_SCROLL_LOCK = 0x1014,
KEY_PRINT = 0x1061,
KEY_SYSREQ = 0x106A,
KEY_BREAK = 0x106B,
KEY_ESCAPE = 0x001B,
KEY_BACKSPACE = 0x0008,
KEY_TAB = 0x0009,
KEY_BACK_TAB = 0x0089,
KEY_RETURN = 0x000D,
KEY_CAPS_LOCK = 0x00E5,
KEY_SHIFT = 0x00E1,
KEY_CTRL = 0x00E3,
KEY_ALT = 0x00E9,
KEY_MENU = 0x1067,
KEY_HYPER = 0x10ED,
KEY_INSERT = 0x1063,
KEY_HOME = 0x1050,
KEY_PG_UP = 0x1055,
KEY_DELETE = 0x10FF,
KEY_END = 0x1057,
KEY_PG_DOWN = 0x1056,
KEY_LEFT_ARROW = 0x1051,
KEY_RIGHT_ARROW = 0x1053,
KEY_UP_ARROW = 0x1052,
KEY_DOWN_ARROW = 0x1054,
KEY_NUM_LOCK = 0x107F,
KEY_KP_PLUS = 0x10AB,
KEY_KP_MINUS = 0x10AD,
KEY_KP_MULTIPLY = 0x10AA,
KEY_KP_DIVIDE = 0x10AF,
KEY_KP_ENTER = 0x108D,
KEY_KP_HOME = 0x10B7,
KEY_KP_UP = 0x10B8,
KEY_KP_PG_UP = 0x10B9,
KEY_KP_LEFT = 0x10B4,
KEY_KP_FIVE = 0x10B5,
KEY_KP_RIGHT = 0x10B6,
KEY_KP_END = 0x10B1,
KEY_KP_DOWN = 0x10B2,
KEY_KP_PG_DOWN = 0x10B3,
KEY_KP_INSERT = 0x10B0,
KEY_KP_DELETE = 0x10AE,
KEY_F1 = 0x00BE,
KEY_F2 = 0x00BF,
KEY_F3 = 0x00C0,
KEY_F4 = 0x00C1,
KEY_F5 = 0x00C2,
KEY_F6 = 0x00C3,
KEY_F7 = 0x00C4,
KEY_F8 = 0x00C5,
KEY_F9 = 0x00C6,
KEY_F10 = 0x00C7,
KEY_F11 = 0x00C8,
KEY_F12 = 0x00C9,
KEY_SPACE = ' ',
KEY_EXCLAM = '!',
KEY_QUOTE = '"',
KEY_NUMBER = '#',
KEY_DOLLAR = '$',
KEY_PERCENT = '%',
KEY_CIRCUMFLEX = '^',
KEY_AMPERSAND = '&',
KEY_APOSTROPHE = '\'',
KEY_LEFT_PARENTHESIS = '(',
KEY_RIGHT_PARENTHESIS = ')',
KEY_ASTERISK = '*',
KEY_PLUS = '+',
KEY_COMMA = ',',
KEY_MINUS = '-',
KEY_PERIOD = '.',
KEY_SLASH = '/',
KEY_0 = '0',
KEY_1 = '1',
KEY_2 = '2',
KEY_3 = '3',
KEY_4 = '4',
KEY_5 = '5',
KEY_6 = '6',
KEY_7 = '7',
KEY_8 = '8',
KEY_9 = '9',
KEY_COLON = ':',
KEY_SEMICOLON = ';',
KEY_LESS_THAN = '<',
KEY_EQUAL = '=',
KEY_GREATER_THAN = '>',
KEY_QUESTION = '?',
KEY_AT = '@',
KEY_CAPITAL_A = 'A',
KEY_CAPITAL_B = 'B',
KEY_CAPITAL_C = 'C',
KEY_CAPITAL_D = 'D',
KEY_CAPITAL_E = 'E',
KEY_CAPITAL_F = 'F',
KEY_CAPITAL_G = 'G',
KEY_CAPITAL_H = 'H',
KEY_CAPITAL_I = 'I',
KEY_CAPITAL_J = 'J',
KEY_CAPITAL_K = 'K',
KEY_CAPITAL_L = 'L',
KEY_CAPITAL_M = 'M',
KEY_CAPITAL_N = 'N',
KEY_CAPITAL_O = 'O',
KEY_CAPITAL_P = 'P',
KEY_CAPITAL_Q = 'Q',
KEY_CAPITAL_R = 'R',
KEY_CAPITAL_S = 'S',
KEY_CAPITAL_T = 'T',
KEY_CAPITAL_U = 'U',
KEY_CAPITAL_V = 'V',
KEY_CAPITAL_W = 'W',
KEY_CAPITAL_X = 'X',
KEY_CAPITAL_Y = 'Y',
KEY_CAPITAL_Z = 'Z',
KEY_LEFT_BRACKET = '[',
KEY_BACK_SLASH = '\\',
KEY_RIGHT_BRACKET = ']',
KEY_UNDERSCORE = '_',
KEY_GRAVE = '`',
KEY_A = 'a',
KEY_B = 'b',
KEY_C = 'c',
KEY_D = 'd',
KEY_E = 'e',
KEY_F = 'f',
KEY_G = 'g',
KEY_H = 'h',
KEY_I = 'i',
KEY_J = 'j',
KEY_K = 'k',
KEY_L = 'l',
KEY_M = 'm',
KEY_N = 'n',
KEY_O = 'o',
KEY_P = 'p',
KEY_Q = 'q',
KEY_R = 'r',
KEY_S = 's',
KEY_T = 't',
KEY_U = 'u',
KEY_V = 'v',
KEY_W = 'w',
KEY_X = 'x',
KEY_Y = 'y',
KEY_Z = 'z',
KEY_LEFT_BRACE = '{',
KEY_BAR = '|',
KEY_RIGHT_BRACE = '}',
KEY_TILDE = '~',
KEY_EURO = 0x20AC,
KEY_POUND = 0x00A3,
KEY_YEN = 0x00A5,
KEY_MIDDLE_DOT = 0x0095,
KEY_SEARCH = 0xFFAA,
};
}
for k,v in ipairs(cc.KeyCodeKey) do
cc.KeyCode[v] = k - 1
end
cc.KeyCode.KEY_BACK = cc.KeyCode.KEY_ESCAPE

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

View File

@ -421,22 +421,16 @@ class SpriteBlur : public Sprite
{
public:
~SpriteBlur();
void setBlurSize(float f);
bool initWithTexture(Texture2D* texture, const Rect& rect);
void initGLProgram();
static SpriteBlur* create(const char *pszFileName);
void setBlurRadius(float radius);
void setBlurSampleNum(float num);
protected:
int _blurRadius;
Vec2 _pixelSize;
int _samplingRadius;
//gaussian = cons * exp( (dx*dx + dy*dy) * scale);
float _scale;
float _cons;
float _weightSum;
float _blurRadius;
float _blurSampleNum;
};
SpriteBlur::~SpriteBlur()
@ -472,14 +466,7 @@ bool SpriteBlur::initWithTexture(Texture2D* texture, const Rect& rect)
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
auto s = getTexture()->getContentSizeInPixels();
_pixelSize = Vec2(1/s.width, 1/s.height);
_samplingRadius = 0;
this->initGLProgram();
getGLProgramState()->setUniformVec2("onePixelSize", _pixelSize);
initGLProgram();
return true;
}
@ -495,43 +482,23 @@ void SpriteBlur::initGLProgram()
auto glProgramState = GLProgramState::getOrCreateWithGLProgram(program);
setGLProgramState(glProgramState);
auto size = getTexture()->getContentSizeInPixels();
getGLProgramState()->setUniformVec2("resolution", size);
getGLProgramState()->setUniformFloat("blurRadius", _blurRadius);
getGLProgramState()->setUniformFloat("sampleNum", 7.0f);
}
void SpriteBlur::setBlurSize(float f)
void SpriteBlur::setBlurRadius(float radius)
{
if(_blurRadius == (int)f)
return;
_blurRadius = (int)f;
_blurRadius = radius;
getGLProgramState()->setUniformFloat("blurRadius", _blurRadius);
}
_samplingRadius = _blurRadius;
if (_samplingRadius > 10)
void SpriteBlur::setBlurSampleNum(float num)
{
_samplingRadius = 10;
}
if (_blurRadius > 0)
{
float sigma = _blurRadius / 2.0f;
_scale = -0.5f / (sigma * sigma);
_cons = -1.0f * _scale / 3.141592f;
_weightSum = -_cons;
float weight;
int squareX;
for(int dx = 0; dx <= _samplingRadius; ++dx)
{
squareX = dx * dx;
weight = _cons * exp(squareX * _scale);
_weightSum += 2.0 * weight;
for (int dy = 1; dy <= _samplingRadius; ++dy)
{
weight = _cons * exp((squareX + dy * dy) * _scale);
_weightSum += 4.0 * weight;
}
}
}
log("_blurRadius:%d",_blurRadius);
getGLProgramState()->setUniformVec4("gaussianCoefficient", Vec4(_samplingRadius, _scale, _cons, _weightSum));
_blurSampleNum = num;
getGLProgramState()->setUniformFloat("sampleNum", _blurSampleNum);
}
// ShaderBlur
@ -551,22 +518,43 @@ std::string ShaderBlur::subtitle() const
return "Gaussian blur";
}
ControlSlider* ShaderBlur::createSliderCtl()
void ShaderBlur::createSliderCtls()
{
auto screenSize = Director::getInstance()->getWinSize();
{
ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
slider->setAnchorPoint(Vec2(0.5f, 1.0f));
slider->setMinimumValue(0.0f); // Sets the min value of range
slider->setMaximumValue(25.0f); // Sets the max value of range
slider->setPosition(Vec2(screenSize.width / 2.0f, screenSize.height / 3.0f));
// When the value of the slider will change, the given selector will be call
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::sliderAction), Control::EventType::VALUE_CHANGED);
slider->setMinimumValue(0.0f);
slider->setMaximumValue(25.0f);
slider->setScale(0.6f);
slider->setPosition(Vec2(screenSize.width / 4.0f, screenSize.height / 3.0f));
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::onRadiusChanged), Control::EventType::VALUE_CHANGED);
slider->setValue(2.0f);
addChild(slider);
_sliderRadiusCtl = slider;
return slider;
auto label = Label::createWithTTF("Blur Radius", "fonts/arial.ttf", 12.0f);
addChild(label);
label->setPosition(Vec2(screenSize.width / 4.0f, screenSize.height / 3.0f - 24.0f));
}
{
ControlSlider *slider = ControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png" ,"extensions/sliderThumb.png");
slider->setAnchorPoint(Vec2(0.5f, 1.0f));
slider->setMinimumValue(0.0f);
slider->setMaximumValue(11.0f);
slider->setScale(0.6f);
slider->setPosition(Vec2(screenSize.width * 3 / 4.0f, screenSize.height / 3.0f));
slider->addTargetWithActionForControlEvents(this, cccontrol_selector(ShaderBlur::onSampleNumChanged), Control::EventType::VALUE_CHANGED);
slider->setValue(7.0f);
addChild(slider);
_sliderNumCtrl = slider;
auto label = Label::createWithTTF("Blur Sample Num", "fonts/arial.ttf", 12.0f);
addChild(label);
label->setPosition(Vec2(screenSize.width * 3 / 4.0f, screenSize.height / 3.0f - 24.0f));
}
}
@ -575,9 +563,7 @@ bool ShaderBlur::init()
if( ShaderTestDemo::init() )
{
_blurSprite = SpriteBlur::create("Images/grossini.png");
auto sprite = Sprite::create("Images/grossini.png");
auto s = Director::getInstance()->getWinSize();
_blurSprite->setPosition(Vec2(s.width/3, s.height/2));
sprite->setPosition(Vec2(2*s.width/3, s.height/2));
@ -585,19 +571,24 @@ bool ShaderBlur::init()
addChild(_blurSprite);
addChild(sprite);
_sliderCtl = createSliderCtl();
createSliderCtls();
addChild(_sliderCtl);
return true;
}
return false;
}
void ShaderBlur::sliderAction(Ref* sender, Control::EventType controlEvent)
void ShaderBlur::onRadiusChanged(Ref* sender, Control::EventType)
{
ControlSlider* slider = (ControlSlider*)sender;
_blurSprite->setBlurSize(slider->getValue());
_blurSprite->setBlurRadius(slider->getValue());
}
void ShaderBlur::onSampleNumChanged(Ref* sender, Control::EventType)
{
ControlSlider* slider = (ControlSlider*)sender;
_blurSprite->setBlurSampleNum(slider->getValue());
}
// ShaderRetroEffect

View File

@ -92,11 +92,14 @@ public:
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual bool init();
ControlSlider* createSliderCtl();
void sliderAction(Ref* sender, Control::EventType controlEvent);
void createSliderCtls();
void onRadiusChanged(Ref* sender, Control::EventType controlEvent);
void onSampleNumChanged(Ref* sender, Control::EventType controlEvent);
protected:
SpriteBlur* _blurSprite;
ControlSlider* _sliderCtl;
ControlSlider* _sliderRadiusCtl;
ControlSlider* _sliderNumCtrl;
};
class ShaderRetroEffect : public ShaderTestDemo

View File

@ -249,80 +249,42 @@ class EffectBlur : public Effect
{
public:
CREATE_FUNC(EffectBlur);
virtual void setTarget(EffectSprite *sprite) override;
void setGaussian(float value);
void setCustomUniforms();
void setBlurSize(float f);
void setBlurRadius(float radius);
void setBlurSampleNum(float num);
protected:
bool init(float blurSize=3.0);
bool init(float blurRadius = 10.0f, float sampleNum = 5.0f);
int _blurRadius;
Vec2 _pixelSize;
int _samplingRadius;
float _scale;
float _cons;
float _weightSum;
float _blurRadius;
float _blurSampleNum;
};
void EffectBlur::setTarget(EffectSprite *sprite)
{
Size s = sprite->getTexture()->getContentSizeInPixels();
_pixelSize = Vec2(1/s.width, 1/s.height);
_glprogramstate->setUniformVec2("onePixelSize", _pixelSize);
Size size = sprite->getTexture()->getContentSizeInPixels();
_glprogramstate->setUniformVec2("resolution", size);
_glprogramstate->setUniformFloat("blurRadius", _blurRadius);
_glprogramstate->setUniformFloat("sampleNum", _blurSampleNum);
}
bool EffectBlur::init(float blurSize)
bool EffectBlur::init(float blurRadius, float sampleNum)
{
initGLProgramState("Shaders/example_Blur.fsh");
auto s = Size(100,100);
_blurRadius = blurRadius;
_blurSampleNum = sampleNum;
_blurRadius = 0;
_pixelSize = Vec2(1/s.width, 1/s.height);
_samplingRadius = 0;
setBlurSize(blurSize);
_glprogramstate->setUniformVec2("onePixelSize", _pixelSize);
_glprogramstate->setUniformVec4("gaussianCoefficient", Vec4(_samplingRadius, _scale, _cons, _weightSum));
return true;
}
void EffectBlur::setBlurSize(float f)
void EffectBlur::setBlurRadius(float radius)
{
if(_blurRadius == (int)f)
return;
_blurRadius = (int)f;
_blurRadius = radius;
}
_samplingRadius = _blurRadius;
if (_samplingRadius > 10)
void EffectBlur::setBlurSampleNum(float num)
{
_samplingRadius = 10;
}
if (_blurRadius > 0)
{
float sigma = _blurRadius / 2.0f;
_scale = -0.5f / (sigma * sigma);
_cons = -1.0f * _scale / 3.141592f;
_weightSum = -_cons;
float weight;
int squareX;
for(int dx = 0; dx <= _samplingRadius; ++dx)
{
squareX = dx * dx;
weight = _cons * exp(squareX * _scale);
_weightSum += 2.0 * weight;
for (int dy = 1; dy <= _samplingRadius; ++dy)
{
weight = _cons * exp((squareX + dy * dy) * _scale);
_weightSum += 4.0 * weight;
}
}
}
_blurSampleNum = num;
}
// Outline

View File

@ -1986,10 +1986,10 @@ void TextureMemoryAlloc::updateImage(cocos2d::Ref *sender)
file = "Images/fire_rgba8888.pvr";
break;
case 2:
file = "Images/grossini_prv_rgba8888.pvr";
file = "Images/grossini_pvr_rgba8888.pvr";
break;
case 3:
file = "Images/grossini_prv_rgba4444.pvr";
file = "Images/grossini_pvr_rgba4444.pvr";
break;
case 4:
file = "Images/test_image_a8.pvr";

View File

@ -1,5 +1,3 @@
// Shader taken from: http://webglsamples.googlecode.com/hg/electricflower/electricflower.html
#ifdef GL_ES
precision mediump float;
#endif
@ -7,50 +5,42 @@ precision mediump float;
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform vec4 gaussianCoefficient;
uniform vec2 onePixelSize;
uniform vec2 resolution;
uniform float blurRadius;
uniform float sampleNum;
void main() {
if(gaussianCoefficient.x > 0.0) {
vec4 sum = vec4(0.0);
vec2 offset;
float weight;
float squareX;
vec3 blur(vec2);
for(float dx = 0.0; dx <= gaussianCoefficient.x; dx += 1.0) {
squareX = dx * dx;
weight = gaussianCoefficient.z * exp(squareX * gaussianCoefficient.y);
offset.x = -dx * onePixelSize.x;
offset.y = 0.0;
sum += texture2D(CC_Texture0, v_texCoord + offset) * weight;
offset.x = dx * onePixelSize.x;
sum += texture2D(CC_Texture0, v_texCoord + offset) * weight;
for(float dy = 1.0; dy <= gaussianCoefficient.x; dy += 1.0) {
weight = gaussianCoefficient.z * exp((squareX + dy * dy) * gaussianCoefficient.y);
offset.x = -dx * onePixelSize.x;
offset.y = -dy * onePixelSize.y;
sum += texture2D(CC_Texture0, v_texCoord + offset) * weight;
offset.y = dy * onePixelSize.y;
sum += texture2D(CC_Texture0, v_texCoord + offset) * weight;
offset.x = dx * onePixelSize.x;
sum += texture2D(CC_Texture0, v_texCoord + offset) * weight;
offset.y = -dy * onePixelSize.y;
sum += texture2D(CC_Texture0, v_texCoord + offset) * weight;
void main(void)
{
vec3 col = blur(v_texCoord);
gl_FragColor = vec4(col, 1.0) * v_fragmentColor;
}
}
sum -= texture2D(CC_Texture0, v_texCoord) * gaussianCoefficient.z;
sum /= gaussianCoefficient.w;
gl_FragColor = sum * v_fragmentColor;
}
else {
gl_FragColor = texture2D(CC_Texture0, v_texCoord) * v_fragmentColor;
vec3 blur(vec2 p)
{
if (blurRadius > 0.0 && sampleNum > 1.0)
{
vec3 col = vec3(0);
vec2 unit = 1.0 / resolution.xy;
float r = blurRadius;
float sampleStep = r / sampleNum;
float count = 0.0;
for(float x = -r; x < r; x += sampleStep)
{
for(float y = -r; y < r; y += sampleStep)
{
float weight = (r - abs(x)) * (r - abs(y));
col += texture2D(CC_Texture0, p + vec2(x * unit.x, y * unit.y)).rgb * weight;
count += weight;
}
}
return col / count;
}
return texture2D(CC_Texture0, p).rgb;
}

View File

@ -16,7 +16,7 @@ local function KeypadMainLayer()
local function onKeyReleased(keyCode, event)
local label = event:getCurrentTarget()
if keyCode == cc.KeyCode.KEY_BACKSPACE then
if keyCode == cc.KeyCode.KEY_BACK then
label:setString("BACK clicked!")
elseif keyCode == cc.KeyCode.KEY_MENU then
label:setString("MENU clicked!")

View File

@ -665,13 +665,13 @@ function LabelKeyboardEventTest:onEnter()
self:addChild(statusLabel)
local function onKeyPressed(keyCode, event)
local buf = string.format("Key %s was pressed!",string.char(keyCode))
local buf = string.format("Key %d was pressed!",keyCode)
local label = event:getCurrentTarget()
label:setString(buf)
end
local function onKeyReleased(keyCode, event)
local buf = string.format("Key %s was released!",string.char(keyCode))
local buf = string.format("Key %d was released!",keyCode)
local label = event:getCurrentTarget()
label:setString(buf)
end

View File

@ -1263,19 +1263,18 @@ local function TextureMemoryAlloc()
end
cc.Director:getInstance():getTextureCache():removeUnusedTextures()
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
local file = ""
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
if cc.PLATFORM_OS_ANDROID == targetPlatform then
if targetPlatform == cc.PLATFORM_OS_ANDROID then
if tag == 0 then
file = "Images/background.png"
elseif tag == 1 then
file = "Images/fire_rgba8888.pvr"
elseif tag == 2 then
file = "Images/grossini_prv_rgba8888.pvr"
file = "Images/grossini_pvr_rgba8888.pvr"
elseif tag == 3 then
file = "Images/grossini_prv_rgba4444.pvr"
file = "Images/grossini_pvr_rgba4444.pvr"
elseif tag == 4 then
file = "Images/test_image_a8.pvr"
end

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

View File

@ -79,7 +79,7 @@ def main():
print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered'
return(0)
data = {"state":"pending", "target_url":target_url}
data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Wait available build machine..."}
access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token}

View File

@ -90,7 +90,7 @@ def main():
print 'skip build for pull request #' + str(pr_num)
return(0)
data = {"state":"pending", "target_url":target_url}
data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Waiting available build machine..."}
access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token}

View File

@ -18,7 +18,7 @@ statuses_url = payload['statuses_url']
J = Jenkins(os.environ['JENKINS_URL'])
target_url = os.environ['BUILD_URL']
build_number = int(os.environ['BUILD_NUMBER'])
data = {"state":"pending", "target_url":target_url}
data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Build finished!"}
access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token}
@ -26,9 +26,10 @@ result = J[os.environ['JOB_NAME']].get_build(build_number).get_status()
if(result == STATUS_SUCCESS):
data['state'] = "success"
data['description'] = "Build successfully!"
else:
data['state'] = "failure"
data['description'] = "Build failed!"
http_proxy = ''
if(os.environ.has_key('HTTP_PROXY')):
http_proxy = os.environ['HTTP_PROXY']

View File

@ -104,7 +104,7 @@ def main():
set_description(pr_desc, target_url)
data = {"state":"pending", "target_url":target_url}
data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Build started..."}
access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token}