diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index f71b356426..c8c992c976 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -434,11 +434,31 @@ void Director::initMatrixStack() kmMat4 identity; kmMat4Identity(&identity); + while (!_modelViewMatrixStack.empty()) + { + _modelViewMatrixStack.pop(); + } + + while (!_projectionMatrixStack.empty()) + { + _projectionMatrixStack.pop(); + } + + while (!_textureMatrixStack.empty()) + { + _textureMatrixStack.pop(); + } + _modelViewMatrixStack.push(identity); _projectionMatrixStack.push(identity); _textureMatrixStack.push(identity); } +void Director::resetMatrixStack() +{ + initMatrixStack(); +} + void Director::popMatrix(MATRIX_STACK_TYPE type) { if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type) diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index 91e1ee9378..157913057b 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -106,6 +106,7 @@ public: void loadMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); void multiplyMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); kmMat4 getMatrix(MATRIX_STACK_TYPE type); + void resetMatrixStack(); public: static const char *EVENT_PROJECTION_CHANGED; static const char* EVENT_AFTER_UPDATE; diff --git a/cocos/2d/ccGLStateCache.cpp b/cocos/2d/ccGLStateCache.cpp index 987f30b709..7e076e5366 100644 --- a/cocos/2d/ccGLStateCache.cpp +++ b/cocos/2d/ccGLStateCache.cpp @@ -65,8 +65,7 @@ namespace GL { void invalidateStateCache( void ) { - kmGLFreeAll(); - + Director::getInstance()->resetMatrixStack(); s_currentProjectionMatrix = -1; s_vertexAttribPosition = false; s_vertexAttribColor = false;