protected override void ChooseEffect(GraphicsDevice graphicsDevice) { // TODO: Free previous descriptor sets and layouts? // Looks like the effect changed, it needs a recompilation var compilerParameters = new CompilerParameters { EffectParameters = EffectCompilerParameters }; foreach (var effectParameterKey in Parameters.ParameterKeyInfos) { if (effectParameterKey.Key.Type == ParameterKeyType.Permutation) { // TODO GRAPHICS REFACTOR avoid direct access, esp. since permutation values might be separated from Objects at some point compilerParameters.SetObject(effectParameterKey.Key, Parameters.ObjectValues[effectParameterKey.BindingSlot]); } } effect = effectSystem.LoadEffect(effectName, compilerParameters).WaitForResult(); }
private void CreateEffect(DynamicEffectInstance effectInstance, ParameterCollection passParameters) { var compilerParameters = new CompilerParameters(); parameterCollections.Clear(); if (passParameters != null) { parameterCollections.Add(passParameters); } effectInstance.FillParameterCollections(ref parameterCollections); foreach (var parameterCollection in parameterCollections) { if (parameterCollection != null) { foreach (var parameter in parameterCollection.InternalValues) { compilerParameters.SetObject(parameter.Key, parameter.Value.Object); } } } compilerParameters.TaskPriority = taskPriority; foreach (var parameter in GraphicsDevice.Parameters.InternalValues) { compilerParameters.SetObject(parameter.Key, parameter.Value.Object); } // Compile shader // possible exception in LoadEffect TaskOrResult <Effect> effect; ParameterCollection usedParameters; try { effect = EffectSystem.LoadEffect(EffectName, compilerParameters, out usedParameters); } catch (Exception) { effectInstance.HasErrors = true; // Fallback to error effect var fallbackEffect = ComputeFallbackEffect(this, FallbackEffectType.Error, EffectName, compilerParameters); UpdateEffect(effectInstance, fallbackEffect.Effect, fallbackEffect.UsedParameters, passParameters); return; } // Do we have an async compilation? if (asyncEffectCompiler && effect.Task != null) { effectInstance.CurrentlyCompilingEffect = effect.Task; effectInstance.CurrentlyCompilingUsedParameters = usedParameters; if (!effectInstance.HasErrors) // If there was an error, stay in that state (we don't want to switch between reloading and error states) { // Fallback to default effect var fallbackEffect = ComputeFallbackEffect(this, FallbackEffectType.Compiling, EffectName, compilerParameters); UpdateEffect(effectInstance, fallbackEffect.Effect, fallbackEffect.UsedParameters, passParameters); } return; } var compiledEffect = effect.WaitForResult(); UpdateEffect(effectInstance, compiledEffect, usedParameters, passParameters); // Effect has been updated effectInstance.CurrentlyCompilingEffect = null; effectInstance.CurrentlyCompilingUsedParameters = null; }