Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LightingCompileGenerator.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Collections.Generic;
4 using System.Linq;
5 
6 using SiliconStudio.Assets.Compiler;
7 using SiliconStudio.BuildEngine;
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Diagnostics;
10 using SiliconStudio.Paradox.Assets.Effect.ValueGenerators;
11 using SiliconStudio.Paradox.Effects;
12 using SiliconStudio.Paradox.Shaders.Compiler;
13 
14 namespace SiliconStudio.Paradox.Assets.Effect
15 {
16  internal class LightingCompileGenerator : PermutationGeneratorBuildStep
17  {
18  protected readonly LightingAsset Asset;
19 
20  public LightingCompileGenerator(LightingAsset asset, AssetCompilerContext context)
21  : base(context, EffectLibraryAssetCompiler.RegisteredCompilerParametersGenerators.ToList())
22  {
23  Asset = asset;
24  }
25 
26  public override string Title
27  {
28  get
29  {
30  return "LightingCompileGenerator";
31  }
32  }
33 
34  public List<CompilerParameters> Execute()
35  {
36  var steps = new List<BuildStep>();
37  Steps = steps;
38 
39  // Pre-generate CompilerParameters for all meshes
40  var log = new LoggerResult("Lighting permutation of asset [{0}]".ToFormat(Asset.Id));
41 
42  var rootParameters = new CompilerParameters
43  {
44  Platform = Context.GetGraphicsPlatform(),
45  Profile = Context.GetGraphicsProfile()
46  };
47 
48  var keys = Asset.Permutations == null ? null : Asset.Permutations.Keys;
49  var children = Asset.Permutations == null ? null : Asset.Permutations.Children;
50 
51  var result = new List<CompilerParameters>();
52 
53  foreach (var parametersPerPermutation in GeneratePermutation(rootParameters, keys, children, log))
54  {
55  var parameters = parametersPerPermutation.Clone();
56  result.Add(parameters);
57  }
58  return result;
59  }
60 
61  private IEnumerable<CompilerParameters> GeneratePermutation(CompilerParameters parameters, EffectParameterKeyStandardGenerator keys, List<EffectPermutation> permutations, ILogger log)
62  {
63  if (keys == null || keys.Count == 0)
64  {
65  if (permutations == null || permutations.Count == 0)
66  {
67  yield return parameters;
68  }
69  else
70  {
71  for (int permutationIndex = 0; permutationIndex < permutations.Count; permutationIndex++)
72  {
73  var permutation = permutations[permutationIndex];
74  foreach (var parametersPerPermutations in GeneratePermutation(parameters, permutation.Keys, permutation.Children, log))
75  {
76  yield return parametersPerPermutations;
77  }
78  }
79  }
80  }
81  else
82  {
83  foreach (var parametersPerKeyValuePermutations in GenerateKeysPermutation(parameters, keys.GenerateKeyValues()))
84  {
85  foreach (var subParameters in GeneratePermutation(parametersPerKeyValuePermutations, null, permutations, log))
86  {
87  yield return subParameters;
88  }
89  }
90  }
91  }
92  }
93 }
Keys
Enumeration for keys.
Definition: Keys.cs:8
SiliconStudio.Core.Diagnostics.LoggerResult LoggerResult
Default implementation for a IEffectParameterGenerator using a dictionary of ParameterKey associated ...
The context used when compiling an asset in a Package.
IEnumerable< ParameterKey > Keys
Gets the keys of this collection.
Platform specific queries and functions.
Definition: Platform.cs:15
Interface for logging.
Definition: ILogger.cs:8