26.09.2020

+ Added BoundingBoxes to Meshes
+ SM.Base.Objects.Mesh
+ Vertex Colors
+ ShowItem Collections + 2D Equlivant
+ Default Class to store Default Values
+ SM.OGL.GLSystem to store OpenGL specific system information

+ SM2D.DrawColor // not working yet
+ SM2D.DrawComplex to allow access to all features.
+ SM2D.DrawPolygon
+ Polygon system // for 2D only yet

~ Renamed SM.OGL.Mesh to SM.OGL.GenericMesh
This commit is contained in:
Michel Fedde 2020-09-26 23:40:16 +02:00
parent c4a0847567
commit 617a7ef044
39 changed files with 598 additions and 66 deletions

View file

@ -0,0 +1,40 @@
using System;
using System.Runtime.CompilerServices;
using OpenTK;
namespace SM.OGL.Mesh
{
public class BoundingBox
{
public Vector3 Max = Vector3.Zero;
public Vector3 Min = Vector3.Zero;
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 BoundingBox() {}
public BoundingBox(Vector3 min, Vector3 max)
{
Min = min;
Max = max;
}
public void Update(Vector2 vector)
{
for (int i = 0; i < 2; i++)
{
Min[i] = Math.Min(Min[i], vector[i]);
Max[i] = Math.Max(Min[i], vector[i]);
}
}
public void Update(Vector3 vector)
{
for (int i = 0; i < 3; i++)
{
Min[i] = Math.Min(Min[i], vector[i]);
Max[i] = Math.Max(Min[i], vector[i]);
}
}
}
}

View file

@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
using Buffer = OpenTK.Graphics.OpenGL4.Buffer;
namespace SM.OGL.Mesh
{
public class Mesh : GLObject
public abstract class GenericMesh : GLObject
{
public static int BufferSizeMultiplier = 3;
protected override bool AutoCompile { get; } = true;
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
@ -17,9 +16,13 @@ namespace SM.OGL.Mesh
public virtual VBO UVs { get; }
public virtual VBO Normals { get; }
public virtual BoundingBox BoundingBox { get; } = new BoundingBox();
public virtual Dictionary<int, VBO> AttribDataIndex { get; }
public Mesh()
public virtual int[] Indices { get; set; }
protected GenericMesh()
{
AttribDataIndex = new Dictionary<int, VBO>()
{

View file

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Mesh
@ -29,6 +31,12 @@ namespace SM.OGL.Mesh
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 Add(Vector2 vector) => Add(vector.X, vector.Y);
public void Add(Vector2 vector, float z) => Add(vector.X, vector.Y, z);
public void Add(Vector2 vector, float z, float w) => Add(vector.X, vector.Y, z, w);
public void Add(Vector3 vector) => Add(vector.X, vector.Y, vector.Z);
public void Add(Vector4 vector) => Add(vector.X, vector.Y, vector.Z, vector.W);
public void Add(Color4 color) => Add(color.R, color.G, color.B, color.A);
public void BindBuffer(int attribID)
{
@ -36,7 +44,7 @@ namespace SM.OGL.Mesh
int buffer = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
GL.BufferData(BufferTarget.ArrayBuffer, data.Length * Mesh.BufferSizeMultiplier, data, BufferUsageHint);
GL.BufferData(BufferTarget.ArrayBuffer, data.Length * sizeof(float), data, BufferUsageHint);
GL.VertexAttribPointer(attribID, PointerSize, PointerType, Normalised, PointerStride, PointerOffset);
GL.EnableVertexAttribArray(attribID);