Skip to content

Commit 4a9b5c6

Browse files
committed
Merge commit '639737286f594f3e06c07b22b352dddb01858883' into scgamex-v3
* commit '639737286f594f3e06c07b22b352dddb01858883': before draw event (cocos2d#17669) Handle auto layout with scaled widget (cocos2d#17822) fix to problem with updating APK in Google Play keeping old OBB (cocos2d#17689) update console to fix compiling issue on with Xcode 8.3+ (cocos2d#17862) Fix iskindof (cocos2d#17785) [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#17857) fix action running times for instant actions (cocos2d#17849) make fps stable on iOS (cocos2d#17852) [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (cocos2d#17848) LayerRadialGradient works on mac and iOS (cocos2d#17826) Fixing serious XMLHTTP leak when CC_ENABLE_GC_FOR_NATIVE_OBJECTS enabled (cocos2d#17844) Call 'update' method in 'stop/stopAll' to cleanup immediately (cocos2d#17846) Add const keyword to Node::isScheduled (cocos2d#17841) small BillBoard optimizations (cocos2d#17825) Allow visit Sprite without camera for render to texture (cocos2d#17824) # Conflicts: # cocos/base/CCDirector.cpp # cocos/base/CCDirector.h # cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp # cocos/ui/UILayoutManager.cpp # tools/cocos2d-console
2 parents faf9182 + 6397372 commit 4a9b5c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3024
-140
lines changed

build/cocos2d_libs.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6654,6 +6654,10 @@
66546654
46A170781807CE7A005B8026 /* CCPhysicsWorld.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorld.h; sourceTree = "<group>"; };
66556655
46C02E0518E91123004B7456 /* xxhash.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xxhash.c; sourceTree = "<group>"; };
66566656
46C02E0618E91123004B7456 /* xxhash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xxhash.h; sourceTree = "<group>"; };
6657+
46E7207B1ECAC75C0034BEC7 /* ccShader_ETC1AS_PositionTextureColor.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_ETC1AS_PositionTextureColor.frag; sourceTree = "<group>"; };
6658+
46E7207C1ECAC75C0034BEC7 /* ccShader_ETC1AS_PositionTextureGray.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_ETC1AS_PositionTextureGray.frag; sourceTree = "<group>"; };
6659+
46E7207E1ECAC75C0034BEC7 /* ccShader_Position.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_Position.vert; sourceTree = "<group>"; };
6660+
46E7207F1ECACB750034BEC7 /* ccShader_LayerRadialGradient.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_LayerRadialGradient.frag; sourceTree = "<group>"; };
66576661
4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCActionTimelineNode.cpp; sourceTree = "<group>"; };
66586662
4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCActionTimelineNode.h; sourceTree = "<group>"; };
66596663
5012168C1AC47380009A4BEA /* CCRenderState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCRenderState.cpp; sourceTree = "<group>"; };
@@ -10032,6 +10036,10 @@
1003210036
5034CA5D191D591900CE6051 /* shaders */ = {
1003310037
isa = PBXGroup;
1003410038
children = (
10039+
46E7207F1ECACB750034BEC7 /* ccShader_LayerRadialGradient.frag */,
10040+
46E7207B1ECAC75C0034BEC7 /* ccShader_ETC1AS_PositionTextureColor.frag */,
10041+
46E7207C1ECAC75C0034BEC7 /* ccShader_ETC1AS_PositionTextureGray.frag */,
10042+
46E7207E1ECAC75C0034BEC7 /* ccShader_Position.vert */,
1003510043
B241A6E21AFB0BE700C5623C /* ccShader_CameraClear.frag */,
1003610044
B241A6E31AFB0BE700C5623C /* ccShader_CameraClear.vert */,
1003710045
B603F1B11AC8F1FD00A9579C /* ccShader_3D_Terrain.frag */,

cocos/2d/CCActionInterval.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,14 @@ void RepeatForever::startWithTarget(Node* target)
596596
void RepeatForever::step(float dt)
597597
{
598598
_innerAction->step(dt);
599-
if (_innerAction->isDone())
599+
// only action interval should prevent jerk, issue #17808
600+
if (_innerAction->isDone() && _innerAction->getDuration() > 0)
600601
{
601602
float diff = _innerAction->getElapsed() - _innerAction->getDuration();
602603
if (diff > _innerAction->getDuration())
603604
diff = fmodf(diff, _innerAction->getDuration());
604605
_innerAction->startWithTarget(_target);
605-
// to prevent jerk. issue #390, 1247
606+
// to prevent jerk. cocos2d-iphone issue #390, 1247
606607
_innerAction->step(0.0f);
607608
_innerAction->step(diff);
608609
}

cocos/2d/CCLayer.cpp

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ THE SOFTWARE.
4242
#include "base/CCEventListenerAcceleration.h"
4343
#include "base/ccUTF8.h"
4444

45+
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
46+
#include "platform/desktop/CCGLViewImpl-desktop.h"
47+
#endif
48+
4549
NS_CC_BEGIN
4650

4751
// Layer
@@ -843,6 +847,245 @@ std::string LayerGradient::getDescription() const
843847
return StringUtils::format("<LayerGradient | Tag = %d>", _tag);
844848
}
845849

850+
/**
851+
* LayerRadialGradient
852+
*/
853+
LayerRadialGradient* LayerRadialGradient::create(const Color4B& startColor, const Color4B& endColor, float radius, const Vec2& center, float expand)
854+
{
855+
auto layerGradient = new LayerRadialGradient();
856+
if (layerGradient && layerGradient->initWithColor(startColor, endColor, radius, center, expand))
857+
{
858+
layerGradient->autorelease();
859+
return layerGradient;
860+
}
861+
862+
delete layerGradient;
863+
return nullptr;
864+
}
865+
866+
LayerRadialGradient* LayerRadialGradient::create()
867+
{
868+
auto layerGradient = new LayerRadialGradient();
869+
if (layerGradient && layerGradient->initWithColor(Color4B::BLACK, Color4B::BLACK, 0, Vec2(0,0), 0))
870+
{
871+
layerGradient->autorelease();
872+
return layerGradient;
873+
}
874+
875+
delete layerGradient;
876+
return nullptr;
877+
}
878+
879+
LayerRadialGradient::LayerRadialGradient()
880+
: _startColor(Color4B::BLACK)
881+
, _startColorRend(Color4F::BLACK)
882+
, _endColor(Color4B::BLACK)
883+
, _endColorRend(Color4F::BLACK)
884+
, _radius(0.f)
885+
, _expand(0.f)
886+
, _center(Vec2(0,0))
887+
, _uniformLocationCenter(0)
888+
, _uniformLocationRadius(0)
889+
, _uniformLocationExpand(0)
890+
, _uniformLocationEndColor(0)
891+
, _uniformLocationStartColor(0)
892+
, _blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED)
893+
{ }
894+
895+
LayerRadialGradient::~LayerRadialGradient()
896+
{}
897+
898+
bool LayerRadialGradient::initWithColor(const cocos2d::Color4B &startColor, const cocos2d::Color4B &endColor, float radius, const Vec2& center, float expand)
899+
{
900+
// should do it before Layer::init()
901+
for (int i = 0; i < 4; ++i)
902+
_vertices[i] = {0.0f, 0.0f};
903+
904+
if (Layer::init())
905+
{
906+
convertColor4B24F(_startColorRend, startColor);
907+
_startColor = startColor;
908+
909+
convertColor4B24F(_endColorRend, endColor);
910+
_endColor = endColor;
911+
912+
_expand = expand;
913+
914+
setRadius(radius);
915+
setCenter(center);
916+
917+
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_LAYER_RADIAL_GRADIENT));
918+
auto program = getGLProgram();
919+
_uniformLocationStartColor = program->getUniformLocation("u_startColor");
920+
_uniformLocationEndColor = program->getUniformLocation("u_endColor");
921+
_uniformLocationExpand = program->getUniformLocation("u_expand");
922+
_uniformLocationRadius = program->getUniformLocation("u_radius");
923+
_uniformLocationCenter = program->getUniformLocation("u_center");
924+
925+
return true;
926+
}
927+
928+
return false;
929+
}
930+
931+
void LayerRadialGradient::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
932+
{
933+
_customCommand.init(_globalZOrder, transform, flags);
934+
_customCommand.func = CC_CALLBACK_0(LayerRadialGradient::onDraw, this, transform, flags);
935+
renderer->addCommand(&_customCommand);
936+
}
937+
938+
void LayerRadialGradient::onDraw(const Mat4& transform, uint32_t /*flags*/)
939+
{
940+
auto program = getGLProgram();
941+
program->use();
942+
program->setUniformsForBuiltins(transform);
943+
program->setUniformLocationWith4f(_uniformLocationStartColor, _startColorRend.r,
944+
_startColorRend.g, _startColorRend.b, _startColorRend.a);
945+
program->setUniformLocationWith4f(_uniformLocationEndColor, _endColorRend.r,
946+
_endColorRend.g, _endColorRend.b, _endColorRend.a);
947+
program->setUniformLocationWith2f(_uniformLocationCenter, _center.x, _center.y);
948+
program->setUniformLocationWith1f(_uniformLocationRadius, _radius);
949+
program->setUniformLocationWith1f(_uniformLocationExpand, _expand);
950+
951+
952+
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION);
953+
954+
//
955+
// Attributes
956+
//
957+
glBindBuffer(GL_ARRAY_BUFFER, 0);
958+
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _vertices);
959+
960+
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
961+
962+
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
963+
964+
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,4);
965+
}
966+
967+
void LayerRadialGradient::setContentSize(const Size& size)
968+
{
969+
_vertices[1].x = size.width;
970+
_vertices[2].y = size.height;
971+
_vertices[3].x = size.width;
972+
_vertices[3].y = size.height;
973+
Layer::setContentSize(size);
974+
}
975+
976+
void LayerRadialGradient::setStartOpacity(GLubyte opacity)
977+
{
978+
_startColorRend.a = opacity / 255.0f;
979+
_startColor.a = opacity;
980+
}
981+
982+
GLubyte LayerRadialGradient::getStartOpacity() const
983+
{
984+
return _startColor.a;
985+
}
986+
987+
void LayerRadialGradient::setEndOpacity(GLubyte opacity)
988+
{
989+
_endColorRend.a = opacity / 255.0f;
990+
_endColor.a = opacity;
991+
}
992+
993+
GLubyte LayerRadialGradient::getEndOpacity() const
994+
{
995+
return _endColor.a;
996+
}
997+
998+
void LayerRadialGradient::setRadius(float radius)
999+
{
1000+
_radius = radius;
1001+
}
1002+
1003+
float LayerRadialGradient::getRadius() const
1004+
{
1005+
return _radius;
1006+
}
1007+
1008+
void LayerRadialGradient::setCenter(const Vec2& center)
1009+
{
1010+
_center = center;
1011+
}
1012+
1013+
Vec2 LayerRadialGradient::getCenter() const
1014+
{
1015+
return _center;
1016+
}
1017+
1018+
void LayerRadialGradient::setExpand(float expand)
1019+
{
1020+
_expand = expand;
1021+
}
1022+
1023+
float LayerRadialGradient::getExpand() const
1024+
{
1025+
return _expand;
1026+
}
1027+
1028+
void LayerRadialGradient::setStartColor(const Color3B& color)
1029+
{
1030+
setStartColor(Color4B(color));
1031+
}
1032+
1033+
void LayerRadialGradient::setStartColor(const cocos2d::Color4B &color)
1034+
{
1035+
_startColor = color;
1036+
convertColor4B24F(_startColorRend, _startColor);
1037+
}
1038+
1039+
Color4B LayerRadialGradient::getStartColor() const
1040+
{
1041+
return _startColor;
1042+
}
1043+
1044+
Color3B LayerRadialGradient::getStartColor3B() const
1045+
{
1046+
return Color3B(_startColor);
1047+
}
1048+
1049+
void LayerRadialGradient::setEndColor(const Color3B& color)
1050+
{
1051+
setEndColor(Color4B(color));
1052+
}
1053+
1054+
void LayerRadialGradient::setEndColor(const cocos2d::Color4B &color)
1055+
{
1056+
_endColor = color;
1057+
convertColor4B24F(_endColorRend, _endColor);
1058+
}
1059+
1060+
Color4B LayerRadialGradient::getEndColor() const
1061+
{
1062+
return _endColor;
1063+
}
1064+
1065+
Color3B LayerRadialGradient::getEndColor3B() const
1066+
{
1067+
return Color3B(_endColor);
1068+
}
1069+
1070+
void LayerRadialGradient::setBlendFunc(const BlendFunc& blendFunc)
1071+
{
1072+
_blendFunc = blendFunc;
1073+
}
1074+
1075+
BlendFunc LayerRadialGradient::getBlendFunc() const
1076+
{
1077+
return _blendFunc;
1078+
}
1079+
1080+
void LayerRadialGradient::convertColor4B24F(Color4F& outColor, const Color4B& inColor)
1081+
{
1082+
outColor.r = inColor.r / 255.0f;
1083+
outColor.g = inColor.g / 255.0f;
1084+
outColor.b = inColor.b / 255.0f;
1085+
outColor.a = inColor.a / 255.0f;
1086+
}
1087+
1088+
8461089
/// MultiplexLayer
8471090

