Indexes.hx 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. package h3d;
  2. @:forward(isDisposed, dispose, uploadBytes)
  3. abstract Indexes(Buffer) to Buffer {
  4. public var count(get,never) : Int;
  5. public function new(count:Int,is32=false) {
  6. this = new Buffer(count,is32 ? hxd.BufferFormat.INDEX32 : hxd.BufferFormat.INDEX16, [IndexBuffer]);
  7. }
  8. public function uploadIndexes( ibuf : hxd.IndexBuffer, bufPos : Int, indices : Int, startIndice = 0 ) {
  9. if( startIndice < 0 || indices < 0 || startIndice + indices > this.vertices )
  10. throw "Invalid indices count";
  11. if( @:privateAccess this.format.inputs[0].precision != F16 )
  12. throw "Can't upload indexes on a 32-bit buffer";
  13. if( indices == 0 )
  14. return;
  15. h3d.Engine.getCurrent().driver.uploadIndexData(this, startIndice, indices, ibuf, bufPos);
  16. }
  17. inline function get_count() return this.vertices;
  18. public static function alloc( i : hxd.IndexBuffer, startPos = 0, length = -1 ) : Indexes {
  19. if( length < 0 ) length = i.length;
  20. var idx = new Indexes(length);
  21. idx.uploadIndexes(i, 0, length);
  22. return idx;
  23. }
  24. }