Fixed Warnings and applied informations

This commit is contained in:
Michel Fedde 2021-03-26 13:22:19 +01:00
parent ee732240f7
commit bf1118c261
7 changed files with 104 additions and 18 deletions

View file

@ -82,14 +82,14 @@ namespace SM.Base
/// <summary>
/// Presets for the log targets.
/// </summary>
public static Dictionary<LogTarget, string> Preset = new Dictionary<LogTarget, string>
public static Dictionary<LogTarget, string> Preset = new()
{
{LogTarget.Console, "[%type%] %msg%"},
{LogTarget.Debugger, "[%type%] %msg%"},
{LogTarget.File, "<%date%, %time%> [%type%] %msg%"}
};
private static readonly Dictionary<LogType, ConsoleColor> Colors = new Dictionary<LogType, ConsoleColor>
private static readonly Dictionary<LogType, ConsoleColor> Colors = new()
{
{LogType.Info, ConsoleColor.Green},
{LogType.Warning, ConsoleColor.Yellow},

View file

@ -113,11 +113,9 @@ namespace SM.Base.Window
/// <summary>
/// This creates a finished setup for a framebuffer.
/// </summary>
/// <param name="multisamples"></param>
/// <returns></returns>
public Framebuffer CreateWindowFramebuffer(int multisamples = 0, PixelInformation? pixelInformation = null, bool depth = true)
{
Framebuffer framebuffer = new Framebuffer(ConnectedWindow);
Framebuffer framebuffer = new(ConnectedWindow);
framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples));
if (depth)

View file

