Skip to content

Commit 41b1026

Browse files
author
pandamicro
committed
Improve updateProjectionUniform performance
1 parent 0ce51b1 commit 41b1026

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

cocos2d/kazmath/gl/mat4stack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
cc.math.Matrix4Stack = function (top, stack) {
3737
this.top = top;
3838
this.stack = stack || [];
39+
this.lastUpdated = 0;
3940
//this._matrixPool = []; // use pool in next version
4041
};
4142
cc.km_mat4_stack = cc.math.Matrix4Stack;

cocos2d/kazmath/gl/matrix.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
throw new Error("Invalid matrix mode specified"); //TODO: Proper error handling
107107
break;
108108
}
109+
cc.current_stack.lastUpdated = cc.director.getTotalFrames();
109110
};
110111

111112
cc.kmGLLoadIdentity = function () {

cocos2d/shaders/CCGLProgram.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cc.GLProgram = cc.Class.extend(/** @lends cc.GLProgram# */{
3939
_uniforms: null,
4040
_hashForUniforms: null,
4141
_usesTime: false,
42+
_projectionUpdated: -1,
4243

4344
// Uniform cache
4445
_updateUniformLocation: function (location) {
@@ -684,8 +685,12 @@ cc.GLProgram = cc.Class.extend(/** @lends cc.GLProgram# */{
684685
this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX_S], false, cc.projection_matrix_stack.top.mat);
685686
},
686687

687-
_updateProjectionUniform: function(){
688-
this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX_S], false, cc.projection_matrix_stack.top.mat);
688+
_updateProjectionUniform: function () {
689+
var stack = cc.projection_matrix_stack;
690+
if (stack.lastUpdated !== this._projectionUpdated) {
691+
this._glContext.uniformMatrix4fv(this._uniforms[cc.UNIFORM_PMATRIX_S], false, stack.top.mat);
692+
this._projectionUpdated = stack.lastUpdated;
693+
}
689694
},
690695

691696
/**

0 commit comments

Comments
 (0)