Example #1
0
        public override CompiledEffectContent Process(StitchedEffectContent input, ContentProcessorContext context)
        {
            StitchedEffectSymbol stitchedEffect = StitchedEffectBuilder.BuildStitchedEffect(input, context);

            // Find out which shader profile to attempt to compile for first.
            ShaderProfile minimumShaderProfile = GetMinimumTargetShaderProfile(stitchedEffect);

            foreach (ShaderProfile shaderProfile in Enum.GetValues(typeof(ShaderProfile)))
            {
                if (shaderProfile < minimumShaderProfile)
                {
                    continue;
                }

                CompiledEffectContent compiledEffect;
                if (AttemptEffectCompilation(context, input, stitchedEffect, shaderProfile, out compiledEffect))
                {
                    return(compiledEffect);
                }
            }

            throw new InvalidContentException(
                      "Could not find a shader profile compatible with this stitched effect.",
                      input.Identity);
        }
Example #2
0
 public static void GenerateAllTechniques(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect,
                                          bool generateVertexShader)
 {
     foreach (TechniqueSymbol technique in stitchedEffect.Techniques)
     {
         GenerateTechnique(generator, technique, generateVertexShader);
     }
 }
Example #3
0
 private static ShaderProfile GetMinimumTargetShaderProfile(StitchedEffectSymbol stitchedEffect)
 {
     foreach (ShaderProfile shaderProfile in Enum.GetValues(typeof(ShaderProfile)))
     {
         if (stitchedEffect.CanBeCompiledForShaderProfile(shaderProfile))
         {
             return(shaderProfile);
         }
     }
     throw new InvalidContentException("Could not find shader profile compatible with this stitched effect.");
 }
Example #4
0
 public EffectCodeGenerator(
     StitchedEffectSymbol stitchedEffect, ShaderProfile targetShaderProfile,
     TextWriter writer)
 {
     _stitchedEffect      = stitchedEffect;
     _targetShaderProfile = targetShaderProfile;
     _output  = new ScriptTextWriter(writer);
     _context = new GeneratorContext
     {
         TargetShaderProfile = _targetShaderProfile
     };
 }
Example #5
0
        private static bool AttemptEffectCompilation(
            ContentProcessorContext context, StitchedEffectContent input,
            StitchedEffectSymbol stitchedEffect, ShaderProfile shaderProfile,
            out CompiledEffectContent compiledEffect)
        {
            // Generate effect code.
            StringWriter        writer        = new StringWriter();
            EffectCodeGenerator codeGenerator = new EffectCodeGenerator(stitchedEffect, shaderProfile, writer);

            codeGenerator.GenerateCode();
            string effectCode = writer.ToString();

            // Save effect code so that if there are errors, we'll be able to view the generated .fx file.
            string tempEffectFile = GetTempEffectFileName(input);

            File.WriteAllText(tempEffectFile, effectCode, Encoding.GetEncoding(1252));

            // Process effect code.
            EffectProcessor effectProcessor = new EffectProcessor
            {
                DebugMode = EffectProcessorDebugMode.Auto,
                Defines   = null
            };

            EffectContent effectContent = new EffectContent
            {
                EffectCode = effectCode,
                Identity   = new ContentIdentity(tempEffectFile),
                Name       = input.Name
            };

            try
            {
                compiledEffect = effectProcessor.Process(effectContent, context);

                // This is only needed if the compilation was successful - if it failed,
                // a more specific error message (with link to the generated file)
                // will be shown to the user.
                context.Logger.LogImportantMessage(string.Format("{0} : Stitched effect generated (double-click this message to view).", tempEffectFile));

                return(true);
            }
            catch (InvalidContentException ex)
            {
                if (ErrorIndicatesNeedForShaderModel3(ex.Message))
                {
                    compiledEffect = null;
                    return(false);
                }
                throw;
            }
        }
Example #6
0
        public static void GenerateAllHeaderCode(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
        {
            List <string> seenFragmentTypes = new List <string>();

            foreach (StitchedFragmentSymbol stitchedFragmentNode in stitchedEffect.StitchedFragments)
            {
                if (seenFragmentTypes.Contains(stitchedFragmentNode.FragmentNode.Name))
                {
                    continue;
                }
                GenerateHeaderCode(generator, stitchedFragmentNode);
                seenFragmentTypes.Add(stitchedFragmentNode.FragmentNode.Name);
            }
        }
        public static List <ExportedValue> GetExportedValues(StitchedEffectSymbol stitchedEffect)
        {
            ExportDictionary     exports        = new ExportDictionary();
            List <ExportedValue> exportedValues = new List <ExportedValue>();

            foreach (StitchedFragmentSymbol stitchedFragment in stitchedEffect.StitchedFragments)
            {
                foreach (ShaderCodeBlockNode codeBlock in stitchedFragment.FragmentNode.VertexShaders)
                {
                    PreProcessCodeBlock(stitchedFragment.UniqueName, codeBlock, exports, exportedValues, true);
                }
                foreach (ShaderCodeBlockNode codeBlock in stitchedFragment.FragmentNode.PixelShaders)
                {
                    PreProcessCodeBlock(stitchedFragment.UniqueName, codeBlock, exports, exportedValues, true);
                }
            }
            return(exportedValues);
        }
Example #8
0
 public static void GenerateAllParameters(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachFragment(WriteParams);
 }
Example #9
0
 public static void WriteAllVertexInputStructures(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachPass(WriteVertexInputStructures);
 }
Example #10
0
 public static void WriteAllPixelOutputStructs(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachPass(WritePixelOutputStructs);
 }
Example #11
0
 public static void WriteAllPixelShaders(EffectCodeGenerator generator, StitchedEffectSymbol stitchedEffect)
 {
     generator.ForEachPass(WritePixelShaders);
 }