瀏覽代碼

minor changes to render context variables management

Nicolas Cannasse 1 年之前
父節點
當前提交
ef7ed5dda1
共有 2 個文件被更改,包括 9 次插入17 次删除
  1. 7 4
      h3d/scene/RenderContext.hx
  2. 2 13
      h3d/scene/Scene.hx

+ 7 - 4
h3d/scene/RenderContext.hx

@@ -12,8 +12,8 @@ private class SharedGlobal {
 @:build(hxsl.Macros.buildGlobals())
 class RenderContext extends h3d.impl.RenderContext {
 
-	public var camera : h3d.Camera;
-	public var scene : Scene;
+	public var camera(default,null) : h3d.Camera;
+	public var scene(default,null) : Scene;
 	public var drawPass : h3d.pass.PassObject;
 	public var pbrLightPass : h3d.mat.Pass;
 	public var computingStatic : Bool;
@@ -47,14 +47,16 @@ class RenderContext extends h3d.impl.RenderContext {
 	var passes : Array<h3d.pass.PassObject>;
 	var lights : Light;
 
-	public function new() {
+	public function new(scene) {
 		super();
+		this.scene = scene;
 		cachedShaderList = [];
 		cachedPassObjects = [];
 		initGlobals();
 	}
 
 	public function setCamera( cam : h3d.Camera ) {
+		camera = cam;
 		cameraView = cam.mcam;
 		cameraNear = cam.zNear;
 		cameraFar = cam.zFar;
@@ -94,9 +96,10 @@ class RenderContext extends h3d.impl.RenderContext {
 		time += elapsedTime;
 		frame++;
 		setCurrent();
+		engine = h3d.Engine.getCurrent();
 		globalTime = time;
 		pixelSize = getCurrentPixelSize();
-		setCamera(camera);
+		setCamera(scene.camera);
 	}
 
 	public inline function nextPass() {

+ 2 - 13
h3d/scene/Scene.hx

@@ -45,7 +45,7 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		var engine = h3d.Engine.getCurrent();
 		if( engine != null )
 			camera.screenRatio = engine.width / engine.height;
-		ctx = new RenderContext();
+		ctx = new RenderContext(this);
 		if( createRenderer ) renderer = h3d.mat.MaterialSetup.current.createRenderer();
 		if( createLightSystem ) lightSystem = h3d.mat.MaterialSetup.current.createLightSystem();
 	}
@@ -285,14 +285,9 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		else
 			camera.screenRatio = t.width / t.height;
 		camera.update();
-		ctx.camera = camera;
-		ctx.engine = engine;
-		ctx.scene = this;
 		ctx.start();
 		syncRec(ctx);
-		ctx.camera = null;
-		ctx.engine = null;
-		ctx.scene = null;
+		ctx.done();
 	}
 
 	/**
@@ -334,9 +329,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		if( camera.rightHanded )
 			engine.driver.setRenderFlag(CameraHandness,1);
 
-		ctx.camera = camera;
-		ctx.engine = engine;
-		ctx.scene = this;
 		ctx.start();
 		renderer.start();
 
@@ -385,9 +377,6 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 
 		ctx.done();
 		ctx.wasContextLost = false;
-		ctx.scene = null;
-		ctx.camera = null;
-		ctx.engine = null;
 		for( i in 0...passIndex ) {
 			var p = ctx.cachedPassObjects[i];
 			p.name = null;