瀏覽代碼

initial hxsdl support

Nicolas Cannasse 10 年之前
父節點
當前提交
daa8567c1f

+ 2 - 0
doc/ref.html

@@ -348,6 +348,8 @@ class Main extends hxd.App {
 
 
 <h1>Using HMD Models</h1>
 <h1>Using HMD Models</h1>
 
 
+<h1>Animation system</h1>
+
 <h1>Mesh Material</h1>
 <h1>Mesh Material</h1>
 
 
 <h1>Lights</h1>
 <h1>Lights</h1>

+ 4 - 0
h3d/impl/Driver.hx

@@ -12,6 +12,10 @@ typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, fmt :
 typedef IndexBuffer = nme.gl.GLBuffer;
 typedef IndexBuffer = nme.gl.GLBuffer;
 typedef VertexBuffer = { b : nme.gl.GLBuffer, stride : Int };
 typedef VertexBuffer = { b : nme.gl.GLBuffer, stride : Int };
 typedef Texture = { t : nme.gl.GLTexture, width : Int, height : Int, fmt : Int, ?fb : nme.gl.GLFramebuffer, ?rb : nme.gl.GLRenderbuffer };
 typedef Texture = { t : nme.gl.GLTexture, width : Int, height : Int, fmt : Int, ?fb : nme.gl.GLFramebuffer, ?rb : nme.gl.GLRenderbuffer };
+#elseif hxsdl
+typedef IndexBuffer = sdl.GL.Buffer;
+typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };
+typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, fmt : Int, ?fb : sdl.GL.Framebuffer, ?rb : sdl.GL.Renderbuffer };
 #else
 #else
 typedef IndexBuffer = Int;
 typedef IndexBuffer = Int;
 typedef VertexBuffer = Int;
 typedef VertexBuffer = Int;

+ 58 - 15
h3d/impl/GlDriver.hx

@@ -20,6 +20,12 @@ private typedef GLShader = nme.gl.GLShader;
 private typedef Uint16Array = nme.utils.Int16Array;
 private typedef Uint16Array = nme.utils.Int16Array;
 private typedef Uint8Array = nme.utils.UInt8Array;
 private typedef Uint8Array = nme.utils.UInt8Array;
 private typedef Float32Array = nme.utils.Float32Array;
 private typedef Float32Array = nme.utils.Float32Array;
