Explorar o código

Ensure that manually created textures with an assigned name, but no actual file to back their contents, will recreate the GPU object after device loss and set data lost state.

Lasse Öörni %!s(int64=11) %!d(string=hai) anos
pai
achega
f1ec4c8a18

+ 7 - 12
Source/Engine/Graphics/Direct3D9/D3D9Texture2D.cpp

@@ -88,24 +88,19 @@ void Texture2D::OnDeviceLost()
 
 void Texture2D::OnDeviceReset()
 {
-    if (pool_ == D3DPOOL_DEFAULT || !object_)
+    if (pool_ == D3DPOOL_DEFAULT || !object_ || dataPending_)
     {
-        // If has a file name, reload through the resource cache. Otherwise just recreate.
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
+        // If has a resource file, reload through the resource cache. Otherwise just recreate.
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+        if (cache->Exists(GetName()))
+            dataLost_ = !cache->ReloadResource(this);
         else
         {
-            Create();
+            if (!object_)
+                Create();
             dataLost_ = true;
         }
     }
-    else if (dataPending_)
-    {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
-        else
-            dataLost_ = true;
-    }
     
     dataPending_ = false;
 }

+ 7 - 12
Source/Engine/Graphics/Direct3D9/D3D9Texture3D.cpp

@@ -128,24 +128,19 @@ void Texture3D::OnDeviceLost()
 
 void Texture3D::OnDeviceReset()
 {
-    if (pool_ == D3DPOOL_DEFAULT || !object_)
+    if (pool_ == D3DPOOL_DEFAULT || !object_ || dataPending_)
     {
-        // If has a file name, reload through the resource cache. Otherwise just recreate.
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
+        // If has a resource file, reload through the resource cache. Otherwise just recreate.
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+        if (cache->Exists(GetName()))
+            dataLost_ = !cache->ReloadResource(this);
         else
         {
-            Create();
+            if (!object_)
+                Create();
             dataLost_ = true;
         }
     }
-    else if (dataPending_)
-    {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
-        else
-            dataLost_ = true;
-    }
     
     dataPending_ = false;
 }

+ 7 - 12
Source/Engine/Graphics/Direct3D9/D3D9TextureCube.cpp

@@ -73,24 +73,19 @@ void TextureCube::OnDeviceLost()
 
 void TextureCube::OnDeviceReset()
 {
-    if (pool_ == D3DPOOL_DEFAULT || !object_)
+    if (pool_ == D3DPOOL_DEFAULT || !object_ || dataPending_)
     {
-        // If has a file name, reload through the resource cache. Otherwise just recreate.
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
+        // If has a resource file, reload through the resource cache. Otherwise just recreate.
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+        if (cache->Exists(GetName()))
+            dataLost_ = !cache->ReloadResource(this);
         else
         {
-            Create();
+            if (!object_)
+                Create();
             dataLost_ = true;
         }
     }
-    else if (dataPending_)
-    {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
-        else
-            dataLost_ = true;
-    }
     
     dataPending_ = false;
 }

+ 7 - 12
Source/Engine/Graphics/OpenGL/OGLTexture2D.cpp

@@ -91,24 +91,19 @@ void Texture2D::OnDeviceLost()
 
 void Texture2D::OnDeviceReset()
 {
-    // If has a file name, reload through the resource cache. Otherwise just recreate.
-    if (!object_)
+    if (!object_ || dataPending_)
     {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
+        // If has a resource file, reload through the resource cache. Otherwise just recreate.
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+        if (cache->Exists(GetName()))
+            dataLost_ = !cache->ReloadResource(this);
         else
         {
-            Create();
+            if (!object_)
+                Create();
             dataLost_ = true;
         }
     }
-    else if (dataPending_)
-    {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
-        else
-            dataLost_ = true;
-    }
     
     dataPending_ = false;
 }

+ 7 - 12
Source/Engine/Graphics/OpenGL/OGLTexture3D.cpp

@@ -135,24 +135,19 @@ void Texture3D::OnDeviceLost()
 
 void Texture3D::OnDeviceReset()
 {
-    // If has a file name, reload through the resource cache. Otherwise just recreate.
-    if (!object_)
+    if (!object_ || dataPending_)
     {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
+        // If has a resource file, reload through the resource cache. Otherwise just recreate.
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+        if (cache->Exists(GetName()))
+            dataLost_ = !cache->ReloadResource(this);
         else
         {
-            Create();
+            if (!object_)
+                Create();
             dataLost_ = true;
         }
     }
-    else if (dataPending_)
-    {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
-        else
-            dataLost_ = true;
-    }
     
     dataPending_ = false;
 }

+ 7 - 12
Source/Engine/Graphics/OpenGL/OGLTextureCube.cpp

@@ -79,24 +79,19 @@ void TextureCube::OnDeviceLost()
 
 void TextureCube::OnDeviceReset()
 {
-    // If has a file name, reload through the resource cache. Otherwise just recreate.
-    if (!object_)
+    if (!object_ || dataPending_)
     {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
+        // If has a resource file, reload through the resource cache. Otherwise just recreate.
+        ResourceCache* cache = GetSubsystem<ResourceCache>();
+        if (cache->Exists(GetName()))
+            dataLost_ = !cache->ReloadResource(this);
         else
         {
-            Create();
+            if (!object_)
+                Create();
             dataLost_ = true;
         }
     }
-    else if (dataPending_)
-    {
-        if (!GetName().Trimmed().Empty())
-            dataLost_ = !GetSubsystem<ResourceCache>()->ReloadResource(this);
-        else
-            dataLost_ = true;
-    }
     
     dataPending_ = false;
 }

+ 2 - 0
Source/Engine/Resource/ResourceCache.cpp

@@ -503,6 +503,8 @@ void ResourceCache::GetResources(PODVector<Resource*>& result, ShortStringHash t
 bool ResourceCache::Exists(const String& nameIn) const
 {
     String name = SanitateResourceName(nameIn);
+    if (name.Empty())
+        return false;
     
     for (unsigned i = 0; i < packages_.Size(); ++i)
     {