Sfoglia il codice sorgente

make s2d.renderer customizable

ncannasse 8 anni fa
parent
commit
77252f2a4c
2 ha cambiato i file con 19 aggiunte e 1 eliminazioni
  1. 14 0
      h2d/RenderContext.hx
  2. 5 1
      h2d/Scene.hx

+ 14 - 0
h2d/RenderContext.hx

@@ -96,6 +96,16 @@ class RenderContext extends h3d.impl.RenderContext {
 		textures.begin(this);
 	}
 
+	public function allocTarget(name, filter = false, size = 0) {
+		var t = textures.allocTarget(name, this, scene.width >> size, scene.height >> size, false);
+		t.filter = filter ? Linear : Nearest;
+		return t;
+	}
+
+	public function clear(color) {
+		engine.clear(color);
+	}
+
 	function initShaders( shaders ) {
 		currentShaders = shaders;
 		compiledShader = manager.compileShaders(shaders);
@@ -205,6 +215,10 @@ class RenderContext extends h3d.impl.RenderContext {
 		engine.setRenderZone();
 	}
 
+	public function drawScene() {
+		@:privateAccess scene.drawRec(this);
+	}
+
 	public inline function flush() {
 		if( hasBuffering() ) _flush();
 	}

+ 5 - 1
h2d/Scene.hx

@@ -11,6 +11,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 
 	public var zoom(get, set) : Int;
 	public var defaultFilter(get, set) : Bool;
+	public var renderer(get, set) : RenderContext;
 
 	var fixedSize : Bool;
 	var interactive : Array<Interactive>;
@@ -57,6 +58,9 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		return v;
 	}
 
+	function get_renderer() return ctx;
+	function set_renderer(v) { ctx = v; return v; }
+
 	public function setFixedSize( w, h ) {
 		width = w;
 		height = h;
@@ -370,7 +374,7 @@ class Scene extends Layers implements h3d.IDrawable implements hxd.SceneEvents.I
 		sync(ctx);
 		if( childs.length == 0 ) return;
 		ctx.begin();
-		drawRec(ctx);
+		ctx.drawScene();
 		ctx.end();
 	}