bstouls 8 years ago
parent
commit
e51609ca36
4 changed files with 35 additions and 12 deletions
  1. 4 0
      h3d/Engine.hx
  2. 7 11
      h3d/scene/Renderer.hx
  3. 5 1
      h3d/scene/Scene.hx
  4. 19 0
      hxd/App.hx

+ 4 - 0
h3d/Engine.hx

@@ -277,6 +277,10 @@ class Engine {
 		driver.present();
 		driver.present();
 	}
 	}
 
 
+	public function getCurrentTarget() {
+		return targetStack == null ? null : targetStack.t;
+	}
+
 	public function pushTarget( tex : h3d.mat.Texture ) {
 	public function pushTarget( tex : h3d.mat.Texture ) {
 		var c = targetTmp;
 		var c = targetTmp;
 		if( c == null )
 		if( c == null )

+ 7 - 11
h3d/scene/Renderer.hx

@@ -125,18 +125,17 @@ class Renderer {
 		ctx.engine.clear(color, depth, stencil);
 		ctx.engine.clear(color, depth, stencil);
 	}
 	}
 
 
-	inline function pushTarget( tex ) {
-		ctx.engine.pushTarget(tex);
-	}
-
-	inline function setTarget( tex ) {
+	function setTarget( tex ) {
 		if( hasSetTarget ) ctx.engine.popTarget();
 		if( hasSetTarget ) ctx.engine.popTarget();
 		ctx.engine.pushTarget(tex);
 		ctx.engine.pushTarget(tex);
 		hasSetTarget = true;
 		hasSetTarget = true;
 	}
 	}
 
 
-	inline function popTarget() {
-		ctx.engine.popTarget();
+	function resetTarget() {
+		if( hasSetTarget ) {
+			ctx.engine.popTarget();
+			hasSetTarget = false;
+		}
 	}
 	}
 
 
 	function get( name : String ) {
 	function get( name : String ) {
@@ -180,10 +179,7 @@ class Renderer {
 			passGroups.set(p.name, p);
 			passGroups.set(p.name, p);
 		}
 		}
 		render();
 		render();
-		if( hasSetTarget ) {
-			ctx.engine.popTarget();
-			hasSetTarget = false;
-		}
+		resetTarget();
 		for( p in passes )
 		for( p in passes )
 			passGroups.set(p.name, null);
 			passGroups.set(p.name, null);
 	}
 	}

+ 5 - 1
h3d/scene/Scene.hx

@@ -263,7 +263,11 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		if( !allocated )
 		if( !allocated )
 			onAlloc();
 			onAlloc();
 
 
-		camera.screenRatio = engine.width / engine.height;
+		var t = engine.getCurrentTarget();
+		if( t == null )
+			camera.screenRatio = engine.width / engine.height;
+		else
+			camera.screenRatio = t.width / t.height;
 		camera.update();
 		camera.update();
 		ctx.camera = camera;
 		ctx.camera = camera;
 		ctx.engine = engine;
 		ctx.engine = engine;

+ 19 - 0
hxd/App.hx

@@ -30,6 +30,25 @@ class App {
 	function onResize() {
 	function onResize() {
 	}
 	}
 
 
+	function setScene3D( s3d : h3d.scene.Scene, disposePrevious = true ) {
+		sevents.removeScene(this.s3d);
+		sevents.addScene(s3d);
+		s3d.addPass(s2d);
+		if( disposePrevious )
+			this.s3d.dispose();
+		this.s3d = s3d;
+	}
+
+	function setScene2D( s2d : h2d.Scene, disposePrevious = true ) {
+		sevents.removeScene(this.s2d);
+		sevents.addScene(s2d,0);
+		s3d.removePass(this.s2d);
+		s3d.addPass(s2d);
+		if( disposePrevious )
+			this.s2d.dispose();
+		this.s2d = s2d;
+	}
+
 	function setup() {
 	function setup() {
 		var initDone = false;
 		var initDone = false;
 		engine.onResized = function() {
 		engine.onResized = function() {