diff --git a/SMCode/SM.OGL/GLDebugging.cs b/SMCode/SM.OGL/GLDebugging.cs
index 4cc20a0..94b4fbd 100644
--- a/SMCode/SM.OGL/GLDebugging.cs
+++ b/SMCode/SM.OGL/GLDebugging.cs
@@ -7,11 +7,17 @@ using OpenTK.Platform.Egl;
namespace SM.OGL
{
+ ///
+ /// Contains everything that is needed to properly debug OpenGL
+ ///
public static class GLDebugging
{
private static DebugProc _debugProc = DebugCallback;
private static GCHandle _debugGcHandle;
+ ///
+ /// A action that is performed, when a OpenGL-error occurs.
+ ///
public static Action DebugAction = DefaultDebugAction;
[DebuggerStepThrough]
@@ -22,6 +28,9 @@ namespace SM.OGL
DebugAction?.Invoke(source, type, severity, msg);
}
+ ///
+ /// Enables the debugging.
+ ///
public static void EnableDebugging()
{
try
@@ -41,6 +50,13 @@ namespace SM.OGL
}
}
+ ///
+ /// Default action for 'DebugAction'.
+ ///
+ ///
+ ///
+ ///
+ ///
public static void DefaultDebugAction(DebugSource source, DebugType type, DebugSeverity severity, string msg)
{
Console.WriteLine($"{severity}, {type}, {source} -> {msg}");
diff --git a/SMCode/SM.OGL/GLObject.cs b/SMCode/SM.OGL/GLObject.cs
index fd16793..ff4f57b 100644
--- a/SMCode/SM.OGL/GLObject.cs
+++ b/SMCode/SM.OGL/GLObject.cs
@@ -2,13 +2,29 @@
namespace SM.OGL
{
+ ///
+ /// Specifies default object behaviour.
+ ///
public abstract class GLObject
{
+ ///
+ /// Contains the OpenGL ID
+ ///
protected int _id = -1;
+ ///
+ /// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
+ ///
protected virtual bool AutoCompile { get; } = false;
+ ///
+ /// Checks if the object was compiled.
+ ///
public bool WasCompiled => _id > 0;
+ ///
+ /// Returns the id for this object.
+ /// It will auto compile, if needed and allowed.
+ ///
public virtual int ID
{
get
@@ -18,18 +34,32 @@ namespace SM.OGL
}
}
+ ///
+ /// Identifies the object.
+ ///
public abstract ObjectLabelIdentifier TypeIdentifier { get; }
+ ///
+ /// The action, that is called, when "ID" tries to compile something.
+ ///
protected virtual void Compile()
{
}
+ ///
+ /// Names the object for debugging.
+ ///
+ ///
public void Name(string name)
{
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
}
+ ///
+ /// Returns the ID for the object.
+ ///
+ ///
public static implicit operator int(GLObject glo) => glo.ID;
}
}
\ No newline at end of file
diff --git a/SMCode/SM.OGL/GLSystem.cs b/SMCode/SM.OGL/GLSystem.cs
index 5a41b89..ab4e7b2 100644
--- a/SMCode/SM.OGL/GLSystem.cs
+++ b/SMCode/SM.OGL/GLSystem.cs
@@ -3,18 +3,42 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL
{
+ ///
+ /// Contains data about the current OpenGL system.
+ ///
public class GLSystem
{
private static bool _init = false;
+ ///
+ /// Contains the device version of OpenGL.
+ ///
public static Version DeviceVersion { get; private set; }
+ ///
+ /// Get/Sets the forced version for OpenGL.
+ /// Needs to be set before init a window.
+ ///
public static Version ForcedVersion { get; set; } = new Version();
+ ///
+ /// Contains the shader version for GLSL.
+ ///
public static Version ShadingVersion { get; private set; }
+ ///
+ /// Contains the extensions for OpenGL.
+ ///
public static string[] Extensions { get; private set; }
+ ///
+ /// Checks if proper Debugging is for this system available.
+ /// Determent, if the system has the "KHR_debug"-extension.
+ ///
public static bool Debugging { get; private set; }
+ ///
+ /// Initialize the system data.
+ /// Does nothing after the data was already collected.
+ ///
public static void INIT_SYSTEM()
{
if (_init) return;
diff --git a/SMCode/SM.OGL/Mesh/BoundingBox.cs b/SMCode/SM.OGL/Mesh/BoundingBox.cs
index db765a8..4284161 100644
--- a/SMCode/SM.OGL/Mesh/BoundingBox.cs
+++ b/SMCode/SM.OGL/Mesh/BoundingBox.cs
@@ -4,21 +4,49 @@ using OpenTK;
namespace SM.OGL.Mesh
{
+ ///
+ /// Contains information about bounding boxes of meshes
+ ///
public class BoundingBox
{
- public Vector3 Max = Vector3.Zero;
+ ///
+ /// The minimum corner.
+ ///
public Vector3 Min = Vector3.Zero;
+ ///
+ /// The maximum corner.
+ ///
+ public Vector3 Max = Vector3.Zero;
+ ///
+ /// Returns specific configurations of corners
+ ///
+ /// If true, it takes the X-value of maximum, otherwise the minimum.
+ /// If true, it takes the Y-value of maximum, otherwise the minimum.
+ /// If true, it takes the Z-value of maximum, otherwise the minimum.
+ ///
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);
+ ///
+ /// Empty constructor
+ ///
public BoundingBox() {}
+ ///
+ /// Creates the bounding box with predefined min and max values
+ ///
+ ///
+ ///
public BoundingBox(Vector3 min, Vector3 max)
{
Min = min;
Max = max;
}
+ ///
+ /// Updates the bounding box.
+ ///
+ ///
public void Update(Vector2 vector)
{
for (int i = 0; i < 2; i++)
@@ -28,6 +56,10 @@ namespace SM.OGL.Mesh
}
}
+ ///
+ /// Updates the bounding box.
+ ///
+ ///
public void Update(Vector3 vector)
{
for (int i = 0; i < 3; i++)
diff --git a/SMCode/SM.OGL/Mesh/GenericMesh.cs b/SMCode/SM.OGL/Mesh/GenericMesh.cs
index 4bee19a..13c004b 100644
--- a/SMCode/SM.OGL/Mesh/GenericMesh.cs
+++ b/SMCode/SM.OGL/Mesh/GenericMesh.cs
@@ -5,23 +5,54 @@ using Buffer = OpenTK.Graphics.OpenGL4.Buffer;
namespace SM.OGL.Mesh
{
+ ///
+ /// Contains information for meshes
+ ///
public abstract class GenericMesh : GLObject
{
+ ///
protected override bool AutoCompile { get; } = true;
+
+ ///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
+ ///
+ /// The primitive type, that determinants how the mesh is drawn.
+ /// Default: Triangles
+ ///
public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles;
+ ///
+ /// Contains the vertices for the mesh.
+ ///
public virtual VBO Vertex { get; }
+ ///
+ /// Contains the texture coords for the mesh.
+ ///
public virtual VBO UVs { get; }
+ ///
+ /// Contains the normals for the mesh.
+ ///
public virtual VBO Normals { get; }
+ ///
+ /// Represents the bounding box.
+ ///
public virtual BoundingBox BoundingBox { get; } = new BoundingBox();
- public virtual Dictionary AttribDataIndex { get; }
+ ///
+ /// Connects the different buffer objects with ids.
+ ///
+ protected Dictionary AttribDataIndex { get; }
+ ///
+ /// Stores indices for a more performance friendly method to draw objects.
+ ///
public virtual int[] Indices { get; set; }
+ ///
+ /// Generates the AttribDataIndex
+ ///
protected GenericMesh()
{
AttribDataIndex = new Dictionary()
@@ -32,6 +63,7 @@ namespace SM.OGL.Mesh
};
}
+ ///
protected override void Compile()
{
_id = GL.GenVertexArray();
diff --git a/SMCode/SM.OGL/Mesh/TypeDefinition.cs b/SMCode/SM.OGL/Mesh/TypeDefinition.cs
deleted file mode 100644
index 901efc6..0000000
--- a/SMCode/SM.OGL/Mesh/TypeDefinition.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-
-namespace SM.OGL.Mesh
-{
- public struct TypeDefinition
- {
- internal int PointerSize;
-
- public TypeDefinition(int pointerSize)
- {
- PointerSize = pointerSize;
- }
- }
-}
\ No newline at end of file
diff --git a/SMCode/SM.OGL/Mesh/VBO.cs b/SMCode/SM.OGL/Mesh/VBO.cs
index d84b03e..16d4481 100644
--- a/SMCode/SM.OGL/Mesh/VBO.cs
+++ b/SMCode/SM.OGL/Mesh/VBO.cs
@@ -7,15 +7,45 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Mesh
{
+ ///
+ /// Represents a Vertex Buffer Object used for meshes.
+ ///
public class VBO : List
{
+ ///
+ /// Specifies the expected usage pattern of the data store.
+ ///
public BufferUsageHint BufferUsageHint;
+ ///
+ /// Specifies the data type of each component in the array.
+ ///
public VertexAttribPointerType PointerType;
+ ///
+ /// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.
+ ///
public int PointerSize;
+ ///
+ /// Normalise floats?
+ ///
public bool Normalised;
+ ///
+ /// Specifies the byte offset between consecutive generic vertex attributes.
+ ///
public int PointerStride;
+ ///
+ /// 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.
+ ///
public int PointerOffset;
+ ///
+ /// Generates a VBO for inserting mesh data.
+ ///
+ /// Specifies the expected usage pattern of the data store. Default: StaticDraw
+ /// Specifies the data type of each component in the array. Default: Float
+ /// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. Default: 3
+ /// Specifies the byte offset between consecutive generic vertex attributes. Default: 0
+ /// 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. Default: 0
+ /// Normalise floats? Default: false
public VBO(BufferUsageHint bufferUsageHint = BufferUsageHint.StaticDraw,
VertexAttribPointerType pointerType = VertexAttribPointerType.Float, int pointerSize = 3,
int pointerStride = 0, int pointerOffset = 0, bool normalised = false)
@@ -28,17 +58,53 @@ namespace SM.OGL.Mesh
Normalised = normalised;
}
+ ///
+ /// Adds two values to the VBO.
+ ///
public void Add(float x, float y) => AddRange(new[] {x,y});
+ ///
+ /// Adds three values to the VBO.
+ ///
public void Add(float x, float y, float z) => AddRange(new[] {x,y,z});
+ ///
+ /// Adds four values to the VBO.
+ ///
public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w});
+ ///
+ /// Adds a Vector2.
+ ///
public void Add(Vector2 vector) => Add(vector.X, vector.Y);
+ ///
+ /// Adds a Vector2 and a value.
+ ///
public void Add(Vector2 vector, float z) => Add(vector.X, vector.Y, z);
+ ///
+ /// Adds a Vector2 and two values.
+ ///
public void Add(Vector2 vector, float z, float w) => Add(vector.X, vector.Y, z, w);
+ ///
+ /// Adds a Vector3.
+ ///
public void Add(Vector3 vector) => Add(vector.X, vector.Y, vector.Z);
+ ///
+ /// Adds a Vector3 and a value.
+ ///
+ public void Add(Vector3 vector, float w) => Add(vector.X, vector.Y, vector.Z, w);
+ ///
+ /// Adds a vector4.
+ ///
+ ///
public void Add(Vector4 vector) => Add(vector.X, vector.Y, vector.Z, vector.W);
+ ///
+ /// Adds a color.
+ ///
public void Add(Color4 color) => Add(color.R, color.G, color.B, color.A);
- public void BindBuffer(int attribID)
+ ///
+ /// Binds the buffer to the active VAO.
+ ///
+ /// The id for the attribute.
+ internal void BindBuffer(int attribID)
{
float[] data = ToArray();
diff --git a/SMCode/SM.OGL/SM.OGL.csproj b/SMCode/SM.OGL/SM.OGL.csproj
index b5726f2..0039260 100644
--- a/SMCode/SM.OGL/SM.OGL.csproj
+++ b/SMCode/SM.OGL/SM.OGL.csproj
@@ -21,6 +21,8 @@
DEBUG;TRACE
prompt
4
+
+
pdbonly
@@ -49,7 +51,6 @@
-
diff --git a/SMCode/SM.OGL/Shaders/GenericShader.cs b/SMCode/SM.OGL/Shaders/GenericShader.cs
index ed9ed4f..a09f2c3 100644
--- a/SMCode/SM.OGL/Shaders/GenericShader.cs
+++ b/SMCode/SM.OGL/Shaders/GenericShader.cs
@@ -3,18 +3,33 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
- public class GenericShader : GLObject
+ ///
+ /// Abstract class, that is used to create graphic shader.
+ ///
+ public abstract class GenericShader : GLObject
{
+ ///
+ /// Contains the different files for the shader.
+ ///
protected ShaderFileCollection ShaderFileFiles;
+ ///
+ /// Contains and manage the uniforms from the shader.
+ ///
protected UniformCollection Uniforms;
+ ///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
- public GenericShader(ShaderFileCollection shaderFileFiles)
+
+ ///
+ protected GenericShader(ShaderFileCollection shaderFileFiles)
{
ShaderFileFiles = shaderFileFiles;
}
+ ///
+ /// Loads the shader to the GPU.
+ ///
public void Load()
{
@@ -43,12 +58,19 @@ namespace SM.OGL.Shaders
}
+ ///
protected override void Compile()
{
Load();
}
- public void DrawObject(Mesh.GenericMesh mesh, int amount, bool bindVAO = false)
+ ///
+ /// Draws the mesh.
+ ///
+ /// The mesh.
+ /// The amounts for instancing.
+ /// Binds the vertex array for the mesh.
+ protected void DrawObject(Mesh.GenericMesh mesh, int amount, bool bindVAO = false)
{
if (bindVAO) GL.BindVertexArray(mesh);
@@ -57,7 +79,9 @@ namespace SM.OGL.Shaders
else
GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count, amount);
}
-
+ ///
+ /// Resets the shader specific settings to ensure proper workings.
+ ///
protected void CleanUp()
{
Uniforms.NextTexture = 0;
diff --git a/SMCode/SM.OGL/Shaders/ShaderFile.cs b/SMCode/SM.OGL/Shaders/ShaderFile.cs
index 269e3b9..0c8ed7d 100644
--- a/SMCode/SM.OGL/Shaders/ShaderFile.cs
+++ b/SMCode/SM.OGL/Shaders/ShaderFile.cs
@@ -4,20 +4,35 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
+ ///
+ /// Contains/Represents a file used in shaders.
+ ///
public class ShaderFile : GLObject
{
private string _data;
+ ///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader;
+ ///
+ /// Contains overrides, that can be used to import values from the CPU to the shader before it is been send to the GPU.
+ ///
public Dictionary StringOverrides = new Dictionary();
+ ///
+ /// Contains other shader files to allow access to their functions.
+ ///
public List GLSLExtensions = new List();
+ ///
+ /// Creates a file.
+ ///
+ /// The source file.
public ShaderFile(string data)
{
_data = data;
}
+
private void GenerateSource()
{
foreach (KeyValuePair kvp in StringOverrides)
diff --git a/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs b/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs
index ba0fa5c..5258d11 100644
--- a/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs
+++ b/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs
@@ -4,25 +4,48 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
+ ///
+ /// Collects all files that are needed for a shader.
+ ///
public struct ShaderFileCollection
{
+ ///
+ /// Contains the vertex file.
+ ///
public ShaderFile Vertex;
+ ///
+ /// Contains the geometry file.
+ ///
public ShaderFile Geometry;
+ ///
+ /// Contains the fragment file.
+ ///
public ShaderFile Fragment;
- public Action SetUniforms;
-
+ ///
+ /// Creating the collection with vertex and fragment files.
+ ///
+ /// The vertex source file.
+ /// The fragment source file.
public ShaderFileCollection(string vertex, string fragment) : this(new ShaderFile(vertex), new ShaderFile(fragment)) {}
+ ///
+ /// Creating the collection with shader files.
+ ///
+ ///
+ ///
+ ///
public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default)
{
Vertex = vertex;
Geometry = geometry;
Fragment = fragment;
-
- SetUniforms = u => { };
}
+ ///
+ /// Appends the files to the shader.
+ ///
+ ///
internal void Append(GenericShader shader)
{
Vertex.Compile(shader, ShaderType.VertexShader);
@@ -30,6 +53,10 @@ namespace SM.OGL.Shaders
Fragment.Compile(shader, ShaderType.FragmentShader);
}
+ ///
+ /// Removes the files form the shader.
+ ///
+ ///
internal void Detach(GenericShader shader)
{
GL.DetachShader(Vertex, shader);
diff --git a/SMCode/SM.OGL/Shaders/Uniform.cs b/SMCode/SM.OGL/Shaders/Uniform.cs
index 5ee3b0e..ce5d649 100644
--- a/SMCode/SM.OGL/Shaders/Uniform.cs
+++ b/SMCode/SM.OGL/Shaders/Uniform.cs
@@ -5,6 +5,9 @@ using SM.OGL.Texture;
namespace SM.OGL.Shaders
{
+ ///
+ /// Manages the uniforms.
+ ///
public struct Uniform
{
///
@@ -162,19 +165,39 @@ namespace SM.OGL.Shaders
#endregion
+ ///
+ /// Try to sets the texture at the next possible position and tells the checkUniform, if worked or not.
+ ///
+ /// The texture you want to add
+ /// The check uniform.
public void SetTexture(TextureBase texture, Uniform checkUniform)
{
checkUniform.SetUniform1(texture != null);
if (texture != null) SetTexture(texture);
}
+ ///
+ /// Try to sets the texture at the specified position and tells the checkUniform, if worked or not.
+ ///
+ /// The texture you want to add
+ /// The position
+ /// The check uniform.
public void SetTexture(TextureBase texture, int pos, Uniform checkUniform)
{
checkUniform.SetUniform1(texture != null);
if (texture != null) SetTexture(texture);
}
+ ///
+ /// Sets the texture to the next possible position.
+ ///
+ ///
public void SetTexture(TextureBase texture) => SetTexture(texture, Parent.NextTexture++);
+ ///
+ /// Sets the texture to the specified position.
+ ///
+ ///
+ ///
public void SetTexture(TextureBase texture, int texturePos)
{
GL.ActiveTexture(TextureUnit.Texture0 + texturePos);
@@ -182,6 +205,10 @@ namespace SM.OGL.Shaders
SetUniform1(texturePos);
}
+ ///
+ /// Returns the location from the uniform
+ ///
+ ///
public static implicit operator int(Uniform u) => u.Location;
}
}
\ No newline at end of file
diff --git a/SMCode/SM.OGL/Shaders/UniformCollection.cs b/SMCode/SM.OGL/Shaders/UniformCollection.cs
index 215b059..a6f7e3e 100644
--- a/SMCode/SM.OGL/Shaders/UniformCollection.cs
+++ b/SMCode/SM.OGL/Shaders/UniformCollection.cs
@@ -4,12 +4,28 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders
{
+ ///
+ /// Contains and manages the uniform of the parent shader.
+ ///
public class UniformCollection : Dictionary
{
+ ///
+ /// The next texture id for the uniform.
+ ///
internal int NextTexture = 0;
+ ///
+ /// The parent shader.
+ ///
internal GenericShader _parentShader;
+ ///
+ /// Get you the uniform under the variable name.
+ /// If it don't find the uniform, it tries to recreate it.
+ /// If the variable doesn't exist in the first place, it will after the recreation send everything to -1, what is the void.
+ ///
+ ///
+ ///
public new Uniform this[string key]
{
get
@@ -27,7 +43,11 @@ namespace SM.OGL.Shaders
}
}
}
-
+ ///
+ /// Adds a uniform with a location.
+ ///
+ ///
+ ///
public void Add(string key, int location)
{
base.Add(key, new Uniform(location, this));
diff --git a/SMCode/SM.OGL/Texture/TextureBase.cs b/SMCode/SM.OGL/Texture/TextureBase.cs
index b95b173..634fa78 100644
--- a/SMCode/SM.OGL/Texture/TextureBase.cs
+++ b/SMCode/SM.OGL/Texture/TextureBase.cs
@@ -2,12 +2,24 @@
namespace SM.OGL.Texture
{
+ ///
+ /// Works as a basis for textures.
+ ///
public abstract class TextureBase : GLObject
{
+ ///
protected override bool AutoCompile { get; } = true;
+
+ ///
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
+ ///
+ /// The texture filter.
+ ///
public abstract TextureMinFilter Filter { get; set; }
+ ///
+ /// The wrap mode.
+ ///
public abstract TextureWrapMode WrapMode { get; set; }
}
}
\ No newline at end of file
diff --git a/SMCode/SM.OGL/Version.cs b/SMCode/SM.OGL/Version.cs
index bd14606..be2ed3c 100644
--- a/SMCode/SM.OGL/Version.cs
+++ b/SMCode/SM.OGL/Version.cs
@@ -1,16 +1,34 @@
namespace SM.OGL
{
+ ///
+ /// Helper struct to manage versions.
+ ///
public struct Version
{
+ ///
+ /// The major version.
+ ///
public int MajorVersion;
+ ///
+ /// The minor version.
+ ///
public int MinorVersion;
+ ///
+ /// Creates the struct with specific major and minor versions.
+ ///
+ ///
+ ///
public Version(int majorVersion, int minorVersion)
{
MinorVersion = minorVersion;
MajorVersion = majorVersion;
}
+ ///
+ /// Creates the struct by reading it out of a string.
+ ///
+ ///
public Version(string version)
{
string[] splits = version.Trim().Split(new []{'.'}, 2);
@@ -18,11 +36,17 @@
MinorVersion = int.Parse(splits[1]);
}
+ ///
public override string ToString()
{
return $"{MajorVersion}.{MinorVersion}";
}
+ ///
+ /// Create a version struct, with a OpenGL Version string.
+ ///
+ ///
+ ///
public static Version CreateGLVersion(string version)
{
return new Version(version.Substring(0, 3));