Skip to content

Commit 7d0f69a

Browse files
author
pandamicro
committed
Improve WebGL Rendering performance
1 parent c4f4886 commit 7d0f69a

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Diff for: cocos2d/core/renderer/RendererWebGL.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,10 @@ return {
273273
}
274274

275275
// Check batching
276-
var texture = cmd._node._texture;
277-
var blendSrc = cmd._node._blendFunc.src;
278-
var blendDst = cmd._node._blendFunc.dst;
276+
var node = cmd._node;
277+
var texture = node._texture;
278+
var blendSrc = node._blendFunc.src;
279+
var blendDst = node._blendFunc.dst;
279280
var shader = cmd._shaderProgram;
280281
if (_batchedInfo.texture !== texture ||
281282
_batchedInfo.blendSrc !== blendSrc ||
@@ -369,4 +370,4 @@ return {
369370
_batchedInfo.texture = null;
370371
}
371372
};
372-
})();
373+
})();

Diff for: cocos2d/core/sprites/CCSpriteWebGLRenderCmd.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,20 @@
272272
var node = this._node,
273273
lx = node._offsetPosition.x, rx = lx + node._rect.width,
274274
by = node._offsetPosition.y, ty = by + node._rect.height,
275-
wt = this._worldTransform;
275+
wt = this._worldTransform,
276+
wtx = wt.tx, wty = wt.ty,
277+
lxa = lx * wt.a, lxb = lx * wt.b, rxa = rx * wt.a, rxb = rx * wt.b,
278+
tyc = ty * wt.c, tyd = ty * wt.d, byc = by * wt.c, byd = by * wt.d;
276279

277280
var vertices = this._vertices;
278-
vertices[0].x = lx * wt.a + ty * wt.c + wt.tx; // tl
279-
vertices[0].y = lx * wt.b + ty * wt.d + wt.ty;
280-
vertices[1].x = lx * wt.a + by * wt.c + wt.tx; // bl
281-
vertices[1].y = lx * wt.b + by * wt.d + wt.ty;
282-
vertices[2].x = rx * wt.a + ty * wt.c + wt.tx; // tr
283-
vertices[2].y = rx * wt.b + ty * wt.d + wt.ty;
284-
vertices[3].x = rx * wt.a + by * wt.c + wt.tx; // br
285-
vertices[3].y = rx * wt.b + by * wt.d + wt.ty;
281+
vertices[0].x = lxa + tyc + wtx; // tl
282+
vertices[0].y = lxb + tyd + wty;
283+
vertices[1].x = lxa + byc + wtx; // bl
284+
vertices[1].y = lxb + byd + wty;
285+
vertices[2].x = rxa + tyc + wtx; // tr
286+
vertices[2].y = rxb + tyd + wty;
287+
vertices[3].x = rxa + byc + wtx; // br
288+
vertices[3].y = rxb + byd + wty;
286289
};
287290

288291
proto.needDraw = function () {
@@ -324,4 +327,4 @@
324327

325328
return len;
326329
};
327-
})();
330+
})();

0 commit comments

Comments
 (0)