migrate cocostudio to director matrix stack

This commit is contained in:
Huabing.Xu 2014-04-03 14:55:55 +08:00
parent 67971e9f0b
commit 960ac300d5
5 changed files with 41 additions and 31 deletions

View File

@ -33,6 +33,7 @@ THE SOFTWARE.
#include "renderer/CCGroupCommand.h" #include "renderer/CCGroupCommand.h"
#include "CCShaderCache.h" #include "CCShaderCache.h"
#include "CCDrawingPrimitives.h" #include "CCDrawingPrimitives.h"
#include "CCDirector.h"
#if ENABLE_PHYSICS_BOX2D_DETECT #if ENABLE_PHYSICS_BOX2D_DETECT
#include "Box2D/Box2D.h" #include "Box2D/Box2D.h"
@ -458,10 +459,13 @@ void Armature::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform,
_transformUpdated = false; _transformUpdated = false;
// IMPORTANT: // 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 // but it is deprecated and your code should not rely on it
kmGLPushMatrix(); Director* director = Director::getInstance();
kmGLLoadMatrix(&_modelViewTransform); 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(); sortAllChildren();
draw(renderer, _modelViewTransform, dirty); draw(renderer, _modelViewTransform, dirty);
@ -469,7 +473,7 @@ void Armature::visit(cocos2d::Renderer *renderer, const kmMat4 &parentTransform,
// reset for next frame // reset for next frame
_orderOfArrival = 0; _orderOfArrival = 0;
kmGLPopMatrix(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
} }
Rect Armature::getBoundingBox() const Rect Armature::getBoundingBox() const

View File

@ -115,10 +115,12 @@ void BatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool pa
_transformUpdated = false; _transformUpdated = false;
// IMPORTANT: // 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 // but it is deprecated and your code should not rely on it
kmGLPushMatrix(); Director* director = Director::getInstance();
kmGLLoadMatrix(&_modelViewTransform); 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(); sortAllChildren();
draw(renderer, _modelViewTransform, dirty); draw(renderer, _modelViewTransform, dirty);
@ -126,7 +128,7 @@ void BatchNode::visit(Renderer *renderer, const kmMat4 &parentTransform, bool pa
// reset for next frame // reset for next frame
_orderOfArrival = 0; _orderOfArrival = 0;
kmGLPopMatrix(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
} }
void BatchNode::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) void BatchNode::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)

View File

@ -193,8 +193,10 @@ void Skeleton::onDraw(const kmMat4 &transform, bool transformUpdated)
} }
if(debugBones || debugSlots) { if(debugBones || debugSlots) {
kmGLPushMatrix(); Director* director = Director::getInstance();
kmGLLoadMatrix(&transform); 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) { if (debugSlots) {
// Slots. // Slots.
@ -234,7 +236,7 @@ void Skeleton::onDraw(const kmMat4 &transform, bool transformUpdated)
} }
} }
kmGLPopMatrix(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
} }
} }

View File

@ -29,6 +29,7 @@
#include "CCProtectedNode.h" #include "CCProtectedNode.h"
#include "kazmath/GL/matrix.h" #include "kazmath/GL/matrix.h"
#include "CCDirector.h"
#if CC_USE_PHYSICS #if CC_USE_PHYSICS
#include "CCPhysicsBody.h" #include "CCPhysicsBody.h"
@ -286,10 +287,12 @@ void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, boo
// IMPORTANT: // 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 // but it is deprecated and your code should not rely on it
kmGLPushMatrix(); Director* director = Director::getInstance();
kmGLLoadMatrix(&_modelViewTransform); 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 i = 0; // used by _children
int j = 0; // used by _protectedChildren int j = 0; // used by _protectedChildren
@ -337,7 +340,7 @@ void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, boo
// reset for next frame // reset for next frame
_orderOfArrival = 0; _orderOfArrival = 0;
kmGLPopMatrix(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
} }
void ProtectedNode::onEnter() void ProtectedNode::onEnter()

View File

@ -755,11 +755,12 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf
_transformUpdated = false; _transformUpdated = false;
// IMPORTANT: // 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 // but it is deprecated and your code should not rely on it
kmGLPushMatrix(); Director* director = Director::getInstance();
kmGLLoadMatrix(&_modelViewTransform); 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 //Add group command
_groupCommand.init(_globalZOrder); _groupCommand.init(_globalZOrder);
@ -827,7 +828,7 @@ void Layout::stencilClippingVisit(Renderer *renderer, const kmMat4 &parentTransf
renderer->popGroup(); renderer->popGroup();
kmGLPopMatrix(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
} }
void Layout::onBeforeVisitStencil() void Layout::onBeforeVisitStencil()
@ -852,20 +853,18 @@ void Layout::onBeforeVisitStencil()
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glStencilFunc(GL_NEVER, mask_layer, mask_layer); glStencilFunc(GL_NEVER, mask_layer, mask_layer);
glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP); glStencilOp(GL_ZERO, GL_KEEP, GL_KEEP);
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLPushMatrix(); Director* director = Director::getInstance();
kmGLLoadIdentity(); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
kmGLMatrixMode(KM_GL_PROJECTION); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
kmGLPushMatrix(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLLoadIdentity(); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1)); DrawPrimitives::drawSolidRect(Point(-1,-1), Point(1,1), Color4F(1, 1, 1, 1));
kmGLMatrixMode(KM_GL_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
kmGLPopMatrix(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLMatrixMode(KM_GL_MODELVIEW);
kmGLPopMatrix();
glStencilFunc(GL_NEVER, mask_layer, mask_layer); glStencilFunc(GL_NEVER, mask_layer, mask_layer);
glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP); glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
} }