From 53bed4fda34b437455cac9809958d6d2f3354aaa Mon Sep 17 00:00:00 2001 From: Arnold <40414978+PatriceJiang@users.noreply.github.com> Date: Thu, 20 Sep 2018 15:18:03 +0800 Subject: [PATCH] DrawNode add isolate flag (#19056) * add isolate flag * add comment for DrawNode::visit * add modifier: const/virtual * update comment & change initializer --- cocos/2d/CCDrawNode.cpp | 32 ++++++++----------- cocos/2d/CCDrawNode.h | 53 +++++++++++++++++++------------- cocos/physics/CCPhysicsWorld.cpp | 1 + 3 files changed, 46 insertions(+), 40 deletions(-) diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 6a4b1923ab..53a9f6df6b 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -101,25 +101,7 @@ static inline Tex2F __t(const Vec2 &v) // implementation of DrawNode DrawNode::DrawNode(GLfloat lineWidth) -: _vao(0) -, _vbo(0) -, _vaoGLPoint(0) -, _vboGLPoint(0) -, _vaoGLLine(0) -, _vboGLLine(0) -, _bufferCapacity(0) -, _bufferCount(0) -, _buffer(nullptr) -, _bufferCapacityGLPoint(0) -, _bufferCountGLPoint(0) -, _bufferGLPoint(nullptr) -, _bufferCapacityGLLine(0) -, _bufferCountGLLine(0) -, _bufferGLLine(nullptr) -, _dirty(false) -, _dirtyGLPoint(false) -, _dirtyGLLine(false) -, _lineWidth(lineWidth) +: _lineWidth(lineWidth) , _defaultLineWidth(lineWidth) { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; @@ -957,5 +939,17 @@ GLfloat DrawNode::getLineWidth() return this->_lineWidth; } +void DrawNode::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags) +{ + if (_isolated) + { + //ignore `parentTransform` from parent + Node::visit(renderer, Mat4::IDENTITY, parentFlags); + } + else + { + Node::visit(renderer, parentTransform, parentFlags); + } +} NS_CC_END diff --git a/cocos/2d/CCDrawNode.h b/cocos/2d/CCDrawNode.h index aa2baec9ce..53bb157143 100644 --- a/cocos/2d/CCDrawNode.h +++ b/cocos/2d/CCDrawNode.h @@ -313,12 +313,22 @@ public: // Overrides virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; + + virtual void visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags) override; void setLineWidth(GLfloat lineWidth); // Get CocosStudio guide lines width. GLfloat getLineWidth(); + /** + * When isolated is set, the position of the node is no longer affected by parent nodes. + * Which means it will be drawn just like a root node. + */ + void setIsolated(bool isolated) { _isolated = isolated; } + + bool isIsolated() const { return _isolated; } + CC_CONSTRUCTOR_ACCESS: DrawNode(GLfloat lineWidth = DEFAULT_LINE_WIDTH); virtual ~DrawNode(); @@ -331,39 +341,40 @@ protected: void setupBuffer(); - GLuint _vao; - GLuint _vbo; - GLuint _vaoGLPoint; - GLuint _vboGLPoint; - GLuint _vaoGLLine; - GLuint _vboGLLine; + GLuint _vao = 0; + GLuint _vbo = 0; + GLuint _vaoGLPoint = 0; + GLuint _vboGLPoint = 0; + GLuint _vaoGLLine = 0; + GLuint _vboGLLine = 0; - int _bufferCapacity; - GLsizei _bufferCount; - V2F_C4B_T2F *_buffer; + int _bufferCapacity = 0; + GLsizei _bufferCount = 0; + V2F_C4B_T2F *_buffer = nullptr; - int _bufferCapacityGLPoint; - GLsizei _bufferCountGLPoint; - V2F_C4B_T2F *_bufferGLPoint; + int _bufferCapacityGLPoint = 0; + GLsizei _bufferCountGLPoint = 0; + V2F_C4B_T2F *_bufferGLPoint = nullptr; Color4F _pointColor; - int _pointSize; + int _pointSize = 0; - int _bufferCapacityGLLine; - GLsizei _bufferCountGLLine; - V2F_C4B_T2F *_bufferGLLine; + int _bufferCapacityGLLine = 0; + GLsizei _bufferCountGLLine = 0; + V2F_C4B_T2F *_bufferGLLine = nullptr; BlendFunc _blendFunc; CustomCommand _customCommand; CustomCommand _customCommandGLPoint; CustomCommand _customCommandGLLine; - bool _dirty; - bool _dirtyGLPoint; - bool _dirtyGLLine; + bool _dirty = false; + bool _dirtyGLPoint = false; + bool _dirtyGLLine = false; + bool _isolated = false; - GLfloat _lineWidth; + GLfloat _lineWidth = 0.0f; - GLfloat _defaultLineWidth; + GLfloat _defaultLineWidth = 0.0f; private: CC_DISALLOW_COPY_AND_ASSIGN(DrawNode); }; diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index cc85d005af..c3679da7ad 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -270,6 +270,7 @@ void PhysicsWorld::debugDraw() if (_debugDraw == nullptr) { _debugDraw = DrawNode::create(); + _debugDraw->setIsolated(true); _debugDraw->retain(); Director::getInstance()->getRunningScene()->addChild(_debugDraw); }