Skip to content

Commit 0a825d3

Browse files
committed
fixed cocos2d#2288 Re-write CCGrid, CCMotionStreak , CCProgressTimer with TypeArray
1 parent 7572b2b commit 0a825d3

File tree

5 files changed

+103
-103
lines changed

5 files changed

+103
-103
lines changed

cocos2d/effects/CCGrid.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,14 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{
362362
this._texCoordinates = new Float32Array(numOfPoints * 2);
363363
this._indices = new Uint16Array(this._gridSize.width * this._gridSize.height * 6);
364364

365+
if(this._verticesBuffer)
366+
gl.deleteBuffer(this._verticesBuffer);
365367
this._verticesBuffer = gl.createBuffer();
368+
if(this._texCoordinateBuffer)
369+
gl.deleteBuffer(this._texCoordinateBuffer);
366370
this._texCoordinateBuffer = gl.createBuffer();
371+
if(this._indicesBuffer)
372+
gl.deleteBuffer(this._indicesBuffer);
367373
this._indicesBuffer = gl.createBuffer();
368374

369375
var x, y, i;
@@ -388,10 +394,10 @@ cc.Grid3D = cc.GridBase.extend(/** @lends cc.Grid3D# */{
388394
this._indices[idx * 6 + 5] = d;
389395

390396
var l1 = [a * 3, b * 3, c * 3, d * 3];
391-
var e = new cc.Vertex3F(x1, y1, 0);
392-
var f = new cc.Vertex3F(x2, y1, 0);
393-
var g = new cc.Vertex3F(x2, y2, 0);
394-
var h = new cc.Vertex3F(x1, y2, 0);
397+
var e = {x:x1, y:y1, z:0}; //new cc.Vertex3F(x1, y1, 0);
398+
var f = {x:x2, y:y1, z:0}; //new cc.Vertex3F(x2, y1, 0);
399+
var g = {x:x2, y:y2, z:0}; // new cc.Vertex3F(x2, y2, 0);
400+
var h = {x:x1, y:y2, z:0}; //new cc.Vertex3F(x1, y2, 0);
395401

396402
var l2 = [e, f, g, h];
397403
var tex1 = [a * 2, b * 2, c * 2, d * 2];
@@ -555,8 +561,14 @@ cc.TiledGrid3D = cc.GridBase.extend(/** @lends cc.TiledGrid3D# */{
555561
this._indices = new Uint16Array(numQuads * 6);
556562

557563
var gl = cc.renderContext;
564+
if(this._verticesBuffer)
565+
gl.deleteBuffer(this._verticesBuffer);
558566
this._verticesBuffer = gl.createBuffer();
567+
if(this._texCoordinateBuffer)
568+
gl.deleteBuffer(this._texCoordinateBuffer);
559569
this._texCoordinateBuffer = gl.createBuffer();
570+
if(this._indicesBuffer)
571+
gl.deleteBuffer(this._indicesBuffer);
560572
this._indicesBuffer = gl.createBuffer();
561573

562574
var x, y, i = 0;

cocos2d/misc_nodes/CCMotionStreak.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{
6262
_vertices:null,
6363
_colorPointer:null,
6464
_texCoords:null,
65+
6566
_verticesBuffer:null,
6667
_colorPointerBuffer:null,
6768
_texCoordsBuffer:null,
@@ -133,6 +134,17 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{
133134
this._positionR = cc.PointZero();
134135
this._color = cc.c3(0, 0, 0);
135136
this._blendFunc = new cc.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
137+
this._vertexWebGLBuffer = cc.renderContext.createBuffer();
138+
},
139+
140+
onExit:function(){
141+
cc.Node.prototype.onExit.call(this);
142+
if(this._verticesBuffer)
143+
cc.renderContext.deleteBuffer(this._verticesBuffer);
144+
if(this._texCoordsBuffer)
145+
cc.renderContext.deleteBuffer(this._texCoordsBuffer);
146+
if(this._colorPointerBuffer)
147+
cc.renderContext.deleteBuffer(this._colorPointerBuffer);
136148
},
137149

138150
isFastMode:function () {
@@ -216,7 +228,6 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{
216228
gl.bufferData(gl.ARRAY_BUFFER, this._texCoords, gl.DYNAMIC_DRAW);
217229
gl.bindBuffer(gl.ARRAY_BUFFER, this._colorPointerBuffer);
218230
gl.bufferData(gl.ARRAY_BUFFER, this._colorPointer, gl.DYNAMIC_DRAW);
219-
this._isDirty = true;
220231

221232
return true;
222233
},
@@ -234,7 +245,6 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{
234245
this._colorPointer[i * 4 + 1] = colors.g;
235246
this._colorPointer[i * 4 + 2] = colors.b;
236247
}
237-
this._isDirty = true;
238248
},
239249

240250
/**
@@ -285,7 +295,7 @@ cc.MotionStreak = cc.Node.extend(/** @lends cc.MotionStreak# */{
285295
ctx.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, ctx.UNSIGNED_BYTE, true, 0, 0);
286296

287297
ctx.drawArrays(ctx.TRIANGLE_STRIP, 0, this._nuPoints * 2);
288-
cc.INCREMENT_GL_DRAWS(1);
298+
cc.g_NumberOfDraws ++;
289299
}
290300
},
291301

0 commit comments

Comments
 (0)