public ShaderBuilder(string path, string source, ShaderBuilderManager manager = null) : this(path) { if (source == null) throw new ArgumentNullException("source"); this.source = source; Construct(manager); }
public ShaderBuilder(string path, string source, ShaderBuilderManager manager = null) : this(path) { if (source == null) { throw new ArgumentNullException("source"); } this.source = source; Construct(manager); }
public ShaderBuilder(string path, Stream source, ShaderBuilderManager manager = null, bool closeSource = false) : this(path) { if (source == null) throw new ArgumentNullException("source"); this.source = new StreamReader(source).ReadToEnd(); if (closeSource) source.Close(); Construct(manager); }
public ShaderBuilder(string path, Stream source, ShaderBuilderManager manager = null, bool closeSource = false) : this(path) { if (source == null) { throw new ArgumentNullException("source"); } this.source = new StreamReader(source).ReadToEnd(); if (closeSource) { source.Close(); } Construct(manager); }
public ShaderBuilder(string path, Assembly assembly, ShaderBuilderManager manager = null) : this(path) { if (assembly == null) throw new ArgumentNullException("assembly"); using (var stream = assembly.GetManifestResourceStream(path)) { if (stream == null) { var names = assembly.GetManifestResourceNames(); throw new ArgumentException(string.Format("Path '{0}' does not appear as a manifest resource for assembly {1}, or is not accessible; the valid names are: {2}.", path, assembly.FullName, string.Join(", ", names))); } this.source = new StreamReader(stream).ReadToEnd(); } Construct(manager); }
public ShaderBuilder(string path, Assembly assembly, ShaderBuilderManager manager = null) : this(path) { if (assembly == null) { throw new ArgumentNullException("assembly"); } using (var stream = assembly.GetManifestResourceStream(path)) { if (stream == null) { var names = assembly.GetManifestResourceNames(); throw new ArgumentException(string.Format("Path '{0}' does not appear as a manifest resource for assembly {1}, or is not accessible; the valid names are: {2}.", path, assembly.FullName, string.Join(", ", names))); } this.source = new StreamReader(stream).ReadToEnd(); } Construct(manager); }
public ShaderBuilder(string path, ShaderBuilderManager manager = null) : this(path) { source = File.ReadAllText(path); Construct(manager ?? new FileManager()); }
void Split(string path, string source, ShaderBuilderManager manager, string lastSection, int lastSectionLine) { sources.Add(path); int sourceIndex = sources.Count - 1; string[] split = source.Split(new string[] { "::" }, StringSplitOptions.None); int line = CountNewlines(split[0]) + 1; AddToSection(lastSection, sourceIndex, 1, split[0]); for (int index = 1; index < split.Length; index += 2) { string fullName = split[index]; string name = fullName.Trim(); if (name.StartsWith("#")) { name = name.Substring(1).Trim(); string command; int commandSplit; for (commandSplit = 0; commandSplit < name.Length; commandSplit++) if (char.IsWhiteSpace(name[commandSplit])) break; command = name.Substring(0, commandSplit); name = name.Substring(commandSplit).Trim(); switch (command) { case "include": bool local = false; string end; if (name.StartsWith("\"")) { local = true; end = "\""; } else if (name.StartsWith("<")) end = ">"; else throw new InvalidOperationException(ErrorString(path, line, "Expected '\"' or '<' and '>' to surround the filename for the include.")); if (!name.EndsWith(end)) throw new InvalidOperationException(ErrorString(path, line, "Expected '{0}' after the file name.", end)); name = name.Substring(1, name.Length - 2); if (manager == null) throw new ArgumentNullException("manager", ErrorString(path, line, "Include cannot be used while manager is null.")); string includePath = manager.IncludePath(sources[0], path, name, local); string includeSource = manager.Include(sources[0], path, name, local); Split(includePath, includeSource, manager, lastSection, lastSectionLine); break; case "version": VersionCode = name; break; default: throw new InvalidOperationException(ErrorString(path, line, "There is no command named '" + command + "'.")); } } else lastSection = name; if (index < split.Length - 1) { string content = split[index + 1]; line += CountNewlines(fullName); AddToSection(lastSection, sourceIndex, line, content); line += CountNewlines(content); lastSection = name; lastSectionLine = line; } } }
void Construct(ShaderBuilderManager manager) { Split(path, source, manager, "Common", 1); }
public static ShaderBuilder CreateFromAssemblyResource(string path, ShaderBuilderManager manager = null) { return new ShaderBuilder(path, Assembly.GetCallingAssembly(), manager); }
void Split(string path, string source, ShaderBuilderManager manager, string lastSection, int lastSectionLine) { sources.Add(path); int sourceIndex = sources.Count - 1; string[] split = source.Split(new string[] { "::" }, StringSplitOptions.None); int line = CountNewlines(split[0]) + 1; AddToSection(lastSection, sourceIndex, 1, split[0]); for (int index = 1; index < split.Length; index += 2) { string fullName = split[index]; string name = fullName.Trim(); if (name.StartsWith("#")) { name = name.Substring(1).Trim(); string command; int commandSplit; for (commandSplit = 0; commandSplit < name.Length; commandSplit++) { if (char.IsWhiteSpace(name[commandSplit])) { break; } } command = name.Substring(0, commandSplit); name = name.Substring(commandSplit).Trim(); switch (command) { case "include": bool local = false; string end; if (name.StartsWith("\"")) { local = true; end = "\""; } else if (name.StartsWith("<")) { end = ">"; } else { throw new InvalidOperationException(ErrorString(path, line, "Expected '\"' or '<' and '>' to surround the filename for the include.")); } if (!name.EndsWith(end)) { throw new InvalidOperationException(ErrorString(path, line, "Expected '{0}' after the file name.", end)); } name = name.Substring(1, name.Length - 2); if (manager == null) { throw new ArgumentNullException("manager", ErrorString(path, line, "Include cannot be used while manager is null.")); } string includePath = manager.IncludePath(sources[0], path, name, local); string includeSource = manager.Include(sources[0], path, name, local); Split(includePath, includeSource, manager, lastSection, lastSectionLine); break; case "version": VersionCode = name; break; default: throw new InvalidOperationException(ErrorString(path, line, "There is no command named '" + command + "'.")); } } else { lastSection = name; } if (index < split.Length - 1) { string content = split[index + 1]; line += CountNewlines(fullName); AddToSection(lastSection, sourceIndex, line, content); line += CountNewlines(content); lastSection = name; lastSectionLine = line; } } }
public static ShaderBuilder CreateFromAssemblyResource(string path, ShaderBuilderManager manager = null) { return(new ShaderBuilder(path, Assembly.GetCallingAssembly(), manager)); }