@@ -33,7 +33,7 @@ var _batchedInfo = {
33
33
blendSrc : null ,
34
34
// The batched blend destination, all batching element should have the same blend destination
35
35
blendDst : null ,
36
- // The batched glProgramState , all batching element should have the same glProgramState
36
+ // The batched gl program state , all batching element should have the same state
37
37
glProgramState : null
38
38
} ,
39
39
@@ -129,7 +129,7 @@ return {
129
129
_cacheToBufferCmds : { } , // an array saves the renderer commands need for cache to other canvas
130
130
_cacheInstanceIds : [ ] ,
131
131
_currentID : 0 ,
132
- _clearColor : cc . color ( ) , //background color,default BLACK
132
+ _clearColor : cc . color ( 0 , 0 , 0 , 255 ) , //background color,default BLACK
133
133
134
134
init : function ( ) {
135
135
var gl = cc . _renderContext ;
@@ -138,7 +138,7 @@ return {
138
138
139
139
this . mat4Identity = new cc . math . Matrix4 ( ) ;
140
140
this . mat4Identity . identity ( ) ;
141
- initQuadBuffer ( 2000 ) ;
141
+ initQuadBuffer ( cc . BATCH_VERTEX_COUNT ) ;
142
142
if ( cc . sys . os === cc . sys . OS_IOS ) {
143
143
_IS_IOS = true ;
144
144
}
@@ -313,18 +313,23 @@ return {
313
313
_batchingSize += increment ;
314
314
} ,
315
315
316
- _updateBatchedInfo : function ( texture , blendFunc , shaderProgram ) {
317
- if ( texture ) {
316
+ _updateBatchedInfo : function ( texture , blendFunc , glProgramState ) {
317
+ if ( texture !== _batchedInfo . texture ||
318
+ blendFunc . src !== _batchedInfo . blendSrc ||
319
+ blendFunc . dst !== _batchedInfo . blendDst ||
320
+ glProgramState !== _batchedInfo . glProgramState ) {
321
+ // Draw batched elements
322
+ this . _batchRendering ( ) ;
323
+ // Update _batchedInfo
318
324
_batchedInfo . texture = texture ;
319
- }
320
-
321
- if ( blendFunc ) {
322
325
_batchedInfo . blendSrc = blendFunc . src ;
323
326
_batchedInfo . blendDst = blendFunc . dst ;
324
- }
327
+ _batchedInfo . glProgramState = glProgramState ;
325
328
326
- if ( shaderProgram ) {
327
- _batchedInfo . shader = shaderProgram ;
329
+ return true ;
330
+ }
331
+ else {
332
+ return false ;
328
333
}
329
334
} ,
330
335
@@ -339,7 +344,7 @@ return {
339
344
340
345
// Check batching
341
346
var node = cmd . _node ;
342
- var texture = node . _texture || ( node . _spriteFrame ? node . _spriteFrame . _texture : null ) ;
347
+ var texture = node . _texture || ( node . _spriteFrame && node . _spriteFrame . _texture ) ;
343
348
var blendSrc = node . _blendFunc . src ;
344
349
var blendDst = node . _blendFunc . dst ;
345
350
var glProgramState = cmd . _glProgramState ;
@@ -361,38 +366,7 @@ return {
361
366
// Upload vertex data
362
367
var len = cmd . uploadData ( _vertexDataF32 , _vertexDataUI32 , _batchingSize * _sizePerVertex ) ;
363
368
if ( len > 0 ) {
364
- var i , curr , type = cmd . vertexType || VertexType . QUAD ;
365
- switch ( type ) {
366
- case VertexType . QUAD :
367
- for ( i = 0 ; i < len ; i += 4 ) {
368
- curr = _batchingSize + i ;
369
- _indexData [ _indexSize ++ ] = curr + 0 ;
370
- _indexData [ _indexSize ++ ] = curr + 1 ;
371
- _indexData [ _indexSize ++ ] = curr + 2 ;
372
- _indexData [ _indexSize ++ ] = curr + 1 ;
373
- _indexData [ _indexSize ++ ] = curr + 2 ;
374
- _indexData [ _indexSize ++ ] = curr + 3 ;
375
- }
376
- break ;
377
- case VertexType . TRIANGLE :
378
- _pureQuad = false ;
379
- for ( i = 0 ; i < len ; i += 3 ) {
380
- curr = _batchingSize + i ;
381
- _indexData [ _indexSize ++ ] = curr + 0 ;
382
- _indexData [ _indexSize ++ ] = curr + 1 ;
383
- _indexData [ _indexSize ++ ] = curr + 2 ;
384
- }
385
- break ;
386
- case VertexType . CUSTOM :
387
- _pureQuad = false ;
388
- if ( cmd . uploadIndexData ) {
389
- _indexSize += cmd . uploadIndexData ( _indexData , _indexSize , _batchingSize ) ;
390
- }
391
- break ;
392
- default :
393
- return ;
394
- }
395
- _batchingSize += len ;
369
+ this . _increaseBatchingSize ( len , cmd . vertexType ) ;
396
370
}
397
371
} ,
398
372
0 commit comments