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