8481091
LayerMultiplex::LayerMultiplex()

cocos/2d/CCLayer.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,93 @@ class CC_DLL LayerGradient : public LayerColor
564564
};
565565

566566

567+
/** @class LayerRadialGradient
568+
* @brief LayerRadialGradient is a subclass of Layer that draws radial gradients across the background.
569+
@since v3.16
570+
*/
571+
class CC_DLL LayerRadialGradient : public Layer
572+
{
573+
public:
574+
/** Create a LayerRadialGradient
575+
* @param startColor the inner color of the gradient
576+
* @param endColor the out color of the gradient
577+
* @param radius the radius of the gradient(length from center of gradient to outer color)
578+
* @param center the position of the center of the gradient
579+
* @param expand an alpha value(0.f-1.f) that specifies how much of that radius in only inner color(the gradient
580+
starts outside of that amount)
581+
*/
582+
static LayerRadialGradient* create(const Color4B& startColor, const Color4B& endColor, float radius, const Vec2& center, float expand);
583+
static LayerRadialGradient* create();
584+
585+
//
586+
// overrides
587+
//
588+
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
589+
virtual void setContentSize(const Size& size) override;
590+
591+
void setStartOpacity(GLubyte opacity);
592+
GLubyte getStartOpacity() const;
593+
594+
void setEndOpacity(GLubyte opacity);
595+
GLubyte getEndOpacity() const;
596+
597+
void setRadius(float radius);
598+
float getRadius() const;
599+
600+
void setCenter(const Vec2& center);
601+
Vec2 getCenter() const;
602+
603+
void setExpand(float expand);
604+
float getExpand() const;
605+
606+
void setStartColor(const Color3B& color);
607+
void setStartColor(const Color4B& color);
608+
Color4B getStartColor() const;
609+
Color3B getStartColor3B() const;
610+
611+
void setEndColor(const Color3B& color);
612+
void setEndColor(const Color4B& color);
613+
Color4B getEndColor() const;
614+
Color3B getEndColor3B() const;
615+
616+
void setBlendFunc(const BlendFunc& blendFunc);
617+
BlendFunc getBlendFunc() const;
618+
619+
CC_CONSTRUCTOR_ACCESS:
620+
LayerRadialGradient();
621+
virtual ~LayerRadialGradient();
622+
623+
bool initWithColor(const Color4B& startColor, const Color4B& endColor, float radius, const Vec2& center, float expand);
624+
625+
protected:
626+
void onDraw(const Mat4& transform, uint32_t flags);
627+
628+
629+
private:
630+
void convertColor4B24F(Color4F& outColor, const Color4B& inColor);
631+
632+
Color4B _startColor;
633+
Color4F _startColorRend; // start color used in shader
634+
635+
Color4B _endColor;
636+
Color4F _endColorRend; // end color used in shader
637+
638+
Vec2 _center;
639+
float _radius;
640+
float _expand;
641+
Vec2 _vertices[4];
642+
CustomCommand _customCommand;
643+
644+
GLint _uniformLocationStartColor;
645+
GLint _uniformLocationEndColor;
646+
GLint _uniformLocationCenter;
647+
GLint _uniformLocationRadius;
648+
GLint _uniformLocationExpand;
649+
650+
BlendFunc _blendFunc;
651+
};
652+
653+
567654
/** @class LayerMultiplex
568655
* @brief MultipleLayer is a Layer with the ability to multiplex it's children.
569656
Features:

0 commit comments

Comments
 (0)