Skip to content

Commit e65afee

Browse files
committed
Issue fixes in auto batching
1 parent d93fdea commit e65afee

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cocos2d/core/renderer/RendererWebGL.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function objEqual (a, b) {
3030
var keys = Object.keys(a);
3131
for (var i = 0; i < keys.length; ++i) {
3232
var key = keys[i];
33-
if (a[key] !== b[key]) {
33+
if (!b[key] || a[key] !== b[key]) {
3434
return false;
3535
}
3636
}
@@ -218,6 +218,9 @@ return {
218218
var buf = pool[i];
219219
if (buf.bufferSize >= bufferSize && buf.indiceSize >= indiceSize) {
220220
removeByLastSwap(pool, i);
221+
this.initBatchBuffers(buf.arrayBuffer, buf.elementBuffer, bufferSize, indiceSize);
222+
buf.bufferSize = bufferSize;
223+
buf.indiceSize = indiceSize;
221224
return buf;
222225
}
223226

@@ -248,7 +251,7 @@ return {
248251
_forwardBatch: function (first) {
249252
var renderCmds = this._renderCmds,
250253
cmd = renderCmds[first];
251-
if (!cmd || !cmd._supportBatch) return;
254+
if (!cmd || !cmd._supportBatch) return 0;
252255

253256
var info = {}, last;
254257

@@ -263,6 +266,9 @@ return {
263266
if (cmd._supportBatch) {
264267
cmd.getBatchInfo(info);
265268
}
269+
else {
270+
break;
271+
}
266272
// Batch info don't match, break batching
267273
if (!objEqual(info, _batchedInfo)) {
268274
break;
@@ -275,6 +281,10 @@ return {
275281
}
276282

277283
var count = last - first;
284+
if (count <= 1) {
285+
return count;
286+
}
287+
278288
_batchedCount = count;
279289

280290
var bufferSize = _batchedInfo.totalBufferSize;
@@ -342,14 +352,15 @@ return {
342352
indices[indiceI] = currentQuad + 0;
343353
indices[indiceI + 1] = currentQuad + 1;
344354
indices[indiceI + 2] = currentQuad + 2;
345-
indices[indiceI + 3] = currentQuad + 1;
355+
indices[indiceI + 3] = currentQuad + 3;
346356
indices[indiceI + 4] = currentQuad + 2;
347-
indices[indiceI + 5] = currentQuad + 3;
357+
indices[indiceI + 5] = currentQuad + 1;
348358
currentQuad += 4;
349359
indiceI += cmd.indicesPerUnit;
350360
}
351361

352362
gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, indices);
363+
return count;
353364
},
354365

355366
_batchRendering: function () {
@@ -408,9 +419,11 @@ return {
408419
cmd = locCmds[i];
409420

410421
// Batching or direct rendering
411-
if (cmd._supportBatch) {
412-
this._forwardBatch(i);
422+
var batchCount = this._forwardBatch(i);
423+
if (batchCount > 1) {
413424
this._batchRendering();
425+
// i will increase by 1 each loop
426+
i += batchCount - 1;
414427
}
415428
else {
416429
cmd.rendering(context);

0 commit comments

Comments
 (0)