소스 검색

hxsdl -> hlsdl, started hldx support

Nicolas Cannasse 8 년 전
부모
커밋
9385d8d8d9
10개의 변경된 파일123개의 추가작업 그리고 64개의 파일을 삭제
  1. 3 1
      h3d/Engine.hx
  2. 38 0
      h3d/impl/DirectXDriver.hx
  3. 1 1
      h3d/impl/Driver.hx
  4. 10 10
      h3d/impl/GlDriver.hx
  5. 1 1
      h3d/mat/Texture.hx
  6. 2 0
      hxd/Cursor.hx
  7. 8 3
      hxd/Stage.hl.hx
  8. 52 19
      hxd/System.hl.hx
  9. 2 26
      hxd/snd/NativeChannel.hx
  10. 6 3
      samples/Base2D.hx

+ 3 - 1
h3d/Engine.hx

@@ -53,10 +53,12 @@ class Engine {
 		realFps = hxd.System.getDefaultFrameRate();
 		lastTime = haxe.Timer.stamp();
 		stage.addResizeEvent(onStageResize);
-		#if (js || cpp || hxsdl || psgl)
+		#if (js || cpp || hlsdl || psgl)
 		driver = new h3d.impl.GlDriver(antiAlias);
 		#elseif flash
 		driver = new h3d.impl.Stage3dDriver(antiAlias);
+		#elseif hldx
+		driver = new h3d.impl.DirectXDriver();
 		#else
 		#if sys Sys.println #else trace #end("No output driver available.");
 		driver = new h3d.impl.LogDriver(new h3d.impl.NullDriver());

+ 38 - 0
h3d/impl/DirectXDriver.hx

@@ -0,0 +1,38 @@
+package h3d.impl;
+
+import h3d.impl.Driver;
+import dx.Driver;
+
+class DirectXDriver extends h3d.impl.Driver {
+
+	var driver : DriverInstance;
+
+	public function new() {
+		driver = Driver.create(@:privateAccess dx.Window.windows[0]);
+		if( driver == null ) throw "Failed to initialize DirectX driver";
+	}
+
+	override function isDisposed() {
+		return false;
+	}
+
+	override function init( onCreate : Bool -> Void, forceSoftware = false ) {
+		haxe.Timer.delay(onCreate.bind(false), 1);
+	}
+
+	override function clear(?color:h3d.Vector, ?depth:Float, ?stencil:Int) {
+		if( color != null )
+			Driver.clearColor(color.r, color.g, color.b, color.a);
+	}
+
+	override function getDriverName(details:Bool) {
+		var desc = "DirectX" + Driver.getSupportedVersion();
+		if( details ) desc += " " + Driver.getDeviceName();
+		return desc;
+	}
+
+	override public function present() {
+		Driver.present();
+	}
+
+}

+ 1 - 1
h3d/impl/Driver.hx

@@ -24,7 +24,7 @@ typedef VertexBuffer = { b : lime.graphics.opengl.GLBuffer, stride : Int };
 typedef Texture = { t : lime.graphics.opengl.GLTexture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };
 typedef DepthBuffer = { r : lime.graphics.opengl.GLRenderbuffer };
 typedef Query = {};
-#elseif hxsdl
+#elseif hlsdl
 typedef IndexBuffer = sdl.GL.Buffer;
 typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };
 typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int };

+ 10 - 10
h3d/impl/GlDriver.hx

@@ -4,7 +4,7 @@ import h3d.mat.Pass;
 import h3d.mat.Stencil;
 import h3d.mat.Data;
 
-#if (js||cpp||hxsdl||psgl)
+#if (js||cpp||hlsdl||psgl)
 
 #if js
 import js.html.Uint16Array;
@@ -33,7 +33,7 @@ private typedef Framebuffer = nme.gl.Framebuffer;
 private typedef Uint16Array = nme.utils.Int16Array;
 private typedef Uint8Array = nme.utils.UInt8Array;
 private typedef Float32Array = nme.utils.Float32Array;
-#elseif hxsdl
+#elseif hlsdl
 import sdl.GL;
 private typedef Uniform = sdl.GL.Uniform;
 private typedef Program = sdl.GL.Program;
@@ -92,7 +92,7 @@ private class CompiledProgram {
 }
 
 @:access(h3d.impl.Shader)
