Example #1
0
        public CodeCompileUnit InitialiseCompileUnit(GLSLAssembly assembly)
        {
            var contentUnit = new CodeCompileUnit();

            SetVersionNumber(contentUnit, assembly.Version);
            string nameSpace = assembly.Namespace;

            if (string.IsNullOrWhiteSpace(nameSpace))
            {
                nameSpace = System.IO.Path.GetFileNameWithoutExtension(assembly.OutputAssembly);
            }
            var contentNs = new CodeNamespace(nameSpace);

            contentUnit.Namespaces.Add(contentNs);
            var uniforms           = CreateClass(contentNs, "Uniforms");
            var defaultConstructor = new CodeTypeConstructor();

            defaultConstructor.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            uniforms.Members.Add(defaultConstructor);
            defaultConstructor.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), "testInt", new CodePrimitiveExpression(0)));
            foreach (var block in mExtractor.Blocks)
            {
                AddStruct(contentNs, uniforms, block);
            }
            return(contentUnit);
        }
Example #2
0
        public void SaveAsCode(CodeDomProvider provider, GLSLAssembly assembly, IGLSLUniformExtractor extractor, CodeGeneratorOptions options)
        {
            string outputFile   = System.IO.Path.GetFileNameWithoutExtension(assembly.OutputAssembly) + ".cs";
            string absolutePath = System.IO.Path.Combine(assembly.Path, outputFile);

            using (var fs = File.OpenWrite(absolutePath))
                using (var writer = new StreamWriter(fs))
                {
                    var contentUnit = InitialiseCompileUnit(assembly);


                    provider.GenerateCodeFromCompileUnit(contentUnit, writer, options);
                }
        }
Example #3
0
        public void SaveAsAssembly(CodeDomProvider provider, GLSLAssembly assembly)
        {
            // Build the parameters for source compilation.
            var cp = new CompilerParameters();

            // Add an assembly reference.
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Runtime.InteropServices.dll");

            if (assembly.ReferencedAssemblies != null)
            {
                foreach (var assemblyName in assembly.ReferencedAssemblies)
                {
                    cp.ReferencedAssemblies.Add(assemblyName);
                }
            }

            // Generate an executable instead of
            // a class library.
            cp.GenerateExecutable = false;

            // Set the assembly file name to generate.
            cp.OutputAssembly = System.IO.Path.Combine(assembly.Path, assembly.OutputAssembly);

            // Save the assembly as a physical file.
            cp.GenerateInMemory = false;

            var contentUnit = InitialiseCompileUnit(assembly);

            // Invoke compilation.
            CompilerResults cr = provider.CompileAssemblyFromDom(cp, contentUnit);

            if (cr.Errors.Count > 0)
            {
                Debug.WriteLine(string.Format("Source built into {0} unsuccessfully.", cr.PathToAssembly));
                // Display compilation errors.
                foreach (CompilerError ce in cr.Errors)
                {
                    Debug.WriteLine("  {0}", ce.ToString());
                }
            }
            else
            {
                Debug.WriteLine(string.Format("Source built into {0} successfully.", cr.PathToAssembly));
            }
        }
        public void SaveAsAssembly(CodeDomProvider provider, GLSLAssembly assembly)
        {
            // Build the parameters for source compilation.
            var cp = new CompilerParameters();

            // Add an assembly reference.
            cp.ReferencedAssemblies.Add( "System.dll" );
            cp.ReferencedAssemblies.Add ("System.Runtime.InteropServices.dll");

            if (assembly.ReferencedAssemblies != null)
            {
                foreach (var assemblyName in assembly.ReferencedAssemblies)
                {
                    cp.ReferencedAssemblies.Add( assemblyName );
                }
            }

            // Generate an executable instead of
            // a class library.
            cp.GenerateExecutable = false;

            // Set the assembly file name to generate.
            cp.OutputAssembly = System.IO.Path.Combine(assembly.Path,assembly.OutputAssembly);

            // Save the assembly as a physical file.
            cp.GenerateInMemory = false;

            var contentUnit = InitialiseCompileUnit (assembly);

            // Invoke compilation.
            CompilerResults cr = provider.CompileAssemblyFromDom(cp, contentUnit);

            if (cr.Errors.Count > 0)
            {
                Debug.WriteLine(string.Format("Source built into {0} unsuccessfully.", cr.PathToAssembly));
                // Display compilation errors.
                foreach (CompilerError ce in cr.Errors)
                {
                    Debug.WriteLine("  {0}", ce.ToString());
                }
            }
            else
            {
                Debug.WriteLine(string.Format("Source built into {0} successfully.", cr.PathToAssembly));
            }
        }
 public CodeCompileUnit InitialiseCompileUnit(GLSLAssembly assembly)
 {
     var contentUnit = new CodeCompileUnit ();
     SetVersionNumber (contentUnit, assembly.Version);
     string nameSpace = assembly.Namespace;
     if (string.IsNullOrWhiteSpace (nameSpace))
     {
         nameSpace = System.IO.Path.GetFileNameWithoutExtension (assembly.OutputAssembly);
     }
     var contentNs = new CodeNamespace (nameSpace);
     contentUnit.Namespaces.Add (contentNs);
     var uniforms = CreateClass (contentNs, "Uniforms");
     var defaultConstructor = new CodeTypeConstructor ();
     defaultConstructor.Attributes = MemberAttributes.Public | MemberAttributes.Final;
     uniforms.Members.Add (defaultConstructor);
     defaultConstructor.Statements.Add (new CodeVariableDeclarationStatement (typeof(int), "testInt", new CodePrimitiveExpression (0)));
     foreach (var block in mExtractor.Blocks)
     {
         AddStruct (contentNs, uniforms, block);
     }
     return contentUnit;
 }
