Compiler* CompilerFactory::CreateCompilerCopy(Compiler* compiler, const wxString& newName) { if (!compiler) return nullptr; // abort if an existing compiler with the same name exists // this also avoids the possibility of throwing an exception // in the compiler->CreateCopy() call below... for (size_t i = 0; i < Compilers.GetCount(); ++i) { if (Compilers[i]->GetName() == newName) return nullptr; } Compiler* newC = compiler->CreateCopy(); if (!newName.IsEmpty()) { Compiler::m_CompilerIDs.Remove(newC->GetID()); newC->SetName(newName); newC->m_ID = newName; newC->MakeValidID(); } newC->ReloadOptions(); RegisterCompiler(newC); newC->LoadSettings(_T("/user_sets")); Manager::Get()->GetLogManager()->DebugLog(F(_T("Added compiler \"%s\""), newC->GetName().wx_str())); return newC; // return the index for the new compiler }
bool csShaderManager::Initialize(iObjectRegistry *objreg) { objectreg = objreg; vc = csQueryRegistry<iVirtualClock> (objectreg); txtmgr = csQueryRegistry<iTextureManager> (objectreg); csRef<iVerbosityManager> verbosemgr ( csQueryRegistry<iVerbosityManager> (objectreg)); if (verbosemgr) do_verbose = verbosemgr->Enabled ("renderer.shader"); else do_verbose = false; Frame = csevFrame(objectreg); SystemOpen = csevSystemOpen(objectreg); SystemClose = csevSystemClose(objectreg); csRef<iEventHandlerRegistry> handlerReg = csQueryRegistry<iEventHandlerRegistry> (objectreg); //eventSucc[0] = handlerReg->GetGenericID ("crystalspace.graphics3d"); csRef<iEventQueue> q = csQueryRegistry<iEventQueue> (objectreg); if (q) { csEventID events[] = { Frame, SystemOpen, SystemClose, CS_EVENTLIST_END }; RegisterWeakListener (q, this, events, weakEventHandler); } csRef<iPluginManager> plugin_mgr = csQueryRegistry<iPluginManager> (objectreg); strings = csQueryRegistryTagInterface<iStringSet> ( objectreg, "crystalspace.shared.stringset"); stringsSvName = csQueryRegistryTagInterface<iShaderVarStringSet> ( objectreg, "crystalspace.shader.variablenameset"); { csRef<csNullShader> nullShader; nullShader.AttachNew (new csNullShader (this)); nullShader->SetName ("*null"); RegisterShader (nullShader); } config.AddConfig (objectreg, "/config/shadermgr.cfg"); csRef<iStringArray> classlist = iSCF::SCF->QueryClassList("crystalspace.graphics3d.shadercompiler."); size_t const nmatches = classlist.IsValid() ? classlist->GetSize() : 0; if (nmatches != 0) { size_t i; for (i = 0; i < nmatches; ++i) { const char* classname = classlist->Get(i); csRef<iShaderCompiler> plugin = csLoadPluginCheck<iShaderCompiler> (plugin_mgr, classname); if (plugin) { if (do_verbose) Report (CS_REPORTER_SEVERITY_NOTIFY, "Loaded compiler plugin %s, compiler: %s", classname,plugin->GetName()); RegisterCompiler(plugin); } } } else { Report (CS_REPORTER_SEVERITY_WARNING, "No shader plugins found!"); } csString cfgKey; const csString keyPrefix ("Video.ShaderManager.Tags."); csSet<csString> knownKeys; csRef<iConfigIterator> it (config->Enumerate (keyPrefix)); while (it->HasNext ()) { it->Next(); const char* key = it->GetKey (true); const char* dot = strrchr (key, '.'); cfgKey.Clear (); cfgKey.Append (key, dot - key); if (knownKeys.In ((const char*)cfgKey)) continue; knownKeys.Add ((const char*)cfgKey); const char* tagName = config->GetStr ( keyPrefix + cfgKey + ".TagName", cfgKey); const char* tagPresence = config->GetStr ( keyPrefix + cfgKey + ".Presence", "Neutral"); int tagPriority = config->GetInt ( keyPrefix + cfgKey + ".Priority", 0); csShaderTagPresence presence; if (strcasecmp (tagPresence, "neutral") == 0) { presence = TagNeutral; } else if (strcasecmp (tagPresence, "forbidden") == 0) { presence = TagForbidden; } else if (strcasecmp (tagPresence, "required") == 0) { presence = TagRequired; } else { Report (CS_REPORTER_SEVERITY_WARNING, "Unknown shader tag presence '%s' for tag config '%s'", tagPresence, (const char*)cfgKey); continue; } csStringID tagID = strings->Request (tagName); SetTagOptions (tagID, presence, tagPriority); } sv_time.AttachNew (new csShaderVariable (stringsSvName->Request ("standard time"))); sv_time->SetValue (0.0f); if (config->GetBool ("Video.ShaderManager.EnableShaderCache", false)) { bool redundantRemove = config->GetBool ("Video.ShaderManager.ShaderCache.RedundantRemove", true); shaderCache.AttachNew (new PlexHierarchicalCache (redundantRemove)); csRef<CS::Utility::VfsHierarchicalCache> cache; const char* cachePath; cachePath = config->GetStr ("Video.ShaderManager.ShaderCachePath.User", "/shadercache/user"); if (cachePath && *cachePath) { cache.AttachNew (new CS::Utility::VfsHierarchicalCache (objectreg, csString().Format ("%s/" CS_VERSION_MAJOR "." CS_VERSION_MINOR, cachePath))); shaderCache->AddSubShaderCache (cache, cachePriorityUser); } cachePath = config->GetStr ("Video.ShaderManager.ShaderCachePath.App", 0); if (cachePath && *cachePath) { cache.AttachNew (new CS::Utility::VfsHierarchicalCache (objectreg, cachePath)); cache->SetReadOnly (true); shaderCache->AddSubShaderCache (cache, cachePriorityApp); } cachePath = config->GetStr ("Video.ShaderManager.ShaderCachePath.Global", "/shadercache/global"); if (cachePath && *cachePath) { cache.AttachNew (new CS::Utility::VfsHierarchicalCache (objectreg, cachePath)); cache->SetReadOnly (true); shaderCache->AddSubShaderCache (cache, cachePriorityGlobal); } } return true; }