소스 검색

changed RawPrimitive to allow context lost reuse of buffers

ncannasse 10 년 전
부모
커밋
9f34d63d28
2개의 변경된 파일17개의 추가작업 그리고 10개의 파일을 삭제
  1. 1 4
      h3d/pass/Border.hx
  2. 16 6
      h3d/prim/RawPrimitive.hx

+ 1 - 4
h3d/pass/Border.hx

@@ -55,13 +55,10 @@ class Border extends ScreenFx<BorderShader> {
 		add(width-size, height);
 		add(width, height);
 
-		var plan = new h3d.prim.RawPrimitive(engine, bbuf, 2);
-		plan.buffer.flags.unset(Triangles);
-		plan.buffer.flags.set(Quads);
+		var plan = new h3d.prim.RawPrimitive({ vbuf : bbuf, stride : 2, quads : true }, true);
 		this.plan.dispose();
 		this.plan = plan;
 		shader.color.set(1,1,1,1);
 	}
 
-
 }

+ 16 - 6
h3d/prim/RawPrimitive.hx

@@ -2,13 +2,23 @@ package h3d.prim;
 
 class RawPrimitive extends Primitive {
 
-	public function new( engine : h3d.Engine, vbuf : hxd.FloatBuffer, stride : Int, ?ibuf : hxd.IndexBuffer ) {
+	public var onContextLost : Void -> { vbuf : hxd.FloatBuffer, stride : Int, ?ibuf : hxd.IndexBuffer, ?quads : Bool };
+
+	public function new( inf : { vbuf : hxd.FloatBuffer, stride : Int, ?ibuf : hxd.IndexBuffer, ?quads : Bool }, persist = false ) {
+		onContextLost = function() return inf;
+		alloc(null);
+		if( !persist ) onContextLost = null;
+	}
+
+	override function alloc( engine : h3d.Engine ) {
+		if( onContextLost == null ) throw "Cannot realloc " + this;
+		var inf = onContextLost();
 		var flags : Array<h3d.Buffer.BufferFlag> = [];
-		if( ibuf == null ) flags.push(Triangles);
-		if( stride < 8 ) flags.push(RawFormat);
-		buffer = h3d.Buffer.ofFloats(vbuf, stride, flags);
-		if( ibuf != null )
-			indexes = h3d.Indexes.alloc(ibuf);
+		if( inf.ibuf == null ) flags.push(inf.quads ? Quads : Triangles);
+		if( inf.stride < 8 ) flags.push(RawFormat);
+		buffer = h3d.Buffer.ofFloats(inf.vbuf, inf.stride, flags);
+		if( inf.ibuf != null )
+			indexes = h3d.Indexes.alloc(inf.ibuf);
 	}
 
 }