diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 3ff1bd2124..f6fa0e4b0f 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -579,38 +579,38 @@ void Director::pushMatrix(MATRIX_STACK_TYPE type) } } -kmMat4 Director::getMatrix(MATRIX_STACK_TYPE type) -{ - if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type) - { - kmMat4 result; - kmGLGetMatrix(KM_GL_MODELVIEW, &result); - return result; - return _modelViewMatrixStack.top(); - } - else if(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION == type) - { - kmMat4 result; - kmGLGetMatrix(KM_GL_PROJECTION, &result); - return result; - return _projectionMatrixStack.top(); - } - else if(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE == type) - { - kmMat4 result; - kmGLGetMatrix(KM_GL_TEXTURE, &result); - return result; - return _textureMatrixStack.top(); - } - else - { - CCASSERT(false, "unknow matrix stack type, will return modelview matrix instead"); - kmMat4 result; - kmGLGetMatrix(KM_GL_MODELVIEW, &result); - return result; - return _modelViewMatrixStack.top(); - } -} +//kmMat4 Director::getMatrix(MATRIX_STACK_TYPE type) +//{ +// if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type) +// { +// kmMat4 result; +// kmGLGetMatrix(KM_GL_MODELVIEW, &result); +// return result; +// return _modelViewMatrixStack.top(); +// } +// else if(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION == type) +// { +// kmMat4 result; +// kmGLGetMatrix(KM_GL_PROJECTION, &result); +// return result; +// return _projectionMatrixStack.top(); +// } +// else if(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE == type) +// { +// kmMat4 result; +// kmGLGetMatrix(KM_GL_TEXTURE, &result); +// return result; +// return _textureMatrixStack.top(); +// } +// else +// { +// CCASSERT(false, "unknow matrix stack type, will return modelview matrix instead"); +// kmMat4 result; +// kmGLGetMatrix(KM_GL_MODELVIEW, &result); +// return result; +// return _modelViewMatrixStack.top(); +// } +//} void Director::setProjection(Projection projection) { @@ -741,7 +741,8 @@ static void GLToClipTransform(kmMat4 *transformOut) CCASSERT(nullptr != director, "Director is null when seting matrix stack"); kmMat4 projection; - projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + //projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + kmGLGetMatrix(KM_GL_PROJECTION, &projection); #if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 //if needed, we need to undo the rotation for Landscape orientation in order to get the correct positions @@ -749,8 +750,8 @@ static void GLToClipTransform(kmMat4 *transformOut) #endif kmMat4 modelview; - modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - + //modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + kmGLGetMatrix(KM_GL_MODELVIEW, &modelview); kmMat4Multiply(transformOut, &projection, &modelview); } diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index 91e1ee9378..1f7b42c6c9 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -105,7 +105,7 @@ public: void loadIdentityMatrix(MATRIX_STACK_TYPE type); void loadMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); void multiplyMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); - kmMat4 getMatrix(MATRIX_STACK_TYPE type); + //kmMat4 getMatrix(MATRIX_STACK_TYPE type); public: static const char *EVENT_PROJECTION_CHANGED; static const char* EVENT_AFTER_UPDATE; diff --git a/cocos/2d/CCGLProgram.cpp b/cocos/2d/CCGLProgram.cpp index 0dab9895cf..e75334355b 100644 --- a/cocos/2d/CCGLProgram.cpp +++ b/cocos/2d/CCGLProgram.cpp @@ -629,8 +629,13 @@ void GLProgram::setUniformLocationWithMatrix4fv(GLint location, const GLfloat* m void GLProgram::setUniformsForBuiltins() { + Director* director = Director::getInstance(); + CCASSERT(nullptr != director, "Director is null when seting matrix stack"); + kmMat4 matrixMV; - kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV); + //matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV); + setUniformsForBuiltins(matrixMV); } @@ -638,8 +643,8 @@ void GLProgram::setUniformsForBuiltins() void GLProgram::setUniformsForBuiltins(const kmMat4 &matrixMV) { kmMat4 matrixP; - - kmGLGetMatrix(KM_GL_PROJECTION, &matrixP); + //= Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + kmGLGetMatrix(KM_GL_PROJECTION, &matrixP); if(_flags.usesP) setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_P_MATRIX], matrixP.mat, 1); diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 3ea3f1d832..5f89de9a6e 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -953,10 +953,12 @@ void Node::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentT // 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; @@ -987,7 +989,7 @@ void Node::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentT // reset for next frame _orderOfArrival = 0; - kmGLPopMatrix(); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } kmMat4 Node::transform(const kmMat4& parentTransform)