From ad8638d9765d2a07a0adc7c1a5522d7bec8812ec Mon Sep 17 00:00:00 2001 From: samuele3 Date: Fri, 6 Dec 2013 14:16:33 +0800 Subject: [PATCH 01/35] issue #3353:Lua gc mechanism will make the extended attributes of lua userdata disapper --- cocos/scripting/lua/bindings/tolua_fix.c | 7 +- external/lua/tolua/tolua++.h | 6 + external/lua/tolua/tolua_map.c | 5 + external/lua/tolua/tolua_push.c | 170 ++++++++++++++--------- tools/tolua/cocos2dx.ini | 7 +- 5 files changed, 126 insertions(+), 69 deletions(-) diff --git a/cocos/scripting/lua/bindings/tolua_fix.c b/cocos/scripting/lua/bindings/tolua_fix.c index f03dd59b5f..2aabde0980 100644 --- a/cocos/scripting/lua/bindings/tolua_fix.c +++ b/cocos/scripting/lua/bindings/tolua_fix.c @@ -53,7 +53,8 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, //printf("[LUA] push CCObject OK - refid: %d, ptr: %x, type: %s\n", *p_refid, (int)ptr, type); } - tolua_pushusertype(L, ptr, type); + tolua_pushusertype_and_addtoroot(L, ptr, type); + return 0; } @@ -118,6 +119,10 @@ TOLUA_API int toluafix_remove_ccobject_by_refid(lua_State* L, int refid) lua_pushstring(L, "tolua_ubox"); /* stack: mt key */ lua_rawget(L, LUA_REGISTRYINDEX); /* stack: mt ubox */ }; + + + // cleanup root + tolua_remove_value_from_root(L, ptr); lua_pushlightuserdata(L, ptr); /* stack: mt ubox ptr */ lua_rawget(L,-2); /* stack: mt ubox ud */ diff --git a/external/lua/tolua/tolua++.h b/external/lua/tolua/tolua++.h index 6183210ba3..173aec08ad 100644 --- a/external/lua/tolua/tolua++.h +++ b/external/lua/tolua/tolua++.h @@ -41,6 +41,8 @@ extern "C" { #define TOLUA_PROTECTED_DESTRUCTOR #define TOLUA_PROPERTY_TYPE(p) +#define TOLUA_VALUE_ROOT "tolua_value_root" + typedef int lua_Object; #include "lua.h" @@ -117,6 +119,10 @@ TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const cha TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v); TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type); TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type); + +TOLUA_API void tolua_pushusertype_and_addtoroot (lua_State* L, void* value, const char* type); +TOLUA_API void tolua_add_value_to_root (lua_State* L,void* value); +TOLUA_API void tolua_remove_value_from_root (lua_State* L, void* value); TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def); TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def); diff --git a/external/lua/tolua/tolua_map.c b/external/lua/tolua/tolua_map.c index 6b6c047e15..5528ef6cbe 100644 --- a/external/lua/tolua/tolua_map.c +++ b/external/lua/tolua/tolua_map.c @@ -304,6 +304,11 @@ TOLUA_API void tolua_open (lua_State* L) lua_pushstring(L,"tolua_opened"); lua_pushboolean(L,1); lua_rawset(L,LUA_REGISTRYINDEX); + + // create value root table + lua_pushstring(L, TOLUA_VALUE_ROOT); + lua_newtable(L); + lua_rawset(L, LUA_REGISTRYINDEX); #ifndef LUA_VERSION_NUM /* only prior to lua 5.1 */ /* create peer object table */ diff --git a/external/lua/tolua/tolua_push.c b/external/lua/tolua/tolua_push.c index dbfdb193b6..8d9ee7b33a 100644 --- a/external/lua/tolua/tolua_push.c +++ b/external/lua/tolua/tolua_push.c @@ -17,6 +17,82 @@ #include +void tolua_pushusertype_internal (lua_State* L, void* value, const char* type, int addToRoot) +{ + if (value == NULL) + lua_pushnil(L); + else + { + luaL_getmetatable(L, type); /* stack: mt */ + if (lua_isnil(L, -1)) { /* NOT FOUND metatable */ + lua_pop(L, 1); + return; + } + lua_pushstring(L,"tolua_ubox"); + lua_rawget(L,-2); /* stack: mt ubox */ + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + lua_pushstring(L, "tolua_ubox"); + lua_rawget(L, LUA_REGISTRYINDEX); + }; + + lua_pushlightuserdata(L,value); /* stack: mt ubox key */ + lua_rawget(L,-2); /* stack: mt ubox ubox[value] */ + + if (lua_isnil(L,-1)) + { + lua_pop(L,1); /* stack: mt ubox */ + lua_pushlightuserdata(L,value); + *(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox value newud */ + lua_pushvalue(L,-1); /* stack: mt ubox value newud newud */ + lua_insert(L,-4); /* stack: mt newud ubox value newud */ + lua_rawset(L,-3); /* ubox[value] = newud, stack: mt newud ubox */ + lua_pop(L,1); /* stack: mt newud */ + /*luaL_getmetatable(L,type);*/ + lua_pushvalue(L, -2); /* stack: mt newud mt */ + lua_setmetatable(L,-2); /* update mt, stack: mt newud */ + +#ifdef LUA_VERSION_NUM + lua_pushvalue(L, TOLUA_NOPEER); /* stack: mt newud peer */ + lua_setfenv(L, -2); /* stack: mt newud */ +#endif + } + else + { + /* check the need of updating the metatable to a more specialized class */ + lua_insert(L,-2); /* stack: mt ubox[u] ubox */ + lua_pop(L,1); /* stack: mt ubox[u] */ + lua_pushstring(L,"tolua_super"); + lua_rawget(L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */ + lua_getmetatable(L,-2); /* stack: mt ubox[u] super mt */ + lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] */ + if (lua_istable(L,-1)) + { + lua_pushstring(L,type); /* stack: mt ubox[u] super super[mt] type */ + lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] flag */ + if (lua_toboolean(L,-1) == 1) /* if true */ + { + lua_pop(L,3); /* mt ubox[u]*/ + lua_remove(L, -2); + return; + } + } + /* type represents a more specilized type */ + /*luaL_getmetatable(L,type); // stack: mt ubox[u] super super[mt] flag mt */ + lua_pushvalue(L, -5); /* stack: mt ubox[u] super super[mt] flag mt */ + lua_setmetatable(L,-5); /* stack: mt ubox[u] super super[mt] flag */ + lua_pop(L,3); /* stack: mt ubox[u] */ + } + lua_remove(L, -2); /* stack: ubox[u]*/ + + if (0 != addToRoot) + { + lua_pushvalue(L, -1); + tolua_add_value_to_root(L, value); + } + } +} + TOLUA_API void tolua_pushvalue (lua_State* L, int lo) { lua_pushvalue(L,lo); @@ -50,72 +126,12 @@ TOLUA_API void tolua_pushuserdata (lua_State* L, void* value) TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type) { - if (value == NULL) - lua_pushnil(L); - else - { - luaL_getmetatable(L, type); /* stack: mt */ - if (lua_isnil(L, -1)) { /* NOT FOUND metatable */ - lua_pop(L, 1); - return; - } - lua_pushstring(L,"tolua_ubox"); - lua_rawget(L,-2); /* stack: mt ubox */ - if (lua_isnil(L, -1)) { - lua_pop(L, 1); - lua_pushstring(L, "tolua_ubox"); - lua_rawget(L, LUA_REGISTRYINDEX); - }; - - lua_pushlightuserdata(L,value); /* stack: mt ubox key */ - lua_rawget(L,-2); /* stack: mt ubox ubox[value] */ - - if (lua_isnil(L,-1)) - { - lua_pop(L,1); /* stack: mt ubox */ - lua_pushlightuserdata(L,value); - *(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox value newud */ - lua_pushvalue(L,-1); /* stack: mt ubox value newud newud */ - lua_insert(L,-4); /* stack: mt newud ubox value newud */ - lua_rawset(L,-3); /* ubox[value] = newud, stack: mt newud ubox */ - lua_pop(L,1); /* stack: mt newud */ - /*luaL_getmetatable(L,type);*/ - lua_pushvalue(L, -2); /* stack: mt newud mt */ - lua_setmetatable(L,-2); /* update mt, stack: mt newud */ + tolua_pushusertype_internal(L, value, type, 0); +} -#ifdef LUA_VERSION_NUM - lua_pushvalue(L, TOLUA_NOPEER); - lua_setfenv(L, -2); -#endif - } - else - { - /* check the need of updating the metatable to a more specialized class */ - lua_insert(L,-2); /* stack: mt ubox[u] ubox */ - lua_pop(L,1); /* stack: mt ubox[u] */ - lua_pushstring(L,"tolua_super"); - lua_rawget(L,LUA_REGISTRYINDEX); /* stack: mt ubox[u] super */ - lua_getmetatable(L,-2); /* stack: mt ubox[u] super mt */ - lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] */ - if (lua_istable(L,-1)) - { - lua_pushstring(L,type); /* stack: mt ubox[u] super super[mt] type */ - lua_rawget(L,-2); /* stack: mt ubox[u] super super[mt] flag */ - if (lua_toboolean(L,-1) == 1) /* if true */ - { - lua_pop(L,3); /* mt ubox[u]*/ - lua_remove(L, -2); - return; - } - } - /* type represents a more specilized type */ - /*luaL_getmetatable(L,type); // stack: mt ubox[u] super super[mt] flag mt */ - lua_pushvalue(L, -5); /* stack: mt ubox[u] super super[mt] flag mt */ - lua_setmetatable(L,-5); /* stack: mt ubox[u] super super[mt] flag */ - lua_pop(L,3); /* stack: mt ubox[u] */ - } - lua_remove(L, -2); /* stack: ubox[u]*/ - } +TOLUA_API void tolua_pushusertype_and_addtoroot (lua_State* L, void* value, const char* type) +{ + tolua_pushusertype_internal(L, value, type, 1); } TOLUA_API void tolua_pushusertype_and_takeownership (lua_State* L, void* value, const char* type) @@ -124,6 +140,30 @@ TOLUA_API void tolua_pushusertype_and_takeownership (lua_State* L, void* value, tolua_register_gc(L,lua_gettop(L)); } +TOLUA_API void tolua_add_value_to_root(lua_State* L, void* ptr) +{ + + lua_pushstring(L, TOLUA_VALUE_ROOT); + lua_rawget(L, LUA_REGISTRYINDEX); /* stack: value root */ + lua_insert(L, -2); /* stack: root value */ + lua_pushlightuserdata(L, ptr); /* stack: root value ptr */ + lua_insert(L, -2); /* stack: root ptr value */ + lua_rawset(L, -3); /* root[ptr] = value, stack: root */ + lua_pop(L, 1); /* stack: - */ +} + + +TOLUA_API void tolua_remove_value_from_root (lua_State* L, void* ptr) +{ + lua_pushstring(L, TOLUA_VALUE_ROOT); + lua_rawget(L, LUA_REGISTRYINDEX); /* stack: root */ + lua_pushlightuserdata(L, ptr); /* stack: root ptr */ + + lua_pushnil(L); /* stack: root ptr nil */ + lua_rawset(L, -3); /* root[ptr] = nil, stack: root */ + lua_pop(L, 1); +} + TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v) { lua_pushnumber(L,index); diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 36a6a98ed9..7f09c7a231 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image +classes = Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image DisplayLinkDirector # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -107,7 +107,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS UserDefault::[getInstance (s|g)etDataForKey], Label::[getLettersInfo], EGLViewProtocol::[setTouchDelegate], - EGLView::[end swapBuffers] + EGLView::[end swapBuffers], + DisplayLinkDirector::[mainLoop setAnimationInterval startAnimation stopAnimation] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection], @@ -138,7 +139,7 @@ base_classes_to_skip = Clonable # classes that create no constructor # Set is special and we will use a hand-written constructor -abstract_classes = Action FiniteTimeAction ActionInterval ActionEase EaseRateAction EaseElastic EaseBounce ActionInstant GridAction Grid3DAction TiledGrid3DAction Director SpriteFrameCache TransitionEaseScene Set SimpleAudioEngine FileUtils Application ClippingNode Label EGLViewProtocol EGLView +abstract_classes = Action FiniteTimeAction ActionInterval ActionEase EaseRateAction EaseElastic EaseBounce ActionInstant GridAction Grid3DAction TiledGrid3DAction Director SpriteFrameCache TransitionEaseScene Set SimpleAudioEngine FileUtils Application ClippingNode Label EGLViewProtocol EGLView DisplayLinkDirector # Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. script_control_cpp = no From 69f1834e61c16686dfd979acd088f14e3d7246fd Mon Sep 17 00:00:00 2001 From: boyu0 Date: Mon, 23 Dec 2013 14:30:43 +0800 Subject: [PATCH 02/35] issue #2771: fix warning log and fix typo. --- cocos/physics/CCPhysicsBody.cpp | 4 ++-- samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cocos/physics/CCPhysicsBody.cpp b/cocos/physics/CCPhysicsBody.cpp index bd0acd3e57..8b9451f873 100644 --- a/cocos/physics/CCPhysicsBody.cpp +++ b/cocos/physics/CCPhysicsBody.cpp @@ -555,7 +555,7 @@ void PhysicsBody::setVelocity(const Point& velocity) { if (!_dynamic) { - CCLOG("physics warning: your cann't set velocity for a static body."); + CCLOG("physics warning: your can't set velocity for a static body."); return; } @@ -581,7 +581,7 @@ void PhysicsBody::setAngularVelocity(float velocity) { if (!_dynamic) { - CCLOG("physics warning: your cann't set angular velocity for a static body."); + CCLOG("physics warning: your can't set angular velocity for a static body."); return; } diff --git a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp index 7697a53ab8..1aef4a2a94 100644 --- a/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -396,7 +396,6 @@ void PhysicsDemo::onTouchMoved(Touch* touch, Event* event) if (it != _mouses.end()) { - it->second->getPhysicsBody()->setVelocity((touch->getLocation() - it->second->getPosition()) * 60.0f); it->second->setPosition(touch->getLocation()); } } From b7c0d7a9e8bf407b97ca620574f7bdb6f3cf42b4 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 14:59:44 +0800 Subject: [PATCH 03/35] 1. remove redundant code in NewRenderTexture 2. rename protected beginWithClear to _beginWithClear --- cocos/2d/CCRenderTexture.cpp | 8 ++++---- cocos/2d/CCRenderTexture.h | 2 +- cocos/2d/renderer/CCNewRenderTexture.cpp | 17 +---------------- cocos/2d/renderer/CCNewRenderTexture.h | 8 ++------ 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index d3d7b305a2..d63ecf2925 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -339,20 +339,20 @@ void RenderTexture::begin() void RenderTexture::beginWithClear(float r, float g, float b, float a) { - beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT); + _beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT); } void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue) { - beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + _beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); } void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue) { - beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + _beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); } -void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) +void RenderTexture::_beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { this->begin(); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 43246aa184..17a338d323 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -164,7 +164,7 @@ public: bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format, GLuint depthStencilFormat); protected: - virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); + virtual void _beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); GLuint _FBO; GLuint _depthRenderBufffer; diff --git a/cocos/2d/renderer/CCNewRenderTexture.cpp b/cocos/2d/renderer/CCNewRenderTexture.cpp index bd61970523..be8b7bc2d2 100644 --- a/cocos/2d/renderer/CCNewRenderTexture.cpp +++ b/cocos/2d/renderer/CCNewRenderTexture.cpp @@ -98,22 +98,7 @@ void NewRenderTexture::draw() } } -void NewRenderTexture::beginWithClear(float r, float g, float b, float a) -{ - beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT); -} - -void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue) -{ - beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); -} - -void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue) -{ - beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); -} - -void NewRenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) +void NewRenderTexture::_beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { setClearColor(Color4F(r, g, b, a)); diff --git a/cocos/2d/renderer/CCNewRenderTexture.h b/cocos/2d/renderer/CCNewRenderTexture.h index 90bf6ce311..65e6694785 100644 --- a/cocos/2d/renderer/CCNewRenderTexture.h +++ b/cocos/2d/renderer/CCNewRenderTexture.h @@ -36,17 +36,13 @@ public: static NewRenderTexture* create(int w, int h, Texture2D::PixelFormat eFormat); static NewRenderTexture* create(int w, int h); - void beginWithClear(float r, float g, float b, float a); - void beginWithClear(float r, float g, float b, float a, float depthValue); - void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue); - void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); - virtual void begin() override; virtual void end() override; virtual void draw() override; void clearDepth(float depthValue); - +protected: + virtual void _beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) override; protected: NewRenderTexture(); virtual ~NewRenderTexture(); From fad585fbefe8a1e28897d0309177a4cd18ed132d Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 15:59:47 +0800 Subject: [PATCH 04/35] move rendering callback to RenderTexture --- cocos/2d/CCRenderTexture.cpp | 120 +++++++++++++++++++++++ cocos/2d/CCRenderTexture.h | 9 ++ cocos/2d/renderer/CCNewRenderTexture.cpp | 120 ----------------------- cocos/2d/renderer/CCNewRenderTexture.h | 10 -- 4 files changed, 129 insertions(+), 130 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index d63ecf2925..f031f06093 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -625,4 +625,124 @@ Image* RenderTexture::newImage(bool fliimage) return image; } +void RenderTexture::onBegin() +{ + // + kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix); + kmGLMatrixMode(KM_GL_PROJECTION); + kmGLLoadMatrix(&_projectionMatrix); + + kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix); + kmGLMatrixMode(KM_GL_MODELVIEW); + kmGLLoadMatrix(&_transformMatrix); + + Director *director = Director::getInstance(); + director->setProjection(director->getProjection()); + + const Size& texSize = _texture->getContentSizeInPixels(); + + // Calculate the adjustment ratios based on the old and new projections + Size size = director->getWinSizeInPixels(); + float widthRatio = size.width / texSize.width; + float heightRatio = size.height / texSize.height; + + // Adjust the orthographic projection and viewport + glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height); + + + kmMat4 orthoMatrix; + kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio, + (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 ); + kmGLMultMatrix(&orthoMatrix); + + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); + glBindFramebuffer(GL_FRAMEBUFFER, _FBO); + + //TODO move this to configration, so we don't check it every time + /* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers. + */ + if (Configuration::getInstance()->checkForGLExtension("GL_QCOM")) + { + // -- bind a temporary texture so we can clear the render buffer without losing our texture + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0); + CHECK_GL_ERROR_DEBUG(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0); + } +} + +void RenderTexture::onEnd() +{ + Director *director = Director::getInstance(); + + glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); + + // restore viewport + director->setViewport(); + + // + kmGLMatrixMode(KM_GL_PROJECTION); + kmGLLoadMatrix(&_oldProjMatrix); + + kmGLMatrixMode(KM_GL_MODELVIEW); + kmGLLoadMatrix(&_oldTransMatrix); +} + +void RenderTexture::onClear() +{ + // save clear color + GLfloat oldClearColor[4] = {0.0f}; + GLfloat oldDepthClearValue = 0.0f; + GLint oldStencilClearValue = 0; + + // backup and set + if (_clearFlags & GL_COLOR_BUFFER_BIT) + { + glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor); + glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); + } + + if (_clearFlags & GL_DEPTH_BUFFER_BIT) + { + glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue); + glClearDepth(_clearDepth); + } + + if (_clearFlags & GL_STENCIL_BUFFER_BIT) + { + glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue); + glClearStencil(_clearStencil); + } + + // clear + glClear(_clearFlags); + + // restore + if (_clearFlags & GL_COLOR_BUFFER_BIT) + { + glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]); + } + if (_clearFlags & GL_DEPTH_BUFFER_BIT) + { + glClearDepth(oldDepthClearValue); + } + if (_clearFlags & GL_STENCIL_BUFFER_BIT) + { + glClearStencil(oldStencilClearValue); + } +} + +void RenderTexture::onClearDepth() +{ + //! save old depth value + GLfloat depthClearValue; + glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue); + + glClearDepth(_clearDepth); + glClear(GL_DEPTH_BUFFER_BIT); + + // restore clear color + glClearDepth(depthClearValue); +} + NS_CC_END diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 17a338d323..ac39dade22 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -187,7 +187,16 @@ protected: - [[renderTexture sprite] setBlendFunc:(BlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; */ Sprite* _sprite; +protected: + //renderer caches and callbacks + void onBegin(); + void onEnd(); + void onClear(); + void onClearDepth(); + + kmMat4 _oldTransMatrix, _oldProjMatrix; + kmMat4 _transformMatrix, _projectionMatrix; private: CC_DISALLOW_COPY_AND_ASSIGN(RenderTexture); diff --git a/cocos/2d/renderer/CCNewRenderTexture.cpp b/cocos/2d/renderer/CCNewRenderTexture.cpp index be8b7bc2d2..3d6c950668 100644 --- a/cocos/2d/renderer/CCNewRenderTexture.cpp +++ b/cocos/2d/renderer/CCNewRenderTexture.cpp @@ -152,113 +152,6 @@ void NewRenderTexture::end() renderer->popGroup(); } -void NewRenderTexture::onBegin() -{ - // - kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix); - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLLoadMatrix(&_projectionMatrix); - - kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLLoadMatrix(&_transformMatrix); - - Director *director = Director::getInstance(); - director->setProjection(director->getProjection()); - - const Size& texSize = _texture->getContentSizeInPixels(); - - // Calculate the adjustment ratios based on the old and new projections - Size size = director->getWinSizeInPixels(); - float widthRatio = size.width / texSize.width; - float heightRatio = size.height / texSize.height; - - // Adjust the orthographic projection and viewport - glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height); - - - kmMat4 orthoMatrix; - kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio, - (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 ); - kmGLMultMatrix(&orthoMatrix); - - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); - glBindFramebuffer(GL_FRAMEBUFFER, _FBO); - - //TODO move this to configration, so we don't check it every time - /* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers. - */ - if (Configuration::getInstance()->checkForGLExtension("GL_QCOM")) - { - // -- bind a temporary texture so we can clear the render buffer without losing our texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0); - CHECK_GL_ERROR_DEBUG(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0); - } -} - -void NewRenderTexture::onEnd() -{ - Director *director = Director::getInstance(); - - glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); - - // restore viewport - director->setViewport(); - - // - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLLoadMatrix(&_oldProjMatrix); - - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLLoadMatrix(&_oldTransMatrix); -} - -void NewRenderTexture::onClear() -{ - // save clear color - GLfloat oldClearColor[4] = {0.0f}; - GLfloat oldDepthClearValue = 0.0f; - GLint oldStencilClearValue = 0; - - // backup and set - if (_clearFlags & GL_COLOR_BUFFER_BIT) - { - glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor); - glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); - } - - if (_clearFlags & GL_DEPTH_BUFFER_BIT) - { - glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue); - glClearDepth(_clearDepth); - } - - if (_clearFlags & GL_STENCIL_BUFFER_BIT) - { - glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue); - glClearStencil(_clearStencil); - } - - // clear - glClear(_clearFlags); - - // restore - if (_clearFlags & GL_COLOR_BUFFER_BIT) - { - glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]); - } - if (_clearFlags & GL_DEPTH_BUFFER_BIT) - { - glClearDepth(oldDepthClearValue); - } - if (_clearFlags & GL_STENCIL_BUFFER_BIT) - { - glClearStencil(oldStencilClearValue); - } -} - void NewRenderTexture::clearDepth(float depthValue) { setClearDepth(depthValue); @@ -274,19 +167,6 @@ void NewRenderTexture::clearDepth(float depthValue) this->end(); } -void NewRenderTexture::onClearDepth() -{ - //! save old depth value - GLfloat depthClearValue; - glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue); - - glClearDepth(_clearDepth); - glClear(GL_DEPTH_BUFFER_BIT); - - // restore clear color - glClearDepth(depthClearValue); -} - NewRenderTexture::NewRenderTexture() :RenderTexture() { diff --git a/cocos/2d/renderer/CCNewRenderTexture.h b/cocos/2d/renderer/CCNewRenderTexture.h index 65e6694785..4d3b989696 100644 --- a/cocos/2d/renderer/CCNewRenderTexture.h +++ b/cocos/2d/renderer/CCNewRenderTexture.h @@ -46,16 +46,6 @@ protected: protected: NewRenderTexture(); virtual ~NewRenderTexture(); - - void onBegin(); - void onEnd(); - - //Clear render buffer - void onClear(); - void onClearDepth(); - - kmMat4 _oldTransMatrix, _oldProjMatrix; - kmMat4 _transformMatrix, _projectionMatrix; }; NS_CC_END From 43e9df17bb1e8add924baeb4325f2c3ed5ed55c5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 16:39:25 +0800 Subject: [PATCH 05/35] =?UTF-8?q?Removes=20unneeded=20=E2=80=98clone?= =?UTF-8?q?=E2=80=99=20in=20cocos2d=5Fspecifics.cpp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 9a92d58fff..fb16fc8a01 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -4f58619fbbaa2bb184766db408386d247df236ce \ No newline at end of file +80b25c13bca3a2d8adfc68a899c732103f68e0f5 \ No newline at end of file From 46cc91be3b4db5c55e4e793f973ad65a04a81497 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 16:41:17 +0800 Subject: [PATCH 06/35] Updates bindings-generator, skips to bind override functions. --- tools/bindings-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bindings-generator b/tools/bindings-generator index ad53201245..5f412d0b3a 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit ad532012457e2eaff15d73d9ba28a638fa748d2d +Subproject commit 5f412d0b3a4eadba3d2abd750de87d1b0e219e0a From ed93f90ccc701e62d70b93b0dc64bfc184eefdda Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 16:58:26 +0800 Subject: [PATCH 07/35] =?UTF-8?q?Removes=20unneeded=20=E2=80=98override?= =?UTF-8?q?=E2=80=99=20codes,=20uses=20`using=20Node::addChild;`=20to=20pr?= =?UTF-8?q?event=20compiler=20warnings.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/CCParticleBatchNode.cpp | 10 ---------- cocos/2d/CCParticleBatchNode.h | 4 ++-- cocos/2d/CCScene.cpp | 10 ---------- cocos/2d/CCScene.h | 3 +-- cocos/2d/CCSprite.cpp | 10 ---------- cocos/2d/CCSprite.h | 5 +---- cocos/2d/CCSpriteBatchNode.h | 4 ++-- extensions/GUI/CCScrollView/CCScrollView.cpp | 10 ---------- extensions/GUI/CCScrollView/CCScrollView.h | 4 ++-- 9 files changed, 8 insertions(+), 52 deletions(-) diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index d6e86dc2b4..e046833d79 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -143,16 +143,6 @@ void ParticleBatchNode::visit() } // override addChild: -void ParticleBatchNode::addChild(Node * child) -{ - Node::addChild(child); -} - -void ParticleBatchNode::addChild(Node * child, int zOrder) -{ - Node::addChild(child, zOrder); -} - void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag) { CCASSERT( aChild != nullptr, "Argument must be non-nullptr"); diff --git a/cocos/2d/CCParticleBatchNode.h b/cocos/2d/CCParticleBatchNode.h index e8b75a3b70..189bfc7da9 100644 --- a/cocos/2d/CCParticleBatchNode.h +++ b/cocos/2d/CCParticleBatchNode.h @@ -105,8 +105,8 @@ public: // Overrides void visit(); - virtual void addChild(Node * child) override; - virtual void addChild(Node * child, int zOrder) override; + + using Node::addChild; virtual void addChild(Node * child, int zOrder, int tag) override; virtual void removeChild(Node* child, bool cleanup) override; virtual void reorderChild(Node * child, int zOrder) override; diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index 37b653aad9..b31a499af6 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -121,16 +121,6 @@ bool Scene::initWithPhysics() return ret; } -void Scene::addChild(Node* child) -{ - Node::addChild(child); -} - -void Scene::addChild(Node* child, int zOrder) -{ - Node::addChild(child, zOrder); -} - void Scene::addChild(Node* child, int zOrder, int tag) { Node::addChild(child, zOrder, tag); diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index 12c0fa1dea..b52d38e969 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -64,8 +64,7 @@ public: inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; } - virtual void addChild(Node* child) override; - virtual void addChild(Node* child, int zOrder) override; + using Node::addChild; virtual void addChild(Node* child, int zOrder, int tag) override; virtual void update(float delta) override; virtual std::string getDescription() const override; diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 6c940d3de3..5bbe9624c6 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -749,16 +749,6 @@ void Sprite::updateQuadVertices() // Node overrides -void Sprite::addChild(Node *child) -{ - Node::addChild(child); -} - -void Sprite::addChild(Node *child, int zOrder) -{ - Node::addChild(child, zOrder); -} - void Sprite::addChild(Node *child, int zOrder, int tag) { CCASSERT(child != nullptr, "Argument must be non-nullptr"); diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 28313662a4..86df10a055 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -413,10 +413,7 @@ public: virtual void removeChild(Node* child, bool cleanup) override; virtual void removeAllChildrenWithCleanup(bool cleanup) override; virtual void reorderChild(Node *child, int zOrder) override; - // Should also override addChild(Node*) and addChild(Node*, int), or binding generator will only - // bind addChild(Node*, int, int); - virtual void addChild(Node* child) override; - virtual void addChild(Node* child, int zOrder) override; + using Node::addChild; virtual void addChild(Node *child, int zOrder, int tag) override; virtual void sortAllChildren() override; virtual void setScale(float scale) override; diff --git a/cocos/2d/CCSpriteBatchNode.h b/cocos/2d/CCSpriteBatchNode.h index 73508fe762..29eb7fadb3 100644 --- a/cocos/2d/CCSpriteBatchNode.h +++ b/cocos/2d/CCSpriteBatchNode.h @@ -154,8 +154,8 @@ public: virtual const BlendFunc& getBlendFunc() const override; virtual void visit() override; - virtual void addChild(Node* child) override{ Node::addChild(child);} - virtual void addChild(Node * child, int zOrder) override { Node::addChild(child, zOrder);} + + using Node::addChild; virtual void addChild(Node * child, int zOrder, int tag) override; virtual void reorderChild(Node *child, int zOrder) override; diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index 4a8ab31c81..7ae70819af 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -485,16 +485,6 @@ void ScrollView::addChild(Node * child, int zOrder, int tag) } } -void ScrollView::addChild(Node * child, int zOrder) -{ - this->addChild(child, zOrder, child->getTag()); -} - -void ScrollView::addChild(Node * child) -{ - this->addChild(child, child->getZOrder(), child->getTag()); -} - /** * clip this view so that outside of the visible bounds can be hidden. */ diff --git a/extensions/GUI/CCScrollView/CCScrollView.h b/extensions/GUI/CCScrollView/CCScrollView.h index fb448c314c..bef479e49b 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.h +++ b/extensions/GUI/CCScrollView/CCScrollView.h @@ -224,9 +224,9 @@ public: * @lua NA */ virtual void visit() override; + + using Node::addChild; virtual void addChild(Node * child, int zOrder, int tag) override; - virtual void addChild(Node * child, int zOrder) override; - virtual void addChild(Node * child) override; protected: /** From a7a50dffcc32e6828ade7a9134363e9d50d53771 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 17:13:06 +0800 Subject: [PATCH 08/35] move begin(), end(),draw() to RenderTexture --- cocos/2d/CCRenderTexture.cpp | 251 ++++++++--------------- cocos/2d/renderer/CCNewRenderTexture.cpp | 96 --------- cocos/2d/renderer/CCNewRenderTexture.h | 9 +- 3 files changed, 91 insertions(+), 265 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index f031f06093..609c287ce2 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -37,6 +37,11 @@ THE SOFTWARE. #include "CCNotificationCenter.h" #include "CCEventType.h" #include "CCGrid.h" + +#include "CCRenderer.h" +#include "CCGroupCommand.h" +#include "CCCustomCommand.h" + // extern #include "kazmath/GL/matrix.h" @@ -296,47 +301,6 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat return ret; } -void RenderTexture::begin() -{ - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPushMatrix(); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPushMatrix(); - - Director *director = Director::getInstance(); - director->setProjection(director->getProjection()); - - const Size& texSize = _texture->getContentSizeInPixels(); - - // Calculate the adjustment ratios based on the old and new projections - Size size = director->getWinSizeInPixels(); - float widthRatio = size.width / texSize.width; - float heightRatio = size.height / texSize.height; - - // Adjust the orthographic projection and viewport - glViewport(0, 0, (GLsizei)texSize.width, (GLsizei)texSize.height); - - - kmMat4 orthoMatrix; - kmMat4OrthographicProjection(&orthoMatrix, (float)-1.0 / widthRatio, (float)1.0 / widthRatio, - (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1,1 ); - kmGLMultMatrix(&orthoMatrix); - - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); - glBindFramebuffer(GL_FRAMEBUFFER, _FBO); - - /* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers. - */ - if (Configuration::getInstance()->checkForGLExtension("GL_QCOM")) - { - // -- bind a temporary texture so we can clear the render buffer without losing our texture - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0); - CHECK_GL_ERROR_DEBUG(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0); - } -} - void RenderTexture::beginWithClear(float r, float g, float b, float a) { _beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT); @@ -354,61 +318,21 @@ void RenderTexture::beginWithClear(float r, float g, float b, float a, float dep void RenderTexture::_beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { + setClearColor(Color4F(r, g, b, a)); + + setClearDepth(depthValue); + + setClearStencil(stencilValue); + + setClearFlags(flags); + this->begin(); - // save clear color - GLfloat clearColor[4] = {0.0f}; - GLfloat depthClearValue = 0.0f; - int stencilClearValue = 0; - - if (flags & GL_COLOR_BUFFER_BIT) - { - glGetFloatv(GL_COLOR_CLEAR_VALUE,clearColor); - glClearColor(r, g, b, a); - } - - if (flags & GL_DEPTH_BUFFER_BIT) - { - glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue); - glClearDepth(depthValue); - } - - if (flags & GL_STENCIL_BUFFER_BIT) - { - glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencilClearValue); - glClearStencil(stencilValue); - } - - glClear(flags); - - // restore - if (flags & GL_COLOR_BUFFER_BIT) - { - glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); - } - if (flags & GL_DEPTH_BUFFER_BIT) - { - glClearDepth(depthClearValue); - } - if (flags & GL_STENCIL_BUFFER_BIT) - { - glClearStencil(stencilClearValue); - } -} - -void RenderTexture::end() -{ - Director *director = Director::getInstance(); - - glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); - - // restore viewport - director->setViewport(); - - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPopMatrix(); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPopMatrix(); + //clear screen + CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand(); + clearCmd->init(0, _vertexZ); + clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this); + Director::getInstance()->getRenderer()->addCommand(clearCmd); } //TODO find a better way to clear the screen, there is no need to rebind render buffer there. @@ -420,16 +344,16 @@ void RenderTexture::clear(float r, float g, float b, float a) void RenderTexture::clearDepth(float depthValue) { + setClearDepth(depthValue); + this->begin(); - //! save old depth value - GLfloat depthClearValue; - glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depthClearValue); - glClearDepth(depthValue); - glClear(GL_DEPTH_BUFFER_BIT); + CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); + cmd->init(0, _vertexZ); + cmd->func = CC_CALLBACK_0(RenderTexture::onClearDepth, this); + + Director::getInstance()->getRenderer()->addCommand(cmd); - // restore clear color - glClearDepth(depthClearValue); this->end(); } @@ -466,69 +390,6 @@ void RenderTexture::visit() _orderOfArrival = 0; } -void RenderTexture::draw() -{ - if( _autoDraw) - { - begin(); - - if (_clearFlags) - { - GLfloat oldClearColor[4] = {0.0f}; - GLfloat oldDepthClearValue = 0.0f; - GLint oldStencilClearValue = 0; - - // backup and set - if (_clearFlags & GL_COLOR_BUFFER_BIT) - { - glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor); - glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); - } - - if (_clearFlags & GL_DEPTH_BUFFER_BIT) - { - glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepthClearValue); - glClearDepth(_clearDepth); - } - - if (_clearFlags & GL_STENCIL_BUFFER_BIT) - { - glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &oldStencilClearValue); - glClearStencil(_clearStencil); - } - - // clear - glClear(_clearFlags); - - // restore - if (_clearFlags & GL_COLOR_BUFFER_BIT) - { - glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[3]); - } - if (_clearFlags & GL_DEPTH_BUFFER_BIT) - { - glClearDepth(oldDepthClearValue); - } - if (_clearFlags & GL_STENCIL_BUFFER_BIT) - { - glClearStencil(oldStencilClearValue); - } - } - - //! make sure all children are drawn - sortAllChildren(); - - for(const auto &child : _children) { - if (child != _sprite) - { - child->visit(); - } - } - - end(); - } -} - bool RenderTexture::saveToFile(const std::string& filename) { bool ret = false; @@ -745,4 +606,66 @@ void RenderTexture::onClearDepth() glClearDepth(depthClearValue); } +void RenderTexture::draw() +{ + if (_autoDraw) + { + //Begin will create a render group using new render target + begin(); + + //clear screen + CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand(); + clearCmd->init(0, _vertexZ); + clearCmd->func = CC_CALLBACK_0(RenderTexture::onClear, this); + Director::getInstance()->getRenderer()->addCommand(clearCmd); + + //! make sure all children are drawn + sortAllChildren(); + + for(const auto &child: _children) + { + if (child != _sprite) + child->visit(); + } + + //End will pop the current render group + end(); + } +} + +void RenderTexture::begin() +{ + kmGLMatrixMode(KM_GL_PROJECTION); + kmGLPushMatrix(); + kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix); + + kmGLMatrixMode(KM_GL_MODELVIEW); + kmGLPushMatrix(); + kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); + + GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); + groupCommand->init(0, _vertexZ); + + Renderer *renderer = Director::getInstance()->getRenderer(); + renderer->addCommand(groupCommand); + renderer->pushGroup(groupCommand->getRenderQueueID()); + + CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand(); + beginCmd->init(0, _vertexZ); + beginCmd->func = CC_CALLBACK_0(RenderTexture::onBegin, this); + + Director::getInstance()->getRenderer()->addCommand(beginCmd); +} + +void RenderTexture::end() +{ + CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand(); + endCmd->init(0, _vertexZ); + endCmd->func = CC_CALLBACK_0(RenderTexture::onEnd, this); + + Renderer *renderer = Director::getInstance()->getRenderer(); + renderer->addCommand(endCmd); + renderer->popGroup(); +} + NS_CC_END diff --git a/cocos/2d/renderer/CCNewRenderTexture.cpp b/cocos/2d/renderer/CCNewRenderTexture.cpp index 3d6c950668..c3aba195e1 100644 --- a/cocos/2d/renderer/CCNewRenderTexture.cpp +++ b/cocos/2d/renderer/CCNewRenderTexture.cpp @@ -71,102 +71,6 @@ NewRenderTexture* NewRenderTexture::create(int w, int h) return nullptr; } -void NewRenderTexture::draw() -{ - if (_autoDraw) - { - //Begin will create a render group using new render target - begin(); - - //clear screen - CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand(); - clearCmd->init(0, _vertexZ); - clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this); - Director::getInstance()->getRenderer()->addCommand(clearCmd); - - //! make sure all children are drawn - sortAllChildren(); - - for(const auto &child: _children) - { - if (child != _sprite) - child->visit(); - } - - //End will pop the current render group - end(); - } -} - -void NewRenderTexture::_beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) -{ - setClearColor(Color4F(r, g, b, a)); - - setClearDepth(depthValue); - - setClearStencil(stencilValue); - - setClearFlags(flags); - - this->begin(); - - //clear screen - CustomCommand* clearCmd = CustomCommand::getCommandPool().generateCommand(); - clearCmd->init(0, _vertexZ); - clearCmd->func = CC_CALLBACK_0(NewRenderTexture::onClear, this); - Director::getInstance()->getRenderer()->addCommand(clearCmd); -} - -void NewRenderTexture::begin() -{ - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPushMatrix(); - kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix); - - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPushMatrix(); - kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); - - GroupCommand* groupCommand = GroupCommand::getCommandPool().generateCommand(); - groupCommand->init(0, _vertexZ); - - Renderer *renderer = Director::getInstance()->getRenderer(); - renderer->addCommand(groupCommand); - renderer->pushGroup(groupCommand->getRenderQueueID()); - - CustomCommand* beginCmd = CustomCommand::getCommandPool().generateCommand(); - beginCmd->init(0, _vertexZ); - beginCmd->func = CC_CALLBACK_0(NewRenderTexture::onBegin, this); - - Director::getInstance()->getRenderer()->addCommand(beginCmd); -} - -void NewRenderTexture::end() -{ - CustomCommand* endCmd = CustomCommand::getCommandPool().generateCommand(); - endCmd->init(0, _vertexZ); - endCmd->func = CC_CALLBACK_0(NewRenderTexture::onEnd, this); - - Renderer *renderer = Director::getInstance()->getRenderer(); - renderer->addCommand(endCmd); - renderer->popGroup(); -} - -void NewRenderTexture::clearDepth(float depthValue) -{ - setClearDepth(depthValue); - - this->begin(); - - CustomCommand* cmd = CustomCommand::getCommandPool().generateCommand(); - cmd->init(0, _vertexZ); - cmd->func = CC_CALLBACK_0(NewRenderTexture::onClearDepth, this); - - Director::getInstance()->getRenderer()->addCommand(cmd); - - this->end(); -} - NewRenderTexture::NewRenderTexture() :RenderTexture() { diff --git a/cocos/2d/renderer/CCNewRenderTexture.h b/cocos/2d/renderer/CCNewRenderTexture.h index 4d3b989696..8c4a46493e 100644 --- a/cocos/2d/renderer/CCNewRenderTexture.h +++ b/cocos/2d/renderer/CCNewRenderTexture.h @@ -36,13 +36,12 @@ public: static NewRenderTexture* create(int w, int h, Texture2D::PixelFormat eFormat); static NewRenderTexture* create(int w, int h); - virtual void begin() override; - virtual void end() override; - virtual void draw() override; + //virtual void begin() override; + //virtual void end() override; - void clearDepth(float depthValue); + //void clearDepth(float depthValue); protected: - virtual void _beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) override; + //virtual void _beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) override; protected: NewRenderTexture(); virtual ~NewRenderTexture(); From 41a77fed6167546c399916f34f38cbb9afc4c3a2 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 17:13:41 +0800 Subject: [PATCH 09/35] TestCase Use RenderTexture instead of NewRenderTexture --- cocos/2d/CCTransition.cpp | 4 ++-- cocos/2d/CCTransitionProgress.cpp | 2 +- .../Classes/RenderTextureTest/RenderTextureTest.cpp | 12 ++++++------ .../Classes/RenderTextureTest/RenderTextureTest.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cocos/2d/CCTransition.cpp b/cocos/2d/CCTransition.cpp index 2fa930379a..1a8ebd2b1c 100644 --- a/cocos/2d/CCTransition.cpp +++ b/cocos/2d/CCTransition.cpp @@ -1275,7 +1275,7 @@ void TransitionCrossFade::onEnter() LayerColor* layer = LayerColor::create(color); // create the first render texture for inScene - RenderTexture* inTexture = NewRenderTexture::create((int)size.width, (int)size.height); + RenderTexture* inTexture = RenderTexture::create((int)size.width, (int)size.height); if (nullptr == inTexture) { @@ -1292,7 +1292,7 @@ void TransitionCrossFade::onEnter() inTexture->end(); // create the second render texture for outScene - RenderTexture* outTexture = NewRenderTexture::create((int)size.width, (int)size.height); + RenderTexture* outTexture = RenderTexture::create((int)size.width, (int)size.height); outTexture->getSprite()->setAnchorPoint( Point(0.5f,0.5f) ); outTexture->setPosition( Point(size.width/2, size.height/2) ); outTexture->setAnchorPoint( Point(0.5f,0.5f) ); diff --git a/cocos/2d/CCTransitionProgress.cpp b/cocos/2d/CCTransitionProgress.cpp index ff217793ee..f0f163bec8 100644 --- a/cocos/2d/CCTransitionProgress.cpp +++ b/cocos/2d/CCTransitionProgress.cpp @@ -72,7 +72,7 @@ void TransitionProgress::onEnter() Size size = Director::getInstance()->getWinSize(); // create the second render texture for outScene - RenderTexture *texture = NewRenderTexture::create((int)size.width, (int)size.height); + RenderTexture *texture = RenderTexture::create((int)size.width, (int)size.height); texture->getSprite()->setAnchorPoint(Point(0.5f,0.5f)); texture->setPosition(Point(size.width/2, size.height/2)); texture->setAnchorPoint(Point(0.5f,0.5f)); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index 507e7594e2..f4135182f7 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -93,7 +93,7 @@ RenderTextureSave::RenderTextureSave() auto s = Director::getInstance()->getWinSize(); // create a render texture, this is what we are going to draw into - _target = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); + _target = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); _target->retain(); _target->setPosition(Point(s.width / 2, s.height / 2)); @@ -241,7 +241,7 @@ RenderTextureIssue937::RenderTextureIssue937() /* A2 & B2 setup */ - auto rend = NewRenderTexture::create(32, 64, Texture2D::PixelFormat::RGBA8888); + auto rend = RenderTexture::create(32, 64, Texture2D::PixelFormat::RGBA8888); if (NULL == rend) { @@ -410,7 +410,7 @@ void RenderTextureZbuffer::onTouchesEnded(const std::vector& touches, Ev void RenderTextureZbuffer::renderScreenShot() { - auto texture = NewRenderTexture::create(512, 512); + auto texture = RenderTexture::create(512, 512); if (NULL == texture) { return; @@ -444,7 +444,7 @@ RenderTextureTestDepthStencil::RenderTextureTestDepthStencil() auto sprite = Sprite::create("Images/fire.png"); sprite->setPosition(Point(s.width * 0.25f, 0)); sprite->setScale(10); - auto rend = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444, GL_DEPTH24_STENCIL8); + auto rend = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444, GL_DEPTH24_STENCIL8); glStencilMask(0xFF); rend->beginWithClear(0, 0, 0, 0, 0, 0); @@ -506,7 +506,7 @@ RenderTextureTargetNode::RenderTextureTargetNode() auto s = Director::getInstance()->getWinSize(); /* Create the render texture */ - auto renderTexture = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444); + auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA4444); this->renderTexture = renderTexture; renderTexture->setPosition(Point(s.width/2, s.height/2)); @@ -591,7 +591,7 @@ void SpriteRenderTextureBug::SimpleSprite::draw() if (_rt == nullptr) { auto s = Director::getInstance()->getWinSize(); - _rt = NewRenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); + _rt = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888); _rt->retain(); } _rt->beginWithClear(0.0f, 0.0f, 0.0f, 1.0f); diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index ac8128a0c1..0c6004b15b 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -31,7 +31,7 @@ public: void saveImage(Object *pSender); private: - NewRenderTexture *_target; + RenderTexture *_target; Sprite *_brush; }; From 4399adc869341f3ba9081c41fa870edb2b237bf4 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 23 Dec 2013 17:31:57 +0800 Subject: [PATCH 10/35] issue #3353:Add the DisplayLinkDirector lua binding --- tools/tolua/cocos2dx.ini | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/tolua/cocos2dx.ini b/tools/tolua/cocos2dx.ini index 02b9a3819e..2c86bc2d8e 100644 --- a/tools/tolua/cocos2dx.ini +++ b/tools/tolua/cocos2dx.ini @@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/2d/cocos2d.h %(cocosdir)s/cocos/audio/include/Simpl # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image Event.* +classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Data SimpleAudioEngine Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Object$ UserDefault EGLViewProtocol EGLView Image Event.* DisplayLinkDirector # what should we skip? in the format ClassName::[function function] # ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also @@ -111,7 +111,8 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS Label::[getLettersInfo], EGLViewProtocol::[setTouchDelegate], EGLView::[end swapBuffers], - NewTextureAtlas::[*] + NewTextureAtlas::[*], + DisplayLinkDirector::[mainLoop setAnimationInterval startAnimation stopAnimation] rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames getSpriteFrameByName=getSpriteFrame], ProgressTimer::[setReverseProgress=setReverseDirection], @@ -142,7 +143,7 @@ base_classes_to_skip = Clonable # classes that create no constructor # Set is special and we will use a hand-written constructor -abstract_classes = Action FiniteTimeAction ActionInterval ActionEase EaseRateAction EaseElastic EaseBounce ActionInstant GridAction Grid3DAction TiledGrid3DAction Director SpriteFrameCache TransitionEaseScene Set SimpleAudioEngine FileUtils Application ClippingNode Label EGLViewProtocol EGLView EventAcceleration +abstract_classes = Action FiniteTimeAction ActionInterval ActionEase EaseRateAction EaseElastic EaseBounce ActionInstant GridAction Grid3DAction TiledGrid3DAction Director SpriteFrameCache TransitionEaseScene Set SimpleAudioEngine FileUtils Application ClippingNode Label EGLViewProtocol EGLView EventAcceleration DisplayLinkDirector # Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. script_control_cpp = no From 487e0b21af171f3f8776b8f28674dad4344b2cd6 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 18:03:08 +0800 Subject: [PATCH 11/35] update Xcode project file& android.mk --- build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id | 2 +- cocos/2d/Android.mk | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 46d83b2d17..a4bc1d2615 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -1df2ba5492ecdbe0c160d2429733c1371b35b21a \ No newline at end of file +6b6f50103f52c3f9535768ce96c0d3eff23c2d20 \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index ee529e0e6d..0c15b3efd8 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -117,7 +117,6 @@ platform/CCEGLViewProtocol.cpp \ platform/CCFileUtils.cpp \ platform/CCSAXParser.cpp \ platform/CCThread.cpp \ -renderer/CCNewRenderTexture.cpp \ renderer/CCNewSprite.cpp \ renderer/CCNewSpriteBatchNode.cpp \ renderer/CCNewTextureAtlas.cpp \ From bcaec978d3120d00f0b4e6913d14aeb729e39bac Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 18:04:04 +0800 Subject: [PATCH 12/35] remove NewRenderTexture Class --- cocos/2d/renderer/CCNewRenderTexture.cpp | 85 ------------------------ cocos/2d/renderer/CCNewRenderTexture.h | 52 --------------- 2 files changed, 137 deletions(-) delete mode 100644 cocos/2d/renderer/CCNewRenderTexture.cpp delete mode 100644 cocos/2d/renderer/CCNewRenderTexture.h diff --git a/cocos/2d/renderer/CCNewRenderTexture.cpp b/cocos/2d/renderer/CCNewRenderTexture.cpp deleted file mode 100644 index c3aba195e1..0000000000 --- a/cocos/2d/renderer/CCNewRenderTexture.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - - -#include "CCNewRenderTexture.h" -#include "CCCustomCommand.h" -#include "CCRenderer.h" -#include "CCGroupCommand.h" -#include "CCConfiguration.h" -#include "CCDirector.h" - -NS_CC_BEGIN - -NewRenderTexture* NewRenderTexture::create(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat) -{ - NewRenderTexture* pRet = new NewRenderTexture(); - - if(pRet && pRet->initWithWidthAndHeight(w, h, eFormat, uDepthStencilFormat)) - { - pRet->autorelease(); - return pRet; - } - CC_SAFE_DELETE(pRet); - return nullptr; -} - -NewRenderTexture* NewRenderTexture::create(int w, int h, Texture2D::PixelFormat eFormat) -{ - NewRenderTexture* pRet = new NewRenderTexture(); - - if(pRet && pRet->initWithWidthAndHeight(w, h, eFormat)) - { - pRet->autorelease(); - return pRet; - } - CC_SAFE_DELETE(pRet); - return nullptr; -} - -NewRenderTexture* NewRenderTexture::create(int w, int h) -{ - NewRenderTexture* pRet = new NewRenderTexture(); - - if(pRet && pRet->initWithWidthAndHeight(w, h, Texture2D::PixelFormat::RGB888 , 0)) - { - pRet->autorelease(); - return pRet; - } - CC_SAFE_DELETE(pRet); - return nullptr; -} - -NewRenderTexture::NewRenderTexture() -:RenderTexture() -{ - -} - -NewRenderTexture::~NewRenderTexture() -{ - -} - -NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCNewRenderTexture.h b/cocos/2d/renderer/CCNewRenderTexture.h deleted file mode 100644 index 8c4a46493e..0000000000 --- a/cocos/2d/renderer/CCNewRenderTexture.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCNewRenderTexture_H_ -#define __CCNewRenderTexture_H_ - -#include "CCRenderTexture.h" - -NS_CC_BEGIN - -class NewRenderTexture : public RenderTexture -{ -public: - static NewRenderTexture* create(int w, int h, Texture2D::PixelFormat eFormat, GLuint uDepthStencilFormat); - static NewRenderTexture* create(int w, int h, Texture2D::PixelFormat eFormat); - static NewRenderTexture* create(int w, int h); - - //virtual void begin() override; - //virtual void end() override; - - //void clearDepth(float depthValue); -protected: - //virtual void _beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) override; -protected: - NewRenderTexture(); - virtual ~NewRenderTexture(); -}; - -NS_CC_END - -#endif //__CCNewRenderTexture_H_ From 9c97fc6f19b03962dc3c286d06cf615a85c07945 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 18:08:50 +0800 Subject: [PATCH 13/35] remove NewRenderTexture include file --- cocos/2d/CCTransition.cpp | 2 -- cocos/2d/CCTransitionProgress.cpp | 1 - cocos/2d/cocos2d.h | 1 - .../Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp | 1 - .../Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h | 1 - 5 files changed, 6 deletions(-) diff --git a/cocos/2d/CCTransition.cpp b/cocos/2d/CCTransition.cpp index 1a8ebd2b1c..4213232139 100644 --- a/cocos/2d/CCTransition.cpp +++ b/cocos/2d/CCTransition.cpp @@ -35,8 +35,6 @@ THE SOFTWARE. #include "CCLayer.h" #include "CCRenderTexture.h" #include "CCNodeGrid.h" -#include "CCNewRenderTexture.h" - NS_CC_BEGIN diff --git a/cocos/2d/CCTransitionProgress.cpp b/cocos/2d/CCTransitionProgress.cpp index f0f163bec8..7e9d3bbc10 100644 --- a/cocos/2d/CCTransitionProgress.cpp +++ b/cocos/2d/CCTransitionProgress.cpp @@ -32,7 +32,6 @@ THE SOFTWARE. #include "CCLayer.h" #include "CCActionInstant.h" #include "CCActionProgressTimer.h" -#include "CCNewRenderTexture.h" NS_CC_BEGIN diff --git a/cocos/2d/cocos2d.h b/cocos/2d/cocos2d.h index fb61bf1679..21cf523bc2 100644 --- a/cocos/2d/cocos2d.h +++ b/cocos/2d/cocos2d.h @@ -119,7 +119,6 @@ THE SOFTWARE. #include "CCParticleSystemQuad.h" // new renderer -#include "renderer/CCNewRenderTexture.h" #include "renderer/CCNewSprite.h" #include "renderer/CCNewSpriteBatchNode.h" #include "renderer/CCNewTextureAtlas.h" diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp index f4135182f7..b679aeb463 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -1,7 +1,6 @@ #include "CCConfiguration.h" #include "RenderTextureTest.h" #include "../testBasic.h" -#include "renderer/CCNewRenderTexture.h" // Test #1 by Jason Booth (slipster216) // Test #3 by David Deaco (ddeaco) diff --git a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h index 0c6004b15b..9e37954566 100644 --- a/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h +++ b/samples/Cpp/TestCpp/Classes/RenderTextureTest/RenderTextureTest.h @@ -4,7 +4,6 @@ #include "cocos2d.h" #include "../testBasic.h" #include "../BaseTest.h" -#include "renderer/CCNewRenderTexture.h" class RenderTextureTest : public BaseTest { From 8c3315de7605110e6f13cf046ae4691467885ec0 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 18:23:39 +0800 Subject: [PATCH 14/35] closed #3478: BitmapFontMultiLineAlignment test shows some unneeded 'line break' --- cocos/2d/CCLabelBMFont.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocos/2d/CCLabelBMFont.cpp b/cocos/2d/CCLabelBMFont.cpp index 868da6591a..1866d022f9 100644 --- a/cocos/2d/CCLabelBMFont.cpp +++ b/cocos/2d/CCLabelBMFont.cpp @@ -867,6 +867,8 @@ void LabelBMFont::updateLabel() startOfLine = startOfWord; start_line = true; } + ++i; + continue; } // Whitespace. From 0dab85a3bff03b55db997fe430b841b33f4df1d9 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 18:37:18 +0800 Subject: [PATCH 15/35] update CMakeLists.txt --- cocos/2d/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 568f5aafe5..aadc31d9a7 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -139,7 +139,6 @@ set(COCOS2D_SRC platform/CCEGLViewProtocol.cpp platform/CCFileUtils.cpp ../../external/edtaa3func/edtaa3func.cpp - renderer/CCNewRenderTexture.cpp renderer/CCNewSprite.cpp renderer/CCNewSpriteBatchNode.cpp renderer/CCNewTextureAtlas.cpp From 509d4513eb4100830ca0073cb26ec9193fcc4486 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 23 Dec 2013 11:48:15 +0000 Subject: [PATCH 16/35] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index a388e918ef..3363b72bc8 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit a388e918ef871c0fcfeb69bd71b1c784747871b8 +Subproject commit 3363b72bc8069455a80704b9261f8e97c74edb67 From 98d573f4cb14adedfd096218c2e41070bf7a1dd6 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 19:59:09 +0800 Subject: [PATCH 17/35] rename protected _beginWithClear to beginWithClear --- cocos/2d/CCRenderTexture.cpp | 8 ++++---- cocos/2d/CCRenderTexture.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 609c287ce2..3ba91d0771 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -303,20 +303,20 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat void RenderTexture::beginWithClear(float r, float g, float b, float a) { - _beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT); + beginWithClear(r, g, b, a, 0, 0, GL_COLOR_BUFFER_BIT); } void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue) { - _beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); + beginWithClear(r, g, b, a, depthValue, 0, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); } void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue) { - _beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + beginWithClear(r, g, b, a, depthValue, stencilValue, GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); } -void RenderTexture::_beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) +void RenderTexture::beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags) { setClearColor(Color4F(r, g, b, a)); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index ac39dade22..8df7eee817 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -164,7 +164,7 @@ public: bool initWithWidthAndHeight(int w, int h, Texture2D::PixelFormat format, GLuint depthStencilFormat); protected: - virtual void _beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); + virtual void beginWithClear(float r, float g, float b, float a, float depthValue, int stencilValue, GLbitfield flags); GLuint _FBO; GLuint _depthRenderBufffer; From 1dd2c1c20cb9c4d721c98704a7c5ab459fc4b488 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 20:11:50 +0800 Subject: [PATCH 18/35] remove NewTextureAtlas --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos/2d/Android.mk | 1 - cocos/2d/CMakeLists.txt | 1 - cocos/2d/cocos2d.h | 1 - cocos/2d/renderer/CCNewTextureAtlas.cpp | 77 ------------------- cocos/2d/renderer/CCNewTextureAtlas.h | 50 ------------ 6 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 cocos/2d/renderer/CCNewTextureAtlas.cpp delete mode 100644 cocos/2d/renderer/CCNewTextureAtlas.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index a4bc1d2615..0b1a05e0fa 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -6b6f50103f52c3f9535768ce96c0d3eff23c2d20 \ No newline at end of file +4b776594c76318354842113d2274acda51fe9178 \ No newline at end of file diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 0c15b3efd8..62d43cfe5c 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -119,7 +119,6 @@ platform/CCSAXParser.cpp \ platform/CCThread.cpp \ renderer/CCNewSprite.cpp \ renderer/CCNewSpriteBatchNode.cpp \ -renderer/CCNewTextureAtlas.cpp \ renderer/CCCustomCommand.cpp \ renderer/CCFrustum.cpp \ renderer/CCGroupCommand.cpp \ diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index aadc31d9a7..4f9918efdb 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -141,7 +141,6 @@ set(COCOS2D_SRC ../../external/edtaa3func/edtaa3func.cpp renderer/CCNewSprite.cpp renderer/CCNewSpriteBatchNode.cpp - renderer/CCNewTextureAtlas.cpp renderer/CCCustomCommand.cpp renderer/CCFrustum.cpp renderer/CCGroupCommand.cpp diff --git a/cocos/2d/cocos2d.h b/cocos/2d/cocos2d.h index 21cf523bc2..64be8231b2 100644 --- a/cocos/2d/cocos2d.h +++ b/cocos/2d/cocos2d.h @@ -121,7 +121,6 @@ THE SOFTWARE. // new renderer #include "renderer/CCNewSprite.h" #include "renderer/CCNewSpriteBatchNode.h" -#include "renderer/CCNewTextureAtlas.h" #include "renderer/CCCustomCommand.h" #include "renderer/CCFrustum.h" #include "renderer/CCGroupCommand.h" diff --git a/cocos/2d/renderer/CCNewTextureAtlas.cpp b/cocos/2d/renderer/CCNewTextureAtlas.cpp deleted file mode 100644 index 4358669fcd..0000000000 --- a/cocos/2d/renderer/CCNewTextureAtlas.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "CCNewTextureAtlas.h" -#include "CCTexture2D.h" -#include "CCDirector.h" -#include "CCRenderer.h" -#include "CCQuadCommand.h" - -NS_CC_BEGIN - -NewTextureAtlas::NewTextureAtlas() -:TextureAtlas() -{ - -} - -NewTextureAtlas::~NewTextureAtlas() -{ - -} - -NewTextureAtlas *NewTextureAtlas::create(const char *file, long capacity) -{ - NewTextureAtlas * textureAtlas = new NewTextureAtlas(); - if(textureAtlas && textureAtlas->initWithFile(file, capacity)) - { - textureAtlas->autorelease(); - return textureAtlas; - } - CC_SAFE_DELETE(textureAtlas); - return nullptr; -} - -NewTextureAtlas *NewTextureAtlas::createWithTexture(Texture2D *texture, long capacity) -{ - NewTextureAtlas * textureAtlas = new NewTextureAtlas(); - if (textureAtlas && textureAtlas->initWithTexture(texture, capacity)) - { - textureAtlas->autorelease(); - return textureAtlas; - } - CC_SAFE_DELETE(textureAtlas); - return nullptr; -} - - -void NewTextureAtlas::drawNumberOfQuads(long numberOfQuads, long start) -{ -// updateTransform(); -// QuadCommand* renderCommand = new QuadCommand(0, 0,_texture->getName(), _shaderProgram, _blendFunc, _quad); -// -// Renderer::getInstance()->addCommand(renderCommand); -} - -NS_CC_END diff --git a/cocos/2d/renderer/CCNewTextureAtlas.h b/cocos/2d/renderer/CCNewTextureAtlas.h deleted file mode 100644 index 9f497c76a6..0000000000 --- a/cocos/2d/renderer/CCNewTextureAtlas.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - - -#ifndef __CCNewTextureAtlas_H_ -#define __CCNewTextureAtlas_H_ - -#include "CCPlatformMacros.h" -#include "CCTextureAtlas.h" - -NS_CC_BEGIN - -class NewTextureAtlas : public TextureAtlas -{ -public: - static NewTextureAtlas* create(const char* file, long capacity); - static NewTextureAtlas* createWithTexture(Texture2D *texture, long capacity); - - void drawNumberOfQuads(long numberOfQuads, long start); - -protected: - NewTextureAtlas(); - virtual ~NewTextureAtlas(); - -}; - -NS_CC_END - -#endif //__CCNewTextureAtlas_H_ From 2efe4b7420af2a226d4b593968e254be780d2a7c Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 23 Dec 2013 12:14:14 +0000 Subject: [PATCH 19/35] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 3363b72bc8..6d602f693d 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 3363b72bc8069455a80704b9261f8e97c74edb67 +Subproject commit 6d602f693d2bb8c92fc860509bc93f8f55a01bf1 From b3cc7d7e688c1d639ec0a232a4af872bc78c81e8 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 20:25:11 +0800 Subject: [PATCH 20/35] Bindings-generator skips Node::setContentSize. Binds it manually. --- 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 9f17145f6a..ba177b8a27 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -37,7 +37,7 @@ classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule], +skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule setContentSize], Sprite::[getQuad getBlendFunc ^setPosition$ setBlendFunc], SpriteBatchNode::[getBlendFunc setBlendFunc getDescendants], MotionStreak::[getBlendFunc setBlendFunc draw update], From 3096c3431145d2fa90a79e27f2ffa98083e31e0e Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 20:25:46 +0800 Subject: [PATCH 21/35] Removes unneeded binding glue codes, Sprite::setPosition. --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index fb16fc8a01..4e31a5e98a 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -80b25c13bca3a2d8adfc68a899c732103f68e0f5 \ No newline at end of file +3ea69b3bde8950d0af9d3a2d25c04bdb0e085f00 \ No newline at end of file From 92ee688b731d593dbf07c430f601c1a7f30b3e41 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 20:26:13 +0800 Subject: [PATCH 22/35] Updates js tests to the latest version. --- samples/Javascript/Shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Javascript/Shared b/samples/Javascript/Shared index 148868f7f4..24c7cad588 160000 --- a/samples/Javascript/Shared +++ b/samples/Javascript/Shared @@ -1 +1 @@ -Subproject commit 148868f7f4407a12444f07cb5e5378b1dbd7511c +Subproject commit 24c7cad588c85c5ddc83d1a380203913607ebd4a From 48a95cfa553bd1fc58ec364258847561bb293d8b Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 23 Dec 2013 20:29:05 +0800 Subject: [PATCH 23/35] [Lua Binding] Supports to bind more container: std::vector, std::vector, cocos2d::Map. --- .../lua/bindings/LuaBasicConversions.cpp | 75 ++++++++++++++++++- .../lua/bindings/LuaBasicConversions.h | 67 ++++++++++++++++- 2 files changed, 135 insertions(+), 7 deletions(-) diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp index 6e96f48d6b..ad7bdeb666 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp @@ -1425,14 +1425,81 @@ bool luaval_to_ccvaluevector(lua_State* L, int lo, cocos2d::ValueVector* ret) bool luaval_to_std_vector_string(lua_State* L, int lo, std::vector* ret) { - // TO BE DONE IN CPP FILE - return false; + if (nullptr == L || nullptr == ret || lua_gettop(L) < lo) + return false; + + tolua_Error tolua_err; + bool ok = true; + if (!tolua_istable(L, lo, 0, &tolua_err)) + { +#if COCOS2D_DEBUG >=1 + luaval_to_native_err(L,"#ferror:",&tolua_err); +#endif + ok = false; + } + + if (ok) + { + size_t len = lua_objlen(L, lo); + std::string value = ""; + for (int i = 0; i < len; i++) + { + lua_pushnumber(L, i + 1); + lua_gettable(L,lo); + if(lua_isstring(L, -1)) + { + ok = luaval_to_std_string(L, -1, &value); + if(ok) + ret->push_back(value); + } + else + { + CCASSERT(false, "string type is needed"); + } + + lua_pop(L, 1); + } + } + + return ok; } bool luaval_to_std_vector_int(lua_State* L, int lo, std::vector* ret) { - // TO BE DONE IN CPP FILE - return false; + if (nullptr == L || nullptr == ret || lua_gettop(L) < lo) + return false; + + tolua_Error tolua_err; + bool ok = true; + if (!tolua_istable(L, lo, 0, &tolua_err)) + { +#if COCOS2D_DEBUG >=1 + luaval_to_native_err(L,"#ferror:",&tolua_err); +#endif + ok = false; + } + + if (ok) + { + size_t len = lua_objlen(L, lo); + for (int i = 0; i < len; i++) + { + lua_pushnumber(L, i + 1); + lua_gettable(L,lo); + if(lua_isnumber(L, -1)) + { + ret->push_back((int)tolua_tonumber(L, -1, 0)); + } + else + { + CCASSERT(false, "int type is needed"); + } + + lua_pop(L, 1); + } + } + + return ok; } void point_to_luaval(lua_State* L,const Point& pt) diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.h b/cocos/scripting/lua/bindings/LuaBasicConversions.h index fe7f05b091..feaf396f70 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.h +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.h @@ -120,8 +120,47 @@ bool luaval_to_std_vector_int(lua_State* L, int lo, std::vector* ret); template bool luaval_to_ccmap_string_key(lua_State* L, int lo, cocos2d::Map* ret) { - // TO BE DONE: - return false; + if(nullptr == L || nullptr == ret || lua_gettop(L) < lo) + return false; + + tolua_Error tolua_err; + bool ok = true; + if (!tolua_istable(L, lo, 0, &tolua_err)) + { +#if COCOS2D_DEBUG >=1 + luaval_to_native_err(L,"#ferror:",&tolua_err); +#endif + ok = false; + } + + if (ok) + { + std::string stringKey = ""; + lua_pushnil(L); /* first key L: lotable ..... nil */ + while ( 0 != lua_next(L, lo ) ) /* L: lotable ..... key value */ + { + if (!lua_isstring(L, -2)) + { + lua_pop(L, 1); /* removes 'value'; keep 'key' for next iteration*/ + continue; + } + + if (lua_isnil(L, -1) || !lua_isuserdata(L, -1)) + { + lua_pop(L, 1); + continue; + } + + luaval_to_std_string(L, -2, &stringKey); + T obj = static_cast(tolua_tousertype(L, -1, NULL) ); + if (nullptr != obj) + ret->insert(stringKey, obj); + + lua_pop(L, 1); /* L: lotable ..... key */ + } + } + + return ok; } @@ -179,7 +218,29 @@ void ccvector_to_luaval(lua_State* L,const cocos2d::Vector& inValue) template void ccmap_string_key_to_luaval(lua_State* L, const cocos2d::Map& v) { - // TO BE DONE: + lua_newtable(L); + + if(nullptr == L) + return; + + for (auto iter = v.begin(); iter != v.end(); ++iter) + { + std::string key = iter->first; + T obj = iter->second; + if (nullptr != dynamic_cast(obj)) + { + std::string name = typeid(*obj).name(); + auto typeIter = g_luaType.find(name); + if (g_luaType.end() != typeIter) + { + lua_pushstring(L, name.c_str()); + int ID = (obj) ? (int)obj->_ID : -1; + int* luaID = (obj) ? &obj->_luaID : NULL; + toluafix_pushusertype_ccobject(L, ID, luaID, (void*)obj,typeIter->second.c_str()); + lua_rawset(L, -3); + } + } + } } void ccvalue_to_luaval(lua_State* L,const cocos2d::Value& inValue); From c3247c800f0d8809297417add97bbeb53a7ddb47 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 21:06:37 +0800 Subject: [PATCH 24/35] merge feature function from NewSprite into Sprite --- cocos/2d/CCSprite.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 5bbe9624c6..642e865aee 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -222,6 +222,7 @@ bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) // designated initializer bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) { + bool result; if (Node::init()) { _batchNode = nullptr; @@ -262,13 +263,15 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" setBatchNode(nullptr); - - return true; + result = true; } else { - return false; + result = false; } + _recursiveDirty = true; + setDirty(true); + return result; } Sprite::Sprite(void) @@ -694,7 +697,7 @@ bool Sprite::culling() const Rect newRect = RectApplyTransform(_rect, worldTM); kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ}; - + AABB aabb(point,point); kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ); aabb.expand(point); @@ -725,8 +728,8 @@ void Sprite::updateQuadVertices() // } // else // { -// CCASSERT( dynamic_cast(_parent), "Logic error in Sprite. Parent must be a Sprite"); -// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast(_parent)->_transformToBatch ); +// CCASSERT( dynamic_cast(_parent), "Logic error in Sprite. Parent must be a Sprite"); +// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast(_parent)->_transformToBatch ); // } //TODO optimize this transformation, should use parent's transformation instead From e66eb6464d41deb36c18716b2fc96329dab5e125 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 23 Dec 2013 21:07:25 +0800 Subject: [PATCH 25/35] use Sprite instead of NewSprite --- cocos/2d/CCLabelTTF.h | 2 +- .../NewRendererTest/NewRendererTest.cpp | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cocos/2d/CCLabelTTF.h b/cocos/2d/CCLabelTTF.h index 34ba14d1d4..5a1600b23a 100644 --- a/cocos/2d/CCLabelTTF.h +++ b/cocos/2d/CCLabelTTF.h @@ -54,7 +54,7 @@ NS_CC_BEGIN * @endcode * */ -class CC_DLL LabelTTF : public NewSprite, public LabelProtocol +class CC_DLL LabelTTF : public Sprite, public LabelProtocol { public: /** diff --git a/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp b/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp index 49b318a442..2d9432020e 100644 --- a/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NewRendererTest/NewRendererTest.cpp @@ -179,21 +179,21 @@ void NewSpriteTest::createNewSpriteTest() { Size winSize = Director::getInstance()->getWinSize(); - NewSprite* parent = NewSprite::create("Images/grossini.png"); + Sprite* parent = Sprite::create("Images/grossini.png"); parent->setPosition(winSize.width*2/3, winSize.height/2); - NewSprite* child1 = NewSprite::create("Images/grossinis_sister1.png"); + Sprite* child1 = Sprite::create("Images/grossinis_sister1.png"); child1->setPosition(0.0f, -20.0f); - NewSprite* child2 = NewSprite::create("Images/grossinis_sister2.png"); + Sprite* child2 = Sprite::create("Images/grossinis_sister2.png"); child2->setPosition(20.0f, -20.0f); - NewSprite* child3 = NewSprite::create("Images/grossinis_sister1.png"); + Sprite* child3 = Sprite::create("Images/grossinis_sister1.png"); child3->setPosition(40.0f, -20.0f); - NewSprite* child4 = NewSprite::create("Images/grossinis_sister2.png"); + Sprite* child4 = Sprite::create("Images/grossinis_sister2.png"); child4->setPosition(60.0f, -20.0f); - NewSprite* child5 = NewSprite::create("Images/grossinis_sister2.png"); + Sprite* child5 = Sprite::create("Images/grossinis_sister2.png"); child5->setPosition(80.0f, -20.0f); - NewSprite* child6 = NewSprite::create("Images/grossinis_sister2.png"); + Sprite* child6 = Sprite::create("Images/grossinis_sister2.png"); child6->setPosition(100.0f, -20.0f); - NewSprite* child7 = NewSprite::create("Images/grossinis_sister2.png"); + Sprite* child7 = Sprite::create("Images/grossinis_sister2.png"); child7->setPosition(120.0f, -20.0f); parent->addChild(child1); @@ -266,7 +266,7 @@ void NewSpriteBatchTest::addNewSpriteWithCoords(Point p) int y = (idx/5) * 121; - auto sprite = NewSprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121)); + auto sprite = Sprite::createWithTexture(BatchNode->getTexture(), Rect(x,y,85,121)); BatchNode->addChild(sprite); sprite->setPosition( Point( p.x, p.y) ); @@ -318,11 +318,11 @@ NewClippingNodeTest::NewClippingNodeTest() //Test with alpha Test clipper->setAlphaThreshold(0.05f); - auto stencil = NewSprite::create("Images/grossini.png"); + auto stencil = Sprite::create("Images/grossini.png"); stencil->setPosition(s.width/2, s.height/2); clipper->setStencil(stencil); - auto content = NewSprite::create("Images/background2.png"); + auto content = Sprite::create("Images/background2.png"); content->setTag( kTagContentNode ); content->setAnchorPoint( Point(0.5, 0.5) ); content->setPosition( Point(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) ); @@ -448,7 +448,7 @@ NewCullingTest::NewCullingTest() parent->addChild(parent2); parent2->setPosition(-50,0); parent2->runAction(RepeatForever::create((JumpBy::create(10, Point(0,0), 400, 1)))); - NewSprite* sprite = NewSprite::create(images[index % images.size()].c_str()); + Sprite* sprite = Sprite::create(images[index % images.size()].c_str()); sprite->setPosition(Point(0,0)); //sprite->runAction(RepeatForever::create(RotateBy::create(3, 360))); sprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(2, 2), ScaleBy::create(2,0.5)))); @@ -461,7 +461,7 @@ NewCullingTest::NewCullingTest() parent->addChild(parent2); parent2->setPosition(50,0); parent2->runAction(RepeatForever::create((JumpBy::create(7, Point(0,0), 400, 1)))); - NewSprite* sprite = NewSprite::create(images[index % images.size()].c_str()); + Sprite* sprite = Sprite::create(images[index % images.size()].c_str()); sprite->setPosition(Point(0,0)); //sprite->runAction(RepeatForever::create(RotateBy::create(3, 360))); sprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(ScaleBy::create(2, 2), ScaleBy::create(2,0.5)))); From b08995ae67138e530a9f29c6376ce181a5828209 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 21:14:55 +0800 Subject: [PATCH 26/35] Updates JS-tests to the latest version. --- samples/Javascript/Shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Javascript/Shared b/samples/Javascript/Shared index 24c7cad588..fda861cde4 160000 --- a/samples/Javascript/Shared +++ b/samples/Javascript/Shared @@ -1 +1 @@ -Subproject commit 24c7cad588c85c5ddc83d1a380203913607ebd4a +Subproject commit fda861cde4387948e95811966d9c4ceea04dc758 From cc7aa1ee0dd02269106cde2c616f99307a6f4a4c Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 23 Dec 2013 13:45:59 +0000 Subject: [PATCH 27/35] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 6d602f693d..67d2c21cc9 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 6d602f693d2bb8c92fc860509bc93f8f55a01bf1 +Subproject commit 67d2c21cc9c6b1c35fc64e7aaa3ceda113cfff5b From 5f17984826e54f9fcd8a30c7d41c13ee59256e88 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 21:53:23 +0800 Subject: [PATCH 28/35] =?UTF-8?q?Don=E2=80=99t=20hide=20parent=E2=80=99s?= =?UTF-8?q?=20addChild=20method=20in=20TMXLayer=20class.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/2d/CCTMXLayer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/2d/CCTMXLayer.h b/cocos/2d/CCTMXLayer.h index b2d254fac4..31cd4b9cbd 100644 --- a/cocos/2d/CCTMXLayer.h +++ b/cocos/2d/CCTMXLayer.h @@ -185,6 +185,7 @@ public: /** TMXLayer doesn't support adding a Sprite manually. @warning addchild(z, tag); is not supported on TMXLayer. Instead of setTileGID. */ + using SpriteBatchNode::addChild; virtual void addChild(Node * child, int zOrder, int tag) override; // super method void removeChild(Node* child, bool cleanup) override; From 3327614a999945668d0dc23928b92a37a8ff9aab Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 21:54:02 +0800 Subject: [PATCH 29/35] Binds Node::setAnchorPoint manually. --- .../javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id | 2 +- tools/tojs/cocos2dx.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id index 4e31a5e98a..333d98180a 100644 --- a/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id +++ b/cocos/scripting/javascript/bindings/cocos2d_specifics.cpp.REMOVED.git-id @@ -1 +1 @@ -3ea69b3bde8950d0af9d3a2d25c04bdb0e085f00 \ No newline at end of file +4ff49d7d50964fb117a48243d728d75dd6d5ef77 \ No newline at end of file diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index ba177b8a27..b95333b068 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -37,7 +37,7 @@ classes_need_extend = Node Layer.* Sprite MenuItemFont Scene DrawNode # will apply to all class names. This is a convenience wildcard to be able to skip similar named # functions from all classes. -skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule setContentSize], +skip = Node::[^setPosition$ setGrid setGLServerState description getUserObject .*UserData getGLServerState .*schedule setContentSize setAnchorPoint], Sprite::[getQuad getBlendFunc ^setPosition$ setBlendFunc], SpriteBatchNode::[getBlendFunc setBlendFunc getDescendants], MotionStreak::[getBlendFunc setBlendFunc draw update], From d6850c363aabb6a53b19d8cbf6360901e79ec421 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Dec 2013 22:00:11 +0800 Subject: [PATCH 30/35] Updates Bindings-generator. --- tools/bindings-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bindings-generator b/tools/bindings-generator index 5f412d0b3a..1b34f5852f 160000 --- a/tools/bindings-generator +++ b/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 5f412d0b3a4eadba3d2abd750de87d1b0e219e0a +Subproject commit 1b34f5852fcf494499be7eb5ce2bada72a0b16a2 From a9d8a64e6378f1bbda8e44195bf8ee930c92de21 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 23 Dec 2013 14:10:01 +0000 Subject: [PATCH 31/35] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 67d2c21cc9..ae83bfe510 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 67d2c21cc9c6b1c35fc64e7aaa3ceda113cfff5b +Subproject commit ae83bfe510cf81f2185b68b5fbca92c816a1c856 From 8d58e43ad2b62a6edb1e4a089b155eb43e64f494 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 24 Dec 2013 09:40:00 +0800 Subject: [PATCH 32/35] remove Class NewSprite --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos/2d/CCLabelTTF.h | 2 +- cocos/2d/cocos2d.h | 1 - cocos/2d/renderer/CCNewSprite.cpp | 165 ------------------ cocos/2d/renderer/CCNewSprite.h | 54 ------ cocos/2d/renderer/CCNewSpriteBatchNode.cpp | 1 - 6 files changed, 2 insertions(+), 223 deletions(-) delete mode 100644 cocos/2d/renderer/CCNewSprite.cpp delete mode 100644 cocos/2d/renderer/CCNewSprite.h diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 0b1a05e0fa..fc0676082c 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -4b776594c76318354842113d2274acda51fe9178 \ No newline at end of file +d5c3a61431f7098ddeabd3d035d501e3cc02c6b1 \ No newline at end of file diff --git a/cocos/2d/CCLabelTTF.h b/cocos/2d/CCLabelTTF.h index 5a1600b23a..c9d4f9de26 100644 --- a/cocos/2d/CCLabelTTF.h +++ b/cocos/2d/CCLabelTTF.h @@ -25,8 +25,8 @@ THE SOFTWARE. #ifndef __CCLABELTTF_H__ #define __CCLABELTTF_H__ -#include "renderer/CCNewSprite.h" #include "CCTexture2D.h" +#include "CCSprite.h" NS_CC_BEGIN diff --git a/cocos/2d/cocos2d.h b/cocos/2d/cocos2d.h index 64be8231b2..6a3881e960 100644 --- a/cocos/2d/cocos2d.h +++ b/cocos/2d/cocos2d.h @@ -119,7 +119,6 @@ THE SOFTWARE. #include "CCParticleSystemQuad.h" // new renderer -#include "renderer/CCNewSprite.h" #include "renderer/CCNewSpriteBatchNode.h" #include "renderer/CCCustomCommand.h" #include "renderer/CCFrustum.h" diff --git a/cocos/2d/renderer/CCNewSprite.cpp b/cocos/2d/renderer/CCNewSprite.cpp deleted file mode 100644 index 6cbd62cb97..0000000000 --- a/cocos/2d/renderer/CCNewSprite.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#include "CCNewSprite.h" -#include "CCRenderer.h" -#include "CCFrustum.h" -#include "CCDirector.h" -#include "CCQuadCommand.h" - -NS_CC_BEGIN - -#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL -#define RENDER_IN_SUBPIXEL -#else -#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__)) -#endif - -NewSprite* NewSprite::create() -{ - NewSprite* sprite = new NewSprite(); - if(sprite && sprite->init()) - { - sprite->autorelease(); - return sprite; - } - CC_SAFE_DELETE(sprite); - return nullptr; -} - -NewSprite* NewSprite::create(const char *filename) -{ - NewSprite* sprite = new NewSprite(); - if(sprite && sprite->initWithFile(filename)) - { - sprite->autorelease(); - return sprite; - } - CC_SAFE_DELETE(sprite); - return nullptr; -} - -NewSprite::NewSprite() -:Sprite() -{ - -} - -NewSprite::~NewSprite(void) -{ -} - -bool NewSprite::initWithTexture(Texture2D *texture, const Rect &rect, bool rotated) -{ - bool result = Sprite::initWithTexture(texture, rect, rotated); - _recursiveDirty = true; - setDirty(true); - return result; -} - -void NewSprite::updateQuadVertices() -{ -#ifdef CC_USE_PHYSICS - updatePhysicsTransform(); - setDirty(true); -#endif - - //TODO optimize the performance cache affineTransformation - - // recalculate matrix only if it is dirty - if(isDirty()) - { - -// if( ! _parent || _parent == (Node*)_batchNode ) -// { -// _transformToBatch = getNodeToParentTransform(); -// } -// else -// { -// CCASSERT( dynamic_cast(_parent), "Logic error in Sprite. Parent must be a Sprite"); -// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast(_parent)->_transformToBatch ); -// } - - //TODO optimize this transformation, should use parent's transformation instead - _transformToBatch = getNodeToWorldTransform(); - - // - // calculate the Quad based on the Affine Matrix - // - Rect newRect = RectApplyTransform(_rect, _transformToBatch); - - _quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMinX()), RENDER_IN_SUBPIXEL(newRect.getMinY()), _vertexZ ); - _quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMaxX()), RENDER_IN_SUBPIXEL(newRect.getMinY()), _vertexZ ); - _quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMinX()), RENDER_IN_SUBPIXEL(newRect.getMaxY()), _vertexZ ); - _quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMaxX()), RENDER_IN_SUBPIXEL(newRect.getMaxY()), _vertexZ ); - - _recursiveDirty = false; - setDirty(false); - } -} - -void NewSprite::draw(void) -{ - kmMat4 mv; - kmGLGetMatrix(KM_GL_MODELVIEW, &mv); - //TODO implement z order - QuadCommand* renderCommand = QuadCommand::getCommandPool().generateCommand(); - renderCommand->init(0, _vertexZ, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); - - if(!culling()) - { - renderCommand->releaseToCommandPool(); - return; - } - - Director::getInstance()->getRenderer()->addCommand(renderCommand); -} - -bool NewSprite::culling() const -{ - Frustum* frustum = Director::getInstance()->getFrustum(); - //TODO optimize this transformation, should use parent's transformation instead - kmMat4 worldTM = getNodeToWorldTransform(); - //generate aabb - - // - // calculate the Quad based on the Affine Matrix - // - Rect newRect = RectApplyTransform(_rect, worldTM); - - kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ}; - - AABB aabb(point,point); - kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ); - aabb.expand(point); - kmVec3Fill(&point,newRect.getMinX(), newRect.getMaxY(), _vertexZ); - aabb.expand(point); - kmVec3Fill(&point,newRect.getMaxX(), newRect.getMaxY(), _vertexZ); - aabb.expand(point); - - return Frustum::IntersectResult::OUTSIDE !=frustum->intersectAABB(aabb); -} - - -NS_CC_END \ No newline at end of file diff --git a/cocos/2d/renderer/CCNewSprite.h b/cocos/2d/renderer/CCNewSprite.h deleted file mode 100644 index aeda67ab50..0000000000 --- a/cocos/2d/renderer/CCNewSprite.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#ifndef __CCNEWSPRITE_H_ -#define __CCNEWSPRITE_H_ - -#include "CCSprite.h" -#include "CCPlatformMacros.h" - -NS_CC_BEGIN - -class NewSprite : public Sprite -{ - -public: - static NewSprite* create(); - static NewSprite* create(const char *filename); - - virtual void updateQuadVertices(); - virtual void draw(void) override; - - bool culling() const; - -protected: - NewSprite(void); - ~NewSprite(); - - virtual bool initWithTexture(Texture2D *texture, const Rect& rect, bool rotated); -}; - -NS_CC_END - -#endif /* defined(__CCNEWSPRITE_H_) */ diff --git a/cocos/2d/renderer/CCNewSpriteBatchNode.cpp b/cocos/2d/renderer/CCNewSpriteBatchNode.cpp index 07aa234fce..b8fe266f03 100644 --- a/cocos/2d/renderer/CCNewSpriteBatchNode.cpp +++ b/cocos/2d/renderer/CCNewSpriteBatchNode.cpp @@ -27,7 +27,6 @@ #include "CCShaderCache.h" #include "CCTextureCache.h" #include "CCSprite.h" -#include "CCNewSprite.h" #include "CCQuadCommand.h" #include "CCRenderer.h" From 8310c18105ba20591ddd8e367f54d9b9d3922da7 Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Tue, 24 Dec 2013 10:07:53 +0800 Subject: [PATCH 33/35] update project file: android and linux --- cocos/2d/Android.mk | 1 - cocos/2d/CMakeLists.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/cocos/2d/Android.mk b/cocos/2d/Android.mk index 62d43cfe5c..48f9f7bffd 100644 --- a/cocos/2d/Android.mk +++ b/cocos/2d/Android.mk @@ -117,7 +117,6 @@ platform/CCEGLViewProtocol.cpp \ platform/CCFileUtils.cpp \ platform/CCSAXParser.cpp \ platform/CCThread.cpp \ -renderer/CCNewSprite.cpp \ renderer/CCNewSpriteBatchNode.cpp \ renderer/CCCustomCommand.cpp \ renderer/CCFrustum.cpp \ diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 4f9918efdb..a574fecac1 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -139,7 +139,6 @@ set(COCOS2D_SRC platform/CCEGLViewProtocol.cpp platform/CCFileUtils.cpp ../../external/edtaa3func/edtaa3func.cpp - renderer/CCNewSprite.cpp renderer/CCNewSpriteBatchNode.cpp renderer/CCCustomCommand.cpp renderer/CCFrustum.cpp From d22f2aaf6786debc9201a2e64b933704672c77e7 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 24 Dec 2013 02:28:17 +0000 Subject: [PATCH 34/35] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index ae83bfe510..3b8073deee 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit ae83bfe510cf81f2185b68b5fbca92c816a1c856 +Subproject commit 3b8073deee86beb5ede81a24e3ccbfef711bfa41 From 325f2e21a76413a47e2e114fca66d4ced04a651b Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 24 Dec 2013 10:41:45 +0800 Subject: [PATCH 35/35] =?UTF-8?q?[JSB]=20long=20=E2=80=94>=20ssize=5Ft=20i?= =?UTF-8?q?n=20JSB=5FTableViewDataSource::callJSDelegate.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bindings/extension/jsb_cocos2dx_extension_manual.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/scripting/javascript/bindings/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/javascript/bindings/extension/jsb_cocos2dx_extension_manual.cpp index beea364b4b..6d27aa81a7 100644 --- a/cocos/scripting/javascript/bindings/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/javascript/bindings/extension/jsb_cocos2dx_extension_manual.cpp @@ -350,7 +350,7 @@ private: return false; } - bool callJSDelegate(TableView* table, long idx, std::string jsFunctionName, jsval& retVal) + bool callJSDelegate(TableView* table, ssize_t idx, std::string jsFunctionName, jsval& retVal) { js_proxy_t * p = jsb_get_native_proxy(table); if (!p) return false; @@ -360,7 +360,7 @@ private: JS::RootedValue temp_retval(cx); jsval dataVal[2]; dataVal[0] = OBJECT_TO_JSVAL(p->obj); - dataVal[1] = long_to_jsval(cx,idx); + dataVal[1] = ssize_to_jsval(cx,idx); JSObject* obj = _JSTableViewDataSource; JSAutoCompartment ac(cx, obj); @@ -377,9 +377,9 @@ private: return false; } - JS_CallFunctionName(cx, obj, jsFunctionName.c_str(), + JSBool ret = JS_CallFunctionName(cx, obj, jsFunctionName.c_str(), 2, dataVal, &retVal); - return true; + return ret == JS_TRUE ? true : false; } return false; }