示例#1
0
		static public ShaderInfo PureGLSLFromString (string effectSource, string filePath, Options options, IEffectCompilerOutput output)
		{

			ShaderInfo shaderInfo = new ShaderInfo ();
			shaderInfo.FilePath = options.SourceFile;
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (effectSource);
			XmlElement effectElement;
			XmlNode current = doc.FirstChild;
			while (current != null && current.NodeType != XmlNodeType.Element) {
				current = current.NextSibling;
			}
			effectElement = (XmlElement)current;
			shaderInfo.Techniques = new List<TechniqueInfo> ();
			foreach (XmlElement technique in effectElement.ChildNodes.OfType<XmlElement>()) {
				TechniqueInfo info = new TechniqueInfo ();
				info.name = technique.GetAttribute ("name");
				info.Passes = new List<PassInfo> ();
				foreach (XmlElement pass in technique.ChildNodes.OfType<XmlElement>()) {
					PassInfo pi = new PassInfo ();
					pi.name = pass.GetAttribute ("name");
					foreach (XmlElement sh in pass.ChildNodes) {
						if (sh.Name == "Shader") {
							if (sh.GetAttribute ("type") == "PixelShader") {
								pi.psFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(shaderInfo.FilePath),sh.GetAttribute ("filename"));
								shaderInfo.Dependencies.Add (pi.psFileName);
								pi.psShaderXML = sh.OuterXml;
							} else if (sh.GetAttribute ("type") == "VertexShader") {
								pi.vsFilename = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(shaderInfo.FilePath),sh.GetAttribute ("filename"));
								shaderInfo.Dependencies.Add (pi.vsFilename);
								pi.vsShaderXML = sh.OuterXml;
							} else {
								throw new PipelineException ("Unsupported Shader type detected");
							}
						} else if (sh.Name == "BlendState") {
							pi.blendState = ParseBlendState (sh);

						} else if (sh.Name == "DepthStencilState") {
							pi.depthStencilState = ParseDepthStencilState (sh);
						} else if (sh.Name == "RasterizerState") {
							pi.rasterizerState = ParseRasterizerState (sh);
						} else {
							throw new PipelineException ("'" + sh.Name + "' element not recognized");
						}
					}
					info.Passes.Add (pi);
				}
				shaderInfo.Techniques.Add (info);
			}

			shaderInfo.Profile = options.Profile;
			shaderInfo.Debug = options.Debug;

			shaderInfo.OutputFilePath = options.OutputFile;

			return shaderInfo;
		}
示例#2
0
        static public ShaderInfo PureGLSLFromString(string effectSource, string filePath, Options options, IEffectCompilerOutput output)
        {
            ShaderInfo shaderInfo = new ShaderInfo();

            shaderInfo.FilePath = options.SourceFile;
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(effectSource);
            XmlElement effectElement;
            XmlNode    current = doc.FirstChild;

            while (current != null && current.NodeType != XmlNodeType.Element)
            {
                current = current.NextSibling;
            }
            effectElement         = (XmlElement)current;
            shaderInfo.Techniques = new List <TechniqueInfo> ();
            foreach (XmlElement technique in effectElement.ChildNodes.OfType <XmlElement>())
            {
                TechniqueInfo info = new TechniqueInfo();
                info.name   = technique.GetAttribute("name");
                info.Passes = new List <PassInfo> ();
                foreach (XmlElement pass in technique.ChildNodes.OfType <XmlElement>())
                {
                    PassInfo pi = new PassInfo();
                    pi.name = pass.GetAttribute("name");
                    foreach (XmlElement sh in pass.ChildNodes)
                    {
                        if (sh.Name == "Shader")
                        {
                            if (sh.GetAttribute("type") == "PixelShader")
                            {
                                pi.psFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(shaderInfo.FilePath), sh.GetAttribute("filename"));
                                shaderInfo.Dependencies.Add(pi.psFileName);
                                pi.psShaderXML = sh.OuterXml;
                            }
                            else if (sh.GetAttribute("type") == "VertexShader")
                            {
                                pi.vsFilename = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(shaderInfo.FilePath), sh.GetAttribute("filename"));
                                shaderInfo.Dependencies.Add(pi.vsFilename);
                                pi.vsShaderXML = sh.OuterXml;
                            }
                            else
                            {
                                throw new PipelineException("Unsupported Shader type detected");
                            }
                        }
                        else if (sh.Name == "BlendState")
                        {
                            pi.blendState = ParseBlendState(sh);
                        }
                        else if (sh.Name == "DepthStencilState")
                        {
                            pi.depthStencilState = ParseDepthStencilState(sh);
                        }
                        else if (sh.Name == "RasterizerState")
                        {
                            pi.rasterizerState = ParseRasterizerState(sh);
                        }
                        else
                        {
                            throw new PipelineException("'" + sh.Name + "' element not recognized");
                        }
                    }
                    info.Passes.Add(pi);
                }
                shaderInfo.Techniques.Add(info);
            }

            shaderInfo.Profile = options.Profile;
            shaderInfo.Debug   = options.Debug;

            shaderInfo.OutputFilePath = options.OutputFile;

            return(shaderInfo);
        }