Selaa lähdekoodia

added setCapture to capture screen output

ncannasse 11 vuotta sitten
vanhempi
commit
6efdc2bb23
3 muutettua tiedostoa jossa 20 lisäystä ja 0 poistoa
  1. 4 0
      h3d/Engine.hx
  2. 3 0
      h3d/impl/Driver.hx
  3. 13 0
      h3d/impl/Stage3dDriver.hx

+ 4 - 0
h3d/Engine.hx

@@ -82,6 +82,10 @@ class Engine {
 	public function driverName(details=false) {
 		return driver.getDriverName(details);
 	}
+	
+	public function setCapture( bmp : hxd.BitmapData, callb : Void -> Void ) {
+		driver.setCapture(bmp,callb);
+	}
 
 	public function selectShader( shader : h3d.impl.Shader ) {
 		if( driver.selectShader(shader) )

+ 3 - 0
h3d/impl/Driver.hx

@@ -30,6 +30,9 @@ class Driver {
 	public function clear( r : Float, g : Float, b : Float, a : Float ) {
 	}
 	
+	public function setCapture( bmp : hxd.BitmapData, callb : Void -> Void ) {
+	}
+	
 	public function reset() {
 	}
 	

+ 13 - 0
h3d/impl/Stage3dDriver.hx

@@ -50,6 +50,7 @@ class Stage3dDriver extends Driver {
 	var width : Int;
 	var height : Int;
 	var enableDraw : Bool;
+	var capture : { bmp : hxd.BitmapData, callb : Void -> Void };
 
 	@:allow(h3d.impl.VertexWrapper)
 	var empty : flash.utils.ByteArray;
@@ -114,6 +115,10 @@ class Stage3dDriver extends Driver {
 		ctx.clear(r, g, b, a);
 	}
 	
+	override function setCapture( bmp : hxd.BitmapData, onCapture : Void -> Void ) {
+		capture = { bmp : bmp, callb : onCapture };
+	}
+	
 	override function dispose() {
 		s3d.removeEventListener(flash.events.Event.CONTEXT3D_CREATE, onCreate);
 		if( ctx != null ) ctx.dispose();
@@ -125,6 +130,14 @@ class Stage3dDriver extends Driver {
 	}
 	
 	override function present() {
+		if( capture != null ) {
+			ctx.drawToBitmapData(capture.bmp.toNative());
+			ctx.present();
+			var callb = capture.callb;
+			capture = null;
+			callb();
+			return;
+		}
 		ctx.present();
 	}