diff --git a/PCK-Studio/Rendering/Texture/Texture.cs b/PCK-Studio/Rendering/Texture/Texture.cs index d74438d7..38e9ccf9 100644 --- a/PCK-Studio/Rendering/Texture/Texture.cs +++ b/PCK-Studio/Rendering/Texture/Texture.cs @@ -6,9 +6,9 @@ using OpenTK.Graphics.OpenGL; namespace PckStudio.Rendering.Texture { - internal class Texture + internal abstract class Texture : IDisposable { - protected readonly int _id; + protected readonly int _GL_Id; protected readonly TextureTarget Target; @@ -73,7 +73,7 @@ namespace PckStudio.Rendering.Texture protected Texture(TextureTarget target) { - _id = GL.GenTexture(); + _GL_Id = GL.GenTexture(); Target = target; } @@ -85,7 +85,7 @@ namespace PckStudio.Rendering.Texture public void Bind(int slot = 0) { GL.ActiveTexture(TextureUnit.Texture0 + slot); - GL.BindTexture(Target, _id); + GL.BindTexture(Target, _GL_Id); } public void Unbind() @@ -99,5 +99,11 @@ namespace PckStudio.Rendering.Texture GL.TexParameter(Target, parameterName, value); Debug.WriteLineIf(GL.GetError() != ErrorCode.NoError, $"{Target}: {parameterName} = {value}"); } + + public void Dispose() + { + Unbind(); + GL.DeleteTexture(_GL_Id); + } } } diff --git a/PCK-Studio/Rendering/Texture/Texture2D.cs b/PCK-Studio/Rendering/Texture/Texture2D.cs index b053b551..93b07930 100644 --- a/PCK-Studio/Rendering/Texture/Texture2D.cs +++ b/PCK-Studio/Rendering/Texture/Texture2D.cs @@ -23,23 +23,17 @@ namespace PckStudio.Rendering.Texture public override void SetTexture(Image image) { Bind(); - var bitmap = new Bitmap(image); - var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + var bitmap = new Bitmap(image); + BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, InternalPixelFormat, bitmap.Width, bitmap.Height, 0, PixelFormat, PixelType.UnsignedByte, data.Scan0); bitmap.UnlockBits(data); Unbind(); } - public void Dispose() - { - Unbind(); - GL.DeleteTexture(_id); - } - public void AttachToFramebuffer(FrameBuffer frameBuffer, FramebufferAttachment attachment) { frameBuffer.Bind(); - GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachment, Target, _id, 0); + GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, attachment, Target, _GL_Id, 0); } } }