Browse Source

setTarget returns previous target (allows cascading)

Nicolas Cannasse 11 years ago
parent
commit
098f999c17
2 changed files with 5 additions and 3 deletions
  1. 2 1
      h2d/RenderContext.hx
  2. 3 2
      h3d/Engine.hx

+ 2 - 1
h2d/RenderContext.hx

@@ -71,9 +71,10 @@ class RenderContext {
 
 
 	public function setTarget( t : h3d.mat.Texture ) {
 	public function setTarget( t : h3d.mat.Texture ) {
 		flush();
 		flush();
-		engine.setTarget(t);
+		var old = engine.setTarget(t);
 		baseShader.halfPixelInverse.set(0.5 / (t == null ? engine.width : t.width), 0.5 / (t == null ? engine.height : t.height));
 		baseShader.halfPixelInverse.set(0.5 / (t == null ? engine.width : t.width), 0.5 / (t == null ? engine.height : t.height));
 		begin();
 		begin();
+		return old;
 	}
 	}
 
 
 	public function flush() {
 	public function flush() {

+ 3 - 2
h3d/Engine.hx

@@ -27,6 +27,7 @@ class Engine {
 	var lastTime : Float;
 	var lastTime : Float;
 	var antiAlias : Int;
 	var antiAlias : Int;
 	var tmpVector = new h3d.Vector();
 	var tmpVector = new h3d.Vector();
+	var currentTarget : h3d.mat.Texture;
 
 
 	@:allow(h3d)
 	@:allow(h3d)
 	var curProjMatrix : h3d.Matrix;
 	var curProjMatrix : h3d.Matrix;
@@ -267,8 +268,6 @@ class Engine {
 		curProjMatrix = null;
 		curProjMatrix = null;
 	}
 	}
 
 
-	var currentTarget : h3d.mat.Texture;
-
 	public function getTarget() {
 	public function getTarget() {
 		return currentTarget;
 		return currentTarget;
 	}
 	}
@@ -278,8 +277,10 @@ class Engine {
      * setTarget to null when you're finished rendering to it.
      * setTarget to null when you're finished rendering to it.
 	 */
 	 */
 	public function setTarget( tex : h3d.mat.Texture ) {
 	public function setTarget( tex : h3d.mat.Texture ) {
+		var prev = currentTarget;
 		currentTarget = tex;
 		currentTarget = tex;
 		driver.setRenderTarget(tex);
 		driver.setRenderTarget(tex);
+		return prev;
 	}
 	}
 
 
 	public function clear( ?color : Int, ?depth : Float, ?stencil : Int ) {
 	public function clear( ?color : Int, ?depth : Float, ?stencil : Int ) {