浏览代码

added App.onContextLost, force sync() after contextLost even for fixedPosition

Nicolas Cannasse 3 年之前
父节点
当前提交
f97182a989
共有 4 个文件被更改,包括 17 次插入2 次删除
  1. 1 1
      h3d/scene/Object.hx
  2. 2 1
      h3d/scene/RenderContext.hx
  3. 8 0
      h3d/scene/Scene.hx
  4. 6 0
      hxd/App.hx

+ 1 - 1
h3d/scene/Object.hx

@@ -725,7 +725,7 @@ class Object {
 		var changed = posChanged;
 		if( changed ) calcAbsPos();
 		if( fixedPosition ) {
-			if( flags.has(FFixedPositionSynced) && !changed ) {
+			if( flags.has(FFixedPositionSynced) && !changed && !ctx.wasContextLost ) {
 				ctx.visibleFlag = old;
 				ctx.cullingCollider = prevCollider;
 				return;

+ 2 - 1
h3d/scene/RenderContext.hx

@@ -21,9 +21,10 @@ class RenderContext extends h3d.impl.RenderContext {
 	public var lightSystem : h3d.scene.LightSystem;
 	public var extraShaders : hxsl.ShaderList;
 	public var visibleFlag : Bool;
+	public var debugCulling : Bool;
+	public var wasContextLost : Bool;
 	public var shaderBuffers : h3d.shader.Buffers;
 	public var cullingCollider : h3d.col.Collider;
-	public var debugCulling : Bool;
 
 	var allocPool : h3d.pass.PassObject;
 	var allocFirst : h3d.pass.PassObject;

+ 8 - 0
h3d/scene/Scene.hx

@@ -367,6 +367,13 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 		ctx.elapsedTime = old;
 	}
 
+	/**
+		Automatically called when the 3D context is lost
+	**/
+	public function onContextLost() {
+		ctx.wasContextLost = true;
+	}
+
 	/**
 		Render the scene on screen. Internal usage only.
 	**/
@@ -442,6 +449,7 @@ class Scene extends Object implements h3d.IDrawable implements hxd.SceneEvents.I
 			engine.driver.setRenderFlag(CameraHandness,0);
 
 		ctx.done();
+		ctx.wasContextLost = false;
 		ctx.scene = null;
 		ctx.camera = null;
 		ctx.engine = null;

+ 6 - 0
hxd/App.hx

@@ -95,6 +95,7 @@ class App implements h3d.IDrawable {
 		engine = h3d.Engine.getCurrent(); // if was changed
 		isDisposed = false;
 		engine.onReady = staticHandler; // in case we have another pending app
+		engine.onContextLost = onContextLost;
 		engine.onResized = function() {
 			if( s2d == null ) return; // if disposed
 			s2d.checkResize();
@@ -103,6 +104,10 @@ class App implements h3d.IDrawable {
 		hxd.System.setLoop(mainLoop);
 	}
 
+	function onContextLost() {
+		if( s3d != null ) s3d.onContextLost();
+	}
+
 	function setScene2D( s2d : h2d.Scene, disposePrevious = true ) {
 		sevents.removeScene(this.s2d);
 		sevents.addScene(s2d,0);
@@ -127,6 +132,7 @@ class App implements h3d.IDrawable {
 	function setup() {
 		var initDone = false;
 		engine.onReady = staticHandler;
+		engine.onContextLost = onContextLost;
 		engine.onResized = function() {
 			if( s2d == null ) return; // if disposed
 			s2d.checkResize();