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

@ -14,7 +14,7 @@ namespace SM.OGL.Framebuffer
/// </summary>
public class ColorAttachment : TextureBase
{
private int _multisamples;
private readonly int _multisamples;
/// <summary>
/// The ID the attachment was given.
@ -50,6 +50,12 @@ namespace SM.OGL.Framebuffer
public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
{ }
/// <summary>
/// Creates a color attachment with a specific id, specific pixel informations and multisamples.
/// </summary>
/// <param name="attachmentID"></param>
/// <param name="pixelInformation"></param>
/// <param name="multisamples"></param>
public ColorAttachment(int attachmentID, PixelInformation pixelInformation, int multisamples = 0)
{
AttachmentID = attachmentID;

View file

@ -14,6 +14,7 @@ namespace SM.OGL.Framebuffer
/// </summary>
public class Framebuffer : GLObject
{
/// <inheritdoc />
protected override bool AutoCompile { get; set; } = true;
/// <summary>
@ -25,8 +26,8 @@ namespace SM.OGL.Framebuffer
CanCompile = false,
};
private IFramebufferWindow _window;
private float _windowScale;
private readonly IFramebufferWindow _window;
private readonly float _windowScale;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Framebuffer;
@ -42,6 +43,9 @@ namespace SM.OGL.Framebuffer
public Dictionary<string, ColorAttachment> ColorAttachments { get; private set; } =
new Dictionary<string, ColorAttachment>();
/// <summary>
/// Contains the current renderbuffer attachments of the framebuffer.
/// </summary>
public List<RenderbufferAttachment> RenderbufferAttachments { get; } = new List<RenderbufferAttachment>();
/// <summary>
@ -131,6 +135,10 @@ namespace SM.OGL.Framebuffer
ColorAttachments.Add(key, value);
}
/// <summary>
/// Appends a renderbuffer attachment to the framebuffer.
/// </summary>
/// <param name="attachment"></param>
public void AppendRenderbuffer(RenderbufferAttachment attachment)
{
RenderbufferAttachments.Add(attachment);
@ -173,6 +181,11 @@ namespace SM.OGL.Framebuffer
GL.Clear(clear);
}
/// <summary>
/// Returns a <see cref="Framebuffer"/> handle of the current framebuffer.
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
{
Framebuffer buffer = new Framebuffer()

View file

@ -5,7 +5,13 @@
/// </summary>
public interface IFramebufferWindow
{
/// <summary>
/// The width of the window.
/// </summary>
int Width { get; }
/// <summary>
/// The height of the window.
/// </summary>
int Height { get; }
}
}

View file

@ -14,20 +14,30 @@ namespace SM.OGL
/// </summary>
public abstract class GLObject
{
private static List<GLObject> _disposableObjects = new List<GLObject>();
private static readonly List<GLObject> _disposableObjects = new List<GLObject>();
private string _name = "";
protected bool ReportAsNotCompiled;
/// <summary>
/// Contains the OpenGL ID
/// </summary>
protected int _id = -1;
/// <summary>
/// This can mark the object to never report as compiled, even when it was.
/// <para>You can still figure out, if it was compiled by checking <see cref="_id"/>. If not -1, its compiled.</para>
/// <para>Default: false</para>
/// </summary>
protected bool ReportAsNotCompiled;
/// <summary>
/// This can prevent the object to compile.
/// <para>Default: true</para>
/// </summary>
protected bool CanCompile = true;
/// <summary>
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
/// <para>Default: false</para>
/// </summary>
protected virtual bool AutoCompile { get; set; } = false;
@ -36,6 +46,10 @@ namespace SM.OGL
/// </summary>
public bool WasCompiled => _id > 0 && !ReportAsNotCompiled;
/// <summary>
/// Names the object
/// <para>If <see cref="GLSystem.Debugging"/> is true, then it will also name the object in the system.</para>
/// </summary>
public string Name
{
get => _name;
@ -111,11 +125,15 @@ namespace SM.OGL
Compile();
}
/// <inheritdoc />
public override string ToString()
{
return $"{GetType().Name} {(string.IsNullOrEmpty(_name) ? "" : $"\"{_name}\" ")}[{_id}]";
}
/// <summary>
/// This disposes the current objects, that where marked by the garbage collector.
/// </summary>
public static void DisposeMarkedObjects()
{
foreach (GLObject o in _disposableObjects)
@ -134,6 +152,9 @@ namespace SM.OGL
return glo.ID;
}
/// <summary>
/// If the garbage collector is trying to remove this object, it will add the object to a list, what get removed when <see cref="DisposeMarkedObjects"/> is called.
/// </summary>
~GLObject()
{
if (WasCompiled) _disposableObjects.Add(this);

View file

@ -49,21 +49,59 @@ namespace SM.OGL.Mesh
/// <returns></returns>
public Vector3 this[bool x, bool y, bool z] => Get(x,y,z);
/// <summary>
/// Equivalent to <see cref="this"/>.
/// <para>Returns specific configurations of corners</para>
/// </summary>
/// <param name="x">If true, it takes the X-value of maximum, otherwise the minimum.</param>
/// <param name="y">If true, it takes the Y-value of maximum, otherwise the minimum.</param>
/// <param name="z">If true, it takes the Z-value of maximum, otherwise the minimum.</param>
/// <returns></returns>
public Vector3 Get(bool x, bool y, bool z)
{
return new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
}
/// <summary>
/// Returns the configuration of the two furthest away corners.
/// </summary>
/// <param name="xyz">If true, it will take the maximum, otherwise the minimum.</param>
/// <returns></returns>
public Vector3 Get(bool xyz) => Get(xyz, xyz, xyz);
/// <summary>
/// Returns the configuration of one corner and applies a transformation to it.
/// <para>If the transformation causes the points to shift to no being in the right location is NOT checked!</para>
/// <para>For that use <see cref="GetBounds"/></para>
/// </summary>
/// <param name="transformation">The transformation</param>
/// <param name="x">If true, it takes the X-value of maximum, otherwise the minimum.</param>
/// <param name="y">If true, it takes the Y-value of maximum, otherwise the minimum.</param>
/// <param name="z">If true, it takes the Z-value of maximum, otherwise the minimum.</param>
/// <returns></returns>
public Vector3 Get(Matrix4 transformation, bool x, bool y, bool z)
{
Vector3 get = Get(x, y, z);
return (new Vector4(get, 1) * transformation).Xyz;
}
/// <summary>
/// Returns the configuration of the two furthest away corners.
/// <para>If the transformation causes the points to shift to no being in the right location is NOT checked!</para>
/// <para>For that use <see cref="GetBounds"/></para>
/// </summary>
/// <param name="transformation">The transformation</param>
/// <param name="xyz">If true, it will take the maximum, otherwise the minimum.</param>
/// <returns></returns>
public Vector3 Get(Matrix4 transformation, bool xyz) => Get(transformation, xyz, xyz, xyz);
/// <summary>
/// Returns the bounds of the bounding box while applying a transformation.
/// <para>This takes care of min and max locations.</para>
/// </summary>
/// <param name="transformation"></param>
/// <param name="min"></param>
/// <param name="max"></param>
public void GetBounds(Matrix4 transformation, out Vector3 min, out Vector3 max)
{
min = Get(transformation, false);
@ -79,6 +117,10 @@ namespace SM.OGL.Mesh
}
}
/// <summary>
/// Updates the bounding box to the mesh provided.
/// </summary>
/// <param name="mesh"></param>
public void Update(GenericMesh mesh)
{
int pos = 0;

View file

@ -13,9 +13,7 @@ namespace SM.OGL.Mesh
public abstract class GenericMesh : GLObject
{
private bool _boundingBoxUpdated = false;
public static int LastID { get; internal set; } = -1;
/// <inheritdoc />
protected override bool AutoCompile { get; set; } = true;
@ -71,12 +69,18 @@ namespace SM.OGL.Mesh
};
}
/// <summary>
/// Updates the object bounding box.
/// </summary>
public void UpdateBoundingBox()
{
BoundingBox.Update(this);
_boundingBoxUpdated = true;
}
/// <summary>
/// Activates the object to be rendered.
/// </summary>
public void Activate()
{
GL.BindVertexArray(ID);
@ -99,6 +103,7 @@ namespace SM.OGL.Mesh
GL.BindVertexArray(0);
}
/// <inheritdoc />
public override void Dispose()
{
GL.DeleteVertexArray(_id);

View file

@ -18,6 +18,12 @@
/// </summary>
public VBO ConnectedVBO;
/// <summary>
/// Creates a attribute for a mesh.
/// </summary>
/// <param name="index"></param>
/// <param name="name"></param>
/// <param name="buffer"></param>
public MeshAttribute(int index, string name, VBO buffer)
{
Index = index;

View file

@ -49,6 +49,11 @@ namespace SM.OGL.Mesh
Add(new MeshAttribute(id, name, vbo));
}
/// <summary>
/// Checks if the attribute list has the attribute name.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool Has(string name)
{
VBO attribute = this[name];

View file

@ -139,6 +139,10 @@ namespace SM.OGL.Mesh
Add(vector.X, vector.Y, z, w);
}
/// <summary>
/// Adds a array of vector2s.
/// </summary>
/// <param name="vectors"></param>
public void Add(params Vector2[] vectors)
{
foreach (Vector2 vector in vectors)
@ -163,6 +167,10 @@ namespace SM.OGL.Mesh
Add(vector.X, vector.Y, vector.Z, w);
}
/// <summary>
/// Adds a array of Vector3s.
/// </summary>
/// <param name="vectors"></param>
public void Add(params Vector3[] vectors)
{
foreach (Vector3 vector in vectors)

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
{