@ -26,7 +26,7 @@ namespace SM.OGL.Framebuffer
/// <summary>
/// Represents the screen buffer.
/// </summary>
public static readonly Framebuffer Screen = new Framebuffer
public static readonly Framebuffer Screen = new()
{
_id = 0,
CanCompile = false,
@ -55,6 +55,11 @@ namespace SM.OGL.Framebuffer
/// </summary>
public Dictionary<RenderbufferAttachment, int> RenderbufferAttachments { get; } = new Dictionary<RenderbufferAttachment, int>();
/// <summary>
/// Gets the color attachment with the specified color name.
/// </summary>
/// <param name="colorName"></param>
/// <returns></returns>
public ColorAttachment this[string colorName] => ColorAttachments[colorName];
/// <summary>
@ -204,7 +209,7 @@ namespace SM.OGL.Framebuffer
/// <returns></returns>
public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
{
Framebuffer buffer = new Framebuffer()
Framebuffer buffer = new()
{
CanCompile = false,
ReportAsNotCompiled = true

View file

@ -14,7 +14,7 @@ namespace SM.OGL
/// </summary>
public abstract class GLObject
{
private static readonly List<GLObject> _disposableObjects = new List<GLObject>();
private static readonly List<GLObject> _disposableObjects = new();
private string _name = "";

View file

@ -10,26 +10,76 @@ using System.Threading.Tasks;
namespace SM.OGL.Mesh
{
/// <summary>
/// Represents a vertex buffer object in C#.
/// </summary>
public abstract class VBO : GLObject
{
private float[] _floatArray;
/// <inheritdoc/>
protected override bool AutoCompile { get => false; set { return; } }
/// <inheritdoc/>
public override ObjectLabelIdentifier TypeIdentifier => ObjectLabelIdentifier.Buffer;
/// <summary>
/// If false, it will not compile the vertex buffer.
/// <para>Default: true</para>
/// </summary>
public bool Active { get; set; } = true;
/// <summary>
/// This determents if the object can be updated.
/// </summary>
public bool CanBeUpdated { get; set; } = true;
/// <summary>
/// Specifies whether fixed-point data values should be normalized (true) or converted directly as fixed-point values (false) when they are accessed.
/// </summary>
public bool Normalized { get; protected set; }
/// <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. The initial value is 0.
/// </summary>
public int PointerOffset { get; protected set; }
/// <summary>
/// Specifies the byte offset between consecutive generic vertex attributes. If stride is 0, the generic vertex attributes are understood to be tightly packed in the array. The initial value is 0.
/// </summary>
public int PointerStride { get; protected set; }
/// <summary>
/// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. Additionally, the symbolic constant GL_BGRA is accepted by glVertexAttribPointer.
/// <para>This value gets usually set by the data type.</para>
/// </summary>
public int PointerSize { get; protected set; }
/// <summary>
/// Specifies the expected usage pattern of the data store.
/// </summary>
public BufferUsageHint UsageHint { get; protected set; }
/// <summary>
/// Specifies the data type of each component in the array.
/// <para>This value gets usually set by the data type of the class.</para>
/// </summary>
public VertexAttribPointerType PointerType { get; protected set; }
/// <summary>
/// The shader id for the mesh.
/// </summary>
public int AttributeID { get; internal set; }
/// <summary>
/// The amount of data.
/// </summary>
public abstract int Count { get; }
/// <summary>
/// The amount of data, when the mesh was compiled.
/// </summary>
public int CompiledCount { get; private set; }
/// <summary>
/// Creates a vertex buffer object.
/// </summary>
/// <param name="bufferUsageHint">Specifies the expected usage pattern of the data store.</param>
/// <param name="pointerStride">Specifies the byte offset between consecutive generic vertex attributes. If stride is 0, the generic vertex attributes are understood to be tightly packed in the array. The initial value is 0.</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. The initial value is 0.</param>
/// <param name="normalised">Specifies whether fixed-point data values should be normalized (true) or converted directly as fixed-point values (false) when they are accessed.</param>
public VBO(BufferUsageHint bufferUsageHint = BufferUsageHint.StaticDraw,
int pointerStride = 0, int pointerOffset = 0, bool normalised = false)
@ -40,6 +90,7 @@ namespace SM.OGL.Mesh
Normalized = normalised;
}
/// <inheritdoc />
public override void Compile()
{
base.Compile();
@ -47,6 +98,7 @@ namespace SM.OGL.Mesh
if (!Active) return;
float[] data = ToFloat();
CompiledCount = data.Length;
_id = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, _id);
@ -58,9 +110,14 @@ namespace SM.OGL.Mesh
CanBeUpdated = false;
}
/// <summary>
/// Updates the buffer object.
/// </summary>
public void Update()
{
float[] data = GetFloats();
if (data.Length > CompiledCount)
throw new NotSupportedException("Updating the amount of data is not yet supported.");
GL.BindBuffer(BufferTarget.ArrayBuffer, _id);
GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, data.Length * sizeof(float), data);
@ -68,12 +125,17 @@ namespace SM.OGL.Mesh
CanBeUpdated = false;
}
/// <inheritdoc/>
public override void Dispose()
{
GL.DeleteBuffer(_id);
base.Dispose();
}
/// <summary>
/// Gets the data stored, in a float array.
/// </summary>
/// <returns></returns>
public float[] GetFloats()
{
if (_floatArray == null || CanBeUpdated)
@ -84,13 +146,18 @@ namespace SM.OGL.Mesh
return _floatArray;
}
/// <summary>
/// Calculates the data stored in a float array.
/// </summary>
/// <returns></returns>
protected abstract float[] ToFloat();
}
/// <inheritdoc/>
public class VBO<TType> : VBO, IEnumerable<TType>
where TType : struct
{
static Dictionary<Type, Tuple<int, VertexAttribPointerType>> _pointerSizes = new Dictionary<Type, Tuple<int, VertexAttribPointerType>>()
static readonly Dictionary<Type, Tuple<int, VertexAttribPointerType>> _pointerSizes = new()
{
{ typeof(float), new Tuple<int, VertexAttribPointerType>(1, VertexAttribPointerType.Float) },
{ typeof(Vector2), new Tuple<int, VertexAttribPointerType>(2, VertexAttribPointerType.Float) },
@ -98,10 +165,21 @@ namespace SM.OGL.Mesh
{ typeof(Vector4), new Tuple<int, VertexAttribPointerType>(4, VertexAttribPointerType.Float) },
{ typeof(Color4), new Tuple<int, VertexAttribPointerType>(4, VertexAttribPointerType.Float) },
};
private List<TType> _values = new List<TType>();
private readonly List<TType> _values = new();
/// <inheritdoc/>
public override int Count => _values.Count;
/// <summary>
/// Exposes the indexer of the list to the public.
/// </summary>
public TType this[int index]
{
get => _values[index];
set { _values[index] = value; CanBeUpdated = true; }
}
/// <inheritdoc/>
public VBO(BufferUsageHint bufferUsageHint = BufferUsageHint.StaticDraw,
int pointerStride = 0, int pointerOffset = 0, bool normalised = false) : base(bufferUsageHint, pointerStride, pointerOffset, normalised)
{
@ -112,26 +190,36 @@ namespace SM.OGL.Mesh
PointerType = _pointerSizes[typeof(TType)].Item2;
}
/// <summary>
/// Adds a new value to the list.
/// </summary>
/// <param name="value"></param>
public void Add(TType value)
{
_values.Add(value);
CanBeUpdated = true;
}
/// <summary>
/// Removes the object at that position.
/// </summary>
/// <param name="pos"></param>
public void RemoveAt(int pos)
{
_values.RemoveAt(pos);
CanBeUpdated = true;
}
/// <inheritdoc/>
public IEnumerator<TType> GetEnumerator()
{
return _values.GetEnumerator();
}
/// <inheritdoc/>
protected override float[] ToFloat()
{
List<float> floats = new List<float>();
List<float> floats = new();
foreach (TType value in _values)
{

View file

@ -20,7 +20,6 @@ namespace SM_TEST
class Program
{
static Scene scene;
private static Font font;
private static GLWindow window;
private static PolyLine line;
static void Main(string[] args)
@ -56,14 +55,10 @@ namespace SM_TEST
if (SM.Base.Controls.Mouse.LeftClick)
line.Vertex.Add(Vector3.Zero);
line.Vertex.RemoveAt(1);
line.Vertex.Add(new Vector3(Mouse2D.InWorld(window.ViewportCamera as Camera)));
line.Vertex[1] = new Vector3(Mouse2D.InWorld(window.ViewportCamera as Camera));
line.Update();
}
private static void WindowOnLoad(IGenericWindow window)
{ }
}
}