Merge pull request #9011 from ricardoquesada/perf_fixes

Performance improvements
This commit is contained in:
Ricardo Quesada 2014-11-04 16:47:00 -08:00
commit 92caf4026a
7 changed files with 38 additions and 56 deletions

View File

@ -553,7 +553,7 @@ void RenderTexture::onBegin()
director->setProjection(director->getProjection());
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
Mat4 modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
auto modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
modifiedProjection = GLViewImpl::sharedOpenGLView()->getReverseOrientationMatrix() * modifiedProjection;
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION,modifiedProjection);
#endif
@ -572,7 +572,7 @@ void RenderTexture::onBegin()
else
{
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8
Mat4 modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
auto modifiedProjection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
modifiedProjection = GLViewImpl::sharedOpenGLView()->getReverseOrientationMatrix() * modifiedProjection;
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, modifiedProjection);
#endif

View File

@ -540,15 +540,15 @@ void Director::multiplyMatrix(MATRIX_STACK_TYPE type, const Mat4& mat)
void Director::pushMatrix(MATRIX_STACK_TYPE type)
{
if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type)
if(type == MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)
{
_modelViewMatrixStack.push(_modelViewMatrixStack.top());
}
else if(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION == type)
else if(type == MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION)
{
_projectionMatrixStack.push(_projectionMatrixStack.top());
}
else if(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE == type)
else if(type == MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE)
{
_textureMatrixStack.push(_textureMatrixStack.top());
}
@ -558,36 +558,23 @@ void Director::pushMatrix(MATRIX_STACK_TYPE type)
}
}
Mat4 Director::getMatrix(MATRIX_STACK_TYPE type)
const Mat4& Director::getMatrix(MATRIX_STACK_TYPE type)
{
Mat4 result;
if(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW == type)
if(type == MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW)
{
result = _modelViewMatrixStack.top();
return _modelViewMatrixStack.top();
}
else if(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION == type)
else if(type == MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION)
{
result = _projectionMatrixStack.top();
return _projectionMatrixStack.top();
}
else if(MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE == type)
else if(type == MATRIX_STACK_TYPE::MATRIX_STACK_TEXTURE)
{
result = _textureMatrixStack.top();
return _textureMatrixStack.top();
}
else
{
CCASSERT(false, "unknow matrix stack type, will return modelview matrix instead");
result = _modelViewMatrixStack.top();
}
// float diffResult(0);
// for (int index = 0; index <16; ++index)
// {
// diffResult += abs(result2.mat[index] - result.mat[index]);
// }
// if(diffResult > 1e-30)
// {
// CCASSERT(false, "Error in director matrix stack");
// }
return result;
CCASSERT(false, "unknow matrix stack type, will return modelview matrix instead");
return _modelViewMatrixStack.top();
}
void Director::setProjection(Projection projection)
@ -717,17 +704,15 @@ static void GLToClipTransform(Mat4 *transformOut)
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 projection;
projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
auto projection = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_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
projection = Director::getInstance()->getOpenGLView()->getReverseOrientationMatrix() * projection;
#endif
Mat4 modelview;
modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto modelview = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
*transformOut = projection * modelview;
}

View File

@ -90,27 +90,12 @@ enum class MATRIX_STACK_TYPE
class CC_DLL Director : public Ref
{
private:
std::stack<Mat4> _modelViewMatrixStack;
std::stack<Mat4> _projectionMatrixStack;
std::stack<Mat4> _textureMatrixStack;
protected:
void initMatrixStack();
public:
void pushMatrix(MATRIX_STACK_TYPE type);
void popMatrix(MATRIX_STACK_TYPE type);
void loadIdentityMatrix(MATRIX_STACK_TYPE type);
void loadMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
void multiplyMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
Mat4 getMatrix(MATRIX_STACK_TYPE type);
void resetMatrixStack();
public:
static const char *EVENT_PROJECTION_CHANGED;
static const char* EVENT_AFTER_UPDATE;
static const char* EVENT_AFTER_VISIT;
static const char* EVENT_AFTER_DRAW;
/** @typedef ccDirectorProjection
Possible OpenGL projections used by director
*/
@ -399,6 +384,14 @@ public:
*/
float getFrameRate() const { return _frameRate; }
void pushMatrix(MATRIX_STACK_TYPE type);
void popMatrix(MATRIX_STACK_TYPE type);
void loadIdentityMatrix(MATRIX_STACK_TYPE type);
void loadMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
void multiplyMatrix(MATRIX_STACK_TYPE type, const Mat4& mat);
const Mat4& getMatrix(MATRIX_STACK_TYPE type);
void resetMatrixStack();
protected:
void purgeDirector();
bool _purgeDirectorInNextLoop; // this flag will be set to true in end()
@ -417,6 +410,12 @@ protected:
void initTextureCache();
void destroyTextureCache();
void initMatrixStack();
std::stack<Mat4> _modelViewMatrixStack;
std::stack<Mat4> _projectionMatrixStack;
std::stack<Mat4> _textureMatrixStack;
/** Scheduler associated with this director
@since v2.0
*/

View File

@ -222,7 +222,7 @@ Mat4 Skin::getNodeToWorldTransformAR() const
void Skin::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
Mat4 mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
//TODO: implement z order
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, mv);

View File

@ -844,15 +844,14 @@ void GLProgram::setUniformsForBuiltins()
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 matrixMV;
matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto matrixMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
setUniformsForBuiltins(matrixMV);
}
void GLProgram::setUniformsForBuiltins(const Mat4 &matrixMV)
{
Mat4 matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
auto matrixP = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
if(_flags.usesP)
setUniformLocationWithMatrix4fv(_builtInUniforms[UNIFORM_P_MATRIX], matrixP.m, 1);

View File

@ -167,9 +167,8 @@ void Box2DTestLayer::onDraw()
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldMV;
oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV);
world->DrawDebugData();
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV);

View File

@ -1447,7 +1447,7 @@ void Sprite3DWithOBBPerfromanceTest::calculateRayByLocationInView(Ray* ray, cons
{
auto dir = Director::getInstance();
auto view = dir->getWinSize();
Mat4 mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
auto mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Vec3 src = Vec3(location.x, location.y, -1);
Vec3 nearPoint;