Browse Source

Fix readable HW depth rendering on D3D11. Do not allocate a dummy color rendertarget for depth-only rendering unnecessarily on D3D11.

Lasse Öörni 10 years ago
parent
commit
c1e2d51338

+ 3 - 1
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -2472,7 +2472,9 @@ void Graphics::PrepareDraw()
         for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
             impl_->renderTargetViews_[i] = renderTargets_[i] ? (ID3D11RenderTargetView*)renderTargets_[i]->GetRenderTargetView() : 0;
         // If rendertarget 0 is null and not doing depth-only rendering, render to the backbuffer
-        if (!renderTargets_[0] && !depthStencil_)
+        // Special case: if rendertarget 0 is null and depth stencil has same size as backbuffer, assume the intention is to do
+        // backbuffer rendering with a custom depth stencil
+        if (!renderTargets_[0] && (!depthStencil_ || (depthStencil_ && depthStencil_->GetWidth() == width_ && depthStencil_->GetHeight() == height_)))
             impl_->renderTargetViews_[0] = impl_->defaultRenderTargetView_;
         
         impl_->deviceContext_->OMSetRenderTargets(MAX_RENDERTARGETS, &impl_->renderTargetViews_[0], impl_->depthStencilView_);

+ 2 - 2
Source/Urho3D/Graphics/View.cpp

@@ -1636,8 +1636,8 @@ void View::SetRenderTargets(RenderPathCommand& command)
                 {
                     useColorWrite = false;
                     useCustomDepth = true;
-                    #ifndef URHO3D_OPENGL
-                    // On D3D actual depth-only rendering is illegal, we need a color rendertarget
+                    #if !defined(URHO3D_OPENGL) && !defined(URHO3D_D3D11)
+                    // On D3D9 actual depth-only rendering is illegal, we need a color rendertarget
                     if (!depthOnlyDummyTexture_)
                     {
                         depthOnlyDummyTexture_ = renderer_->GetScreenBuffer(texture->GetWidth(), texture->GetHeight(),