15.09.2020

Everything currently don't work / can't be tested.

+ Generic Shader-Implermentation
+ Mesh-System + Plate-Mesh
This commit is contained in:
Michel Fedde 2020-09-15 22:16:18 +02:00
parent 551d393ac2
commit 421d03f91d
24 changed files with 726 additions and 4 deletions

44
SM.Core/Mesh/Mesh.cs Normal file
View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Mesh
{
public class Mesh : GLObject
{
public static int BufferSizeMultiplier = 3;
protected override bool AutoCompile { get; } = true;
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles;
public virtual VBO Vertex { get; }
public virtual VBO UVs { get; }
public virtual VBO Normals { get; }
public virtual Dictionary<int, VBO> AttribDataIndex { get; }
public Mesh()
{
AttribDataIndex = new Dictionary<int, VBO>()
{
{0, Vertex},
{1, UVs},
{2, Normals},
};
}
protected 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);
GL.BindVertexArray(0);
}
}
}

View file

@ -0,0 +1,14 @@
using System;
namespace SM.OGL.Mesh
{
public struct TypeDefinition
{
internal int PointerSize;
public TypeDefinition(int pointerSize)
{
PointerSize = pointerSize;
}
}
}

34
SM.Core/Mesh/VBO.cs Normal file
View file

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Mesh
{
public class VBO : List<float>
{
public BufferUsageHint BufferUsageHint = BufferUsageHint.StaticDraw;
public VertexAttribPointerType PointerType = VertexAttribPointerType.Float;
public int PointerSize = 3;
public bool Normalised = false;
public int PointerStride = 0;
public int PointerOffset = 0;
public void Add(float x, float y) => AddRange(new[] {x,y});
public void Add(float x, float y, float z) => AddRange(new[] {x,y,z});
public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w});
public void BindBuffer(int attribID)
{
float[] data = ToArray();
int buffer = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
GL.BufferData(BufferTarget.ArrayBuffer, data.Length * Mesh.BufferSizeMultiplier, data, BufferUsageHint);
GL.VertexAttribPointer(attribID, PointerSize, PointerType, Normalised, PointerStride, PointerOffset);
GL.EnableVertexAttribArray(attribID);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
}
}
}