diff --git a/Diamond/Buffers/GLBuffer.cs b/Diamond/Buffers/GLBuffer.cs index edbe3a4..fc69e83 100644 --- a/Diamond/Buffers/GLBuffer.cs +++ b/Diamond/Buffers/GLBuffer.cs @@ -38,10 +38,10 @@ namespace Diamond.Buffers public class GLBuffer : GLObject where T : struct { - private GLBufferWrapper _buffer; + private readonly GLBufferWrapper _buffer; internal override GLWrapper Wrapper => _buffer; - private int _size; + private readonly int _size; public BufferTarget Target => _buffer.Target; diff --git a/Diamond/Buffers/VertexPointerAttribute.cs b/Diamond/Buffers/VertexPointerAttribute.cs index 4b56d7e..a121912 100644 --- a/Diamond/Buffers/VertexPointerAttribute.cs +++ b/Diamond/Buffers/VertexPointerAttribute.cs @@ -91,7 +91,7 @@ namespace Diamond.Buffers } } - private static Dictionary attribCache = + private static readonly Dictionary attribCache = new Dictionary(); public static VertexDataInfo GetInfo() where T : struct diff --git a/Diamond/Mesh.cs b/Diamond/Mesh.cs index 5c45d94..bfe8230 100644 --- a/Diamond/Mesh.cs +++ b/Diamond/Mesh.cs @@ -17,7 +17,7 @@ namespace Diamond public string Name { get; set; } - private static VertexDataInfo tVdi; + private static readonly VertexDataInfo tVdi; private static List attribs; static Mesh() diff --git a/Diamond/NLog.xsd b/Diamond/NLog.xsd index e7ad6b0..53a7cb6 100644 --- a/Diamond/NLog.xsd +++ b/Diamond/NLog.xsd @@ -404,7 +404,7 @@ - Instance of that is used to format log messages. + Instance of that is used to internalFormat log messages. @@ -464,7 +464,7 @@ - Indicates whether to include source info (file name and line number) in the information sent over the network. + Indicates whether to include source info (file name and line number) in the ininternalFormation sent over the network. @@ -479,7 +479,7 @@ - Indicates whether to include call site (class and method name) in the information sent over the network. + Indicates whether to include call site (class and method name) in the ininternalFormation sent over the network. @@ -957,7 +957,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. @@ -991,7 +991,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. @@ -1170,7 +1170,7 @@ - Indicates whether to compress archive files into the zip archive format. + Indicates whether to compress archive files into the zip archive internalFormat. @@ -1220,7 +1220,7 @@ - Value specifying the date format to use when archiving files. + Value specifying the date internalFormat to use when archiving files. @@ -1771,7 +1771,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. @@ -1804,7 +1804,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. @@ -1814,7 +1814,7 @@ - Indicates whether to use the XML format when serializing message. This will also disable creating queues. + Indicates whether to use the XML internalFormat when serializing message. This will also disable creating queues. @@ -1909,7 +1909,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. @@ -2014,7 +2014,7 @@ - Instance of that is used to format log messages. + Instance of that is used to internalFormat log messages. @@ -2074,7 +2074,7 @@ - Indicates whether to include source info (file name and line number) in the information sent over the network. + Indicates whether to include source info (file name and line number) in the ininternalFormation sent over the network. @@ -2089,7 +2089,7 @@ - Indicates whether to include call site (class and method name) in the information sent over the network. + Indicates whether to include call site (class and method name) in the ininternalFormation sent over the network. @@ -2116,7 +2116,7 @@ - + @@ -2126,10 +2126,10 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. - + Indicates whether to perform layout calculation. @@ -2157,7 +2157,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. @@ -2438,7 +2438,7 @@ - Layout used to format log messages. + Layout used to internalFormat log messages. diff --git a/Diamond/Textures/Texture.cs b/Diamond/Textures/Texture.cs index fa1b757..e304b7e 100644 --- a/Diamond/Textures/Texture.cs +++ b/Diamond/Textures/Texture.cs @@ -1,35 +1,23 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Drawing.Imaging; +using NLog; using OpenTK.Graphics.OpenGL4; using PixelFormat = OpenTK.Graphics.OpenGL4.PixelFormat; namespace Diamond.Textures { - /// - /// Wrapper class for gl Textures. - /// - public class Texture : GLWrapper + internal class TextureWrapper : GLWrapper { - public TextureTarget Target; - - public Texture(TextureTarget target = TextureTarget.Texture2D) - : base((uint) GL.GenTexture()) + internal TextureWrapper(TextureTarget target) { + Id = GL.GenTexture(); Target = target; } - protected override void Delete() => GL.DeleteTexture(Id); + public readonly TextureTarget Target; - public void Bind() - { - GL.BindTexture(Target, Id); - } - - public void Bind(TextureUnit unit) - { - GL.ActiveTexture(unit); - Bind(); - } + public void Bind() => GL.BindTexture(Target, Id); public void Bind(int unit) { @@ -37,38 +25,56 @@ namespace Diamond.Textures Bind(); } - public void Unbind() + public void TexParameter(TextureParameterName parameter, int value) => GL.TexParameter(Target, parameter, + value); + + 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); + + public override void GLDelete() => GL.DeleteTexture(Id); + } + + public class Texture : GLObject + { + internal static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + private readonly TextureWrapper _texture; + internal override GLWrapper Wrapper => _texture; + + internal Texture(TextureWrapper wrapper, string name) { - GL.BindTexture(Target, 0); + _texture = wrapper; + Name = name; } - public void Unbind(TextureUnit unit) - { - GL.ActiveTexture(unit); - Unbind(); - } + public TextureTarget Target => _texture.Target; - public void Unbind(int unit) - { - GL.ActiveTexture(TextureUnit.Texture0 + unit); - Unbind(); - } + public void Bind() => _texture.Bind(); + public void Bind(int unit) => _texture.Bind(unit); - public static Texture FromBitmap(Bitmap bmp) + public override string ToString() => Name == null ? $"{Target} ({Id})" : $"{Target} \'{Name}\' ({Id})"; + + public static Texture FromBitmap(Bitmap bmp, string name = null) { - var tex = new Texture(TextureTarget.Texture2D); - tex.Bind(); - GL.TexParameter(tex.Target, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.Nearest); - GL.TexParameter(tex.Target, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Nearest); + var wrapper= new TextureWrapper(TextureTarget.Texture2D); + var service = new Texture(wrapper, null); + + Logger.Debug("Created texture {0}", service); + + wrapper.Bind(); + wrapper.TexParameter(TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); + wrapper.TexParameter(TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); + var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - GL.TexImage2D(tex.Target, 0, PixelInternalFormat.Rgba, bmp.Width, bmp.Height, 0, PixelFormat.Bgra, - PixelType.UnsignedByte, data.Scan0); + wrapper.Image2D(PixelInternalFormat.Rgba, bmp.Width,bmp.Height,PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); - tex.Unbind(); - return tex; + + return service; } + public static Texture FromFile(string path) { return FromBitmap(new Bitmap(path));