readied director::getMatrix again. remove kmGLgetMatrix

This commit is contained in:
Huabing.Xu 2014-04-03 17:26:06 +08:00
parent 5e76c6713d
commit 67e62ce73d
9 changed files with 62 additions and 67 deletions

View File

@ -579,38 +579,42 @@ void Director::pushMatrix(MATRIX_STACK_TYPE type)
} }
} }
//kmMat4 Director::getMatrix(MATRIX_STACK_TYPE type) kmMat4 Director::getMatrix(MATRIX_STACK_TYPE type)
//{ {
// if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type) kmMat4 result;
// { kmMat4 result2;
// kmMat4 result; if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type)
// kmGLGetMatrix(KM_GL_MODELVIEW, &result); {
// return result; kmGLGetMatrix(KM_GL_MODELVIEW, &result2);
// return _modelViewMatrixStack.top(); result = _modelViewMatrixStack.top();
// } }
// else if(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION == type) else if(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION == type)
// { {
// kmMat4 result; kmGLGetMatrix(KM_GL_PROJECTION, &result2);
// kmGLGetMatrix(KM_GL_PROJECTION, &result); result = _projectionMatrixStack.top();
// return result; }
// return _projectionMatrixStack.top(); else if(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE == type)
// } {
// else if(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE == type) kmGLGetMatrix(KM_GL_TEXTURE, &result2);
// { result = _textureMatrixStack.top();
// kmMat4 result; }
// kmGLGetMatrix(KM_GL_TEXTURE, &result); else
// return result; {
// return _textureMatrixStack.top(); CCASSERT(false, "unknow matrix stack type, will return modelview matrix instead");
// } kmGLGetMatrix(KM_GL_MODELVIEW, &result2);
// else result = _modelViewMatrixStack.top();
// { }
// CCASSERT(false, "unknow matrix stack type, will return modelview matrix instead"); float diffResult(0);
// kmMat4 result; for (int index = 0; index <16; ++index)
// kmGLGetMatrix(KM_GL_MODELVIEW, &result); {
// return result; diffResult += abs(result2.mat[index] - result.mat[index]);
// return _modelViewMatrixStack.top(); }
// } if(diffResult > 1e-30)
//} {
CCASSERT(false, "Error in director matrix stack");
}
return result;
}
void Director::setProjection(Projection projection) void Director::setProjection(Projection projection)
{ {
@ -741,8 +745,7 @@ static void GLToClipTransform(kmMat4 *transformOut)
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 projection; 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 CC_TARGET_PLATFORM == CC_PLATFORM_WP8
//if needed, we need to undo the rotation for Landscape orientation in order to get the correct positions //if needed, we need to undo the rotation for Landscape orientation in order to get the correct positions
@ -750,8 +753,7 @@ static void GLToClipTransform(kmMat4 *transformOut)
#endif #endif
kmMat4 modelview; 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); kmMat4Multiply(transformOut, &projection, &modelview);
} }

View File

@ -105,7 +105,7 @@ public:
void loadIdentityMatrix(MATRIX_STACK_TYPE type); void loadIdentityMatrix(MATRIX_STACK_TYPE type);
void loadMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat); void loadMatrix(MATRIX_STACK_TYPE type, const kmMat4& mat);
void multiplyMatrix(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: public:
static const char *EVENT_PROJECTION_CHANGED; static const char *EVENT_PROJECTION_CHANGED;
static const char* EVENT_AFTER_UPDATE; static const char* EVENT_AFTER_UPDATE;

View File

@ -633,18 +633,14 @@ void GLProgram::setUniformsForBuiltins()
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 matrixMV; kmMat4 matrixMV;
//matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV);
setUniformsForBuiltins(matrixMV); setUniformsForBuiltins(matrixMV);
} }
void GLProgram::setUniformsForBuiltins(const kmMat4 &matrixMV) void GLProgram::setUniformsForBuiltins(const kmMat4 &matrixMV)
{ {
kmMat4 matrixP; kmMat4 matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
//= Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
kmGLGetMatrix(KM_GL_PROJECTION, &matrixP);
if(_flags.usesP) if(_flags.usesP)
setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_P_MATRIX], matrixP.mat, 1); setUniformLocationWithMatrix4fv(_uniforms[UNIFORM_P_MATRIX], matrixP.mat, 1);

View File

@ -933,8 +933,7 @@ void Node::draw(Renderer* renderer, const kmMat4 &transform, bool transformUpdat
void Node::visit() void Node::visit()
{ {
auto renderer = Director::getInstance()->getRenderer(); auto renderer = Director::getInstance()->getRenderer();
kmMat4 parentTransform; kmMat4 parentTransform = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &parentTransform);
visit(renderer, parentTransform, true); visit(renderer, parentTransform, true);
} }

View File

