mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-22 16:36:16 +00:00
Texture.cs - Add IDisposable interface
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user