Browse Source

Add GetFullName in ShaderVariation, make code more clear.

aster2013 12 years ago
parent
commit
9b31d29a54

+ 2 - 2
Source/Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -1040,7 +1040,7 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
                 bool success = vs->Create();
                 bool success = vs->Create();
                 if (!success)
                 if (!success)
                 {
                 {
-                    LOGERROR("Failed to compile vertex shader " + vs->GetName() + ":\n" + vs->GetCompilerOutput());
+                    LOGERROR("Failed to compile vertex shader " + vs->GetFullName() + ":\n" + vs->GetCompilerOutput());
                     vs = 0;
                     vs = 0;
                 }
                 }
             }
             }
@@ -1083,7 +1083,7 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
                 bool success = ps->Create();
                 bool success = ps->Create();
                 if (!success)
                 if (!success)
                 {
                 {
-                    LOGERROR("Failed to compile pixel shader " + ps->GetName() + ":\n" + ps->GetCompilerOutput());
+                    LOGERROR("Failed to compile pixel shader " + ps->GetFullName() + ":\n" + ps->GetCompilerOutput());
                     ps = 0;
                     ps = 0;
                 }
                 }
             }
             }

+ 6 - 2
Source/Engine/Graphics/Direct3D9/D3D9ShaderVariation.cpp

@@ -141,12 +141,16 @@ void ShaderVariation::Release()
 
 
 void ShaderVariation::SetName(const String& name)
 void ShaderVariation::SetName(const String& name)
 {
 {
-    name_ = name.Trimmed().Replaced(' ', '_');
+	name_ = name;
+    // Set full name
+	fullName_ = name_ + "(" + defines_ + ")";
 }
 }
 
 
 void ShaderVariation::SetDefines(const String& defines)
 void ShaderVariation::SetDefines(const String& defines)
 {
 {
     defines_ = defines;
     defines_ = defines;
+    // Set full name
+	fullName_ = name_ + "(" + defines_ + ")";
 }
 }
 
 
 Shader* ShaderVariation::GetOwner() const
 Shader* ShaderVariation::GetOwner() const
@@ -284,7 +288,7 @@ bool ShaderVariation::Compile(PODVector<unsigned>& byteCode)
         // In debug mode, check that all defines are referenced by the shader code
         // In debug mode, check that all defines are referenced by the shader code
         #ifdef _DEBUG
         #ifdef _DEBUG
         if (sourceCode.Find(defines[i]) == String::NPOS)
         if (sourceCode.Find(defines[i]) == String::NPOS)
-            LOGWARNING("Shader " + GetName() + " does not use the define " + defines[i]);
+            LOGWARNING("Shader " + GetFullName() + " does not use the define " + defines[i]);
         #endif
         #endif
     }
     }
     
     

+ 6 - 2
Source/Engine/Graphics/Direct3D9/D3D9ShaderVariation.h

@@ -86,10 +86,12 @@ public:
     Shader* GetOwner() const;
     Shader* GetOwner() const;
     /// Return shader type.
     /// Return shader type.
     ShaderType GetShaderType() const { return type_; }
     ShaderType GetShaderType() const { return type_; }
-    /// Return full shader name.
+    /// Return shader name.
     const String& GetName() const { return name_; }
     const String& GetName() const { return name_; }
     /// Return defines.
     /// Return defines.
     const String& GetDefines() const { return defines_; }
     const String& GetDefines() const { return defines_; }
+	/// Return full shader name.
+	const String& GetFullName() const { return fullName_; }
     /// Return compile error/warning string.
     /// Return compile error/warning string.
     const String& GetCompilerOutput() const { return compilerOutput_; }
     const String& GetCompilerOutput() const { return compilerOutput_; }
     /// Return whether uses a parameter.
     /// Return whether uses a parameter.
@@ -115,10 +117,12 @@ private:
     WeakPtr<Shader> owner_;
     WeakPtr<Shader> owner_;
     /// Shader type.
     /// Shader type.
     ShaderType type_;
     ShaderType type_;
-    /// Full shader name.
+    /// Shader name.
     String name_;
     String name_;
     /// Defines to use in compiling.
     /// Defines to use in compiling.
     String defines_;
     String defines_;