-#if (cpp||hxsdl||psgl)
+#if (cpp||hlsdl||psgl)
 @:build(h3d.impl.MacroHelper.replaceGL())
 #end
 class GlDriver extends Driver {
@@ -103,7 +103,7 @@ class GlDriver extends Driver {
 	public var gl : js.html.webgl.RenderingContext;
 	#end
 
-	#if (hxsdl||psgl)
+	#if (hlsdl||psgl)
 	var commonVA : VertexArray;
 	#end
 
@@ -145,7 +145,7 @@ class GlDriver extends Driver {
 		curAttribs = 0;
 		curMatBits = -1;
 		defStencil = new Stencil();
-		#if hxsdl
+		#if hlsdl
 		var v : String = gl.getParameter(GL.VERSION);
 		if( v.indexOf("ES") < 0 ){
 			commonVA = gl.createVertexArray();
@@ -248,7 +248,7 @@ class GlDriver extends Driver {
 			p.vertex = compileShader(glout,shader.vertex);
 			p.fragment = compileShader(glout,shader.fragment);
 			p.p = gl.createProgram();
-			#if hxsdl
+			#if hlsdl
 			if( !glout.glES ) {
 				var outCount = 0;
 				for( v in shader.fragment.data.vars )
@@ -275,7 +275,7 @@ class GlDriver extends Driver {
 				#if js
 				gl.deleteProgram(p.p);
 				#end
-				#if hxsdl
+				#if hlsdl
 				/*
 					Tentative patch on some driver that report an higher shader version that it's allowed to use.
 				*/
@@ -747,7 +747,7 @@ class GlDriver extends Driver {
 	}
 
 	override function uploadTextureBitmap( t : h3d.mat.Texture, bmp : hxd.BitmapData, mipLevel : Int, side : Int ) {
-	#if (nme || hxsdl || psgl || openfl || lime)
+	#if (nme || hlsdl || psgl || openfl || lime)
 		var pixels = bmp.getPixels();
 		uploadTexturePixels(t, pixels, mipLevel, side);
 		pixels.dispose();
@@ -768,7 +768,7 @@ class GlDriver extends Driver {
 	#end
 	}
 
-	#if !(hxsdl || psgl)
+	#if !(hlsdl || psgl)
 	inline static function bytesToUint8Array( b : haxe.io.Bytes ) : Uint8Array {
 		#if (lime && !js)
 		return new Uint8Array(b);
@@ -1080,7 +1080,7 @@ class GlDriver extends Driver {
 
 	override function hasFeature( f : Feature ) : Bool {
 		return switch( f ) {
-		#if (hxsdl || psgl)
+		#if (hlsdl || psgl)
 		case StandardDerivatives, FloatTextures, MultipleRenderTargets, Queries:
 			true; // runtime extension detect required ?
 		#else

+ 1 - 1
h3d/mat/Texture.hx

@@ -19,7 +19,7 @@ class Texture {
 	/**
 		Tells if the Driver requires y-flipping the texture pixels before uploading.
 	**/
-	public static inline var nativeFlip = 	#if (hxsdl) true
+	public static inline var nativeFlip = 	#if (hlsdl) true
 											#elseif (openfl) false
 											#elseif (lime && (cpp || neko || nodejs)) true
 											#else false #end;

+ 2 - 0
hxd/Cursor.hx

@@ -18,6 +18,8 @@ class CustomCursor {
 	var offsetY : Int;
 	#if hlsdl
 	var alloc : sdl.Cursor;
+	#elseif hldx
+	var alloc : dx.Cursor;
 	#elseif flash
 	static var UID = 0;
 	var name : String;

+ 8 - 3
hxd/Stage.hl.hx

@@ -14,9 +14,12 @@ class Stage {
 	public var mouseLock(get, set) : Bool;
 	public var vsync(get, set) : Bool;
 
-	#if !psgl
+	#if hlsdl
 	var window : sdl.Window;
 	var fullScreenMode : sdl.Window.DisplayMode = Borderless;
+	#elseif hldx
+	var window : dx.Window;
+	var fullScreenMode : dx.Window.DisplayMode = Borderless;
 	#end
 	var windowWidth = 800;
 	var windowHeight = 600;
@@ -31,8 +34,10 @@ class Stage {
 		this.windowHeight = height;
 		eventTargets = new List();
 		resizeEvents = new List();
-		#if !psgl
+		#if hlsdl
 		window = new sdl.Window(title, width, height);
+		#elseif hldx
+		window = new dx.Window(title, width, height);
 		#end
 	}
 
@@ -111,7 +116,7 @@ class Stage {
 		return false;
 	}
 
-	#if psgl
+	#if (psgl || hldx)
 
 	function get_vsync() : Bool return true;
 

+ 52 - 19
hxd/System.hl.hx

@@ -1,5 +1,11 @@
 package hxd;
 
+#if hlsdl
+import sdl.Cursor;
+#elseif hldx
+import dx.Cursor;
+#end
+
 enum Platform {
 	IOS;
 	Android;
@@ -28,7 +34,7 @@ class System {
 	static var loopFunc : Void -> Void;
 
 	// -- HL
-	static var currentNativeCursor : Cursor = Default;
+	static var currentNativeCursor : hxd.Cursor = Default;
 	static var cursorVisible = true;
 
 	public static function getCurrentLoop() : Void -> Void {
@@ -54,8 +60,6 @@ class System {
 		@:privateAccess Stage.inst = new Stage("", psgl.Api.width, psgl.Api.height);
 		init();
 		#else
-		sdl.Sdl.tick();
-		sdl.Sdl.init();
 		var width = 800;
 		var height = 600;
 		var size = haxe.macro.Compiler.getDefine("windowSize");
@@ -67,34 +71,42 @@ class System {
 			width = Std.parseInt(p[0]);
 			height = Std.parseInt(p[1]);
 		}
-		@:privateAccess Stage.initChars();
-		@:privateAccess Stage.inst = new Stage(title, width, height);
-		init();
-		sdl.Sdl.defaultEventHandler = @:privateAccess Stage.inst.onEvent;
+		#if hlsdl
+			sdl.Sdl.tick();
+			sdl.Sdl.init();
+			@:privateAccess Stage.initChars();
+			@:privateAccess Stage.inst = new Stage(title, width, height);
+			init();
+			sdl.Sdl.defaultEventHandler = @:privateAccess Stage.inst.onEvent;
+		#elseif hldx
+			@:privateAccess Stage.inst = new Stage(title, width, height);
+			init();
+		#end
+
 		#end
 		haxe.MainLoop.add(mainLoop);
 	}
 
-	public static function setNativeCursor( c : Cursor ) : Void {
+	public static function setNativeCursor( c : hxd.Cursor ) : Void {
 		#if !psgl
 		if( c.equals(currentNativeCursor) )
 			return;
 		currentNativeCursor = c;
 		if( c == Hide ) {
 			cursorVisible = false;
-			sdl.Cursor.show(false);
+			Cursor.show(false);
 			return;
 		}
-		var cur : sdl.Cursor;
+		var cur : Cursor;
 		switch( c ) {
 		case Default:
-			cur = sdl.Cursor.createSystem(Arrow);
+			cur = Cursor.createSystem(Arrow);
 		case Button:
-			cur = sdl.Cursor.createSystem(Hand);
+			cur = Cursor.createSystem(Hand);
 		case Move:
 			throw "Cursor not supported";
 		case TextInput:
-			cur = sdl.Cursor.createSystem(IBeam);
+			cur = Cursor.createSystem(IBeam);
 		case Hide:
 			throw "assert";
 		case Custom(c):
@@ -102,9 +114,13 @@ class System {
 				if( c.frames.length > 1 ) throw "Animated cursor not supported";
 				var pixels = c.frames[0].getPixels();
 				pixels.convert(BGRA);
+				#if hlsdl
 				var surf = sdl.Surface.fromBGRA(pixels.bytes, pixels.width, pixels.height);
 				c.alloc = sdl.Cursor.create(surf, c.offsetX, c.offsetY);
 				surf.free();
+				#elseif hldx
+				throw "TODO";
+				#end
 				pixels.dispose();
 			}
 			cur = c.alloc;
@@ -112,7 +128,7 @@ class System {
 		cur.set();
 		if( !cursorVisible ) {
 			cursorVisible = true;
-			sdl.Cursor.show(true);
+			Cursor.show(true);
 		}
 		#end
 	}
@@ -120,8 +136,10 @@ class System {
 	public static function getDeviceName() : String {
 		#if psgl
 		return psgl.Api.name;
-		#else
+		#elseif hlsdl
 		return "PC/" + sdl.Sdl.getDevices()[0];
+		#elseif hldx
+		return "PC/" + dx.Driver.getDeviceName();
 		#end
 	}
 
@@ -162,9 +180,24 @@ class System {
 
 	// getters
 
-	static function get_width() : Int return #if psgl psgl.Api.width #else sdl.Sdl.getScreenWidth() #end;
-	static function get_height() : Int return #if psgl psgl.Api.height #else sdl.Sdl.getScreenHeight() #end;
-	static function get_platform() : Platform return #if psgl Console #else PC #end;
-	static function get_screenDPI() : Int return 72; // TODO : SDL ?
+	#if psgl
+	static function get_width() : Int return psgl.Api.width;
+	static function get_height() : Int return psgl.Api.height;
+	static function get_platform() : Platform return Console;
+	#elseif hldx
+	static function get_width() : Int return dx.Driver.getScreenWidth();
+	static function get_height() : Int return dx.Driver.getScreenHeight();
+	static function get_platform() : Platform return PC; // TODO : Xbox ?
+	#elseif hlsdl
+	static function get_width() : Int return sdl.Sdl.getScreenWidth();
+	static function get_height() : Int return sdl.Sdl.getScreenHeight();
+	static function get_platform() : Platform return PC; // TODO : Xbox ?
+	#else
+	static function get_width() : Int return 800;
+	static function get_height() : Int return 600;
+	static function get_platform() : Platform return PC;
+	#end
+
+	static function get_screenDPI() : Int return 72; // TODO
 
 }

+ 2 - 26
hxd/snd/NativeChannel.hx

@@ -1,21 +1,6 @@
 package hxd.snd;
 
-#if hxsdl
-private class ChannelMapper extends sdl.SoundChannel {
-	var native : NativeChannel;
-	public function new(samples, native) {
-		super(samples);
-		this.native = native;
-	}
-	#if cpp
-	override function onSample( buf : cpp.Pointer<cpp.Float32>, len : Int ) {
-		var data : haxe.io.BytesData = [];
-		cpp.NativeArray.setUnmanagedData(data, buf.reinterpret(), len<<2);
-		@:privateAccess native.onSample(haxe.io.Float32Array.fromBytes(haxe.io.Bytes.ofData(data)));
-	}
-	#end
-}
-#elseif lime_openal
+#if lime_openal
 import lime.media.openal.AL;
 import lime.media.openal.ALBuffer;
 import lime.media.openal.ALSource;
@@ -51,7 +36,7 @@ private class ALChannel {
 	public function stop() {
 		if ( src != null ){
 			lime.app.Application.current.onUpdate.remove( onUpdate );
-			
+
 			AL.sourceStop(src);
 			AL.deleteSource(src);
 			AL.deleteBuffers(buffers);
@@ -118,8 +103,6 @@ class NativeChannel {
 	}
 	var sproc : js.html.audio.ScriptProcessorNode;
 	var tmpBuffer : haxe.io.Float32Array;
-	#elseif hxsdl
-	var channel : ChannelMapper;
 	#elseif lime_openal
 	var channel : ALChannel;
 	#end
@@ -138,8 +121,6 @@ class NativeChannel {
 		tmpBuffer = new haxe.io.Float32Array(bufferSamples * 2);
 		sproc.connect(ctx.destination);
 		sproc.onaudioprocess = onJsSample;
-		#elseif hxsdl
-		channel = new ChannelMapper(bufferSamples, this);
 		#elseif lime_openal
 		channel = new ALChannel(bufferSamples, this);
 		#end
@@ -183,11 +164,6 @@ class NativeChannel {
 			sproc.disconnect();
 			sproc = null;
 		}
-		#elseif hxsdl
-		if( channel != null ) {
-			channel.stop();
-			channel = null;
-		}
 		#elseif lime_openal
 		if( channel != null ) {
 			channel.stop();

+ 6 - 3
samples/Base2D.hx

@@ -4,7 +4,7 @@ class Base2D extends hxd.App {
 	var tf : h2d.Text;
 
 	override function init() {
-
+/*
 		// creates a new sprite and put it at the center of the sceen
 		spr = new h2d.Sprite(s2d);
 		spr.x = Std.int(s2d.width / 2);
@@ -64,12 +64,14 @@ class Base2D extends hxd.App {
 
 		tf.y = 20;
 		tf.x = 20;
-		tf.scale(7);
+		tf.scale(7);*/
 	}
 
 	// if we the window has been resized
 	override function onResize() {
 
+		if( spr == null ) return;
+
 		// center our sprite
 		spr.x = Std.int(s2d.width / 2);
 		spr.y = Std.int(s2d.height / 2);
@@ -80,10 +82,11 @@ class Base2D extends hxd.App {
 
 	override function update(dt:Float) {
 		// rotate our sprite every frame
-		spr.rotation += 0.01 * dt;
+		if( spr != null ) spr.rotation += 0.01 * dt;
 	}
 
 	static function main() {
+		trace(hxd.System.width + "x" + hxd.System.height + " " + hxd.System.getDeviceName());
 		hxd.Res.initEmbed();
 		new Base2D();
 	}