From 960ac300d5a43d655c6c2e77ddf2389a4e41a23a Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Thu, 3 Apr 2014 14:55:55 +0800 Subject: [PATCH] migrate cocostudio to director matrix stack --- .../editor-support/cocostudio/CCArmature.cpp | 12 ++++--- .../editor-support/cocostudio/CCBatchNode.cpp | 10 +++--- cocos/editor-support/spine/CCSkeleton.cpp | 8 +++-- cocos/ui/CCProtectedNode.cpp | 11 ++++--- cocos/ui/UILayout.cpp | 31 +++++++++---------- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmature.cpp b/cocos/editor-support/cocostudio/CCArmature.cpp index 491df8e3ec..c339a20fcb 100644 --- a/cocos/editor-support/cocostudio/CCArmature.cpp +++ b/cocos/editor-support/cocostudio/CCArmature.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include "renderer/CCGroupCommand.h" #include "CCShaderCache.h" #include "CCDrawingPrimitives.h" +#include "CCDirector.h" #if ENABLE_PHYSICS_BOX2D_DETECT #include "Box2D/Box2D.h" @@ -458,10 +459,13 @@ void Armature::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, _transformUpdated = false; // IMPORTANT: - // To ease the migration to v3.0, we still support the kmGL stack, + // To ease the migration to v3.0, we still support the kmMat4 stack, // but it is deprecated and your code should not rely on it - kmGLPushMatrix(); - kmGLLoadMatrix(&_modelViewTransform); + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); + sortAllChildren(); draw(renderer, _modelViewTransform, dirty); @@ -469,7 +473,7 @@ void Armature::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform, // reset for next frame _orderOfArrival = 0; - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } Rect Armature::getBoundingBox() const diff --git a/cocos/editor-support/cocostudio/CCBatchNode.cpp b/cocos/editor-support/cocostudio/CCBatchNode.cpp index 49cd5caf26..0e70acb721 100644 --- a/cocos/editor-support/cocostudio/CCBatchNode.cpp +++ b/cocos/editor-support/cocostudio/CCBatchNode.cpp @@ -115,10 +115,12 @@ void BatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool pa _transformUpdated = false; // IMPORTANT: - // To ease the migration to v3.0, we still support the kmGL stack, + // To ease the migration to v3.0, we still support the kmMat4 stack, // but it is deprecated and your code should not rely on it - kmGLPushMatrix(); - kmGLLoadMatrix(&_modelViewTransform); + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); sortAllChildren(); draw(renderer, _modelViewTransform, dirty); @@ -126,7 +128,7 @@ void BatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool pa // reset for next frame _orderOfArrival = 0; - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } void BatchNode::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) diff --git a/cocos/editor-support/spine/CCSkeleton.cpp b/cocos/editor-support/spine/CCSkeleton.cpp index 06b1de9241..0ebbbd91f7 100644 --- a/cocos/editor-support/spine/CCSkeleton.cpp +++ b/cocos/editor-support/spine/CCSkeleton.cpp @@ -193,8 +193,10 @@ void Skeleton::onDraw(const kmMat4 &transform, bool transformUpdated) } if(debugBones || debugSlots) { - kmGLPushMatrix(); - kmGLLoadMatrix(&transform); + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); if (debugSlots) { // Slots. @@ -234,7 +236,7 @@ void Skeleton::onDraw(const kmMat4 &transform, bool transformUpdated) } } - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } } diff --git a/cocos/ui/CCProtectedNode.cpp b/cocos/ui/CCProtectedNode.cpp index d8a12940ec..812af89a26 100644 --- a/cocos/ui/CCProtectedNode.cpp +++ b/cocos/ui/CCProtectedNode.cpp @@ -29,6 +29,7 @@ #include "CCProtectedNode.h" #include "kazmath/GL/matrix.h" +#include "CCDirector.h" #if CC_USE_PHYSICS #include "CCPhysicsBody.h" @@ -286,10 +287,12 @@ void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, boo // IMPORTANT: - // To ease the migration to v3.0, we still support the kmGL stack, + // To ease the migration to v3.0, we still support the kmMat4 stack, // but it is deprecated and your code should not rely on it - kmGLPushMatrix(); - kmGLLoadMatrix(&_modelViewTransform); + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); int i = 0; // used by _children int j = 0; // used by _protectedChildren @@ -337,7 +340,7 @@ void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, boo // reset for next frame _orderOfArrival = 0; - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } void ProtectedNode::onEnter() diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 9808553d62..d3fa364f78 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -755,11 +755,12 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf _transformUpdated = false; // IMPORTANT: - // To ease the migration to v3.0, we still support the kmGL stack, + // To ease the migration to v3.0, we still support the kmMat4 stack, // but it is deprecated and your code should not rely on it - kmGLPushMatrix(); - kmGLLoadMatrix(&_modelViewTransform); - + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); //Add group command _groupCommand.init(_globalZOrder); @@ -827,7 +828,7 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf renderer->popGroup(); - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } void Layout::onBeforeVisitStencil() @@ -852,20 +853,18 @@ void Layout::onBeforeVisitStencil() glDepthMask(GL_FALSE); glStencilFunc(GL_NEVER, mask_layer, mask_layer); glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPushMatrix(); - kmGLLoadIdentity(); - - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPushMatrix(); - kmGLLoadIdentity(); + + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1)); - kmGLMatrixMode(KM_GL_PROJECTION); - kmGLPopMatrix(); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); glStencilFunc(GL_NEVER, mask_layer, mask_layer); glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP); }