فهرست منبع

Trails: alloc larger buffers to avoid re-allocating every frame

trethaller 6 سال پیش
والد
کامیت
9a8add2ebc
2فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 7 2
      h3d/prim/DynamicPrimitive.hx
  2. 4 0
      h3d/scene/Trail.hx

+ 7 - 2
h3d/prim/DynamicPrimitive.hx

@@ -8,6 +8,11 @@ class DynamicPrimitive extends Primitive {
 	var isize : Int;
 	var stride : Int;
 
+	/** Minimum number of elements in vertex buffer **/
+	public var minVSize = 0;
+	/** Minimum number of elements in index index buffer **/
+	public var minISize = 0;
+
 	public var bounds = new h3d.col.Bounds();
 
 	public function new( stride : Int ) {
@@ -54,9 +59,9 @@ class DynamicPrimitive extends Primitive {
 		}
 
 		if( buffer == null )
-			buffer = alloc.allocBuffer(vsize, stride, Dynamic);
+			buffer = alloc.allocBuffer(hxd.Math.imax(minVSize, vsize), stride, Dynamic);
 		if( indexes == null )
-			indexes = alloc.allocIndexBuffer(isize);
+			indexes = alloc.allocIndexBuffer(hxd.Math.imax(minISize, isize));
 
 		buffer.uploadVector(vbuf, 0, vsize);
 		indexes.upload(ibuf, 0, isize);

+ 4 - 0
h3d/scene/Trail.hx

@@ -252,6 +252,10 @@ class Trail extends Mesh {
 			idx[out++] = p + 1;
 		}
 
+		var reservePoints = Math.ceil(duration * hxd.Timer.wantedFPS);
+		dprim.minVSize = hxd.Math.nextPOT(reservePoints * 2);
+		dprim.minISize = hxd.Math.nextPOT(reservePoints * 6);
+
 		dprim.flush();
 	}