Browse Source

Add support for openfl/lime

MrCdK 10 years ago
parent
commit
d4996d7b1a
5 changed files with 85 additions and 6 deletions
  1. 4 0
      h3d/impl/Driver.hx
  2. 11 1
      h3d/impl/GlDriver.hx
  3. 1 1
      hxd/BitmapData.hx
  4. 2 2
      hxd/Stage.hx
  5. 67 2
      hxd/System.hx

+ 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 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 };
+#elseif lime
+typedef IndexBuffer = lime.graphics.opengl.GLBuffer;
+typedef VertexBuffer = { b : lime.graphics.opengl.GLBuffer, stride : Int };
+typedef Texture = { t : lime.graphics.opengl.GLTexture, width : Int, height : Int, fmt : Int, ?fb : lime.graphics.opengl.GLFramebuffer, ?rb : lime.graphics.opengl.GLRenderbuffer };
 #elseif hxsdl
 typedef IndexBuffer = sdl.GL.Buffer;
 typedef VertexBuffer = { b : sdl.GL.Buffer, stride : Int };

+ 11 - 1
h3d/impl/GlDriver.hx

@@ -12,6 +12,14 @@ private typedef GL = js.html.webgl.GL;
 private typedef Uniform = js.html.webgl.UniformLocation;
 private typedef Program = js.html.webgl.Program;
 private typedef GLShader = js.html.webgl.Shader;
+#elseif lime
+import lime.graphics.opengl.GL;
+private typedef Uniform = Dynamic;
+private typedef Program = lime.graphics.opengl.GLProgram;
+private typedef GLShader = lime.graphics.opengl.GLShader;
+private typedef Uint16Array = lime.utils.UInt16Array;
+private typedef Uint8Array = lime.utils.UInt8Array;
+private typedef Float32Array = lime.utils.Float32Array;
 #elseif nme
 import nme.gl.GL;
 private typedef Uniform = Dynamic;
@@ -137,7 +145,7 @@ class GlDriver extends Driver {
 		var code = glout.run(shader.data);
 		gl.shaderSource(s, code);
 		gl.compileShader(s);
-		if( gl.getShaderParameter(s, GL.COMPILE_STATUS) != cast 1 ) {
+		if ( gl.getShaderParameter(s, GL.COMPILE_STATUS) != cast 1 ) {
 			var log = gl.getShaderInfoLog(s);
 			var lid = Std.parseInt(log.substr(9));
 			var line = lid == null ? null : code.split("\n")[lid - 1];
@@ -464,6 +472,8 @@ class GlDriver extends Driver {
 		pixels.setFlip(true);
 		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, bmp.width, bmp.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, pixels.bytes.getData());
 		pixels.dispose();
+		#elseif lime
+		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, bmp.width, bmp.height, 0, GL.RGBA, GL.UNSIGNED_BYTE, img.image.data);
 		#else
 		gl.texImage2D(GL.TEXTURE_2D, mipLevel, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, img.getImageData(0, 0, bmp.width, bmp.height));
 		#end

+ 1 - 1
hxd/BitmapData.hx

@@ -350,7 +350,7 @@ class BitmapData {
 
 	public function getPixels() : Pixels {
 		#if (flash || nme || openfl)
-		var p = new Pixels(width, height, haxe.io.Bytes.ofData(bmp.getPixels(bmp.rect)), ARGB);
+		var p = new Pixels(width, height, haxe.io.Bytes.ofData(bmp.getPixels(bmp.rect)#if openfl .getData() #end), ARGB);
 		p.flags.set(AlphaPremultiplied);
 		return p;
 		#elseif js

+ 2 - 2
hxd/Stage.hx

@@ -71,8 +71,8 @@ class Stage {
 			setupOnCloseEvent();
 		#end
 	}
-
-	#if flash
+	
+	#if (flash || openfl)
 
 	function initGesture(b) {
 		if( hxd.System.isTouch && ENABLE_TOUCH ) {

+ 67 - 2
hxd/System.hx

@@ -78,7 +78,7 @@ class System {
 
 	static var loop = null;
 	static var loopFunc = null;
-	#if nme
+	#if (nme || openfl)
 	static var VIEW = null;
 	#end
 
@@ -94,7 +94,14 @@ class System {
 			VIEW.name = "glView";
 			flash.Lib.current.addChildAt(VIEW,0);
 		}
-		VIEW.render = function(_) if( f != null ) f();
+		VIEW.render = function(_) if ( f != null ) f();
+		#elseif openfl
+		if( VIEW == null ) {
+			VIEW = new openfl.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);
@@ -143,6 +150,64 @@ class System {
          (0 == 2 ? nme.Lib.HW_AA : 0),
          "Heaps Application"
 		);
+		#elseif openfl
+		var windowSize = haxe.macro.Compiler.getDefine("window");
+		if( windowSize == null ) windowSize = "800x600";
+		var windowSize = windowSize.split("x");
+		var width = Std.parseInt(windowSize[0]), height = Std.parseInt(windowSize[1]);
+		if( width < 100 ) width = 100;
+		if ( height < 100 ) height = 100;
+		
+		var config = {
+			
+			build: "1",
+			company: "Heaps",
+			fps: 60,
+			orientation: "",
+			packageName: "heaps.application",
+			version: "0.0.1",
+			windows: [
+				
+				{
+					antialiasing: 0,
+					background: 16777215,
+					borderless: false,
+					depthBuffer: true,
+					display: 0,
+					fullscreen: false,
+					hardware: true,
+					height: height,
+					parameters: "{}",
+					resizable: true,
+					stencilBuffer: true,
+					title: "Heaps Application",
+					vsync: true,
+					width: width,
+					x: null,
+					y: null
+				},
+			]
+			
+		};
+		
+		var app = new openfl.display.Application ();
+		app.create (config);
+		
+		try {
+			callb();
+		} catch( e : Dynamic ) {
+			Sys.println(e);
+			#if debug
+			Sys.println(haxe.CallStack.toString(haxe.CallStack.exceptionStack()));
+			#end
+		}
+		
+		var result = app.exec ();
+		
+		#if sys
+		Sys.exit(result);
+		#end
+		
 		#else
 		callb();
 		#end