Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
EffectLibraryAssetCompiler.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 using SiliconStudio.Assets.Compiler;
6 using SiliconStudio.BuildEngine;
7 using SiliconStudio.Core.IO;
8 using SiliconStudio.Paradox.Shaders.Compiler;
9 
10 namespace SiliconStudio.Paradox.Assets.Effect
11 {
12  /// <summary>
13  /// Entry point to compile an <see cref="EffectLibraryAsset"/>
14  /// </summary>
15  public class EffectLibraryAssetCompiler : AssetCompilerBase<EffectLibraryAsset>
16  {
17  private static readonly List<ICompilerParametersGenerator> registeredCompilerParametersGenerators = new List<ICompilerParametersGenerator>();
18 
19  /// <summary>
20  /// Gets the registered <see cref="CompilerParameters"/> generators.
21  /// </summary>
22  /// <value>The registered <see cref="CompilerParameters"/> generators.</value>
23  public static IEnumerable<ICompilerParametersGenerator> RegisteredCompilerParametersGenerators
24  {
25  get
26  {
27  lock (registeredCompilerParametersGenerators)
28  {
29  return registeredCompilerParametersGenerators.ToList();
30  }
31  }
32  }
33 
34  /// <summary>
35  /// Registers a <see cref="CompilerParameters"/> generator.
36  /// </summary>
37  /// <param name="generator">The generator.</param>
39  {
40  lock (registeredCompilerParametersGenerators)
41  {
42  if (!registeredCompilerParametersGenerators.Contains(generator))
43  {
44  var insertIndex = registeredCompilerParametersGenerators.FindIndex(x => x.GeneratorPriority > generator.GeneratorPriority);
45  if (insertIndex == -1)
46  registeredCompilerParametersGenerators.Add(generator);
47  else
48  registeredCompilerParametersGenerators.Insert(insertIndex, generator);
49  }
50  }
51  }
52 
53  protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, EffectLibraryAsset asset, AssetCompilerResult result)
54  {
55  result.ShouldWaitForPreviousBuilds = true; // force to wait on all assets before starting EffectCompilerGeneratorBuildStep
56  result.BuildSteps = new ListBuildStep { new EffectCompileGeneratorBuildStep(context, urlInStorage, RegisteredCompilerParametersGenerators.ToList(), asset) };
57  }
58  }
59 }
Result of a compilation of assets when using IAssetCompiler.Compile
override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, EffectLibraryAsset asset, AssetCompilerResult result)
The context used when compiling an asset in a Package.
A dynamic generator of CompilerParameters from a source parameters. See remarks.
static void RegisterCompilerParametersGenerator(ICompilerParametersGenerator generator)
Registers a CompilerParameters generator.
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13