Przeglądaj źródła

support hl/hxsdl

Nicolas Cannasse 9 lat temu
rodzic
commit
c913c4b726
5 zmienionych plików z 18 dodań i 14 usunięć
  1. 1 1
      h3d/Engine.hx
  2. 6 4
      h3d/impl/GlDriver.hx
  3. 3 3
      h3d/impl/NullDriver.hx
  4. 1 1
      hxd/impl/Float32.hx
  5. 7 5
      hxd/snd/NativeChannel.hx

+ 1 - 1
h3d/Engine.hx

@@ -53,7 +53,7 @@ class Engine {
 		realFps = hxd.System.getDefaultFrameRate();
 		lastTime = haxe.Timer.stamp();
 		stage.addResizeEvent(onStageResize);
-		#if (js || cpp)
+		#if (js || cpp || hxsdl)
 		driver = new h3d.impl.GlDriver();
 		#elseif flash
 		driver = new h3d.impl.Stage3dDriver();

+ 6 - 4
h3d/impl/GlDriver.hx

@@ -2,7 +2,7 @@ package h3d.impl;
 import h3d.impl.Driver;
 import h3d.mat.Pass;
 
-#if (js||cpp)
+#if (js||cpp||hxsdl)
 
 #if js
 import js.html.Uint16Array;
@@ -62,7 +62,7 @@ private class CompiledProgram {
 }
 
 @:access(h3d.impl.Shader)
-#if cpp
+#if (cpp||hxsdl)
 @:build(h3d.impl.MacroHelper.replaceGL())
 #end
 class GlDriver extends Driver {
@@ -529,7 +529,8 @@ class GlDriver extends Driver {
 		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);
+		var data = #if hl @:privateAccess (cast buf.getNative() : hl.types.ArrayBase.ArrayF32).bytes #else buf.getNative() #end;
+		gl.bufferSubData(GL.ARRAY_BUFFER, startVertex * stride * 4, data, bufPos, vertexCount * stride * 4);
 		#else
 		var buf = new Float32Array(buf.getNative());
 		var sub = new Float32Array(buf.buffer, bufPos, vertexCount * stride #if cpp * (fixMult?4:1) #end);
@@ -554,7 +555,8 @@ class GlDriver extends Driver {
 	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);
+		var data = #if hl @:privateAccess (cast buf.getNative() : hl.types.ArrayBase.ArrayI16).bytes #else buf.getNative() #end;
+		gl.bufferSubData(GL.ELEMENT_ARRAY_BUFFER, startIndice * 2, data, bufPos, indiceCount * 2);
 		#else
 		var buf = new Uint16Array(buf.getNative());
 		var sub = new Uint16Array(buf.buffer, bufPos, indiceCount #if cpp * (fixMult?2:1) #end);

+ 3 - 3
h3d/impl/NullDriver.hx

@@ -48,15 +48,15 @@ class NullDriver extends Driver {
 	}
 
 	override function allocTexture( t : h3d.mat.Texture ) : Texture {
-		return null;
+		return cast {};
 	}
 
 	override function allocIndexes( count : Int ) : IndexBuffer {
-		return null;
+		return cast {};
 	}
 
 	override function allocVertexes( m : ManagedBuffer ) : VertexBuffer {
-		return null;
+		return cast {};
 	}
 
 }

+ 1 - 1
hxd/impl/Float32.hx

@@ -1,3 +1,3 @@
 package hxd.impl;
 
-typedef Float32 = #if cpp cpp.Float32 #else Float #end;
+typedef Float32 = #if cpp cpp.Float32 #elseif hl hl.types.F32 #else Float #end;

+ 7 - 5
hxd/snd/NativeChannel.hx

@@ -7,11 +7,13 @@ private class ChannelMapper extends sdl.SoundChannel {
 		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
 import lime.audio.openal.AL;
@@ -22,7 +24,7 @@ private class ALChannel {
 
 	var buffers : Array<Int>;
 	var src : Int;
-	
+
 	var fbuf : haxe.io.Bytes;
 	var ibuf : haxe.io.Bytes;
 	var iview : lime.utils.ArrayBufferView;
@@ -37,7 +39,7 @@ private class ALChannel {
 		fbuf = haxe.io.Bytes.alloc( samples<<3 );
 		ibuf = haxe.io.Bytes.alloc( samples<<2 );
 		iview = new lime.utils.Int16Array(ibuf);
-		
+
 		for ( b in buffers )
 			onSample(b);
 		forcePlay();
@@ -56,7 +58,7 @@ private class ALChannel {
 
 	@:noDebug function onSample( buf : Int ) {
 		@:privateAccess native.onSample(haxe.io.Float32Array.fromBytes(fbuf));
-		
+
 		// Convert Float32 to Int16
 		#if cpp
 		var fb = fbuf.getData();
@@ -74,10 +76,10 @@ private class ALChannel {
 		AL.bufferData(buf, AL.FORMAT_STEREO16, iview, ibuf.length, 44100);
 		AL.sourceQueueBuffers(src, 1, [buf]);
 	}
-	
+
 	inline function forcePlay() {
 		if( AL.getSourcei(src,AL.SOURCE_STATE) != AL.PLAYING )
-			AL.sourcePlay(src);	
+			AL.sourcePlay(src);
 	}
 
 	function onUpdate( i : Int ){