Browse Source

added setTarget/setRenderZone

Nicolas Cannasse 13 năm trước cách đây
mục cha
commit
cb91d53e01
2 tập tin đã thay đổi với 27 bổ sung3 xóa
  1. 23 3
      h3d/Engine.hx
  2. 4 0
      h3d/impl/MemoryManager.hx

+ 23 - 3
h3d/Engine.hx

@@ -247,9 +247,7 @@ class Engine {
 		return true;
 	}
 	
-	public function end() {
-		ctx.present();
-		// reset
+	function reset() {
 		curMatBits = -1;
 		curShader = null;
 		curBuffer = null;
@@ -261,6 +259,28 @@ class Engine {
 		curTextures = [];
 	}
 	
+	public function end() {
+		ctx.present();
+		reset();
+	}
+	
+	public function setTarget( tex : h3d.mat.Texture ) {
+		if( tex == null )
+			ctx.setRenderToBackBuffer();
+		else {
+			ctx.setRenderToTexture(tex.t);
+			reset();
+			ctx.clear(0, 0, 0, 0);
+		}
+	}
+	
+	public function setRenderZone( x = 0, y = 0, width = -1, height = -1 ) {
+		if( x == 0 && y == 0 && width < 0 && height < 0 )
+			ctx.setScissorRectangle(null);
+		else
+			ctx.setScissorRectangle(new flash.geom.Rectangle(x, y, width < 0 ? this.width : width, height < 0 ? this.height : height));
+	}
+	
 	public function render( obj : { function render( engine : Engine ) : Void; } ) {
 		if( !begin() ) return false;
 		obj.render(this);

+ 4 - 0
h3d/impl/MemoryManager.hx

@@ -152,6 +152,10 @@ class MemoryManager {
 	public function allocTexture( width : Int, height : Int ) {
 		return new h3d.mat.Texture(ctx.createTexture(width, height, flash.display3D.Context3DTextureFormat.BGRA, false), width, height, false);
 	}
+	
+	public function allocTargetTexture( width : Int, height : Int ) {
+		return new h3d.mat.Texture(ctx.createTexture(width, height, flash.display3D.Context3DTextureFormat.BGRA, true), width, height, false);
+	}
 
 	public function makeTexture( ?bmp : flash.display.BitmapData, ?mbmp : h3d.mat.Bitmap ) {
 		var t;