Prechádzať zdrojové kódy

fixed plan2D, share it between screenfx

ncannasse 10 rokov pred
rodič
commit
edfecc5c3c
3 zmenil súbory, kde vykonal 10 pridanie a 7 odobranie
  1. 1 3
      h3d/pass/Border.hx
  2. 1 2
      h3d/pass/ScreenFx.hx
  3. 8 2
      h3d/prim/Plan2D.hx

+ 1 - 3
h3d/pass/Border.hx

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

+ 1 - 2
h3d/pass/ScreenFx.hx

@@ -18,7 +18,7 @@ class ScreenFx<T:hxsl.Shader> {
 		pass = new h3d.mat.Pass(Std.string(this), new hxsl.ShaderList(shader));
 		pass.culling = None;
 		pass.depth(false, Always);
-		plan = new h3d.prim.Plan2D();
+		plan = h3d.prim.Plan2D.get();
 		engine = h3d.Engine.getCurrent();
 		fullClearRequired = engine.hasFeature(FullClearRequired);
 	}
@@ -40,7 +40,6 @@ class ScreenFx<T:hxsl.Shader> {
 	}
 
 	public function dispose() {
-		plan.dispose();
 	}
 
 }

+ 8 - 2
h3d/prim/Plan2D.hx

@@ -2,7 +2,7 @@ package h3d.prim;
 
 class Plan2D extends Primitive {
 
-	public function new() {
+	function new() {
 	}
 
 	override function alloc( engine : h3d.Engine ) {
@@ -31,8 +31,14 @@ class Plan2D extends Primitive {
 	}
 
 	override function render(engine:h3d.Engine) {
-		if( buffer == null ) alloc(engine);
+		if( buffer == null || buffer.isDisposed() ) alloc(engine);
 		engine.renderQuadBuffer(buffer);
 	}
 
+	static var inst = null;
+	public static function get() {
+		if( inst == null ) inst = new Plan2D();
+		return inst;
+	}
+
 }