+#elseif hxsdl
+import sdl.GL;
+private typedef Uniform = sdl.GL.Uniform;
+private typedef Program = sdl.GL.Program;
+private typedef GLShader = sdl.GL.Shader;
+private typedef Texture = h3d.impl.Driver.Texture;
 #end
 #end
 
 
 private class CompiledShader {
 private class CompiledShader {
@@ -48,13 +54,15 @@ private class CompiledProgram {
 }
 }
 
 
 @:access(h3d.impl.Shader)
 @:access(h3d.impl.Shader)
+#if cpp
+@:build(h3d.impl.MacroHelper.replaceGL())
+#end
 class GlDriver extends Driver {
 class GlDriver extends Driver {
 
 
 	#if js
 	#if js
 	var canvas : js.html.CanvasElement;
 	var canvas : js.html.CanvasElement;
 	public var gl : js.html.webgl.RenderingContext;
 	public var gl : js.html.webgl.RenderingContext;
 	#elseif cpp
 	#elseif cpp
-	static var gl = GL;
 	var fixMult : Bool;
 	var fixMult : Bool;
 	#end
 	#end
 
 
@@ -76,7 +84,7 @@ class GlDriver extends Driver {
 		if( gl == null ) throw "Could not acquire GL context";
 		if( gl == null ) throw "Could not acquire GL context";
 		// debug if webgl_debug.js is included
 		// debug if webgl_debug.js is included
 		untyped if( __js__('typeof')(WebGLDebugUtils) != "undefined" ) gl = untyped WebGLDebugUtils.makeDebugContext(gl);
 		untyped if( __js__('typeof')(WebGLDebugUtils) != "undefined" ) gl = untyped WebGLDebugUtils.makeDebugContext(gl);
-		#elseif cpp
+		#elseif (nme || openfl)
 		// check for a bug in HxCPP handling of sub buffers
 		// check for a bug in HxCPP handling of sub buffers
 		var tmp = new Float32Array(8);
 		var tmp = new Float32Array(8);
 		var sub = new Float32Array(tmp.buffer, 0, 4);
 		var sub = new Float32Array(tmp.buffer, 0, 4);
@@ -85,7 +93,9 @@ class GlDriver extends Driver {
 		programs = new Map();
 		programs = new Map();
 		curAttribs = 0;
 		curAttribs = 0;
 		curMatBits = -1;
 		curMatBits = -1;
+		#if js
 		gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);
 		gl.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);
+		#end
 	}
 	}
 
 
 	override function logImpl( str : String ) {
 	override function logImpl( str : String ) {
@@ -201,21 +211,21 @@ class GlDriver extends Driver {
 		switch( which ) {
 		switch( which ) {
 		case Globals:
 		case Globals:
 			if( s.globals != null ) {
 			if( s.globals != null ) {
-				#if js
-				var a = new Float32Array(buf.globals.toData()).subarray(0, s.shader.globalsSize * 4);
+				#if hxsdl
+				gl.uniform4fv(s.globals, buf.globals.toData(), 0, s.shader.globalsSize);
 				#else
 				#else
-				var a = new Float32Array(buf.globals.toData(), 0, s.shader.globalsSize * 4);
-				#end
+				var a = new Float32Array(buf.globals.toData()).subarray(0, s.shader.globalsSize * 4);
 				gl.uniform4fv(s.globals, a);
 				gl.uniform4fv(s.globals, a);
+				#end
 			}
 			}
 		case Params:
 		case Params:
 			if( s.params != null ) {
 			if( s.params != null ) {
-				#if js
-				var a = new Float32Array(buf.params.toData()).subarray(0, s.shader.paramsSize * 4);
+				#if hxsdl
+				gl.uniform4fv(s.params, buf.params.toData(), 0, s.shader.paramsSize);
 				#else
 				#else
-				var a = new Float32Array(buf.params.toData(), 0, s.shader.paramsSize * 4);
-				#end
+				var a = new Float32Array(buf.params.toData()).subarray(0, s.shader.paramsSize * 4);
 				gl.uniform4fv(s.params, a);
 				gl.uniform4fv(s.params, a);
+				#end
 			}
 			}
 		case Textures:
 		case Textures:
 			for( i in 0...s.textures.length ) {
 			for( i in 0...s.textures.length ) {
@@ -282,7 +292,7 @@ class GlDriver extends Driver {
 			var cop = Pass.getBlendOp(bits);
 			var cop = Pass.getBlendOp(bits);
 			var aop = Pass.getBlendAlphaOp(bits);
 			var aop = Pass.getBlendAlphaOp(bits);
 			if( cop == aop ) {
 			if( cop == aop ) {
-				#if cpp
+				#if (nme || openfl)
 				if( OP[cop] != GL.FUNC_ADD )
 				if( OP[cop] != GL.FUNC_ADD )
 					throw "blendEquation() disable atm (crash)";
 					throw "blendEquation() disable atm (crash)";
 				#else
 				#else
@@ -387,6 +397,8 @@ class GlDriver extends Driver {
 		if( m.size * m.stride == 0 ) throw "assert";
 		if( m.size * m.stride == 0 ) throw "assert";
 		#if js
 		#if js
 		gl.bufferData(GL.ARRAY_BUFFER, m.size * m.stride * 4, m.flags.has(Dynamic) ? GL.DYNAMIC_DRAW : GL.STATIC_DRAW);
 		gl.bufferData(GL.ARRAY_BUFFER, m.size * m.stride * 4, m.flags.has(Dynamic) ? GL.DYNAMIC_DRAW : GL.STATIC_DRAW);
+		#elseif hxsdl
+		gl.bufferDataSize(GL.ARRAY_BUFFER, m.size * m.stride * 4, m.flags.has(Dynamic) ? GL.DYNAMIC_DRAW : GL.STATIC_DRAW);
 		#else
 		#else
 		var tmp = new Uint8Array(m.size * m.stride * 4);
 		var tmp = new Uint8Array(m.size * m.stride * 4);
 		gl.bufferData(GL.ARRAY_BUFFER, tmp, m.flags.has(Dynamic) ? GL.DYNAMIC_DRAW : GL.STATIC_DRAW);
 		gl.bufferData(GL.ARRAY_BUFFER, tmp, m.flags.has(Dynamic) ? GL.DYNAMIC_DRAW : GL.STATIC_DRAW);
@@ -400,6 +412,8 @@ class GlDriver extends Driver {
 		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, b);
 		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, b);
 		#if js
 		#if js
 		gl.bufferData(GL.ELEMENT_ARRAY_BUFFER, count * 2, GL.STATIC_DRAW);
 		gl.bufferData(GL.ELEMENT_ARRAY_BUFFER, count * 2, GL.STATIC_DRAW);
+		#elseif hxsdl
+		gl.bufferDataSize(GL.ELEMENT_ARRAY_BUFFER, count * 2, GL.STATIC_DRAW);
 		#else
 		#else
 		var tmp = new Uint16Array(count);
 		var tmp = new Uint16Array(count);
 		gl.bufferData(GL.ELEMENT_ARRAY_BUFFER, tmp, GL.STATIC_DRAW);
 		gl.bufferData(GL.ELEMENT_ARRAY_BUFFER, tmp, GL.STATIC_DRAW);
@@ -430,7 +444,11 @@ class GlDriver extends Driver {
 		#else
 		#else
 		var img = bmp.toNative();
 		var img = bmp.toNative();
 		gl.bindTexture(GL.TEXTURE_2D, t.t.t);
 		gl.bindTexture(GL.TEXTURE_2D, t.t.t);
+		#if hxsdl
+		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, bmp.width, bmp.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, img.pixels.toData());
+		#else
 		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, img.getImageData(0, 0, bmp.width, bmp.height));
 		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, img.getImageData(0, 0, bmp.width, bmp.height));
+		#end
 		if( t.flags.has(MipMapped) ) gl.generateMipmap(GL.TEXTURE_2D);
 		if( t.flags.has(MipMapped) ) gl.generateMipmap(GL.TEXTURE_2D);
 		gl.bindTexture(GL.TEXTURE_2D, null);
 		gl.bindTexture(GL.TEXTURE_2D, null);
 		#end
 		#end
@@ -439,43 +457,63 @@ class GlDriver extends Driver {
 	override function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
 	override function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
 		gl.bindTexture(GL.TEXTURE_2D, t.t.t);
 		gl.bindTexture(GL.TEXTURE_2D, t.t.t);
 		pixels.convert(RGBA);
 		pixels.convert(RGBA);
+		#if hxsdl
+		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, t.width, t.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, pixels.bytes.getData());
+		#else
 		var pixels = new Uint8Array(pixels.bytes.getData());
 		var pixels = new Uint8Array(pixels.bytes.getData());
 		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, t.width, t.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, pixels);
 		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, t.width, t.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, pixels);
+		#end
 		if( t.flags.has(MipMapped) ) gl.generateMipmap(GL.TEXTURE_2D);
 		if( t.flags.has(MipMapped) ) gl.generateMipmap(GL.TEXTURE_2D);
 		gl.bindTexture(GL.TEXTURE_2D, null);
 		gl.bindTexture(GL.TEXTURE_2D, null);
 	}
 	}
 
 
 	override function uploadVertexBuffer( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
 	override function uploadVertexBuffer( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : hxd.FloatBuffer, bufPos : Int ) {
 		var stride : Int = v.stride;
 		var stride : Int = v.stride;
+		gl.bindBuffer(GL.ARRAY_BUFFER, v.b);
+		#if hxsdl
+		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, buf.getNative(), bufPos, vertexCount * stride * 4);
+		#else
 		var buf = new Float32Array(buf.getNative());
 		var buf = new Float32Array(buf.getNative());
 		var sub = new Float32Array(buf.buffer, bufPos, vertexCount * stride #if cpp * (fixMult?4:1) #end);
 		var sub = new Float32Array(buf.buffer, bufPos, vertexCount * stride #if cpp * (fixMult?4:1) #end);
-		gl.bindBuffer(GL.ARRAY_BUFFER, v.b);
 		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, sub);
 		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, sub);
+		#end
 		gl.bindBuffer(GL.ARRAY_BUFFER, null);
 		gl.bindBuffer(GL.ARRAY_BUFFER, null);
 	}
 	}
 
 
 	override function uploadVertexBytes( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
 	override function uploadVertexBytes( v : VertexBuffer, startVertex : Int, vertexCount : Int, buf : haxe.io.Bytes, bufPos : Int ) {
 		var stride : Int = v.stride;
 		var stride : Int = v.stride;
+		gl.bindBuffer(GL.ARRAY_BUFFER, v.b);
+		#if hxsdl
+		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, buf.getData(), bufPos, vertexCount * stride * 4);
+		#else
 		var buf = new Uint8Array(buf.getData());
 		var buf = new Uint8Array(buf.getData());
 		var sub = new Uint8Array(buf.buffer, bufPos, vertexCount * stride * 4);
 		var sub = new Uint8Array(buf.buffer, bufPos, vertexCount * stride * 4);
-		gl.bindBuffer(GL.ARRAY_BUFFER, v.b);
 		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, sub);
 		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, sub);
+		#end
 		gl.bindBuffer(GL.ARRAY_BUFFER, null);
 		gl.bindBuffer(GL.ARRAY_BUFFER, null);
 	}
 	}
 
 
 	override function uploadIndexBuffer( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : hxd.IndexBuffer, bufPos : Int ) {
 	override function uploadIndexBuffer( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : hxd.IndexBuffer, bufPos : Int ) {
+		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, i);
+		#if hxsdl
+		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, buf.getNative(), bufPos, indiceCount * 2);
+		#else
 		var buf = new Uint16Array(buf.getNative());
 		var buf = new Uint16Array(buf.getNative());
 		var sub = new Uint16Array(buf.buffer, bufPos, indiceCount #if cpp * (fixMult?2:1) #end);
 		var sub = new Uint16Array(buf.buffer, bufPos, indiceCount #if cpp * (fixMult?2:1) #end);
-		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, i);
 		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, sub);
 		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, sub);
