Browse Source

solved multiple gl context issues

ncannasse 7 năm trước cách đây
mục cha
commit
973cab6dc5
4 tập tin đã thay đổi với 49 bổ sung4 xóa
  1. 1 1
      hide.hxproj
  2. 12 1
      hide/comp/Scene.hx
  3. 9 1
      hide/comp/SceneTree.hx
  4. 27 1
      hide/ui/Ide.hx

+ 1 - 1
hide.hxproj

@@ -24,7 +24,7 @@
     <option noInlineOnDebug="False" />
     <option mainClass="hide.ui.Ide" />
     <option enabledebug="False" />
-    <option additional="-D hscriptPos&#xA;-D old-error-format&#xA;-dce no" />
+    <option additional="-D hscriptPos&#xA;-D old-error-format&#xA;-D multidriver&#xA;-dce no" />
   </build>
   <!-- haxelib libraries -->
   <haxelib>

+ 12 - 1
hide/comp/Scene.hx

@@ -67,6 +67,7 @@ class Scene extends Component implements h3d.IDrawable {
 	public var s3d : h3d.scene.Scene;
 	public var sevents : hxd.SceneEvents;
 	public var speed : Float = 1.0;
+	public var visible(default, null) : Bool = true;
 
 	public function new(root) {
 		super(root);
@@ -116,6 +117,7 @@ class Scene extends Component implements h3d.IDrawable {
 		};
 		engine.onResized = function() {
 			if( s2d == null ) return;
+			visible = engine.width > 32 && engine.height > 32; // 32x32 when hidden !
 			s2d.setFixedSize(engine.width, engine.height);
 			onResize();
 		};
@@ -145,17 +147,24 @@ class Scene extends Component implements h3d.IDrawable {
 		initRec(root);
 	}
 
-	function setCurrent() {
+	public function setCurrent() {
 		engine.setCurrent();
 		stage.setCurrent();
 	}
 
+	function checkCurrent() {
+		if( h3d.Engine.getCurrent() != engine )
+			throw "Invalid current engine : use setCurrent() first";
+	}
+
 	function sync() {
 		if( new Element(canvas).parents("html").length == 0 ) {
 			stage.dispose();
 			ide.unregisterUpdate(sync);
 			return;
 		}
+		if( !visible )
+			return;
 		setCurrent();
 		sevents.checkEvents();
 		s2d.setElapsedTime(hxd.Timer.tmod * speed / 60);
@@ -254,6 +263,7 @@ class Scene extends Component implements h3d.IDrawable {
 	}
 
 	public function loadModel( path : String, mainScene = false ) {
+		checkCurrent();
 		if( StringTools.endsWith(path.toLowerCase(), ".hsd") ) {
 			var hsd = loadHSD(path);
 			if( mainScene ) defaultCamera = hsd.camera;
@@ -333,6 +343,7 @@ class Scene extends Component implements h3d.IDrawable {
 	}
 
 	function loadHMD( path : String, isAnimation : Bool ) {
+		checkCurrent();
 		var fullPath = ide.getPath(path);
 		var key = fullPath;
 		var hmd = hmdCache.get(key);

+ 9 - 1
hide/comp/SceneTree.hx

@@ -72,7 +72,7 @@ class SceneTree extends IconTree<String> {
 				var c = root.getChildAt(i);
 				{
 					data : path+i,
-					text : c.name == null ? c.toString()+"@"+i : c.name,
+					text : getObjectName(c),
 					icon : "fa fa-" + getIcon(c),
 					children : c.isMesh() || c.numChildren > 0,
 					state : { opened : c.numChildren > 0 && c.numChildren < 10 }
@@ -93,4 +93,12 @@ class SceneTree extends IconTree<String> {
 		return elements;
 	}
 
+	public function getObjectName( o : h3d.scene.Object ) {
+		if( o.name != null )
+			return o.name;
+		if( o.parent == null )
+			return o.toString();
+		return o.toString() + "@" + @:privateAccess o.parent.children.indexOf(o);
+	}
+
 }

+ 27 - 1
hide/ui/Ide.hx

@@ -238,7 +238,7 @@ class Ide {
 		shaderLoader = new hide.tools.ShaderLoader();
 
 		var localDir = sys.FileSystem.exists(resourceDir) ? resourceDir : projectDir;
-		hxd.res.Loader.currentInstance = new hxd.res.Loader(new hxd.fs.LocalFileSystem(localDir));
+		hxd.res.Loader.currentInstance = new CustomLoader(new hxd.fs.LocalFileSystem(localDir));
 		renderers = [
 			new h3d.mat.MaterialSetup("Default"),
 		];
@@ -523,3 +523,29 @@ class Ide {
 	}
 
 }
+
+
+class CustomLoader extends hxd.res.Loader {
+
+	var pathKeys = new Map<String,{}>();
+
+	function getKey( path : String ) {
+		var k = pathKeys.get(path);
+		if( k == null ) {
+			k = {};
+			pathKeys.set(path, k);
+		}
+		return k;
+	}
+
+	override function loadImage( path : String ) {
+		var engine = h3d.Engine.getCurrent();
+		var i : hxd.res.Image = @:privateAccess engine.resCache.get(getKey(path));
+		if( i == null ) {
+			i = new hxd.res.Image(fs.get(path));
+			@:privateAccess engine.resCache.set(getKey(path), i);
+		}
+		return i;
+	}
+
+}