Ver código fonte

If no RenderTarget is set clear() clears backbuffer

TothBenoit 1 ano atrás
pai
commit
aee4452e31
3 arquivos alterados com 21 adições e 8 exclusões
  1. 13 5
      h3d/impl/DX12Driver.hx
  2. 2 0
      h3d/impl/DirectXDriver.hx
  3. 6 3
      h3d/pass/DirShadowMap.hx

+ 13 - 5
h3d/impl/DX12Driver.hx

@@ -59,6 +59,7 @@ class ManagedHeapArray {
 
 class DxFrame {
 	public var backBuffer : ResourceData;
+	public var backBufferView : Address;
 	public var depthBuffer : GpuResource;
 	public var allocator : CommandAllocator;
 	public var commandList : CommandList;
@@ -452,9 +453,10 @@ class DX12Driver extends h3d.impl.Driver {
 		curStencilRef = -1;
 		currentIndex = null;
 
+		frame.backBufferView = renderTargetViews.alloc(1);
+		Driver.createRenderTargetView(frame.backBuffer.res, null, frame.backBufferView);
 		setRenderTarget(null);
 
-
 		frame.shaderResourceCache.reset();
 		frame.samplerCache.reset();
 		frame.shaderResourceViews = frame.shaderResourceCache.next();
@@ -488,7 +490,7 @@ class DX12Driver extends h3d.impl.Driver {
 			}
 			// clear backbuffer
 			if( count == 0 )
-				frame.commandList.clearRenderTargetView(tmp.renderTargets[0], clear);
+				frame.commandList.clearRenderTargetView(frame.backBufferView, clear);
 		}
 		if( depth != null || stencil != null )
 			frame.commandList.clearDepthStencilView(tmp.depthStencils[0], depth != null ? (stencil != null ? BOTH : DEPTH) : STENCIL, (depth:Float), stencil);
@@ -673,7 +675,6 @@ class DX12Driver extends h3d.impl.Driver {
 
 		depthEnabled = depthBinding != NotBound;
 
-		var texView = renderTargetViews.alloc(1);
 		var isArr = tex != null && (tex.flags.has(IsArray) || tex.flags.has(Cube));
 		var desc = null;
 		if( layer != 0 || mipLevel != 0 || isArr ) {
@@ -691,8 +692,15 @@ class DX12Driver extends h3d.impl.Driver {
 				desc.planeSlice = 0;
 			}
 		}
-		Driver.createRenderTargetView(tex == null ? frame.backBuffer.res : tex.t.res, desc, texView);
-		tmp.renderTargets[0] = texView;
+		if (tex != null) {
+			var texView = renderTargetViews.alloc(1);
+			Driver.createRenderTargetView(tex.t.res, desc, texView);
+			tmp.renderTargets[0] = texView;
+		}
+		else {
+			tmp.renderTargets[0] = frame.backBufferView;
+		}
+
 		if ( tex != null && !tex.flags.has(WasCleared) ) {
 			tex.flags.set(WasCleared);
 			var clear = tmp.clearColor;

+ 2 - 0
h3d/impl/DirectXDriver.hx

@@ -280,6 +280,8 @@ class DirectXDriver extends h3d.impl.Driver {
 		if( color != null ) {
 			for( i in 0...targetsCount )
 				Driver.clearColor(currentTargets[i], color.r, color.g, color.b, color.a);
+			if (targetsCount == 0)
+				Driver.clearColor(defaultTarget, color.r, color.g, color.b, color.a);
 		}
 		if( currentDepth != null && (depth != null || stencil != null) )
 			Driver.clearDepthStencilView(currentDepth.depthView, depth, stencil);

+ 6 - 3
h3d/pass/DirShadowMap.hx

@@ -266,11 +266,14 @@ class DirShadowMap extends Shadows {
 	}
 
 	function processShadowMap( passes, tex, ?sort) {
-		if ( tex.isDepth() )
+		if ( tex.isDepth() ) {
 			ctx.engine.pushDepth(tex);
-		else
+			ctx.engine.clear(null, 1.0);
+		}
+		else {
 			ctx.engine.pushTarget(tex);
-		ctx.engine.clear(0xFFFFFF, 1.0);
+			ctx.engine.clear(0xFFFFFF);
+		}
 		super.draw(passes, sort);
 
 		var doBlur = blur.radius > 0 && (mode != Mixed || !ctx.computingStatic);