5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Collections;
7 using SiliconStudio.Paradox.Graphics;
8 using SiliconStudio.Paradox.Shaders.Compiler;
10 namespace SiliconStudio.
Paradox.Effects
17 private readonly EffectParameterUpdater updater;
18 private readonly FastList<ParameterCollection> parameterCollections;
20 private readonly
string effectName;
34 if (services == null)
throw new ArgumentNullException(
"services");
35 if (effectName == null)
throw new ArgumentNullException(
"effectName");
37 this.effectName = effectName;
40 updater =
new EffectParameterUpdater();
41 parameterCollections =
new FastList<ParameterCollection>();
54 public string EffectName
81 bool effectChanged =
false;
85 effectInstance.UpdaterDefinition.Initialize(effectInstance.Effect);
86 UpdateLevels(effectInstance);
90 if (effectInstance.
Effect == null || HasCollectionChanged(effectInstance))
92 CreateEffect(effectInstance);
101 PrepareUpdater(effectInstance);
102 return updater.HasChanged(effectInstance.UpdaterDefinition);
105 private void CreateEffect(DynamicEffectInstance effectInstance)
108 parameterCollections.Clear(
true);
109 effectInstance.FillParameterCollections(parameterCollections);
111 foreach (var parameterCollection
in parameterCollections)
113 if (parameterCollection != null)
115 foreach (var parameter
in parameterCollection.InternalValues)
117 compilerParameters.SetObject(parameter.Key, parameter.Value.Object);
124 compilerParameters.SetObject(parameter.Key, parameter.Value.Object);
129 var effect = EffectSystem.LoadEffect(EffectName, compilerParameters);
131 if (!ReferenceEquals(effect, effectInstance.Effect))
134 if (effectInstance.Effect != null)
136 foreach (var parameter
in effectInstance.Effect.Parameters.InternalValues)
138 effect.Parameters.SetObject(parameter.Key, parameter.Value.Object);
142 effectInstance.Effect = effect;
143 effectInstance.UpdaterDefinition =
new EffectParameterUpdaterDefinition(effect);
149 effectInstance.UpdaterDefinition.UpdateCounter(effect.CompilationParameters);
152 UpdateLevels(effectInstance);
153 updater.UpdateCounters(effectInstance.UpdaterDefinition);
156 private void UpdateLevels(DynamicEffectInstance effectInstance)
158 PrepareUpdater(effectInstance);
159 updater.ComputeLevels(effectInstance.UpdaterDefinition);
166 private void PrepareUpdater(DynamicEffectInstance effectInstance)
168 parameterCollections.Clear(
true);
169 parameterCollections.Add(effectInstance.Effect.DefaultCompilationParameters);
170 effectInstance.FillParameterCollections(parameterCollections);
171 parameterCollections.Add(GraphicsDevice.Parameters);
173 updater.Update(effectInstance.UpdaterDefinition, parameterCollections.Items, parameterCollections.Count);
A dynamic effect instance updated by DynamicEffectCompiler.
Service providing method to access GraphicsDevice life-cycle.
DynamicEffectCompiler(IServiceRegistry services, string effectName)
Initializes a new instance of the DynamicEffectCompiler class.
Parameters used for compilation.
A service registry is a IServiceProvider that provides methods to register and unregister services...
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
Provides a dynamic compiler for an effect based on parameters changed.
bool Changed
Gets a boolean indicating if the effect changed since last update.
Effect Effect
Gets the effect currently being compiled.
bool Update(DynamicEffectInstance effectInstance)
Update a dynamic effect instance based on its parameters.
ParameterCollection Parameters
Gets the parameters attached to this particular device. This Parameters are used to override Effect p...