/// <summary> /// Compiles Shaders related to this effect. /// </summary> /// <param name="device"></param> /// <returns></returns> public static List <Shader> CompileAll(Device device, ShaderLibrary library) { List <Shader> shaders = new List <Shader>(); foreach (Program program in library.Programs) { Shader shader = new Shader(device); if (program.VertexShader != null) { foreach (Source source in from n in program.VertexShader.Includes from m in library.Sources where n.Source == m.ID select m) { shader.AppendVertexSource(source.Code); } } if (program.GeometryShader != null) { shader.InputTopology = program.GeometryShader.InputTopology; shader.OutputTopology = program.GeometryShader.OutputTopology; shader.OutputVertexCount = program.GeometryShader.OutputVertexCount; foreach (Source source in from n in program.GeometryShader.Includes from m in library.Sources where n.Source == m.ID select m) { shader.AppendGeometrySource(source.Code); } } if (program.FragmentShader != null) { foreach (Source source in from n in program.FragmentShader.Includes from m in library.Sources where n.Source == m.ID select m) { shader.AppendFragmentSource(source.Code); } } ShaderCompileResult compileResult = shader.Compile(); if (!compileResult.HasError) { shaders.Add(shader); } else { throw new Exception(compileResult.Summary); } } return(shaders); }
public static ShaderLibrary Load(string filename) { XDocument document = XDocument.Load(filename); ShaderLibrary library = new ShaderLibrary(); read_library(library, document.Root); return(library); }
public static ShaderLibrary Parse(string xml) { XDocument document = XDocument.Parse(xml); ShaderLibrary library = new ShaderLibrary(); read_library(library, document.Root); return(library); }
private static void read_library(ShaderLibrary effect, XElement element) { foreach (XElement e in element.Elements()) { if (e.Name.LocalName.ToLower() == "source") { Source source = new Source(); read_source(source, e); effect.sources.Add(source); } if (e.Name.LocalName.ToLower() == "program") { Program program = new Program(); read_program(program, e); effect.programs.Add(program); } } }
/// <summary> /// Compiles Shaders related to this effect. /// </summary> /// <param name="device"></param> /// <returns></returns> public static List<Shader> CompileAll(Device device, ShaderLibrary library) { List<Shader> shaders = new List<Shader>(); foreach (Program program in library.Programs) { Shader shader = new Shader(device); if (program.VertexShader != null) { foreach (Source source in from n in program.VertexShader.Includes from m in library.Sources where n.Source == m.ID select m) shader.AppendVertexSource(source.Code); } if (program.GeometryShader != null) { shader.InputTopology = program.GeometryShader.InputTopology; shader.OutputTopology = program.GeometryShader.OutputTopology; shader.OutputVertexCount = program.GeometryShader.OutputVertexCount; foreach (Source source in from n in program.GeometryShader.Includes from m in library.Sources where n.Source == m.ID select m) shader.AppendGeometrySource(source.Code); } if (program.FragmentShader != null) { foreach (Source source in from n in program.FragmentShader.Includes from m in library.Sources where n.Source == m.ID select m) shader.AppendFragmentSource(source.Code); } ShaderCompileResult compileResult = shader.Compile(); if (!compileResult.HasError) { shaders.Add(shader); } else { throw new Exception(compileResult.Summary); } } return shaders; }
public static ShaderLibrary Parse (string xml) { XDocument document = XDocument.Parse(xml); ShaderLibrary library = new ShaderLibrary(); read_library(library, document.Root); return library; }
public static ShaderLibrary Load (string filename) { XDocument document = XDocument.Load(filename); ShaderLibrary library = new ShaderLibrary(); read_library(library, document.Root); return library; }
private static void read_library (ShaderLibrary effect, XElement element) { foreach(XElement e in element.Elements()) { if (e.Name.LocalName.ToLower() == "source") { Source source = new Source(); read_source(source, e); effect.sources.Add(source); } if (e.Name.LocalName.ToLower() == "program") { Program program = new Program(); read_program(program, e); effect.programs.Add(program); } } }