4 using System.Collections.Generic;
8 using SiliconStudio.Core;
10 namespace SiliconStudio.
Paradox.Shaders
23 Mixins =
new List<ShaderClassSource>();
24 Compositions =
new Core.Collections.SortedList<string,
ShaderSource>();
25 Macros =
new List<ShaderMacro>();
39 public List<ShaderClassSource> Mixins {
get; set; }
45 public List<ShaderMacro> Macros {
get; set; }
51 public Core.Collections.SortedList<string,
ShaderSource> Compositions {
get; set; }
60 Compositions[name] = shaderSource;
71 if (!Compositions.TryGetValue(name, out shaderSource))
75 shaderArraySource.Add(shaderSourceElement);
83 public void AddMacro(
string name,
object value)
96 throw new ArgumentNullException(
"parent",
string.Format(
"Cannot clone mixin [{0}] from a null parent"));
98 Mixins.AddRange(parent.Mixins);
99 Macros.AddRange(parent.Macros);
100 foreach (var shaderBasic
in parent.Compositions)
102 Compositions[shaderBasic.Key] = shaderBasic.Value;
114 throw new ArgumentNullException(
"parent",
string.Format(
"Cannot deep clone mixin [{0}] from a null parent"));
116 foreach (var mixin
in parent.Mixins)
118 Macros.AddRange(parent.Macros);
119 foreach (var shaderBasic
in parent.Compositions)
121 Compositions[shaderBasic.Key] = (
ShaderSource)shaderBasic.Value.Clone();
125 public override bool Equals(
object against)
127 if (ReferenceEquals(null, against))
return false;
128 if (ReferenceEquals(
this, against))
return true;
129 if (against.GetType() != this.GetType())
return false;
135 if (ReferenceEquals(null, other))
return false;
136 if (ReferenceEquals(
this, other))
return true;
139 return Utilities.Compare(Mixins, other.Mixins) &&
Utilities.
Compare(Macros, other.
Macros) && Utilities.Compare<string,
ShaderSource>(Compositions, other.Compositions);
156 newMixin.Compositions = Compositions == null ? null : ToSortedList(Compositions.Select(x =>
new KeyValuePair<string, ShaderSource>(x.Key, (
ShaderSource)x.Value.Clone())));
157 newMixin.Mixins = Mixins == null ? null : Mixins.Select(x => (
ShaderClassSource)x.Clone()).ToList();
158 newMixin.Macros = Macros == null ? null :
new List<ShaderMacro>(Macros.ToArray());
164 var values =
new Core.Collections.SortedList<TKey, TValue>();
165 foreach(var item
in list)
166 values.Add(item.Key, item.Value);
172 var result =
new StringBuilder();
174 if (Mixins != null && Mixins.Count > 0)
176 result.Append(
" : ");
177 for (
int i = 0; i < Mixins.Count; i++)
181 result.Append(Mixins[i]);
185 if (Compositions != null && Compositions.Count > 0)
188 var keys = Compositions.Keys.ToList();
190 for (
int i = 0; i < keys.Count; i++)
195 result.AppendFormat(
"{{{0} = {1}}}", key, Compositions[key]);
199 return result.ToString();
SiliconStudio.Paradox.Shaders.ShaderMacro ShaderMacro
void CloneFrom(ShaderMixinSource parent)
Clones from the specified ShaderMixinSource.
static bool Compare(IEnumerable left, IEnumerable right)
Compares two collection, element by elements.
A mixin performing a combination of ShaderClassSource and other mixins.
List< ShaderMacro > Macros
Gets or sets the macros.
override int GetHashCode()
void AddComposition(string name, ShaderSource shaderSource)
Adds a composition to this mixin.
override object Clone()
Deep clones this instance.
bool Equals(ShaderMixinSource other)
override bool Equals(object against)
Determines whether the specified System.Object is equal to this instance.
static int GetHashCode(IDictionary dict)
Computes a hashcode for a dictionary.
void DeepCloneFrom(ShaderMixinSource parent)
Clones from the specified ShaderMixinSource. Clones members too.
An array of ShaderSource used only in shader mixin compositions.
override string ToString()
ShaderMixinSource()
Initializes a new instance of the ShaderMixinSource class.
void AddMacro(string name, object value)
Adds a macro to this mixin.
void AddCompositionToArray(string name, ShaderSource shaderSourceElement)
Adds a composition to this mixin.
A shader class used for mixin.