Prechádzať zdrojové kódy

begin of lime JS target support, still not working right now.

Before GlslOut conditional compilation with GLES
kiroukou 9 rokov pred
rodič
commit
f8949cb291

+ 6 - 6
h3d/impl/GlDriver.hx

@@ -86,18 +86,18 @@ class GlDriver extends Driver {
 	var curTarget : h3d.mat.Texture;
 
 	public function new() {
-		#if js
+		#if (nme || openfl || lime)
+		// check for a bug in HxCPP handling of sub buffers
+		var tmp = new Float32Array(8);
+		var sub = new Float32Array(tmp.buffer, 0, 4);
+		#if cpp fixMult = sub.length == 1; #end  // should be 4
+		#elseif js
 		canvas = @:privateAccess hxd.Stage.getCanvas();
 		if( canvas == null ) throw "Canvas #webgl not found";
 		gl = canvas.getContextWebGL({alpha:false});
 		if( gl == null ) throw "Could not acquire GL context";
 		// debug if webgl_debug.js is included
 		untyped if( __js__('typeof')(WebGLDebugUtils) != "undefined" ) gl = untyped WebGLDebugUtils.makeDebugContext(gl);
-		#elseif (nme || openfl || lime)
-		// check for a bug in HxCPP handling of sub buffers
-		var tmp = new Float32Array(8);
-		var sub = new Float32Array(tmp.buffer, 0, 4);
-		fixMult = sub.length == 1; // should be 4
 		#end
 		programs = new Map();
 		curAttribs = 0;

+ 5 - 5
hxd/Stage.hx

@@ -17,7 +17,7 @@ class Stage {
 	var resizeEvents : List<Void -> Void>;
 	var eventTargets : List<Event -> Void>;
 
-	#if js
+	#if (js && !lime)
 	@:allow(hxd)
 	static function getCanvas() {
 		var canvas : js.html.CanvasElement = cast js.Browser.document.getElementById("webgl");
@@ -42,6 +42,9 @@ class Stage {
 		stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
 		stage.addEventListener(flash.events.Event.RESIZE, onResize);
 		initGesture(false);
+		#elseif lime
+		limeStage = new hxd.impl.LimeStage( this );
+		lime.app.Application.current.addModule( limeStage );
 		#elseif js
 		canvas = getCanvas();
 		canvasPos = canvas.getBoundingClientRect();
@@ -67,9 +70,6 @@ class Stage {
 				onResize(null);
 			}
 		};
-		#elseif lime
-		limeStage = new hxd.impl.LimeStage( this );
-		lime.app.Application.current.addModule( limeStage );
 		#end
 		#if flash
 		if( untyped hxd.System.isAir() )
@@ -336,7 +336,7 @@ class Stage {
 		event(ev);
 	}
 
-#elseif js
+#elseif (js && !lime)
 
 	var curMouseX : Float = 0.;
 	var curMouseY : Float = 0.;

+ 4 - 1
hxd/fs/LimeFileSystem.hx

@@ -136,7 +136,10 @@ private class LimeEntry extends FileEntry {
 		loader.loadBytes(bytes);
 		close(); // flash will copy bytes content in loadBytes() !
 		#else
-		onLoaded( new LoadedBitmap(lime.graphics.Image.fromBytes(bytes)) );
+		
+		lime.graphics.Image.fromBytes(bytes, function(img) {
+			onLoaded(new hxd.fs.LoadedBitmap(img));
+		});
 		close();
 		#end
 	}

+ 9 - 6
hxd/fs/LoadedBitmap.hx

@@ -2,10 +2,10 @@ package hxd.fs;
 
 #if (flash || openfl)
 typedef LoadedBitmapData = flash.display.BitmapData;
-#elseif js 
-typedef LoadedBitmapData = js.html.Image;
 #elseif lime
 typedef LoadedBitmapData = lime.graphics.Image;
+#elseif js 
+typedef LoadedBitmapData = js.html.Image;
 #else 
 typedef LoadedBitmapData = Dynamic;
 #end
@@ -19,13 +19,16 @@ abstract LoadedBitmap(LoadedBitmapData) {
 	public function toBitmap() : hxd.BitmapData {
 		#if (flash || openfl)
 		return hxd.BitmapData.fromNative(this);
-		#elseif js
+		#elseif lime
 		var bmp = new hxd.BitmapData(this.width, this.height);
-		@:privateAccess bmp.ctx.drawImage(this, 0, 0);
+			//TODO  test this
+			#if js @:privateAccess bmp.pixel = this.src;
+			#else @:privateAccess bmp.data = this;
+			#end
 		return bmp;
-		#elseif lime
+		#elseif js
 		var bmp = new hxd.BitmapData(this.width, this.height);
-		@:privateAccess bmp.data = this;
+		@:privateAccess bmp.ctx.drawImage(this, 0, 0);
 		return bmp;
 		#else
 		throw "TODO";

+ 7 - 3
hxsl/GlslOut.hx

@@ -372,10 +372,14 @@ class GlslOut {
 		decls = [];
 		buf = new StringBuf();
 		exprValues = [];
-		//Version is required on desktop for precision qualifier, but version 1.0.0 only is supported on webgl
-		#if (windows||linux)
+		
+		//#if GL_ES_VERSION_2_0  would be the test to use at compilation time, but would require a GL context to call glGetString (GL_SHADING_LANGUAGE_VERSION)
+		//#ifdef GL_ES is to test in the shader itself but #version  muse be declared first
+		#if((cpp && mobile)||js)
+		decls.push("#version 100");
+		#else
 		decls.push("#version 130");
-		#end
+		#end 
 		decls.push("precision mediump float;");
 		
 		if( s.funs.length != 1 ) throw "assert";