From 6920bec6efcf5e806475880b07eed9a45c01b7d3 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 28 Feb 2014 11:20:53 -0800 Subject: [PATCH] transform object returns the MV code cleaner. the kmGL code is altogether --- cocos/2d/CCClippingNode.cpp | 11 ++++++-- cocos/2d/CCLabel.cpp | 11 ++++++-- cocos/2d/CCNode.cpp | 28 +++++++++---------- cocos/2d/CCNode.h | 2 +- cocos/2d/CCNodeGrid.cpp | 14 +++++++--- cocos/2d/CCParticleBatchNode.cpp | 10 +++++-- cocos/2d/CCRenderTexture.cpp | 10 +++++-- cocos/2d/CCSpriteBatchNode.cpp | 10 +++++-- .../editor-support/cocostudio/CCArmature.cpp | 10 +++++-- .../editor-support/cocostudio/CCBatchNode.cpp | 9 ++++-- cocos/gui/UILayout.cpp | 10 +++++-- extensions/GUI/CCScrollView/CCScrollView.cpp | 10 +++++-- .../ClippingNodeTest/ClippingNodeTest.cpp | 4 +-- 13 files changed, 94 insertions(+), 45 deletions(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 4fe5438493..6417e9e458 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -204,11 +204,16 @@ void ClippingNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool if(!_visible) return; - kmGLPushMatrix(); - bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); + //Add group command _groupCommand.init(_globalZOrder); diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 877d9f88a8..b0f488568f 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -693,11 +693,16 @@ void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parent return; } - kmGLPushMatrix(); - bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); + draw(renderer, _modelViewTransform, dirty); kmGLPopMatrix(); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index fc59f584c2..1eca50367e 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -925,13 +925,17 @@ void Node::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentT { return; } - - kmGLPushMatrix(); bool dirty = _transformDirty || parentTransformDirty; - if(dirty) - this->transform(); + _modelViewTransform = this->transform(parentTransform); + + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); int i = 0; @@ -967,21 +971,17 @@ void Node::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentT void Node::transformAncestors() { - if( _parent != nullptr ) - { - _parent->transformAncestors(); - _parent->transform(); - } + // remove me + CCASSERT(false, "no longer supported"); } -void Node::transform() +kmMat4 Node::transform(const kmMat4& parentTransform) { + kmMat4 ret; kmMat4 transfrom4x4 = this->getNodeToParentTransform(); + kmMat4Multiply(&ret, &parentTransform, &transfrom4x4); - kmGLMultMatrix( &transfrom4x4 ); - - // saves the MV matrix - kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewTransform); + return ret; } void Node::onEnter() diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index c9911df79d..e9b04215d2 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1256,7 +1256,7 @@ public: /** * Performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes. */ - void transform(); + kmMat4 transform(const kmMat4 &parentTransform); /** * Performs OpenGL view-matrix transformation of it's ancestors. * Generally the ancestors are already transformed, but in certain cases (eg: attaching a FBO) diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 6fe62fb361..a94bfcecb0 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -94,7 +94,16 @@ void NodeGrid::visit(Renderer *renderer, const kmMat4 &parentTransform, bool par renderer->addCommand(&_groupCommand); renderer->pushGroup(_groupCommand.getRenderQueueID()); + bool dirty = parentTransformDirty || _transformDirty; + if(dirty) + _modelViewTransform = this->transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); + Director::Projection beforeProjectionType; if(_nodeGrid && _nodeGrid->isActive()) { @@ -106,10 +115,7 @@ void NodeGrid::visit(Renderer *renderer, const kmMat4 &parentTransform, bool par _gridBeginCommand.func = CC_CALLBACK_0(NodeGrid::onGridBeginDraw, this); renderer->addCommand(&_gridBeginCommand); - bool dirty = parentTransformDirty || _transformDirty; - if(dirty) - this->transform(); - + if(_gridTarget) { _gridTarget->visit(renderer, _modelViewTransform, dirty); diff --git a/cocos/2d/CCParticleBatchNode.cpp b/cocos/2d/CCParticleBatchNode.cpp index 5cc31db804..7f68da628b 100644 --- a/cocos/2d/CCParticleBatchNode.cpp +++ b/cocos/2d/CCParticleBatchNode.cpp @@ -134,11 +134,15 @@ void ParticleBatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, return; } - kmGLPushMatrix(); - bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); draw(renderer, _modelViewTransform, dirty); diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index 0b2397b866..91eaedae55 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -370,11 +370,15 @@ void RenderTexture::visit(Renderer *renderer, const kmMat4 &parentTransform, boo return; } - kmGLPushMatrix(); - bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); _sprite->visit(renderer, _modelViewTransform, dirty); draw(renderer, _modelViewTransform, dirty); diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 2c813aaeaa..f5d38a732b 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -147,13 +147,17 @@ void SpriteBatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, b return; } - kmGLPushMatrix(); - sortAllChildren(); bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); draw(renderer, _modelViewTransform, dirty); diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index c08ed2a87f..3599e9d867 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -452,11 +452,17 @@ void Armature::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, { return; } - kmGLPushMatrix(); bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); + sortAllChildren(); draw(renderer, _modelViewTransform, dirty); diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 6b2815b099..58841cb695 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -108,11 +108,16 @@ void BatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool pa { return; } - kmGLPushMatrix(); bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); sortAllChildren(); draw(renderer, _modelViewTransform, dirty); diff --git a/cocos/gui/UILayout.cpp b/cocos/gui/UILayout.cpp index 9eb8723ad2..e33742808c 100644 --- a/cocos/gui/UILayout.cpp +++ b/cocos/gui/UILayout.cpp @@ -204,10 +204,16 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf if(!_visible) return; - kmGLPushMatrix(); bool dirty = parentTransformDirty || _transformDirty; if(dirty) - transform(); + _modelViewTransform = transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); + //Add group command _groupCommand.init(_globalZOrder); diff --git a/extensions/GUI/CCScrollView/CCScrollView.cpp b/extensions/GUI/CCScrollView/CCScrollView.cpp index b8914f6447..f681ba2339 100644 --- a/extensions/GUI/CCScrollView/CCScrollView.cpp +++ b/extensions/GUI/CCScrollView/CCScrollView.cpp @@ -560,11 +560,15 @@ void ScrollView::visit(Renderer *renderer, const kmMat4 &parentTransform, bool p return; } - kmGLPushMatrix(); - bool dirty = parentTransformDirty || _transformDirty; if(dirty) - this->transform(); + _modelViewTransform = this->transform(parentTransform); + + // IMPORTANT: + // To ease the migration to v3.0, we still support the kmGL stack, + // but it is deprecated and your code should not rely on it + kmGLPushMatrix(); + kmGLLoadMatrix(&_modelViewTransform); this->beforeDraw(); diff --git a/tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp index 59d1c8e2d0..0949d0163a 100644 --- a/tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/tests/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -633,7 +633,7 @@ void RawStencilBufferTest::draw(Renderer *renderer, const kmMat4 &transform, boo ++iter; kmGLPushMatrix(); - this->transform(); + _modelViewTransform = this->transform(transform); _sprites.at(i)->visit(renderer, _modelViewTransform, transformDirty); kmGLPopMatrix(); @@ -643,7 +643,7 @@ void RawStencilBufferTest::draw(Renderer *renderer, const kmMat4 &transform, boo ++iter; kmGLPushMatrix(); - this->transform(); + _modelViewTransform = this->transform(transform); _sprites.at(i)->visit(renderer, _modelViewTransform, transformDirty); kmGLPopMatrix(); }