浏览代码

For less confusing code, do not allocate a depth stencil into colorShadowMaps_ in fallback mode. Instead define a separate variable shadowDepthStencil_.

Lasse Öörni 14 年之前
父节点
当前提交
1e086c84f6
共有 2 个文件被更改,包括 14 次插入15 次删除
  1. 12 15
      Engine/Graphics/Renderer.cpp
  2. 2 0
      Engine/Graphics/Renderer.h

+ 12 - 15
Engine/Graphics/Renderer.cpp

@@ -1297,8 +1297,10 @@ bool Renderer::CreateShadowMaps()
     
     if (!drawShadows_)
     {
+        shadowDepthStencil_.Reset();
         for (unsigned i = 0; i < NUM_SHADOWMAP_RESOLUTIONS; ++i)
         {
+            colorShadowMaps_[i].Reset();
             for (unsigned j = 0; j < shadowMaps_[i].Size(); ++j)
                 shadowMaps_[i][j].Reset();
         }
@@ -1325,6 +1327,14 @@ bool Renderer::CreateShadowMaps()
     // Create shadow maps and dummy color rendertargets
     unsigned size = shadowMapSize_;
     bool fallback = graphics_->GetFallback();
+    // Create one depth stencil buffer in fallback mode to be shared by all shadow maps
+    if (fallback)
+    {
+        if (!shadowDepthStencil_)
+            shadowDepthStencil_ = new Texture2D(context_);
+        if (!shadowDepthStencil_->SetSize(size, size, D3DFMT_D16, TEXTURE_DEPTHSTENCIL))
+            return false;
+    }
     for (unsigned i = 0; i < NUM_SHADOWMAP_RESOLUTIONS; ++i)
     {
         // Dummy color rendertargets are not required in fallback mode, as the shadows are rendered into a color texture
@@ -1335,17 +1345,6 @@ bool Renderer::CreateShadowMaps()
             if (!colorShadowMaps_[i]->SetSize(size, size, dummyColorFormat, TEXTURE_RENDERTARGET))
                 return false;
         }
-        else
-        {
-            // In fallback mode, create one depth stencil that is large enough for the largest shadow map
-            if (!i)
-            {
-                if (!colorShadowMaps_[i])
-                    colorShadowMaps_[i] = new Texture2D(context_);
-                if (!colorShadowMaps_[i]->SetSize(size, size, D3DFMT_D16, TEXTURE_DEPTHSTENCIL))
-                    return false;
-            }
-        }
         for (unsigned j = 0; j < shadowMaps_[i].Size(); ++j)
         {
             if (!shadowMaps_[i][j])
@@ -1359,10 +1358,8 @@ bool Renderer::CreateShadowMaps()
                 shadowMaps_[i][j]->GetRenderSurface()->SetLinkedRenderTarget(colorShadowMaps_[i]->GetRenderSurface());
             }
             else
-            {
-                shadowMaps_[i][j]->SetFilterMode(FILTER_NEAREST);
-                shadowMaps_[i][j]->GetRenderSurface()->SetLinkedDepthBuffer(colorShadowMaps_[0]->GetRenderSurface());
-            }
+                // In fallback mode, link the shared depth stencil buffer to all shadow maps
+                shadowMaps_[i][j]->GetRenderSurface()->SetLinkedDepthBuffer(shadowDepthStencil_->GetRenderSurface());
         }
         size >>= 1;
     }

+ 2 - 0
Engine/Graphics/Renderer.h

@@ -335,6 +335,8 @@ private:
     Vector<SharedPtr<Texture2D> > shadowMaps_[NUM_SHADOWMAP_RESOLUTIONS];
     /// Shadow map dummy color textures by resolution.
     SharedPtr<Texture2D> colorShadowMaps_[NUM_SHADOWMAP_RESOLUTIONS];
+    /// Shadow map depth stencil buffer, used only in fallback mode.
+    SharedPtr<Texture2D> shadowDepthStencil_;
     /// Shadow map use count if reusing is disabled. Is reset for each view.
     unsigned shadowMapUseCount_[NUM_SHADOWMAP_RESOLUTIONS];
     /// Stencil rendering vertex shader.