Indexes.hx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package h3d;
  2. @:allow(h3d.impl.MemoryManager)
  3. @:allow(h3d.Engine)
  4. class Indexes {
  5. var mem : h3d.impl.MemoryManager;
  6. var ibuf : h3d.impl.Driver.IndexBuffer;
  7. public var is32(default,null) : Bool;
  8. public var count(default,null) : Int;
  9. #if track_alloc
  10. var allocPos : hxd.impl.AllocPos;
  11. #end
  12. public function new(count,is32=false) {
  13. this.mem = h3d.Engine.getCurrent().mem;
  14. this.count = count;
  15. this.is32 = is32;
  16. mem.allocIndexes(this);
  17. #if track_alloc
  18. allocPos = new hxd.impl.AllocPos();
  19. #end
  20. }
  21. public function isDisposed() {
  22. return ibuf == null;
  23. }
  24. public function upload( indexes : hxd.IndexBuffer, pos : Int, count : Int, bufferPos = 0 ) {
  25. mem.driver.uploadIndexBuffer(this.ibuf, pos, count, indexes, bufferPos);
  26. }
  27. public function uploadBytes( bytes : haxe.io.Bytes, dataPos : Int, indices : Int ) {
  28. mem.driver.uploadIndexBytes(this.ibuf, 0, indices, bytes, dataPos);
  29. }
  30. public function readBytes( bytes : haxe.io.Bytes, bytesPosition : Int, indices : Int, startIndice : Int = 0 ) {
  31. mem.driver.readIndexBytes(this.ibuf, startIndice, indices, bytes, bytesPosition);
  32. }
  33. public function dispose() {
  34. if( ibuf != null )
  35. mem.deleteIndexes(this);
  36. }
  37. public static function alloc( i : hxd.IndexBuffer, startPos = 0, length = -1 ) {
  38. if( length < 0 ) length = i.length;
  39. var idx = new Indexes( length );
  40. idx.upload(i, 0, length);
  41. return idx;
  42. }
  43. }