Holidays 12.10. -> 25.10.2020

~ Moved code around in files.

SM.Base:
+ PostProcessing-system
+ OnInitialization() for Scenes.
+ Shader-Extensions
+ Added option to not react while unfocused to the window.
+ Added Screenshots to the window.
+ Connected the log system to the SM.OGL-action system.

~ Replaced IShader with abstract MaterialShader.
~ When a log compression folder doesn't exist, it will create one.

SM.OGL:
+ Added support for UniformArrays
+ Added ShaderPreProcessing
+ Added Shader Extensions.
+ Added Debug actions.
+ SM.OGL settings

~ Framebuffer Size is automaticly changed, when the window and scale is set.

SM2D:
+ Added easy shader drawing.
This commit is contained in:
Michel Fedde 2020-10-24 15:10:36 +02:00
parent 2c00dbd31a
commit 03b3942732
102 changed files with 2683 additions and 1398 deletions

View file

@ -1,39 +1,36 @@
using System;
using System.Runtime.CompilerServices;
#region usings
using System;
using OpenTK;
#endregion
namespace SM.OGL.Mesh
{
/// <summary>
/// Contains information about bounding boxes of meshes
/// Contains information about bounding boxes of meshes
/// </summary>
public class BoundingBox
{
/// <summary>
/// The minimum corner.
/// </summary>
public Vector3 Min = Vector3.Zero;
/// <summary>
/// The maximum corner.
/// The maximum corner.
/// </summary>
public Vector3 Max = Vector3.Zero;
/// <summary>
/// Returns specific configurations of corners
/// The minimum corner.
/// </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 this[bool x, bool y, bool z] => new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
public Vector3 Min = Vector3.Zero;
/// <summary>
/// Empty constructor
/// Empty constructor
/// </summary>
public BoundingBox() {}
public BoundingBox()
{
}
/// <summary>
/// Creates the bounding box with predefined min and max values
/// Creates the bounding box with predefined min and max values
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
@ -44,12 +41,22 @@ namespace SM.OGL.Mesh
}
/// <summary>
/// Updates the bounding box.
/// Returns specific configurations of corners
/// </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 this[bool x, bool y, bool z] =>
new Vector3(x ? Max.X : Min.X, y ? Max.Y : Min.Y, z ? Max.Z : Min.Z);
/// <summary>
/// Updates the bounding box.
/// </summary>
/// <param name="vector"></param>
public void Update(Vector2 vector)
{
for (int i = 0; i < 2; i++)
for (var i = 0; i < 2; i++)
{
Min[i] = Math.Min(Min[i], vector[i]);
Max[i] = Math.Max(Max[i], vector[i]);
@ -57,12 +64,12 @@ namespace SM.OGL.Mesh
}
/// <summary>
/// Updates the bounding box.
/// Updates the bounding box.
/// </summary>
/// <param name="vector"></param>
public void Update(Vector3 vector)
{
for (int i = 0; i < 3; i++)
for (var i = 0; i < 3; i++)
{
Min[i] = Math.Min(Min[i], vector[i]);
Max[i] = Math.Max(Min[i], vector[i]);

View file

@ -1,15 +1,31 @@
using System;
#region usings
using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
using Buffer = OpenTK.Graphics.OpenGL4.Buffer;
#endregion
namespace SM.OGL.Mesh
{
/// <summary>
/// Contains information for meshes
/// Contains information for meshes
/// </summary>
public abstract class GenericMesh : GLObject
{
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
AttribDataIndex = new Dictionary<int, VBO>
{
{0, Vertex},
{1, UVs},
{2, Normals}
};
}
/// <inheritdoc />
protected override bool AutoCompile { get; } = true;
@ -17,61 +33,50 @@ namespace SM.OGL.Mesh
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
/// <summary>
/// The primitive type, that determinants how the mesh is drawn.
/// <para>Default: Triangles</para>
/// The primitive type, that determinants how the mesh is drawn.
/// <para>Default: Triangles</para>
/// </summary>
public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles;
/// <summary>
/// Contains the vertices for the mesh.
/// Contains the vertices for the mesh.
/// </summary>
public virtual VBO Vertex { get; }
/// <summary>
/// Contains the texture coords for the mesh.
/// Contains the texture coords for the mesh.
/// </summary>
public virtual VBO UVs { get; }
/// <summary>
/// Contains the normals for the mesh.
/// Contains the normals for the mesh.
/// </summary>
public virtual VBO Normals { get; }
/// <summary>
/// Represents the bounding box.
/// Represents the bounding box.
/// </summary>
public virtual BoundingBox BoundingBox { get; } = new BoundingBox();
/// <summary>
/// Connects the different buffer objects with ids.
/// Connects the different buffer objects with ids.
/// </summary>
public Dictionary<int, VBO> AttribDataIndex { get; }
/// <summary>
/// Stores indices for a more performance friendly method to draw objects.
/// Stores indices for a more performance friendly method to draw objects.
/// </summary>
public virtual int[] Indices { get; set; }
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
AttribDataIndex = new Dictionary<int, VBO>()
{
{0, Vertex},
{1, UVs},
{2, Normals},
};
}
/// <inheritdoc />
public override void Compile()
{
_id = GL.GenVertexArray();
GL.BindVertexArray(_id);
if (AttribDataIndex == null) throw new Exception("[Critical] The model requires a attribute data index.");
foreach (KeyValuePair<int, VBO> kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key);
foreach (var kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key);
GL.BindVertexArray(0);
}

View file

@ -1,51 +1,78 @@
using System;
#region usings
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
#endregion
namespace SM.OGL.Mesh
{
/// <summary>
/// Represents a Vertex Buffer Object used for meshes.
/// Represents a Vertex Buffer Object used for meshes.
/// </summary>
public class VBO : List<float>
{
/// <summary>
/// Specifies the expected usage pattern of the data store.
/// Specifies the expected usage pattern of the data store.
/// </summary>
public BufferUsageHint BufferUsageHint;
/// <summary>
/// Specifies the data type of each component in the array.
/// </summary>
public VertexAttribPointerType PointerType;
/// <summary>
/// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.
/// </summary>
public int PointerSize;
/// <summary>
/// Normalise floats?
/// Normalise floats?
/// </summary>
public bool Normalised;
/// <summary>
/// Specifies the byte offset between consecutive generic vertex attributes.
/// </summary>
public int PointerStride;
/// <summary>
/// Specifies a offset of the first component of the first generic vertex attribute in the array in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target.
/// Specifies a offset of the first component of the first generic vertex attribute in the array in the data store of
/// the buffer currently bound to the GL_ARRAY_BUFFER target.
/// </summary>
public int PointerOffset;
/// <summary>
/// Generates a VBO for inserting mesh data.
/// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.
/// </summary>
/// <param name="bufferUsageHint">Specifies the expected usage pattern of the data store. <para>Default: StaticDraw</para></param>
/// <param name="pointerType">Specifies the data type of each component in the array. <para>Default: Float</para></param>
/// <param name="pointerSize">Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. <para>Default: 3</para></param>
/// <param name="pointerStride">Specifies the byte offset between consecutive generic vertex attributes. <para>Default: 0</para></param>
/// <param name="pointerOffset">Specifies a offset of the first component of the first generic vertex attribute in the array in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target. <para>Default: 0</para></param>
/// <param name="normalised">Normalise floats? <para>Default: false</para></param>
public int PointerSize;
/// <summary>
/// Specifies the byte offset between consecutive generic vertex attributes.
/// </summary>
public int PointerStride;
/// <summary>
/// Specifies the data type of each component in the array.
/// </summary>
public VertexAttribPointerType PointerType;
/// <summary>
/// Generates a VBO for inserting mesh data.
/// </summary>
/// <param name="bufferUsageHint">
/// Specifies the expected usage pattern of the data store.
/// <para>Default: StaticDraw</para>
/// </param>
/// <param name="pointerType">
/// Specifies the data type of each component in the array.
/// <para>Default: Float</para>
/// </param>
/// <param name="pointerSize">
/// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.
/// <para>Default: 3</para>
/// </param>
/// <param name="pointerStride">
/// Specifies the byte offset between consecutive generic vertex attributes.
/// <para>Default: 0</para>
/// </param>
/// <param name="pointerOffset">
/// Specifies a offset of the first component of the first generic vertex attribute in the
/// array in the data store of the buffer currently bound to the GL_ARRAY_BUFFER target.
/// <para>Default: 0</para>
/// </param>
/// <param name="normalised">
/// Normalise floats?
/// <para>Default: false</para>
/// </param>
public VBO(BufferUsageHint bufferUsageHint = BufferUsageHint.StaticDraw,
VertexAttribPointerType pointerType = VertexAttribPointerType.Float, int pointerSize = 3,
int pointerStride = 0, int pointerOffset = 0, bool normalised = false)
@ -59,56 +86,95 @@ namespace SM.OGL.Mesh
}
/// <summary>
/// Adds two values to the VBO.
/// Adds two values to the VBO.
/// </summary>
public void Add(float x, float y) => AddRange(new[] {x,y});
/// <summary>
/// Adds three values to the VBO.
/// </summary>
public void Add(float x, float y, float z) => AddRange(new[] {x,y,z});
/// <summary>
/// Adds four values to the VBO.
/// </summary>
public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w});
/// <summary>
/// Adds a Vector2.
/// </summary>
public void Add(Vector2 vector) => Add(vector.X, vector.Y);
/// <summary>
/// Adds a Vector2 and a value.
/// </summary>
public void Add(Vector2 vector, float z) => Add(vector.X, vector.Y, z);
/// <summary>
/// Adds a Vector2 and two values.
/// </summary>
public void Add(Vector2 vector, float z, float w) => Add(vector.X, vector.Y, z, w);
/// <summary>
/// Adds a Vector3.
/// </summary>
public void Add(Vector3 vector) => Add(vector.X, vector.Y, vector.Z);
/// <summary>
/// Adds a Vector3 and a value.
/// </summary>
public void Add(Vector3 vector, float w) => Add(vector.X, vector.Y, vector.Z, w);
/// <summary>
/// Adds a vector4.
/// </summary>
/// <param name="vector"></param>
public void Add(Vector4 vector) => Add(vector.X, vector.Y, vector.Z, vector.W);
/// <summary>
/// Adds a color.
/// </summary>
public void Add(Color4 color) => Add(color.R, color.G, color.B, color.A);
public void Add(float x, float y)
{
AddRange(new[] {x, y});
}
/// <summary>
/// Binds the buffer to the active VAO.
/// Adds three values to the VBO.
/// </summary>
public void Add(float x, float y, float z)
{
AddRange(new[] {x, y, z});
}
/// <summary>
/// Adds four values to the VBO.
/// </summary>
public void Add(float x, float y, float z, float w)
{
AddRange(new[] {x, y, z, w});
}
/// <summary>
/// Adds a Vector2.
/// </summary>
public void Add(Vector2 vector)
{
Add(vector.X, vector.Y);
}
/// <summary>
/// Adds a Vector2 and a value.
/// </summary>
public void Add(Vector2 vector, float z)
{
Add(vector.X, vector.Y, z);
}
/// <summary>
/// Adds a Vector2 and two values.
/// </summary>
public void Add(Vector2 vector, float z, float w)
{
Add(vector.X, vector.Y, z, w);
}
/// <summary>
/// Adds a Vector3.
/// </summary>
public void Add(Vector3 vector)
{
Add(vector.X, vector.Y, vector.Z);
}
/// <summary>
/// Adds a Vector3 and a value.
/// </summary>
public void Add(Vector3 vector, float w)
{
Add(vector.X, vector.Y, vector.Z, w);
}
/// <summary>
/// Adds a vector4.
/// </summary>
/// <param name="vector"></param>
public void Add(Vector4 vector)
{
Add(vector.X, vector.Y, vector.Z, vector.W);
}
/// <summary>
/// Adds a color.
/// </summary>
public void Add(Color4 color)
{
Add(color.R, color.G, color.B, color.A);
}
/// <summary>
/// Binds the buffer to the active VAO.
/// </summary>
/// <param name="attribID">The id for the attribute.</param>
internal void BindBuffer(int attribID)
{
float[] data = ToArray();
var data = ToArray();
int buffer = GL.GenBuffer();
var buffer = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
GL.BufferData(BufferTarget.ArrayBuffer, data.Length * sizeof(float), data, BufferUsageHint);