using System.Collections.Generic;
namespace SM.OGL.Shaders
{
///
/// This class controls uniform array structures.
///
public class UniformArray : IUniform
{
private readonly Dictionary> storedUniforms = new Dictionary>();
internal List UniformNames = new List();
///
public int Location { get; internal set; }
///
/// The name of the uniform.
///
public string Name { get; internal set; }
///
/// The uniform collection the uniform is from.
///
public UniformCollection Parent { get; internal set; }
///
/// The shader the uniform is from.
///
public GenericShader ParentShader { get; internal set; }
///
/// The length of the array.
///
public int Length => storedUniforms.Count;
///
/// Returns a dictionary to control the current index inside the array.
///
public Dictionary this[int index] => Get(index);
///
/// Equivalent to
/// Returns a dictionary to control the current index inside the array.
///
public Dictionary Get(int index)
{
if (!storedUniforms.ContainsKey(index))
{
Dictionary dic = storedUniforms[index] = new Dictionary();
for (int i = 0; i < UniformNames.Count; i++)
{
dic.Add(UniformNames[i], new Uniform(Name + $"[{index}]." + UniformNames[i], ParentShader, Parent));
}
}
return storedUniforms[index];
}
}
}