Added summeries to SM.OGL

This commit is contained in:
Michel Fedde 2020-09-27 13:01:50 +02:00
parent 2aa12f8d25
commit 16366fa015
15 changed files with 363 additions and 27 deletions

View file

@ -7,11 +7,17 @@ using OpenTK.Platform.Egl;
namespace SM.OGL namespace SM.OGL
{ {
/// <summary>
/// Contains everything that is needed to properly debug OpenGL
/// </summary>
public static class GLDebugging public static class GLDebugging
{ {
private static DebugProc _debugProc = DebugCallback; private static DebugProc _debugProc = DebugCallback;
private static GCHandle _debugGcHandle; private static GCHandle _debugGcHandle;
/// <summary>
/// A action that is performed, when a OpenGL-error occurs.
/// </summary>
public static Action<DebugSource, DebugType, DebugSeverity, string> DebugAction = DefaultDebugAction; public static Action<DebugSource, DebugType, DebugSeverity, string> DebugAction = DefaultDebugAction;
[DebuggerStepThrough] [DebuggerStepThrough]
@ -22,6 +28,9 @@ namespace SM.OGL
DebugAction?.Invoke(source, type, severity, msg); DebugAction?.Invoke(source, type, severity, msg);
} }
/// <summary>
/// Enables the debugging.
/// </summary>
public static void EnableDebugging() public static void EnableDebugging()
{ {
try try
@ -41,6 +50,13 @@ namespace SM.OGL
} }
} }
/// <summary>
/// Default action for 'DebugAction'.
/// </summary>
/// <param name="source"></param>
/// <param name="type"></param>
/// <param name="severity"></param>
/// <param name="msg"></param>
public static void DefaultDebugAction(DebugSource source, DebugType type, DebugSeverity severity, string msg) public static void DefaultDebugAction(DebugSource source, DebugType type, DebugSeverity severity, string msg)
{ {
Console.WriteLine($"{severity}, {type}, {source} -> {msg}"); Console.WriteLine($"{severity}, {type}, {source} -> {msg}");

View file

@ -2,13 +2,29 @@
namespace SM.OGL namespace SM.OGL
{ {
/// <summary>
/// Specifies default object behaviour.
/// </summary>
public abstract class GLObject public abstract class GLObject
{ {
/// <summary>
/// Contains the OpenGL ID
/// </summary>
protected int _id = -1; protected int _id = -1;
/// <summary>
/// If true, the system will call "Compile()", when "ID" is tried to get, but the id is still -1.
/// </summary>
protected virtual bool AutoCompile { get; } = false; protected virtual bool AutoCompile { get; } = false;
/// <summary>
/// Checks if the object was compiled.
/// </summary>
public bool WasCompiled => _id > 0; public bool WasCompiled => _id > 0;
/// <summary>
/// Returns the id for this object.
/// <para>It will auto compile, if needed and allowed.</para>
/// </summary>
public virtual int ID public virtual int ID
{ {
get get
@ -18,18 +34,32 @@ namespace SM.OGL
} }
} }
/// <summary>
/// Identifies the object.
/// </summary>
public abstract ObjectLabelIdentifier TypeIdentifier { get; } public abstract ObjectLabelIdentifier TypeIdentifier { get; }
/// <summary>
/// The action, that is called, when "ID" tries to compile something.
/// </summary>
protected virtual void Compile() protected virtual void Compile()
{ {
} }
/// <summary>
/// Names the object for debugging.
/// </summary>
/// <param name="name"></param>
public void Name(string name) public void Name(string name)
{ {
if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name); if (GLSystem.Debugging) GL.ObjectLabel(TypeIdentifier, _id, name.Length, name);
} }
/// <summary>
/// Returns the ID for the object.
/// </summary>
/// <param name="glo"></param>
public static implicit operator int(GLObject glo) => glo.ID; public static implicit operator int(GLObject glo) => glo.ID;
} }
} }

