+ AxisHelper

~ Transformation can now set to be ignored. (Sending a Identity, when requested)
~ Changed how Meshes store Attributes
This commit is contained in:
Michel Fedde 2020-12-13 13:03:57 +01:00
parent 0895c600cf
commit 2e7051d800
14 changed files with 146 additions and 30 deletions

View file

@ -13,16 +13,17 @@ namespace SM.OGL.Mesh
/// </summary>
public abstract class GenericMesh : GLObject
{
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh()
{
AttribDataIndex = new Dictionary<int, VBO>
Attributes = new MeshAttributeList()
{
{0, Vertex},
{1, UVs},
{2, Normals}
{0, "vertex", Vertex},
{1, "uv", UVs},
{2, "normal", Normals}
};
}
@ -61,7 +62,7 @@ namespace SM.OGL.Mesh
/// <summary>
/// Connects the different buffer objects with ids.
/// </summary>
public Dictionary<int, VBO> AttribDataIndex { get; }
public MeshAttributeList Attributes { get; }
/// <summary>
/// Stores indices for a more performance friendly method to draw objects.
@ -74,9 +75,9 @@ namespace SM.OGL.Mesh
_id = GL.GenVertexArray();
GL.BindVertexArray(_id);
if (AttribDataIndex == null) throw new Exception("[Critical] The model requires a attribute data index.");
if (Attributes == null) throw new Exception("[Critical] The model requires attributes.");
foreach (var kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key);
foreach (var kvp in Attributes) kvp.ConnectedVBO?.BindBuffer(kvp.Index);
GL.BindVertexArray(0);
}

View file

@ -0,0 +1,16 @@
namespace SM.OGL.Mesh
{
public struct MeshAttribute
{
public int Index;
public string Name;
public VBO ConnectedVBO;
public MeshAttribute(int index, string name, VBO buffer)
{
Index = index;
Name = name;
ConnectedVBO = buffer;
}
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace SM.OGL.Mesh
{
public class MeshAttributeList : List<MeshAttribute>
{
public VBO this[string name]
{
get
{
for (int i = 0; i < Count; i++)
{
if (this[i].Name == name)
{
return this[i].ConnectedVBO;
}
}
return null;
}
}
public void Add(int id, string name, VBO vbo)
{
if (vbo == null) return;
Add(new MeshAttribute(id, name, vbo));
}
}
}