当前位置: 首页>>代码示例>>C#>>正文


C# CompilationContext.GetOutputPath方法代码示例

本文整理汇总了C#中CompilationContext.GetOutputPath方法的典型用法代码示例。如果您正苦于以下问题:C# CompilationContext.GetOutputPath方法的具体用法?C# CompilationContext.GetOutputPath怎么用?C# CompilationContext.GetOutputPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CompilationContext的用法示例。


在下文中一共展示了CompilationContext.GetOutputPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

        public void Compile(CompilationContext context, string inputPath, string outputPath, Database.ContentEntry contentData)
        {
            outputPath += ".mat";

            Material material;
            using (var nodeGraphPanel = new NodeGraphPanel())
            {
                nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeFloat());
                nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeVector3());
                nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeVector4());

                nodeGraphPanel.LoadCurrentViewPure(inputPath);

                RootNode root = null;
                foreach (var node in nodeGraphPanel.View.NodeCollection)
                {
                    if (node is RootNode)
                    {
                        root = node as RootNode;
                        break;
                    }
                }

                var result = root.Process(0) as BuildShaderData;

                material = new Material();
                material.ShaderSource = result.Value;
                material.Defines = result.Defines;
                material.Samplers = new Dictionary<string, string>(Context.Samplers);
            }

            var murmur128 = MurmurHash.Create128(managed: false);
            var shader = Encoding.UTF8.GetBytes(material.ShaderSource);
            var hash = murmur128.ComputeHash(shader);

            var shaderName = BitConverter.ToString(hash).ToLowerInvariant().Replace("-", "");
            var shaderPath = "generated/shaders/" + shaderName;
            var shaderOutputPath = context.GetOutputPath(shaderPath + ".glsl");

            var template = context.GetShaderTemplate();
            material.ShaderSource = template.Replace("//__MATERIAL__PLACEHOLDER__", material.ShaderSource);
            if (material.Defines.Count > 0)
                material.ShaderSource = material.Defines.Select(d => "#define " + d).Aggregate((a, b) => a + "\n" + b) + "\n" + material.ShaderSource;

            using (var stream = context.OpenOutput(shaderPath + ".glsl"))
            using (var writer = new StreamWriter(stream))
            {
                writer.Write(material.ShaderSource);
            }

            using (var stream = File.Open(outputPath, FileMode.Create))
            using (var writer = new BinaryWriter(stream))
            {
                // Magic
                writer.Write('M');
                writer.Write('A');
                writer.Write('T');
                writer.Write('E');

                // Version
                writer.Write(Version);

                // Shader reference
                writer.Write("/shaders/" + shaderName);

                // Samplers
                writer.Write(material.Samplers.Count);

                foreach (var sampler in material.Samplers)
                {
                    writer.Write(sampler.Key);
                    writer.Write(sampler.Value);
                }
            }
        }
开发者ID:johang88,项目名称:triton,代码行数:75,代码来源:MaterialCompiler.cs


注:本文中的CompilationContext.GetOutputPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。