@ -524,10 +524,10 @@ void RenderTexture::onBegin()
// //
Director *director = Director::getInstance(); Director *director = Director::getInstance();
Size size = director->getWinSizeInPixels(); Size size = director->getWinSizeInPixels();
kmGLGetMatrix(KM_GL_PROJECTION, &_oldProjMatrix); _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix);
kmGLGetMatrix(KM_GL_MODELVIEW, &_oldTransMatrix); _oldTransMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _transformMatrix); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _transformMatrix);
if(!_keepMatrix) if(!_keepMatrix)
@ -678,10 +678,10 @@ void RenderTexture::begin()
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
kmGLGetMatrix(KM_GL_PROJECTION, &_projectionMatrix); _projectionMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &_transformMatrix); _transformMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
if(!_keepMatrix) if(!_keepMatrix)
{ {

View File

@ -610,7 +610,7 @@ void Sprite::drawDebugData()
Director* director = Director::getInstance(); Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 oldModelView; kmMat4 oldModelView;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldModelView); oldModelView = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
// draw bounding box // draw bounding box
Point vertices[4] = { Point vertices[4] = {

View File

@ -221,8 +221,7 @@ kmMat4 Skin::getNodeToWorldTransformAR() const
void Skin::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) void Skin::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
{ {
kmMat4 mv; kmMat4 mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &mv);
//TODO implement z order //TODO implement z order
_quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv); _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, mv);

View File

@ -1671,10 +1671,9 @@ void ActionCatmullRomStacked::draw(Renderer *renderer, const kmMat4 &transform,
kmMat4Translation(&translation,50,50,0); kmMat4Translation(&translation,50,50,0);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder); _customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this, transform, transformUpdated); _customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this, transform, transformUpdated);
@ -1687,7 +1686,7 @@ void ActionCatmullRomStacked::onDraw(const kmMat4 &transform, bool transformUpda
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 oldMat; kmMat4 oldMat;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCatmullRom(_array1,50); DrawPrimitives::drawCatmullRom(_array1,50);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
@ -1792,7 +1791,7 @@ void ActionCardinalSplineStacked::draw(Renderer *renderer, const kmMat4 &transfo
kmMat4Translation(&translation,50,50,0); kmMat4Translation(&translation,50,50,0);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
@ -1803,7 +1802,7 @@ void ActionCardinalSplineStacked::draw(Renderer *renderer, const kmMat4 &transfo
kmMat4Translation(&translation,s.width/2,50,0); kmMat4Translation(&translation,s.width/2,50,0);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder); _customCommand.init(_globalZOrder);
@ -1817,7 +1816,7 @@ void ActionCardinalSplineStacked::onDraw(const kmMat4 &transform, bool transform
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 oldMat; kmMat4 oldMat;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCardinalSpline(_array, 0, 100); DrawPrimitives::drawCardinalSpline(_array, 0, 100);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
@ -2173,10 +2172,10 @@ void ActionCatmullRom::draw(Renderer *renderer, const kmMat4 &transform, bool tr
//Create a rotation matrix using the axis and the angle //Create a rotation matrix using the axis and the angle
kmMat4Translation(&translation,50,50,0); kmMat4Translation(&translation,50,50,0);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder); _customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this, transform, transformUpdated); _customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this, transform, transformUpdated);
@ -2190,7 +2189,7 @@ void ActionCatmullRom::onDraw(const kmMat4 &transform, bool transformUpdated)
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 oldMat; kmMat4 oldMat;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCatmullRom(_array1, 50); DrawPrimitives::drawCatmullRom(_array1, 50);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
@ -2278,7 +2277,7 @@ void ActionCardinalSpline::draw(Renderer *renderer, const kmMat4 &transform, boo
//Create a rotation matrix using the axis and the angle //Create a rotation matrix using the axis and the angle
kmMat4Translation(&translation,50,50,0); kmMat4Translation(&translation,50,50,0);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV1); _modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
@ -2288,7 +2287,7 @@ void ActionCardinalSpline::draw(Renderer *renderer, const kmMat4 &transform, boo
//Create a rotation matrix using the axis and the angle //Create a rotation matrix using the axis and the angle
kmMat4Translation(&translation,s.width/2,50,0); kmMat4Translation(&translation,s.width/2,50,0);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV2); _modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder); _customCommand.init(_globalZOrder);
@ -2302,7 +2301,7 @@ void ActionCardinalSpline::onDraw(const kmMat4 &transform, bool transformUpdated
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 oldMat; kmMat4 oldMat;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCardinalSpline(_array, 0, 100); DrawPrimitives::drawCardinalSpline(_array, 0, 100);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);

View File

@ -152,7 +152,7 @@ void Box2DTestLayer::draw(Renderer *renderer, const kmMat4 &transform, bool tran
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder); _customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this); _customCommand.func = CC_CALLBACK_0(Box2DTestLayer::onDraw, this);
@ -169,7 +169,7 @@ void Box2DTestLayer::onDraw()
CCASSERT(nullptr != director, "Director is null when seting matrix stack"); CCASSERT(nullptr != director, "Director is null when seting matrix stack");
kmMat4 oldMV; kmMat4 oldMV;
kmGLGetMatrix(KM_GL_MODELVIEW, &oldMV); oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV);
world->DrawDebugData(); world->DrawDebugData();
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV);