Skip to content

Commit 7672694

Browse files
committed
Issue cocos2d#2698: corrected a mistake of cc.math.Matrix in constructor.
1 parent f863933 commit 7672694

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

cocos2d/clipping-nodes/CCClippingNodeWebGLRenderCmd.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,29 @@
144144

145145
proto._drawFullScreenQuadClearStencil = function () {
146146
// draw a fullscreen solid rectangle to clear the stencil buffer
147-
cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
148-
cc.kmGLPushMatrix();
149-
cc.kmGLLoadIdentity();
150-
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
151-
cc.kmGLPushMatrix();
152-
cc.kmGLLoadIdentity();
147+
var projStack = cc.projection_matrix_stack;
148+
//cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
149+
//cc.kmGLPushMatrix();
150+
//cc.kmGLLoadIdentity();
151+
projStack.push();
152+
projStack.top.identity();
153+
154+
//cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
155+
//cc.kmGLPushMatrix();
156+
//cc.kmGLLoadIdentity();
157+
var modelViewStack = cc.modelview_matrix_stack;
158+
modelViewStack.push();
159+
modelViewStack.top.identity();
160+
153161
cc._drawingUtil.drawSolidRect(cc.p(-1, -1), cc.p(1, 1), cc.color(255, 255, 255, 255));
154-
cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
155-
cc.kmGLPopMatrix();
156-
cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
157-
cc.kmGLPopMatrix();
162+
163+
//cc.kmGLMatrixMode(cc.KM_GL_PROJECTION);
164+
//cc.kmGLPopMatrix();
165+
projStack.pop();
166+
167+
//cc.kmGLMatrixMode(cc.KM_GL_MODELVIEW);
168+
//cc.kmGLPopMatrix();
169+
modelViewStack.pop();
158170
};
159171

160172
proto._onBeforeVisit = function(ctx){

cocos2d/kazmath/gl/mat4stack.js

+18
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._matrixPool = []; // use pool in next version
3940
};
4041
cc.km_mat4_stack = cc.math.Matrix4Stack;
4142
var proto = cc.math.Matrix4Stack.prototype;
@@ -61,17 +62,34 @@
6162
};
6263

6364
proto.push = function(item) {
65+
item = item || this.top;
6466
this.stack.push(this.top);
6567
this.top = new cc.math.Matrix4(item);
68+
//this.top = this._getFromPool(item);
6669
};
6770

6871
proto.pop = function() {
72+
//this._putInPool(this.top);
6973
this.top = this.stack.pop();
7074
};
7175

7276
proto.release = function(){
7377
this.stack = null;
7478
this.top = null;
79+
this._matrixPool = null;
80+
};
81+
82+
proto._getFromPool = function (item) {
83+
var pool = this._matrixPool;
84+
if (pool.length === 0)
85+
return new cc.math.Matrix4(item);
86+
var ret = pool.pop();
87+
ret.assignFrom(item);
88+
return ret;
89+
};
90+
91+
proto._putInPool = function(matrix){
92+
this._matrixPool.push(matrix);
7593
};
7694
})(cc);
7795

cocos2d/kazmath/mat3.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929
var Float32Array = Float32Array || Array;
3030
(function(cc){
3131
cc.math.Matrix3 = function(mat3) {
32-
if (mat3) {
33-
this.mat = new Float32Array(mat3);
32+
if (mat3 && mat3.mat) {
33+
this.mat = new Float32Array(mat3.mat);
3434
} else {
35-
this.mat = new Float32Array([0, 0, 0,
36-
0, 0, 0,
37-
0, 0, 0]);
35+
this.mat = new Float32Array(9);
3836
}
3937
};
4038
cc.kmMat3 = cc.math.Matrix3;

cocos2d/kazmath/mat4.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@
4040
* @param {cc.math.Matrix4} [mat4]
4141
*/
4242
cc.math.Matrix4 = function (mat4) {
43-
if(mat4){
43+
if(mat4 && mat4.mat){
4444
this.mat = new Float32Array(mat4.mat);
4545
} else {
46-
this.mat = new Float32Array([0, 0, 0, 0,
47-
0, 0, 0, 0,
48-
0, 0, 0, 0,
49-
0, 0, 0, 0]);
46+
this.mat = new Float32Array(16);
5047
}
5148
};
5249
cc.kmMat4 = cc.math.Matrix4;

0 commit comments

Comments
 (0)