Added documentation to all Wrapper types
This commit is contained in:
@@ -3,6 +3,9 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Wrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for OpenGL Buffer objects
|
||||
/// </summary>
|
||||
internal sealed class BufferWrap : Wrapper
|
||||
{
|
||||
#region Constructor, GLDelete()
|
||||
@@ -22,19 +25,43 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region Stored
|
||||
|
||||
/// <summary>
|
||||
/// BufferTarget parameter used in gl* calls
|
||||
/// </summary>
|
||||
public BufferTarget Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// BufferUsageHint parameter using in glBufferData calls
|
||||
/// </summary>
|
||||
public BufferUsageHint Usage { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Binds this buffer (glBindBuffer)
|
||||
/// </summary>
|
||||
public void Bind() => GL.BindBuffer(Target, Id);
|
||||
|
||||
/// <summary>
|
||||
/// Upload data to this buffer (glBufferData)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of value to upload</typeparam>
|
||||
/// <param name="size">Size of T in bytes</param>
|
||||
/// <param name="data">Values to upload</param>
|
||||
public void Data<T>(int size, T[] data) where T : struct
|
||||
{
|
||||
Bind();
|
||||
GL.BufferData(Target, (IntPtr) (size * data.Length), data, Usage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload a range data to this buffer (glBufferSubData)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of value to upload</typeparam>
|
||||
/// <param name="size">Size of T in bytes</param>
|
||||
/// <param name="offset">Offset of upload range in bytes</param>
|
||||
/// <param name="count">Number of bytes to upload</param>
|
||||
/// <param name="data">All values to upload (offset will be applied to both this and the target)</param>
|
||||
public void SubData<T>(int size, int offset, int count, T[] data) where T : struct
|
||||
{
|
||||
Bind();
|
||||
|
||||
@@ -3,6 +3,9 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Wrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for OpenGL Program objects
|
||||
/// </summary>
|
||||
internal sealed class ProgramWrap : Wrapper
|
||||
{
|
||||
#region Constructor, GLDelete()
|
||||
@@ -18,28 +21,62 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of active uniforms for this program
|
||||
/// </summary>
|
||||
public int ActiveUniforms => Get(GetProgramParameterName.ActiveUniforms);
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of active attributes for this program
|
||||
/// </summary>
|
||||
public int ActiveAttributes => Get(GetProgramParameterName.ActiveAttributes);
|
||||
|
||||
/// <summary>
|
||||
/// Check whether this program has been Linked
|
||||
/// </summary>
|
||||
public bool Linked => Get(GetProgramParameterName.LinkStatus) != 0;
|
||||
|
||||
/// <summary>
|
||||
/// Get the InfoLog related to this program. Unless Link() failed, should be null.
|
||||
/// </summary>
|
||||
public string InfoLog => GL.GetProgramInfoLog(Id).Trim(); // trim to remove trailing newlines
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get a parameter from this program (glGetProgram)
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to get</param>
|
||||
/// <returns>The int value of the parameter</returns>
|
||||
public int Get(GetProgramParameterName parameter)
|
||||
{
|
||||
GL.GetProgram(Id, parameter, out int res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public int ActiveUniforms => Get(GetProgramParameterName.ActiveUniforms);
|
||||
public int ActiveAttributes => Get(GetProgramParameterName.ActiveAttributes);
|
||||
public bool Linked => Get(GetProgramParameterName.LinkStatus) != 0;
|
||||
|
||||
public string InfoLog => GL.GetProgramInfoLog(Id).Trim();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Attach a compiled shader to this program (glAttachShader)
|
||||
/// </summary>
|
||||
/// <param name="shader"></param>
|
||||
public void Attach(ShaderWrap shader) => GL.AttachShader(Id, shader.Id);
|
||||
|
||||
/// <summary>
|
||||
/// Link this program (glLinkProgram)
|
||||
/// </summary>
|
||||
public void Link() => GL.LinkProgram(Id);
|
||||
|
||||
/// <summary>
|
||||
/// Use this program (glUseProgram)
|
||||
/// </summary>
|
||||
public void Use() => GL.UseProgram(Id);
|
||||
|
||||
/// <summary>
|
||||
/// Get the name of the uniform at a location
|
||||
/// </summary>
|
||||
/// <param name="location">The uniform id</param>
|
||||
/// <returns>The uniform name</returns>
|
||||
public string UniformName(int location)
|
||||
{
|
||||
var sb = new StringBuilder(64);
|
||||
@@ -47,6 +84,11 @@ namespace Diamond.Wrappers
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the name of the attribute at a location
|
||||
/// </summary>
|
||||
/// <param name="location">The attribute id</param>
|
||||
/// <returns>The attribute name</returns>
|
||||
public string AttributeName(int location)
|
||||
{
|
||||
var sb = new StringBuilder(64);
|
||||
|
||||
@@ -3,6 +3,9 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Wrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for OpenGL Shader objects
|
||||
/// </summary>
|
||||
internal sealed class ShaderWrap : Wrapper
|
||||
{
|
||||
#region Constructor, GLDelete()
|
||||
@@ -21,10 +24,16 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region Stored
|
||||
|
||||
/// <summary>
|
||||
/// The type of this shader - stored at creation time to prevent repeated queries
|
||||
/// </summary>
|
||||
public ShaderType ShaderType { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Get or set the source of this shader (glShaderSource)
|
||||
/// </summary>
|
||||
public string Source
|
||||
{
|
||||
get
|
||||
@@ -36,6 +45,9 @@ namespace Diamond.Wrappers
|
||||
set { GL.ShaderSource(Id, value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check the compilation status of this shader
|
||||
/// </summary>
|
||||
public bool Compiled
|
||||
{
|
||||
get
|
||||
@@ -51,6 +63,20 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Get a parameter of this shader (glGetShader)
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to get</param>
|
||||
/// <returns>The parameter value</returns>
|
||||
public int Get(ShaderParameter parameter)
|
||||
{
|
||||
GL.GetShader(Id, parameter, out int res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compile this shader (glCompileShader)
|
||||
/// </summary>
|
||||
public void Compile() => GL.CompileShader(Id);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -3,6 +3,9 @@ using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace Diamond.Wrappers
|
||||
{
|
||||
/// <summary>
|
||||
/// Wrapper class for OpenGL Texture objects
|
||||
/// </summary>
|
||||
internal sealed class TextureWrap : Wrapper
|
||||
{
|
||||
#region Constructor, GLDelete()
|
||||
@@ -21,6 +24,9 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region Stored
|
||||
|
||||
/// <summary>
|
||||
/// The target for this texture; Texture type.
|
||||
/// </summary>
|
||||
public TextureTarget Target { get; }
|
||||
|
||||
#endregion
|
||||
@@ -29,17 +35,38 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Bind this texture to the currently active TextureUnit (glBindTexture)
|
||||
/// </summary>
|
||||
public void Bind() => GL.BindTexture(Target, Id);
|
||||
|
||||
/// <summary>
|
||||
/// Bind this texture to a particular TextureUnit (glActiveTexture, glBindTexture)
|
||||
/// </summary>
|
||||
/// <param name="unit">Unit to bind to</param>
|
||||
public void Bind(int unit)
|
||||
{
|
||||
GL.ActiveTexture(TextureUnit.Texture0 + unit);
|
||||
Bind();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a texture parameter (glTexParameter)
|
||||
/// </summary>
|
||||
/// <param name="parameter">The parameter to set</param>
|
||||
/// <param name="value">The value to set</param>
|
||||
public void TexParameter(TextureParameterName parameter, int value) => GL.TexParameter(Target, parameter,
|
||||
value);
|
||||
|
||||
/// <summary>
|
||||
/// Upload data to this texture
|
||||
/// </summary>
|
||||
/// <param name="internalFormat">The number of color components in the texture</param>
|
||||
/// <param name="width">The width of the texture</param>
|
||||
/// <param name="height">The height of the texture</param>
|
||||
/// <param name="format">The pixel format of the texture</param>
|
||||
/// <param name="type">The type of the pixel data</param>
|
||||
/// <param name="pixels">Location of the pixel data</param>
|
||||
public void Image2D(PixelInternalFormat internalFormat, int width, int height, PixelFormat format,
|
||||
PixelType type, IntPtr pixels) =>
|
||||
GL.TexImage2D(Target, 0, internalFormat, width, height, 0, format, type, pixels);
|
||||
|
||||
@@ -6,12 +6,19 @@ namespace Diamond.Wrappers
|
||||
{
|
||||
internal abstract class Wrapper : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Logger for all Wrapper types.
|
||||
/// </summary>
|
||||
protected static readonly Logger Logger = LogManager.GetLogger("Wrapper");
|
||||
|
||||
/// <summary>
|
||||
/// The OpenGL name of this object
|
||||
/// </summary>
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static explicit operator int(Wrapper o) => o.Id;
|
||||
|
||||
// Force wrapper types to generate an Id at creation time
|
||||
protected Wrapper(int id)
|
||||
{
|
||||
Id = id;
|
||||
@@ -19,6 +26,9 @@ namespace Diamond.Wrappers
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
/// Delete this OpenGL object (glDelete*)
|
||||
/// </summary>
|
||||
protected abstract void GLDelete();
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
|
||||
Reference in New Issue
Block a user