/// <summary> /// Creates an effect parameter collection from the specified collection of techniques. /// </summary> /// <param name="techniques">The collection of techniques from which to create an effect parameter collection.</param> /// <param name="parameters">The collection of expected parameter names, or <see langword="null"/> to query /// effect parameters from shader uniforms.</param> /// <returns>The effect parameter collection that was created.</returns> private OpenGLEffectParameterCollection CreateEffectParameters( IEnumerable <OpenGLEffectTechnique> techniques, IEnumerable <String> parameters) { var paramlist = new Dictionary <String, OpenGLEffectParameter>(); var uniforms = from tech in techniques from pass in tech.Passes from prog in ((OpenGLEffectPass)pass).Programs from unif in prog.Uniforms let name = unif.Name let nameSanitized = name.EndsWith("[0]") ? name.Substring(0, name.Length - "[0]".Length) : name where parameters == null || parameters.Contains(nameSanitized) group unif by nameSanitized into g select g; var mismatches = uniforms.Where(x => x.Select(y => y.Type).Distinct().Count() > 1); if (mismatches.Any()) { throw new InvalidOperationException(OpenGLStrings.EffectUniformTypeMismatch.Format(mismatches.First().Key)); } foreach (var kvp in uniforms) { var name = kvp.Key; var type = kvp.Select(x => x.Type).First(); var parameter = new OpenGLEffectParameter(Ultraviolet, name, type); paramlist[name] = parameter; foreach (var uniform in kvp) { uniform.SetDataSource(parameter.Data); } } if (parameters != null) { foreach (var p in parameters) { if (!paramlist.ContainsKey(p)) { throw new InvalidOperationException(OpenGLStrings.EffectParameterCannotFindUniform.Format(p)); } } } return(new OpenGLEffectParameterCollection(paramlist.Values)); }
/// <summary> /// Creates an effect parameter collection from the specified collection of techniques. /// </summary> /// <param name="techniques">The collection of techniques from which to create an effect parameter collection.</param> /// <param name="parameters">The collection of expected parameter names, or <see langword="null"/> to query /// effect parameters from shader uniforms.</param> /// <returns>The effect parameter collection that was created.</returns> private OpenGLEffectParameterCollection CreateEffectParameters( IEnumerable<OpenGLEffectTechnique> techniques, IEnumerable<String> parameters) { var paramlist = new Dictionary<String, OpenGLEffectParameter>(); var uniforms = from tech in techniques from pass in tech.Passes from prog in ((OpenGLEffectPass)pass).Programs from unif in prog.Uniforms let name = unif.Name let nameSanitized = name.EndsWith("[0]") ? name.Substring(0, name.Length - "[0]".Length) : name where parameters == null || parameters.Contains(nameSanitized) group unif by nameSanitized into g select g; var mismatches = uniforms.Where(x => x.Select(y => y.Type).Distinct().Count() > 1); if (mismatches.Any()) throw new InvalidOperationException(OpenGLStrings.EffectUniformTypeMismatch.Format(mismatches.First().Key)); foreach (var kvp in uniforms) { var name = kvp.Key; var type = kvp.Select(x => x.Type).First(); var parameter = new OpenGLEffectParameter(Ultraviolet, name, type); paramlist[name] = parameter; foreach (var uniform in kvp) { uniform.SetDataSource(parameter.Data); } } if (parameters != null) { foreach (var p in parameters) { if (!paramlist.ContainsKey(p)) throw new InvalidOperationException(OpenGLStrings.EffectParameterCannotFindUniform.Format(p)); } } return new OpenGLEffectParameterCollection(paramlist.Values); }