]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - plugins/shaders/shaders.cpp
Merge commit '48410b113dd2036e69dbf723a39ec9af02fc9b12'
[xonotic/netradiant.git] / plugins / shaders / shaders.cpp
index 3a7fae2d743316c7da5041a71134f78bee1f3f40..202a817f6596d0497389be58db1b5dde9c6f1d70 100644 (file)
@@ -1093,39 +1093,6 @@ public:
     }
 
     realiseLighting();
-
-    if(m_layers.size() == 1)
-    {
-      const BlendFuncExpression& blendFunc = m_template.m_layers.front().blendFunc();
-      if(!string_empty(blendFunc.second.c_str()))
-      {
-        m_blendFunc = BlendFunc(
-          evaluateBlendFactor(blendFunc.first.c_str(), m_template.m_params, m_args),
-          evaluateBlendFactor(blendFunc.second.c_str(), m_template.m_params, m_args)
-        );
-      }
-      else
-      {
-        const char* blend = evaluateShaderValue(blendFunc.first.c_str(), m_template.m_params, m_args);
-
-        if(string_equal_nocase(blend, "add"))
-        {
-          m_blendFunc = BlendFunc(BLEND_ONE, BLEND_ONE);
-        }
-        else if(string_equal_nocase(blend, "filter"))
-        {
-          m_blendFunc = BlendFunc(BLEND_DST_COLOUR, BLEND_ZERO);
-        }
-        else if(string_equal_nocase(blend, "blend"))
-        {
-          m_blendFunc = BlendFunc(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
-        }
-        else
-        {
-          globalErrorStream() << "parsing blend value failed: " << makeQuoted(blend) << "\n";
-        }
-      }
-    }
   }
 
   void unrealise()
@@ -1159,6 +1126,39 @@ public:
       {
         m_layers.push_back(evaluateLayer(*i, m_template.m_params, m_args));
       }
+
+      if(m_layers.size() == 1)
+      {
+        const BlendFuncExpression& blendFunc = m_template.m_layers.front().blendFunc();
+        if(!string_empty(blendFunc.second.c_str()))
+        {
+          m_blendFunc = BlendFunc(
+            evaluateBlendFactor(blendFunc.first.c_str(), m_template.m_params, m_args),
+            evaluateBlendFactor(blendFunc.second.c_str(), m_template.m_params, m_args)
+          );
+        }
+        else
+        {
+          const char* blend = evaluateShaderValue(blendFunc.first.c_str(), m_template.m_params, m_args);
+
+          if(string_equal_nocase(blend, "add"))
+          {
+            m_blendFunc = BlendFunc(BLEND_ONE, BLEND_ONE);
+          }
+          else if(string_equal_nocase(blend, "filter"))
+          {
+            m_blendFunc = BlendFunc(BLEND_DST_COLOUR, BLEND_ZERO);
+          }
+          else if(string_equal_nocase(blend, "blend"))
+          {
+            m_blendFunc = BlendFunc(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
+          }
+          else
+          {
+            globalErrorStream() << "parsing blend value failed: " << makeQuoted(blend) << "\n";
+          }
+        }
+      }
     }
   }
 
@@ -1177,6 +1177,8 @@ public:
         GlobalTexturesCache().release((*i).texture());
       }
       m_layers.clear();
+
+      m_blendFunc = BlendFunc(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
     }
   }
 
@@ -1697,11 +1699,15 @@ CShader* Try_Shader_ForName(const char* name)
       return (*i).second;
     }
   }
-
-  // not found, create it
+  // active shader was not found
+  
+  // find matching shader definition
   ShaderDefinitionMap::iterator i = g_shaderDefinitions.find(name);
   if(i == g_shaderDefinitions.end())
   {
+    // shader definition was not found
+
+    // create new shader definition from default shader template
     ShaderTemplatePointer shaderTemplate(new ShaderTemplate());
     shaderTemplate->CreateDefault(name);
     g_shaderTemplates.insert(ShaderTemplateMap::value_type(shaderTemplate->getName(), shaderTemplate));
@@ -1709,6 +1715,7 @@ CShader* Try_Shader_ForName(const char* name)
     i = g_shaderDefinitions.insert(ShaderDefinitionMap::value_type(name, ShaderDefinition(shaderTemplate.get(), ShaderArguments(), ""))).first;
   }
 
+  // create shader from existing definition
   ShaderPointer pShader(new CShader((*i).second));
   pShader->setName(name);
   g_ActiveShaders.insert(shaders_t::value_type(name, pShader));
@@ -1761,9 +1768,9 @@ void IfFound_dumpUnreferencedShader(bool& bFound, const char* filename)
     if(!bFound)
     {
       bFound = true;
-      globalOutputStream() << "Following shader files are not referenced in shaderlist.txt:\n";
+      globalOutputStream() << "Following shader files are not referenced in any shaderlist.txt:\n";
     }
-    globalOutputStream() << filename << "\n";
+    globalOutputStream() << "\t" << filename << "\n";
   }
 }
 typedef ReferenceCaller1<bool, const char*, IfFound_dumpUnreferencedShader> IfFoundDumpUnreferencedShaderCaller;
@@ -1833,6 +1840,30 @@ void FreeShaderList()
   }
 }
 
+void ShaderList_addFromArchive(const char *archivename)
+{
+  const char *shaderpath = GlobalRadiant().getGameDescriptionKeyValue("shaderpath");
+  if (string_empty(shaderpath))
+    return;
+
+  StringOutputStream shaderlist(256);
+  shaderlist << DirectoryCleaned(shaderpath) << "shaderlist.txt";
+
+  Archive *archive = GlobalFileSystem().getArchive(archivename, false);
+  if (archive)
+  {
+    ArchiveTextFile *file = archive->openTextFile(shaderlist.c_str());
+    if (file)
+    {
+      globalOutputStream() << "Found shaderlist.txt in " << archivename << "\n";
+      BuildShaderList(file->getInputStream());
+      file->release();
+    }
+  }
+}
+
+typedef FreeCaller1<const char *, ShaderList_addFromArchive> AddShaderListFromArchiveCaller;
+
 #include "stream/filestream.h"
 
 bool shaderlist_findOrInstall(const char* enginePath, const char* toolsPath, const char* shaderPath, const char* gamename)
@@ -1891,22 +1922,8 @@ void Shaders_Load()
         shaderlist_findOrInstall(enginePath, toolsPath, path.c_str(), gamename);
       }
 
-      StringOutputStream absShaderList(256);
-      absShaderList << enginePath << gamename << '/' << path.c_str() << "shaderlist.txt";
-
-      {
-        globalOutputStream() << "Parsing shader files from " << absShaderList.c_str() << "\n";
-        TextFileInputStream shaderlistFile(absShaderList.c_str());
-        if(shaderlistFile.failed())
-        {
-          globalErrorStream() << "Couldn't find '" << absShaderList.c_str() << "'\n";
-        }
-        else
-        {
-          BuildShaderList(shaderlistFile);
-          DumpUnreferencedShaders();
-        }
-      }
+      GlobalFileSystem().forEachArchive(AddShaderListFromArchiveCaller(), false, true);
+      DumpUnreferencedShaders();
     }
     else
     {