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:
parent
c4a0847567
commit
617a7ef044
39 changed files with 598 additions and 66 deletions
|
|
@ -32,10 +32,10 @@ namespace SM.OGL
|
|||
GL.Enable(EnableCap.DebugOutput);
|
||||
GL.Enable(EnableCap.DebugOutputSynchronous);
|
||||
}
|
||||
catch
|
||||
catch (AccessViolationException)
|
||||
{
|
||||
Console.WriteLine("Enableing proper GLDebugging failed. \n" +
|
||||
"Often it fails, because your hardware doesn't provied proper OpenGL 4 \n" +
|
||||
"Often it fails, because your hardware doesn't provide proper OpenGL 4 \n" +
|
||||
" or KHR_debug extension support.");
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace SM.OGL
|
|||
{
|
||||
get
|
||||
{
|
||||
if (AutoCompile && _id < 0) Compile();
|
||||
if (AutoCompile && !WasCompiled) Compile();
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ namespace SM.OGL
|
|||
|
||||
public void Name(string name)
|
||||
{
|
||||
GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
|
||||
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
|
||||
}
|
||||
|
||||
public static implicit operator int(GLObject glo) => glo.ID;
|
||||
|
|
|
|||
33
SMCode/SM.OGL/GLSystem.cs
Normal file
33
SMCode/SM.OGL/GLSystem.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System.Linq;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace SM.OGL
|
||||
{
|
||||
public class GLSystem
|
||||
{
|
||||
private static bool _init = false;
|
||||
|
||||
public static Version DeviceVersion { get; private set; }
|
||||
public static Version ForcedVersion { get; set; } = new Version();
|
||||
|
||||
public static Version ShadingVersion { get; private set; }
|
||||
public static string[] Extensions { get; private set; }
|
||||
|
||||
public static bool Debugging { get; private set; }
|
||||
|
||||
public static void INIT_SYSTEM()
|
||||
{
|
||||
if (_init) return;
|
||||
|
||||
DeviceVersion = Version.CreateGLVersion(GL.GetString(StringName.Version));
|
||||
|
||||
ShadingVersion = Version.CreateGLVersion(GL.GetString(StringName.ShadingLanguageVersion));
|
||||
Extensions = GL.GetString(StringName.Extensions).Split(' ');
|
||||
|
||||
Debugging = Extensions.Contains("KHR_debug");
|
||||
if (Debugging) GLDebugging.EnableDebugging();
|
||||
|
||||
_init = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
SMCode/SM.OGL/Mesh/BoundingBox.cs
Normal file
40
SMCode/SM.OGL/Mesh/BoundingBox.cs
Normal 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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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>()
|
||||
{
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,9 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="GLDebugging.cs" />
|
||||
<Compile Include="GLObject.cs" />
|
||||
<Compile Include="Mesh\Mesh.cs" />
|
||||
<Compile Include="GLSystem.cs" />
|
||||
<Compile Include="Mesh\BoundingBox.cs" />
|
||||
<Compile Include="Mesh\GenericMesh.cs" />
|
||||
<Compile Include="Mesh\TypeDefinition.cs" />
|
||||
<Compile Include="Mesh\VBO.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
@ -56,6 +58,7 @@
|
|||
<Compile Include="Shaders\Uniform.cs" />
|
||||
<Compile Include="Shaders\UniformCollection.cs" />
|
||||
<Compile Include="Texture\TextureBase.cs" />
|
||||
<Compile Include="Version.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -48,10 +48,22 @@ namespace SM.OGL.Shaders
|
|||
Load();
|
||||
}
|
||||
|
||||
public void DrawObject(Mesh.Mesh mesh, int amount, bool bindVAO = false)
|
||||
public void DrawObject(Mesh.GenericMesh mesh, int amount, bool bindVAO = false)
|
||||
{
|
||||
if (bindVAO) GL.BindVertexArray(mesh);
|
||||
GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count, amount);
|
||||
|
||||
if (mesh.Indices != null)
|
||||
GL.DrawElementsInstanced(mesh.PrimitiveType, 0, DrawElementsType.UnsignedInt, mesh.Indices, amount);
|
||||
else
|
||||
GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count, amount);
|
||||
}
|
||||
|
||||
protected void CleanUp()
|
||||
{
|
||||
Uniforms.NextTexture = 0;
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
SMCode/SM.OGL/Version.cs
Normal file
31
SMCode/SM.OGL/Version.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
namespace SM.OGL
|
||||
{
|
||||
public struct Version
|
||||
{
|
||||
public int MajorVersion;
|
||||
public int MinorVersion;
|
||||
|
||||
public Version(int majorVersion, int minorVersion)
|
||||
{
|
||||
MinorVersion = minorVersion;
|
||||
MajorVersion = majorVersion;
|
||||
}
|
||||
|
||||
public Version(string version)
|
||||
{
|
||||
string[] splits = version.Trim().Split(new []{'.'}, 2);
|
||||
MajorVersion = int.Parse(splits[0]);
|
||||
MinorVersion = int.Parse(splits[1]);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{MajorVersion}.{MinorVersion}";
|
||||
}
|
||||
|
||||
public static Version CreateGLVersion(string version)
|
||||
{
|
||||
return new Version(version.Substring(0, 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue