Browse Source

Removed duplicate code from shadow map setup.

Lasse Öörni 11 years ago
parent
commit
210b295f81

+ 1 - 1
Source/Engine/Container/Str.h

@@ -373,7 +373,7 @@ public:
     int Compare(const String& str, bool caseSensitive = true) const;
     /// Return comparision result with a C string.
     int Compare(const char* str, bool caseSensitive = true) const;
-    /// Return whether contains a specific occurences of string.
+    /// Return whether contains a specific occurence of a string.
     bool Contains(const String& str, bool caseSensitive = true) const { return Find(str, 0, caseSensitive) != NPOS; }
     /// Return whether contains a specific character.
     bool Contains(char c, bool caseSensitive = true) const { return Find(c, 0, caseSensitive) != NPOS; }

+ 4 - 4
Source/Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -2272,11 +2272,11 @@ void Graphics::Release(bool clearGPUObjects, bool closeWindow)
     shaderPrograms_.Clear();
     
     // End fullscreen mode first to counteract transition and getting stuck problems on OS X
-#if defined(__APPLE__) && !defined(IOS)
+    #if defined(__APPLE__) && !defined(IOS)
     if (closeWindow && fullscreen_ && !externalWindow_)
         SDL_SetWindowFullscreen(impl_->window_, SDL_FALSE);
-#endif
-        
+    #endif
+
     if (impl_->context_)
     {
         // Do not log this message if we are exiting
@@ -2582,7 +2582,7 @@ void Graphics::CheckFeatureSupport(String& extensions)
         deferredSupport_ = true;
     
     #if defined(__APPLE__) && !defined(IOS)
-    // On Apple check for an Intel driver and use shadow map RGBA dummy color textures, because mixing
+    // On OS X check for an Intel driver and use shadow map RGBA dummy color textures, because mixing
     // depth-only FBO rendering and backbuffer rendering will bug, resulting in a black screen in full
     // screen mode, and incomplete shadow maps in windowed mode
     String renderer((const char*)glGetString(GL_RENDERER));

+ 10 - 30
Source/Engine/Graphics/Renderer.cpp

@@ -873,9 +873,6 @@ Texture2D* Renderer::GetShadowMap(Light* light, Camera* camera, unsigned viewWid
     int retries = 3;
     unsigned dummyColorFormat = graphics_->GetDummyColorFormat();
     
-    // OpenGL: create shadow map only in normal cases. Color rendertarget is only needed for a workaround
-    // of an OS X + Intel bug
-    #ifdef URHO3D_OPENGL
     while (retries)
     {
         if (!newShadowMap->SetSize(width, height, shadowMapFormat, TEXTURE_DEPTHSTENCIL))
@@ -886,10 +883,19 @@ Texture2D* Renderer::GetShadowMap(Light* light, Camera* camera, unsigned viewWid
         }
         else
         {
+            #ifdef URHO3D_OPENGL
             #ifndef GL_ES_VERSION_2_0
+            // OpenGL (desktop): shadow compare mode needs to be specifically enabled for the shadow map
             newShadowMap->SetFilterMode(FILTER_BILINEAR);
             newShadowMap->SetShadowCompare(true);
             #endif
+            #else
+            // Direct3D9: when shadow compare must be done manually, use nearest filtering so that the filtering of point lights
+            // and other shadowed lights matches
+            newShadowMap->SetFilterMode(graphics_->GetHardwareShadowSupport() ? FILTER_BILINEAR : FILTER_NEAREST);
+            #endif
+            // Create dummy color texture for the shadow map if necessary: Direct3D9, or OpenGL when working around an OS X +
+            // Intel driver bug
             if (dummyColorFormat)
             {
                 // If no dummy color rendertarget for this size exists yet, create one now
@@ -904,33 +910,7 @@ Texture2D* Renderer::GetShadowMap(Light* light, Camera* camera, unsigned viewWid
             break;
         }
     }
-    #else
-    // Direct3D9: create shadow map and dummy color rendertarget
-    while (retries)
-    {
-        if (!newShadowMap->SetSize(width, height, shadowMapFormat, TEXTURE_DEPTHSTENCIL))
-        {
-            width >>= 1;
-            height >>= 1;
-            --retries;
-        }
-        else
-        {
-            // When shadow compare must be done manually, use nearest filtering so that the filtering of point lights and other
-            // shadowed lights matches
-            newShadowMap->SetFilterMode(graphics_->GetHardwareShadowSupport() ? FILTER_BILINEAR : FILTER_NEAREST);
-            // If no dummy color rendertarget for this size exists yet, create one now
-            if (!colorShadowMaps_.Contains(searchKey))
-            {
-                colorShadowMaps_[searchKey] = new Texture2D(context_);
-                colorShadowMaps_[searchKey]->SetSize(width, height, dummyColorFormat, TEXTURE_RENDERTARGET);
-            }
-            // Link the color rendertarget to the shadow map
-            newShadowMap->GetRenderSurface()->SetLinkedRenderTarget(colorShadowMaps_[searchKey]->GetRenderSurface());
-            break;
-        }
-    }
-    #endif
+    
     // If failed to set size, store a null pointer so that we will not retry
     if (!retries)
         newShadowMap.Reset();