InstanceBuffer.hx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package h3d.impl;
  2. @:allow(h3d.impl.Driver)
  3. class InstanceBuffer {
  4. var data : Dynamic;
  5. var driver : h3d.impl.Driver;
  6. var indexCount : Int;
  7. var startIndex : Int;
  8. public var triCount(default,null) : Int = 0;
  9. public var commandCount(default, null) : Int;
  10. public function new() {
  11. }
  12. public function setCommand( commandCount : Int, indexCount : Int, startIndex=0 ) {
  13. this.commandCount = commandCount;
  14. this.indexCount = indexCount;
  15. this.triCount = Std.int((commandCount * indexCount) / 3);
  16. this.startIndex = startIndex;
  17. }
  18. /**
  19. Bytes are structures of 5 i32 with the following values:
  20. - indexCount : number of indexes per instance
  21. - instanceCount : number of indexed draws
  22. - startIndexLocation : offset in indexes
  23. - baseVertexLocation : offset in buffer
  24. - startInstanceLocation : offset in per instance buffer
  25. **/
  26. public function setBuffer( commandCount : Int, bytes : haxe.io.Bytes ) {
  27. dispose();
  28. for( i in 0...commandCount ) {
  29. var idxCount = bytes.getInt32(i * 20);
  30. var instCount = bytes.getInt32(i * 20 + 4);
  31. var tri = Std.int((idxCount * instCount) / 3);
  32. triCount += tri;
  33. }
  34. this.commandCount = commandCount;
  35. this.indexCount = 0;
  36. driver = h3d.Engine.getCurrent().driver;
  37. driver.allocInstanceBuffer(this, bytes);
  38. }
  39. public function dispose() {
  40. if( data != null ) driver.disposeInstanceBuffer(this);
  41. }
  42. }