浏览代码

added Driver.copyTexture

ncannasse 8 年之前
父节点
当前提交
0a669fc64c
共有 3 个文件被更改,包括 19 次插入15 次删除
  1. 9 14
      h3d/impl/DirectXDriver.hx
  2. 7 0
      h3d/impl/Driver.hx
  3. 3 1
      h3d/pass/Copy.hx

+ 9 - 14
h3d/impl/DirectXDriver.hx

@@ -491,6 +491,15 @@ class DirectXDriver extends h3d.impl.Driver {
 		};
 	}
 
+	override function copyTexture(from:h3d.mat.Texture, to:h3d.mat.Texture) {
+		if( from.t == null || from.format != to.format || from.width != to.width || from.height != to.height )
+			return false;
+		if( to.t == null )
+			to.alloc();
+		to.t.res.copyResource(from.t.res);
+		return true;
+	}
+
 	override function setRenderTarget(tex:Null<h3d.mat.Texture>, face = 0, mipLevel = 0) {
 		if( face != 0 || mipLevel != 0 )
 			throw "TODO";
@@ -511,13 +520,6 @@ class DirectXDriver extends h3d.impl.Driver {
 			throw "Can't render to texture which is not allocated with Target flag";
 		if( tex.depthBuffer != null && (tex.depthBuffer.width != tex.width || tex.depthBuffer.height != tex.height) )
 			throw "Invalid depth buffer size : does not match render target size";
-
-		// required or we might get some noise
-		if( !tex.flags.has(WasCleared) ) {
-			tex.flags.set(WasCleared);
-			Driver.clearColor(tex.t.rt, 0, 0, 0, 0);
-		}
-
 		unbind(tex.t.view);
 
 		// we can't use defaultDepth as it might have different resolution than our rendertarget
@@ -557,13 +559,6 @@ class DirectXDriver extends h3d.impl.Driver {
 			var tex = textures[i];
 			if( tex.t == null )
 				tex.alloc();
-
-			// required or we might get some noise
-			if( !tex.flags.has(WasCleared) ) {
-				tex.flags.set(WasCleared);
-				Driver.clearColor(tex.t.rt, 0, 0, 0, 0);
-			}
-
 			currentTargets[i] = tex.t.rt;
 			unbind(tex.t.view);
 		}

+ 7 - 0
h3d/impl/Driver.hx

@@ -233,6 +233,13 @@ class Driver {
 	public function uploadTexturePixels( t : h3d.mat.Texture, pixels : hxd.Pixels, mipLevel : Int, side : Int ) {
 	}
 
+	/**
+		Returns true if we could copy the texture, false otherwise (not supported by driver or mismatch in size/format)
+	**/
+	public function copyTexture( from : h3d.mat.Texture, to : h3d.mat.Texture ) {
+		return false;
+	}
+
 	// --- QUERY API
 
 	public function allocQuery( queryKind : QueryKind ) : Query {

+ 3 - 1
h3d/pass/Copy.hx

@@ -51,7 +51,9 @@ class Copy extends ScreenFx<CopyShader> {
 	}
 
 	static var inst : Copy;
-	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend, ?pass : h3d.mat.Pass ) {
+	public static function run( from : h3d.mat.Texture, to : h3d.mat.Texture, ?blend : h3d.mat.BlendMode, ?pass : h3d.mat.Pass ) {
+		if( to != null && from != null && (blend == null || blend == None) && pass == null && h3d.Engine.getCurrent().driver.copyTexture(from, to) )
+			return;
 		if( inst == null ) inst = new Copy();
 		return inst.apply(from, to, blend, pass);
 	}