Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ModuleMixinInfo.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.Core.Storage;
7 using SiliconStudio.Paradox.Shaders.Parser.Ast;
8 using SiliconStudio.Shaders.Ast;
9 using SiliconStudio.Shaders.Utility;
10 
11 namespace SiliconStudio.Paradox.Shaders.Parser.Mixins
12 {
13  internal class ModuleMixinInfo
14  {
15  #region Private members
16 
17  /// <summary>
18  /// The name of the mixin
19  /// </summary>
20  private string mixinName = "";
21 
22  /// <summary>
23  /// The ShaderClassType
24  /// </summary>
25  private ShaderClassType mixinAst;
26 
27  #endregion
28 
29  #region Public members and properties
30 
31  /// <summary>
32  /// The ShaderClassSource to load
33  /// </summary>
34  public ShaderSource ShaderSource { get; set; }
35 
36  /// <summary>
37  /// The name of the mixin (property)
38  /// </summary>
39  public string MixinName { get { return mixinName; } }
40 
41  /// <summary>
42  /// The name of the mixin with its hashed code (property)
43  /// </summary>
44  public string MixinGenericName;
45 
46  /// <summary>
47  /// The log stored by this mixin info.
48  /// </summary>
49  public readonly LoggerResult Log;
50 
51  /// <summary>
52  /// The ShaderClassType (property)
53  /// </summary>
54  public ShaderClassType MixinAst
55  {
56  get
57  {
58  return mixinAst;
59  }
60  set
61  {
62  mixinAst = value;
63  mixinName = mixinAst.Name.Text;
64  }
65  }
66 
67  /// <summary>
68  /// The ModuleMixin
69  /// </summary>
70  public ModuleMixin Mixin = new ModuleMixin();
71 
72  /// <summary>
73  /// A flag stating that the mixin is instanciated
74  /// </summary>
75  public bool Instanciated { get; set; }
76 
77  /// <summary>
78  /// a flag checking that the check for replacement has be done
79  /// </summary>
80  public bool ReplacementChecked = false;
81 
82  /// <summary>
83  /// the source hash
84  /// </summary>
85  public ObjectId SourceHash;
86 
87  /// <summary>
88  /// the SHA1 hash of the source
89  /// </summary>
90  public ObjectId HashPreprocessSource;
91 
92  /// <summary>
93  /// The macros used for this mixin
94  /// </summary>
96 
97  /// <summary>
98  /// the list of all the necessary MixinInfos to compile the shader
99  /// </summary>
100  public HashSet<ModuleMixinInfo> MinimalContext = new HashSet<ModuleMixinInfo>();
101 
102  #endregion
103 
104  public ModuleMixinInfo()
105  {
106  Log = new LoggerResult();
107  Instanciated = true;
108  }
109 
110  #region Public methods
111 
112  public ModuleMixinInfo Copy(SiliconStudio.Shaders.Parser.ShaderMacro[] macros)
113  {
114  var mixinInfo = new ModuleMixinInfo();
115  mixinInfo.ShaderSource = ShaderSource;
116  mixinInfo.MixinAst = MixinAst;
117  mixinInfo.MixinGenericName = MixinGenericName;
118  mixinInfo.Mixin = Mixin;
119  mixinInfo.Instanciated = Instanciated;
120  mixinInfo.HashPreprocessSource = HashPreprocessSource;
121  mixinInfo.Macros = macros;
122 
123  return mixinInfo;
124  }
125 
126  public bool AreEqual(ShaderSource shaderSource, SiliconStudio.Shaders.Parser.ShaderMacro[] macros)
127  {
128  return ShaderSource.Equals(shaderSource) && macros.All(macro => Macros.Any(x => x.Name == macro.Name && x.Definition == macro.Definition)) && Macros.All(macro => macros.Any(x => x.Name == macro.Name && x.Definition == macro.Definition));
129  }
130 
131  #endregion
132 
133  #region Static members
134 
135  /// <summary>
136  /// Cleans the identifiers (i.e. make them use the minimal string)
137  /// </summary>
138  /// <param name="genList">The list of identifier</param>
139  public static void CleanIdentifiers(List<Identifier> genList)
140  {
141  foreach (var gen in genList.OfType<LiteralIdentifier>())
142  {
143  gen.Text = gen.Value.Value.ToString();
144  }
145  }
146 
147  #endregion
148  }
149 }
Macro to be used with PreProcessor.
Definition: ShaderMacro.cs:11
SiliconStudio.Core.Diagnostics.LoggerResult LoggerResult
A class to collect parsing/expression messages.
Definition: LoggerResult.cs:13
A hash to uniquely identify data.
Definition: ObjectId.cs:13
Output message to log right away.