@@ -3,6 +3,16 @@ package h3d.impl;
33@:allow (h3d.impl. Driver )
44class InstanceBuffer {
55
6+ /**
7+ Bytes are structures of 5 i32 with the following values:
8+ - indexCount : number of indexes per instance
9+ - instanceCount : number of indexed draws
10+ - startIndexLocation : offset in indexes
11+ - baseVertexLocation : offset in buffer
12+ - startInstanceLocation : offset in per instance buffer
13+ **/
14+ public static var ELEMENT_SIZE = 20 ;
15+
616 var countBuffer : Dynamic ;
717 var data : Dynamic ;
818 var driver : h3d.impl. Driver ;
@@ -25,38 +35,29 @@ class InstanceBuffer {
2535 {
2636 triCount = 0 ;
2737 for ( i in 0 ... commandCount ) {
28- var idxCount = bytes .getInt32 (i * 20 );
29- var instCount = bytes .getInt32 (i * 20 + 4 );
38+ var idxCount = bytes .getInt32 (i * ELEMENT_SIZE );
39+ var instCount = bytes .getInt32 (i * ELEMENT_SIZE + 4 );
3040 var tri = Std .int ((idxCount * instCount ) / 3 );
3141 triCount + = tri ;
3242 }
3343 }
3444
35- /**
36- Bytes are structures of 5 i32 with the following values:
37- - indexCount : number of indexes per instance
38- - instanceCount : number of indexed draws
39- - startIndexLocation : offset in indexes
40- - baseVertexLocation : offset in buffer
41- - startInstanceLocation : offset in per instance buffer
42- **/
43- public function setBuffer ( commandCount : Int , bytes : haxe.io. Bytes ) {
44- if (commandCount > this .commandCount ){
45- dispose ();
45+ public function uploadBytes (commandCount : Int , bytes : haxe.io. Bytes ) {
46+ updateTriCount (commandCount , bytes );
47+ this .commandCount = commandCount ;
48+ this .indexCount = 0 ;
49+ driver = h3d. Engine .getCurrent ().driver ;
50+ driver .uploadInstanceBufferBytes (this , 0 , commandCount , bytes , 0 );
51+ }
4652
47- updateTriCount (commandCount , bytes );
48- this .commandCount = commandCount ;
49- this .indexCount = 0 ;
50- driver = h3d. Engine .getCurrent ().driver ;
51- driver .allocInstanceBuffer (this , bytes );
52- } else {
53+ public function allocFromBytes (commandCount : Int , bytes : haxe.io. Bytes ) {
54+ dispose ();
5355
54- updateTriCount (commandCount , bytes );
55- this .commandCount = commandCount ;
56- this .indexCount = 0 ;
57- driver = h3d. Engine .getCurrent ().driver ;
58- driver .uploadInstanceBufferBytes (this , 0 , commandCount , bytes , 0 );
59- }
56+ updateTriCount (commandCount , bytes );
57+ this .commandCount = commandCount ;
58+ this .indexCount = 0 ;
59+ driver = h3d. Engine .getCurrent ().driver ;
60+ driver .allocInstanceBuffer (this , bytes );
6061 }
6162
6263 public function dispose () {
0 commit comments