+		#end
 		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
 		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
 	}
 	}
 
 
 	override function uploadIndexBytes( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : haxe.io.Bytes , bufPos : Int ) {
 	override function uploadIndexBytes( i : IndexBuffer, startIndice : Int, indiceCount : Int, buf : haxe.io.Bytes , bufPos : Int ) {
+		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, i);
+		#if hxsdl
+		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, buf.getData(), bufPos, indiceCount * 2);
+		#else
 		var buf = new Uint8Array(buf.getData());
 		var buf = new Uint8Array(buf.getData());
 		var sub = new Uint8Array(buf.buffer, bufPos, indiceCount * 2);
 		var sub = new Uint8Array(buf.buffer, bufPos, indiceCount * 2);
-		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, i);
 		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, sub);
 		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, sub);
+		#end
 		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
 		gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
 	}
 	}
 
 
@@ -589,10 +627,15 @@ class GlDriver extends Driver {
 
 
 	override function hasFeature( f : Feature ) : Bool {
 	override function hasFeature( f : Feature ) : Bool {
 		return switch( f ) {
 		return switch( f ) {
+		#if hxsdl
+		case StandardDerivatives, FloatTextures:
+			true; // runtime extension detect required ?
+		#else
 		case StandardDerivatives:
 		case StandardDerivatives:
 			gl.getExtension('OES_standard_derivatives') != null;
 			gl.getExtension('OES_standard_derivatives') != null;
 		case FloatTextures:
 		case FloatTextures:
 			gl.getExtension('OES_texture_float') != null && gl.getExtension('OES_texture_float_linear') != null;
 			gl.getExtension('OES_texture_float') != null && gl.getExtension('OES_texture_float_linear') != null;
+		#end
 		case PerTargetDepthBuffer:
 		case PerTargetDepthBuffer:
 			true;
 			true;
 		case TargetUseDefaultDepthBuffer:
 		case TargetUseDefaultDepthBuffer:

+ 31 - 0
h3d/impl/MacroHelper.hx

@@ -0,0 +1,31 @@
+package h3d.impl;
+import haxe.macro.Context;
+import haxe.macro.Expr;
+
+class MacroHelper {
+
+#if macro
+
+	static function replaceGLLoop( e : Expr ) {
+		switch( e.expr ) {
+		case EConst(CIdent("gl")):
+			e.expr = EConst(CIdent("GL"));
+		default:
+			haxe.macro.ExprTools.iter(e, replaceGLLoop);
+		}
+	}
+
+	public static function replaceGL() {
+		var fields = Context.getBuildFields();
+		for( f in fields )
+			switch( f.kind ) {
+			case FFun(f):
+				if( f.expr != null ) replaceGLLoop(f.expr);
+			default:
+			}
+		return fields;
+	}
+
+#end
+
+}

+ 2 - 2
h3d/shader/Buffers.hx

@@ -8,8 +8,8 @@ package h3d.shader;
 
 
 class ShaderBuffers {
 class ShaderBuffers {
 
 
-	public var globals : haxe.ds.Vector<Float>;
-	public var params : haxe.ds.Vector<Float>;
+	public var globals : haxe.ds.Vector<hxd.impl.Float32>;
+	public var params : haxe.ds.Vector<hxd.impl.Float32>;
 	public var tex : haxe.ds.Vector<h3d.mat.Texture>;
 	public var tex : haxe.ds.Vector<h3d.mat.Texture>;
 
 
 	public function new( s : hxsl.RuntimeShader.RuntimeShaderData ) {
 	public function new( s : hxsl.RuntimeShader.RuntimeShaderData ) {

+ 1 - 1
h3d/shader/Manager.hx

@@ -16,7 +16,7 @@ class Manager {
 	}
 	}
 
 
 	@:noDebug
 	@:noDebug
-	function fillRec( v : Dynamic, type : hxsl.Ast.Type, out : haxe.ds.Vector<Float>, pos : Int ) {
+	function fillRec( v : Dynamic, type : hxsl.Ast.Type, out : haxe.ds.Vector<hxd.impl.Float32>, pos : Int ) {
 		switch( type ) {
 		switch( type ) {
 		case TFloat:
 		case TFloat:
 			out[pos] = v;
 			out[pos] = v;

+ 16 - 4
hxd/BitmapData.hx

@@ -6,7 +6,15 @@ typedef BitmapInnerData =
 #elseif js
 #elseif js
 	js.html.CanvasRenderingContext2D;
 	js.html.CanvasRenderingContext2D;
 #else
 #else
-	Int;
+	BitmapInnerDataImpl;
+
+class BitmapInnerDataImpl {
+	public var pixels : haxe.ds.Vector<Int>;
+	public var width : Int;
+	public var height : Int;
+	public function new() {
+	}
+}
 #end
 #end
 
 
 class BitmapData {
 class BitmapData {
@@ -23,6 +31,8 @@ class BitmapData {
 	var ctx : js.html.CanvasRenderingContext2D;
 	var ctx : js.html.CanvasRenderingContext2D;
 	var lockImage : js.html.ImageData;
 	var lockImage : js.html.ImageData;
 	var pixel : js.html.ImageData;
 	var pixel : js.html.ImageData;
+#else
+	var data : BitmapInnerData;
 #end
 #end
 
 
 	public var width(get, never) : Int;
 	public var width(get, never) : Int;
@@ -40,7 +50,10 @@ class BitmapData {
 			canvas.height = height;
 			canvas.height = height;
 			ctx = canvas.getContext2d();
 			ctx = canvas.getContext2d();
 			#else
 			#else
-			notImplemented();
+			data = new BitmapInnerData();
+			data.pixels = new haxe.ds.Vector(width * height);
+			data.width = width;
+			data.height = height;
 			#end
 			#end
 		}
 		}
 	}
 	}
@@ -374,8 +387,7 @@ class BitmapData {
 		#elseif js
 		#elseif js
 		return ctx;
 		return ctx;
 		#else
 		#else
-		notImplemented();
-		return 0;
+		return data;
 		#end
 		#end
 	}
 	}
 
 

+ 1 - 1
hxd/FloatBuffer.hx

@@ -1,6 +1,6 @@
 package hxd;
 package hxd;
 
 
-private typedef InnerData = #if flash flash.Vector<Float> #else Array<Float> #end
+private typedef InnerData = #if flash flash.Vector<Float> #else Array<hxd.impl.Float32> #end
 
 
 private class InnerIterator {
 private class InnerIterator {
 	var b : InnerData;
 	var b : InnerData;

+ 1 - 1
hxd/IndexBuffer.hx

@@ -1,6 +1,6 @@
 package hxd;
 package hxd;
 
 
-private typedef InnerData = #if flash flash.Vector<UInt> #else Array<Int> #end
+private typedef InnerData = #if flash flash.Vector<UInt> #else Array<hxd.impl.UInt16> #end
 
 
 private class InnerIterator {
 private class InnerIterator {
 	var b : InnerData;
 	var b : InnerData;

+ 38 - 2
hxd/Stage.hx

@@ -67,7 +67,7 @@ class Stage {
 	}
 	}
 
 
 	#if flash
 	#if flash
-	
+
 	function initGesture(b) {
 	function initGesture(b) {
 		if( hxd.System.isTouch ) {
 		if( hxd.System.isTouch ) {
 			if( b )  {
 			if( b )  {
@@ -98,7 +98,7 @@ class Stage {
 			stage.addEventListener(flash.events.MouseEvent.RIGHT_MOUSE_UP, onRMouseUp);
 			stage.addEventListener(flash.events.MouseEvent.RIGHT_MOUSE_UP, onRMouseUp);
 		}
 		}
 	}
 	}
-	
+
 	function setupOnCloseEvent() {
 	function setupOnCloseEvent() {
 		var nw : flash.events.EventDispatcher = Reflect.field(stage, "nativeWindow");
 		var nw : flash.events.EventDispatcher = Reflect.field(stage, "nativeWindow");
 		if( nw == null ) return;
 		if( nw == null ) return;
@@ -391,6 +391,33 @@ class Stage {
 			r();
 			r();
 	}
 	}
 
 
+#elseif hxsdl
+
+	function get_mouseX() {
+		return 0;
+	}
+
+	function get_mouseY() {
+		return 0;
+	}
+
+	function get_width() {
+		return @:privateAccess System.windowWidth;
+	}
+
+	function get_height() {
+		return @:privateAccess System.windowHeight;
+	}
+
+	function get_mouseLock() {
+		return false;
+	}
+
+	function set_mouseLock(b) {
+		if( b ) throw "Not implemented";
+		return b;
+	}
+
 #else
 #else
 
 
 	function get_mouseX() {
 	function get_mouseX() {
@@ -409,6 +436,15 @@ class Stage {
 		return 0;
 		return 0;
 	}
 	}
 
 
+	function get_mouseLock() {
+		return false;
+	}
+
+	function set_mouseLock(b) {
+		if( b ) throw "Not implemented";
+		return b;
+	}
+
 #end
 #end
 
 
 }
 }

+ 64 - 4
hxd/System.hx

@@ -21,6 +21,8 @@ class System {
 
 
 	public static var screenDPI(get,never) : Float;
 	public static var screenDPI(get,never) : Float;
 
 
+	public static var setCursor = setNativeCursor;
+
 	#if (flash || nme || openfl)
 	#if (flash || nme || openfl)
 
 
 	static function get_isWindowed() {
 	static function get_isWindowed() {
@@ -152,8 +154,6 @@ class System {
 			flash.system.System.exit(0);
 			flash.system.System.exit(0);
 	}
 	}
 
 
-	public static var setCursor = setNativeCursor;
-
 	public static function setNativeCursor( c : Cursor ) {
 	public static function setNativeCursor( c : Cursor ) {
 		#if cpp
 		#if cpp
 		// TODO
 		// TODO
@@ -254,8 +254,6 @@ class System {
 		callb();
 		callb();
 	}
 	}
 
 
-	public static var setCursor = setNativeCursor;
-
 	public static function setNativeCursor( c : Cursor ) {
 	public static function setNativeCursor( c : Cursor ) {
 		var canvas = js.Browser.document.getElementById("webgl");
 		var canvas = js.Browser.document.getElementById("webgl");
 		if( canvas != null ) {
 		if( canvas != null ) {
@@ -302,6 +300,68 @@ class System {
 		return Math.round(js.Browser.document.body.clientHeight  * js.Browser.window.devicePixelRatio);
 		return Math.round(js.Browser.document.body.clientHeight  * js.Browser.window.devicePixelRatio);
 	}
 	}
 
 
+	#elseif hxsdl
+
+	public static function setNativeCursor( c : Cursor ) {
+		trace("TODO " + c);
+	}
+
+	static function get_screenDPI() {
+		return 72; // not implemented in SDL ???
+	}
+
+	static function get_isIOS() {
+		return false;
+	}
+
+	static function get_isAndroid() {
+		return false;
+	}
+
+	static function get_isWindowed() {
+		return true;
+	}
+
+	static function get_isTouch() {
+		return false;
+	}
+
+	static function get_lang() {
+		return "en";
+	}
+
+	static function get_width() {
+		return sdl.Sdl.getScreenWidth();
+	}
+
+	static function get_height() {
+		return sdl.Sdl.getScreenHeight();
+	}
+
+	static var win : sdl.Window;
+	static var windowWidth = 800;
+	static var windowHeight = 600;
+	static var currentLoop = null;
+
+	public static function setLoop( f : Void -> Void ) {
+		currentLoop = f;
+	}
+
+	static function mainLoop() {
+		if( currentLoop != null ) currentLoop();
+		win.present();
+	}
+
+	public static function start( init : Void -> Void ) {
+		sdl.Sdl.init();
+		win = new sdl.Window("", windowWidth, windowHeight);
+		win.vsync = false;
+		init();
+		sdl.Sdl.loop(mainLoop);
+		sdl.Sdl.quit();
+	}
+
+
 	#end
 	#end
 
 
 }
 }

+ 2 - 2
hxd/fmt/hmd/Library.hx

@@ -15,8 +15,8 @@ private class FormatMap {
 }
 }
 
 
 class GeometryBuffer {
 class GeometryBuffer {
-	public var vertexes : haxe.ds.Vector<Float>;
-	public var indexes : haxe.ds.Vector<Int>;
+	public var vertexes : haxe.ds.Vector<hxd.impl.Float32>;
+	public var indexes : haxe.ds.Vector<hxd.impl.UInt16>;
 	public function new() {
 	public function new() {
 	}
 	}
 }
 }

+ 3 - 0
hxd/impl/Float32.hx

@@ -0,0 +1,3 @@
+package hxd.impl;
+
+typedef Float32 = #if (hxsdl && !macro) cpp.Float32 #else Float #end;

+ 3 - 0
hxd/impl/UInt16.hx

@@ -0,0 +1,3 @@
+package hxd.impl;
+
+typedef UInt16 = #if (hxsdl && !macro) cpp.UInt16 #else Int #end;

+ 1 - 2
samples/basic/basic_ogl.hxml

@@ -3,6 +3,5 @@
 -lib heaps
 -lib heaps
 -D resourcesPath=../res
 -D resourcesPath=../res
 -dce full
 -dce full
--lib nme
---remap flash:nme
+-lib hxsdl
 --macro include('h3d')
 --macro include('h3d')

+ 1 - 1
samples/basic/basic_ogl.hxproj

@@ -24,7 +24,7 @@
     <option noInlineOnDebug="False" />
     <option noInlineOnDebug="False" />
     <option mainClass="Main" />
     <option mainClass="Main" />
     <option enabledebug="False" />
     <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')" />
+    <option additional="-lib heaps&#xA;-D resourcesPath=../res&#xA;-dce full&#xA;-lib hxsdl&#xA;--macro include('h3d')" />
   </build>
   </build>
   <!-- haxelib libraries -->
   <!-- haxelib libraries -->
   <haxelib>
   <haxelib>