View file

@ -3,18 +3,42 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL namespace SM.OGL
{ {
/// <summary>
/// Contains data about the current OpenGL system.
/// </summary>
public class GLSystem public class GLSystem
{ {
private static bool _init = false; private static bool _init = false;
/// <summary>
/// Contains the device version of OpenGL.
/// </summary>
public static Version DeviceVersion { get; private set; } public static Version DeviceVersion { get; private set; }
/// <summary>
/// Get/Sets the forced version for OpenGL.
/// <para>Needs to be set before init a window.</para>
/// </summary>
public static Version ForcedVersion { get; set; } = new Version(); public static Version ForcedVersion { get; set; } = new Version();
/// <summary>
/// Contains the shader version for GLSL.
/// </summary>
public static Version ShadingVersion { get; private set; } public static Version ShadingVersion { get; private set; }
/// <summary>
/// Contains the extensions for OpenGL.
/// </summary>
public static string[] Extensions { get; private set; } public static string[] Extensions { get; private set; }
/// <summary>
/// Checks if proper Debugging is for this system available.
/// <para>Determent, if the system has the "KHR_debug"-extension. </para>
/// </summary>
public static bool Debugging { get; private set; } public static bool Debugging { get; private set; }
/// <summary>
/// Initialize the system data.
/// <para>Does nothing after the data was already collected.</para>
/// </summary>
public static void INIT_SYSTEM() public static void INIT_SYSTEM()
{ {
if (_init) return; if (_init) return;

View file

@ -4,21 +4,49 @@ using OpenTK;
namespace SM.OGL.Mesh namespace SM.OGL.Mesh
{ {
/// <summary>
/// Contains information about bounding boxes of meshes
/// </summary>
public class BoundingBox public class BoundingBox
{ {
public Vector3 Max = Vector3.Zero; /// <summary>
/// The minimum corner.
/// </summary>
public Vector3 Min = Vector3.Zero; public Vector3 Min = Vector3.Zero;
/// <summary>
/// The maximum corner.
/// </summary>
public Vector3 Max = Vector3.Zero;
/// <summary>
/// Returns specific configurations of corners
/// </summary>
/// <param name="x">If true, it takes the X-value of maximum, otherwise the minimum.</param>
/// <param name="y">If true, it takes the Y-value of maximum, otherwise the minimum.</param>
/// <param name="z">If true, it takes the Z-value of maximum, otherwise the minimum.</param>
/// <returns></returns>
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 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);
/// <summary>
/// Empty constructor
/// </summary>
public BoundingBox() {} public BoundingBox() {}
/// <summary>
/// Creates the bounding box with predefined min and max values
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
public BoundingBox(Vector3 min, Vector3 max) public BoundingBox(Vector3 min, Vector3 max)
{ {
Min = min; Min = min;
Max = max; Max = max;
} }
/// <summary>
/// Updates the bounding box.
/// </summary>
/// <param name="vector"></param>
public void Update(Vector2 vector) public void Update(Vector2 vector)
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
@ -28,6 +56,10 @@ namespace SM.OGL.Mesh
} }
} }
/// <summary>
/// Updates the bounding box.
/// </summary>
/// <param name="vector"></param>
public void Update(Vector3 vector) public void Update(Vector3 vector)
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)

View file

@ -5,23 +5,54 @@ using Buffer = OpenTK.Graphics.OpenGL4.Buffer;
namespace SM.OGL.Mesh namespace SM.OGL.Mesh
{ {
/// <summary>
/// Contains information for meshes
/// </summary>
public abstract class GenericMesh : GLObject public abstract class GenericMesh : GLObject
{ {
/// <inheritdoc />
protected override bool AutoCompile { get; } = true; protected override bool AutoCompile { get; } = true;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray; public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.VertexArray;
/// <summary>
/// The primitive type, that determinants how the mesh is drawn.
/// <para>Default: Triangles</para>
/// </summary>
public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles; public virtual PrimitiveType PrimitiveType { get; } = PrimitiveType.Triangles;
/// <summary>
/// Contains the vertices for the mesh.
/// </summary>
public virtual VBO Vertex { get; } public virtual VBO Vertex { get; }
/// <summary>
/// Contains the texture coords for the mesh.
/// </summary>
public virtual VBO UVs { get; } public virtual VBO UVs { get; }
/// <summary>
/// Contains the normals for the mesh.
/// </summary>
public virtual VBO Normals { get; } public virtual VBO Normals { get; }
/// <summary>
/// Represents the bounding box.
/// </summary>
public virtual BoundingBox BoundingBox { get; } = new BoundingBox(); public virtual BoundingBox BoundingBox { get; } = new BoundingBox();
public virtual Dictionary<int, VBO> AttribDataIndex { get; } /// <summary>
/// Connects the different buffer objects with ids.
/// </summary>
protected Dictionary<int, VBO> AttribDataIndex { get; }
/// <summary>
/// Stores indices for a more performance friendly method to draw objects.
/// </summary>
public virtual int[] Indices { get; set; } public virtual int[] Indices { get; set; }
/// <summary>
/// Generates the AttribDataIndex
/// </summary>
protected GenericMesh() protected GenericMesh()
{ {
AttribDataIndex = new Dictionary<int, VBO>() AttribDataIndex = new Dictionary<int, VBO>()
@ -32,6 +63,7 @@ namespace SM.OGL.Mesh
}; };
} }
/// <inheritdoc />
protected override void Compile() protected override void Compile()
{ {
_id = GL.GenVertexArray(); _id = GL.GenVertexArray();

View file

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

View file

@ -7,15 +7,45 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Mesh namespace SM.OGL.Mesh
{ {
/// <summary>
/// Represents a Vertex Buffer Object used for meshes.
/// </summary>
public class VBO : List<float> public class VBO : List<float>
{ {
/// <summary>
/// Specifies the expected usage pattern of the data store.
/// </summary>
public BufferUsageHint BufferUsageHint; public BufferUsageHint BufferUsageHint;
/// <summary>
/// Specifies the data type of each component in the array.
/// </summary>
public VertexAttribPointerType PointerType; public VertexAttribPointerType PointerType;
/// <summary>
/// Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4.
/// </summary>
public int PointerSize; public int PointerSize;
/// <summary>
/// Normalise floats?
/// </summary>
public bool Normalised; public bool Normalised;
/// <summary>
/// Specifies the byte offset between consecutive generic vertex attributes.
/// </summary>
public int PointerStride; public int PointerStride;
/// <summary>
/// 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.
/// </summary>
public int PointerOffset; public int PointerOffset;
/// <summary>
/// Generates a VBO for inserting mesh data.
/// </summary>
/// <param name="bufferUsageHint">Specifies the expected usage pattern of the data store. <para>Default: StaticDraw</para></param>
/// <param name="pointerType">Specifies the data type of each component in the array. <para>Default: Float</para></param>
/// <param name="pointerSize">Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. <para>Default: 3</para></param>
/// <param name="pointerStride">Specifies the byte offset between consecutive generic vertex attributes. <para>Default: 0</para></param>
/// <param name="pointerOffset">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. <para>Default: 0</para></param>
/// <param name="normalised">Normalise floats? <para>Default: false</para></param>
public VBO(BufferUsageHint bufferUsageHint = BufferUsageHint.StaticDraw, public VBO(BufferUsageHint bufferUsageHint = BufferUsageHint.StaticDraw,
VertexAttribPointerType pointerType = VertexAttribPointerType.Float, int pointerSize = 3, VertexAttribPointerType pointerType = VertexAttribPointerType.Float, int pointerSize = 3,
int pointerStride = 0, int pointerOffset = 0, bool normalised = false) int pointerStride = 0, int pointerOffset = 0, bool normalised = false)
@ -28,17 +58,53 @@ namespace SM.OGL.Mesh
Normalised = normalised; Normalised = normalised;
} }
/// <summary>
/// Adds two values to the VBO.
/// </summary>
public void Add(float x, float y) => AddRange(new[] {x,y}); public void Add(float x, float y) => AddRange(new[] {x,y});
/// <summary>
/// Adds three values to the VBO.
/// </summary>
public void Add(float x, float y, float z) => AddRange(new[] {x,y,z}); public void Add(float x, float y, float z) => AddRange(new[] {x,y,z});
/// <summary>
/// Adds four values to the VBO.
/// </summary>
public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w}); public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w});
/// <summary>
/// Adds a Vector2.
/// </summary>
public void Add(Vector2 vector) => Add(vector.X, vector.Y); public void Add(Vector2 vector) => Add(vector.X, vector.Y);
/// <summary>
/// Adds a Vector2 and a value.
/// </summary>
public void Add(Vector2 vector, float z) => Add(vector.X, vector.Y, z); public void Add(Vector2 vector, float z) => Add(vector.X, vector.Y, z);
/// <summary>
/// Adds a Vector2 and two values.
/// </summary>
public void Add(Vector2 vector, float z, float w) => Add(vector.X, vector.Y, z, w); public void Add(Vector2 vector, float z, float w) => Add(vector.X, vector.Y, z, w);
/// <summary>
/// Adds a Vector3.
/// </summary>
public void Add(Vector3 vector) => Add(vector.X, vector.Y, vector.Z); public void Add(Vector3 vector) => Add(vector.X, vector.Y, vector.Z);
/// <summary>
/// Adds a Vector3 and a value.
/// </summary>
public void Add(Vector3 vector, float w) => Add(vector.X, vector.Y, vector.Z, w);
/// <summary>
/// Adds a vector4.
/// </summary>
/// <param name="vector"></param>
public void Add(Vector4 vector) => Add(vector.X, vector.Y, vector.Z, vector.W); public void Add(Vector4 vector) => Add(vector.X, vector.Y, vector.Z, vector.W);
/// <summary>
/// Adds a color.
/// </summary>
public void Add(Color4 color) => Add(color.R, color.G, color.B, color.A); public void Add(Color4 color) => Add(color.R, color.G, color.B, color.A);
public void BindBuffer(int attribID) /// <summary>
/// Binds the buffer to the active VAO.
/// </summary>
/// <param name="attribID">The id for the attribute.</param>
internal void BindBuffer(int attribID)
{ {
float[] data = ToArray(); float[] data = ToArray();

View file

@ -21,6 +21,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@ -49,7 +51,6 @@
<Compile Include="GLSystem.cs" /> <Compile Include="GLSystem.cs" />
<Compile Include="Mesh\BoundingBox.cs" /> <Compile Include="Mesh\BoundingBox.cs" />
<Compile Include="Mesh\GenericMesh.cs" /> <Compile Include="Mesh\GenericMesh.cs" />
<Compile Include="Mesh\TypeDefinition.cs" />
<Compile Include="Mesh\VBO.cs" /> <Compile Include="Mesh\VBO.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Shaders\GenericShader.cs" /> <Compile Include="Shaders\GenericShader.cs" />

View file

@ -3,18 +3,33 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders namespace SM.OGL.Shaders
{ {
public class GenericShader : GLObject /// <summary>
/// Abstract class, that is used to create graphic shader.
/// </summary>
public abstract class GenericShader : GLObject
{ {
/// <summary>
/// Contains the different files for the shader.
/// </summary>
protected ShaderFileCollection ShaderFileFiles; protected ShaderFileCollection ShaderFileFiles;
/// <summary>
/// Contains and manage the uniforms from the shader.
/// </summary>
protected UniformCollection Uniforms; protected UniformCollection Uniforms;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program; public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Program;
public GenericShader(ShaderFileCollection shaderFileFiles)
/// <inheritdoc />
protected GenericShader(ShaderFileCollection shaderFileFiles)
{ {
ShaderFileFiles = shaderFileFiles; ShaderFileFiles = shaderFileFiles;
} }
/// <summary>
/// Loads the shader to the GPU.
/// </summary>
public void Load() public void Load()
{ {
@ -43,12 +58,19 @@ namespace SM.OGL.Shaders
} }
/// <inheritdoc />
protected override void Compile() protected override void Compile()
{ {
Load(); Load();
} }
public void DrawObject(Mesh.GenericMesh mesh, int amount, bool bindVAO = false) /// <summary>
/// Draws the mesh.
/// </summary>
/// <param name="mesh">The mesh.</param>
/// <param name="amount">The amounts for instancing.</param>
/// <param name="bindVAO">Binds the vertex array for the mesh.</param>
protected void DrawObject(Mesh.GenericMesh mesh, int amount, bool bindVAO = false)
{ {
if (bindVAO) GL.BindVertexArray(mesh); if (bindVAO) GL.BindVertexArray(mesh);
@ -57,7 +79,9 @@ namespace SM.OGL.Shaders
else else
GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count, amount); GL.DrawArraysInstanced(mesh.PrimitiveType, 0, mesh.Vertex.Count, amount);
} }
/// <summary>
/// Resets the shader specific settings to ensure proper workings.
/// </summary>
protected void CleanUp() protected void CleanUp()
{ {
Uniforms.NextTexture = 0; Uniforms.NextTexture = 0;

View file

@ -4,20 +4,35 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders namespace SM.OGL.Shaders
{ {
/// <summary>
/// Contains/Represents a file used in shaders.
/// </summary>
public class ShaderFile : GLObject public class ShaderFile : GLObject
{ {
private string _data; private string _data;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader; public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Shader;
/// <summary>
/// Contains overrides, that can be used to import values from the CPU to the shader before it is been send to the GPU.
/// </summary>
public Dictionary<string, string> StringOverrides = new Dictionary<string, string>(); public Dictionary<string, string> StringOverrides = new Dictionary<string, string>();
/// <summary>
/// Contains other shader files to allow access to their functions.
/// </summary>
public List<ShaderFile> GLSLExtensions = new List<ShaderFile>(); public List<ShaderFile> GLSLExtensions = new List<ShaderFile>();
/// <summary>
/// Creates a file.
/// </summary>
/// <param name="data">The source file.</param>
public ShaderFile(string data) public ShaderFile(string data)
{ {
_data = data; _data = data;
} }
private void GenerateSource() private void GenerateSource()
{ {
foreach (KeyValuePair<string, string> kvp in StringOverrides) foreach (KeyValuePair<string, string> kvp in StringOverrides)

View file

@ -4,25 +4,48 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders namespace SM.OGL.Shaders
{ {
/// <summary>
/// Collects all files that are needed for a shader.
/// </summary>
public struct ShaderFileCollection public struct ShaderFileCollection
{ {
/// <summary>
/// Contains the vertex file.
/// </summary>
public ShaderFile Vertex; public ShaderFile Vertex;
/// <summary>
/// Contains the geometry file.
/// </summary>
public ShaderFile Geometry; public ShaderFile Geometry;
/// <summary>
/// Contains the fragment file.
/// </summary>
public ShaderFile Fragment; public ShaderFile Fragment;
public Action<UniformCollection> SetUniforms; /// <summary>
/// Creating the collection with vertex and fragment files.
/// </summary>
/// <param name="vertex">The vertex source file.</param>
/// <param name="fragment">The fragment source file.</param>
public ShaderFileCollection(string vertex, string fragment) : this(new ShaderFile(vertex), new ShaderFile(fragment)) {} public ShaderFileCollection(string vertex, string fragment) : this(new ShaderFile(vertex), new ShaderFile(fragment)) {}
/// <summary>
/// Creating the collection with shader files.
/// </summary>
/// <param name="vertex"></param>
/// <param name="fragment"></param>
/// <param name="geometry"></param>
public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default) public ShaderFileCollection(ShaderFile vertex, ShaderFile fragment, ShaderFile geometry = default)
{ {
Vertex = vertex; Vertex = vertex;
Geometry = geometry; Geometry = geometry;
Fragment = fragment; Fragment = fragment;
SetUniforms = u => { };
} }
/// <summary>
/// Appends the files to the shader.
/// </summary>
/// <param name="shader"></param>
internal void Append(GenericShader shader) internal void Append(GenericShader shader)
{ {
Vertex.Compile(shader, ShaderType.VertexShader); Vertex.Compile(shader, ShaderType.VertexShader);
@ -30,6 +53,10 @@ namespace SM.OGL.Shaders
Fragment.Compile(shader, ShaderType.FragmentShader); Fragment.Compile(shader, ShaderType.FragmentShader);
} }
/// <summary>
/// Removes the files form the shader.
/// </summary>
/// <param name="shader"></param>
internal void Detach(GenericShader shader) internal void Detach(GenericShader shader)
{ {
GL.DetachShader(Vertex, shader); GL.DetachShader(Vertex, shader);

View file

@ -5,6 +5,9 @@ using SM.OGL.Texture;
namespace SM.OGL.Shaders namespace SM.OGL.Shaders
{ {
/// <summary>
/// Manages the uniforms.
/// </summary>
public struct Uniform public struct Uniform
{ {
/// <summary> /// <summary>
@ -162,19 +165,39 @@ namespace SM.OGL.Shaders
#endregion #endregion
/// <summary>
/// Try to sets the texture at the next possible position and tells the checkUniform, if worked or not.
/// </summary>
/// <param name="texture">The texture you want to add</param>
/// <param name="checkUniform">The check uniform.</param>
public void SetTexture(TextureBase texture, Uniform checkUniform) public void SetTexture(TextureBase texture, Uniform checkUniform)
{ {
checkUniform.SetUniform1(texture != null); checkUniform.SetUniform1(texture != null);
if (texture != null) SetTexture(texture); if (texture != null) SetTexture(texture);
} }
/// <summary>
/// Try to sets the texture at the specified position and tells the checkUniform, if worked or not.
/// </summary>
/// <param name="texture">The texture you want to add</param>
/// <param name="pos">The position</param>
/// <param name="checkUniform">The check uniform.</param>
public void SetTexture(TextureBase texture, int pos, Uniform checkUniform) public void SetTexture(TextureBase texture, int pos, Uniform checkUniform)
{ {
checkUniform.SetUniform1(texture != null); checkUniform.SetUniform1(texture != null);
if (texture != null) SetTexture(texture); if (texture != null) SetTexture(texture);
} }
/// <summary>
/// Sets the texture to the next possible position.
/// </summary>
/// <param name="texture"></param>
public void SetTexture(TextureBase texture) => SetTexture(texture, Parent.NextTexture++); public void SetTexture(TextureBase texture) => SetTexture(texture, Parent.NextTexture++);
/// <summary>
/// Sets the texture to the specified position.
/// </summary>
/// <param name="texture"></param>
/// <param name="texturePos"></param>
public void SetTexture(TextureBase texture, int texturePos) public void SetTexture(TextureBase texture, int texturePos)
{ {
GL.ActiveTexture(TextureUnit.Texture0 + texturePos); GL.ActiveTexture(TextureUnit.Texture0 + texturePos);
@ -182,6 +205,10 @@ namespace SM.OGL.Shaders
SetUniform1(texturePos); SetUniform1(texturePos);
} }
/// <summary>
/// Returns the location from the uniform
/// </summary>
/// <param name="u"></param>
public static implicit operator int(Uniform u) => u.Location; public static implicit operator int(Uniform u) => u.Location;
} }
} }

View file

@ -4,12 +4,28 @@ using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Shaders namespace SM.OGL.Shaders
{ {
/// <summary>
/// Contains and manages the uniform of the parent shader.
/// </summary>
public class UniformCollection : Dictionary<string, Uniform> public class UniformCollection : Dictionary<string, Uniform>
{ {
/// <summary>
/// The next texture id for the uniform.
/// </summary>
internal int NextTexture = 0; internal int NextTexture = 0;
/// <summary>
/// The parent shader.
/// </summary>
internal GenericShader _parentShader; internal GenericShader _parentShader;
/// <summary>
/// Get you the uniform under the variable name.
/// <para>If it don't find the uniform, it tries to recreate it.</para>
/// <para>If the variable doesn't exist in the first place, it will after the recreation send everything to -1, what is the void.</para>
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public new Uniform this[string key] public new Uniform this[string key]
{ {
get get
@ -27,7 +43,11 @@ namespace SM.OGL.Shaders
} }
} }
} }
/// <summary>
/// Adds a uniform with a location.
/// </summary>
/// <param name="key"></param>
/// <param name="location"></param>
public void Add(string key, int location) public void Add(string key, int location)
{ {
base.Add(key, new Uniform(location, this)); base.Add(key, new Uniform(location, this));

View file

@ -2,12 +2,24 @@
namespace SM.OGL.Texture namespace SM.OGL.Texture
{ {
/// <summary>
/// Works as a basis for textures.
/// </summary>
public abstract class TextureBase : GLObject public abstract class TextureBase : GLObject
{ {
/// <inheritdoc />
protected override bool AutoCompile { get; } = true; protected override bool AutoCompile { get; } = true;
/// <inheritdoc />
public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture; public override ObjectLabelIdentifier TypeIdentifier { get; } = ObjectLabelIdentifier.Texture;
/// <summary>
/// The texture filter.
/// </summary>
public abstract TextureMinFilter Filter { get; set; } public abstract TextureMinFilter Filter { get; set; }
/// <summary>
/// The wrap mode.
/// </summary>
public abstract TextureWrapMode WrapMode { get; set; } public abstract TextureWrapMode WrapMode { get; set; }
} }
} }

View file

@ -1,16 +1,34 @@
namespace SM.OGL namespace SM.OGL
{ {
/// <summary>
/// Helper struct to manage versions.
/// </summary>
public struct Version public struct Version
{ {
/// <summary>
/// The major version.
/// </summary>
public int MajorVersion; public int MajorVersion;
/// <summary>
/// The minor version.
/// </summary>
public int MinorVersion; public int MinorVersion;
/// <summary>
/// Creates the struct with specific major and minor versions.
/// </summary>
/// <param name="majorVersion"></param>
/// <param name="minorVersion"></param>
public Version(int majorVersion, int minorVersion) public Version(int majorVersion, int minorVersion)
{ {
MinorVersion = minorVersion; MinorVersion = minorVersion;
MajorVersion = majorVersion; MajorVersion = majorVersion;
} }
/// <summary>
/// Creates the struct by reading it out of a string.
/// </summary>
/// <param name="version"></param>
public Version(string version) public Version(string version)
{ {
string[] splits = version.Trim().Split(new []{'.'}, 2); string[] splits = version.Trim().Split(new []{'.'}, 2);
@ -18,11 +36,17 @@
MinorVersion = int.Parse(splits[1]); MinorVersion = int.Parse(splits[1]);
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{MajorVersion}.{MinorVersion}"; return $"{MajorVersion}.{MinorVersion}";
} }
/// <summary>
/// Create a version struct, with a OpenGL Version string.
/// </summary>
/// <param name="version"></param>
/// <returns></returns>
public static Version CreateGLVersion(string version) public static Version CreateGLVersion(string version)
{ {
return new Version(version.Substring(0, 3)); return new Version(version.Substring(0, 3));