+	/// Full shader name.
+	String fullName_;
     /// Shader compile error string.
     /// Shader compile error string.
     String compilerOutput_;
     String compilerOutput_;
     /// Shader parameters.
     /// Shader parameters.

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

@@ -1027,10 +1027,10 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
             
             
             bool success = vs->Create();
             bool success = vs->Create();
             if (success)
             if (success)
-                LOGDEBUG("Compiled vertex shader " + vs->GetName());
+                LOGDEBUG("Compiled vertex shader " + vs->GetFullName());
             else
             else
             {
             {
-                LOGERROR("Failed to compile vertex shader " + vs->GetName() + ":\n" + vs->GetCompilerOutput());
+                LOGERROR("Failed to compile vertex shader " + vs->GetFullName() + ":\n" + vs->GetCompilerOutput());
                 vs = 0;
                 vs = 0;
             }
             }
         }
         }
@@ -1046,10 +1046,10 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
             
             
             bool success = ps->Create();
             bool success = ps->Create();
             if (success)
             if (success)
-                LOGDEBUG("Compiled pixel shader " + ps->GetName());
+                LOGDEBUG("Compiled pixel shader " + ps->GetFullName());
             else
             else
             {
             {
-                LOGERROR("Failed to compile pixel shader " + ps->GetName() + ":\n" + ps->GetCompilerOutput());
+                LOGERROR("Failed to compile pixel shader " + ps->GetFullName() + ":\n" + ps->GetCompilerOutput());
                 ps = 0;
                 ps = 0;
             }
             }
         }
         }
@@ -1094,14 +1094,14 @@ void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
             SharedPtr<ShaderProgram> newProgram(new ShaderProgram(this, vs, ps));
             SharedPtr<ShaderProgram> newProgram(new ShaderProgram(this, vs, ps));
             if (newProgram->Link())
             if (newProgram->Link())
             {
             {
-                LOGDEBUG("Linked vertex shader " + vs->GetName() + " and pixel shader " + ps->GetName());
+                LOGDEBUG("Linked vertex shader " + vs->GetFullName() + " and pixel shader " + ps->GetFullName());
                 // Note: Link() calls glUseProgram() to set the texture sampler uniforms,
                 // Note: Link() calls glUseProgram() to set the texture sampler uniforms,
                 // so it is not necessary to call it again
                 // so it is not necessary to call it again
                 shaderProgram_ = newProgram;
                 shaderProgram_ = newProgram;
             }
             }
             else
             else
             {
             {
-                LOGERROR("Failed to link vertex shader " + vs->GetName() + " and pixel shader " + ps->GetName() + ":\n" +
+                LOGERROR("Failed to link vertex shader " + vs->GetFullName() + " and pixel shader " + ps->GetFullName() + ":\n" +
                     newProgram->GetLinkerOutput());
                     newProgram->GetLinkerOutput());
                 glUseProgram(0);
                 glUseProgram(0);
                 shaderProgram_ = 0;
                 shaderProgram_ = 0;

+ 6 - 2
Source/Engine/Graphics/OpenGL/OGLShaderVariation.cpp

@@ -119,7 +119,7 @@ bool ShaderVariation::Create()
         #ifdef _DEBUG
         #ifdef _DEBUG
         String defineCheck = defineString.Substring(8, defineString.Find(' ', 8) - 8);
         String defineCheck = defineString.Substring(8, defineString.Find(' ', 8) - 8);
         if (originalShaderCode.Find(defineCheck) == String::NPOS)
         if (originalShaderCode.Find(defineCheck) == String::NPOS)
-            LOGWARNING("Shader " + GetName() + " does not use the define " + defineCheck);
+            LOGWARNING("Shader " + GetFullName() + " does not use the define " + defineCheck);
         #endif
         #endif
     }
     }
     
     
@@ -153,12 +153,16 @@ bool ShaderVariation::Create()
 
 
 void ShaderVariation::SetName(const String& name)
 void ShaderVariation::SetName(const String& name)
 {
 {
-    name_ = name.Trimmed().Replaced(' ', '_');
+    name_ = name;
+	// Set full name
+	fullName_ = name_ + "(" + defines_ + ")";
 }
 }
 
 
 void ShaderVariation::SetDefines(const String& defines)
 void ShaderVariation::SetDefines(const String& defines)
 {
 {
     defines_ = defines;
     defines_ = defines;
+	// Set full name
+	fullName_ = name_ + "(" + defines_ + ")";
 }
 }
 
 
 Shader* ShaderVariation::GetOwner() const
 Shader* ShaderVariation::GetOwner() const

