@@ -96,6 +96,7 @@ class MeshBatch extends MultiMaterial {
9696 function getMaxElements () return storageBufferEnabled () ? MAX_STORAGE_BUFFER_ELEMENTS : MAX_BUFFER_ELEMENTS ;
9797 function hasPrimitiveOffset () return meshBatchFlags .has (HasPrimitiveOffset );
9898 function useCommandBuffer () return false ;
99+ function useCountBuffer () return false ;
99100
100101 public function begin ( emitCountTip = - 1 ) : Int {
101102 instanceCount = 0 ;
@@ -338,15 +339,15 @@ class MeshBatch extends MultiMaterial {
338339 var commandCountAllocated = hxd. Math .imin ( hxd. Math .nextPOT ( count ), p .maxInstance );
339340 if ( p .commandBuffers == null ) {
340341 p .commandBuffers = [];
341- p .countBuffers = [];
342+ if ( useCountBuffer () )
343+ p .countBuffers = [];
342344 }
343345 var buf = p .commandBuffers [index ];
344- var cbuf = p .countBuffers [index ];
345346 if ( buf == null ) {
346347 buf = alloc .allocBuffer ( commandCountAllocated , INDIRECT_DRAW_ARGUMENTS_FMT , UniformReadWrite );
347- cbuf = alloc .allocBuffer ( 1 , hxd. BufferFormat .VEC4_DATA , UniformReadWrite );
348348 p .commandBuffers [index ] = buf ;
349- p .countBuffers [index ] = cbuf ;
349+ if ( useCountBuffer () )
350+ p .countBuffers [index ] = alloc .allocBuffer ( 1 , hxd. BufferFormat .VEC4_DATA , UniformReadWrite );
350351 }
351352 else if ( buf .vertices < commandCountAllocated ) {
352353 alloc .disposeBuffer ( buf );
@@ -507,7 +508,8 @@ class MeshBatch extends MultiMaterial {
507508 instanced .setCommand (p .matIndex , instanced .screenRatioToLod (curScreenRatio ), count );
508509 if ( useCommandBuffer () ) {
509510 @:privateAccess instanced .commands .data = p .commandBuffers [bufferIndex ].vbuf ;
510- @:privateAccess instanced .commands .countBuffer = p .countBuffers [bufferIndex ].vbuf ;
511+ if ( useCountBuffer () )
512+ @:privateAccess instanced .commands .countBuffer = p .countBuffers [bufferIndex ].vbuf ;
511513 }
512514 } else
513515 instanced .commands = p .instanceBuffers [bufferIndex ];
@@ -597,13 +599,15 @@ class BatchData {
597599
598600 public function clean () {
599601 var alloc = hxd.impl. Allocator .get ();
600- if ( commandBuffers != null && commandBuffers . length > 0 ) {
602+ if ( commandBuffers != null ) {
601603 for ( buf in commandBuffers )
602604 alloc .disposeBuffer (buf );
603- commandBuffers .resize (0 );
605+ commandBuffers = null ;
606+ }
607+ if ( countBuffers != null ) {
604608 for ( buf in countBuffers )
605609 alloc .disposeBuffer (buf );
606- countBuffers . resize ( 0 ) ;
610+ countBuffers = null ;
607611 }
608612
609613 pass .removeShader (shader );
0 commit comments