Example #6
0
        public static int Main(string[] args)
        {
            //			try
            //			{
                if (args.Length < 2)
                {
                    Console.WriteLine("Invalid arguments");
                    Console.WriteLine("{0} {1} {n}... ");
                    Console.WriteLine("{0} = output file");
                    Console.WriteLine("{1} = glsl shader file 1");
                    Console.WriteLine("{n} = glsl shader file n");
                    return 1;
                }

                foreach(var arg in args)
                {
                    Console.WriteLine(arg);
                }

                IGLSLTypeLookup lookup = new OpenTKTypeLookup ();
                lookup.Initialize ();
                var extractor = new GLSLUniformExtractor (lookup);
                extractor.Initialize ();

                var debug = new InfoSinkBase (SinkType.StdOut);
                var info = new InfoSinkBase (SinkType.StdOut);
                var infoSink = new InfoSink (info, debug);
                var preprocessor = InitialisePreprocessor (infoSink);

                for (int i = 1; i < args.Length; ++i)
                {
                    var fileName = args[i];
                    using (var fs = File.Open(fileName, FileMode.Open))
                    {
                        var stage = Standalone.FindLanguage(fileName);
                        string result;
                        preprocessor.Run(fs, stage, out result);

                        int actual = extractor.Extract (result);
                        Console.WriteLine("{0} - no of blocks extracted : {1}", fileName, actual);
                    }
                }

                GLSLAssembly output = new GLSLAssembly ();
                output.OutputAssembly = System.IO.Path.GetFileName(args[0]);
                output.Version = "1.0.0.1";
                output.Namespace = "";
                output.Path = System.IO.Path.GetPathRoot(args[0]);
                output.ReferencedAssemblies = new string[]{"OpenTK.dll"};

                IGLSLStructGenerator generator = new GLSLStructGenerator(extractor);
                using (var provider = new CSharpCodeProvider ())
                {
                    //generator.SaveAsAssembly (provider, output);
                    var options = new CodeGeneratorOptions();
                    options.BlankLinesBetweenMembers = true;
                    generator.SaveAsCode(provider, output, extractor, options);
                }

                return 0;
            //			}
            //			catch (Exception ex)
            //			{
            //				Debug.WriteLine (ex.Message);
            //				return 1;
            //			}
            //	Test();
        }
        public void SaveAsCode(CodeDomProvider provider, GLSLAssembly assembly, IGLSLUniformExtractor extractor, CodeGeneratorOptions options)
        {
            string outputFile = System.IO.Path.GetFileNameWithoutExtension (assembly.OutputAssembly) + ".cs";
            string absolutePath = System.IO.Path.Combine(assembly.Path,outputFile);

            using (var fs = File.OpenWrite (absolutePath))
            using (var writer = new StreamWriter(fs))
            {
                var contentUnit = InitialiseCompileUnit (assembly);

                provider.GenerateCodeFromCompileUnit (contentUnit, writer, options);
            }
        }