Skip to content

Commit 53bed4f

Browse files
PatriceJiangminggo
authored andcommitted
DrawNode add isolate flag (cocos2d#19056)
* add isolate flag * add comment for DrawNode::visit * add modifier: const/virtual * update comment & change initializer
1 parent f8ed20e commit 53bed4f

File tree

3 files changed

+46
-40
lines changed

3 files changed

+46
-40
lines changed

cocos/2d/CCDrawNode.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,7 @@ static inline Tex2F __t(const Vec2 &v)
101101
// implementation of DrawNode
102102

103103
DrawNode::DrawNode(GLfloat lineWidth)
104-
: _vao(0)
105-
, _vbo(0)
106-
, _vaoGLPoint(0)
107-
, _vboGLPoint(0)
108-
, _vaoGLLine(0)
109-
, _vboGLLine(0)
110-
, _bufferCapacity(0)
111-
, _bufferCount(0)
112-
, _buffer(nullptr)
113-
, _bufferCapacityGLPoint(0)
114-
, _bufferCountGLPoint(0)
115-
, _bufferGLPoint(nullptr)
116-
, _bufferCapacityGLLine(0)
117-
, _bufferCountGLLine(0)
118-
, _bufferGLLine(nullptr)
119-
, _dirty(false)
120-
, _dirtyGLPoint(false)
121-
, _dirtyGLLine(false)
122-
, _lineWidth(lineWidth)
104+
: _lineWidth(lineWidth)
123105
, _defaultLineWidth(lineWidth)
124106
{
125107
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@@ -957,5 +939,17 @@ GLfloat DrawNode::getLineWidth()
957939
return this->_lineWidth;
958940
}
959941

942+
void DrawNode::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)
943+
{
944+
if (_isolated)
945+
{
946+
//ignore `parentTransform` from parent
947+
Node::visit(renderer, Mat4::IDENTITY, parentFlags);
948+
}
949+
else
950+
{
951+
Node::visit(renderer, parentTransform, parentFlags);
952+
}
953+
}
960954

961955
NS_CC_END

cocos/2d/CCDrawNode.h

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,22 @@ class CC_DLL DrawNode : public Node
313313

314314
// Overrides
315315
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
316+
317+
virtual void visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags) override;
316318

317319
void setLineWidth(GLfloat lineWidth);
318320

319321
// Get CocosStudio guide lines width.
320322
GLfloat getLineWidth();
321323

324+
/**
325+
* When isolated is set, the position of the node is no longer affected by parent nodes.
326+
* Which means it will be drawn just like a root node.
327+
*/
328+
void setIsolated(bool isolated) { _isolated = isolated; }
329+
330+
bool isIsolated() const { return _isolated; }
331+
322332
CC_CONSTRUCTOR_ACCESS:
323333
DrawNode(GLfloat lineWidth = DEFAULT_LINE_WIDTH);
324334
virtual ~DrawNode();
@@ -331,39 +341,40 @@ class CC_DLL DrawNode : public Node
331341

332342
void setupBuffer();
333343

334-
GLuint _vao;
335-
GLuint _vbo;
336-
GLuint _vaoGLPoint;
337-
GLuint _vboGLPoint;
338-
GLuint _vaoGLLine;
339-
GLuint _vboGLLine;
344+
GLuint _vao = 0;
345+
GLuint _vbo = 0;
346+
GLuint _vaoGLPoint = 0;
347+
GLuint _vboGLPoint = 0;
348+
GLuint _vaoGLLine = 0;
349+
GLuint _vboGLLine = 0;
340350

341-
int _bufferCapacity;
342-
GLsizei _bufferCount;
343-
V2F_C4B_T2F *_buffer;
351+
int _bufferCapacity = 0;
352+
GLsizei _bufferCount = 0;
353+
V2F_C4B_T2F *_buffer = nullptr;
344354

345-
int _bufferCapacityGLPoint;
346-
GLsizei _bufferCountGLPoint;
347-
V2F_C4B_T2F *_bufferGLPoint;
355+
int _bufferCapacityGLPoint = 0;
356+
GLsizei _bufferCountGLPoint = 0;
357+
V2F_C4B_T2F *_bufferGLPoint = nullptr;
348358
Color4F _pointColor;
349-
int _pointSize;
359+
int _pointSize = 0;
350360

351-
int _bufferCapacityGLLine;
352-
GLsizei _bufferCountGLLine;
353-
V2F_C4B_T2F *_bufferGLLine;
361+
int _bufferCapacityGLLine = 0;
362+
GLsizei _bufferCountGLLine = 0;
363+
V2F_C4B_T2F *_bufferGLLine = nullptr;
354364

355365
BlendFunc _blendFunc;
356366
CustomCommand _customCommand;
357367
CustomCommand _customCommandGLPoint;
358368
CustomCommand _customCommandGLLine;
359369

360-
bool _dirty;
361-
bool _dirtyGLPoint;
362-
bool _dirtyGLLine;
370+
bool _dirty = false;
371+
bool _dirtyGLPoint = false;
372+
bool _dirtyGLLine = false;
373+
bool _isolated = false;
363374

364-
GLfloat _lineWidth;
375+
GLfloat _lineWidth = 0.0f;
365376

366-
GLfloat _defaultLineWidth;
377+
GLfloat _defaultLineWidth = 0.0f;
367378
private:
368379
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode);
369380
};

cocos/physics/CCPhysicsWorld.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ void PhysicsWorld::debugDraw()
270270
if (_debugDraw == nullptr)
271271
{
272272
_debugDraw = DrawNode::create();
273+
_debugDraw->setIsolated(true);
273274
_debugDraw->retain();
274275
Director::getInstance()->getRunningScene()->addChild(_debugDraw);
275276
}

0 commit comments

Comments
 (0)