Exemplo n.º 1
0
 internal TShader(InfoSink sink, ShaderLanguage language, GLSLIntermediate intermediate, SymbolLookup symbols)
 {
     mInfoSink     = sink;
     mLanguage     = language;
     mIntermediate = intermediate;
     mSymbols      = symbols;
 }
Exemplo n.º 2
0
 public void TestCase()
 {
     var debug = new InfoSinkBase (SinkType.String);
     var info = new InfoSinkBase (SinkType.String);
     var infoSink = new InfoSink(info, debug);
     var intermediate = new GLSLIntermediate ();
     var symbols = new SymbolLookup ();
     symbols.SetPreambleManually (Profile.CoreProfile);
     symbols.DefineAs ("GL_ARB_shader_storage_buffer_object", 1);
     var preprocessor = new Standalone (infoSink, intermediate, symbols);
     string result;
     Assert.IsTrue(preprocessor.Run("Sample.vert", out result));
     Assert.IsNotNull (result);
 }
Exemplo n.º 3
0
 internal ParseContext(
     int version,
     Profile profile,
     InfoSink infoSink,
     bool forwardCompatible,
     SymbolLookup symbols,
     GLSLIntermediate intermediate)
 {
     mIntermediate       = intermediate;
     mVersion            = version;
     mProfile            = profile;
     mInfoSink           = infoSink;
     mExtensionBehaviors = new Dictionary <string, ExtensionBehavior> ();
     contextPragma       = new Pragma(true, false);
     mSymbols            = symbols;
 }
Exemplo n.º 4
0
        internal ParseContext(
			int version,
			Profile profile,
			InfoSink infoSink,
			bool forwardCompatible,
			SymbolLookup symbols,
			GLSLIntermediate intermediate)
        {
            mIntermediate = intermediate;
            mVersion = version;
            mProfile = profile;
            mInfoSink = infoSink;
            mExtensionBehaviors = new Dictionary<string, ExtensionBehavior> ();
            contextPragma = new Pragma (true, false);
            mSymbols = symbols;
        }
Exemplo n.º 5
0
 public Standalone(InfoSink infoSink, GLSLIntermediate intermediate, SymbolLookup symbols)
 {
     mInfoSink     = infoSink;
     mIntermediate = intermediate;
     mSymbols      = symbols;
 }
