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 "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

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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()

View File

@ -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);
}