瀏覽代碼

Print one-time error if shader variation is not found.

Lasse Öörni 14 年之前
父節點
當前提交
c590973745

+ 8 - 8
Engine/Graphics/Direct3D9/D3D9Shader.cpp

@@ -149,14 +149,14 @@ bool Shader::Load(Deserializer& source)
 
 ShaderVariation* Shader::GetVariation(const String& name)
 {
-    return GetVariation(StringHash(name));
-}
-
-ShaderVariation* Shader::GetVariation(StringHash nameHash)
-{
+    StringHash nameHash(name);
     Map<StringHash, SharedPtr<ShaderVariation> >::Iterator i = variations_.Find(nameHash);
-    if (i != variations_.End())
-        return i->second_;
-    else
+    if (i == variations_.End())
+    {
+        LOGERROR("Could not find shader variation " + GetName() + "_" + name);
+        variations_[nameHash] = 0; // Store a null pointer so that the error is printed only once
         return 0;
+    }
+    else
+        return i->second_;
 }

+ 1 - 3
Engine/Graphics/Direct3D9/D3D9Shader.h

@@ -43,10 +43,8 @@ public:
     /// Load resource. Return true if successful.
     virtual bool Load(Deserializer& source);
     
-    /// Get a named variation. Return null if not found or could not be created.
+    /// Return a named variation. Return null if not found.
     ShaderVariation* GetVariation(const String& name);
-    /// Get a named variation. Return null if not found or could not be created.
-    ShaderVariation* GetVariation(StringHash nameHash);
     /// Release (unload) all variations.
     void ReleaseAll();
     

+ 9 - 8
Engine/Graphics/OpenGL/OGLShader.cpp

@@ -97,14 +97,15 @@ bool Shader::Load(Deserializer& source)
 
 ShaderVariation* Shader::GetVariation(const String& name)
 {
-    return GetVariation(StringHash(name));
-}
-
-ShaderVariation* Shader::GetVariation(StringHash nameHash)
-{
+    StringHash nameHash(name);
     Map<StringHash, SharedPtr<ShaderVariation> >::Iterator i = variations_.Find(nameHash);
-    if (i != variations_.End())
-        return i->second_;
-    else
+    if (i == variations_.End())
+    {
+        LOGERROR("Could not find shader variation " + GetName() + "_" + name);
+        variations_[nameHash] = 0; // Store a null pointer so that the error is printed only once
         return 0;
+    }
+    else
+        return i->second_;
 }
+

+ 1 - 3
Engine/Graphics/OpenGL/OGLShader.h

@@ -44,10 +44,8 @@ public:
     /// Load resource. Return true if successful.
     virtual bool Load(Deserializer& source);
     
-    /// Get a named variation. Return null if not found or could not be created.
+    /// Return a named variation. Return null if not found.
     ShaderVariation* GetVariation(const String& name);
-    /// Get a named variation. Return null if not found or could not be created.
-    ShaderVariation* GetVariation(StringHash nameHash);
     /// Release (unload) all variations.
     void ReleaseAll();