Exemplo n.º 6
0
 static Standalone InitialisePreprocessor(InfoSink infoSink)
 {
     var intermediate = new GLSLIntermediate ();
     var symbols = new SymbolLookup ();
     symbols.SetPreambleManually (Profile.CoreProfile);
     symbols.DefineAs ("GL_ARB_shader_storage_buffer_object", 1);
     return new Standalone (infoSink, intermediate, symbols);
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
 public Standalone(InfoSink infoSink, GLSLIntermediate intermediate, SymbolLookup symbols)
 {
     mInfoSink = infoSink;
     mIntermediate = intermediate;
     mSymbols = symbols;
 }
Exemplo n.º 9
0
        static bool DeduceVersionProfile(InfoSink infoSink, ShaderLanguage stage, bool versionNotFirst, int defaultVersion, ref int version, ref Profile profile)
        {
            const int FirstProfileVersion = 150;
            bool      correct             = true;

            // Get a good version...
            if (version == 0)
            {
                version = defaultVersion;
                // infoSink.info.message(EPrefixWarning, "#version: statement missing; use #version on first line of shader");
            }

            // Get a good profile...
            if (profile == Profile.NoProfile)
            {
                if (version == 300 || version == 310)
                {
                    correct = false;
                    infoSink.Info.WriteMessage(PrefixType.Error, "#version: versions 300 and 310 require specifying the 'es' profile");
                    profile = Profile.EsProfile;
                }
                else if (version == 100)
                {
                    profile = Profile.EsProfile;
                }
                else if (version >= FirstProfileVersion)
                {
                    profile = Profile.CoreProfile;
                }
                else
                {
                    profile = Profile.NoProfile;
                }
            }
            else
            {
                // a profile was provided...
                if (version < 150)
                {
                    correct = false;
                    infoSink.Info.WriteMessage(PrefixType.Error, "#version: versions before 150 do not allow a profile token");
                    if (version == 100)
                    {
                        profile = Profile.EsProfile;
                    }
                    else
                    {
                        profile = Profile.NoProfile;
                    }
                }
                else if (version == 300 || version == 310)
                {
                    if (profile != Profile.EsProfile)
                    {
                        correct = false;
                        infoSink.Info.WriteMessage(PrefixType.Error, "#version: versions 300 and 310 support only the es profile");
                    }
                    profile = Profile.EsProfile;
                }
                else
                {
                    if (profile == Profile.EsProfile)
                    {
                        correct = false;
                        infoSink.Info.WriteMessage(PrefixType.Error, "#version: only version 300 and 310 support the es profile");
                        if (version >= FirstProfileVersion)
                        {
                            profile = Profile.CoreProfile;
                        }
                        else
                        {
                            profile = Profile.NoProfile;
                        }
                    }
                    // else: typical desktop case... e.g., "#version 410 core"
                }
            }

            // Correct for stage type...
            switch (stage)
            {
            case ShaderLanguage.Geometry:
                if ((profile == Profile.EsProfile && version < 310) ||
                    (profile != Profile.EsProfile && version < 150))
                {
                    correct = false;
                    infoSink.Info.WriteMessage(PrefixType.Error, "#version: geometry shaders require es profile with version 310 or non-es profile with version 150 or above");
                    version = (profile == Profile.EsProfile) ? 310 : 150;
                    if (profile == Profile.EsProfile || profile == Profile.NoProfile)
                    {
                        profile = Profile.CoreProfile;
                    }
                }
                break;

            case ShaderLanguage.TessControl:
            case ShaderLanguage.TessEvaluation:
                if ((profile == Profile.EsProfile && version < 310) ||
                    (profile != Profile.EsProfile && version < 150))
                {
                    correct = false;
                    infoSink.Info.WriteMessage(PrefixType.Error, "#version: tessellation shaders require es profile with version 310 or non-es profile with version 150 or above");
                    version = (profile == Profile.EsProfile) ? 310 : 400;                     // 150 supports the extension, correction is to 400 which does not
                    if (profile == Profile.EsProfile || profile == Profile.NoProfile)
                    {
                        profile = Profile.CoreProfile;
                    }
                }
                break;

            case ShaderLanguage.Compute:
                if ((profile == Profile.EsProfile && version < 310) ||
                    (profile != Profile.EsProfile && version < 420))
                {
                    correct = false;
                    infoSink.Info.WriteMessage(PrefixType.Error, "#version: compute shaders require es profile with version 310 or above, or non-es profile with version 420 or above");
                    version = profile == Profile.EsProfile ? 310 : 430;                     // 420 supports the extension, correction is to 430 which does not
                    profile = Profile.CoreProfile;
                }
                break;

            default:
                break;
            }

            if (profile == Profile.EsProfile && version >= 300 && versionNotFirst)
            {
                correct = false;
                infoSink.Info.WriteMessage(PrefixType.Error, "#version: statement must appear first in es-profile shader; before comments or newlines");
            }

            // A metacheck on the condition of the compiler itself...
            switch (version)
            {
            // ES versions
            case 100:
            case 300:
                // versions are complete
                break;

            // Desktop versions
            case 110:
            case 120:
            case 130:
            case 140:
            case 150:
            case 330:
                // versions are complete
                break;

            case 310:
            case 400:
            case 410:
            case 420:
            case 430:
            case 440:
            case 450:
                infoSink.Info
                .Append("Warning, version ")
                .Append(version.ToString())
                .Append(" is not yet complete; most version-specific features are present, but some are missing.\n");
                break;

            default:
                infoSink.Info
                .Append("Warning, version ")
                .Append(version.ToString())
                .Append(" is unknown.\n");
                break;
            }

            return(correct);
        }