Vector Shader Builder. A utility to load Shader source code from a fragmented XML document. Shader source code can be compiled into working programs. See Specification for Format.
Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        public static ShaderLibrary Load(string filename)
        {
            XDocument document = XDocument.Load(filename);

            ShaderLibrary library = new ShaderLibrary();

            read_library(library, document.Root);

            return(library);
        }
Esempio n. 3
0
        public static ShaderLibrary Parse(string xml)
        {
            XDocument document = XDocument.Parse(xml);

            ShaderLibrary library = new ShaderLibrary();

            read_library(library, document.Root);

            return(library);
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        /// <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;
        }
Esempio n. 6
0
        public  static       ShaderLibrary Parse  (string xml)
        {
            XDocument document = XDocument.Parse(xml);

            ShaderLibrary library = new ShaderLibrary();

            read_library(library, document.Root);

            return library;
        }
Esempio n. 7
0
        public  static       ShaderLibrary Load   (string filename)
        {
            XDocument document = XDocument.Load(filename);

            ShaderLibrary library = new ShaderLibrary();

            read_library(library, document.Root);

            return library;
        }
Esempio n. 8
0
        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);
                }

               
            }
        }