3 using System.Collections.Generic;
5 using System.Net.Configuration;
8 using SiliconStudio.Core.IO;
9 using SiliconStudio.Core.Serialization.Assets;
10 using SiliconStudio.Core.Storage;
12 namespace SiliconStudio.
Paradox.Shaders.Parser.Mixins
19 private readonly
object locker =
new object();
20 private readonly Dictionary<string, ShaderSourceWithHash> loadedShaderSources =
new Dictionary<string, ShaderSourceWithHash>();
21 private readonly Dictionary<string, string> classNameToPath =
new Dictionary<string, string>();
23 private const string DefaultEffectFileExtension =
".pdxsl";
29 public List<string> LookupDirectoryList {
get; set; }
35 public Dictionary<string, string> UrlToFilePath {
get; set; }
42 LookupDirectoryList =
new List<string>();
43 UrlToFilePath =
new Dictionary<string, string>();
52 foreach (var shaderName
in modifiedShaders)
54 loadedShaderSources.Remove(shaderName);
61 return LoadShaderSource(type).Hash;
77 if (!loadedShaderSources.TryGetValue(type, out shaderSource))
79 var sourceUrl = FindFilePath(type);
80 if (sourceUrl != null)
84 if (modifiedShaders != null && modifiedShaders.Contains(sourceUrl))
86 using (var fileStream = AssetManager.FileProvider.OpenStream(sourceUrl +
"/path", VirtualFileMode.Open, VirtualFileAccess.Read, VirtualFileShare.Read))
88 string shaderSourcePath;
90 shaderSourcePath = sr.ReadToEnd();
94 using (var sourceStream = File.Open(shaderSourcePath, FileMode.Open, FileAccess.Read))
97 shaderSource.Source = sr.ReadToEnd();
100 catch (FileNotFoundException)
102 throw new FileNotFoundException(
string.Format(
"Unable to find shader [{0}] on disk", type),
string.Format(
"{0}.pdxsl", type));
108 using (var fileStream = AssetManager.FileProvider.OpenStream(sourceUrl, VirtualFileMode.Open, VirtualFileAccess.Read, VirtualFileShare.Read))
111 shaderSource.Source = sr.ReadToEnd();
114 if (databaseStream != null)
116 shaderSource.Hash = databaseStream.ObjectId;
124 shaderSource.Hash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(shaderSource.Source));
129 UrlToFilePath.TryGetValue(sourceUrl, out shaderSource.Path);
132 if (shaderSource.Path == null)
134 shaderSource.Path = type;
136 loadedShaderSources[type] = shaderSource;
140 throw new FileNotFoundException(
string.Format(
"Unable to find shader [{0}]", type),
string.Format(
"{0}.pdxsl", type));
154 return FindFilePath(typeName) != null;
161 if (LookupDirectoryList == null)
165 if (classNameToPath.TryGetValue(type, out path))
168 foreach (var directory
in LookupDirectoryList)
170 var fileName = Path.ChangeExtension(type, DefaultEffectFileExtension);
171 var testPath = string.IsNullOrEmpty(directory) || directory ==
"/" || directory ==
"\\" ?
string.Format(
"/{0}", fileName) : string.Format(
"{0}/{1}", directory.TrimEnd(
'/'), fileName);
179 classNameToPath.Add(type, path);
System.Text.Encoding Encoding
override bool FileExists(string url)
Determines whether the specified path points to an existing file. The path.
static DatabaseFileProvider FileProvider
ObjectId GetShaderSourceHash(string type)
void DeleteObsoleteCache(HashSet< string > modifiedShaders)
Deletes the shader cache for the specified shaders.
static readonly ObjectId Empty
Class ShaderSourceManager
A hash to uniquely identify data.
ShaderSourceWithHash LoadShaderSource(string type, HashSet< string > modifiedShaders=null)
Loads the shader source with the specified type name.
ShaderSourceManager()
Initializes a new instance of the ShaderSourceManager class.
string FindFilePath(string type)
bool IsClassExists(string typeName)
Determines whether a class with the specified type name exists.