@@ -30,7 +30,7 @@ function objEqual (a, b) {
30
30
var keys = Object . keys ( a ) ;
31
31
for ( var i = 0 ; i < keys . length ; ++ i ) {
32
32
var key = keys [ i ] ;
33
- if ( a [ key ] !== b [ key ] ) {
33
+ if ( ! b [ key ] || a [ key ] !== b [ key ] ) {
34
34
return false ;
35
35
}
36
36
}
@@ -218,6 +218,9 @@ return {
218
218
var buf = pool [ i ] ;
219
219
if ( buf . bufferSize >= bufferSize && buf . indiceSize >= indiceSize ) {
220
220
removeByLastSwap ( pool , i ) ;
221
+ this . initBatchBuffers ( buf . arrayBuffer , buf . elementBuffer , bufferSize , indiceSize ) ;
222
+ buf . bufferSize = bufferSize ;
223
+ buf . indiceSize = indiceSize ;
221
224
return buf ;
222
225
}
223
226
@@ -248,7 +251,7 @@ return {
248
251
_forwardBatch : function ( first ) {
249
252
var renderCmds = this . _renderCmds ,
250
253
cmd = renderCmds [ first ] ;
251
- if ( ! cmd || ! cmd . _supportBatch ) return ;
254
+ if ( ! cmd || ! cmd . _supportBatch ) return 0 ;
252
255
253
256
var info = { } , last ;
254
257
@@ -263,6 +266,9 @@ return {
263
266
if ( cmd . _supportBatch ) {
264
267
cmd . getBatchInfo ( info ) ;
265
268
}
269
+ else {
270
+ break ;
271
+ }
266
272
// Batch info don't match, break batching
267
273
if ( ! objEqual ( info , _batchedInfo ) ) {
268
274
break ;
@@ -275,6 +281,10 @@ return {
275
281
}
276
282
277
283
var count = last - first ;
284
+ if ( count <= 1 ) {
285
+ return count ;
286
+ }
287
+
278
288
_batchedCount = count ;
279
289
280
290
var bufferSize = _batchedInfo . totalBufferSize ;
@@ -342,14 +352,15 @@ return {
342
352
indices [ indiceI ] = currentQuad + 0 ;
343
353
indices [ indiceI + 1 ] = currentQuad + 1 ;
344
354
indices [ indiceI + 2 ] = currentQuad + 2 ;
345
- indices [ indiceI + 3 ] = currentQuad + 1 ;
355
+ indices [ indiceI + 3 ] = currentQuad + 3 ;
346
356
indices [ indiceI + 4 ] = currentQuad + 2 ;
347
- indices [ indiceI + 5 ] = currentQuad + 3 ;
357
+ indices [ indiceI + 5 ] = currentQuad + 1 ;
348
358
currentQuad += 4 ;
349
359
indiceI += cmd . indicesPerUnit ;
350
360
}
351
361
352
362
gl . bufferSubData ( gl . ELEMENT_ARRAY_BUFFER , 0 , indices ) ;
363
+ return count ;
353
364
} ,
354
365
355
366
_batchRendering : function ( ) {
@@ -408,9 +419,11 @@ return {
408
419
cmd = locCmds [ i ] ;
409
420
410
421
// Batching or direct rendering
411
- if ( cmd . _supportBatch ) {
412
- this . _forwardBatch ( i ) ;
422
+ var batchCount = this . _forwardBatch ( i ) ;
423
+ if ( batchCount > 1 ) {
413
424
this . _batchRendering ( ) ;
425
+ // i will increase by 1 each loop
426
+ i += batchCount - 1 ;
414
427
}
415
428
else {
416
429
cmd . rendering ( context ) ;
0 commit comments