Răsfoiți Sursa

added nme/glview support

Nicolas Cannasse 11 ani în urmă
părinte
comite
4d626bb249

+ 1 - 2
.gitignore

@@ -2,6 +2,5 @@
 *.swf
 *.js
 *.js.map
-/bin
-/samples/res/.tmp
+bin
 .tmp

+ 0 - 9
h3d/Engine.hx

@@ -36,15 +36,6 @@ class Engine {
 		this.hardware = hardware;
 		this.antiAlias = aa;
 		this.autoResize = true;
-
-		#if (!flash && openfl)
-			hxd.Stage.openFLBoot(start);
-		#else
-			start();
-		#end
-	}
-
-	function start() {
 		fullScreen = !hxd.System.isWindowed;
 		var stage = hxd.Stage.getInstance();
 		realFps = stage.getFrameRate();

+ 5 - 1
h3d/impl/GlDriver.hx

@@ -86,7 +86,6 @@ class GlDriver extends Driver {
 		programs = new Map();
 		curAttribs = 0;
 		curMatBits = -1;
-		selectMaterialBits(0);
 	}
 
 	override function logImpl( str : String ) {
@@ -99,6 +98,10 @@ class GlDriver extends Driver {
 
 	override function begin(frame) {
 		this.frame = frame;
+		#if cpp
+		curAttribs = 0;
+		curMatBits = -1;
+		#end
 		reset();
 	}
 
@@ -175,6 +178,7 @@ class GlDriver extends Driver {
 			programs.set(shader.id, p);
 		}
 		if( curShader == p ) return false;
+
 		gl.useProgram(p.p);
 		for( i in curAttribs...p.attribs.length ) {
 			gl.enableVertexAttribArray(i);

+ 5 - 3
hxd/App.hx

@@ -11,9 +11,11 @@ class App {
 			this.engine = engine;
 			haxe.Timer.delay(setup, 0);
 		} else {
-			this.engine = engine = new h3d.Engine();
-			engine.onReady = setup;
-			engine.init();
+			hxd.System.start(function() {
+				this.engine = engine = new h3d.Engine();
+				engine.onReady = setup;
+				engine.init();
+			});
 		}
 	}
 

+ 2 - 14
hxd/Stage.hx

@@ -29,7 +29,7 @@ class Stage {
 	function new() {
 		eventTargets = new List();
 		resizeEvents = new List();
-		#if (flash || openfl)
+		#if (flash || openfl || nme)
 		stage = flash.Lib.current.stage;
 		stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
 		stage.addEventListener(flash.events.Event.RESIZE, onResize);
@@ -241,7 +241,7 @@ class Stage {
 	}
 
 	function getCharCode( e : flash.events.KeyboardEvent ) {
-		#if openfl
+		#if cpp
 		return e.charCode;
 		#else
 		// disable some invalid charcodes
@@ -386,16 +386,4 @@ class Stage {
 
 #end
 
-#if openfl
-
-	static function openFLBoot(callb) {
-		// init done with OpenFL ApplicationMain
-		if( flash.Lib.current.stage != null ) {
-			callb();
-			return;
-		}
-	}
-
-#end
-
 }

+ 44 - 81
hxd/System.hx

@@ -62,8 +62,19 @@ class System {
 	}
 
 	static var loop = null;
+	#if nme
+	static var VIEW = null;
+	#end
 
 	public static function setLoop( f : Void -> Void ) {
+		#if nme
+		if( VIEW == null ) {
+			VIEW = new nme.display.OpenGLView();
+			VIEW.name = "glView";
+			flash.Lib.current.addChildAt(VIEW,0);
+		}
+		VIEW.render = function(_) if( f != null ) f();
+		#else
 		if( loop != null )
 			flash.Lib.current.removeEventListener(flash.events.Event.ENTER_FRAME, loop);
 		if( f == null )
@@ -72,6 +83,35 @@ class System {
 			loop = function(_) f();
 			flash.Lib.current.addEventListener(flash.events.Event.ENTER_FRAME, loop);
 		}
+		#end
+	}
+
+	public static function start(callb) {
+		#if nme
+		nme.Lib.create(function() {
+            nme.Lib.current.stage.align = nme.display.StageAlign.TOP_LEFT;
+            nme.Lib.current.stage.scaleMode = nme.display.StageScaleMode.NO_SCALE;
+            nme.Lib.current.loaderInfo = nme.display.LoaderInfo.create(null);
+            callb();
+         },
+         640, 480,
+         120, // using 60 FPS with no vsync gives a fps ~= 50
+         0xFFFFFF,
+         (true ? nme.Lib.HARDWARE : 0) |
+         nme.Lib.ALLOW_SHADERS | nme.Lib.REQUIRE_SHADERS |
+         (true ? nme.Lib.DEPTH_BUFFER : 0) |
+         (false ? nme.Lib.STENCIL_BUFFER : 0) |
+         (true ? nme.Lib.RESIZABLE : 0) |
+         (false ? nme.Lib.BORDERLESS : 0) |
+         (true ? nme.Lib.VSYNC : 0) |
+         (false ? nme.Lib.FULLSCREEN : 0) |
+         (0 == 4 ? nme.Lib.HW_AA_HIRES : 0) |
+         (0 == 2 ? nme.Lib.HW_AA : 0),
+         "Heaps Application"
+		);
+		#else
+		callb();
+		#end
 	}
 
 	#if flash
@@ -176,6 +216,10 @@ class System {
 		LOOP = f;
 	}
 
+	public static function start( callb ) {
+		callb();
+	}
+
 	public static var setCursor = setNativeCursor;
 
 	public static function setNativeCursor( c : Cursor ) {
@@ -220,87 +264,6 @@ class System {
 		return Math.round(js.Browser.document.body.clientHeight  * js.Browser.window.devicePixelRatio);
 	}
 
-	#elseif openfl
-
-	static var VIEW = null;
-
-	public static function setLoop( f : Void -> Void ) {
-		if( VIEW == null ) {
-			VIEW = new openfl.display.OpenGLView();
-			VIEW.name = "glView";
-			flash.Lib.current.addChildAt(VIEW,0);
-		}
-		VIEW.render = function(_) if( f != null ) f();
-	}
-
-	public static var setCursor = setNativeCursor;
-
-	public static function setNativeCursor( c : Cursor ) {
-		/* not supported by openFL
-		flash.ui.Mouse.cursor = switch( c ) {
-		case Default: "auto";
-		case Button: "button";
-		case Move: "hand";
-		case TextInput: "ibeam";
-		}*/
-	}
-
-	static function get_lang() {
-		return flash.system.Capabilities.language.split("-")[0];
-	}
-
-	static function get_screenDPI() {
-		return flash.system.Capabilities.screenDPI;
-	}
-
-	static function get_isAndroid() {
-		#if android
-		return true;
-		#else
-		return false;
-		#end
-	}
-
-	static var CACHED_NAME = null;
-	public static function getDeviceName() {
-		if( CACHED_NAME != null )
-			return CACHED_NAME;
-		var name;
-		if( isAndroid ) {
-			try {
-				var content = sys.io.File.getContent("/system/build.prop");
-				name = StringTools.trim(content.split("ro.product.model=")[1].split("\n")[0]);
-			} catch( e : Dynamic ) {
-				name = "Android";
-			}
-		} else
-			name = "PC";
-		CACHED_NAME = name;
-		return name;
-	}
-
-	public static function exit() {
-		Sys.exit(0);
-	}
-
-	static function get_isWindowed() {
-		return true;
-	}
-
-	static function get_isTouch() {
-		return false;
-	}
-
-	static function get_width() {
-		var Cap = flash.system.Capabilities;
-		return isWindowed ? flash.Lib.current.stage.stageWidth : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionX : Cap.screenResolutionY);
-	}
-
-	static function get_height() {
-		var Cap = flash.system.Capabilities;
-		return isWindowed ? flash.Lib.current.stage.stageHeight : Std.int(Cap.screenResolutionX > Cap.screenResolutionY ? Cap.screenResolutionY : Cap.screenResolutionX);
-	}
-
 	#end
 
 }

+ 8 - 0
samples/2d/2d_ogl.hxml

@@ -0,0 +1,8 @@
+-cpp bin
+-main Main
+-lib heaps
+-dce full
+-D resourcesPath=../res
+--macro include('h2d')
+-lib nme
+--remap flash:nme

+ 53 - 0
samples/2d/2d_ogl.hxproj

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project version="2">
+  <!-- Output SWF options -->
+  <output>
+    <movie outputType="Application" />
+    <movie input="" />
+    <movie path="bin" />
+    <movie fps="60" />
+    <movie width="800" />
+    <movie height="600" />
+    <movie version="1" />
+    <movie minorVersion="0" />
+    <movie platform="C++" />
+    <movie background="#FFFFFF" />
+  </output>
+  <!-- Other classes to be compiled into your SWF -->
+  <classpaths>
+    <!-- example: <class path="..." /> -->
+  </classpaths>
+  <!-- Build options -->
+  <build>
+    <option directives="" />
+    <option flashStrict="False" />
+    <option noInlineOnDebug="False" />
+    <option mainClass="Main" />
+    <option enabledebug="False" />
+    <option additional="-lib heaps&#xA;-dce full&#xA;-D resourcesPath=../res&#xA;--macro include('h2d')&#xA;-lib nme&#xA;--remap flash:nme" />
+  </build>
+  <!-- haxelib libraries -->
+  <haxelib>
+    <!-- example: <library name="..." /> -->
+  </haxelib>
+  <!-- Class files to compile (other referenced classes will automatically be included) -->
+  <compileTargets>
+    <!-- example: <compile path="..." /> -->
+  </compileTargets>
+  <!-- Paths to exclude from the Project Explorer tree -->
+  <hiddenPaths>
+    <hidden path="obj" />
+  </hiddenPaths>
+  <!-- Executed before build -->
+  <preBuildCommand />
+  <!-- Executed after build -->
+  <postBuildCommand alwaysRun="False" />
+  <!-- Other project options -->
+  <options>
+    <option showHiddenPaths="False" />
+    <option testMovie="OpenDocument" />
+    <option testMovieCommand="bin\Main-debug.exe" />
+  </options>
+  <!-- Plugin storage -->
+  <storage />
+</project>

+ 4 - 1
samples/2d/Main.hx

@@ -31,6 +31,7 @@ class Main extends hxd.App {
 			bmp.blendMode = Add;
 		}
 
+		#if !cpp
 		// load a true type font, can be not very high quality
 		var font = hxd.Res.trueTypeFont.build(64);
 
@@ -50,6 +51,8 @@ class Main extends hxd.App {
 		tf.x = 20;
 		tf.y = s2d.height - 80;
 
+		#end
+
 		// load a bitmap font Resource
 		var font = hxd.Res.customFont.toFont();
 
@@ -72,7 +75,7 @@ class Main extends hxd.App {
 		spr.y = Std.int(s2d.height / 2);
 
 		// move our text up/down accordingly
-		tf.y = s2d.height - 80;
+		if( tf != null ) tf.y = s2d.height - 80;
 	}
 
 	override function update(dt:Float) {

+ 8 - 0
samples/basic/basic_ogl.hxml

@@ -0,0 +1,8 @@
+-cpp bin
+-main Main
+-lib heaps
+-D resourcesPath=../res
+-dce full
+-lib nme
+--remap flash:nme
+--macro include('h3d')

+ 56 - 0
samples/basic/basic_ogl.hxproj

@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project version="2">
+  <!-- Output SWF options -->
+  <output>
+    <movie outputType="Application" />
+    <movie input="" />
+    <movie path="bin" />
+    <movie fps="60" />
+    <movie width="800" />
+    <movie height="600" />
+    <movie version="1" />
+    <movie minorVersion="0" />
+    <movie platform="C++" />
+    <movie background="#FFFFFF" />
+  </output>
+  <!-- Other classes to be compiled into your SWF -->
+  <classpaths>
+    <!-- example: <class path="..." /> -->
+  </classpaths>
+  <!-- Build options -->
+  <build>
+    <option directives="" />
+    <option flashStrict="False" />
+    <option noInlineOnDebug="False" />
+    <option mainClass="Main" />
+    <option enabledebug="False" />
+    <option additional="-lib heaps&#xA;-D resourcesPath=../res&#xA;-dce full&#xA;-lib nme&#xA;--remap flash:nme&#xA;--macro include('h3d')" />
+  </build>
+  <!-- haxelib libraries -->
+  <haxelib>
+    <!-- example: <library name="..." /> -->
+  </haxelib>
+  <!-- Class files to compile (other referenced classes will automatically be included) -->
+  <compileTargets>
+    <!-- example: <compile path="..." /> -->
+  </compileTargets>
+  <!-- Paths to exclude from the Project Explorer tree -->
+  <hiddenPaths>
+    <hidden path="engine.hxml" />
+    <hidden path="obj" />
+    <hidden path="main.js" />
+    <hidden path="main.js.map" />
+  </hiddenPaths>
+  <!-- Executed before build -->
+  <preBuildCommand />
+  <!-- Executed after build -->
+  <postBuildCommand alwaysRun="False" />
+  <!-- Other project options -->
+  <options>
+    <option showHiddenPaths="False" />
+    <option testMovie="OpenDocument" />
+    <option testMovieCommand="bin\Main-Debug.exe" />
+  </options>
+  <!-- Plugin storage -->
+  <storage />
+</project>