浏览代码

BigPrimitive.begin now requires index count

ncannasse 9 年之前
父节点
当前提交
124777e50d
共有 3 个文件被更改,包括 19 次插入5 次删除
  1. 10 4
      h3d/prim/BigPrimitive.hx
  2. 1 1
      h3d/scene/Graphics.hx
  3. 8 0
      hxd/IndexBuffer.hx

+ 10 - 4
h3d/prim/BigPrimitive.hx

@@ -39,10 +39,10 @@ class BigPrimitive extends Primitive {
 		Call begin() before starting to add vertexes/indexes to the primitive.
 		Call begin() before starting to add vertexes/indexes to the primitive.
 		The count value is the number of vertexes you will add, it will automatically flush() if it doesn't fit into the current buffer.
 		The count value is the number of vertexes you will add, it will automatically flush() if it doesn't fit into the current buffer.
 	**/
 	**/
-	public function begin(count) {
+	public function begin(vcount,icount) {
 		startIndex = Std.int(bufPos / stride);
 		startIndex = Std.int(bufPos / stride);
-		if( startIndex + count >= 65535 ) {
-			if( count >= 65535 ) throw "Too many vertices in begin()";
+		if( startIndex + vcount >= 65535 ) {
+			if( vcount >= 65535 ) throw "Too many vertices in begin()";
 			flush();
 			flush();
 		}
 		}
 		if( tmpBuf == null ) {
 		if( tmpBuf == null ) {
@@ -60,6 +60,12 @@ class BigPrimitive extends Primitive {
 			else
 			else
 				PREV_INDEX = null;
 				PREV_INDEX = null;
 		}
 		}
+		if( idxPos + icount > tmpIdx.length ) {
+			var size = tmpIdx.length == 0 ? 1024 : tmpIdx.length;
+			var req = idxPos + icount;
+			while( size < req ) size <<= 1;
+			tmpIdx.grow(size);
+		}
 	}
 	}
 
 
 	/**
 	/**
@@ -170,7 +176,7 @@ class BigPrimitive extends Primitive {
 	public function addSub( buf : hxd.FloatBuffer, idx : hxd.IndexBuffer, startVert, startTri, nvert, triCount, dx : Float = 0. , dy : Float = 0., dz : Float = 0., rotation = 0., scale = 1., stride = -1, deltaU = 0., deltaV = 0., color = 1. ) {
 	public function addSub( buf : hxd.FloatBuffer, idx : hxd.IndexBuffer, startVert, startTri, nvert, triCount, dx : Float = 0. , dy : Float = 0., dz : Float = 0., rotation = 0., scale = 1., stride = -1, deltaU = 0., deltaV = 0., color = 1. ) {
 		if( stride < 0 ) stride = this.stride;
 		if( stride < 0 ) stride = this.stride;
 		if( stride < this.stride ) throw "only stride >= " + this.stride+" allowed";
 		if( stride < this.stride ) throw "only stride >= " + this.stride+" allowed";
-		begin(nvert);
+		begin(nvert, triCount*3);
 		var start = startIndex;
 		var start = startIndex;
 		var cr = Math.cos(rotation);
 		var cr = Math.cos(rotation);
 		var sr = Math.sin(rotation);
 		var sr = Math.sin(rotation);

+ 1 - 1
h3d/scene/Graphics.hx

@@ -56,7 +56,7 @@ class Graphics extends Mesh {
 	}
 	}
 
 
 	public function lineTo( x : Float, y : Float, z : Float ) {
 	public function lineTo( x : Float, y : Float, z : Float ) {
-		bprim.begin(4);
+		bprim.begin(4,6);
 		var nx = x - curX;
 		var nx = x - curX;
 		var ny = y - curY;
 		var ny = y - curY;
 		var nz = z - curZ;
 		var nz = z - curZ;

+ 8 - 0
hxd/IndexBuffer.hx

@@ -41,6 +41,14 @@ abstract IndexBuffer(InnerData) {
 		#end
 		#end
 	}
 	}
 
 
+	public inline function grow( v : Int ) {
+		#if flash
+		if( v > this.length ) this.length = v;
+		#else
+		while( this.length < v ) this.push(0);
+		#end
+	}
+
 	@:arrayAccess inline function arrayRead(key:Int) : Int {
 	@:arrayAccess inline function arrayRead(key:Int) : Int {
 		return this[key];
 		return this[key];
 	}
 	}