Added Summeries

This commit is contained in:
Michel Fedde 2021-03-19 20:59:02 +01:00
parent 71a22df8bd
commit 8296d9b8a9
47 changed files with 812 additions and 177 deletions

View file

@ -70,6 +70,11 @@ namespace SM.OGL.Shaders
ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry);
}
/// <summary>
/// Creates a shader out of a vertex and an fragment shader.
/// </summary>
/// <param name="vertex"></param>
/// <param name="fragment"></param>
protected GenericShader(string vertex, string fragment) : this(new ShaderFileCollection(vertex, fragment)){}
/// <inheritdoc />
@ -81,6 +86,10 @@ namespace SM.OGL.Shaders
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
/// <summary>
/// Updates the shader files and recompiles the shader.
/// </summary>
/// <param name="newShaderFiles"></param>
public void Update(ShaderFileCollection newShaderFiles)
{
ShaderFileFiles = newShaderFiles;
@ -104,6 +113,9 @@ namespace SM.OGL.Shaders
GLDebugging.CheckGLErrors($"A error occured at shader creation for '{GetType()}': %code%");
}
/// <summary>
/// Activates the shader
/// </summary>
public void Activate()
{
GL.UseProgram(ID);
@ -115,6 +127,7 @@ namespace SM.OGL.Shaders
Load();
}
/// <inheritdoc />
public override void Dispose()
{
GL.DeleteProgram(this);
@ -136,14 +149,15 @@ namespace SM.OGL.Shaders
/// <summary>
/// Draws the mesh while forcing a primitive type instead of using the mesh type.
/// </summary>
/// <param name="modelType">The type, as what the object should be rendered.</param>
/// <param name="mesh">The mesh.</param>
/// <param name="amount">The amounts for instancing.</param>
public static void DrawObject(PrimitiveType forcedType, GenericMesh mesh, int amount = 1)
public static void DrawObject(PrimitiveType modelType, GenericMesh mesh, int amount = 1)
{
if (mesh.Indices != null)
GL.DrawElementsInstanced(forcedType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
GL.DrawElementsInstanced(modelType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
else
GL.DrawArraysInstanced(forcedType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
GL.DrawArraysInstanced(modelType, 0, mesh.Vertex.Count / mesh.Vertex.PointerSize, amount);
}
/// <summary>

View file

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

View file

@ -8,14 +8,34 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
/// <summary>
/// Collects and provied the uniforms of a shader.
/// </summary>
public class UniformCollection : Dictionary<string, IUniform>
{
public int NextTexture = 0;
internal string KeyString = "";
/// <summary>
/// The next uniform-position for textures.
/// </summary>
public int NextTexture = 0;
/// <summary>
/// The shader this collections is connected to.
/// </summary>
public GenericShader ParentShader { get; internal set; }
/// <summary>
///
/// </summary>
/// <param name="key"></param>
public new Uniform this[string key] => Get(key);
/// <summary>
/// Equivalent to <see cref="this"/>
/// <para>Gets the uniform with the provied key.</para>
/// <para>If it can't find it, it will create a warning and a uniform with the location of -1.</para>
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Uniform Get(string key)
{
try
@ -31,18 +51,22 @@ namespace SM.OGL.Shaders
}
}
/// <summary>
/// Gets a array.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="KeyNotFoundException">If the key wasn't found, it will throw a exception</exception>
public UniformArray GetArray(string key)
{
try
{
if (ContainsKey(key))
return (UniformArray) base[key];
}
catch (KeyNotFoundException)
{
throw new Exception("UniformArray '"+key+"' wasn't found");
}
else throw new KeyNotFoundException("UniformArray '"+key+"' wasn't found");
}
/// <summary>
/// Adds a uniform to the collection.
/// </summary>
public void Add(string key, int location)
{
base.Add(key, new Uniform(location, this));
@ -101,7 +125,7 @@ namespace SM.OGL.Shaders
}
if (keySplits[1] == "0")
array.uniformNames.Add(keySplits[2].Substring(1));
array.UniformNames.Add(keySplits[2].Substring(1));
}
else
{