Added documentation comments, reorganized HexRender
This commit is contained in:
@@ -3,14 +3,45 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Buffers
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = true)]
|
||||
/// <summary>
|
||||
/// Marks a field as an attribute to be sent to a shader. Must be used on public fields of a struct.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||
public sealed class VertexPointerAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The attribute name that the values of this field should point to
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of elements in this attribute
|
||||
/// Corresponds to the <code>size</code> parameter to <code>glVertexAttribPointer</code>.
|
||||
/// </summary>
|
||||
public int Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The element type of the attribute
|
||||
/// Corresponds to the <code>type</code> parameter to <code>glVertexAttribPointer</code>
|
||||
/// </summary>
|
||||
public VertexAttribPointerType Type { get; set; } = VertexAttribPointerType.Float;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to normalize the values of this attribute
|
||||
/// Corresponds to the <code>normalized</code> parameter to <code>glVertexAttribPointer</code>
|
||||
/// </summary>
|
||||
public bool Normalized { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The divisor to Instanced draw calls
|
||||
/// Corresponds to the <code>divisor</code> parameter to <code>glVertexAttribDivisor</code>
|
||||
/// </summary>
|
||||
public int Divisor { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The offset of this attribute within each element
|
||||
/// Corresponds to the <code>offset</code> parameter to <code>glVertexAttribPointer</code>
|
||||
/// </summary>
|
||||
public int Offset { get; set; } = 0;
|
||||
|
||||
public VertexPointerAttribute(string name, int size)
|
||||
|
||||
@@ -2,18 +2,35 @@
|
||||
|
||||
namespace Diamond
|
||||
{
|
||||
/// <summary>
|
||||
/// Parent class for all gl Object wrappers.
|
||||
/// </summary>
|
||||
public abstract class GLObject : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of this object
|
||||
/// </summary>
|
||||
public uint Id { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Force all <code>GLObject</code>s to define their name.
|
||||
/// </summary>
|
||||
/// <param name="id">The name of this object</param>
|
||||
protected GLObject(uint id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to free the name of this object. Usually corresponds to <code>glDelete*</code>.
|
||||
/// </summary>
|
||||
protected abstract void Delete();
|
||||
|
||||
private bool _disposed = false;
|
||||
|
||||
/// <summary>
|
||||
/// Free the name of this object
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Diamond.Shaders
|
||||
private Dictionary<string, int> uniforms = new Dictionary<string, int>();
|
||||
private Dictionary<string, int> attributes = new Dictionary<string, int>();
|
||||
|
||||
public string Log => GL.GetProgramInfoLog((int) Id);
|
||||
public string Log => GL.GetProgramInfoLog((int) Id).Trim();
|
||||
|
||||
public Program()
|
||||
: base((uint) GL.CreateProgram())
|
||||
@@ -23,7 +23,7 @@ namespace Diamond.Shaders
|
||||
|
||||
public void Attach(Shader shader) => GL.AttachShader(Id, shader.Id);
|
||||
|
||||
public bool LinkStatus
|
||||
public bool Linked
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -4,10 +4,19 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps methods for GL Shader objects.
|
||||
/// </summary>
|
||||
public class Shader : GLObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of this shader.
|
||||
/// </summary>
|
||||
public readonly ShaderType Type;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets and sets the shader source with <code>glShaderSource</code> and <code>glGetShaderSource</code>.
|
||||
/// </summary>
|
||||
public string Source
|
||||
{
|
||||
get
|
||||
@@ -19,8 +28,14 @@ namespace Diamond.Shaders
|
||||
set { GL.ShaderSource((int) Id, value); }
|
||||
}
|
||||
|
||||
public string Log => GL.GetShaderInfoLog((int) Id);
|
||||
/// <summary>
|
||||
/// Retrieves this shader's compilation log with <code>glGetShaderInfoLog</code>.
|
||||
/// </summary>
|
||||
public string Log => GL.GetShaderInfoLog((int) Id).Trim();
|
||||
|
||||
/// <summary>
|
||||
/// Checks the compilation status of this shader with <code>glGetShader</code>.
|
||||
/// </summary>
|
||||
public bool Compiled
|
||||
{
|
||||
get
|
||||
@@ -30,29 +45,52 @@ namespace Diamond.Shaders
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a wrapper for a gl Shader object.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of the shader to create</param>
|
||||
public Shader(ShaderType type)
|
||||
: base((uint) GL.CreateShader(type))
|
||||
{
|
||||
Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Frees this gl object. Called by <code>GLObject.Dispose()</code>.
|
||||
/// </summary>
|
||||
protected override void Delete()
|
||||
{
|
||||
GL.DeleteShader(Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compile the shader.
|
||||
/// </summary>
|
||||
/// <returns>Compilation success</returns>
|
||||
public bool Compile()
|
||||
{
|
||||
GL.CompileShader(Id);
|
||||
GL.GetShader(Id, ShaderParameter.CompileStatus, out int success);
|
||||
return success != 0;
|
||||
return Compiled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and compiles a shader from a source file.
|
||||
/// </summary>
|
||||
/// <param name="path">Source file location</param>
|
||||
/// <param name="type">Type of the shader</param>
|
||||
/// <returns>The compiled shader</returns>
|
||||
public static Shader FromFile(string path, ShaderType type)
|
||||
{
|
||||
return FromFile(path, type, out bool success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and compiles a shader from a source file.
|
||||
/// </summary>
|
||||
/// <param name="path">Source file location</param>
|
||||
/// <param name="type">Type of the shader</param>
|
||||
/// <param name="success">Compilation success</param>
|
||||
/// <returns>The compiled shader</returns>
|
||||
public static Shader FromFile(string path, ShaderType type, out bool success)
|
||||
{
|
||||
var s = new Shader(type);
|
||||
|
||||
@@ -3,6 +3,9 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace Diamond.Shaders
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception relating to <code>Shader</code> and <code>Program</code> operations.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ShaderException : Exception
|
||||
{
|
||||
|
||||
@@ -5,6 +5,9 @@ using PixelFormat = OpenTK.Graphics.OpenGL4.PixelFormat;
|
||||
|
||||
namespace Diamond.Textures
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for gl Textures.
|
||||
/// </summary>
|
||||
public class Texture : GLObject
|
||||
{
|
||||
public TextureTarget Target;
|
||||
|
||||
Reference in New Issue
Block a user