+ 6 - 2
Source/Engine/Graphics/OpenGL/OGLShaderVariation.h

@@ -58,10 +58,12 @@ public:
     Shader* GetOwner() const;
     Shader* GetOwner() const;
     /// Return shader type.
     /// Return shader type.
     ShaderType GetShaderType() const { return type_; }
     ShaderType GetShaderType() const { return type_; }
-    /// Return full shader name.
+    /// Return name.
     const String& GetName() const { return name_; }
     const String& GetName() const { return name_; }
     /// Return defines.
     /// Return defines.
     const String& GetDefines() const { return defines_; }
     const String& GetDefines() const { return defines_; }
+	/// Return full shader name.
+	const String& GetFullName() const { return fullName_; }
     /// Return compile error/warning string.
     /// Return compile error/warning string.
     const String& GetCompilerOutput() const { return compilerOutput_; }
     const String& GetCompilerOutput() const { return compilerOutput_; }
     
     
@@ -70,10 +72,12 @@ private:
     WeakPtr<Shader> owner_;
     WeakPtr<Shader> owner_;
     /// Shader type.
     /// Shader type.
     ShaderType type_;
     ShaderType type_;
-    /// Full shader name.
+    /// Shader name.
     String name_;
     String name_;
     /// Defines to use in compiling.
     /// Defines to use in compiling.
     String defines_;
     String defines_;
+	/// Full shader anme.
+	String fullName_;
     /// Shader compile error string.
     /// Shader compile error string.
     String compilerOutput_;
     String compilerOutput_;
 };
 };

+ 2 - 2
Source/Engine/Graphics/Shader.cpp

@@ -147,7 +147,7 @@ ShaderVariation* Shader::GetVariation(ShaderType type, const char* defines)
                 if (definesHash != normalizedHash)
                 if (definesHash != normalizedHash)
                     vsVariations_.Insert(MakePair(definesHash, i->second_));
                     vsVariations_.Insert(MakePair(definesHash, i->second_));
                 
                 
-                i->second_->SetName(GetFileName(GetName()) + " " + normalizedDefines);
+                i->second_->SetName(GetFileName(GetName()));
                 i->second_->SetDefines(normalizedDefines);
                 i->second_->SetDefines(normalizedDefines);
                 ++numVariations_;
                 ++numVariations_;
                 RefreshMemoryUse();
                 RefreshMemoryUse();
@@ -173,7 +173,7 @@ ShaderVariation* Shader::GetVariation(ShaderType type, const char* defines)
                 if (definesHash != normalizedHash)
                 if (definesHash != normalizedHash)
                     psVariations_.Insert(MakePair(definesHash, i->second_));
                     psVariations_.Insert(MakePair(definesHash, i->second_));
                 
                 
-                i->second_->SetName(GetFileName(GetName()) + " " + normalizedDefines);
+                i->second_->SetName(GetFileName(GetName()));
                 i->second_->SetDefines(normalizedDefines);
                 i->second_->SetDefines(normalizedDefines);
                 ++numVariations_;
                 ++numVariations_;
                 RefreshMemoryUse();
                 RefreshMemoryUse();

+ 2 - 2
Source/Engine/Graphics/ShaderPrecache.cpp

@@ -84,8 +84,8 @@ void ShaderPrecache::StoreShaders(ShaderVariation* vs, ShaderVariation* ps)
         return;
         return;
     usedPtrCombinations_.Insert(shaderPair);
     usedPtrCombinations_.Insert(shaderPair);
     
     
-    String vsName = vs->GetName().Substring(0, vs->GetName().Find('_'));
-    String psName = ps->GetName().Substring(0, ps->GetName().Find('_'));
+    String vsName = vs->GetName();
+    String psName = ps->GetName();
     const String& vsDefines = vs->GetDefines();
     const String& vsDefines = vs->GetDefines();
     const String& psDefines = ps->GetDefines();
     const String& psDefines = ps->GetDefines();