Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MaterialNodeClassLoader.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 SiliconStudio.Paradox.Effects;
4 using SiliconStudio.Paradox.Shaders;
5 using SiliconStudio.Paradox.Shaders.Parser.Ast;
6 using SiliconStudio.Paradox.Shaders.Parser.Mixins;
7 using SiliconStudio.Shaders.Utility;
8 
9 namespace SiliconStudio.Paradox.Assets.Materials
10 {
11  internal class MaterialNodeClassLoader
12  {
13  /// <summary>
14  /// static and unique instance of the loader.
15  /// </summary>
16  private static MaterialNodeClassLoader materialNodeClassLoader;
17 
18  /// <summary>
19  /// Get the unique instance of the class.
20  /// </summary>
21  /// <returns></returns>
22  public static MaterialNodeClassLoader GetLoader()
23  {
24  if (materialNodeClassLoader == null)
25  materialNodeClassLoader = new MaterialNodeClassLoader();
26  return materialNodeClassLoader;
27  }
28 
29  /// <summary>
30  /// The source manager.
31  /// </summary>
32  private readonly ShaderSourceManager manager;
33 
34  /// <summary>
35  /// The shader loader.
36  /// </summary>
37  private readonly ShaderLoader loader;
38 
39  /// <summary>
40  /// The logger.
41  /// </summary>
42  private readonly LoggerResult logger;
43 
44  private MaterialNodeClassLoader()
45  {
46  manager = new ShaderSourceManager();
47  manager.LookupDirectoryList.Add(EffectSystem.DefaultSourceShaderFolder);
49  loader = new ShaderLoader(manager);
50  }
51 
52  /// <summary>
53  /// Get the shader.
54  /// </summary>
55  /// <param name="name">The name of the shader.</param>
56  /// <returns>The shader.</returns>
57  public ShaderClassType GetShader(string name)
58  {
59  try
60  {
61  if (!loader.ClassExists(name))
62  return null;
63 
64  var shader = loader.LoadClassSource(new ShaderClassSource(name), null, logger);
65  if (logger.HasErrors)
66  {
67  // TODO: output messages
68  logger.Messages.Clear();
69  return null;
70  }
71  return shader;
72  }
73  catch
74  {
75  // TODO: output messages
76  return null;
77  }
78  }
79 
80  public ShaderClassType ParseShader(string shaderSource)
81  {
82  try
83  {
84  var shader = loader.ParseSource(shaderSource, logger);
85  if (logger.HasErrors)
86  {
87  // TODO: output messages
88  logger.Messages.Clear();
89  return null;
90  }
91  return shader;
92  }
93  catch
94  {
95  // TODO: output messages
96  return null;
97  }
98  }
99  }
100 }
A class to collect parsing/expression messages.
Definition: LoggerResult.cs:13