Beispiel #1
0
        public string FindMethodBlock(Type shader, MethodInfo method, CompilerOutputs outputType)
        {
            // find shaders namespace
            var match = Regex.Match(Code, shader.Namespace + @"\s*?\{(.*\})", RegexOptions.Singleline);

            if (match.Success && match.Groups.Count == 2)
            {
                // find shader class
                var namespaceBlock = match.Groups[1].Value;
                int end            = getBlockEnd(namespaceBlock);
                namespaceBlock = namespaceBlock.Remove(end);
                match          = Regex.Match(namespaceBlock, @"class\s*" + shader.Name + @".*?\{(.*\})", RegexOptions.Singleline);
                if (match.Success && match.Groups.Count == 2)
                {
                    // find method
                    var classBlock = match.Groups[1].Value;
                    end        = getBlockEnd(classBlock);
                    classBlock = classBlock.Remove(end);
                    match      = Regex.Match(classBlock, Compiler.convertToBasicType(method.ReturnType, outputType, false) + @"\s*" + method.Name + @".*?\{(.*\})", RegexOptions.Singleline);
                    if (match.Success && match.Groups.Count == 2)
                    {
                        var methodBlock = match.Groups[1].Value;
                        end         = getBlockEnd(methodBlock);
                        methodBlock = methodBlock.Remove(end);
                        return('{' + methodBlock + '}');
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        public void Compile(string outDirectory, CompilerOutputs outputType, bool compileMaterial, bool compileMetroShaders, bool compileSilverlightShaders)
        {
            this.outDirectory = outDirectory;
            this.outputType = outputType;

            // compile shader library
            /*var exeDir = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", "MSBuildToolsPath", "") as string;
            if (string.IsNullOrEmpty(exeDir)) throw new Exception("Cant find MSBuild for .NET 4.");

            var process = new System.Diagnostics.Process();
            process.StartInfo.FileName = exeDir + "MSBuild.exe";
            process.StartInfo.Arguments = string.Format("{0} /property:Configuration=Debug", inDirectory + inFile);
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            process.WaitForExit();*/

            // make sure output directory exists
            if (!Directory.Exists(outDirectory))
            {
                Directory.CreateDirectory(outDirectory);
            }

            compileLibrary(inDirectory + "bin/Debug/" + inFile.Split('.')[0] + ".dll", compileMaterial, compileMetroShaders, compileSilverlightShaders);
        }
Beispiel #3
0
        public void Compile(string outDirectory, CompilerOutputs outputType, bool compileMaterial, bool compileMetroShaders, bool compileSilverlightShaders)
        {
            this.outDirectory = outDirectory;
            this.outputType   = outputType;

            // compile shader library

            /*var exeDir = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", "MSBuildToolsPath", "") as string;
             * if (string.IsNullOrEmpty(exeDir)) throw new Exception("Cant find MSBuild for .NET 4.");
             *
             * var process = new System.Diagnostics.Process();
             * process.StartInfo.FileName = exeDir + "MSBuild.exe";
             * process.StartInfo.Arguments = string.Format("{0} /property:Configuration=Debug", inDirectory + inFile);
             * process.StartInfo.CreateNoWindow = true;
             * process.StartInfo.UseShellExecute = false;
             * process.Start();
             * process.WaitForExit();*/

            // make sure output directory exists
            if (!Directory.Exists(outDirectory))
            {
                Directory.CreateDirectory(outDirectory);
            }

            compileLibrary(inDirectory + "bin/Debug/" + inFile.Split('.')[0] + ".dll", compileMaterial, compileMetroShaders, compileSilverlightShaders);
        }
Beispiel #4
0
        public string FindMethodBlock(Type shader, MethodInfo method, CompilerOutputs outputType)
        {
            // find shaders namespace
            var match = Regex.Match(Code, shader.Namespace + @"\s*?\{(.*\})", RegexOptions.Singleline);
            if (match.Success && match.Groups.Count == 2)
            {
                // find shader class
                var namespaceBlock = match.Groups[1].Value;
                int end = getBlockEnd(namespaceBlock);
                namespaceBlock = namespaceBlock.Remove(end);
                match = Regex.Match(namespaceBlock, @"class\s*" + shader.Name + @".*?\{(.*\})", RegexOptions.Singleline);
                if (match.Success && match.Groups.Count == 2)
                {
                    // find method
                    var classBlock = match.Groups[1].Value;
                    end = getBlockEnd(classBlock);
                    classBlock = classBlock.Remove(end);
                    match = Regex.Match(classBlock, Compiler.convertToBasicType(method.ReturnType, outputType, false) + @"\s*" + method.Name + @".*?\{(.*\})", RegexOptions.Singleline);
                    if (match.Success && match.Groups.Count == 2)
                    {
                        var methodBlock = match.Groups[1].Value;
                        end = getBlockEnd(methodBlock);
                        methodBlock = methodBlock.Remove(end);
                        return '{' + methodBlock + '}';
                    }
                }
            }

            return null;
        }
Beispiel #5
0
        internal static string Output(CompilerOutputs output)
        {
            var baseType = Compiler.getBaseCompilerOutput(output);
            if (baseType == BaseCompilerOutputs.HLSL) return "float4x4";
            if (baseType == BaseCompilerOutputs.GLSL) return "mat4";
            if (baseType == BaseCompilerOutputs.CG) return "float4x4";

            throw new Exception("Matrix4 - Unsuported platform.");
        }
Beispiel #6
0
        internal static string convertToBasicType(string type, CompilerOutputs outputType, bool convertVectorTypes)
        {
            switch (type)
            {
            case ("Void"): return("void");

            case ("Int32"): return("int");

            case ("UInt32"): return("uint");

            case ("Single"): return("float");

            case ("Double"): return("float");

            case ("Boolean"): return("bool");

            case ("Vector2"): return(convertVectorTypes ? Vector2.Output(outputType) : type);

            case ("Vector3"): return(convertVectorTypes ? Vector3.Output(outputType) : type);

            case ("Vector4"): return(convertVectorTypes ? Vector4.Output(outputType) : type);

            case ("Matrix3"): return(convertVectorTypes ? Matrix3.Output(outputType) : type);

            case ("Matrix4"): return(convertVectorTypes ? Matrix4.Output(outputType) : type);

            case ("Void[]"): return("void");

            case ("Int32[]"): return("int");

            case ("UInt32[]"): return("uint");

            case ("Single[]"): return("float");

            case ("Double[]"): return("float");

            case ("Boolean[]"): return("bool");

            case ("Vector2[]"): return(convertVectorTypes ? Vector2.Output(outputType) : type);

            case ("Vector3[]"): return(convertVectorTypes ? Vector3.Output(outputType) : type);

            case ("Vector4[]"): return(convertVectorTypes ? Vector4.Output(outputType) : type);

            case ("Matrix3[]"): return(convertVectorTypes ? Matrix3.Output(outputType) : type);

            case ("Matrix4[]"): return(convertVectorTypes ? Matrix4.Output(outputType) : type);

            case ("Texture2D"): return(convertVectorTypes ? Texture2D.Output(outputType) : type);

            default: return(type);
            }
        }
Beispiel #7
0
 internal static string Output(CompilerOutputs output)
 {
     switch (output)
     {
         case (CompilerOutputs.D3D11): return "texture2D";
         case (CompilerOutputs.D3D9): return "sampler2D";
         case (CompilerOutputs.XNA): return "texture2D";
         case (CompilerOutputs.Silverlight): return "sampler2D";
         case (CompilerOutputs.GL3): return "sampler2D";
         case (CompilerOutputs.GL2): return "sampler2D";
         case (CompilerOutputs.GLES2): return "sampler2D";
         case (CompilerOutputs.Vita): return "sampler2D";
         default: throw new Exception("Texture2D - Unsuported platform.");
     }
 }
Beispiel #8
0
        internal static string Output(CompilerOutputs output)
        {
            var baseType = Compiler.getBaseCompilerOutput(output);

            if (baseType == BaseCompilerOutputs.HLSL)
            {
                return("float3x3");
            }
            if (baseType == BaseCompilerOutputs.GLSL)
            {
                return("mat3");
            }
            if (baseType == BaseCompilerOutputs.CG)
            {
                return("float3x3");
            }

            throw new Exception("Matrix3 - Unsuported platform.");
        }
Beispiel #9
0
        internal static BaseCompilerOutputs getBaseCompilerOutput(CompilerOutputs outputType)
        {
            switch (outputType)
            {
            case (CompilerOutputs.D3D11): return(BaseCompilerOutputs.HLSL);

            case (CompilerOutputs.D3D9): return(BaseCompilerOutputs.HLSL);

            case (CompilerOutputs.XNA): return(BaseCompilerOutputs.HLSL);

            case (CompilerOutputs.Silverlight): return(BaseCompilerOutputs.HLSL);

            case (CompilerOutputs.GL3): return(BaseCompilerOutputs.GLSL);

            case (CompilerOutputs.GL2): return(BaseCompilerOutputs.GLSL);

            case (CompilerOutputs.GLES2): return(BaseCompilerOutputs.GLSL);

            case (CompilerOutputs.Vita): return(BaseCompilerOutputs.CG);

            default: throw new Exception("Unknown BaseCompilerType.");
            }
        }
Beispiel #10
0
        internal static string Output(CompilerOutputs output)
        {
            switch (output)
            {
            case (CompilerOutputs.D3D11): return("texture2D");

            case (CompilerOutputs.D3D9): return("sampler2D");

            case (CompilerOutputs.XNA): return("texture2D");

            case (CompilerOutputs.Silverlight): return("sampler2D");

            case (CompilerOutputs.GL3): return("sampler2D");

            case (CompilerOutputs.GL2): return("sampler2D");

            case (CompilerOutputs.GLES2): return("sampler2D");

            case (CompilerOutputs.Vita): return("sampler2D");

            default: throw new Exception("Texture2D - Unsuported platform.");
            }
        }
Beispiel #11
0
 internal static string convertToBasicType(Type type, CompilerOutputs outputType, bool convertVectorTypes)
 {
     return(convertToBasicType(type.Name, outputType, convertVectorTypes));
 }
Beispiel #12
0
 internal static BaseCompilerOutputs getBaseCompilerOutput(CompilerOutputs outputType)
 {
     switch (outputType)
     {
         case (CompilerOutputs.D3D11): return BaseCompilerOutputs.HLSL;
         case (CompilerOutputs.D3D9): return BaseCompilerOutputs.HLSL;
         case (CompilerOutputs.XNA): return BaseCompilerOutputs.HLSL;
         case (CompilerOutputs.Silverlight): return BaseCompilerOutputs.HLSL;
         case (CompilerOutputs.GL3): return BaseCompilerOutputs.GLSL;
         case (CompilerOutputs.GL2): return BaseCompilerOutputs.GLSL;
         case (CompilerOutputs.GLES2): return BaseCompilerOutputs.GLSL;
         case (CompilerOutputs.Vita): return BaseCompilerOutputs.CG;
         default: throw new Exception("Unknown BaseCompilerType.");
     }
 }
Beispiel #13
0
        internal static string convertToBasicType(string type, CompilerOutputs outputType, bool convertVectorTypes)
        {
            switch (type)
            {
                case ("Void"): return "void";
                case ("Int32"): return "int";
                case ("UInt32"): return "uint";
                case ("Single"): return "float";
                case ("Double"): return "float";
                case ("Boolean"): return "bool";
                case ("Vector2"): return convertVectorTypes ? Vector2.Output(outputType) : type;
                case ("Vector3"): return convertVectorTypes ? Vector3.Output(outputType) : type;
                case ("Vector4"): return convertVectorTypes ? Vector4.Output(outputType) : type;
                case ("Matrix3"): return convertVectorTypes ? Matrix3.Output(outputType) : type;
                case ("Matrix4"): return convertVectorTypes ? Matrix4.Output(outputType) : type;

                case ("Void[]"): return "void";
                case ("Int32[]"): return "int";
                case ("UInt32[]"): return "uint";
                case ("Single[]"): return "float";
                case ("Double[]"): return "float";
                case ("Boolean[]"): return "bool";
                case ("Vector2[]"): return convertVectorTypes ? Vector2.Output(outputType) : type;
                case ("Vector3[]"): return convertVectorTypes ? Vector3.Output(outputType) : type;
                case ("Vector4[]"): return convertVectorTypes ? Vector4.Output(outputType) : type;
                case ("Matrix3[]"): return convertVectorTypes ? Matrix3.Output(outputType) : type;
                case ("Matrix4[]"): return convertVectorTypes ? Matrix4.Output(outputType) : type;
                case ("Texture2D"): return convertVectorTypes ? Texture2D.Output(outputType) : type;
                default: return type;
            }
        }
Beispiel #14
0
 internal static string convertToBasicType(Type type, CompilerOutputs outputType, bool convertVectorTypes)
 {
     return convertToBasicType(type.Name, outputType, convertVectorTypes);
 }